Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_SVL_POOLITEM_HXX
20 : #define INCLUDED_SVL_POOLITEM_HXX
21 :
22 : #include <svl/svldllapi.h>
23 : #include <com/sun/star/uno/Any.hxx>
24 :
25 : #include <sal/config.h>
26 : #include <tools/rtti.hxx>
27 : #include <limits.h>
28 : #include <tools/solar.h>
29 : #include <tools/debug.hxx>
30 : #include <svl/hint.hxx>
31 :
32 : class SbxVariable;
33 : class SbxObject;
34 : class SvStream;
35 : class Color;
36 : class IntlWrapper;
37 :
38 : namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
39 :
40 : enum SfxItemKind {
41 : SFX_ITEMS_NONE,
42 : SFX_ITEMS_DELETEONIDLE,
43 : SFX_ITEMS_STATICDEFAULT,
44 : SFX_ITEMS_POOLDEFAULT
45 : };
46 :
47 : #define SFX_ITEMS_OLD_MAXREF 0xffef
48 : #define SFX_ITEMS_MAXREF 0xfffffffe
49 : #define SFX_ITEMS_SPECIAL 0xffffffff
50 :
51 : #define CONVERT_TWIPS 0x80 // Uno conversion for measurement (for MemberId)
52 :
53 :
54 :
55 : // UNO3 shortcuts
56 :
57 : // warning, if there is no boolean inside the any this will always return the value false
58 52169 : inline bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
59 : {
60 52169 : bool nValue = false;
61 52169 : if( rValue.hasValue() )
62 : {
63 52169 : if( rValue.getValueType() == cppu::UnoType<bool>::get() )
64 : {
65 52169 : nValue = *static_cast<sal_Bool const *>(rValue.getValue());
66 : }
67 : else
68 : {
69 0 : sal_Int32 nNum = 0;
70 0 : if( rValue >>= nNum )
71 0 : nValue = nNum != 0;
72 : }
73 : }
74 :
75 52169 : return nValue;
76 : }
77 :
78 : enum SfxMapUnit
79 : {
80 : SFX_MAPUNIT_100TH_MM,
81 : SFX_MAPUNIT_10TH_MM,
82 : SFX_MAPUNIT_MM,
83 : SFX_MAPUNIT_CM,
84 : SFX_MAPUNIT_1000TH_INCH,
85 : SFX_MAPUNIT_100TH_INCH,
86 : SFX_MAPUNIT_10TH_INCH,
87 : SFX_MAPUNIT_INCH,
88 : SFX_MAPUNIT_POINT,
89 : SFX_MAPUNIT_TWIP,
90 : SFX_MAPUNIT_PIXEL,
91 : SFX_MAPUNIT_SYSFONT,
92 : SFX_MAPUNIT_APPFONT,
93 : SFX_MAPUNIT_RELATIVE,
94 : SFX_MAPUNIT_ABSOLUTE
95 : };
96 :
97 :
98 :
99 : enum SfxItemPresentation
100 :
101 : /*
102 : * The values of this enum describe the degree of textual
103 : * representation of an item after calling the virtual
104 : * method <SfxPoolItem::GetPresentation()const>.
105 : */
106 : {
107 : SFX_ITEM_PRESENTATION_NAMELESS,
108 : SFX_ITEM_PRESENTATION_COMPLETE
109 : };
110 :
111 : /**
112 : * These values have to match the values in the
113 : * com::sun::star::frame::status::ItemState IDL
114 : * to be found at offapi/com/sun/star/frame/status/ItemState.idl
115 : */
116 : enum class SfxItemState {
117 :
118 : /** Specifies an unknown state. */
119 : UNKNOWN = 0,
120 :
121 : /** Specifies that the property is currently disabled. */
122 : DISABLED = 0x0001,
123 :
124 : /** Specifies that the property is currently read-only. */
125 : READONLY = 0x0002,
126 :
127 : /** Specifies that the property is currently in a don't care state.
128 : * <br/>
129 : * This is normally used if a selection provides more than one state
130 : * for a property at the same time.
131 : */
132 : DONTCARE = 0x0010,
133 :
134 : /** Specifies that the property is currently in a default state. */
135 : DEFAULT = 0x0020,
136 :
137 : /** The property has been explicitly set to a given value hence we know
138 : * we are not taking the default value.
139 : * <br/>
140 : * For example, you may want to get the font color and it might either
141 : * be the default one or one that has been explicitly set.
142 : */
143 : SET = 0x0030
144 : };
145 :
146 : class SvXMLUnitConverter;
147 : class SfxItemPool;
148 : class SfxItemSet;
149 :
150 :
151 :
152 :
153 : class SVL_DLLPUBLIC SfxPoolItem
154 : {
155 : friend class SfxItemPool;
156 : friend class SfxItemDisruptor_Impl;
157 : friend class SfxItemPoolCache;
158 : friend class SfxItemSet;
159 : friend class SfxVoidItem;
160 :
161 : mutable sal_uLong m_nRefCount;
162 : sal_uInt16 m_nWhich;
163 : SfxItemKind m_nKind;
164 :
165 : private:
166 : inline void SetRefCount( sal_uLong n );
167 : inline void SetKind( SfxItemKind n );
168 : public:
169 : inline void AddRef( sal_uLong n = 1 ) const;
170 : private:
171 : inline sal_uLong ReleaseRef( sal_uLong n = 1 ) const;
172 :
173 : protected:
174 : explicit SfxPoolItem( sal_uInt16 nWhich = 0 );
175 : SfxPoolItem( const SfxPoolItem& );
176 :
177 : public:
178 : TYPEINFO();
179 : virtual ~SfxPoolItem();
180 :
181 5229408 : void SetWhich( sal_uInt16 nId ) { m_nWhich = nId; }
182 215646952 : sal_uInt16 Which() const { return m_nWhich; }
183 : virtual bool operator==( const SfxPoolItem& ) const = 0;
184 242673 : bool operator!=( const SfxPoolItem& rItem ) const
185 242673 : { return !(*this == rItem); }
186 : virtual int Compare( const SfxPoolItem &rWith ) const;
187 : virtual int Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const;
188 :
189 : /** @return true if it has a valid string representation */
190 : virtual bool GetPresentation( SfxItemPresentation ePresentation,
191 : SfxMapUnit eCoreMetric,
192 : SfxMapUnit ePresentationMetric,
193 : OUString &rText,
194 : const IntlWrapper * pIntlWrapper = 0 ) const;
195 :
196 : virtual sal_uInt16 GetVersion( sal_uInt16 nFileFormatVersion ) const;
197 : virtual bool ScaleMetrics( long lMult, long lDiv );
198 : virtual bool HasMetrics() const;
199 :
200 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
201 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 );
202 :
203 : virtual SfxPoolItem* Create( SvStream &, sal_uInt16 nItemVersion ) const;
204 : virtual SvStream& Store( SvStream &, sal_uInt16 nItemVersion ) const;
205 : virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const = 0;
206 :
207 106752296 : sal_uLong GetRefCount() const { return m_nRefCount; }
208 117810370 : inline SfxItemKind GetKind() const { return m_nKind; }
209 : virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
210 :
211 : private:
212 : SfxPoolItem& operator=( const SfxPoolItem& ) SAL_DELETED_FUNCTION;
213 : };
214 :
215 :
216 :
217 1443519 : inline void SfxPoolItem::SetRefCount( sal_uLong n )
218 : {
219 1443519 : m_nRefCount = n;
220 1443519 : m_nKind = SFX_ITEMS_NONE;
221 1443519 : }
222 :
223 5163999 : inline void SfxPoolItem::SetKind( SfxItemKind n )
224 : {
225 5163999 : m_nRefCount = SFX_ITEMS_SPECIAL;
226 5163999 : m_nKind = n;
227 5163999 : }
228 :
229 46224076 : inline void SfxPoolItem::AddRef( sal_uLong n ) const
230 : {
231 : DBG_ASSERT(m_nRefCount <= SFX_ITEMS_MAXREF, "AddRef with non-Pool-Item");
232 : DBG_ASSERT(ULONG_MAX - m_nRefCount > n, "AddRef: refcount overflow");
233 46224076 : m_nRefCount += n;
234 46224076 : }
235 :
236 46016298 : inline sal_uLong SfxPoolItem::ReleaseRef( sal_uLong n ) const
237 : {
238 : DBG_ASSERT(m_nRefCount <= SFX_ITEMS_MAXREF, "AddRef with non-Pool-Item");
239 : DBG_ASSERT(m_nRefCount >= n, "AddRef: refcount underflow");
240 46016298 : m_nRefCount -= n;
241 46016298 : return m_nRefCount;
242 : }
243 :
244 :
245 :
246 3602699 : inline bool IsPoolDefaultItem(const SfxPoolItem *pItem )
247 : {
248 3602699 : return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
249 : }
250 :
251 20084559 : inline bool IsStaticDefaultItem(const SfxPoolItem *pItem )
252 : {
253 20084559 : return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
254 : }
255 :
256 44328376 : inline bool IsDefaultItem( const SfxPoolItem *pItem )
257 : {
258 44328376 : return pItem && (pItem->GetKind() == SFX_ITEMS_STATICDEFAULT || pItem->GetKind() == SFX_ITEMS_POOLDEFAULT);
259 : }
260 :
261 26325591 : inline bool IsPooledItem( const SfxPoolItem *pItem )
262 : {
263 26325591 : return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
264 : }
265 :
266 112267422 : inline bool IsInvalidItem(const SfxPoolItem *pItem)
267 : {
268 112267422 : return pItem == reinterpret_cast<SfxPoolItem *>(-1);
269 : }
270 :
271 :
272 :
273 : class SVL_DLLPUBLIC SfxVoidItem: public SfxPoolItem
274 : {
275 : SfxVoidItem & operator=( const SfxVoidItem& ) SAL_DELETED_FUNCTION;
276 : public:
277 : TYPEINFO_OVERRIDE();
278 : explicit SfxVoidItem( sal_uInt16 nWhich );
279 : SfxVoidItem( sal_uInt16 nWhich, SvStream & );
280 : SfxVoidItem( const SfxVoidItem& );
281 : virtual ~SfxVoidItem();
282 :
283 : virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
284 :
285 : virtual bool GetPresentation( SfxItemPresentation ePres,
286 : SfxMapUnit eCoreMetric,
287 : SfxMapUnit ePresMetric,
288 : OUString &rText,
289 : const IntlWrapper * = 0 ) const SAL_OVERRIDE;
290 :
291 : // create a copy of itself
292 : virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
293 : void SetWhich(sal_uInt16 nWh) { m_nWhich = nWh; }
294 : };
295 :
296 :
297 :
298 : class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
299 : {
300 : SfxItemSet *pSet;
301 :
302 : SfxSetItem & operator=( const SfxSetItem& ) SAL_DELETED_FUNCTION;
303 :
304 : public:
305 : TYPEINFO_OVERRIDE();
306 : SfxSetItem( sal_uInt16 nWhich, SfxItemSet *pSet );
307 : SfxSetItem( sal_uInt16 nWhich, const SfxItemSet &rSet );
308 : SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = 0 );
309 : virtual ~SfxSetItem();
310 :
311 : virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
312 :
313 : virtual bool GetPresentation( SfxItemPresentation ePres,
314 : SfxMapUnit eCoreMetric,
315 : SfxMapUnit ePresMetric,
316 : OUString &rText,
317 : const IntlWrapper * = 0 ) const SAL_OVERRIDE;
318 :
319 : // create a copy of itself
320 : virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE = 0;
321 : virtual SfxPoolItem* Create(SvStream &, sal_uInt16 nVersion) const SAL_OVERRIDE = 0;
322 : virtual SvStream& Store(SvStream &, sal_uInt16 nVer) const SAL_OVERRIDE;
323 :
324 46120932 : const SfxItemSet& GetItemSet() const
325 46120932 : { return *pSet; }
326 774291 : SfxItemSet& GetItemSet()
327 774291 : { return *pSet; }
328 : };
329 :
330 :
331 : class SVL_DLLPUBLIC SfxPoolItemHint: public SfxHint
332 : {
333 : SfxPoolItem* pObj;
334 : public:
335 30561 : explicit SfxPoolItemHint( SfxPoolItem* Object ) : pObj(Object) {}
336 30561 : virtual ~SfxPoolItemHint() {}
337 0 : SfxPoolItem* GetObject() const { return pObj; }
338 : };
339 :
340 :
341 :
342 : #endif // INCLUDED_SVL_POOLITEM_HXX
343 :
344 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|