LCOV - code coverage report
Current view: top level - svtools/source/config - menuoptions.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 137 0.0 %
Date: 2014-04-14 Functions: 0 21 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 <svtools/menuoptions.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             : #include <vcl/svapp.hxx>
      28             : #include <vcl/settings.hxx>
      29             : 
      30             : #include "itemholder2.hxx"
      31             : 
      32             : #include <list>
      33             : 
      34             : 
      35             : //  namespaces
      36             : 
      37             : 
      38             : using namespace ::utl                   ;
      39             : using namespace ::rtl                   ;
      40             : using namespace ::osl                   ;
      41             : using namespace ::com::sun::star::uno   ;
      42             : 
      43             : #define ROOTNODE_MENU                           OUString("Office.Common/View/Menu"  )
      44             : #define DEFAULT_DONTHIDEDISABLEDENTRIES         false
      45             : #define DEFAULT_FOLLOWMOUSE                     true
      46             : #define DEFAULT_MENUICONS                       TRISTATE_INDET
      47             : 
      48             : #define PROPERTYNAME_DONTHIDEDISABLEDENTRIES    OUString("DontHideDisabledEntry"    )
      49             : #define PROPERTYNAME_FOLLOWMOUSE                OUString("FollowMouse"              )
      50             : #define PROPERTYNAME_SHOWICONSINMENUES          OUString("ShowIconsInMenues"        )
      51             : #define PROPERTYNAME_SYSTEMICONSINMENUES        OUString("IsSystemIconsInMenus"     )
      52             : 
      53             : #define PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES  0
      54             : #define PROPERTYHANDLE_FOLLOWMOUSE              1
      55             : #define PROPERTYHANDLE_SHOWICONSINMENUES        2
      56             : #define PROPERTYHANDLE_SYSTEMICONSINMENUES      3
      57             : 
      58             : #define PROPERTYCOUNT                           4
      59             : 
      60             : #include <tools/link.hxx>
      61             : 
      62             : 
      63             : //  private declarations!
      64             : 
      65             : 
      66             : class SvtMenuOptions_Impl : public ConfigItem
      67             : {
      68             : 
      69             :     //  private member
      70             : 
      71             : 
      72             :     private:
      73             :         ::std::list<Link> aList;
      74             :         bool        m_bDontHideDisabledEntries          ;   /// cache "DontHideDisabledEntries" of Menu section
      75             :         bool        m_bFollowMouse                      ;   /// cache "FollowMouse" of Menu section
      76             :         TriState    m_eMenuIcons                        ;   /// cache "MenuIcons" of Menu section
      77             : 
      78             : 
      79             :     //  public methods
      80             : 
      81             : 
      82             :     public:
      83             : 
      84             : 
      85             :         //  constructor / destructor
      86             : 
      87             : 
      88             :          SvtMenuOptions_Impl();
      89             :         virtual ~SvtMenuOptions_Impl();
      90             : 
      91             :         void AddListenerLink( const Link& rLink );
      92             :         void RemoveListenerLink( const Link& rLink );
      93             : 
      94             : 
      95             :         //  overloaded methods of baseclass
      96             : 
      97             : 
      98             :         /*-****************************************************************************************************
      99             :             @short      called for notify of configmanager
     100             :             @descr      These method is called from the ConfigManager before application ends or from the
     101             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
     102             :                         internal values.
     103             : 
     104             :             @seealso    baseclass ConfigItem
     105             : 
     106             :             @param      "seqPropertyNames" is the list of properties which should be updated.
     107             :         *//*-*****************************************************************************************************/
     108             : 
     109             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
     110             : 
     111             :         /*-****************************************************************************************************
     112             :             @short      write changes to configuration
     113             :             @descr      These method writes the changed values into the sub tree
     114             :                         and should always called in our destructor to guarantee consistency of config data.
     115             : 
     116             :             @seealso    baseclass ConfigItem
     117             :         *//*-*****************************************************************************************************/
     118             : 
     119             :         virtual void Commit() SAL_OVERRIDE;
     120             : 
     121             : 
     122             :         //  public interface
     123             : 
     124             : 
     125             :         /*-****************************************************************************************************
     126             :             @short      access method to get internal values
     127             :             @descr      These methods give us a chance to regulate access to our internal values.
     128             :                         It's not used in the moment - but it's possible for the future!
     129             :         *//*-*****************************************************************************************************/
     130             : 
     131           0 :         bool        IsEntryHidingEnabled() const
     132           0 :                     { return m_bDontHideDisabledEntries; }
     133             : 
     134           0 :         TriState    GetMenuIconsState() const
     135           0 :                     { return m_eMenuIcons; }
     136             : 
     137           0 :         void        SetMenuIconsState(TriState eState)
     138             :                     {
     139           0 :                         m_eMenuIcons = eState;
     140           0 :                         SetModified();
     141           0 :                         for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
     142           0 :                             iter->Call( this );
     143           0 :                         Commit();
     144           0 :                     }
     145             : 
     146             : 
     147             :     //  private methods
     148             : 
     149             : 
     150             :     private:
     151             : 
     152             :         /*-****************************************************************************************************
     153             :             @short      return list of fix key names of our configuration management which represent our module tree
     154             :             @descr      These methods return a static const list of key names. We need it to get needed values from our
     155             :                         configuration management.
     156             :             @return     A list of needed configuration keys is returned.
     157             :         *//*-*****************************************************************************************************/
     158             : 
     159             :         static Sequence< OUString > impl_GetPropertyNames();
     160             : };
     161             : 
     162             : 
     163             : //  constructor
     164             : 
     165           0 : SvtMenuOptions_Impl::SvtMenuOptions_Impl()
     166             :     // Init baseclasses first
     167             :     :   ConfigItem                  ( ROOTNODE_MENU                     )
     168             :     // Init member then.
     169             :     ,   m_bDontHideDisabledEntries  ( DEFAULT_DONTHIDEDISABLEDENTRIES   )
     170             :     ,   m_bFollowMouse              ( DEFAULT_FOLLOWMOUSE               )
     171           0 :     ,   m_eMenuIcons                ( DEFAULT_MENUICONS                 )
     172             : {
     173             :     // Use our static list of configuration keys to get his values.
     174           0 :     Sequence< OUString >    seqNames    = impl_GetPropertyNames();
     175           0 :     Sequence< Any >         seqValues   = GetProperties( seqNames ) ;
     176             : 
     177             :     // Safe impossible cases.
     178             :     // We need values from ALL configuration keys.
     179             :     // Follow assignment use order of values in relation to our list of key names!
     180             :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nI miss some values of configuration keys!\n" );
     181             : 
     182           0 :     bool bMenuIcons = true;
     183           0 :     bool bSystemMenuIcons = true;
     184           0 :     if (m_eMenuIcons == TRISTATE_INDET)
     185           0 :         bMenuIcons = Application::GetSettings().GetStyleSettings().GetPreferredUseImagesInMenus();
     186             :     else
     187             :     {
     188           0 :         bSystemMenuIcons = false;
     189           0 :         bMenuIcons = m_eMenuIcons ? sal_True : sal_False;
     190             :     }
     191             : 
     192             :     // Copy values from list in right order to our internal member.
     193           0 :     sal_Int32 nPropertyCount    =   seqValues.getLength()   ;
     194           0 :     sal_Int32 nProperty         =   0                       ;
     195           0 :     for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
     196             :     {
     197             :         // Safe impossible cases.
     198             :         // Check any for valid value.
     199             :         DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nInvalid property value for property detected!\n" );
     200             : 
     201           0 :         if (!seqValues[nProperty].hasValue())
     202           0 :             continue;
     203             : 
     204           0 :         switch( nProperty )
     205             :         {
     206             :             case PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES :   {
     207             :                                                                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\DontHideDisabledEntry\"?" );
     208           0 :                                                                 seqValues[nProperty] >>= m_bDontHideDisabledEntries;
     209             :                                                             }
     210           0 :                                                             break;
     211             : 
     212             :             case PROPERTYHANDLE_FOLLOWMOUSE             :   {
     213             :                                                                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\FollowMouse\"?" );
     214           0 :                                                                 seqValues[nProperty] >>= m_bFollowMouse;
     215             :                                                             }
     216           0 :                                                             break;
     217             :             case PROPERTYHANDLE_SHOWICONSINMENUES       :   {
     218             :                                                                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShowIconsInMenues\"?" );
     219           0 :                                                                 seqValues[nProperty] >>= bMenuIcons;
     220             :                                                             }
     221           0 :                                                             break;
     222             :             case PROPERTYHANDLE_SYSTEMICONSINMENUES     :   {
     223             :                                                                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\IsSystemIconsInMenus\"?" );
     224           0 :                                                                 seqValues[nProperty] >>= bSystemMenuIcons;
     225             :                                                             }
     226           0 :                                                             break;
     227             :         }
     228             :     }
     229             : 
     230           0 :     m_eMenuIcons = bSystemMenuIcons ? TRISTATE_INDET : static_cast<TriState>(bMenuIcons);
     231             : 
     232           0 :     EnableNotification( seqNames );
     233           0 : }
     234             : 
     235             : 
     236             : //  destructor
     237             : 
     238           0 : SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
     239             : {
     240             :     // Flush data to configuration!
     241             :     // User has no chance to do that.
     242           0 :     if( IsModified() )
     243             :     {
     244           0 :         Commit();
     245             :     }
     246           0 : }
     247             : 
     248             : 
     249             : //  public method
     250             : 
     251           0 : void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
     252             : {
     253             :     // Use given list of updated properties to get his values from configuration directly!
     254           0 :     Sequence< Any > seqValues = GetProperties( seqPropertyNames );
     255             :     // Safe impossible cases.
     256             :     // We need values from ALL notified configuration keys.
     257             :     DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtMenuOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
     258             : 
     259           0 :     bool bMenuSettingsChanged = false;
     260           0 :     bool bMenuIcons = true;
     261           0 :     bool bSystemMenuIcons = true;
     262           0 :     if (m_eMenuIcons == TRISTATE_INDET)
     263           0 :         bMenuIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
     264             :     else
     265             :     {
     266           0 :         bSystemMenuIcons = false;
     267           0 :         bMenuIcons = m_eMenuIcons ? sal_True : sal_False;
     268             :     }
     269             : 
     270             :     // Step over list of property names and get right value from coreesponding value list to set it on internal members!
     271           0 :     sal_Int32 nCount = seqPropertyNames.getLength();
     272           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     273             :     {
     274           0 :         if( seqPropertyNames[nProperty] == PROPERTYNAME_DONTHIDEDISABLEDENTRIES )
     275             :         {
     276             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\View\\Menu\\DontHideDisabledEntry\"?" );
     277           0 :             seqValues[nProperty] >>= m_bDontHideDisabledEntries;
     278             :         }
     279           0 :         else if( seqPropertyNames[nProperty] == PROPERTYNAME_FOLLOWMOUSE )
     280             :         {
     281             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\View\\Menu\\FollowMouse\"?" );
     282           0 :             seqValues[nProperty] >>= m_bFollowMouse;
     283             :         }
     284           0 :         else if( seqPropertyNames[nProperty] == PROPERTYNAME_SHOWICONSINMENUES )
     285             :         {
     286             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShowIconsInMenues\"?" );
     287           0 :             bMenuSettingsChanged |= seqValues[nProperty] >>= bMenuIcons;
     288             :         }
     289           0 :         else if( seqPropertyNames[nProperty] == PROPERTYNAME_SYSTEMICONSINMENUES )
     290             :         {
     291             :             DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\IsSystemIconsInMenus\"?" );
     292           0 :             bMenuSettingsChanged |= seqValues[nProperty] >>= bSystemMenuIcons;
     293             :         }
     294             : 
     295             :         #if OSL_DEBUG_LEVEL > 1
     296             :         else DBG_ASSERT( sal_False, "SvtMenuOptions_Impl::Notify()\nUnknown property detected ... I can't handle these!\n" );
     297             :         #endif
     298             :     }
     299             : 
     300           0 :     if ( bMenuSettingsChanged )
     301           0 :         m_eMenuIcons = bSystemMenuIcons ? TRISTATE_INDET : static_cast<TriState>(bMenuIcons);
     302             : 
     303           0 :     for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
     304           0 :         iter->Call( this );
     305           0 : }
     306             : 
     307             : 
     308             : //  public method
     309             : 
     310           0 : void SvtMenuOptions_Impl::Commit()
     311             : {
     312             :     // Get names of supported properties, create a list for values and copy current values to it.
     313           0 :     Sequence< OUString >    seqNames    = impl_GetPropertyNames();
     314           0 :     sal_Int32               nCount      = seqNames.getLength();
     315           0 :     Sequence< Any >         seqValues   ( nCount );
     316           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     317             :     {
     318           0 :         switch( nProperty )
     319             :         {
     320             :             case PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES :   {
     321           0 :                                                                 seqValues[nProperty] <<= m_bDontHideDisabledEntries;
     322             :                                                             }
     323           0 :                                                             break;
     324             : 
     325             :             case PROPERTYHANDLE_FOLLOWMOUSE             :   {
     326           0 :                                                                 seqValues[nProperty] <<= m_bFollowMouse;
     327             :                                                             }
     328           0 :                                                             break;
     329             :             //Output cache of current setting as possibly modified by System Theme for older version
     330             :             case PROPERTYHANDLE_SHOWICONSINMENUES       :   {
     331           0 :                                                                 sal_Bool bValue = (sal_Bool)(Application::GetSettings().GetStyleSettings().GetUseImagesInMenus());
     332           0 :                                                                 seqValues[nProperty] <<= bValue;
     333             :                                                             }
     334           0 :                                                             break;
     335             :             case PROPERTYHANDLE_SYSTEMICONSINMENUES     :   {
     336           0 :                                                                 sal_Bool bValue = (m_eMenuIcons == TRISTATE_INDET ? sal_True : sal_False) ;
     337           0 :                                                                 seqValues[nProperty] <<= bValue;
     338             :                                                             }
     339           0 :                                                             break;
     340             :         }
     341             :     }
     342             :     // Set properties in configuration.
     343           0 :     PutProperties( seqNames, seqValues );
     344           0 : }
     345             : 
     346             : 
     347             : //  private method
     348             : 
     349           0 : Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames()
     350             : {
     351             :     // Build static list of configuration key names.
     352             :     static const OUString pProperties[] =
     353             :     {
     354             :         PROPERTYNAME_DONTHIDEDISABLEDENTRIES    ,
     355             :         PROPERTYNAME_FOLLOWMOUSE                ,
     356             :         PROPERTYNAME_SHOWICONSINMENUES          ,
     357             :         PROPERTYNAME_SYSTEMICONSINMENUES
     358           0 :     };
     359             :     // Initialize return sequence with these list ...
     360           0 :     static const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
     361             :     // ... and return it.
     362           0 :     return seqPropertyNames;
     363             : }
     364             : 
     365           0 : void SvtMenuOptions_Impl::AddListenerLink( const Link& rLink )
     366             : {
     367           0 :     aList.push_back( rLink );
     368           0 : }
     369             : 
     370           0 : void SvtMenuOptions_Impl::RemoveListenerLink( const Link& rLink )
     371             : {
     372           0 :     for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
     373             :     {
     374           0 :         if ( *iter == rLink )
     375             :         {
     376           0 :             aList.erase(iter);
     377           0 :             break;
     378             :         }
     379             :     }
     380           0 : }
     381             : 
     382             : 
     383             : //  initialize static member
     384             : //  DON'T DO IT IN YOUR HEADER!
     385             : //  see definition for further information
     386             : 
     387             : SvtMenuOptions_Impl*    SvtMenuOptions::m_pDataContainer    = NULL  ;
     388             : sal_Int32               SvtMenuOptions::m_nRefCount         = 0     ;
     389             : 
     390             : 
     391             : //  constructor
     392             : 
     393           0 : SvtMenuOptions::SvtMenuOptions()
     394             : {
     395             :     // Global access, must be guarded (multithreading!).
     396           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     397             :     // Increase our refcount ...
     398           0 :     ++m_nRefCount;
     399             :     // ... and initialize our data container only if it not already!
     400           0 :     if( m_pDataContainer == NULL )
     401             :     {
     402           0 :         m_pDataContainer = new SvtMenuOptions_Impl();
     403             : 
     404           0 :         svtools::ItemHolder2::holdConfigItem(E_MENUOPTIONS);
     405           0 :     }
     406           0 : }
     407             : 
     408             : 
     409             : //  destructor
     410             : 
     411           0 : SvtMenuOptions::~SvtMenuOptions()
     412             : {
     413             :     // Global access, must be guarded (multithreading!)
     414           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     415             :     // Decrease our refcount.
     416           0 :     --m_nRefCount;
     417             :     // If last instance was deleted ...
     418             :     // we must destroy our static data container!
     419           0 :     if( m_nRefCount <= 0 )
     420             :     {
     421           0 :         delete m_pDataContainer;
     422           0 :         m_pDataContainer = NULL;
     423           0 :     }
     424           0 : }
     425             : 
     426             : 
     427             : //  public method
     428             : 
     429           0 : bool SvtMenuOptions::IsEntryHidingEnabled() const
     430             : {
     431           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     432           0 :     return m_pDataContainer->IsEntryHidingEnabled();
     433             : }
     434             : 
     435             : 
     436             : //  public method
     437             : 
     438           0 : TriState SvtMenuOptions::GetMenuIconsState() const
     439             : {
     440           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     441           0 :     return m_pDataContainer->GetMenuIconsState();
     442             : }
     443             : 
     444             : 
     445             : //  public method
     446             : 
     447           0 : void SvtMenuOptions::SetMenuIconsState(TriState eState)
     448             : {
     449           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     450           0 :     m_pDataContainer->SetMenuIconsState(eState);
     451           0 : }
     452             : 
     453             : 
     454             : //  private method
     455             : 
     456           0 : Mutex& SvtMenuOptions::GetOwnStaticMutex()
     457             : {
     458             :     // Initialize static mutex only for one time!
     459             :     static Mutex* pMutex = NULL;
     460             :     // If these method first called (Mutex not already exist!) ...
     461           0 :     if( pMutex == NULL )
     462             :     {
     463             :         // ... we must create a new one. Protect follow code with the global mutex -
     464             :         // It must be - we create a static variable!
     465           0 :         MutexGuard aGuard( Mutex::getGlobalMutex() );
     466             :         // We must check our pointer again - because it can be that another instance of our class will be faster than these!
     467           0 :         if( pMutex == NULL )
     468             :         {
     469             :             // Create the new mutex and set it for return on static variable.
     470           0 :             static Mutex aMutex;
     471           0 :             pMutex = &aMutex;
     472           0 :         }
     473             :     }
     474             :     // Return new created or already existing mutex object.
     475           0 :     return *pMutex;
     476             : }
     477             : 
     478           0 : void SvtMenuOptions::AddListenerLink( const Link& rLink )
     479             : {
     480           0 :     m_pDataContainer->AddListenerLink( rLink );
     481           0 : }
     482             : 
     483           0 : void SvtMenuOptions::RemoveListenerLink( const Link& rLink )
     484             : {
     485           0 :     m_pDataContainer->RemoveListenerLink( rLink );
     486           0 : }
     487             : 
     488             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10