LCOV - code coverage report
Current view: top level - unotools/source/config - fontoptions.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 50 93 53.8 %
Date: 2014-04-11 Functions: 12 18 66.7 %
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             : #include <unotools/fontoptions.hxx>
      21             : #include <unotools/configmgr.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : 
      27             : #include <rtl/instance.hxx>
      28             : #include "itemholder1.hxx"
      29             : 
      30             : using namespace ::utl;
      31             : using namespace ::rtl;
      32             : using namespace ::osl;
      33             : using namespace ::com::sun::star::uno;
      34             : 
      35             : #define ROOTNODE_FONT                       OUString("Office.Common/Font")
      36             : 
      37             : #define PROPERTYNAME_REPLACEMENTTABLE       OUString("Substitution/Replacement")
      38             : #define PROPERTYNAME_FONTHISTORY            OUString("View/History")
      39             : #define PROPERTYNAME_FONTWYSIWYG            OUString("View/ShowFontBoxWYSIWYG")
      40             : 
      41             : #define PROPERTYHANDLE_REPLACEMENTTABLE     0
      42             : #define PROPERTYHANDLE_FONTHISTORY          1
      43             : #define PROPERTYHANDLE_FONTWYSIWYG          2
      44             : 
      45             : #define PROPERTYCOUNT                       3
      46             : 
      47             : class SvtFontOptions_Impl : public ConfigItem
      48             : {
      49             :     public:
      50             : 
      51             :          SvtFontOptions_Impl();
      52             :         virtual ~SvtFontOptions_Impl();
      53             : 
      54             :         /*-****************************************************************************************************
      55             :             @short      called for notify of configmanager
      56             :             @descr      These method is called from the ConfigManager before application ends or from the
      57             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
      58             :                         internal values.
      59             : 
      60             :             @seealso    baseclass ConfigItem
      61             : 
      62             :             @param      "seqPropertyNames" is the list of properties which should be updated.
      63             :         *//*-*****************************************************************************************************/
      64             : 
      65             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
      66             : 
      67             :         /*-****************************************************************************************************
      68             :             @short      write changes to configuration
      69             :             @descr      These method writes the changed values into the sub tree
      70             :                         and should always called in our destructor to guarantee consistency of config data.
      71             : 
      72             :             @seealso    baseclass ConfigItem
      73             :         *//*-*****************************************************************************************************/
      74             : 
      75             :         virtual void Commit() SAL_OVERRIDE;
      76             : 
      77             :         /*-****************************************************************************************************
      78             :             @short      access method to get internal values
      79             :             @descr      These method give us a chance to regulate acces to our internal values.
      80             :                         It's not used in the moment - but it's possible for the feature!
      81             :         *//*-*****************************************************************************************************/
      82             : 
      83             :         bool    IsFontHistoryEnabled        (                   ) const;
      84             :         void        EnableFontHistory           ( bool bState   );
      85             : 
      86             :         bool    IsFontWYSIWYGEnabled        (                   ) const;
      87             :         void        EnableFontWYSIWYG           ( bool bState   );
      88             : 
      89             :     private:
      90             : 
      91             :         /*-****************************************************************************************************
      92             :             @short      return list of key names of our configuration management which represent oue module tree
      93             :             @descr      These methods return a static const list of key names. We need it to get needed values from our
      94             :                         configuration management.
      95             :             @return     A list of needed configuration keys is returned.
      96             :         *//*-*****************************************************************************************************/
      97             : 
      98             :         static Sequence< OUString > impl_GetPropertyNames();
      99             : 
     100             :     private:
     101             : 
     102             :         bool        m_bReplacementTable;
     103             :         bool        m_bFontHistory;
     104             :         bool        m_bFontWYSIWYG;
     105             : };
     106             : 
     107             : //  constructor
     108             : 
     109          25 : SvtFontOptions_Impl::SvtFontOptions_Impl()
     110             :     // Init baseclasses first
     111             :     :   ConfigItem          ( ROOTNODE_FONT )
     112             :     // Init member then.
     113             :     ,   m_bReplacementTable ( false     )
     114             :     ,   m_bFontHistory      ( false     )
     115          25 :     ,   m_bFontWYSIWYG      ( false     )
     116             : {
     117             :     // Use our static list of configuration keys to get his values.
     118          25 :     Sequence< OUString >    seqNames    = impl_GetPropertyNames (           );
     119          50 :     Sequence< Any >         seqValues   = GetProperties         ( seqNames  );
     120             : 
     121             :     // Safe impossible cases.
     122             :     // We need values from ALL configuration keys.
     123             :     // Follow assignment use order of values in relation to our list of key names!
     124             :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nI miss some values of configuration keys!\n" );
     125             : 
     126             :     // Copy values from list in right order to our internal member.
     127          25 :     sal_Int32 nPropertyCount = seqValues.getLength();
     128         100 :     for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
     129             :     {
     130             :         // Safe impossible cases.
     131             :         // Check any for valid value.
     132             :         DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nInvalid property value detected!\n" );
     133          75 :         switch( nProperty )
     134             :         {
     135             :             case PROPERTYHANDLE_REPLACEMENTTABLE    :   {
     136             :                                                             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nWho has changed the value type of \"Office.Common\\Font\\Substitution\\Replacement\"?" );
     137          25 :                                                             seqValues[nProperty] >>= m_bReplacementTable;
     138             :                                                         }
     139          25 :                                                         break;
     140             :             case PROPERTYHANDLE_FONTHISTORY         :   {
     141             :                                                             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nWho has changed the value type of \"Office.Common\\Font\\View\\History\"?" );
     142          25 :                                                             seqValues[nProperty] >>= m_bFontHistory;
     143             :                                                         }
     144          25 :                                                         break;
     145             :             case PROPERTYHANDLE_FONTWYSIWYG         :   {
     146             :                                                             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtFontOptions_Impl::SvtFontOptions_Impl()\nWho has changed the value type of \"Office.Common\\Font\\View\\ShowFontBoxWYSIWYG\"?" );
     147          25 :                                                             seqValues[nProperty] >>= m_bFontWYSIWYG;
     148             :                                                         }
     149          25 :                                                         break;
     150             :         }
     151             :     }
     152             : 
     153             :     // Enable notification mechanism of our baseclass.
     154             :     // We need it to get information about changes outside these class on our used configuration keys!
     155          50 :     EnableNotification( seqNames );
     156          25 : }
     157             : 
     158             : //  destructor
     159             : 
     160          75 : SvtFontOptions_Impl::~SvtFontOptions_Impl()
     161             : {
     162             :     // We must save our current values .. if user forget it!
     163          25 :     if( IsModified() )
     164             :     {
     165           0 :         Commit();
     166             :     }
     167          50 : }
     168             : 
     169             : //  public method
     170             : 
     171           0 : void SvtFontOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
     172             : {
     173             :     // Use given list of updated properties to get his values from configuration directly!
     174           0 :     Sequence< Any > seqValues = GetProperties( seqPropertyNames );
     175             :     // Safe impossible cases.
     176             :     // We need values from ALL notified configuration keys.
     177             :     DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtFontOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
     178             :     // Step over list of property names and get right value from coreesponding value list to set it on internal members!
     179           0 :     sal_Int32 nCount = seqPropertyNames.getLength();
     180           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     181             :     {
     182           0 :         if( seqPropertyNames[nProperty] == PROPERTYNAME_REPLACEMENTTABLE )
     183             :         {
     184             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtFontOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Font\\Substitution\\Replacement\"?" );
     185           0 :             seqValues[nProperty] >>= m_bReplacementTable;
     186             :         }
     187             :         else
     188           0 :         if( seqPropertyNames[nProperty] == PROPERTYNAME_FONTHISTORY )
     189             :         {
     190             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtFontOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Font\\View\\History\"?" );
     191           0 :             seqValues[nProperty] >>= m_bFontHistory;
     192             :         }
     193             :         else
     194           0 :         if( seqPropertyNames[nProperty] == PROPERTYNAME_FONTWYSIWYG )
     195             :         {
     196             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtFontOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Font\\View\\ShowFontBoxWYSIWYG\"?" );
     197           0 :             seqValues[nProperty] >>= m_bFontWYSIWYG;
     198             :         }
     199             :         #if OSL_DEBUG_LEVEL > 1
     200             :         else DBG_ASSERT( sal_False, "SvtFontOptions_Impl::Notify()\nUnknown property detected ... I can't handle these!\n" );
     201             :         #endif
     202           0 :     }
     203           0 : }
     204             : 
     205             : //  public method
     206             : 
     207           0 : void SvtFontOptions_Impl::Commit()
     208             : {
     209             :     // Get names of supported properties, create a list for values and copy current values to it.
     210           0 :     Sequence< OUString >    seqNames    = impl_GetPropertyNames();
     211           0 :     sal_Int32               nCount      = seqNames.getLength();
     212           0 :     Sequence< Any >         seqValues   ( nCount );
     213           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     214             :     {
     215           0 :         switch( nProperty )
     216             :         {
     217             :             case PROPERTYHANDLE_REPLACEMENTTABLE    :   {
     218           0 :                                                             seqValues[nProperty] <<= m_bReplacementTable;
     219             :                                                         }
     220           0 :                                                         break;
     221             :             case PROPERTYHANDLE_FONTHISTORY         :   {
     222           0 :                                                             seqValues[nProperty] <<= m_bFontHistory;
     223             :                                                         }
     224           0 :                                                         break;
     225             :             case PROPERTYHANDLE_FONTWYSIWYG         :   {
     226           0 :                                                             seqValues[nProperty] <<= m_bFontWYSIWYG;
     227             :                                                         }
     228           0 :                                                         break;
     229             :         }
     230             :     }
     231             :     // Set properties in configuration.
     232           0 :     PutProperties( seqNames, seqValues );
     233           0 : }
     234             : 
     235             : //  public method
     236             : 
     237         563 : bool SvtFontOptions_Impl::IsFontHistoryEnabled() const
     238             : {
     239         563 :     return m_bFontHistory;
     240             : }
     241             : 
     242             : //  public method
     243             : 
     244           0 : void SvtFontOptions_Impl::EnableFontHistory( bool bState )
     245             : {
     246           0 :     m_bFontHistory = bState;
     247           0 :     SetModified();
     248           0 : }
     249             : 
     250             : //  public method
     251             : 
     252         563 : bool SvtFontOptions_Impl::IsFontWYSIWYGEnabled() const
     253             : {
     254         563 :     return m_bFontWYSIWYG;
     255             : }
     256             : 
     257             : //  public method
     258             : 
     259           0 : void SvtFontOptions_Impl::EnableFontWYSIWYG( bool bState )
     260             : {
     261           0 :     m_bFontWYSIWYG = bState;
     262           0 :     SetModified();
     263           0 : }
     264             : 
     265             : //  private method
     266             : 
     267          25 : Sequence< OUString > SvtFontOptions_Impl::impl_GetPropertyNames()
     268             : {
     269             :     // Build list of configuration key names.
     270             :     const OUString pProperties[] =
     271             :     {
     272             :         PROPERTYNAME_REPLACEMENTTABLE   ,
     273             :         PROPERTYNAME_FONTHISTORY        ,
     274             :         PROPERTYNAME_FONTWYSIWYG        ,
     275         100 :     };
     276             :     // Initialize return sequence with these list ...
     277          25 :     const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
     278             :     // ... and return it.
     279         100 :     return seqPropertyNames;
     280             : }
     281             : 
     282             : //  initialize static member
     283             : //  DON'T DO IT IN YOUR HEADER!
     284             : //  see definition for further information
     285             : 
     286             : SvtFontOptions_Impl*    SvtFontOptions::m_pDataContainer    = NULL;
     287             : sal_Int32               SvtFontOptions::m_nRefCount         = 0;
     288             : 
     289             : //  constructor
     290             : 
     291         588 : SvtFontOptions::SvtFontOptions()
     292             : {
     293             :     // Global access, must be guarded (multithreading!).
     294         588 :     MutexGuard aGuard( impl_GetOwnStaticMutex() );
     295             :     // Increase our refcount ...
     296         588 :     ++m_nRefCount;
     297             :     // ... and initialize our data container only if it not already exist!
     298         588 :     if( m_pDataContainer == NULL )
     299             :     {
     300          25 :         m_pDataContainer = new SvtFontOptions_Impl;
     301             : 
     302          25 :         ItemHolder1::holdConfigItem(E_FONTOPTIONS);
     303         588 :     }
     304         588 : }
     305             : 
     306             : //  destructor
     307             : 
     308        1201 : SvtFontOptions::~SvtFontOptions()
     309             : {
     310             :     // Global access, must be guarded (multithreading!)
     311         588 :     MutexGuard aGuard( impl_GetOwnStaticMutex() );
     312             :     // Decrease our refcount.
     313         588 :     --m_nRefCount;
     314             :     // If last instance was deleted ...
     315             :     // we must destroy our static data container!
     316         588 :     if( m_nRefCount <= 0 )
     317             :     {
     318          25 :         delete m_pDataContainer;
     319          25 :         m_pDataContainer = NULL;
     320         588 :     }
     321         613 : }
     322             : 
     323             : //  public method
     324             : 
     325         563 : bool SvtFontOptions::IsFontHistoryEnabled() const
     326             : {
     327         563 :     MutexGuard aGuard( impl_GetOwnStaticMutex() );
     328         563 :     return m_pDataContainer->IsFontHistoryEnabled();
     329             : }
     330             : 
     331             : //  public method
     332             : 
     333           0 : void SvtFontOptions::EnableFontHistory( bool bState )
     334             : {
     335           0 :     MutexGuard aGuard( impl_GetOwnStaticMutex() );
     336           0 :     m_pDataContainer->EnableFontHistory( bState );
     337           0 : }
     338             : 
     339             : //  public method
     340             : 
     341         563 : bool SvtFontOptions::IsFontWYSIWYGEnabled() const
     342             : {
     343         563 :     MutexGuard aGuard( impl_GetOwnStaticMutex() );
     344         563 :     return m_pDataContainer->IsFontWYSIWYGEnabled();
     345             : }
     346             : 
     347             : //  public method
     348             : 
     349           0 : void SvtFontOptions::EnableFontWYSIWYG( bool bState )
     350             : {
     351           0 :     MutexGuard aGuard( impl_GetOwnStaticMutex() );
     352           0 :     m_pDataContainer->EnableFontWYSIWYG( bState );
     353           0 : }
     354             : 
     355             : namespace
     356             : {
     357             :     class theFontOptionsMutex : public rtl::Static<osl::Mutex, theFontOptionsMutex> {};
     358             : }
     359             : 
     360             : //  private method
     361             : 
     362        2302 : Mutex& SvtFontOptions::impl_GetOwnStaticMutex()
     363             : {
     364        2302 :     return theFontOptionsMutex::get();
     365             : }
     366             : 
     367             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10