1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <tools/solar.h>
29 #include <tools/debug.hxx>
30 #include <svl/hint.hxx>
38 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{ class Any
; } } } }
42 SFX_ITEMS_DELETEONIDLE
,
43 SFX_ITEMS_STATICDEFAULT
,
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)
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
)
61 if( rValue
.hasValue() )
63 if( rValue
.getValueType() == cppu::UnoType
<bool>::get() )
65 nValue
= *static_cast<sal_Bool
const *>(rValue
.getValue());
78 inline ::com::sun::star::uno::Any
Bool2Any( bool bValue
)
80 return ::com::sun::star::uno::Any( &bValue
, cppu::UnoType
<bool>::get() );
89 SFX_MAPUNIT_1000TH_INCH
,
90 SFX_MAPUNIT_100TH_INCH
,
91 SFX_MAPUNIT_10TH_INCH
,
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. */
126 /** Specifies that the property is currently disabled. */
129 /** Specifies that the property is currently read-only. */
132 /** Specifies that the property is currently in a don't care state.
134 * This is normally used if a selection provides more than one state
135 * for a property at the same time.
139 /** Specifies that the property is currently in a default state. */
142 /** The property has been explicitly set to a given value hence we know
143 * we are not taking the default value.
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.
151 class SvXMLUnitConverter
;
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
;
171 inline void SetRefCount( sal_uLong n
);
172 inline void SetKind( SfxItemKind n
);
174 inline void AddRef( sal_uLong n
= 1 ) const;
176 inline sal_uLong
ReleaseRef( sal_uLong n
= 1 ) const;
179 explicit SfxPoolItem( sal_uInt16 nWhich
= 0 );
180 SfxPoolItem( const SfxPoolItem
& );
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
,
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;
217 SfxPoolItem
& operator=( const SfxPoolItem
& ) SAL_DELETED_FUNCTION
;
222 inline void SfxPoolItem::SetRefCount( sal_uLong n
)
225 m_nKind
= SFX_ITEMS_NONE
;
228 inline void SfxPoolItem::SetKind( SfxItemKind n
)
230 m_nRefCount
= SFX_ITEMS_SPECIAL
;
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");
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");
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
;
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
,
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
307 SfxSetItem
& operator=( const SfxSetItem
& ) SAL_DELETED_FUNCTION
;
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
,
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
331 SfxItemSet
& GetItemSet()
336 class SVL_DLLPUBLIC SfxPoolItemHint
: public SfxHint
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: */