LCOV - code coverage report
Current view: top level - svtools/source/config - miscopt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 225 311 72.3 %
Date: 2014-04-11 Functions: 37 67 55.2 %
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 <svtools/miscopt.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             : #include <tools/link.hxx>
      27             : 
      28             : #include <rtl/instance.hxx>
      29             : #include "itemholder2.hxx"
      30             : 
      31             : #include <svtools/imgdef.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <vcl/settings.hxx>
      34             : 
      35             : #include <list>
      36             : 
      37             : using namespace ::utl                   ;
      38             : using namespace ::rtl                   ;
      39             : using namespace ::osl                   ;
      40             : using namespace ::com::sun::star::uno   ;
      41             : using namespace ::com::sun::star;
      42             : 
      43             : #define ROOTNODE_MISC                       "Office.Common/Misc"
      44             : 
      45             : // PROPERTYHANDLE defines must be sequential from zero for Commit/Load
      46             : #define PROPERTYNAME_PLUGINSENABLED         "PluginsEnabled"
      47             : #define PROPERTYHANDLE_PLUGINSENABLED           0
      48             : #define PROPERTYNAME_SYMBOLSET              "SymbolSet"
      49             : #define PROPERTYHANDLE_SYMBOLSET                1
      50             : #define PROPERTYNAME_TOOLBOXSTYLE           "ToolboxStyle"
      51             : #define PROPERTYHANDLE_TOOLBOXSTYLE             2
      52             : #define PROPERTYNAME_USESYSTEMFILEDIALOG    "UseSystemFileDialog"
      53             : #define PROPERTYHANDLE_USESYSTEMFILEDIALOG      3
      54             : #define PROPERTYNAME_ICONTHEME              "SymbolStyle"
      55             : #define PROPERTYHANDLE_SYMBOLSTYLE              4
      56             : #define PROPERTYNAME_USESYSTEMPRINTDIALOG   "UseSystemPrintDialog"
      57             : #define PROPERTYHANDLE_USESYSTEMPRINTDIALOG     5
      58             : #define PROPERTYNAME_SHOWLINKWARNINGDIALOG  "ShowLinkWarningDialog"
      59             : #define PROPERTYHANDLE_SHOWLINKWARNINGDIALOG    6
      60             : #define PROPERTYNAME_DISABLEUICUSTOMIZATION "DisableUICustomization"
      61             : #define PROPERTYHANDLE_DISABLEUICUSTOMIZATION   7
      62             : #define PROPERTYNAME_ALWAYSALLOWSAVE        "AlwaysAllowSave"
      63             : #define PROPERTYHANDLE_ALWAYSALLOWSAVE          8
      64             : #define PROPERTYNAME_EXPERIMENTALMODE       "ExperimentalMode"
      65             : #define PROPERTYHANDLE_EXPERIMENTALMODE         9
      66             : #define PROPERTYNAME_MACRORECORDERMODE       "MacroRecorderMode"
      67             : #define PROPERTYHANDLE_MACRORECORDERMODE        10
      68             : 
      69             : #define VCL_TOOLBOX_STYLE_FLAT              ((sal_uInt16)0x0004) // from <vcl/toolbox.hxx>
      70             : 
      71             : class SvtMiscOptions_Impl : public ConfigItem
      72             : {
      73             :     private:
      74             :     ::std::list<Link> aList;
      75             :     bool        m_bUseSystemFileDialog;
      76             :     bool        m_bIsUseSystemFileDialogRO;
      77             :     bool        m_bPluginsEnabled;
      78             :     bool        m_bIsPluginsEnabledRO;
      79             :     sal_Int16   m_nSymbolsSize;
      80             :     bool        m_bIsSymbolsSizeRO;
      81             :     bool        m_bIsSymbolsStyleRO;
      82             :     sal_Int16   m_nToolboxStyle;
      83             :     bool        m_bIsToolboxStyleRO;
      84             :     bool        m_bUseSystemPrintDialog;
      85             :     bool        m_bIsUseSystemPrintDialogRO;
      86             :     bool        m_bShowLinkWarningDialog;
      87             :     bool        m_bIsShowLinkWarningDialogRO;
      88             :     bool        m_bDisableUICustomization;
      89             :     bool        m_bAlwaysAllowSave;
      90             :     bool        m_bExperimentalMode;
      91             :     bool        m_bMacroRecorderMode;
      92             :     bool        m_bIconThemeWasSetAutomatically;
      93             : 
      94             :     public:
      95             : 
      96             :          SvtMiscOptions_Impl();
      97             :         virtual ~SvtMiscOptions_Impl();
      98             : 
      99             :         /*-****************************************************************************************************
     100             :             @short      called for notify of configmanager
     101             :             @descr      These method is called from the ConfigManager before application ends or from the
     102             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
     103             :                         internal values.
     104             : 
     105             :             @seealso    baseclass ConfigItem
     106             : 
     107             :             @param      "seqPropertyNames" is the list of properties which should be updated.
     108             :         *//*-*****************************************************************************************************/
     109             : 
     110             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
     111             : 
     112             :         /** loads required data from the configuration. It's called in the constructor to
     113             :          read all entries and form ::Notify to re-read changed settings
     114             : 
     115             :          */
     116             :         void Load( const Sequence< OUString >& rPropertyNames );
     117             : 
     118             :         /*-****************************************************************************************************
     119             :             @short      write changes to configuration
     120             :             @descr      These method writes the changed values into the sub tree
     121             :                         and should always called in our destructor to guarantee consistency of config data.
     122             : 
     123             :             @seealso    baseclass ConfigItem
     124             :         *//*-*****************************************************************************************************/
     125             : 
     126             :         virtual void Commit() SAL_OVERRIDE;
     127             : 
     128             : 
     129             :         //  public interface
     130             : 
     131             : 
     132          82 :         inline bool UseSystemFileDialog() const
     133          82 :         { return m_bUseSystemFileDialog; }
     134             : 
     135         160 :         inline void SetUseSystemFileDialog( bool bSet )
     136         160 :         {  m_bUseSystemFileDialog = bSet; SetModified(); }
     137             : 
     138           0 :         inline bool IsUseSystemFileDialogReadOnly() const
     139           0 :         { return m_bIsUseSystemFileDialogRO; }
     140             : 
     141        1363 :         inline bool DisableUICustomization() const
     142        1363 :         { return m_bDisableUICustomization; }
     143             : 
     144           0 :         inline void SetSaveAlwaysAllowed( bool bSet )
     145           0 :         { m_bAlwaysAllowSave = bSet; SetModified(); }
     146             : 
     147        1499 :         inline bool IsSaveAlwaysAllowed() const
     148        1499 :         { return m_bAlwaysAllowSave; }
     149             : 
     150           2 :         inline void SetExperimentalMode( bool bSet )
     151           2 :         { m_bExperimentalMode = bSet; SetModified(); }
     152             : 
     153         626 :         inline bool IsExperimentalMode() const
     154         626 :         { return m_bExperimentalMode; }
     155             : 
     156           0 :         inline void SetMacroRecorderMode( bool bSet )
     157           0 :         { m_bMacroRecorderMode = bSet; SetModified(); }
     158             : 
     159           0 :         inline bool IsMacroRecorderMode() const
     160           0 :         { return m_bMacroRecorderMode; }
     161             : 
     162           0 :         inline bool IsPluginsEnabled() const
     163           0 :         { return m_bPluginsEnabled; }
     164             : 
     165       10666 :         inline sal_Int16 GetSymbolsSize()
     166       10666 :         { return m_nSymbolsSize; }
     167             : 
     168             :         void SetSymbolsSize( sal_Int16 nSet );
     169             : 
     170             :         OUString GetIconTheme() const;
     171             : 
     172             :         enum SetModifiedFlag { SET_MODIFIED, DONT_SET_MODIFIED };
     173             : 
     174             :         /** Set the icon theme
     175             :          *
     176             :          * @param theme
     177             :          * The name of the icon theme to use.
     178             :          *
     179             :          * @param setModified
     180             :          * Whether to call SetModified() and CallListeners().
     181             :          *
     182             :          * @internal
     183             :          * The @p setModified flag was introduced because the unittests fail if we call SetModified()
     184             :          * during initialization in the constructor.
     185             :          */
     186             :         void
     187             :         SetIconTheme(const OUString &theme, SetModifiedFlag setModified = SET_MODIFIED );
     188             : 
     189           0 :         bool IconThemeWasSetAutomatically()
     190           0 :         {return m_bIconThemeWasSetAutomatically;}
     191             : 
     192             :         /** Set the icon theme automatically by detecting the best theme for the desktop environment.
     193             :          * The parameter setModified controls whether SetModified() will be called.
     194             :          */
     195             :         void SetIconThemeAutomatically(SetModifiedFlag = SET_MODIFIED);
     196             : 
     197             :         // translate to VCL settings ( "0" = 3D, "1" = FLAT )
     198        6103 :         inline sal_Int16 GetToolboxStyle()
     199        6103 :         { return m_nToolboxStyle ? VCL_TOOLBOX_STYLE_FLAT : 0; }
     200             : 
     201             :         // translate from VCL settings
     202             :         void SetToolboxStyle( sal_Int16 nStyle, bool _bSetModified );
     203             : 
     204           0 :         inline bool UseSystemPrintDialog() const
     205           0 :         { return m_bUseSystemPrintDialog; }
     206             : 
     207           0 :         inline void SetUseSystemPrintDialog( bool bSet )
     208           0 :         {  m_bUseSystemPrintDialog = bSet; SetModified(); }
     209             : 
     210           0 :         inline bool ShowLinkWarningDialog() const
     211           0 :         { return m_bShowLinkWarningDialog; }
     212             : 
     213           0 :         void SetShowLinkWarningDialog( bool bSet )
     214           0 :         {  m_bShowLinkWarningDialog = bSet; SetModified(); }
     215             : 
     216           0 :         bool IsShowLinkWarningDialogReadOnly() const
     217           0 :         { return m_bIsShowLinkWarningDialogRO; }
     218             : 
     219             :         void AddListenerLink( const Link& rLink );
     220             :         void RemoveListenerLink( const Link& rLink );
     221             :         void CallListeners();
     222             : 
     223             : 
     224             :     //  private methods
     225             : 
     226             : 
     227             :     private:
     228             : 
     229             :         /*-****************************************************************************************************
     230             :             @short      return list of key names of our configuration management which represent oue module tree
     231             :             @descr      These methods return a static const list of key names. We need it to get needed values from our
     232             :                         configuration management.
     233             :             @return     A list of needed configuration keys is returned.
     234             :         *//*-*****************************************************************************************************/
     235             : 
     236             :         static Sequence< OUString > GetPropertyNames();
     237             : };
     238             : 
     239             : 
     240             : //  constructor
     241             : 
     242         124 : SvtMiscOptions_Impl::SvtMiscOptions_Impl()
     243             :     // Init baseclasses first
     244             :     : ConfigItem( ROOTNODE_MISC )
     245             : 
     246             :     , m_bUseSystemFileDialog( false )
     247             :     , m_bIsUseSystemFileDialogRO( false )
     248             :     , m_bPluginsEnabled( false )
     249             :     , m_bIsPluginsEnabledRO( false )
     250             :     , m_nSymbolsSize( 0 )
     251             :     , m_bIsSymbolsSizeRO( false )
     252             :     , m_bIsSymbolsStyleRO( false )
     253             :     , m_nToolboxStyle( 1 )
     254             :     , m_bIsToolboxStyleRO( false )
     255             :     , m_bUseSystemPrintDialog( false )
     256             :     , m_bIsUseSystemPrintDialogRO( false )
     257             :     , m_bShowLinkWarningDialog( true )
     258             :     , m_bIsShowLinkWarningDialogRO( false )
     259             :     , m_bAlwaysAllowSave( false )
     260             :     , m_bExperimentalMode( false )
     261             :     , m_bMacroRecorderMode( false )
     262         124 :     , m_bIconThemeWasSetAutomatically( false )
     263             : {
     264             :     // Use our static list of configuration keys to get his values.
     265         124 :     Sequence< OUString >    seqNames    = GetPropertyNames  (           );
     266         124 :     Load( seqNames );
     267         248 :     Sequence< Any >         seqValues   = GetProperties     ( seqNames  );
     268         248 :     Sequence< sal_Bool >    seqRO       = GetReadOnlyStates ( seqNames  );
     269             : 
     270             :     // Safe impossible cases.
     271             :     // We need values from ALL configuration keys.
     272             :     // Follow assignment use order of values in relation to our list of key names!
     273             :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtMiscOptions_Impl::SvtMiscOptions_Impl()\nI miss some values of configuration keys!\n" );
     274             : 
     275             :     // Copy values from list in right order to our internal member.
     276         124 :     sal_Int32 nPropertyCount = seqValues.getLength();
     277        1488 :     for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
     278             :     {
     279        1364 :         if (!seqValues[nProperty].hasValue())
     280           0 :             continue;
     281        1364 :         switch( nProperty )
     282             :         {
     283             :             case PROPERTYHANDLE_PLUGINSENABLED :
     284             :             {
     285         124 :                 if( !(seqValues[nProperty] >>= m_bPluginsEnabled) )
     286             :                 {
     287             :                     OSL_FAIL("Wrong type of \"Misc\\PluginsEnabled\"!" );
     288             :                 }
     289         124 :                 m_bIsPluginsEnabledRO = seqRO[nProperty];
     290         124 :                 break;
     291             :             }
     292             : 
     293             :             case PROPERTYHANDLE_SYMBOLSET :
     294             :             {
     295         124 :                 if( !(seqValues[nProperty] >>= m_nSymbolsSize) )
     296             :                 {
     297             :                     OSL_FAIL("Wrong type of \"Misc\\SymbolSet\"!" );
     298             :                 }
     299         124 :                 m_bIsSymbolsSizeRO = seqRO[nProperty];
     300         124 :                 break;
     301             :             }
     302             : 
     303             :             case PROPERTYHANDLE_TOOLBOXSTYLE :
     304             :             {
     305         124 :                 if( !(seqValues[nProperty] >>= m_nToolboxStyle) )
     306             :                 {
     307             :                     OSL_FAIL("Wrong type of \"Misc\\ToolboxStyle\"!" );
     308             :                 }
     309         124 :                 m_bIsToolboxStyleRO = seqRO[nProperty];
     310         124 :                 break;
     311             :             }
     312             : 
     313             :             case PROPERTYHANDLE_USESYSTEMFILEDIALOG :
     314             :             {
     315         124 :                 if( !(seqValues[nProperty] >>= m_bUseSystemFileDialog) )
     316             :                 {
     317             :                     OSL_FAIL("Wrong type of \"Misc\\UseSystemFileDialog\"!" );
     318             :                 }
     319         124 :                 m_bIsUseSystemFileDialogRO = seqRO[nProperty];
     320         124 :                 break;
     321             :             }
     322             : 
     323             :             case PROPERTYHANDLE_USESYSTEMPRINTDIALOG :
     324             :             {
     325         124 :                 if( !(seqValues[nProperty] >>= m_bUseSystemPrintDialog) )
     326             :                 {
     327             :                     OSL_FAIL("Wrong type of \"Misc\\UseSystemPrintDialog\"!" );
     328             :                 }
     329         124 :                 m_bIsUseSystemPrintDialogRO = seqRO[nProperty];
     330         124 :                 break;
     331             :             }
     332             : 
     333             :             case PROPERTYHANDLE_SHOWLINKWARNINGDIALOG :
     334             :             {
     335         124 :                 if( !(seqValues[nProperty] >>= m_bShowLinkWarningDialog) )
     336             :                 {
     337             :                     OSL_FAIL("Wrong type of \"Misc\\ShowLinkWarningDialog\"!" );
     338             :                 }
     339         124 :                 m_bIsShowLinkWarningDialogRO = seqRO[nProperty];
     340         124 :                 break;
     341             :             }
     342             : 
     343             :             case PROPERTYHANDLE_SYMBOLSTYLE :
     344             :             {
     345         124 :                 OUString aIconTheme;
     346         124 :                 if( seqValues[nProperty] >>= aIconTheme ) {
     347         124 :                     if (aIconTheme == "auto") {
     348         124 :                         SetIconThemeAutomatically(DONT_SET_MODIFIED);
     349             :                     }
     350             :                     else {
     351           0 :                         SetIconTheme(aIconTheme, DONT_SET_MODIFIED);
     352             :                     }
     353             :                 }
     354             :                 else
     355             :                 {
     356             :                     OSL_FAIL("Wrong type of \"Misc\\SymbolStyle\"!" );
     357             :                 }
     358         124 :                 m_bIsSymbolsStyleRO = seqRO[nProperty];
     359         124 :                 break;
     360             :             }
     361             : 
     362             :             case PROPERTYHANDLE_DISABLEUICUSTOMIZATION :
     363             :             {
     364         124 :                 if( !(seqValues[nProperty] >>= m_bDisableUICustomization) )
     365             :                     OSL_FAIL("Wrong type of \"Misc\\DisableUICustomization\"!" );
     366         124 :                 break;
     367             :             }
     368             :             case PROPERTYHANDLE_ALWAYSALLOWSAVE :
     369             :             {
     370         124 :                 if( !(seqValues[nProperty] >>= m_bAlwaysAllowSave) )
     371             :                     OSL_FAIL("Wrong type of \"Misc\\AlwaysAllowSave\"!" );
     372         124 :                 break;
     373             :             }
     374             :             case PROPERTYHANDLE_EXPERIMENTALMODE :
     375             :             {
     376         124 :                 if( !(seqValues[nProperty] >>= m_bExperimentalMode) )
     377             :                     OSL_FAIL("Wrong type of \"Misc\\ExperimentalMode\"!" );
     378         124 :                 break;
     379             :             }
     380             :             case PROPERTYHANDLE_MACRORECORDERMODE :
     381             :             {
     382         124 :                 if( !(seqValues[nProperty] >>= m_bMacroRecorderMode) )
     383             :                     OSL_FAIL("Wrong type of \"Misc\\MacroRecorderMode\"!" );
     384         124 :                 break;
     385             :             }
     386             :         }
     387             :     }
     388             : 
     389             :     // Enable notification mechanism of our baseclass.
     390             :     // We need it to get information about changes outside these class on our used configuration keys!
     391         248 :     EnableNotification( seqNames );
     392         124 : }
     393             : 
     394             : 
     395             : //  destructor
     396             : 
     397         366 : SvtMiscOptions_Impl::~SvtMiscOptions_Impl()
     398             : {
     399             :     // We must save our current values .. if user forgets it!
     400         122 :     if( IsModified() )
     401             :     {
     402           1 :         Commit();
     403             :     }
     404         244 : }
     405             : 
     406        1364 : static int lcl_MapPropertyName( const OUString& rCompare,
     407             :                 const uno::Sequence< OUString>& aInternalPropertyNames)
     408             : {
     409        8184 :     for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
     410             :     {
     411        8184 :         if( aInternalPropertyNames[nProp] == rCompare )
     412        1364 :             return nProp;
     413             :     }
     414           0 :     return -1;
     415             : }
     416             : 
     417         124 : void SvtMiscOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
     418             : {
     419         124 :     const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
     420         248 :     Sequence< Any > seqValues = GetProperties( rPropertyNames  );
     421             : 
     422             :     // Safe impossible cases.
     423             :     // We need values from ALL configuration keys.
     424             :     // Follow assignment use order of values in relation to our list of key names!
     425             :     DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()), "SvtSecurityOptions_Impl::SvtSecurityOptions_Impl()\nI miss some values of configuration keys!\n" );
     426             : 
     427             :     // Copy values from list in right order to our internal member.
     428         124 :     sal_Int32 nPropertyCount = seqValues.getLength();
     429        1488 :     for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
     430             :     {
     431        1364 :         if (!seqValues[nProperty].hasValue())
     432           0 :             continue;
     433        1364 :         switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
     434             :         {
     435             :             case PROPERTYHANDLE_PLUGINSENABLED      :   {
     436         124 :                                                             if( !(seqValues[nProperty] >>= m_bPluginsEnabled) )
     437             :                                                             {
     438             :                                                                 OSL_FAIL("Wrong type of \"Misc\\PluginsEnabled\"!" );
     439             :                                                             }
     440             :                                                         }
     441         124 :                                                     break;
     442             :             case PROPERTYHANDLE_SYMBOLSET           :   {
     443         124 :                                                             if( !(seqValues[nProperty] >>= m_nSymbolsSize) )
     444             :                                                             {
     445             :                                                                 OSL_FAIL("Wrong type of \"Misc\\SymbolSet\"!" );
     446             :                                                             }
     447             :                                                         }
     448         124 :                                                     break;
     449             :             case PROPERTYHANDLE_TOOLBOXSTYLE        :   {
     450         124 :                                                             if( !(seqValues[nProperty] >>= m_nToolboxStyle) )
     451             :                                                             {
     452             :                                                                 OSL_FAIL("Wrong type of \"Misc\\ToolboxStyle\"!" );
     453             :                                                             }
     454             :                                                         }
     455         124 :                                                     break;
     456             :             case PROPERTYHANDLE_USESYSTEMFILEDIALOG      :   {
     457         124 :                                                             if( !(seqValues[nProperty] >>= m_bUseSystemFileDialog) )
     458             :                                                             {
     459             :                                                                 OSL_FAIL("Wrong type of \"Misc\\UseSystemFileDialog\"!" );
     460             :                                                             }
     461             :                                                         }
     462         124 :                                                     break;
     463             :             case PROPERTYHANDLE_USESYSTEMPRINTDIALOG     :   {
     464         124 :                                                             if( !(seqValues[nProperty] >>= m_bUseSystemPrintDialog) )
     465             :                                                             {
     466             :                                                                 OSL_FAIL("Wrong type of \"Misc\\UseSystemPrintDialog\"!" );
     467             :                                                             }
     468             :                                                         }
     469         124 :                                                     break;
     470             :             case PROPERTYHANDLE_SHOWLINKWARNINGDIALOG     :   {
     471         124 :                                                             if( !(seqValues[nProperty] >>= m_bShowLinkWarningDialog) )
     472             :                                                             {
     473             :                                                                 OSL_FAIL("Wrong type of \"Misc\\ShowLinkWarningDialog\"!" );
     474             :                                                             }
     475             :                                                         }
     476         124 :                                                     break;
     477             :             case PROPERTYHANDLE_SYMBOLSTYLE         :   {
     478         124 :                                                             OUString aIconTheme;
     479         124 :                                                             if( seqValues[nProperty] >>= aIconTheme ) {
     480         124 :                                                                 if (aIconTheme == "auto") {
     481         124 :                                                                     SetIconThemeAutomatically(DONT_SET_MODIFIED);
     482             :                                                                 }
     483             :                                                                 else {
     484           0 :                                                                     SetIconTheme(aIconTheme, DONT_SET_MODIFIED);
     485             :                                                                 }
     486             :                                                             }
     487             :                                                             else {
     488             :                                                                 OSL_FAIL("Wrong type of \"Misc\\SymbolStyle\"!" );
     489         124 :                                                             }
     490             :                                                         }
     491         124 :                                                     break;
     492             :             case PROPERTYHANDLE_DISABLEUICUSTOMIZATION      :   {
     493         124 :                                                             if( !(seqValues[nProperty] >>= m_bDisableUICustomization) )
     494             :                                                                 OSL_FAIL("Wrong type of \"Misc\\DisableUICustomization\"!" );
     495             :                                                         }
     496         124 :                                                     break;
     497             :             case PROPERTYHANDLE_ALWAYSALLOWSAVE:
     498             :             {
     499         124 :                 if( !(seqValues[nProperty] >>= m_bAlwaysAllowSave) )
     500             :                     OSL_FAIL("Wrong type of \"Misc\\AlwaysAllowSave\"!" );
     501             :             }
     502         124 :             break;
     503             :         }
     504         124 :     }
     505         124 : }
     506             : 
     507        6130 : void SvtMiscOptions_Impl::AddListenerLink( const Link& rLink )
     508             : {
     509        6130 :     aList.push_back( rLink );
     510        6130 : }
     511             : 
     512        6116 : void SvtMiscOptions_Impl::RemoveListenerLink( const Link& rLink )
     513             : {
     514       11398 :     for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
     515             :     {
     516       11398 :         if ( *iter == rLink )
     517             :         {
     518        6116 :             aList.erase(iter);
     519        6116 :             break;
     520             :         }
     521             :     }
     522        6116 : }
     523             : 
     524         248 : void SvtMiscOptions_Impl::CallListeners()
     525             : {
     526         248 :     for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
     527           0 :         iter->Call( this );
     528         248 : }
     529             : 
     530           0 : void SvtMiscOptions_Impl::SetToolboxStyle( sal_Int16 nStyle, bool _bSetModified )
     531             : {
     532           0 :     m_nToolboxStyle = nStyle ? 1 : 0;
     533           0 :     if ( _bSetModified )
     534           0 :         SetModified();
     535           0 :     CallListeners();
     536           0 : }
     537             : 
     538           0 : void SvtMiscOptions_Impl::SetSymbolsSize( sal_Int16 nSet )
     539             : {
     540           0 :     m_nSymbolsSize = nSet;
     541           0 :     SetModified();
     542           0 :     CallListeners();
     543           0 : }
     544             : 
     545       77594 : OUString SvtMiscOptions_Impl::GetIconTheme() const
     546             : {
     547       77594 :     return Application::GetSettings().GetStyleSettings().DetermineIconTheme();
     548             : }
     549             : 
     550             : void
     551         248 : SvtMiscOptions_Impl::SetIconTheme(const OUString &rName, SetModifiedFlag setModified)
     552             : {
     553         248 :     AllSettings aAllSettings = Application::GetSettings();
     554         496 :     StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
     555         248 :     aStyleSettings.SetIconTheme( rName );
     556         248 :     m_bIconThemeWasSetAutomatically = false;
     557             : 
     558         248 :     aAllSettings.SetStyleSettings(aStyleSettings);
     559         248 :     Application::MergeSystemSettings( aAllSettings );
     560         248 :     Application::SetSettings(aAllSettings);
     561             : 
     562         248 :     if (setModified == SET_MODIFIED) {
     563           0 :         SetModified();
     564             :     }
     565         496 :     CallListeners();
     566         248 : }
     567             : 
     568             : 
     569             : //  public method
     570             : 
     571           0 : void SvtMiscOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
     572             : {
     573           0 :     Load( rPropertyNames );
     574           0 :     CallListeners();
     575           0 : }
     576             : 
     577             : 
     578             : //  public method
     579             : 
     580         161 : void SvtMiscOptions_Impl::Commit()
     581             : {
     582             :     // Get names of supported properties, create a list for values and copy current values to it.
     583         161 :     Sequence< OUString >    seqNames    = GetPropertyNames  ();
     584         161 :     sal_Int32               nCount      = seqNames.getLength();
     585         322 :     Sequence< Any >         seqValues   ( nCount );
     586        1932 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     587             :     {
     588        1771 :         switch( nProperty )
     589             :         {
     590             :             case PROPERTYHANDLE_PLUGINSENABLED :
     591             :             {
     592         161 :                 if ( !m_bIsPluginsEnabledRO )
     593         161 :                     seqValues[nProperty] <<= m_bPluginsEnabled;
     594         161 :                 break;
     595             :             }
     596             : 
     597             :             case PROPERTYHANDLE_SYMBOLSET :
     598             :             {
     599         161 :                 if ( !m_bIsSymbolsSizeRO )
     600         161 :                    seqValues[nProperty] <<= m_nSymbolsSize;
     601         161 :                 break;
     602             :             }
     603             : 
     604             :             case PROPERTYHANDLE_TOOLBOXSTYLE :
     605             :             {
     606         161 :                 if ( !m_bIsToolboxStyleRO )
     607         161 :                     seqValues[nProperty] <<= m_nToolboxStyle;
     608         161 :                 break;
     609             :             }
     610             : 
     611             :             case PROPERTYHANDLE_USESYSTEMFILEDIALOG :
     612             :             {
     613         161 :                 if ( !m_bIsUseSystemFileDialogRO )
     614         161 :                     seqValues[nProperty] <<= m_bUseSystemFileDialog;
     615         161 :                 break;
     616             :             }
     617             : 
     618             :             case PROPERTYHANDLE_SYMBOLSTYLE :
     619             :             {
     620         161 :                 if ( !m_bIsSymbolsStyleRO ) {
     621         161 :                     OUString value;
     622         161 :                     if (m_bIconThemeWasSetAutomatically) {
     623         161 :                         value = "auto";
     624             :                     }
     625             :                     else {
     626           0 :                         value = GetIconTheme();
     627             :                     }
     628         161 :                     seqValues[nProperty] <<= value;
     629             :                 }
     630         161 :                 break;
     631             :             }
     632             : 
     633             :             case PROPERTYHANDLE_USESYSTEMPRINTDIALOG :
     634             :             {
     635         161 :                 if ( !m_bIsUseSystemPrintDialogRO )
     636         161 :                     seqValues[nProperty] <<= m_bUseSystemPrintDialog;
     637         161 :                 break;
     638             :             }
     639             : 
     640             :             case PROPERTYHANDLE_SHOWLINKWARNINGDIALOG :
     641             :             {
     642         161 :                 if ( !m_bIsShowLinkWarningDialogRO )
     643         161 :                     seqValues[nProperty] <<= m_bShowLinkWarningDialog;
     644         161 :                 break;
     645             :             }
     646             : 
     647             :             case PROPERTYHANDLE_DISABLEUICUSTOMIZATION :
     648             :             {
     649         161 :                 seqValues[nProperty] <<= m_bDisableUICustomization;
     650         161 :                 break;
     651             :             }
     652             :             case PROPERTYHANDLE_ALWAYSALLOWSAVE :
     653             :             {
     654         161 :                 seqValues[nProperty] <<= m_bAlwaysAllowSave;
     655         161 :                 break;
     656             :             }
     657             :             case PROPERTYHANDLE_EXPERIMENTALMODE :
     658             :             {
     659         161 :                 seqValues[nProperty] <<= m_bExperimentalMode;
     660         161 :                 break;
     661             :             }
     662             :             case PROPERTYHANDLE_MACRORECORDERMODE :
     663             :             {
     664         161 :                 seqValues[nProperty] <<= m_bMacroRecorderMode;
     665         161 :                 break;
     666             :             }
     667             :         }
     668             :     }
     669             :     // Set properties in configuration.
     670         322 :     PutProperties( seqNames, seqValues );
     671         161 : }
     672             : 
     673             : 
     674             : //  private method
     675             : 
     676         409 : Sequence< OUString > SvtMiscOptions_Impl::GetPropertyNames()
     677             : {
     678             :     // Build list of configuration key names.
     679             :     const OUString pProperties[] =
     680             :     {
     681             :         OUString(PROPERTYNAME_PLUGINSENABLED),
     682             :         OUString(PROPERTYNAME_SYMBOLSET),
     683             :         OUString(PROPERTYNAME_TOOLBOXSTYLE),
     684             :         OUString(PROPERTYNAME_USESYSTEMFILEDIALOG),
     685             :         OUString(PROPERTYNAME_ICONTHEME),
     686             :         OUString(PROPERTYNAME_USESYSTEMPRINTDIALOG),
     687             :         OUString(PROPERTYNAME_SHOWLINKWARNINGDIALOG),
     688             :         OUString(PROPERTYNAME_DISABLEUICUSTOMIZATION),
     689             :         OUString(PROPERTYNAME_ALWAYSALLOWSAVE),
     690             :         OUString(PROPERTYNAME_EXPERIMENTALMODE),
     691             :         OUString(PROPERTYNAME_MACRORECORDERMODE)
     692        4908 :     };
     693             : 
     694             :     // Initialize return sequence with these list ...
     695         409 :     const Sequence< OUString > seqPropertyNames( pProperties, SAL_N_ELEMENTS( pProperties ) );
     696             :     // ... and return it.
     697        4908 :     return seqPropertyNames;
     698             : }
     699             : 
     700             : 
     701             : //  initialize static member
     702             : //  DON'T DO IT IN YOUR HEADER!
     703             : //  see definition for further information
     704             : 
     705             : SvtMiscOptions_Impl*    SvtMiscOptions::m_pDataContainer    = NULL  ;
     706             : sal_Int32               SvtMiscOptions::m_nRefCount = 0     ;
     707             : 
     708             : 
     709             : //  constructor
     710             : 
     711      109783 : SvtMiscOptions::SvtMiscOptions()
     712             : {
     713             :     // SvtMiscOptions_Impl ctor indirectly calls code that requires locked
     714             :     // SolarMutex; lock it first:
     715      109783 :     SolarMutexGuard g;
     716             :     // Global access, must be guarded (multithreading!).
     717      219566 :     MutexGuard aGuard( GetInitMutex() );
     718             :     // Increase our refcount ...
     719      109783 :     ++m_nRefCount;
     720             :     // ... and initialize our data container only if it not already exist!
     721      109783 :     if( m_pDataContainer == NULL )
     722             :     {
     723         124 :        m_pDataContainer = new SvtMiscOptions_Impl;
     724         124 :        svtools::ItemHolder2::holdConfigItem(E_MISCOPTIONS);
     725      109783 :     }
     726      109783 : }
     727             : 
     728             : 
     729             : //  destructor
     730             : 
     731      219679 : SvtMiscOptions::~SvtMiscOptions()
     732             : {
     733             :     // Global access, must be guarded (multithreading!)
     734      109778 :     MutexGuard aGuard( GetInitMutex() );
     735             :     // Decrease our refcount.
     736      109778 :     --m_nRefCount;
     737             :     // If last instance was deleted ...
     738             :     // we must destroy our static data container!
     739      109778 :     if( m_nRefCount <= 0 )
     740             :     {
     741         122 :         delete m_pDataContainer;
     742         122 :         m_pDataContainer = NULL;
     743      109778 :     }
     744      109901 : }
     745             : 
     746          82 : bool SvtMiscOptions::UseSystemFileDialog() const
     747             : {
     748          82 :     return m_pDataContainer->UseSystemFileDialog();
     749             : }
     750             : 
     751         160 : void SvtMiscOptions::SetUseSystemFileDialog( bool bEnable )
     752             : {
     753         160 :     m_pDataContainer->SetUseSystemFileDialog( bEnable );
     754         160 : }
     755             : 
     756           0 : bool SvtMiscOptions::IsUseSystemFileDialogReadOnly() const
     757             : {
     758           0 :     return m_pDataContainer->IsUseSystemFileDialogReadOnly();
     759             : }
     760             : 
     761           0 : bool SvtMiscOptions::IsPluginsEnabled() const
     762             : {
     763           0 :     return m_pDataContainer->IsPluginsEnabled();
     764             : }
     765             : 
     766           0 : sal_Int16 SvtMiscOptions::GetSymbolsSize() const
     767             : {
     768           0 :     return m_pDataContainer->GetSymbolsSize();
     769             : }
     770             : 
     771           0 : void SvtMiscOptions::SetSymbolsSize( sal_Int16 nSet )
     772             : {
     773           0 :     m_pDataContainer->SetSymbolsSize( nSet );
     774           0 : }
     775             : 
     776       10666 : sal_Int16 SvtMiscOptions::GetCurrentSymbolsSize() const
     777             : {
     778       10666 :     sal_Int16 eOptSymbolsSize = m_pDataContainer->GetSymbolsSize();
     779             : 
     780       10666 :     if ( eOptSymbolsSize == SFX_SYMBOLS_SIZE_AUTO )
     781             :     {
     782             :         // Use system settings, we have to retrieve the toolbar icon size from the
     783             :         // Application class
     784       10666 :         sal_uLong nStyleIconSize = Application::GetSettings().GetStyleSettings().GetToolbarIconSize();
     785       10666 :         if ( nStyleIconSize == STYLE_TOOLBAR_ICONSIZE_LARGE )
     786           0 :             eOptSymbolsSize = SFX_SYMBOLS_SIZE_LARGE;
     787             :         else
     788       10666 :             eOptSymbolsSize = SFX_SYMBOLS_SIZE_SMALL;
     789             :     }
     790             : 
     791       10666 :     return eOptSymbolsSize;
     792             : }
     793             : 
     794       10639 : bool SvtMiscOptions::AreCurrentSymbolsLarge() const
     795             : {
     796       10639 :     return ( GetCurrentSymbolsSize() == SFX_SYMBOLS_SIZE_LARGE );
     797             : }
     798             : 
     799       77594 : OUString SvtMiscOptions::GetIconTheme() const
     800             : {
     801       77594 :     return m_pDataContainer->GetIconTheme();
     802             : }
     803             : 
     804           0 : void SvtMiscOptions::SetIconTheme(const OUString& iconTheme)
     805             : {
     806           0 :     m_pDataContainer->SetIconTheme(iconTheme);
     807           0 : }
     808             : 
     809        1363 : bool SvtMiscOptions::DisableUICustomization() const
     810             : {
     811        1363 :     return m_pDataContainer->DisableUICustomization();
     812             : }
     813             : 
     814        6103 : sal_Int16 SvtMiscOptions::GetToolboxStyle() const
     815             : {
     816        6103 :     return m_pDataContainer->GetToolboxStyle();
     817             : }
     818             : 
     819           0 : void SvtMiscOptions::SetToolboxStyle( sal_Int16 nStyle )
     820             : {
     821           0 :     m_pDataContainer->SetToolboxStyle( nStyle, true );
     822           0 : }
     823             : 
     824           0 : bool SvtMiscOptions::UseSystemPrintDialog() const
     825             : {
     826           0 :     return m_pDataContainer->UseSystemPrintDialog();
     827             : }
     828             : 
     829           0 : void SvtMiscOptions::SetUseSystemPrintDialog( bool bEnable )
     830             : {
     831           0 :     m_pDataContainer->SetUseSystemPrintDialog( bEnable );
     832           0 : }
     833             : 
     834           0 : bool SvtMiscOptions::ShowLinkWarningDialog() const
     835             : {
     836           0 :     return m_pDataContainer->ShowLinkWarningDialog();
     837             : }
     838             : 
     839           0 : void SvtMiscOptions::SetShowLinkWarningDialog( bool bSet )
     840             : {
     841           0 :     m_pDataContainer->SetShowLinkWarningDialog( bSet );
     842           0 : }
     843             : 
     844           0 : bool SvtMiscOptions::IsShowLinkWarningDialogReadOnly() const
     845             : {
     846           0 :     return m_pDataContainer->IsShowLinkWarningDialogReadOnly();
     847             : }
     848             : 
     849           0 : void SvtMiscOptions::SetSaveAlwaysAllowed( bool bSet )
     850             : {
     851           0 :     m_pDataContainer->SetSaveAlwaysAllowed( bSet );
     852           0 : }
     853             : 
     854        1499 : bool SvtMiscOptions::IsSaveAlwaysAllowed() const
     855             : {
     856        1499 :     return m_pDataContainer->IsSaveAlwaysAllowed();
     857             : }
     858             : 
     859           2 : void SvtMiscOptions::SetExperimentalMode( bool bSet )
     860             : {
     861           2 :     m_pDataContainer->SetExperimentalMode( bSet );
     862           2 : }
     863             : 
     864         626 : bool SvtMiscOptions::IsExperimentalMode() const
     865             : {
     866         626 :     return m_pDataContainer->IsExperimentalMode();
     867             : }
     868             : 
     869           0 : void SvtMiscOptions::SetMacroRecorderMode( bool bSet )
     870             : {
     871           0 :     m_pDataContainer->SetMacroRecorderMode( bSet );
     872           0 : }
     873             : 
     874           0 : bool SvtMiscOptions::IsMacroRecorderMode() const
     875             : {
     876           0 :     return m_pDataContainer->IsMacroRecorderMode();
     877             : }
     878             : 
     879             : namespace
     880             : {
     881             :     class theSvtMiscOptionsMutex :
     882             :         public rtl::Static< osl::Mutex, theSvtMiscOptionsMutex > {};
     883             : }
     884             : 
     885      219561 : Mutex & SvtMiscOptions::GetInitMutex()
     886             : {
     887      219561 :     return theSvtMiscOptionsMutex::get();
     888             : }
     889             : 
     890        6130 : void SvtMiscOptions::AddListenerLink( const Link& rLink )
     891             : {
     892        6130 :     m_pDataContainer->AddListenerLink( rLink );
     893        6130 : }
     894             : 
     895        6116 : void SvtMiscOptions::RemoveListenerLink( const Link& rLink )
     896             : {
     897        6116 :     m_pDataContainer->RemoveListenerLink( rLink );
     898        6116 : }
     899             : 
     900             : void
     901         248 : SvtMiscOptions_Impl::SetIconThemeAutomatically(enum SetModifiedFlag setModified)
     902             : {
     903         248 :     OUString theme = Application::GetSettings().GetStyleSettings().GetAutomaticallyChosenIconTheme();
     904         248 :     SetIconTheme(theme, setModified);
     905         248 :     m_bIconThemeWasSetAutomatically = true;
     906         248 : }
     907             : 
     908             : void
     909           0 : SvtMiscOptions::SetIconThemeAutomatically()
     910             : {
     911           0 :     m_pDataContainer->SetIconThemeAutomatically();
     912           0 : }
     913             : 
     914             : bool
     915           0 : SvtMiscOptions::IconThemeWasSetAutomatically()
     916             : {
     917           0 :     return m_pDataContainer->IconThemeWasSetAutomatically();
     918             : }
     919             : 
     920             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10