xref: /aoo41x/main/sw/inc/txatbase.hxx (revision dec99bbd)
11d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
31d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
41d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
51d2dbeb0SAndrew Rist  * distributed with this work for additional information
61d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
71d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
81d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
91d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
101d2dbeb0SAndrew Rist  *
111d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
121d2dbeb0SAndrew Rist  *
131d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
141d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
151d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
161d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
171d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
181d2dbeb0SAndrew Rist  * under the License.
191d2dbeb0SAndrew Rist  *
201d2dbeb0SAndrew Rist  *************************************************************/
211d2dbeb0SAndrew Rist 
221d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir #ifndef _TXATBASE_HXX
24cdf0e10cSrcweir #define _TXATBASE_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <tools/solar.h>
27cdf0e10cSrcweir #include <svl/poolitem.hxx>
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <errhdl.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <boost/utility.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir class SfxItemPool;
35cdf0e10cSrcweir class SvXMLAttrContainerItem;
36cdf0e10cSrcweir class SwFmtRuby;
37cdf0e10cSrcweir class SwFmtCharFmt;
38cdf0e10cSrcweir class SwFmtAutoFmt;
39cdf0e10cSrcweir class SwFmtINetFmt;
40cdf0e10cSrcweir class SwFmtFld;
41cdf0e10cSrcweir class SwFmtFtn;
42cdf0e10cSrcweir class SwFmtFlyCnt;
43cdf0e10cSrcweir class SwTOXMark;
44cdf0e10cSrcweir class SwFmtRefMark;
45cdf0e10cSrcweir class SwFmtMeta;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir class SwTxtAttr : private boost::noncopyable
49cdf0e10cSrcweir {
50cdf0e10cSrcweir private:
51cdf0e10cSrcweir     SfxPoolItem * const m_pAttr;
52cdf0e10cSrcweir     xub_StrLen m_nStart;
53cdf0e10cSrcweir     bool m_bDontExpand          : 1;
54cdf0e10cSrcweir     bool m_bLockExpandFlag      : 1;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     bool m_bDontMoveAttr        : 1;    // refmarks, toxmarks
57cdf0e10cSrcweir     bool m_bCharFmtAttr         : 1;    // charfmt, inet
58cdf0e10cSrcweir     bool m_bOverlapAllowedAttr  : 1;    // refmarks, toxmarks
59cdf0e10cSrcweir     bool m_bPriorityAttr        : 1;    // attribute has priority (redlining)
60cdf0e10cSrcweir     bool m_bDontExpandStart     : 1;    // don't expand start at paragraph start (ruby)
61cdf0e10cSrcweir     bool m_bNesting             : 1;    // SwTxtAttrNesting
62cdf0e10cSrcweir     bool m_bHasDummyChar        : 1;    // without end + meta
6369a74367SOliver-Rainer Wittmann     bool m_bHasContent          : 1;    // text attribute with content
64cdf0e10cSrcweir 
65cdf0e10cSrcweir protected:
66cdf0e10cSrcweir     SwTxtAttr( SfxPoolItem& rAttr, xub_StrLen nStart );
67cdf0e10cSrcweir     virtual ~SwTxtAttr();
68cdf0e10cSrcweir 
SetLockExpandFlag(bool bFlag)69cdf0e10cSrcweir     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
SetDontMoveAttr(bool bFlag)70cdf0e10cSrcweir     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
SetCharFmtAttr(bool bFlag)71cdf0e10cSrcweir     void SetCharFmtAttr( bool bFlag )       { m_bCharFmtAttr = bFlag; }
SetOverlapAllowedAttr(bool bFlag)72cdf0e10cSrcweir     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
SetDontExpandStartAttr(bool bFlag)73cdf0e10cSrcweir     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
SetNesting(const bool bFlag)74cdf0e10cSrcweir     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
SetHasDummyChar(const bool bFlag)75cdf0e10cSrcweir     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
SetHasContent(const bool bFlag)7669a74367SOliver-Rainer Wittmann     void SetHasContent( const bool bFlag )  { m_bHasContent = bFlag; }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir public:
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /// destroy instance
81cdf0e10cSrcweir     static void Destroy( SwTxtAttr * pToDestroy, SfxItemPool& rPool );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /// start position
GetStart()84cdf0e10cSrcweir                   xub_StrLen* GetStart()        { return & m_nStart; }
GetStart() const85cdf0e10cSrcweir             const xub_StrLen* GetStart() const  { return & m_nStart; }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /// end position
8869a74367SOliver-Rainer Wittmann             virtual xub_StrLen* GetEnd(); // also used to change the end position
8969a74367SOliver-Rainer Wittmann             inline const xub_StrLen* End() const;
9069a74367SOliver-Rainer Wittmann             /// end (if available), else start
9169a74367SOliver-Rainer Wittmann             inline const xub_StrLen* GetAnyEnd() const;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     inline void SetDontExpand( bool bDontExpand );
DontExpand() const94cdf0e10cSrcweir     bool DontExpand() const                 { return m_bDontExpand; }
IsLockExpandFlag() const95cdf0e10cSrcweir     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
IsDontMoveAttr() const96cdf0e10cSrcweir     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
IsCharFmtAttr() const97cdf0e10cSrcweir     bool IsCharFmtAttr() const              { return m_bCharFmtAttr; }
IsOverlapAllowedAttr() const98cdf0e10cSrcweir     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
IsPriorityAttr() const99cdf0e10cSrcweir     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
SetPriorityAttr(bool bFlag)100cdf0e10cSrcweir     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
IsDontExpandStartAttr() const101cdf0e10cSrcweir     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
IsNesting() const102cdf0e10cSrcweir     bool IsNesting() const                  { return m_bNesting; }
HasDummyChar() const103cdf0e10cSrcweir     bool HasDummyChar() const               { return m_bHasDummyChar; }
HasContent() const10469a74367SOliver-Rainer Wittmann     bool HasContent() const                 { return m_bHasContent; }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	inline const SfxPoolItem& GetAttr() const;
107cdf0e10cSrcweir     inline       SfxPoolItem& GetAttr();
Which() const108cdf0e10cSrcweir 	inline sal_uInt16 Which() const { return GetAttr().Which(); }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	virtual	int         operator==( const SwTxtAttr& ) const;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	inline const SwFmtCharFmt			&GetCharFmt() const;
113cdf0e10cSrcweir     inline const SwFmtAutoFmt           &GetAutoFmt() const;
114c0286415SOliver-Rainer Wittmann 	inline const SwFmtFld				&GetFmtFld() const;
115cdf0e10cSrcweir 	inline const SwFmtFtn				&GetFtn() const;
116cdf0e10cSrcweir 	inline const SwFmtFlyCnt			&GetFlyCnt() const;
117cdf0e10cSrcweir 	inline const SwTOXMark				&GetTOXMark() const;
118cdf0e10cSrcweir 	inline const SwFmtRefMark			&GetRefMark() const;
119cdf0e10cSrcweir 	inline const SwFmtINetFmt			&GetINetFmt() const;
120cdf0e10cSrcweir 	inline const SwFmtRuby				&GetRuby() const;
121cdf0e10cSrcweir     inline const SwFmtMeta              &GetMeta() const;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir };
124cdf0e10cSrcweir 
125cdf0e10cSrcweir class SwTxtAttrEnd : public SwTxtAttr
126cdf0e10cSrcweir {
127cdf0e10cSrcweir protected:
128cdf0e10cSrcweir     xub_StrLen m_nEnd;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir public:
131cdf0e10cSrcweir     SwTxtAttrEnd( SfxPoolItem& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     virtual xub_StrLen* GetEnd();
134cdf0e10cSrcweir };
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // --------------- Inline Implementierungen ------------------------
138cdf0e10cSrcweir 
End() const13969a74367SOliver-Rainer Wittmann inline const xub_StrLen* SwTxtAttr::End() const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     return const_cast<SwTxtAttr * >(this)->GetEnd();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
GetAnyEnd() const144cdf0e10cSrcweir inline const xub_StrLen* SwTxtAttr::GetAnyEnd() const
145cdf0e10cSrcweir {
14669a74367SOliver-Rainer Wittmann 	const xub_StrLen* pEnd = End();
147cdf0e10cSrcweir     return pEnd ? pEnd : GetStart();
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
GetAttr() const150cdf0e10cSrcweir inline const SfxPoolItem& SwTxtAttr::GetAttr() const
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     ASSERT( m_pAttr, "SwTxtAttr: where is my attribute?" );
153cdf0e10cSrcweir     return *m_pAttr;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
GetAttr()156cdf0e10cSrcweir inline SfxPoolItem& SwTxtAttr::GetAttr()
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     return const_cast<SfxPoolItem&>(
159cdf0e10cSrcweir             const_cast<const SwTxtAttr*>(this)->GetAttr());
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
SetDontExpand(bool bDontExpand)162cdf0e10cSrcweir inline void SwTxtAttr::SetDontExpand( bool bDontExpand )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     if ( !m_bLockExpandFlag )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         m_bDontExpand = bDontExpand;
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir //------------------------------------------------------------------------
171cdf0e10cSrcweir 
GetCharFmt() const172cdf0e10cSrcweir inline const SwFmtCharFmt& SwTxtAttr::GetCharFmt() const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT,
175cdf0e10cSrcweir         "Wrong attribute" );
176cdf0e10cSrcweir     return (const SwFmtCharFmt&)(*m_pAttr);
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
GetAutoFmt() const179cdf0e10cSrcweir inline const SwFmtAutoFmt& SwTxtAttr::GetAutoFmt() const
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT,
182cdf0e10cSrcweir         "Wrong attribute" );
183cdf0e10cSrcweir     return (const SwFmtAutoFmt&)(*m_pAttr);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
GetFmtFld() const186c0286415SOliver-Rainer Wittmann inline const SwFmtFld& SwTxtAttr::GetFmtFld() const
187cdf0e10cSrcweir {
18869a74367SOliver-Rainer Wittmann     ASSERT( m_pAttr
18969a74367SOliver-Rainer Wittmann             && ( m_pAttr->Which() == RES_TXTATR_FIELD
190*dec99bbdSOliver-Rainer Wittmann                  || m_pAttr->Which() == RES_TXTATR_ANNOTATION
19169a74367SOliver-Rainer Wittmann                  || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ),
19269a74367SOliver-Rainer Wittmann             "Wrong attribute" );
193cdf0e10cSrcweir     return (const SwFmtFld&)(*m_pAttr);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
GetFtn() const196cdf0e10cSrcweir inline const SwFmtFtn& SwTxtAttr::GetFtn() const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN, "Wrong attribute" );
199cdf0e10cSrcweir     return (const SwFmtFtn&)(*m_pAttr);
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
GetFlyCnt() const202cdf0e10cSrcweir inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT,
205cdf0e10cSrcweir         "Wrong attribute" );
206cdf0e10cSrcweir     return (const SwFmtFlyCnt&)(*m_pAttr);
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
GetTOXMark() const209cdf0e10cSrcweir inline const SwTOXMark& SwTxtAttr::GetTOXMark() const
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK,
212cdf0e10cSrcweir         "Wrong attribute" );
213cdf0e10cSrcweir     return (const SwTOXMark&)(*m_pAttr);
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
GetRefMark() const216cdf0e10cSrcweir inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK,
219cdf0e10cSrcweir         "Wrong attribute" );
220cdf0e10cSrcweir     return (const SwFmtRefMark&)(*m_pAttr);
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
GetINetFmt() const223cdf0e10cSrcweir inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT,
226cdf0e10cSrcweir         "Wrong attribute" );
227cdf0e10cSrcweir     return (const SwFmtINetFmt&)(*m_pAttr);
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
GetRuby() const230cdf0e10cSrcweir inline const SwFmtRuby& SwTxtAttr::GetRuby() const
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY,
233cdf0e10cSrcweir         "Wrong attribute" );
234cdf0e10cSrcweir     return (const SwFmtRuby&)(*m_pAttr);
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
GetMeta() const237cdf0e10cSrcweir inline const SwFmtMeta& SwTxtAttr::GetMeta() const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     ASSERT( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
240cdf0e10cSrcweir                         m_pAttr->Which() == RES_TXTATR_METAFIELD),
241cdf0e10cSrcweir         "Wrong attribute" );
242cdf0e10cSrcweir     return (const SwFmtMeta&)(*m_pAttr);
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir #endif
246