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