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