xref: /trunk/main/svl/inc/svl/poolitem.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SFXPOOLITEM_HXX
24 #define _SFXPOOLITEM_HXX
25 
26 #include "svl/svldllapi.h"
27 #include <com/sun/star/uno/Any.hxx>
28 
29 #define TF_POOLABLE
30 #include <sal/config.h>
31 #include <tools/rtti.hxx>
32 #include <limits.h>
33 #include <tools/solar.h>
34 #include <tools/debug.hxx>
35 #include <tools/string.hxx>
36 #include <svl/svarray.hxx>
37 #include <svl/hint.hxx>
38 
39 typedef long SfxArgumentError;
40 
41 class SbxVariable;
42 class SbxObject;
43 class SvStream;
44 class Color;
45 class IntlWrapper;
46 
47 namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
48 
49 static const sal_uInt32 SFX_ITEMS_DIRECT=   0xffffffff;
50 static const sal_uInt32 SFX_ITEMS_NULL=     0xfffffff0;  // instead StoreSurrogate
51 static const sal_uInt32 SFX_ITEMS_DEFAULT=  0xfffffffe;
52 
53 #define SFX_ITEMS_POOLDEFAULT               0xffff
54 #define SFX_ITEMS_STATICDEFAULT             0xfffe
55 #define SFX_ITEMS_DELETEONIDLE              0xfffd
56 
57 #define SFX_ITEMS_OLD_MAXREF                0xffef
58 #define SFX_ITEMS_MAXREF                    0xfffffffe
59 #define SFX_ITEMS_SPECIAL                   0xffffffff
60 
61 #define CONVERT_TWIPS                       0x80    //Uno-Konvertierung fuer Massangaben (fuer MemberId)
62 
63 // -----------------------------------------------------------------------
64 
65 // UNO3 shortcuts
66 
67 // warning, if there is no boolean inside the any this will always return the value false
Any2Bool(const::com::sun::star::uno::Any & rValue)68 inline sal_Bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
69 {
70     sal_Bool nValue = sal_False;
71     if( rValue.hasValue() )
72     {
73         if( rValue.getValueType() == ::getCppuBooleanType() )
74         {
75             nValue = *(sal_Bool*)rValue.getValue();
76         }
77         else
78         {
79             sal_Int32 nNum = 0;
80             if( rValue >>= nNum )
81                 nValue = nNum != 0;
82         }
83     }
84 
85     return nValue;
86 }
87 
Bool2Any(sal_Bool bValue)88 inline ::com::sun::star::uno::Any Bool2Any( sal_Bool bValue )
89 {
90     return ::com::sun::star::uno::Any( &bValue, ::getCppuBooleanType() );
91 }
92 
93 // -----------------------------------------------------------------------
94 
95 //! Notloesung!!!
96 enum SfxFieldUnit
97 {
98     SFX_FUNIT_NONE, SFX_FUNIT_MM, SFX_FUNIT_CM, SFX_FUNIT_M, SFX_FUNIT_KM,
99     SFX_FUNIT_TWIP, SFX_FUNIT_POINT, SFX_FUNIT_PICA,
100     SFX_FUNIT_INCH, SFX_FUNIT_FOOT, SFX_FUNIT_MILE, SFX_FUNIT_CUSTOM
101 };
102 
103 enum SfxMapUnit
104 {
105     SFX_MAPUNIT_100TH_MM,
106     SFX_MAPUNIT_10TH_MM,
107     SFX_MAPUNIT_MM,
108     SFX_MAPUNIT_CM,
109     SFX_MAPUNIT_1000TH_INCH,
110     SFX_MAPUNIT_100TH_INCH,
111     SFX_MAPUNIT_10TH_INCH,
112     SFX_MAPUNIT_INCH,
113     SFX_MAPUNIT_POINT,
114     SFX_MAPUNIT_TWIP,
115     SFX_MAPUNIT_PIXEL,
116     SFX_MAPUNIT_SYSFONT,
117     SFX_MAPUNIT_APPFONT,
118     SFX_MAPUNIT_RELATIVE,
119     SFX_MAPUNIT_ABSOLUTE
120 };
121 
122 // -----------------------------------------------------------------------
123 
124 enum SfxItemPresentation
125 
126 /*  [Beschreibung]
127 
128     Die Werte dieses Enums bezeichnen den Grad der textuellen
129     Presentation eines Items nach Aufruf der virtuellen Methode
130     <SfxPoolItem::GetPresentation()const>.
131 */
132 
133 {
134     SFX_ITEM_PRESENTATION_NONE,
135     SFX_ITEM_PRESENTATION_NAMEONLY,
136     SFX_ITEM_PRESENTATION_NAMELESS,
137     SFX_ITEM_PRESENTATION_COMPLETE
138 };
139 
140 // -----------------------------------------------------------------------
141 
142 typedef sal_uInt16 SfxItemState;
143 
144 #define SFX_ITEM_UNKNOWN    0x0000
145 
146 #define SFX_ITEM_DISABLED   0x0001
147 #define SFX_ITEM_READONLY   0x0002
148 
149 #define SFX_ITEM_DONTCARE   0x0010
150 #define SFX_ITEM_DEFAULT    0x0020
151 #define SFX_ITEM_SET        0x0030
152 
153 // old stuff - dont use!!!
154 #define SFX_ITEM_AVAILABLE  SFX_ITEM_DEFAULT
155 #define SFX_ITEM_OFF        SFX_ITEM_DEFAULT
156 #define SFX_ITEM_ON         SFX_ITEM_SET
157 
158 DBG_NAMEEX_VISIBILITY(SfxPoolItem, SVL_DLLPUBLIC)
159 DBG_NAMEEX(SfxVoidItem)
160 DBG_NAMEEX(SfxItemHandle)
161 
162 class SvXMLUnitConverter;
163 class SfxItemPool;
164 class SfxItemSet;
165 
166 class String;
167 namespace rtl
168 {
169     class OUString;
170 }
171 
172 // -----------------------------------------------------------------------
173 
174 class SVL_DLLPUBLIC SfxPoolItem
175 {
176 friend class SfxItemPool;
177 friend class SfxItemDesruptor_Impl;
178 friend class SfxItemPoolCache;
179 friend class SfxItemSet;
180 friend class SfxVoidItem;
181 
182     sal_uLong                    nRefCount;                    // Referenzzaehler
183     sal_uInt16                   nWhich;
184     sal_uInt16                   nKind;
185 
186 private:
187     inline void              SetRefCount( sal_uLong n );
188     inline void              SetKind( sal_uInt16 n );
189 public:
190     inline sal_uLong             AddRef( sal_uLong n = 1 ) const;
191     inline sal_uLong             ReleaseRef( sal_uLong n = 1 ) const;
192 private:
193     SVL_DLLPRIVATE long      Delete_Impl(void*);
194 
195 #if 0
196     // @@@ virtual, but private, and dummy impl. @@@
197     virtual void             Store( SvStream & ) const;
198     virtual void             GetVersion() const;
199 #endif
200 
201 protected:
202                              SfxPoolItem( sal_uInt16 nWhich = 0 );
203                              SfxPoolItem( const SfxPoolItem& );
204 
205 public:
206                              TYPEINFO();
207     virtual                  ~SfxPoolItem();
208 
SetWhich(sal_uInt16 nId)209     void                     SetWhich( sal_uInt16 nId ) {
210                                 DBG_CHKTHIS(SfxPoolItem, 0);
211                                 nWhich = nId; }
Which() const212     sal_uInt16                   Which() const {
213                                  DBG_CHKTHIS(SfxPoolItem, 0);
214                                  return nWhich; }
215     virtual int              operator==( const SfxPoolItem& ) const = 0;
operator !=(const SfxPoolItem & rItem) const216     int                      operator!=( const SfxPoolItem& rItem ) const
217                              { return !(*this == rItem); }
218     virtual int              Compare( const SfxPoolItem &rWith ) const;
219     virtual int              Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const;
220 
221     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePresentation,
222                                     SfxMapUnit eCoreMetric,
223                                     SfxMapUnit ePresentationMetric,
224                                     XubString &rText,
225                                     const IntlWrapper * pIntlWrapper = 0 ) const;
226 
227     virtual sal_uInt16           GetVersion( sal_uInt16 nFileFormatVersion ) const;
228     virtual int              ScaleMetrics( long lMult, long lDiv );
229     virtual int              HasMetrics() const;
230 
231     virtual sal_Bool             QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
232     virtual sal_Bool             PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 );
233 
234     virtual SfxPoolItem*     Create( SvStream &, sal_uInt16 nItemVersion ) const;
235     virtual SvStream&        Store( SvStream &, sal_uInt16 nItemVersion ) const;
236     virtual SfxPoolItem*     Clone( SfxItemPool *pPool = 0 ) const = 0;
237 
GetRefCount() const238     sal_uLong                    GetRefCount() const { return nRefCount; }
GetKind() const239     inline sal_uInt16            GetKind() const { return nKind; }
240 
241     /** Read in a Unicode string from a streamed byte string representation.
242 
243         @param rStream  Some (input) stream.  Its Stream/TargetCharSets must
244         be set to correct values!
245 
246         @param rString  On success, returns the reconstructed Unicode string.
247 
248         @return  True if the string was successfully read and reconstructed.
249      */
250     static bool readByteString(SvStream & rStream, UniString & rString);
251 
252     /** Write a byte string representation of a Unicode string into a stream.
253 
254         @param rStream  Some (output) stream.  Its Stream/TargetCharSets must
255         be set to correct values!
256 
257         @param rString  Some Unicode string.
258      */
259     static void writeByteString(SvStream & rStream,
260                                 UniString const & rString);
261 
262     /** Read in a Unicode string from either a streamed Unicode or byte string
263         representation.
264 
265         @param rStream  Some (input) stream.  If bUnicode is false, its
266         Stream/TargetCharSets must be set to correct values!
267 
268         @param rString  On success, returns the reconstructed Unicode string.
269 
270         @param bUnicode  Whether to read in a stream Unicode (true) or byte
271         string (false) representation.
272 
273         @return  True if the string was successfully read and reconstructed.
274      */
275     static bool readUnicodeString(SvStream & rStream, UniString & rString,
276                                   bool bUnicode);
277 
278     /** Write a Unicode string representation of a Unicode string into a
279         stream.
280 
281         @param rStream  Some (output) stream.
282 
283         @param rString  Some Unicode string.
284      */
285     static void writeUnicodeString(SvStream & rStream,
286                                    UniString const & rString);
287 
288 private:
289     SfxPoolItem&             operator=( const SfxPoolItem& );    // n.i.!!
290 };
291 
292 // -----------------------------------------------------------------------
293 
SetRefCount(sal_uLong n)294 inline void SfxPoolItem::SetRefCount( sal_uLong n )
295 {
296     DBG_CHKTHIS( SfxPoolItem, 0 );
297     nRefCount = n;
298     nKind = 0;
299 }
300 
SetKind(sal_uInt16 n)301 inline void SfxPoolItem::SetKind( sal_uInt16 n )
302 {
303     DBG_CHKTHIS( SfxPoolItem, 0 );
304     nRefCount = SFX_ITEMS_SPECIAL;
305     nKind = n;
306 }
307 
AddRef(sal_uLong n) const308 inline sal_uLong SfxPoolItem::AddRef( sal_uLong n ) const
309 {
310     DBG_CHKTHIS( SfxPoolItem, 0 );
311     DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
312     DBG_ASSERT( ULONG_MAX - nRefCount > n, "AddRef: Referenzzaehler ueberschlaegt sich" );
313     return ( ((SfxPoolItem *)this)->nRefCount += n );
314 }
315 
ReleaseRef(sal_uLong n) const316 inline sal_uLong SfxPoolItem::ReleaseRef( sal_uLong n ) const
317 {
318     DBG_CHKTHIS( SfxPoolItem, 0 );
319     DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
320     DBG_ASSERT( nRefCount >= n, "ReleaseRef: Referenzzaehler ueberschlaegt sich" );
321     ((SfxPoolItem *)this)->nRefCount -= n;
322     return nRefCount;
323 }
324 
325 // -----------------------------------------------------------------------
326 
IsPoolDefaultItem(const SfxPoolItem * pItem)327 inline int IsPoolDefaultItem(const SfxPoolItem *pItem )
328 {
329     return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
330 }
331 
IsStaticDefaultItem(const SfxPoolItem * pItem)332 inline int IsStaticDefaultItem(const SfxPoolItem *pItem )
333 {
334     return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
335 }
336 
IsDefaultItem(const SfxPoolItem * pItem)337 inline int IsDefaultItem( const SfxPoolItem *pItem )
338 {
339     return pItem && pItem->GetKind() >= SFX_ITEMS_STATICDEFAULT;
340 }
341 
IsPooledItem(const SfxPoolItem * pItem)342 inline int IsPooledItem( const SfxPoolItem *pItem )
343 {
344     return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
345 }
346 
IsInvalidItem(const SfxPoolItem * pItem)347 inline int IsInvalidItem(const SfxPoolItem *pItem)
348 {
349     return pItem == (SfxPoolItem *)-1;
350 }
351 
352 // -----------------------------------------------------------------------
353 
354 class SVL_DLLPUBLIC SfxVoidItem: public SfxPoolItem
355 {
356     SfxVoidItem & operator=( const SfxVoidItem& ); // not implemented.
357 public:
358                             TYPEINFO();
359                             SfxVoidItem( sal_uInt16 nWhich );
360                             SfxVoidItem( sal_uInt16 nWhich, SvStream & );
361                             SfxVoidItem( const SfxVoidItem& );
362                             ~SfxVoidItem();
363 
364     virtual int             operator==( const SfxPoolItem& ) const;
365 
366     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
367                                     SfxMapUnit eCoreMetric,
368                                     SfxMapUnit ePresMetric,
369                                     XubString &rText,
370                                     const IntlWrapper * = 0 ) const;
371 
372     // von sich selbst eine Kopie erzeugen
373     virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const;
SetWhich(sal_uInt16 nWh)374             void            SetWhich(sal_uInt16 nWh) { nWhich = nWh; }
375 };
376 
377 // -----------------------------------------------------------------------
378 
379 class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
380 {
381     SfxItemSet              *pSet;
382 
383     SfxSetItem & operator=( const SfxSetItem& ); // not implemented.
384 
385 public:
386                             TYPEINFO();
387                             SfxSetItem( sal_uInt16 nWhich, SfxItemSet *pSet );
388                             SfxSetItem( sal_uInt16 nWhich, const SfxItemSet &rSet );
389                             SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = 0 );
390                             ~SfxSetItem();
391 
392     virtual int             operator==( const SfxPoolItem& ) const;
393 
394     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
395                                     SfxMapUnit eCoreMetric,
396                                     SfxMapUnit ePresMetric,
397                                     XubString &rText,
398                                     const IntlWrapper * = 0 ) const;
399 
400     // von sich selbst eine Kopie erzeugen
401     virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const = 0;
402     virtual SfxPoolItem*    Create(SvStream &, sal_uInt16 nVersion) const = 0;
403     virtual SvStream&       Store(SvStream &, sal_uInt16 nVer) const;
404 
GetItemSet() const405     const SfxItemSet&       GetItemSet() const
406                             { return *pSet; }
GetItemSet()407     SfxItemSet&             GetItemSet()
408                             { return *pSet; }
409 };
410 
411 // -----------------------------------------------------------------------
412 
413 #if 0  /* @@@ NOT USED @@@ */
414 class SfxInvalidItem: public SfxPoolItem
415 {
416 friend class SfxItemSet;
417 
418     const SfxPoolItem*      pDefaultItem;
419 
420 private:
421                             TYPEINFO();
422                             SfxInvalidItem( sal_uInt16 nWhich, const SfxPoolItem &rDefault );
423                             SfxInvalidItem( const SfxInvalidItem& );
424     virtual                 ~SfxInvalidItem();
425 
426 public:
427     virtual int             operator==( const SfxPoolItem& ) const;
428 
429     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
430                                     SfxMapUnit eCoreMetric,
431                                     SfxMapUnit ePresMetric,
432                                     XubString &rText,
433                                     const IntlWrapper * = 0 ) const;
434     const SfxPoolItem*      GetDefaultItem() const { return pDefaultItem; }
435 
436     // von sich selbst eine Kopie erzeugen
437     virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const;
438     virtual SfxPoolItem*    Create(SvStream &, sal_uInt16 nVersion) const;
439     virtual SvStream&       Store(SvStream &, sal_uInt16 nVer ) const;
440 };
441 #endif /* @@@ NOT USED @@@ */
442 
443 // -----------------------------------------------------------------------
444 // Handle Klasse fuer PoolItems
445 
446 class SVL_DLLPUBLIC SfxItemHandle
447 {
448     sal_uInt16      *pRef;
449     SfxPoolItem *pItem;
450 public:
451     SfxItemHandle( SfxPoolItem& );
452     SfxItemHandle( const SfxItemHandle& );
453     ~SfxItemHandle();
454 
455     const SfxItemHandle &operator=(const SfxItemHandle &);
GetItem() const456     const SfxPoolItem &GetItem() const { return *pItem; }
457 };
458 
459 // -----------------------------------------------------------------------
460 
461 DECL_PTRHINT(SVL_DLLPUBLIC, SfxPoolItemHint, SfxPoolItem);
462 
463 // -----------------------------------------------------------------------
464 
465 #if 0  /* @@@ NOT USED @@@ */
466 class SfxItemChangedHint: public SfxHint
467 {
468     const SfxPoolItem&  _rOld;
469     const SfxPoolItem&  _rNew;
470 
471 public:
472                         TYPEINFO(); \
473                         SfxItemChangedHint( const SfxPoolItem &rOld,
474                                             const SfxPoolItem &rNew )
475                         :   _rOld( rOld ),
476                             _rNew( rNew )
477                         {}
478 
479     const SfxPoolItem&  GetOldItem() const { return _rOld; }
480     const SfxPoolItem&  GetNewItem() const { return _rNew; }
481 };
482 
483 #endif /* @@@ NOT USED @@@ */
484 
485 #endif // #ifndef _SFXPOOLITEM_HXX
486