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

Generated by: LCOV version 1.10