xref: /aoo41x/main/sw/inc/txatbase.hxx (revision c0286415)
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 
64 protected:
65     SwTxtAttr( SfxPoolItem& rAttr, xub_StrLen nStart );
66     virtual ~SwTxtAttr();
67 
68     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
69     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
70     void SetCharFmtAttr( bool bFlag )       { m_bCharFmtAttr = bFlag; }
71     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
72     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
73     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
74     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
75 
76 public:
77 
78     /// destroy instance
79     static void Destroy( SwTxtAttr * pToDestroy, SfxItemPool& rPool );
80 
81     /// start position
82                   xub_StrLen* GetStart()        { return & m_nStart; }
83             const xub_StrLen* GetStart() const  { return & m_nStart; }
84 
85     /// end position
86 	virtual 	 xub_StrLen* GetEnd();
87 	inline const xub_StrLen* GetEnd() const;
88     /// end (if available), else start
89 	inline const xub_StrLen* GetAnyEnd() const;
90 
91     inline void SetDontExpand( bool bDontExpand );
92     bool DontExpand() const                 { return m_bDontExpand; }
93     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
94     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
95     bool IsCharFmtAttr() const              { return m_bCharFmtAttr; }
96     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
97     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
98     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
99     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
100     bool IsNesting() const                  { return m_bNesting; }
101     bool HasDummyChar() const               { return m_bHasDummyChar; }
102 
103 	inline const SfxPoolItem& GetAttr() const;
104     inline       SfxPoolItem& GetAttr();
105 	inline sal_uInt16 Which() const { return GetAttr().Which(); }
106 
107 	virtual	int         operator==( const SwTxtAttr& ) const;
108 
109 	inline const SwFmtCharFmt			&GetCharFmt() const;
110     inline const SwFmtAutoFmt           &GetAutoFmt() const;
111 	inline const SwFmtFld				&GetFmtFld() const;
112 	inline const SwFmtFtn				&GetFtn() const;
113 	inline const SwFmtFlyCnt			&GetFlyCnt() const;
114 	inline const SwTOXMark				&GetTOXMark() const;
115 	inline const SwFmtRefMark			&GetRefMark() const;
116 	inline const SwFmtINetFmt			&GetINetFmt() const;
117 	inline const SwFmtRuby				&GetRuby() const;
118     inline const SwFmtMeta              &GetMeta() const;
119 
120 };
121 
122 class SwTxtAttrEnd : public SwTxtAttr
123 {
124 protected:
125     xub_StrLen m_nEnd;
126 
127 public:
128     SwTxtAttrEnd( SfxPoolItem& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
129 
130     using SwTxtAttr::GetEnd;
131     virtual xub_StrLen* GetEnd();
132 };
133 
134 
135 // --------------- Inline Implementierungen ------------------------
136 
137 inline const xub_StrLen* SwTxtAttr::GetEnd() const
138 {
139     return const_cast<SwTxtAttr * >(this)->GetEnd();
140 }
141 
142 inline const xub_StrLen* SwTxtAttr::GetAnyEnd() const
143 {
144 	const xub_StrLen* pEnd = GetEnd();
145     return pEnd ? pEnd : GetStart();
146 }
147 
148 inline const SfxPoolItem& SwTxtAttr::GetAttr() const
149 {
150     ASSERT( m_pAttr, "SwTxtAttr: where is my attribute?" );
151     return *m_pAttr;
152 }
153 
154 inline SfxPoolItem& SwTxtAttr::GetAttr()
155 {
156     return const_cast<SfxPoolItem&>(
157             const_cast<const SwTxtAttr*>(this)->GetAttr());
158 }
159 
160 inline void SwTxtAttr::SetDontExpand( bool bDontExpand )
161 {
162     if ( !m_bLockExpandFlag )
163     {
164         m_bDontExpand = bDontExpand;
165     }
166 }
167 
168 //------------------------------------------------------------------------
169 
170 inline const SwFmtCharFmt& SwTxtAttr::GetCharFmt() const
171 {
172     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT,
173         "Wrong attribute" );
174     return (const SwFmtCharFmt&)(*m_pAttr);
175 }
176 
177 inline const SwFmtAutoFmt& SwTxtAttr::GetAutoFmt() const
178 {
179     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT,
180         "Wrong attribute" );
181     return (const SwFmtAutoFmt&)(*m_pAttr);
182 }
183 
184 inline const SwFmtFld& SwTxtAttr::GetFmtFld() const
185 {
186     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FIELD,
187         "Wrong attribute" );
188     return (const SwFmtFld&)(*m_pAttr);
189 }
190 
191 inline const SwFmtFtn& SwTxtAttr::GetFtn() const
192 {
193     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN, "Wrong attribute" );
194     return (const SwFmtFtn&)(*m_pAttr);
195 }
196 
197 inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const
198 {
199     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT,
200         "Wrong attribute" );
201     return (const SwFmtFlyCnt&)(*m_pAttr);
202 }
203 
204 inline const SwTOXMark& SwTxtAttr::GetTOXMark() const
205 {
206     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK,
207         "Wrong attribute" );
208     return (const SwTOXMark&)(*m_pAttr);
209 }
210 
211 inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const
212 {
213     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK,
214         "Wrong attribute" );
215     return (const SwFmtRefMark&)(*m_pAttr);
216 }
217 
218 inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const
219 {
220     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT,
221         "Wrong attribute" );
222     return (const SwFmtINetFmt&)(*m_pAttr);
223 }
224 
225 inline const SwFmtRuby& SwTxtAttr::GetRuby() const
226 {
227     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY,
228         "Wrong attribute" );
229     return (const SwFmtRuby&)(*m_pAttr);
230 }
231 
232 inline const SwFmtMeta& SwTxtAttr::GetMeta() const
233 {
234     ASSERT( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
235                         m_pAttr->Which() == RES_TXTATR_METAFIELD),
236         "Wrong attribute" );
237     return (const SwFmtMeta&)(*m_pAttr);
238 }
239 
240 #endif
241