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

Generated by: LCOV version 1.10