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

Generated by: LCOV version 1.11