LCOV - code coverage report
Current view: top level - include/svl - style.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 21 23 91.3 %
Date: 2014-04-11 Functions: 17 25 68.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             : 
      20             : #ifndef INCLUDED_SVL_STYLE_HXX
      21             : #define INCLUDED_SVL_STYLE_HXX
      22             : 
      23             : #include <com/sun/star/style/XStyle.hpp>
      24             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      25             : 
      26             : #include <rtl/ref.hxx>
      27             : #include <vector>
      28             : #include <comphelper/weak.hxx>
      29             : #include <cppuhelper/implbase2.hxx>
      30             : #include <svl/svldllapi.h>
      31             : #include <rsc/rscsfx.hxx>
      32             : #include <svl/hint.hxx>
      33             : #include <svl/lstner.hxx>
      34             : #include <svl/brdcst.hxx>
      35             : #include <svl/poolitem.hxx>
      36             : #include <svl/stylesheetuser.hxx>
      37             : 
      38             : #include <svl/style.hrc>
      39             : #include <boost/shared_ptr.hpp>
      40             : 
      41             : class SfxItemSet;
      42             : class SfxItemPool;
      43             : class SfxStyleSheetBasePool;
      44             : class SvStream;
      45             : 
      46             : namespace svl { class IndexedStyleSheets; }
      47             : /*
      48             : Everyone changing instances of SfxStyleSheetBasePool or SfxStyleSheetBase
      49             : must broadcast this using <SfxStyleSheetBasePool::GetBroadcaster()> broadcasts.
      50             : The class <SfxStyleSheetHint> is used for this, it contains an Action-Id and a
      51             : pointer to the <SfxStyleSheetBase>. The actions are:
      52             : 
      53             : #define SFX_STYLESHEET_CREATED      // style is created
      54             : #define SFX_STYLESHEET_MODIFIED     // style is modified
      55             : #define SFX_STYLESHEET_CHANGED      // style is replaced
      56             : #define SFX_STYLESHEET_ERASED       // style is deleted
      57             : 
      58             : The following methods already broadcast themself
      59             : 
      60             : SfxSimpleHint(SFX_HINT_DYING) from:
      61             :    SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
      62             : 
      63             : SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) from:
      64             :    SfxStyleSheetBasePool::Make( const String& rName,
      65             :    SfxStyleFamily eFam, sal_uInt16 mask)
      66             : 
      67             : SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *pNew ) from:
      68             :    SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
      69             : 
      70             : SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) from:
      71             :    SfxStyleSheetBasePool::Erase( SfxStyleSheetBase* p )
      72             :    SfxStyleSheetBasePool::Clear()
      73             : */
      74             : 
      75             : class SVL_DLLPUBLIC SfxStyleSheetBase : public comphelper::OWeakTypeObject
      76             : {
      77             : private:
      78             :     friend class SfxStyleSheetBasePool;
      79             :     SVL_DLLPRIVATE static SfxStyleSheetBasePool& implGetStaticPool();
      80             : 
      81             : protected:
      82             :     SfxStyleSheetBasePool*  pPool;          // zugehoeriger Pool
      83             :     SfxStyleFamily          nFamily;        // Familie
      84             : 
      85             :     OUString                aName, aParent, aFollow;
      86             :     OUString                maDisplayName;
      87             :     OUString                aHelpFile;      // Name der Hilfedatei
      88             :     SfxItemSet*             pSet;           // ItemSet
      89             :     sal_uInt16              nMask;          // Flags
      90             : 
      91             :     sal_uLong               nHelpId;        // Hilfe-ID
      92             : 
      93             :     bool                    bMySet;         // sal_True: Set loeschen im dtor
      94             :     bool                    bHidden;
      95             : 
      96             :     SfxStyleSheetBase( const OUString&, SfxStyleSheetBasePool*, SfxStyleFamily eFam, sal_uInt16 mask );
      97             :     SfxStyleSheetBase( const SfxStyleSheetBase& );
      98             :     virtual ~SfxStyleSheetBase();
      99             :     virtual void Load( SvStream&, sal_uInt16 );
     100             :     virtual void Store( SvStream& );
     101             : 
     102             : public:
     103             :     TYPEINFO();
     104             : 
     105             :     // returns the internal name of this style
     106             :     virtual const OUString& GetName() const;
     107             : 
     108             :     // sets the internal name of this style
     109             :     virtual bool SetName( const OUString& );
     110             : 
     111             :     /** returns the display name of this style, it is used at the user interface.
     112             :         If the display name is empty, this method returns the internal name. */
     113             :     virtual OUString GetDisplayName() const;
     114             : 
     115             :     // sets the display name of this style
     116             :     virtual void SetDisplayName( const OUString& );
     117             : 
     118             :     virtual const OUString& GetParent() const;
     119             :     virtual bool SetParent( const OUString& );
     120             :     virtual const OUString& GetFollow() const;
     121             :     virtual bool SetFollow( const OUString& );
     122             :     virtual bool HasFollowSupport() const;      // Default true
     123             :     virtual bool HasParentSupport() const;      // Default true
     124             :     virtual bool HasClearParentSupport() const; // Default false
     125             :     virtual bool IsUsed() const;                // Default true
     126             :         // Default aus dem Itemset; entweder dem uebergebenen
     127             :         // oder aus dem per GetItemSet() zurueckgelieferten Set
     128             :     virtual OUString GetDescription();
     129             :     virtual OUString GetDescription( SfxMapUnit eMetric );
     130             : 
     131       91954 :     SfxStyleSheetBasePool& GetPool() { return *pPool; }
     132     2081467 :     SfxStyleFamily GetFamily() const     { return nFamily; }
     133      571511 :     sal_uInt16   GetMask() const     { return nMask; }
     134           0 :     void     SetMask( sal_uInt16 mask) { nMask = mask; }
     135        2046 :     bool     IsUserDefined() const
     136        2046 :            { return ( nMask & SFXSTYLEBIT_USERDEF) != 0; }
     137             : 
     138        8592 :     virtual bool IsHidden() const { return bHidden; }
     139             :     virtual void SetHidden( bool bValue );
     140             : 
     141             :     virtual sal_uLong GetHelpId( OUString& rFile );
     142             :     virtual void   SetHelpId( const OUString& r, sal_uLong nId );
     143             : 
     144             :     virtual SfxItemSet& GetItemSet();
     145             :     virtual sal_uInt16 GetVersion() const;
     146             : };
     147             : 
     148             : /* Class to iterate and search on a SfxStyleSheetBasePool */
     149             : class SVL_DLLPUBLIC SfxStyleSheetIterator
     150             : {
     151             : public:
     152             :     /** Constructor.
     153             :      * The iterator will only iterate over style sheets which have the family \p eFam
     154             :      */
     155             :     SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
     156             :                           SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
     157             :     virtual sal_uInt16 GetSearchMask() const;
     158             :     virtual SfxStyleFamily GetSearchFamily() const;
     159             :     virtual sal_uInt16 Count();
     160             :     virtual SfxStyleSheetBase *operator[](sal_uInt16 nIdx);
     161             :     virtual SfxStyleSheetBase* First();
     162             :     virtual SfxStyleSheetBase* Next();
     163             :     virtual SfxStyleSheetBase* Find(const OUString& rStr);
     164             :     virtual ~SfxStyleSheetIterator();
     165             : 
     166     2042097 :     bool                    SearchUsed() const { return bSearchUsed; }
     167             : 
     168             : protected:
     169             : 
     170             :     SfxStyleSheetBasePool*  pBasePool;
     171             :     SfxStyleFamily          nSearchFamily;
     172             :     sal_uInt16              nMask;
     173             : 
     174             : 
     175             : private:
     176             :     sal_uInt16                  GetPos() { return nAktPosition; }
     177             :     SVL_DLLPRIVATE bool         IsTrivialSearch();
     178             : 
     179             :     SfxStyleSheetBase*      pAktStyle;
     180             :     sal_uInt16              nAktPosition;
     181             :     bool                    bSearchUsed;
     182             : 
     183             : friend class SfxStyleSheetBasePool;
     184             : };
     185             : 
     186             : typedef ::boost::shared_ptr< SfxStyleSheetIterator > SfxStyleSheetIteratorPtr;
     187             : 
     188             : 
     189             : class SfxStyleSheetBasePool_Impl;
     190             : 
     191             : class SVL_DLLPUBLIC SfxStyleSheetBasePool: public SfxBroadcaster, public comphelper::OWeakTypeObject
     192             : {
     193             : friend class SfxStyleSheetIterator;
     194             : friend class SfxStyleSheetBase;
     195             : 
     196             :     SfxStyleSheetBasePool_Impl *pImp;
     197             : 
     198             : protected:
     199             :     SfxStyleSheetIterator&      GetIterator_Impl();
     200             : 
     201             :     OUString                    aAppName;
     202             :     SfxItemPool&                rPool;
     203             :     SfxStyleFamily              nSearchFamily;
     204             :     sal_uInt16                  nMask;
     205             : 
     206             :     void                        ChangeParent( const OUString&, const OUString&, bool bVirtual = true );
     207             :     virtual SfxStyleSheetBase*  Create( const OUString&, SfxStyleFamily, sal_uInt16 );
     208             :     virtual SfxStyleSheetBase*  Create( const SfxStyleSheetBase& );
     209             : 
     210             :     virtual                     ~SfxStyleSheetBasePool();
     211             : 
     212             :     void                        StoreStyleSheet(rtl::Reference< SfxStyleSheetBase >);
     213             : 
     214             :     /** Obtain the indexed style sheets.
     215             :      */
     216             :     const svl::IndexedStyleSheets&
     217             :                                 GetIndexedStyleSheets() const;
     218             :     rtl::Reference<SfxStyleSheetBase>
     219             :                                 GetStyleSheetByPositionInIndex(unsigned pos);
     220             : 
     221             : public:
     222             :                                 SfxStyleSheetBasePool( SfxItemPool& );
     223             :                                 SfxStyleSheetBasePool( const SfxStyleSheetBasePool& );
     224             : 
     225           0 :     const OUString&             GetAppName() const { return aAppName;   }
     226             : 
     227             :     SfxItemPool&                GetPool();
     228             :     const SfxItemPool&          GetPool() const;
     229             : 
     230             :     virtual SfxStyleSheetIteratorPtr CreateIterator(SfxStyleFamily, sal_uInt16 nMask);
     231             :     virtual sal_uInt16              Count();
     232             :     virtual SfxStyleSheetBase*  operator[](sal_uInt16 nIdx);
     233             : 
     234             :     virtual SfxStyleSheetBase&  Make(const OUString&,
     235             :                                      SfxStyleFamily eFam,
     236             :                                      sal_uInt16 nMask = SFXSTYLEBIT_ALL);
     237             : 
     238             :     virtual void             Replace(
     239             :         SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget );
     240             : 
     241             :     virtual void                Remove( SfxStyleSheetBase* );
     242             :     virtual void                Insert( SfxStyleSheetBase* );
     243             : 
     244             :     virtual void                Clear();
     245             : 
     246             :     SfxStyleSheetBasePool&      operator=( const SfxStyleSheetBasePool& );
     247             :     SfxStyleSheetBasePool&      operator+=( const SfxStyleSheetBasePool& );
     248             : 
     249             :     unsigned                    GetNumberOfStyles();
     250             : 
     251             :     virtual SfxStyleSheetBase*  First();
     252             :     virtual SfxStyleSheetBase*  Next();
     253             :     virtual SfxStyleSheetBase*  Find( const OUString&, SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
     254             : 
     255             :     virtual bool                SetParent(SfxStyleFamily eFam,
     256             :                                           const OUString &rStyle,
     257             :                                           const OUString &rParent);
     258             : 
     259      415928 :     SfxStyleSheetBase*          Find(const OUString& rStr)
     260      415928 :                                 { return Find(rStr, nSearchFamily, nMask); }
     261             : 
     262             :     void                        SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n=SFXSTYLEBIT_ALL );
     263             :     sal_uInt16                      GetSearchMask() const;
     264        1669 :     SfxStyleFamily              GetSearchFamily() const  { return nSearchFamily; }
     265             : 
     266             :     void                        Reindex();
     267             :     /** Add a style sheet.
     268             :      * Not an actual public function. Do not call it from non-subclasses.
     269             :      */
     270             :     SfxStyleSheetBase&          Add( const SfxStyleSheetBase& );
     271             : 
     272             : private:
     273             :     /** This member holds the indexed style sheets.
     274             :      *
     275             :      * @internal
     276             :      * This member is private and not protected in order to have more control which style sheets are added
     277             :      * where. Ideally, all calls which add/remove/change style sheets are done in the base class.
     278             :      */
     279             :     boost::shared_ptr<svl::IndexedStyleSheets> mIndexedStyleSheets;
     280             : };
     281             : 
     282             : 
     283             : 
     284             : class SVL_DLLPUBLIC SfxStyleSheet: public SfxStyleSheetBase,
     285             :                      public SfxListener, public SfxBroadcaster, public svl::StyleSheetUser
     286             : {
     287             : public:
     288             :                         TYPEINFO_OVERRIDE();
     289             : 
     290             :                         SfxStyleSheet( const OUString&, const SfxStyleSheetBasePool&, SfxStyleFamily, sal_uInt16 );
     291             :                         SfxStyleSheet( const SfxStyleSheet& );
     292             : 
     293             :     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
     294             : 
     295             :     virtual bool        isUsedByModel() const SAL_OVERRIDE;
     296             : 
     297             :     virtual bool        SetParent( const OUString& ) SAL_OVERRIDE;
     298             : 
     299             : protected:
     300             :     SfxStyleSheet() // do not use! needed by MSVC at compile time to satisfy ImplInheritanceHelper2
     301             :         : SfxStyleSheetBase(OUString("dummy"), NULL, SFX_STYLE_FAMILY_ALL, 0)
     302             :     {
     303             :         assert(false);
     304             :     }
     305             :     virtual             ~SfxStyleSheet();
     306             : };
     307             : 
     308             : 
     309             : 
     310         910 : class SVL_DLLPUBLIC SfxStyleSheetPool: public SfxStyleSheetBasePool
     311             : {
     312             : protected:
     313             :     using SfxStyleSheetBasePool::Create;
     314             :     virtual SfxStyleSheetBase* Create(const OUString&, SfxStyleFamily, sal_uInt16 mask) SAL_OVERRIDE;
     315             :     virtual SfxStyleSheetBase* Create(const SfxStyleSheet &);
     316             : 
     317             : public:
     318             :     SfxStyleSheetPool( SfxItemPool const& );
     319             : };
     320             : 
     321             : 
     322             : 
     323             : #define SFX_STYLESHEET_CREATED       1  // new
     324             : #define SFX_STYLESHEET_MODIFIED      2  // changed
     325             : #define SFX_STYLESHEET_CHANGED       3  // erased and re-created (replaced)
     326             : #define SFX_STYLESHEET_ERASED        4  // erased
     327             : #define SFX_STYLESHEET_INDESTRUCTION 5  // in the process of being destructed
     328             : 
     329             : #define SFX_STYLESHEETPOOL_CHANGES  1  // Changes which change the state of the pool, but should not be
     330             :                                        // broadcasted by STYLESHEET hits.
     331             : 
     332             : 
     333             : 
     334         274 : class SVL_DLLPUBLIC SfxStyleSheetPoolHint : public SfxHint
     335             : {
     336             :     sal_uInt16 nHint;
     337             : 
     338             : public:
     339             :     TYPEINFO_OVERRIDE();
     340             : 
     341         274 :                         SfxStyleSheetPoolHint(sal_uInt16 nArgHint) :  nHint(nArgHint){}
     342             :     sal_uInt16              GetHint() const
     343             :                         { return nHint; }
     344             : };
     345             : 
     346             : 
     347             : 
     348       88204 : class SVL_DLLPUBLIC SfxStyleSheetHint: public SfxHint
     349             : {
     350             :     SfxStyleSheetBase*  pStyleSh;
     351             :     sal_uInt16              nHint;
     352             : 
     353             : public:
     354             :                         TYPEINFO_OVERRIDE();
     355             : 
     356             :                         SfxStyleSheetHint( sal_uInt16, SfxStyleSheetBase& );
     357       31100 :     SfxStyleSheetBase*  GetStyleSheet() const
     358       31100 :                         { return pStyleSh; }
     359       49324 :     sal_uInt16              GetHint() const
     360       49324 :                         { return nHint; }
     361             : };
     362             : 
     363         444 : class SVL_DLLPUBLIC SfxStyleSheetHintExtended: public SfxStyleSheetHint
     364             : {
     365             :     OUString            aName;
     366             : 
     367             : public:
     368             :                         TYPEINFO_OVERRIDE();
     369             : 
     370             :                         SfxStyleSheetHintExtended( sal_uInt16, const OUString& rOld,
     371             :                                                    SfxStyleSheetBase& );
     372        5678 :     const OUString&       GetOldName() { return aName; }
     373             : };
     374             : 
     375        8688 : class SVL_DLLPUBLIC SfxUnoStyleSheet : public ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >
     376             : {
     377             : public:
     378             :     SfxUnoStyleSheet( const OUString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske );
     379             : 
     380             :     static SfxUnoStyleSheet* getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle );
     381             : 
     382             :     // XUnoTunnel
     383             :     virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     384             : 
     385             : private:
     386             :     SfxUnoStyleSheet(); // not implemented
     387             : 
     388             :     static const ::com::sun::star::uno::Sequence< ::sal_Int8 >& getIdentifier();
     389             : };
     390             : 
     391             : #endif
     392             : 
     393             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10