LCOV - code coverage report
Current view: top level - libreoffice/svl/inc/svl - poolitem.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 35 94.3 %
Date: 2012-12-27 Functions: 15 16 93.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #ifndef _SFXPOOLITEM_HXX
      20             : #define _SFXPOOLITEM_HXX
      21             : 
      22             : #include "svl/svldllapi.h"
      23             : #include <com/sun/star/uno/Any.hxx>
      24             : 
      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 <tools/string.hxx>
      31             : #include <svl/hint.hxx>
      32             : 
      33             : typedef long SfxArgumentError;
      34             : 
      35             : class SbxVariable;
      36             : class SbxObject;
      37             : class SvStream;
      38             : class Color;
      39             : class IntlWrapper;
      40             : 
      41             : namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
      42             : 
      43             : static const sal_uInt32 SFX_ITEMS_DIRECT=   0xffffffff;
      44             : static const sal_uInt32 SFX_ITEMS_NULL=     0xfffffff0;  // instead StoreSurrogate
      45             : static const sal_uInt32 SFX_ITEMS_DEFAULT=  0xfffffffe;
      46             : 
      47             : #define SFX_ITEMS_POOLDEFAULT               0xffff
      48             : #define SFX_ITEMS_STATICDEFAULT             0xfffe
      49             : #define SFX_ITEMS_DELETEONIDLE              0xfffd
      50             : 
      51             : #define SFX_ITEMS_OLD_MAXREF                0xffef
      52             : #define SFX_ITEMS_MAXREF                    0xfffffffe
      53             : #define SFX_ITEMS_SPECIAL                   0xffffffff
      54             : 
      55             : #define CONVERT_TWIPS                       0x80    //Uno-Konvertierung fuer Massangaben (fuer MemberId)
      56             : 
      57             : // -----------------------------------------------------------------------
      58             : 
      59             : // UNO3 shortcuts
      60             : 
      61             : // warning, if there is no boolean inside the any this will always return the value false
      62             : inline sal_Bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
      63             : {
      64             :     sal_Bool nValue = sal_False;
      65             :     if( rValue.hasValue() )
      66             :     {
      67             :         if( rValue.getValueType() == ::getCppuBooleanType() )
      68             :         {
      69             :             nValue = *(sal_Bool*)rValue.getValue();
      70             :         }
      71             :         else
      72             :         {
      73             :             sal_Int32 nNum = 0;
      74             :             if( rValue >>= nNum )
      75             :                 nValue = nNum != 0;
      76             :         }
      77             :     }
      78             : 
      79             :     return nValue;
      80             : }
      81             : 
      82             : inline ::com::sun::star::uno::Any Bool2Any( sal_Bool bValue )
      83             : {
      84             :     return ::com::sun::star::uno::Any( &bValue, ::getCppuBooleanType() );
      85             : }
      86             : 
      87             : // -----------------------------------------------------------------------
      88             : 
      89             : //! Notloesung!!!
      90             : enum SfxFieldUnit
      91             : {
      92             :     SFX_FUNIT_NONE, SFX_FUNIT_MM, SFX_FUNIT_CM, SFX_FUNIT_M, SFX_FUNIT_KM,
      93             :     SFX_FUNIT_TWIP, SFX_FUNIT_POINT, SFX_FUNIT_PICA,
      94             :     SFX_FUNIT_INCH, SFX_FUNIT_FOOT, SFX_FUNIT_MILE, SFX_FUNIT_CHAR, SFX_FUNIT_LINE, SFX_FUNIT_CUSTOM
      95             : };
      96             : 
      97             : enum SfxMapUnit
      98             : {
      99             :     SFX_MAPUNIT_100TH_MM,
     100             :     SFX_MAPUNIT_10TH_MM,
     101             :     SFX_MAPUNIT_MM,
     102             :     SFX_MAPUNIT_CM,
     103             :     SFX_MAPUNIT_1000TH_INCH,
     104             :     SFX_MAPUNIT_100TH_INCH,
     105             :     SFX_MAPUNIT_10TH_INCH,
     106             :     SFX_MAPUNIT_INCH,
     107             :     SFX_MAPUNIT_POINT,
     108             :     SFX_MAPUNIT_TWIP,
     109             :     SFX_MAPUNIT_PIXEL,
     110             :     SFX_MAPUNIT_SYSFONT,
     111             :     SFX_MAPUNIT_APPFONT,
     112             :     SFX_MAPUNIT_RELATIVE,
     113             :     SFX_MAPUNIT_ABSOLUTE
     114             : };
     115             : 
     116             : // -----------------------------------------------------------------------
     117             : 
     118             : enum SfxItemPresentation
     119             : 
     120             : /*  [Beschreibung]
     121             : 
     122             :     Die Werte dieses Enums bezeichnen den Grad der textuellen
     123             :     Presentation eines Items nach Aufruf der virtuellen Methode
     124             :     <SfxPoolItem::GetPresentation()const>.
     125             : */
     126             : 
     127             : {
     128             :     SFX_ITEM_PRESENTATION_NONE,
     129             :     SFX_ITEM_PRESENTATION_NAMEONLY,
     130             :     SFX_ITEM_PRESENTATION_NAMELESS,
     131             :     SFX_ITEM_PRESENTATION_COMPLETE
     132             : };
     133             : 
     134             : // -----------------------------------------------------------------------
     135             : 
     136             : typedef sal_uInt16 SfxItemState;
     137             : 
     138             : #define SFX_ITEM_UNKNOWN    0x0000
     139             : 
     140             : #define SFX_ITEM_DISABLED   0x0001
     141             : #define SFX_ITEM_READONLY   0x0002
     142             : 
     143             : #define SFX_ITEM_DONTCARE   0x0010
     144             : #define SFX_ITEM_DEFAULT    0x0020
     145             : #define SFX_ITEM_SET        0x0030
     146             : 
     147             : // old stuff - dont use!!!
     148             : #define SFX_ITEM_AVAILABLE  SFX_ITEM_DEFAULT
     149             : #define SFX_ITEM_OFF        SFX_ITEM_DEFAULT
     150             : #define SFX_ITEM_ON         SFX_ITEM_SET
     151             : 
     152             : DBG_NAMEEX_VISIBILITY(SfxPoolItem, SVL_DLLPUBLIC)
     153             : DBG_NAMEEX(SfxVoidItem)
     154             : DBG_NAMEEX(SfxItemHandle)
     155             : 
     156             : class SvXMLUnitConverter;
     157             : class SfxItemPool;
     158             : class SfxItemSet;
     159             : 
     160             : class String;
     161             : namespace rtl
     162             : {
     163             :     class OUString;
     164             : }
     165             : 
     166             : // -----------------------------------------------------------------------
     167             : 
     168             : class SVL_DLLPUBLIC SfxPoolItem
     169             : {
     170             : friend class SfxItemPool;
     171             : friend class SfxItemDesruptor_Impl;
     172             : friend class SfxItemPoolCache;
     173             : friend class SfxItemSet;
     174             : friend class SfxVoidItem;
     175             : 
     176             :     sal_uLong                    nRefCount;                    // Referenzzaehler
     177             :     sal_uInt16                   nWhich;
     178             :     sal_uInt16                   nKind;
     179             : 
     180             : private:
     181             :     inline void              SetRefCount( sal_uLong n );
     182             :     inline void              SetKind( sal_uInt16 n );
     183             : public:
     184             :     inline sal_uLong             AddRef( sal_uLong n = 1 ) const;
     185             : private:
     186             :     inline sal_uLong             ReleaseRef( sal_uLong n = 1 ) const;
     187             :     SVL_DLLPRIVATE long      Delete_Impl(void*);
     188             : 
     189             : protected:
     190             :                              explicit SfxPoolItem( sal_uInt16 nWhich = 0 );
     191             :                              SfxPoolItem( const SfxPoolItem& );
     192             : 
     193             : public:
     194             :                              TYPEINFO();
     195             :     virtual                  ~SfxPoolItem();
     196             : 
     197      204722 :     void                     SetWhich( sal_uInt16 nId ) {
     198             :                                 DBG_CHKTHIS(SfxPoolItem, 0);
     199      204722 :                                 nWhich = nId; }
     200     6791744 :     sal_uInt16                   Which() const {
     201             :                                  DBG_CHKTHIS(SfxPoolItem, 0);
     202     6791744 :                                  return nWhich; }
     203             :     virtual int              operator==( const SfxPoolItem& ) const = 0;
     204        1670 :     int                      operator!=( const SfxPoolItem& rItem ) const
     205        1670 :                              { return !(*this == rItem); }
     206             :     virtual int              Compare( const SfxPoolItem &rWith ) const;
     207             :     virtual int              Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const;
     208             : 
     209             :     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePresentation,
     210             :                                     SfxMapUnit eCoreMetric,
     211             :                                     SfxMapUnit ePresentationMetric,
     212             :                                     XubString &rText,
     213             :                                     const IntlWrapper * pIntlWrapper = 0 ) const;
     214             : 
     215             :     virtual sal_uInt16           GetVersion( sal_uInt16 nFileFormatVersion ) const;
     216             :     virtual bool             ScaleMetrics( long lMult, long lDiv );
     217             :     virtual bool             HasMetrics() const;
     218             : 
     219             :     virtual bool             QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
     220             :     virtual bool             PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 );
     221             : 
     222             :     virtual SfxPoolItem*     Create( SvStream &, sal_uInt16 nItemVersion ) const;
     223             :     virtual SvStream&        Store( SvStream &, sal_uInt16 nItemVersion ) const;
     224             :     virtual SfxPoolItem*     Clone( SfxItemPool *pPool = 0 ) const = 0;
     225             : 
     226     4919800 :     sal_uLong                    GetRefCount() const { return nRefCount; }
     227     3352257 :     inline sal_uInt16            GetKind() const { return nKind; }
     228             : 
     229             :     /** Read in a Unicode string from a streamed byte string representation.
     230             : 
     231             :         @param rStream  Some (input) stream.  Its Stream/TargetCharSets must
     232             :         be set to correct values!
     233             : 
     234             :         @param rString  On success, returns the reconstructed Unicode string.
     235             : 
     236             :         @return  True if the string was successfuly read and reconstructed.
     237             :      */
     238             :     static rtl::OUString readByteString(SvStream & rStream);
     239             : 
     240             :     /** Write a byte string representation of a Unicode string into a stream.
     241             : 
     242             :         @param rStream  Some (output) stream.  Its Stream/TargetCharSets must
     243             :         be set to correct values!
     244             : 
     245             :         @param rString  Some Unicode string.
     246             :      */
     247             :     static void writeByteString(SvStream & rStream,
     248             :                                 const rtl::OUString& rString);
     249             : 
     250             :     /** Read in a Unicode string from either a streamed Unicode or byte string
     251             :         representation.
     252             : 
     253             :         @param rStream  Some (input) stream.  If bUnicode is false, its
     254             :         Stream/TargetCharSets must be set to correct values!
     255             : 
     256             :         @param bUnicode  Whether to read in a stream Unicode (true) or byte
     257             :         string (false) representation.
     258             : 
     259             :         @return          On success, returns the reconstructed Unicode string.
     260             :      */
     261             :     static rtl::OUString readUnicodeString(SvStream & rStream, bool bUnicode);
     262             : 
     263             :     /** Write a Unicode string representation of a Unicode string into a
     264             :         stream.
     265             : 
     266             :         @param rStream  Some (output) stream.
     267             : 
     268             :         @param rString  Some Unicode string.
     269             :      */
     270             :     static void writeUnicodeString(SvStream & rStream,
     271             :                                    const rtl::OUString& rString);
     272             : 
     273             : private:
     274             :     SfxPoolItem&             operator=( const SfxPoolItem& );    // n.i.!!
     275             : };
     276             : 
     277             : // -----------------------------------------------------------------------
     278             : 
     279        7212 : inline void SfxPoolItem::SetRefCount( sal_uLong n )
     280             : {
     281             :     DBG_CHKTHIS( SfxPoolItem, 0 );
     282        7212 :     nRefCount = n;
     283        7212 :     nKind = 0;
     284        7212 : }
     285             : 
     286      501265 : inline void SfxPoolItem::SetKind( sal_uInt16 n )
     287             : {
     288             :     DBG_CHKTHIS( SfxPoolItem, 0 );
     289      501265 :     nRefCount = SFX_ITEMS_SPECIAL;
     290      501265 :     nKind = n;
     291      501265 : }
     292             : 
     293     2109298 : inline sal_uLong SfxPoolItem::AddRef( sal_uLong n ) const
     294             : {
     295             :     DBG_CHKTHIS( SfxPoolItem, 0 );
     296             :     DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
     297             :     DBG_ASSERT( ULONG_MAX - nRefCount > n, "AddRef: Referenzzaehler ueberschlaegt sich" );
     298     2109298 :     return ( ((SfxPoolItem *)this)->nRefCount += n );
     299             : }
     300             : 
     301     2074299 : inline sal_uLong SfxPoolItem::ReleaseRef( sal_uLong n ) const
     302             : {
     303             :     DBG_CHKTHIS( SfxPoolItem, 0 );
     304             :     DBG_ASSERT( nRefCount <= SFX_ITEMS_MAXREF, "AddRef mit nicht-Pool-Item" );
     305             :     DBG_ASSERT( nRefCount >= n, "ReleaseRef: Referenzzaehler ueberschlaegt sich" );
     306     2074299 :     ((SfxPoolItem *)this)->nRefCount -= n;
     307     2074299 :     return nRefCount;
     308             : }
     309             : 
     310             : // -----------------------------------------------------------------------
     311             : 
     312       80874 : inline int IsPoolDefaultItem(const SfxPoolItem *pItem )
     313             : {
     314       80874 :     return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
     315             : }
     316             : 
     317      795201 : inline int IsStaticDefaultItem(const SfxPoolItem *pItem )
     318             : {
     319      795201 :     return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
     320             : }
     321             : 
     322     1699580 : inline int IsDefaultItem( const SfxPoolItem *pItem )
     323             : {
     324     1699580 :     return pItem && pItem->GetKind() >= SFX_ITEMS_STATICDEFAULT;
     325             : }
     326             : 
     327     1286952 : inline int IsPooledItem( const SfxPoolItem *pItem )
     328             : {
     329     1286952 :     return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
     330             : }
     331             : 
     332     3276748 : inline int IsInvalidItem(const SfxPoolItem *pItem)
     333             : {
     334     3276748 :     return pItem == (SfxPoolItem *)-1;
     335             : }
     336             : 
     337             : // -----------------------------------------------------------------------
     338             : 
     339             : class SVL_DLLPUBLIC SfxVoidItem: public SfxPoolItem
     340             : {
     341             :     SfxVoidItem & operator=( const SfxVoidItem& ); // not implemented.
     342             : public:
     343             :                             TYPEINFO();
     344             :                             explicit SfxVoidItem( sal_uInt16 nWhich );
     345             :                             SfxVoidItem( sal_uInt16 nWhich, SvStream & );
     346             :                             SfxVoidItem( const SfxVoidItem& );
     347             :                             ~SfxVoidItem();
     348             : 
     349             :     virtual int             operator==( const SfxPoolItem& ) const;
     350             : 
     351             :     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
     352             :                                     SfxMapUnit eCoreMetric,
     353             :                                     SfxMapUnit ePresMetric,
     354             :                                     XubString &rText,
     355             :                                     const IntlWrapper * = 0 ) const;
     356             : 
     357             :     // von sich selbst eine Kopie erzeugen
     358             :     virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const;
     359             :             void            SetWhich(sal_uInt16 nWh) { nWhich = nWh; }
     360             : };
     361             : 
     362             : // -----------------------------------------------------------------------
     363             : 
     364             : class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
     365             : {
     366             :     SfxItemSet              *pSet;
     367             : 
     368             :     SfxSetItem & operator=( const SfxSetItem& ); // not implemented.
     369             : 
     370             : public:
     371             :                             TYPEINFO();
     372             :                             SfxSetItem( sal_uInt16 nWhich, SfxItemSet *pSet );
     373             :                             SfxSetItem( sal_uInt16 nWhich, const SfxItemSet &rSet );
     374             :                             SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = 0 );
     375             :                             ~SfxSetItem();
     376             : 
     377             :     virtual int             operator==( const SfxPoolItem& ) const;
     378             : 
     379             :     virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
     380             :                                     SfxMapUnit eCoreMetric,
     381             :                                     SfxMapUnit ePresMetric,
     382             :                                     XubString &rText,
     383             :                                     const IntlWrapper * = 0 ) const;
     384             : 
     385             :     // von sich selbst eine Kopie erzeugen
     386             :     virtual SfxPoolItem*    Clone( SfxItemPool *pPool = 0 ) const = 0;
     387             :     virtual SfxPoolItem*    Create(SvStream &, sal_uInt16 nVersion) const = 0;
     388             :     virtual SvStream&       Store(SvStream &, sal_uInt16 nVer) const;
     389             : 
     390           0 :     const SfxItemSet&       GetItemSet() const
     391           0 :                             { return *pSet; }
     392       18199 :     SfxItemSet&             GetItemSet()
     393       18199 :                             { return *pSet; }
     394             : };
     395             : 
     396             : // -----------------------------------------------------------------------
     397             : // Handle Klasse fuer PoolItems
     398             : 
     399             : class SVL_DLLPUBLIC SfxItemHandle
     400             : {
     401             :     sal_uInt16      *pRef;
     402             :     SfxPoolItem *pItem;
     403             : public:
     404             :     explicit SfxItemHandle( SfxPoolItem& );
     405             :     SfxItemHandle( const SfxItemHandle& );
     406             :     ~SfxItemHandle();
     407             : 
     408             :     const SfxItemHandle &operator=(const SfxItemHandle &);
     409             :     const SfxPoolItem &GetItem() const { return *pItem; }
     410             : };
     411             : 
     412             : // -----------------------------------------------------------------------
     413             : 
     414             : DECL_PTRHINT(SVL_DLLPUBLIC, SfxPoolItemHint, SfxPoolItem);
     415             : 
     416             : // -----------------------------------------------------------------------
     417             : 
     418             : #endif // #ifndef _SFXPOOLITEM_HXX
     419             : 
     420             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10