xref: /trunk/main/sw/inc/txatbase.hxx (revision 69a74367)
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 
69     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
70     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
71     void SetCharFmtAttr( bool bFlag )       { m_bCharFmtAttr = bFlag; }
72     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
73     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
74     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
75     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = 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
84                   xub_StrLen* GetStart()        { return & m_nStart; }
85             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 );
94     bool DontExpand() const                 { return m_bDontExpand; }
95     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
96     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
97     bool IsCharFmtAttr() const              { return m_bCharFmtAttr; }
98     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
99     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
100     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
101     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
102     bool IsNesting() const                  { return m_bNesting; }
103     bool HasDummyChar() const               { return m_bHasDummyChar; }
104     bool HasContent() const                 { return m_bHasContent; }
105 
106 	inline const SfxPoolItem& GetAttr() const;
107     inline       SfxPoolItem& GetAttr();
108 	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 
139 inline const xub_StrLen* SwTxtAttr::End() const
140 {
141     return const_cast<SwTxtAttr * >(this)->GetEnd();
142 }
143 
144 inline const xub_StrLen* SwTxtAttr::GetAnyEnd() const
145 {
146 	const xub_StrLen* pEnd = End();
147     return pEnd ? pEnd : GetStart();
148 }
149 
150 inline const SfxPoolItem& SwTxtAttr::GetAttr() const
151 {
152     ASSERT( m_pAttr, "SwTxtAttr: where is my attribute?" );
153     return *m_pAttr;
154 }
155 
156 inline SfxPoolItem& SwTxtAttr::GetAttr()
157 {
158     return const_cast<SfxPoolItem&>(
159             const_cast<const SwTxtAttr*>(this)->GetAttr());
160 }
161 
162 inline void SwTxtAttr::SetDontExpand( bool bDontExpand )
163 {
164     if ( !m_bLockExpandFlag )
165     {
166         m_bDontExpand = bDontExpand;
167     }
168 }
169 
170 //------------------------------------------------------------------------
171 
172 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 
179 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 
186 inline const SwFmtFld& SwTxtAttr::GetFmtFld() const
187 {
188     ASSERT( m_pAttr
189             && ( m_pAttr->Which() == RES_TXTATR_FIELD
190                  || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ),
191             "Wrong attribute" );
192     return (const SwFmtFld&)(*m_pAttr);
193 }
194 
195 inline const SwFmtFtn& SwTxtAttr::GetFtn() const
196 {
197     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN, "Wrong attribute" );
198     return (const SwFmtFtn&)(*m_pAttr);
199 }
200 
201 inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const
202 {
203     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT,
204         "Wrong attribute" );
205     return (const SwFmtFlyCnt&)(*m_pAttr);
206 }
207 
208 inline const SwTOXMark& SwTxtAttr::GetTOXMark() const
209 {
210     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK,
211         "Wrong attribute" );
212     return (const SwTOXMark&)(*m_pAttr);
213 }
214 
215 inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const
216 {
217     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK,
218         "Wrong attribute" );
219     return (const SwFmtRefMark&)(*m_pAttr);
220 }
221 
222 inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const
223 {
224     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT,
225         "Wrong attribute" );
226     return (const SwFmtINetFmt&)(*m_pAttr);
227 }
228 
229 inline const SwFmtRuby& SwTxtAttr::GetRuby() const
230 {
231     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY,
232         "Wrong attribute" );
233     return (const SwFmtRuby&)(*m_pAttr);
234 }
235 
236 inline const SwFmtMeta& SwTxtAttr::GetMeta() const
237 {
238     ASSERT( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
239                         m_pAttr->Which() == RES_TXTATR_METAFIELD),
240         "Wrong attribute" );
241     return (const SwFmtMeta&)(*m_pAttr);
242 }
243 
244 #endif
245