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

Generated by: LCOV version 1.10