LCOV - code coverage report
Current view: top level - svtools/source/config - toolpanelopt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 111 59.5 %
Date: 2015-06-13 12:38:46 Functions: 17 22 77.3 %
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/toolpanelopt.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             : 
      34             : #include <list>
      35             : 
      36             : using namespace ::utl;
      37             : using namespace ::osl;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star;
      40             : 
      41             : #define ROOTNODE_TOOLPANEL                     OUString("Office.Impress/MultiPaneGUI/ToolPanel/Visible")
      42             : 
      43             : #define PROPERTYNAME_VISIBLE_IMPRESSVIEW       OUString("ImpressView")
      44             : #define PROPERTYHANDLE_VISIBLE_IMPRESSVIEW     0
      45             : #define PROPERTYNAME_VISIBLE_OUTLINEVIEW       OUString("OutlineView")
      46             : #define PROPERTYHANDLE_VISIBLE_OUTLINEVIEW     1
      47             : #define PROPERTYNAME_VISIBLE_NOTESVIEW         OUString("NotesView")
      48             : #define PROPERTYHANDLE_VISIBLE_NOTESVIEW       2
      49             : #define PROPERTYNAME_VISIBLE_HANDOUTVIEW       OUString("HandoutView")
      50             : #define PROPERTYHANDLE_VISIBLE_HANDOUTVIEW     3
      51             : #define PROPERTYNAME_VISIBLE_SLIDESORTERVIEW   OUString("SlideSorterView")
      52             : #define PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW 4
      53             : 
      54             : class SvtToolPanelOptions_Impl : public ConfigItem
      55             : {
      56             :     private:
      57             :     Sequence< OUString > m_seqPropertyNames;
      58             : 
      59             :     public:
      60             : 
      61             :          SvtToolPanelOptions_Impl();
      62             :         virtual ~SvtToolPanelOptions_Impl();
      63             : 
      64             :         /** called for notify of configmanager
      65             : 
      66             :             These method is called from the ConfigManager before application ends or from the
      67             :             PropertyChangeListener if the sub tree broadcasts changes. You must update your
      68             :             internal values.
      69             : 
      70             :             \sa baseclass ConfigItem
      71             :             \param[in,out] seqPropertyNames is the list of properties which should be updated.
      72             :         */
      73             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
      74             : 
      75             :         /**
      76             :          loads required data from the configuration. It's called in the constructor to
      77             :          read all entries and form ::Notify to re-read changed setting
      78             :         */
      79             :         void Load( const Sequence< OUString >& rPropertyNames );
      80             : 
      81             :         //  public interface
      82             :         bool m_bVisibleImpressView;
      83             :         bool m_bVisibleOutlineView;
      84             :         bool m_bVisibleNotesView;
      85             :         bool m_bVisibleHandoutView;
      86             :         bool m_bVisibleSlideSorterView;
      87             : 
      88             :     private:
      89             : 
      90             :         virtual void ImplCommit() SAL_OVERRIDE;
      91             : 
      92             :         /** return list of key names of our configuration management which represent oue module tree
      93             : 
      94             :             These methods return a static const list of key names. We need it to get needed values from our
      95             :             configuration management.
      96             : 
      97             :             \return A list of needed configuration keys is returned.
      98             :         */
      99             :         static Sequence< OUString > GetPropertyNames();
     100             : 
     101             :     protected:
     102             : };
     103             : 
     104         410 : SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()
     105             :     // Init baseclasses first
     106             :     : ConfigItem( ROOTNODE_TOOLPANEL )
     107             : 
     108             :     , m_bVisibleImpressView( false )
     109             :     , m_bVisibleOutlineView( false )
     110             :     , m_bVisibleNotesView( false )
     111             :     , m_bVisibleHandoutView( false )
     112         410 :     , m_bVisibleSlideSorterView( false )
     113             : 
     114             : {
     115         410 :     m_seqPropertyNames = GetPropertyNames( );
     116             : 
     117             :     // Use our static list of configuration keys to get his values.
     118         410 :     Sequence< Any > seqValues = GetProperties( m_seqPropertyNames  );
     119             : 
     120             :     // Safe impossible cases.
     121             :     // We need values from ALL configuration keys.
     122             :     // Follow assignment use order of values in relation to our list of key names!
     123             :     DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
     124             :                 "SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()\nI miss some values of configuration keys!\n" );
     125             : 
     126             :     // Copy values from list in right order to our internal member.
     127        2460 :     for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
     128             :     {
     129        2050 :         if (!seqValues[nProperty].hasValue())
     130           0 :             continue;
     131        2050 :         switch( nProperty )
     132             :         {
     133             :             case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
     134             :             {
     135         410 :                 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
     136             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleImpressView\"!" );
     137         410 :                 break;
     138             :             }
     139             :             case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
     140             :             {
     141         410 :                 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
     142             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleOutlineView\"!" );
     143         410 :                 break;
     144             :             }
     145             :             case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
     146             :             {
     147         410 :                 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
     148             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleNotesView\"!" );
     149         410 :                 break;
     150             :             }
     151             :             case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
     152             :             {
     153         410 :                 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
     154             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleHandoutView\"!" );
     155         410 :                 break;
     156             :             }
     157             :             case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
     158             :             {
     159         410 :                 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
     160             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleSlideSorterView\"!" );
     161         410 :                 break;
     162             :             }
     163             :         }
     164             :     }
     165             : 
     166             :     // Enable notification mechanism of our baseclass.
     167             :     // We need it to get information about changes outside these class on our used configuration keys!
     168         410 :     EnableNotification( m_seqPropertyNames );
     169         410 : }
     170             : 
     171         820 : SvtToolPanelOptions_Impl::~SvtToolPanelOptions_Impl()
     172             : {
     173             :     assert(!IsModified()); // should have been committed
     174         820 : }
     175             : 
     176           0 : static int lcl_MapPropertyName( const OUString& rCompare,
     177             :                 const uno::Sequence< OUString>& aInternalPropertyNames)
     178             : {
     179           0 :     for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
     180             :     {
     181           0 :         if( aInternalPropertyNames[nProp] == rCompare )
     182           0 :             return nProp;
     183             :     }
     184           0 :     return -1;
     185             : }
     186             : 
     187           0 : void SvtToolPanelOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
     188             : {
     189           0 :     const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
     190           0 :     Sequence< Any > seqValues = GetProperties( rPropertyNames  );
     191             : 
     192             :     // Safe impossible cases.
     193             :     // We need values from ALL configuration keys.
     194             :     // Follow assignment use order of values in relation to our list of key names!
     195             :     DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
     196             :                 "SvtToolPanelOptions_Impl::SvtToolPanelOptions_Impl()\nI miss some values of configuration keys!\n" );
     197             : 
     198             :     // Copy values from list in right order to our internal member.
     199           0 :     for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
     200             :     {
     201           0 :         if (!seqValues[nProperty].hasValue())
     202           0 :             continue;
     203           0 :         switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
     204             :         {
     205             :             case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
     206             :             {
     207           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
     208             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleImpressView\"!" );
     209             :             }
     210           0 :             break;
     211             :             case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
     212             :             {
     213           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
     214             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleOutlineView\"!" );
     215             :             }
     216           0 :             break;
     217             :             case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
     218             :             {
     219           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
     220             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleNotesView\"!" );
     221             :             }
     222           0 :             break;
     223             :             case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
     224             :             {
     225           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
     226             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleHandoutView\"!" );
     227             :             }
     228           0 :             break;
     229             :             case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
     230             :             {
     231           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
     232             :                     OSL_FAIL("Wrong type of \"ToolPanel\\VisibleSlideSorterView\"!" );
     233             :             }
     234           0 :             break;
     235             :        }
     236           0 :     }
     237           0 : }
     238             : 
     239           0 : void SvtToolPanelOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
     240             : {
     241           0 :     Load( rPropertyNames );
     242           0 : }
     243             : 
     244           0 : void SvtToolPanelOptions_Impl::ImplCommit()
     245             : {
     246             :     // Get names of supported properties, create a list for values and copy current values to it.
     247           0 :     sal_Int32               nCount      = m_seqPropertyNames.getLength();
     248           0 :     Sequence< Any >         seqValues   ( nCount );
     249           0 :     for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
     250             :     {
     251           0 :         switch( nProperty )
     252             :         {
     253             :             case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
     254             :             {
     255           0 :                 seqValues[nProperty] <<= m_bVisibleImpressView;
     256           0 :                 break;
     257             :             }
     258             :             case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW:
     259             :             {
     260           0 :                 seqValues[nProperty] <<= m_bVisibleOutlineView;
     261           0 :                 break;
     262             :             }
     263             :             case PROPERTYHANDLE_VISIBLE_NOTESVIEW:
     264             :             {
     265           0 :                 seqValues[nProperty] <<= m_bVisibleNotesView;
     266           0 :                 break;
     267             :             }
     268             :             case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW:
     269             :             {
     270           0 :                 seqValues[nProperty] <<= m_bVisibleHandoutView;
     271           0 :                 break;
     272             :             }
     273             :             case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW:
     274             :             {
     275           0 :                 seqValues[nProperty] <<= m_bVisibleSlideSorterView;
     276           0 :                 break;
     277             :             }
     278             :         }
     279             :     }
     280             :     // Set properties in configuration.
     281           0 :     PutProperties( m_seqPropertyNames, seqValues );
     282           0 : }
     283             : 
     284         410 : Sequence< OUString > SvtToolPanelOptions_Impl::GetPropertyNames()
     285             : {
     286             :     // Build list of configuration key names.
     287             :     OUString pProperties[] =
     288             :     {
     289             :         PROPERTYNAME_VISIBLE_IMPRESSVIEW,
     290             :         PROPERTYNAME_VISIBLE_OUTLINEVIEW,
     291             :         PROPERTYNAME_VISIBLE_NOTESVIEW,
     292             :         PROPERTYNAME_VISIBLE_HANDOUTVIEW,
     293             :         PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
     294        2460 :     };
     295             : 
     296             :     // Initialize return sequence with these list and run
     297        2460 :     return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
     298             : }
     299             : 
     300             : //  initialize static member, see definition for further information
     301             : //  DON'T DO IT IN YOUR HEADER!
     302             : SvtToolPanelOptions_Impl* SvtToolPanelOptions::m_pDataContainer = NULL;
     303             : sal_Int32               SvtToolPanelOptions::m_nRefCount = 0;
     304             : 
     305         410 : SvtToolPanelOptions::SvtToolPanelOptions()
     306             : {
     307             :     // Global access, must be guarded (multithreading!).
     308         410 :     MutexGuard aGuard( GetInitMutex() );
     309         410 :     ++m_nRefCount;
     310             :     // ... and initialize our data container only if it not already exist!
     311         410 :     if( m_pDataContainer == NULL )
     312             :     {
     313         410 :        m_pDataContainer = new SvtToolPanelOptions_Impl;
     314         410 :     }
     315         410 : }
     316             : 
     317         820 : SvtToolPanelOptions::~SvtToolPanelOptions()
     318             : {
     319             :     // Global access, must be guarded (multithreading!)
     320         410 :     MutexGuard aGuard( GetInitMutex() );
     321         410 :     --m_nRefCount;
     322             :     // If last instance was deleted we must destroy our static data container!
     323         410 :     if( m_nRefCount <= 0 )
     324             :     {
     325         410 :         delete m_pDataContainer;
     326         410 :         m_pDataContainer = NULL;
     327         410 :     }
     328         410 : }
     329             : 
     330          41 : bool SvtToolPanelOptions::GetVisibleImpressView() const
     331             : {
     332          41 :     return m_pDataContainer->m_bVisibleImpressView;
     333             : }
     334             : 
     335          41 : void SvtToolPanelOptions::SetVisibleImpressView(bool bVisible)
     336             : {
     337          41 :     m_pDataContainer->m_bVisibleImpressView = bVisible;
     338          41 : }
     339             : 
     340          41 : bool SvtToolPanelOptions::GetVisibleOutlineView() const
     341             : {
     342          41 :     return m_pDataContainer->m_bVisibleOutlineView;
     343             : }
     344             : 
     345          41 : void SvtToolPanelOptions::SetVisibleOutlineView(bool bVisible)
     346             : {
     347          41 :     m_pDataContainer->m_bVisibleOutlineView = bVisible;
     348          41 : }
     349             : 
     350          41 : bool SvtToolPanelOptions::GetVisibleNotesView() const
     351             : {
     352          41 :     return m_pDataContainer->m_bVisibleNotesView;
     353             : }
     354             : 
     355          41 : void SvtToolPanelOptions::SetVisibleNotesView(bool bVisible)
     356             : {
     357          41 :     m_pDataContainer->m_bVisibleNotesView = bVisible;
     358          41 : }
     359             : 
     360          41 : bool SvtToolPanelOptions::GetVisibleHandoutView() const
     361             : {
     362          41 :     return m_pDataContainer->m_bVisibleHandoutView;
     363             : }
     364             : 
     365          41 : void SvtToolPanelOptions::SetVisibleHandoutView(bool bVisible)
     366             : {
     367          41 :     m_pDataContainer->m_bVisibleHandoutView = bVisible;
     368          41 : }
     369             : 
     370          41 : bool SvtToolPanelOptions::GetVisibleSlideSorterView() const
     371             : {
     372          41 :     return m_pDataContainer->m_bVisibleSlideSorterView;
     373             : }
     374             : 
     375          41 : void SvtToolPanelOptions::SetVisibleSlideSorterView(bool bVisible)
     376             : {
     377          41 :     m_pDataContainer->m_bVisibleSlideSorterView = bVisible;
     378          41 : }
     379             : 
     380             : namespace
     381             : {
     382             :     class theSvtToolPanelOptionsMutex :
     383             :         public rtl::Static< osl::Mutex, theSvtToolPanelOptionsMutex > {};
     384             : }
     385             : 
     386         820 : Mutex & SvtToolPanelOptions::GetInitMutex()
     387             : {
     388         820 :     return theSvtToolPanelOptionsMutex::get();
     389             : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11