sync master with lastest vba changes
[ooovba.git] / binfilter / inc / bf_svtools / poolitem.hxx
blob7d246eceef1ff46c136297a848d804d9d99e0a8b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: poolitem.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SFXPOOLITEM_HXX
31 #define _SFXPOOLITEM_HXX
33 #include <com/sun/star/uno/Any.hxx>
35 #define TF_POOLABLE
37 #include <sal/config.h>
38 #include <tools/rtti.hxx>
39 #include <limits.h>
40 #include <tools/solar.h>
41 #include <tools/debug.hxx>
42 #include <tools/string.hxx>
43 #include <bf_svtools/svarray.hxx>
44 #include <bf_svtools/hint.hxx>
46 class SbxObject;
48 class SvStream;
49 class Color;
50 class IntlWrapper;
52 namespace binfilter
54 typedef long SfxArgumentError;
56 #define SFX_ITEMS_DIRECT 0xffff
57 #define SFX_ITEMS_NULL 0xfff0 // anstelle StoreSurrogate
59 #define SFX_ITEMS_POOLDEFAULT 0xffff
60 #define SFX_ITEMS_STATICDEFAULT 0xfffe
61 #define SFX_ITEMS_DELETEONIDLE 0xfffd
63 #define SFX_ITEMS_OLD_MAXREF 0xffef
64 #define SFX_ITEMS_MAXREF 0xfffffffe
65 #define SFX_ITEMS_SPECIAL 0xffffffff
67 #define CONVERT_TWIPS 0x80 //Uno-Konvertierung fuer Massangaben (fuer MemberId)
69 // -----------------------------------------------------------------------
71 // UNO3 shortcuts
73 // warning, if there is no boolean inside the any this will always return the value false
74 inline sal_Bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
76 sal_Bool nValue = sal_False;
77 if( rValue.hasValue() )
79 if( rValue.getValueType() == ::getCppuBooleanType() )
81 nValue = *(sal_Bool*)rValue.getValue();
83 else
85 sal_Int32 nNum = 0;
86 if( rValue >>= nNum )
87 nValue = nNum != 0;
91 return nValue;
94 inline ::com::sun::star::uno::Any Bool2Any( sal_Bool bValue )
96 return ::com::sun::star::uno::Any( &bValue, ::getCppuBooleanType() );
99 // -----------------------------------------------------------------------
101 //! Notloesung!!!
102 enum SfxFieldUnit
104 SFX_FUNIT_NONE, SFX_FUNIT_MM, SFX_FUNIT_CM, SFX_FUNIT_M, SFX_FUNIT_KM,
105 SFX_FUNIT_TWIP, SFX_FUNIT_POINT, SFX_FUNIT_PICA,
106 SFX_FUNIT_INCH, SFX_FUNIT_FOOT, SFX_FUNIT_MILE, SFX_FUNIT_CUSTOM
109 enum SfxMapUnit
111 SFX_MAPUNIT_100TH_MM,
112 SFX_MAPUNIT_10TH_MM,
113 SFX_MAPUNIT_MM,
114 SFX_MAPUNIT_CM,
115 SFX_MAPUNIT_1000TH_INCH,
116 SFX_MAPUNIT_100TH_INCH,
117 SFX_MAPUNIT_10TH_INCH,
118 SFX_MAPUNIT_INCH,
119 SFX_MAPUNIT_POINT,
120 SFX_MAPUNIT_TWIP,
121 SFX_MAPUNIT_PIXEL,
122 SFX_MAPUNIT_SYSFONT,
123 SFX_MAPUNIT_APPFONT,
124 SFX_MAPUNIT_RELATIVE,
125 SFX_MAPUNIT_ABSOLUTE
128 // -----------------------------------------------------------------------
130 enum SfxItemPresentation
132 /* [Beschreibung]
134 Die Werte dieses Enums bezeichnen den Grad der textuellen
135 Presentation eines Items nach Aufruf der virtuellen Methode
136 <SfxPoolItem::GetPresentation()const>.
140 SFX_ITEM_PRESENTATION_NONE,
141 SFX_ITEM_PRESENTATION_NAMEONLY,
142 SFX_ITEM_PRESENTATION_NAMELESS,
143 SFX_ITEM_PRESENTATION_COMPLETE
146 // -----------------------------------------------------------------------
148 typedef USHORT SfxItemState;
150 #define SFX_ITEM_UNKNOWN 0x0000
152 #define SFX_ITEM_DISABLED 0x0001
153 #define SFX_ITEM_READONLY 0x0002
155 #define SFX_ITEM_DONTCARE 0x0010
156 #define SFX_ITEM_DEFAULT 0x0020
157 #define SFX_ITEM_SET 0x0030
159 // old stuff - dont use!!!
160 #define SFX_ITEM_AVAILABLE SFX_ITEM_DEFAULT
161 #define SFX_ITEM_OFF SFX_ITEM_DEFAULT
162 #define SFX_ITEM_ON SFX_ITEM_SET
164 DBG_NAMEEX_VISIBILITY(SfxPoolItem, )
165 DBG_NAMEEX(SfxVoidItem)
167 class SvXMLUnitConverter;
168 class SfxItemPool;
169 class SfxItemSet;
171 // -----------------------------------------------------------------------
173 class SfxPoolItem
175 friend class SfxItemPool;
176 friend class SfxItemPoolCache;
177 friend class SfxItemSet;
178 friend class SfxVoidItem;
180 ULONG nRefCount; // Referenzzaehler
181 USHORT nWhich;
182 USHORT nKind;
184 private:
185 inline void SetRefCount( ULONG n );
186 inline void SetKind( USHORT n );
187 public:
188 inline ULONG AddRef( ULONG n = 1 ) const;
189 private:
190 inline ULONG ReleaseRef( ULONG n = 1 ) const;
191 long Delete_Impl(void*);
193 protected:
194 SfxPoolItem( USHORT nWhich = 0 );
195 SfxPoolItem( const SfxPoolItem& );
197 public:
198 TYPEINFO();
199 virtual ~SfxPoolItem();
201 void SetWhich( USHORT nId ) {
202 DBG_CHKTHIS(SfxPoolItem, 0);
203 nWhich = nId; }
204 USHORT Which() const {
205 DBG_CHKTHIS(SfxPoolItem, 0);
206 return nWhich; }
207 virtual int operator==( const SfxPoolItem& ) const = 0;
208 int operator!=( const SfxPoolItem& rItem ) const
209 { return !(*this == rItem); }
210 virtual int Compare( const SfxPoolItem &rWith ) const;
211 virtual int Compare( const SfxPoolItem &rWith, const ::IntlWrapper& rIntlWrapper ) const;
213 virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePresentation,
214 SfxMapUnit eCoreMetric,
215 SfxMapUnit ePresentationMetric,
216 XubString &rText,
217 const ::IntlWrapper * pIntlWrapper = 0 ) const;
219 virtual USHORT GetVersion( USHORT nFileFormatVersion ) const;
220 virtual int ScaleMetrics( long lMult, long lDiv );
221 virtual int HasMetrics() const;
223 virtual BOOL QueryValue( ::com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 ) const;
224 virtual BOOL PutValue( const ::com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 );
226 virtual SfxPoolItem* Create( SvStream &, USHORT nItemVersion ) const;
227 virtual SvStream& Store( SvStream &, USHORT nItemVersion ) const;
228 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const = 0;
230 ULONG GetRefCount() const { return nRefCount; }
231 inline USHORT GetKind() const { return nKind; }
233 /** Read in a Unicode string from a streamed byte string representation.
235 @param rStream Some (input) stream. Its Stream/TargetCharSets must
236 be set to correct values!
238 @param rString On success, returns the reconstructed Unicode string.
240 @return True if the string was successfuly read and reconstructed.
242 static bool readByteString(SvStream & rStream, UniString & rString);
244 /** Write a byte string representation of a Unicode string into a stream.
246 @param rStream Some (output) stream. Its Stream/TargetCharSets must
247 be set to correct values!
249 @param rString Some Unicode string.
251 static void writeByteString(SvStream & rStream,
252 UniString const & rString);
254 /** Read in a Unicode string from either a streamed Unicode or byte string
255 representation.
257 @param rStream Some (input) stream. If bUnicode is false, its
258 Stream/TargetCharSets must be set to correct values!
260 @param rString On success, returns the reconstructed Unicode string.
262 @param bUnicode Whether to read in a stream Unicode (true) or byte
263 string (false) representation.
265 @return True if the string was successfuly read and reconstructed.
267 static bool readUnicodeString(SvStream & rStream, UniString & rString,
268 bool bUnicode);
270 /** Write a Unicode string representation of a Unicode string into a
271 stream.
273 @param rStream Some (output) stream.
275 @param rString Some Unicode string.
277 static void writeUnicodeString(SvStream & rStream,
278 UniString const & rString);
280 private:
281 SfxPoolItem& operator=( const SfxPoolItem& ); // n.i.!!
284 // -----------------------------------------------------------------------
286 inline void SfxPoolItem::SetRefCount( ULONG n )
288 DBG_CHKTHIS( SfxPoolItem, 0 );
289 nRefCount = n;
290 nKind = 0;
293 inline void SfxPoolItem::SetKind( USHORT n )
295 DBG_CHKTHIS( SfxPoolItem, 0 );
296 nRefCount = SFX_ITEMS_SPECIAL;
297 nKind = n;
300 inline ULONG SfxPoolItem::AddRef( ULONG n ) const
302 DBG_CHKTHIS( SfxPoolItem, 0 );
303 DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
304 DBG_ASSERT( ULONG_MAX - nRefCount > n, "AddRef: Referenzzaehler ueberschlaegt sich" );
305 return ( ((SfxPoolItem *)this)->nRefCount += n );
308 inline ULONG SfxPoolItem::ReleaseRef( ULONG n ) const
310 DBG_CHKTHIS( SfxPoolItem, 0 );
311 DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
312 DBG_ASSERT( nRefCount >= n, "ReleaseRef: Referenzzaehler ueberschlaegt sich" );
313 ((SfxPoolItem *)this)->nRefCount -= n;
314 return nRefCount;
317 // -----------------------------------------------------------------------
319 inline int IsPoolDefaultItem(const SfxPoolItem *pItem )
321 return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
324 inline int IsStaticDefaultItem(const SfxPoolItem *pItem )
326 return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
329 inline int IsDefaultItem( const SfxPoolItem *pItem )
331 return pItem && pItem->GetKind() >= SFX_ITEMS_STATICDEFAULT;
334 inline int IsPooledItem( const SfxPoolItem *pItem )
336 return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
339 inline int IsInvalidItem(const SfxPoolItem *pItem)
341 return pItem == (SfxPoolItem *)-1;
344 // -----------------------------------------------------------------------
346 class SfxVoidItem: public SfxPoolItem
348 SfxVoidItem & operator=( const SfxVoidItem& ); // not implemented.
349 public:
350 TYPEINFO();
351 SfxVoidItem( USHORT nWhich );
352 SfxVoidItem( USHORT nWhich, SvStream & );
353 SfxVoidItem( const SfxVoidItem& );
354 ~SfxVoidItem();
356 virtual int operator==( const SfxPoolItem& ) const;
358 virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
359 SfxMapUnit eCoreMetric,
360 SfxMapUnit ePresMetric,
361 XubString &rText,
362 const ::IntlWrapper * = 0 ) const;
364 // von sich selbst eine Kopie erzeugen
365 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const;
366 void SetWhich(USHORT nWh) { nWhich = nWh; }
369 // -----------------------------------------------------------------------
371 class SfxSetItem: public SfxPoolItem
373 SfxItemSet *pSet;
375 SfxSetItem & operator=( const SfxSetItem& ); // not implemented.
377 public:
378 TYPEINFO();
379 SfxSetItem( USHORT nWhich, SfxItemSet *pSet );
380 SfxSetItem( USHORT nWhich, const SfxItemSet &rSet );
381 SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = 0 );
382 ~SfxSetItem();
384 virtual int operator==( const SfxPoolItem& ) const;
386 virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
387 SfxMapUnit eCoreMetric,
388 SfxMapUnit ePresMetric,
389 XubString &rText,
390 const ::IntlWrapper * = 0 ) const;
392 // von sich selbst eine Kopie erzeugen
393 virtual SfxPoolItem* Clone( SfxItemPool *pPool = 0 ) const = 0;
394 virtual SfxPoolItem* Create(SvStream &, USHORT nVersion) const = 0;
395 virtual SvStream& Store(SvStream &, USHORT nVer) const;
397 const SfxItemSet& GetItemSet() const
398 { return *pSet; }
399 SfxItemSet& GetItemSet()
400 { return *pSet; }
403 // -----------------------------------------------------------------------
405 DECL_PTRHINT(, SfxPoolItemHint, SfxPoolItem);
409 #endif // #ifndef _SFXPOOLITEM_HXX