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

Generated by: LCOV version 1.10