xref: /aoo42x/main/sw/inc/txatbase.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef _TXATBASE_HXX
28*cdf0e10cSrcweir #define _TXATBASE_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <tools/solar.h>
31*cdf0e10cSrcweir #include <svl/poolitem.hxx>
32*cdf0e10cSrcweir #include <hintids.hxx>
33*cdf0e10cSrcweir #include <errhdl.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <boost/utility.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir class SfxItemPool;
39*cdf0e10cSrcweir class SvXMLAttrContainerItem;
40*cdf0e10cSrcweir class SwFmtRuby;
41*cdf0e10cSrcweir class SwFmtCharFmt;
42*cdf0e10cSrcweir class SwFmtAutoFmt;
43*cdf0e10cSrcweir class SwFmtINetFmt;
44*cdf0e10cSrcweir class SwFmtFld;
45*cdf0e10cSrcweir class SwFmtFtn;
46*cdf0e10cSrcweir class SwFmtFlyCnt;
47*cdf0e10cSrcweir class SwTOXMark;
48*cdf0e10cSrcweir class SwFmtRefMark;
49*cdf0e10cSrcweir class SwFmtMeta;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir class SwTxtAttr : private boost::noncopyable
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir private:
55*cdf0e10cSrcweir     SfxPoolItem * const m_pAttr;
56*cdf0e10cSrcweir     xub_StrLen m_nStart;
57*cdf0e10cSrcweir     bool m_bDontExpand          : 1;
58*cdf0e10cSrcweir     bool m_bLockExpandFlag      : 1;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     bool m_bDontMoveAttr        : 1;    // refmarks, toxmarks
61*cdf0e10cSrcweir     bool m_bCharFmtAttr         : 1;    // charfmt, inet
62*cdf0e10cSrcweir     bool m_bOverlapAllowedAttr  : 1;    // refmarks, toxmarks
63*cdf0e10cSrcweir     bool m_bPriorityAttr        : 1;    // attribute has priority (redlining)
64*cdf0e10cSrcweir     bool m_bDontExpandStart     : 1;    // don't expand start at paragraph start (ruby)
65*cdf0e10cSrcweir     bool m_bNesting             : 1;    // SwTxtAttrNesting
66*cdf0e10cSrcweir     bool m_bHasDummyChar        : 1;    // without end + meta
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir protected:
69*cdf0e10cSrcweir     SwTxtAttr( SfxPoolItem& rAttr, xub_StrLen nStart );
70*cdf0e10cSrcweir     virtual ~SwTxtAttr();
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
73*cdf0e10cSrcweir     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
74*cdf0e10cSrcweir     void SetCharFmtAttr( bool bFlag )       { m_bCharFmtAttr = bFlag; }
75*cdf0e10cSrcweir     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
76*cdf0e10cSrcweir     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
77*cdf0e10cSrcweir     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
78*cdf0e10cSrcweir     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir public:
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     /// destroy instance
83*cdf0e10cSrcweir     static void Destroy( SwTxtAttr * pToDestroy, SfxItemPool& rPool );
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     /// start position
86*cdf0e10cSrcweir                   xub_StrLen* GetStart()        { return & m_nStart; }
87*cdf0e10cSrcweir             const xub_StrLen* GetStart() const  { return & m_nStart; }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     /// end position
90*cdf0e10cSrcweir 	virtual 	 xub_StrLen* GetEnd();
91*cdf0e10cSrcweir 	inline const xub_StrLen* GetEnd() const;
92*cdf0e10cSrcweir     /// end (if available), else start
93*cdf0e10cSrcweir 	inline const xub_StrLen* GetAnyEnd() const;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     inline void SetDontExpand( bool bDontExpand );
96*cdf0e10cSrcweir     bool DontExpand() const                 { return m_bDontExpand; }
97*cdf0e10cSrcweir     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
98*cdf0e10cSrcweir     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
99*cdf0e10cSrcweir     bool IsCharFmtAttr() const              { return m_bCharFmtAttr; }
100*cdf0e10cSrcweir     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
101*cdf0e10cSrcweir     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
102*cdf0e10cSrcweir     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
103*cdf0e10cSrcweir     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
104*cdf0e10cSrcweir     bool IsNesting() const                  { return m_bNesting; }
105*cdf0e10cSrcweir     bool HasDummyChar() const               { return m_bHasDummyChar; }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	inline const SfxPoolItem& GetAttr() const;
108*cdf0e10cSrcweir     inline       SfxPoolItem& GetAttr();
109*cdf0e10cSrcweir 	inline sal_uInt16 Which() const { return GetAttr().Which(); }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	virtual	int         operator==( const SwTxtAttr& ) const;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	inline const SwFmtCharFmt			&GetCharFmt() const;
114*cdf0e10cSrcweir     inline const SwFmtAutoFmt           &GetAutoFmt() const;
115*cdf0e10cSrcweir 	inline const SwFmtFld				&GetFld() const;
116*cdf0e10cSrcweir 	inline const SwFmtFtn				&GetFtn() const;
117*cdf0e10cSrcweir 	inline const SwFmtFlyCnt			&GetFlyCnt() const;
118*cdf0e10cSrcweir 	inline const SwTOXMark				&GetTOXMark() const;
119*cdf0e10cSrcweir 	inline const SwFmtRefMark			&GetRefMark() const;
120*cdf0e10cSrcweir 	inline const SwFmtINetFmt			&GetINetFmt() const;
121*cdf0e10cSrcweir 	inline const SwFmtRuby				&GetRuby() const;
122*cdf0e10cSrcweir     inline const SwFmtMeta              &GetMeta() const;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir };
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir class SwTxtAttrEnd : public SwTxtAttr
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir protected:
129*cdf0e10cSrcweir     xub_StrLen m_nEnd;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir public:
132*cdf0e10cSrcweir     SwTxtAttrEnd( SfxPoolItem& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     using SwTxtAttr::GetEnd;
135*cdf0e10cSrcweir     virtual xub_StrLen* GetEnd();
136*cdf0e10cSrcweir };
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir // --------------- Inline Implementierungen ------------------------
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir inline const xub_StrLen* SwTxtAttr::GetEnd() const
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     return const_cast<SwTxtAttr * >(this)->GetEnd();
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir inline const xub_StrLen* SwTxtAttr::GetAnyEnd() const
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	const xub_StrLen* pEnd = GetEnd();
149*cdf0e10cSrcweir     return pEnd ? pEnd : GetStart();
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir inline const SfxPoolItem& SwTxtAttr::GetAttr() const
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     ASSERT( m_pAttr, "SwTxtAttr: where is my attribute?" );
155*cdf0e10cSrcweir     return *m_pAttr;
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir inline SfxPoolItem& SwTxtAttr::GetAttr()
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     return const_cast<SfxPoolItem&>(
161*cdf0e10cSrcweir             const_cast<const SwTxtAttr*>(this)->GetAttr());
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir inline void SwTxtAttr::SetDontExpand( bool bDontExpand )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     if ( !m_bLockExpandFlag )
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir         m_bDontExpand = bDontExpand;
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //------------------------------------------------------------------------
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir inline const SwFmtCharFmt& SwTxtAttr::GetCharFmt() const
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT,
177*cdf0e10cSrcweir         "Wrong attribute" );
178*cdf0e10cSrcweir     return (const SwFmtCharFmt&)(*m_pAttr);
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir inline const SwFmtAutoFmt& SwTxtAttr::GetAutoFmt() const
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT,
184*cdf0e10cSrcweir         "Wrong attribute" );
185*cdf0e10cSrcweir     return (const SwFmtAutoFmt&)(*m_pAttr);
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir inline const SwFmtFld& SwTxtAttr::GetFld() const
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FIELD,
191*cdf0e10cSrcweir         "Wrong attribute" );
192*cdf0e10cSrcweir     return (const SwFmtFld&)(*m_pAttr);
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir inline const SwFmtFtn& SwTxtAttr::GetFtn() const
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN, "Wrong attribute" );
198*cdf0e10cSrcweir     return (const SwFmtFtn&)(*m_pAttr);
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT,
204*cdf0e10cSrcweir         "Wrong attribute" );
205*cdf0e10cSrcweir     return (const SwFmtFlyCnt&)(*m_pAttr);
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir inline const SwTOXMark& SwTxtAttr::GetTOXMark() const
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK,
211*cdf0e10cSrcweir         "Wrong attribute" );
212*cdf0e10cSrcweir     return (const SwTOXMark&)(*m_pAttr);
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK,
218*cdf0e10cSrcweir         "Wrong attribute" );
219*cdf0e10cSrcweir     return (const SwFmtRefMark&)(*m_pAttr);
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT,
225*cdf0e10cSrcweir         "Wrong attribute" );
226*cdf0e10cSrcweir     return (const SwFmtINetFmt&)(*m_pAttr);
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir inline const SwFmtRuby& SwTxtAttr::GetRuby() const
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY,
232*cdf0e10cSrcweir         "Wrong attribute" );
233*cdf0e10cSrcweir     return (const SwFmtRuby&)(*m_pAttr);
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir inline const SwFmtMeta& SwTxtAttr::GetMeta() const
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     ASSERT( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
239*cdf0e10cSrcweir                         m_pAttr->Which() == RES_TXTATR_METAFIELD),
240*cdf0e10cSrcweir         "Wrong attribute" );
241*cdf0e10cSrcweir     return (const SwFmtMeta&)(*m_pAttr);
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir #endif
245