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

Generated by: LCOV version 1.10