LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/svl - poolitem.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 48 89.6 %
Date: 2012-08-25 Functions: 18 20 90.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 24 66.7 %

           Branch data     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                 :      48593 : inline sal_Bool Any2Bool( const ::com::sun::star::uno::Any&rValue )
      63                 :            : {
      64                 :      48593 :     sal_Bool nValue = sal_False;
      65         [ +  - ]:      48593 :     if( rValue.hasValue() )
      66                 :            :     {
      67         [ +  - ]:      48593 :         if( rValue.getValueType() == ::getCppuBooleanType() )
      68                 :            :         {
      69                 :      48593 :             nValue = *(sal_Bool*)rValue.getValue();
      70                 :            :         }
      71                 :            :         else
      72                 :            :         {
      73                 :          0 :             sal_Int32 nNum = 0;
      74         [ #  # ]:          0 :             if( rValue >>= nNum )
      75                 :          0 :                 nValue = nNum != 0;
      76                 :            :         }
      77                 :            :     }
      78                 :            : 
      79                 :      48593 :     return nValue;
      80                 :            : }
      81                 :            : 
      82                 :       5759 : inline ::com::sun::star::uno::Any Bool2Any( sal_Bool bValue )
      83                 :            : {
      84                 :       5759 :     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                 :            :                              SfxPoolItem( sal_uInt16 nWhich = 0 );
     191                 :            :                              SfxPoolItem( const SfxPoolItem& );
     192                 :            : 
     193                 :            : public:
     194                 :            :                              TYPEINFO();
     195                 :            :     virtual                  ~SfxPoolItem();
     196                 :            : 
     197                 :    1740718 :     void                     SetWhich( sal_uInt16 nId ) {
     198                 :            :                                 DBG_CHKTHIS(SfxPoolItem, 0);
     199                 :    1740718 :                                 nWhich = nId; }
     200                 :   76737692 :     sal_uInt16                   Which() const {
     201                 :            :                                  DBG_CHKTHIS(SfxPoolItem, 0);
     202                 :   76737692 :                                  return nWhich; }
     203                 :            :     virtual int              operator==( const SfxPoolItem& ) const = 0;
     204                 :     204700 :     int                      operator!=( const SfxPoolItem& rItem ) const
     205                 :     204700 :                              { 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                 :   51880317 :     sal_uLong                    GetRefCount() const { return nRefCount; }
     227                 :   28248317 :     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                 :     989480 : inline void SfxPoolItem::SetRefCount( sal_uLong n )
     280                 :            : {
     281                 :            :     DBG_CHKTHIS( SfxPoolItem, 0 );
     282                 :     989480 :     nRefCount = n;
     283                 :     989480 :     nKind = 0;
     284                 :     989480 : }
     285                 :            : 
     286                 :    3780988 : inline void SfxPoolItem::SetKind( sal_uInt16 n )
     287                 :            : {
     288                 :            :     DBG_CHKTHIS( SfxPoolItem, 0 );
     289                 :    3780988 :     nRefCount = SFX_ITEMS_SPECIAL;
     290                 :    3780988 :     nKind = n;
     291                 :    3780988 : }
     292                 :            : 
     293                 :   19462356 : 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                 :   19462356 :     return ( ((SfxPoolItem *)this)->nRefCount += n );
     299                 :            : }
     300                 :            : 
     301                 :   19403974 : 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                 :   19403974 :     ((SfxPoolItem *)this)->nRefCount -= n;
     307                 :   19403974 :     return nRefCount;
     308                 :            : }
     309                 :            : 
     310                 :            : // -----------------------------------------------------------------------
     311                 :            : 
     312                 :     360410 : inline int IsPoolDefaultItem(const SfxPoolItem *pItem )
     313                 :            : {
     314 [ +  - ][ +  + ]:     360410 :     return pItem && pItem->GetKind() == SFX_ITEMS_POOLDEFAULT;
     315                 :            : }
     316                 :            : 
     317                 :    5075093 : inline int IsStaticDefaultItem(const SfxPoolItem *pItem )
     318                 :            : {
     319 [ +  - ][ +  + ]:    5075093 :     return pItem && pItem->GetKind() == SFX_ITEMS_STATICDEFAULT;
     320                 :            : }
     321                 :            : 
     322                 :   17795269 : inline int IsDefaultItem( const SfxPoolItem *pItem )
     323                 :            : {
     324 [ +  - ][ +  + ]:   17795269 :     return pItem && pItem->GetKind() >= SFX_ITEMS_STATICDEFAULT;
     325                 :            : }
     326                 :            : 
     327                 :   14093690 : inline int IsPooledItem( const SfxPoolItem *pItem )
     328                 :            : {
     329 [ +  - ][ +  + ]:   14093690 :     return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
                 [ +  + ]
     330                 :            : }
     331                 :            : 
     332                 :   32901976 : inline int IsInvalidItem(const SfxPoolItem *pItem)
     333                 :            : {
     334                 :   32901976 :     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                 :            :                             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                 :   32246503 :     const SfxItemSet&       GetItemSet() const
     391                 :   32246503 :                             { return *pSet; }
     392                 :     192903 :     SfxItemSet&             GetItemSet()
     393                 :     192903 :                             { 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                 :            :     SfxItemHandle( SfxPoolItem& );
     405                 :            :     SfxItemHandle( const SfxItemHandle& );
     406                 :            :     ~SfxItemHandle();
     407                 :            : 
     408                 :            :     const SfxItemHandle &operator=(const SfxItemHandle &);
     409                 :          0 :     const SfxPoolItem &GetItem() const { return *pItem; }
     410                 :            : };
     411                 :            : 
     412                 :            : // -----------------------------------------------------------------------
     413                 :            : 
     414                 :          0 : 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