Branch libreoffice-5-0-4
[LibreOffice.git] / include / svl / poolitem.hxx
blob518c875d96f1b38d5843839d0e4fa1a8aa8e4042
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SVL_POOLITEM_HXX
20 #define INCLUDED_SVL_POOLITEM_HXX
22 #include <svl/svldllapi.h>
23 #include <com/sun/star/uno/Any.hxx>
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>
32 class SbxVariable;
33 class SbxObject;
34 class SvStream;
35 class Color;
36 class IntlWrapper;
38 namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
40 enum SfxItemKind {
41 SFX_ITEMS_NONE,
42 SFX_ITEMS_DELETEONIDLE,
43 SFX_ITEMS_STATICDEFAULT,
44 SFX_ITEMS_POOLDEFAULT
47 #define SFX_ITEMS_OLD_MAXREF 0xffef
48 #define SFX_ITEMS_MAXREF 0xfffffffe
49 #define SFX_ITEMS_SPECIAL 0xffffffff
51 #define CONVERT_TWIPS 0x80 // Uno conversion for measurement (for MemberId)
55 // UNO3 shortcuts
57 // warning, if there is no boolean inside the any this will always return the value false
58 inline bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
60 bool nValue = false;
61 if( rValue.hasValue() )
63 if( rValue.getValueType() == cppu::UnoType<bool>::get() )
65 nValue = *static_cast<sal_Bool const *>(rValue.getValue());
67 else
69 sal_Int32 nNum = 0;
70 if( rValue >>= nNum )
71 nValue = nNum != 0;
75 return nValue;
78 inline ::com::sun::star::uno::Any Bool2Any( bool bValue )
80 return ::com::sun::star::uno::Any( &bValue, cppu::UnoType<bool>::get() );
83 enum SfxMapUnit
85 SFX_MAPUNIT_100TH_MM,
86 SFX_MAPUNIT_10TH_MM,
87 SFX_MAPUNIT_MM,
88 SFX_MAPUNIT_CM,
89 SFX_MAPUNIT_1000TH_INCH,
90 SFX_MAPUNIT_100TH_INCH,
91 SFX_MAPUNIT_10TH_INCH,
92 SFX_MAPUNIT_INCH,
93 SFX_MAPUNIT_POINT,
94 SFX_MAPUNIT_TWIP,
95 SFX_MAPUNIT_PIXEL,
96 SFX_MAPUNIT_SYSFONT,
97 SFX_MAPUNIT_APPFONT,
98 SFX_MAPUNIT_RELATIVE,
99 SFX_MAPUNIT_ABSOLUTE
104 enum SfxItemPresentation
107 * The values of this enum describe the degree of textual
108 * representation of an item after calling the virtual
109 * method <SfxPoolItem::GetPresentation()const>.
112 SFX_ITEM_PRESENTATION_NAMELESS,
113 SFX_ITEM_PRESENTATION_COMPLETE
117 * These values have to match the values in the
118 * com::sun::star::frame::status::ItemState IDL
119 * to be found at offapi/com/sun/star/frame/status/ItemState.idl
121 enum class SfxItemState {
123 /** Specifies an unknown state. */
124 UNKNOWN = 0,
126 /** Specifies that the property is currently disabled. */
127 DISABLED = 0x0001,
129 /** Specifies that the property is currently read-only. */
130 READONLY = 0x0002,
132 /** Specifies that the property is currently in a don't care state.
133 * <br/>
134 * This is normally used if a selection provides more than one state
135 * for a property at the same time.
137 DONTCARE = 0x0010,
139 /** Specifies that the property is currently in a default state. */
140 DEFAULT = 0x0020,
142 /** The property has been explicitly set to a given value hence we know
143 * we are not taking the default value.
144 * <br/>
145 * For example, you may want to get the font color and it might either
146 * be the default one or one that has been explicitly set.
148 SET = 0x0030
151 class SvXMLUnitConverter;
152 class SfxItemPool;
153 class SfxItemSet;
158 class SVL_DLLPUBLIC SfxPoolItem
160 friend class SfxItemPool;
161 friend class SfxItemDisruptor_Impl;
162 friend class SfxItemPoolCache;
163 friend class SfxItemSet;
164 friend class SfxVoidItem;
166 mutable sal_uLong m_nRefCount;
167 sal_uInt16 m_nWhich;
168 SfxItemKind m_nKind;
170 private:
171 inline void SetRefCount( sal_uLong n );
172 inline void SetKind( SfxItemKind n );
173 public:
174 inline void AddRef( sal_uLong n = 1 ) const;
175 private:
176 inline sal_uLong ReleaseRef( sal_uLong n = 1 ) const;
178 protected:
179 explicit SfxPoolItem( sal_uInt16 nWhich = 0 );
180 SfxPoolItem( const SfxPoolItem& );
182 public:
183 TYPEINFO();
184 virtual ~SfxPoolItem();
186 void SetWhich( sal_uInt16 nId ) { m_nWhich = nId; }
187 sal_uInt16 Which() const { return m_nWhich; }
188 virtual bool operator==( const SfxPoolItem& ) const = 0;
189 bool operator!=( const SfxPoolItem& rItem ) const
190 { return !(*this == rItem); }
191 virtual int Compare( const SfxPoolItem &rWith ) const;
192 virtual int Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const;
194 /** @return true if it has a valid string representation */
195 virtual bool GetPresentation( SfxItemPresentation ePresentation,
196 SfxMapUnit eCoreMetric,
197 SfxMapUnit ePresentationMetric,
198 OUString &rText,
199 const IntlWrapper * pIntlWrapper = 0 ) const;
201 virtual sal_uInt16 GetVersion( sal_uInt16 nFileFormatVersion ) const;
202 virtual bool ScaleMetrics( long lMult, long lDiv );
203 virtual bool HasMetrics() const;
205 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
206 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 );
208 virtual SfxPoolItem* Create( SvStream &, sal_uInt16 nItemVersion ) const;
209 virtual SvStream& Store( SvStream &, sal_uInt16 nItemVersion ) const;
210 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const = 0;
212 sal_uLong GetRefCount() const { return m_nRefCount; }
213 inline SfxItemKind GetKind() const { return m_nKind; }
214 virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
216 private:
217 SfxPoolItem& operator=( const SfxPoolItem& ) SAL_DELETED_FUNCTION;
222 inline void SfxPoolItem::SetRefCount( sal_uLong n )
224 m_nRefCount = n;
225 m_nKind = SFX_ITEMS_NONE;
228 inline void SfxPoolItem::SetKind( SfxItemKind n )
230 m_nRefCount = SFX_ITEMS_SPECIAL;
231 m_nKind = n;
234 inline void SfxPoolItem::AddRef( sal_uLong n ) const
236 DBG_ASSERT(m_nRefCount <= SFX_ITEMS_MAXREF, "AddRef with non-Pool-Item");
237 DBG_ASSERT(ULONG_MAX - m_nRefCount > n, "AddRef: refcount overflow");
238 m_nRefCount += n;
241 inline sal_uLong SfxPoolItem::ReleaseRef( sal_uLong n ) const
243 DBG_ASSERT(m_nRefCount <= SFX_ITEMS_MAXREF, "AddRef with non-Pool-Item");
244 DBG_ASSERT(m_nRefCount >= n, "AddRef: refcount underflow");
245 m_nRefCount -= n;
246 return m_nRefCount;
251 inline bool IsPoolDefaultItem(const SfxPoolItem *pItem )
253 return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
256 inline bool IsStaticDefaultItem(const SfxPoolItem *pItem )
258 return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
261 inline bool IsDefaultItem( const SfxPoolItem *pItem )
263 return pItem && (pItem->GetKind() == SFX_ITEMS_STATICDEFAULT || pItem->GetKind() == SFX_ITEMS_POOLDEFAULT);
266 inline bool IsPooledItem( const SfxPoolItem *pItem )
268 return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
271 inline bool IsInvalidItem(const SfxPoolItem *pItem)
273 return pItem == reinterpret_cast<SfxPoolItem *>(-1);
278 class SVL_DLLPUBLIC SfxVoidItem: public SfxPoolItem
280 SfxVoidItem & operator=( const SfxVoidItem& ) SAL_DELETED_FUNCTION;
281 public:
282 TYPEINFO_OVERRIDE();
283 explicit SfxVoidItem( sal_uInt16 nWhich );
284 SfxVoidItem( sal_uInt16 nWhich, SvStream & );
285 SfxVoidItem( const SfxVoidItem& );
286 virtual ~SfxVoidItem();
288 virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
290 virtual bool GetPresentation( SfxItemPresentation ePres,
291 SfxMapUnit eCoreMetric,
292 SfxMapUnit ePresMetric,
293 OUString &rText,
294 const IntlWrapper * = 0 ) const SAL_OVERRIDE;
296 // create a copy of itself
297 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE;
298 void SetWhich(sal_uInt16 nWh) { m_nWhich = nWh; }
303 class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
305 SfxItemSet *pSet;
307 SfxSetItem & operator=( const SfxSetItem& ) SAL_DELETED_FUNCTION;
309 public:
310 TYPEINFO_OVERRIDE();
311 SfxSetItem( sal_uInt16 nWhich, SfxItemSet *pSet );
312 SfxSetItem( sal_uInt16 nWhich, const SfxItemSet &rSet );
313 SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = 0 );
314 virtual ~SfxSetItem();
316 virtual bool operator==( const SfxPoolItem& ) const SAL_OVERRIDE;
318 virtual bool GetPresentation( SfxItemPresentation ePres,
319 SfxMapUnit eCoreMetric,
320 SfxMapUnit ePresMetric,
321 OUString &rText,
322 const IntlWrapper * = 0 ) const SAL_OVERRIDE;
324 // create a copy of itself
325 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const SAL_OVERRIDE = 0;
326 virtual SfxPoolItem* Create(SvStream &, sal_uInt16 nVersion) const SAL_OVERRIDE = 0;
327 virtual SvStream& Store(SvStream &, sal_uInt16 nVer) const SAL_OVERRIDE;
329 const SfxItemSet& GetItemSet() const
330 { return *pSet; }
331 SfxItemSet& GetItemSet()
332 { return *pSet; }
336 class SVL_DLLPUBLIC SfxPoolItemHint: public SfxHint
338 SfxPoolItem* pObj;
339 public:
340 explicit SfxPoolItemHint( SfxPoolItem* Object ) : pObj(Object) {}
341 virtual ~SfxPoolItemHint() {}
342 SfxPoolItem* GetObject() const { return pObj; }
347 #endif // INCLUDED_SVL_POOLITEM_HXX
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */