summaryrefslogtreecommitdiff
path: root/svl/inc/svl/poolitem.hxx
blob: 498b48d31aac2d6d01174326fb01f7061757c20b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _SFXPOOLITEM_HXX
#define _SFXPOOLITEM_HXX

#include "svl/svldllapi.h"
#include <com/sun/star/uno/Any.hxx>

#define TF_POOLABLE
#include <sal/config.h>
#include <tools/rtti.hxx>
#include <limits.h>
#include <tools/solar.h>
#include <tools/debug.hxx>
#include <tools/string.hxx>
#include <svl/svarray.hxx>
#include <svl/hint.hxx>

typedef long SfxArgumentError;

class SbxVariable;
class SbxObject;
class SvStream;
class Color;
class IntlWrapper;

namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }

#define SFX_ITEMS_DIRECT                    0xffff
#define SFX_ITEMS_NULL                      0xfff0  // anstelle StoreSurrogate

#define SFX_ITEMS_POOLDEFAULT               0xffff
#define SFX_ITEMS_STATICDEFAULT             0xfffe
#define SFX_ITEMS_DELETEONIDLE              0xfffd

#define SFX_ITEMS_OLD_MAXREF                0xffef
#define SFX_ITEMS_MAXREF                    0xfffffffe
#define SFX_ITEMS_SPECIAL                   0xffffffff

#define CONVERT_TWIPS                       0x80    //Uno-Konvertierung fuer Massangaben (fuer MemberId)

// -----------------------------------------------------------------------

// UNO3 shortcuts

// warning, if there is no boolean inside the any this will always return the value false
inline sal_Bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
{
    sal_Bool nValue = sal_False;
    if( rValue.hasValue() )
    {
        if( rValue.getValueType() == ::getCppuBooleanType() )
        {
            nValue = *(sal_Bool*)rValue.getValue();
        }
        else
        {
            sal_Int32 nNum = 0;
            if( rValue >>= nNum )
                nValue = nNum != 0;
        }
    }

    return nValue;
}

inline ::com::sun::star::uno::Any Bool2Any( sal_Bool bValue )
{
    return ::com::sun::star::uno::Any( &bValue, ::getCppuBooleanType() );
}

// -----------------------------------------------------------------------

//! Notloesung!!!
enum SfxFieldUnit
{
    SFX_FUNIT_NONE, SFX_FUNIT_MM, SFX_FUNIT_CM, SFX_FUNIT_M, SFX_FUNIT_KM,
    SFX_FUNIT_TWIP, SFX_FUNIT_POINT, SFX_FUNIT_PICA,
    SFX_FUNIT_INCH, SFX_FUNIT_FOOT, SFX_FUNIT_MILE, SFX_FUNIT_CHAR, SFX_FUNIT_LINE, SFX_FUNIT_CUSTOM
};

enum SfxMapUnit
{
    SFX_MAPUNIT_100TH_MM,
    SFX_MAPUNIT_10TH_MM,
    SFX_MAPUNIT_MM,
    SFX_MAPUNIT_CM,
    SFX_MAPUNIT_1000TH_INCH,
    SFX_MAPUNIT_100TH_INCH,
    SFX_MAPUNIT_10TH_INCH,
    SFX_MAPUNIT_INCH,
    SFX_MAPUNIT_POINT,
    SFX_MAPUNIT_TWIP,
    SFX_MAPUNIT_PIXEL,
    SFX_MAPUNIT_SYSFONT,
    SFX_MAPUNIT_APPFONT,
    SFX_MAPUNIT_RELATIVE,
    SFX_MAPUNIT_ABSOLUTE
};

// -----------------------------------------------------------------------

enum SfxItemPresentation

/*  [Beschreibung]

    Die Werte dieses Enums bezeichnen den Grad der textuellen
    Presentation eines Items nach Aufruf der virtuellen Methode
    <SfxPoolItem::GetPresentation()const>.
*/

{
    SFX_ITEM_PRESENTATION_NONE,
    SFX_ITEM_PRESENTATION_NAMEONLY,
    SFX_ITEM_PRESENTATION_NAMELESS,
    SFX_ITEM_PRESENTATION_COMPLETE
};

// -----------------------------------------------------------------------

typedef USHORT SfxItemState;

#define SFX_ITEM_UNKNOWN    0x0000

#define SFX_ITEM_DISABLED   0x0001
#define SFX_ITEM_READONLY   0x0002

#define SFX_ITEM_DONTCARE   0x0010
#define SFX_ITEM_DEFAULT    0x0020
#define SFX_ITEM_SET        0x0030

// old stuff - dont use!!!
#define SFX_ITEM_AVAILABLE  SFX_ITEM_DEFAULT
#define SFX_ITEM_OFF        SFX_ITEM_DEFAULT
#define SFX_ITEM_ON         SFX_ITEM_SET

DBG_NAMEEX_VISIBILITY(SfxPoolItem, SVL_DLLPUBLIC)
DBG_NAMEEX(SfxVoidItem)
DBG_NAMEEX(SfxItemHandle)

class SvXMLUnitConverter;
class SfxItemPool;
class SfxItemSet;

class String;
namespace rtl
{
    class OUString;
}

// -----------------------------------------------------------------------

class SVL_DLLPUBLIC SfxPoolItem
{
friend class SfxItemPool;
friend class SfxItemDesruptor_Impl;
friend class SfxItemPoolCache;
friend class SfxItemSet;
friend class SfxVoidItem;

    ULONG                    nRefCount;                    // Referenzzaehler
    USHORT                   nWhich;
    USHORT                   nKind;

private:
    inline void              SetRefCount( ULONG n );
    inline void              SetKind( USHORT n );
public:
    inline ULONG             AddRef( ULONG n = 1 ) const;
private:
    inline ULONG             ReleaseRef( ULONG n = 1 ) const;
    SVL_DLLPRIVATE long      Delete_Impl(void*);

#if 0
    // @@@ virtual, but private, and dummy impl. @@@
    virtual void             Store( SvStream & ) const;
    virtual void             GetVersion() const;
#endif

protected:
                             SfxPoolItem( USHORT nWhich = 0 );
                             SfxPoolItem( const SfxPoolItem& );

public:
                             TYPEINFO();
    virtual                  ~SfxPoolItem();

    void                     SetWhich( USHORT nId ) {
                                DBG_CHKTHIS(SfxPoolItem, 0);
                                nWhich = nId; }
    USHORT                   Which() const {
                                 DBG_CHKTHIS(SfxPoolItem, 0);
                                 return nWhich; }
    virtual int              operator==( const SfxPoolItem& ) const = 0;
    int                      operator!=( const SfxPoolItem& rItem ) const
                             { return !(*this == rItem); }
    virtual int              Compare( const SfxPoolItem &rWith ) const;
    virtual int              Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const;

    virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePresentation,
                                    SfxMapUnit eCoreMetric,
                                    SfxMapUnit ePresentationMetric,
                                    XubString &rText,
                                    const IntlWrapper * pIntlWrapper = 0 ) const;

    virtual USHORT           GetVersion( USHORT nFileFormatVersion ) const;
    virtual int              ScaleMetrics( long lMult, long lDiv );
    virtual int              HasMetrics() const;

    virtual BOOL             QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 ) const;
    virtual BOOL             PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 );

    virtual SfxPoolItem*     Create( SvStream &, USHORT nItemVersion ) const;
    virtual SvStream&        Store( SvStream &, USHORT nItemVersion ) const;
    virtual SfxPoolItem*     Clone( SfxItemPool *pPool = 0 ) const = 0;

    ULONG                    GetRefCount() const { return nRefCount; }
    inline USHORT            GetKind() const { return nKind; }

    /** Read in a Unicode string from a streamed byte string representation.

        @param rStream  Some (input) stream.  Its Stream/TargetCharSets must
        be set to correct values!

        @param rString  On success, returns the reconstructed Unicode string.

        @return  True if the string was successfuly read and reconstructed.
     */
    static bool readByteString(SvStream & rStream, UniString & rString);

    /** Write a byte string representation of a Unicode string into a stream.

        @param rStream  Some (output) stream.  Its Stream/TargetCharSets must
        be set to correct values!

        @param rString  Some Unicode string.
     */
    static void writeByteString(SvStream & rStream,
                                UniString const & rString);

    /** Read in a Unicode string from either a streamed Unicode or byte string
        representation.

        @param rStream  Some (input) stream.  If bUnicode is false, its
        Stream/TargetCharSets must be set to correct values!

        @param rString  On success, returns the reconstructed Unicode string.

        @param bUnicode  Whether to read in a stream Unicode (true) or byte
        string (false) representation.

        @return  True if the string was successfuly read and reconstructed.
     */
    static bool readUnicodeString(SvStream & rStream, UniString & rString,
                                  bool bUnicode);

    /** Write a Unicode string representation of a Unicode string into a
        stream.

        @param rStream  Some (output) stream.

        @param rString  Some Unicode string.
     */
    static void writeUnicodeString(SvStream & rStream,
                                   UniString const & rString);

private:
    SfxPoolItem&             operator=( const SfxPoolItem& );    // n.i.!!
};

// -----------------------------------------------------------------------

inline void SfxPoolItem::SetRefCount( ULONG n )
{
    DBG_CHKTHIS( SfxPoolItem, 0 );
    nRefCount = n;
    nKind = 0;
}

inline void SfxPoolItem::SetKind( USHORT n )
{
    DBG_CHKTHIS( SfxPoolItem, 0 );
    nRefCount = SFX_ITEMS_SPECIAL;
    nKind = n;
}

inline ULONG SfxPoolItem::AddRef( ULONG n ) const
{
    DBG_CHKTHIS( SfxPoolItem, 0 );
    DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
    DBG_ASSERT( ULONG_MAX - nRefCount > n, "AddRef: Referenzzaehler ueberschlaegt sich" );
    return ( ((SfxPoolItem *)this)->nRefCount += n );
}

inline ULONG SfxPoolItem::ReleaseRef( ULONG n ) const
{
    DBG_CHKTHIS( SfxPoolItem, 0 );
    DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
    DBG_ASSERT( nRefCount >= n, "ReleaseRef: Referenzzaehler ueberschlaegt sich" );
    ((SfxPoolItem *)this)->nRefCount -= n;
    return nRefCount;
}

// -----------------------------------------------------------------------

inline int IsPoolDefaultItem(const SfxPoolItem *pItem )
{
    return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
}

inline int IsStaticDefaultItem(const SfxPoolItem *pItem )
{
    return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
}

inline int IsDefaultItem( const SfxPoolItem *pItem )
{
    return pItem && pItem->GetKind() >= SFX_ITEMS_STATICDEFAULT;
}

inline int IsPooledItem( const SfxPoolItem *pItem )
{
    return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
}

inline int IsInvalidItem(const SfxPoolItem *pItem)
{
    return pItem == (SfxPoolItem *)-1;
}

// -----------------------------------------------------------------------

class SVL_DLLPUBLIC SfxVoidItem: public SfxPoolItem
{
    SfxVoidItem & operator=( const SfxVoidItem& ); // not implemented.
public:
                            TYPEINFO();
                            SfxVoidItem( USHORT nWhich );
                            SfxVoidItem( USHORT nWhich, SvStream & );
                            SfxVoidItem( const SfxVoidItem& );
                            ~SfxVoidItem();

    virtual int             operator==( const SfxPoolItem& ) const;

    virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
                                    SfxMapUnit eCoreMetric,
                                    SfxMapUnit ePresMetric,
                                    XubString &rText,
                                    const IntlWrapper * = 0 ) const;

    // von sich selbst eine Kopie erzeugen
    virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const;
            void            SetWhich(USHORT nWh) { nWhich = nWh; }
};

// -----------------------------------------------------------------------

class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
{
    SfxItemSet              *pSet;

    SfxSetItem & operator=( const SfxSetItem& ); // not implemented.

public:
                            TYPEINFO();
                            SfxSetItem( USHORT nWhich, SfxItemSet *pSet );
                            SfxSetItem( USHORT nWhich, const SfxItemSet &rSet );
                            SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = 0 );
                            ~SfxSetItem();

    virtual int             operator==( const SfxPoolItem& ) const;

    virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
                                    SfxMapUnit eCoreMetric,
                                    SfxMapUnit ePresMetric,
                                    XubString &rText,
                                    const IntlWrapper * = 0 ) const;

    // von sich selbst eine Kopie erzeugen
    virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const = 0;
    virtual SfxPoolItem*    Create(SvStream &, USHORT nVersion) const = 0;
    virtual SvStream&       Store(SvStream &, USHORT nVer) const;

    const SfxItemSet&       GetItemSet() const
                            { return *pSet; }
    SfxItemSet&             GetItemSet()
                            { return *pSet; }
};

// -----------------------------------------------------------------------

#if 0  /* @@@ NOT USED @@@ */
class SfxInvalidItem: public SfxPoolItem
{
friend class SfxItemSet;

    const SfxPoolItem*      pDefaultItem;

private:
                            TYPEINFO();
                            SfxInvalidItem( USHORT nWhich, const SfxPoolItem &rDefault );
                            SfxInvalidItem( const SfxInvalidItem& );
    virtual                 ~SfxInvalidItem();

public:
    virtual int             operator==( const SfxPoolItem& ) const;

    virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
                                    SfxMapUnit eCoreMetric,
                                    SfxMapUnit ePresMetric,
                                    XubString &rText,
                                    const IntlWrapper * = 0 ) const;
    const SfxPoolItem*      GetDefaultItem() const { return pDefaultItem; }

    // von sich selbst eine Kopie erzeugen
    virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const;
    virtual SfxPoolItem*    Create(SvStream &, USHORT nVersion) const;
    virtual SvStream&       Store(SvStream &, USHORT nVer ) const;
};
#endif /* @@@ NOT USED @@@ */

// -----------------------------------------------------------------------
// Handle Klasse fuer PoolItems

class SVL_DLLPUBLIC SfxItemHandle
{
    USHORT      *pRef;
    SfxPoolItem *pItem;
public:
    SfxItemHandle( SfxPoolItem& );
    SfxItemHandle( const SfxItemHandle& );
    ~SfxItemHandle();

    const SfxItemHandle &operator=(const SfxItemHandle &);
    const SfxPoolItem &GetItem() const { return *pItem; }
};

// -----------------------------------------------------------------------

DECL_PTRHINT(SVL_DLLPUBLIC, SfxPoolItemHint, SfxPoolItem);

// -----------------------------------------------------------------------

#if 0  /* @@@ NOT USED @@@ */
class SfxItemChangedHint: public SfxHint
{
    const SfxPoolItem&  _rOld;
    const SfxPoolItem&  _rNew;

public:
                        TYPEINFO(); \
                        SfxItemChangedHint( const SfxPoolItem &rOld,
                                            const SfxPoolItem &rNew )
                        :   _rOld( rOld ),
                            _rNew( rNew )
                        {}

    const SfxPoolItem&  GetOldItem() const { return _rOld; }
    const SfxPoolItem&  GetNewItem() const { return _rNew; }
};

#endif /* @@@ NOT USED @@@ */

#endif // #ifndef _SFXPOOLITEM_HXX