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

Generated by: LCOV version 1.10