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

Generated by: LCOV version 1.10