LCOV - code coverage report
Current view: top level - svtools/source/config - slidesorterbaropt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 73 122 59.8 %
Date: 2015-06-13 12:38:46 Functions: 19 24 79.2 %
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 <osl/diagnose.h>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/uno/Sequence.hxx>
      27             : 
      28             : #include <comphelper/lok.hxx>
      29             : #include <rtl/instance.hxx>
      30             : 
      31             : using namespace ::utl;
      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             :         virtual ~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 ) SAL_OVERRIDE;
      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             :         //  public interface
      78             :         bool m_bVisibleImpressView;
      79             :         bool m_bVisibleOutlineView;
      80             :         bool m_bVisibleNotesView;
      81             :         bool m_bVisibleHandoutView;
      82             :         bool m_bVisibleSlideSorterView;
      83             :         bool m_bVisibleDrawView;
      84             : 
      85             :     private:
      86             :         virtual void ImplCommit() SAL_OVERRIDE;
      87             : 
      88             :         /** return list of key names of our configuration management which represent oue module tree
      89             : 
      90             :             These methods return a static const list of key names. We need it to get needed values from our
      91             :             configuration management.
      92             : 
      93             :             \return A list of needed configuration keys is returned.
      94             :         */
      95             :         static Sequence< OUString > GetPropertyNames();
      96             : 
      97             :     protected:
      98             : };
      99             : 
     100        1524 : SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()
     101             :     // Init baseclasses first
     102             :     : ConfigItem( ROOTNODE_SLIDESORTERBAR )
     103             : 
     104             :     , m_bVisibleImpressView( false )
     105             :     , m_bVisibleOutlineView( false )
     106             :     , m_bVisibleNotesView( false )
     107             :     , m_bVisibleHandoutView( false )
     108             :     , m_bVisibleSlideSorterView( false )
     109        1524 :     , m_bVisibleDrawView( false )
     110             : 
     111             : {
     112        1524 :     m_seqPropertyNames = GetPropertyNames( );
     113             : 
     114             :     // Use our static list of configuration keys to get his values.
     115        1524 :     Sequence< Any > seqValues = GetProperties( m_seqPropertyNames  );
     116             : 
     117             :     // Safe impossible cases.
     118             :     // We need values from ALL configuration keys.
     119             :     // Follow assignment use order of values in relation to our list of key names!
     120             :     DBG_ASSERT( !(m_seqPropertyNames.getLength()!=seqValues.getLength()),
     121             :                 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
     122             : 
     123             :     // Copy values from list in right order to our internal member.
     124       10668 :     for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
     125             :     {
     126        9144 :         if (!seqValues[nProperty].hasValue())
     127           0 :             continue;
     128        9144 :         switch( nProperty )
     129             :         {
     130             :             case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW :
     131             :             {
     132        1524 :                 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
     133             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
     134        1524 :                 break;
     135             :             }
     136             :             case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
     137             :             {
     138        1524 :                 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
     139             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
     140        1524 :                 break;
     141             :             }
     142             :             case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
     143             :             {
     144        1524 :                 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
     145             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
     146        1524 :                 break;
     147             :             }
     148             :             case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
     149             :             {
     150        1524 :                 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
     151             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
     152        1524 :                 break;
     153             :             }
     154             :             case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
     155             :             {
     156        1524 :                 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
     157             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
     158        1524 :                 break;
     159             :             }
     160             :             case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
     161             :             {
     162        1524 :                 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
     163             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
     164        1524 :                 break;
     165             :             }
     166             :         }
     167             :     }
     168             : 
     169             :     // Enable notification mechanism of our baseclass.
     170             :     // We need it to get information about changes outside these class on our used configuration keys!
     171        1524 :     EnableNotification( m_seqPropertyNames );
     172        1524 : }
     173             : 
     174        3048 : SvtSlideSorterBarOptions_Impl::~SvtSlideSorterBarOptions_Impl()
     175             : {
     176             :     assert(!IsModified()); // should have been committed
     177        3048 : }
     178             : 
     179           0 : static int lcl_MapPropertyName( const OUString& rCompare,
     180             :                 const uno::Sequence< OUString>& aInternalPropertyNames)
     181             : {
     182           0 :     for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
     183             :     {
     184           0 :         if( aInternalPropertyNames[nProp] == rCompare )
     185           0 :             return nProp;
     186             :     }
     187           0 :     return -1;
     188             : }
     189             : 
     190           0 : void SvtSlideSorterBarOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
     191             : {
     192           0 :     const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
     193           0 :     Sequence< Any > seqValues = GetProperties( rPropertyNames  );
     194             : 
     195             :     // Safe impossible cases.
     196             :     // We need values from ALL configuration keys.
     197             :     // Follow assignment use order of values in relation to our list of key names!
     198             :     DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()),
     199             :                 "SvtSlideSorterBarOptions_Impl::SvtSlideSorterBarOptions_Impl()\nI miss some values of configuration keys!\n" );
     200             : 
     201             :     // Copy values from list in right order to our internal member.
     202           0 :     for( sal_Int32 nProperty=0; nProperty<seqValues.getLength(); ++nProperty )
     203             :     {
     204           0 :         if (!seqValues[nProperty].hasValue())
     205           0 :             continue;
     206           0 :         switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
     207             :         {
     208             :             case PROPERTYHANDLE_VISIBLE_IMPRESSVIEW:
     209             :             {
     210           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleImpressView) )
     211             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleImpressView\"!" );
     212             :             }
     213           0 :             break;
     214             :             case PROPERTYHANDLE_VISIBLE_OUTLINEVIEW :
     215             :             {
     216           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleOutlineView) )
     217             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleOutlineView\"!" );
     218             :             }
     219           0 :             break;
     220             :             case PROPERTYHANDLE_VISIBLE_NOTESVIEW :
     221             :             {
     222           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleNotesView) )
     223             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleNotesView\"!" );
     224             :             }
     225           0 :             break;
     226             :             case PROPERTYHANDLE_VISIBLE_HANDOUTVIEW :
     227             :             {
     228           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleHandoutView) )
     229             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleHandoutView\"!" );
     230             :             }
     231           0 :             break;
     232             :             case PROPERTYHANDLE_VISIBLE_SLIDESORTERVIEW :
     233             :             {
     234           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleSlideSorterView) )
     235             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleSlideSorterView\"!" );
     236             :             }
     237           0 :             break;
     238             : 
     239             :             case PROPERTYHANDLE_VISIBLE_DRAWVIEW :
     240             :             {
     241           0 :                 if( !(seqValues[nProperty] >>= m_bVisibleDrawView) )
     242             :                     OSL_FAIL("Wrong type of \"SlideSorterBar\\VisibleDrawView\"!" );
     243             :             }
     244           0 :             break;
     245             :        }
     246           0 :     }
     247           0 : }
     248             : 
     249           0 : void SvtSlideSorterBarOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
     250             : {
     251           0 :     Load( rPropertyNames );
     252           0 : }
     253             : 
     254           0 : void SvtSlideSorterBarOptions_Impl::ImplCommit()
     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             :             case PROPERTYHANDLE_VISIBLE_DRAWVIEW:
     289             :             {
     290           0 :                 seqValues[nProperty] <<= m_bVisibleDrawView;
     291           0 :                 break;
     292             :             }
     293             : 
     294             :         }
     295             :     }
     296             :     // Set properties in configuration.
     297           0 :     PutProperties( m_seqPropertyNames, seqValues );
     298           0 : }
     299             : 
     300        1524 : Sequence< OUString > SvtSlideSorterBarOptions_Impl::GetPropertyNames()
     301             : {
     302             :     // Build list of configuration key names.
     303             :     OUString pProperties[] =
     304             :     {
     305             :         PROPERTYNAME_VISIBLE_IMPRESSVIEW,
     306             :         PROPERTYNAME_VISIBLE_OUTLINEVIEW,
     307             :         PROPERTYNAME_VISIBLE_NOTESVIEW,
     308             :         PROPERTYNAME_VISIBLE_HANDOUTVIEW,
     309             :         PROPERTYNAME_VISIBLE_SLIDESORTERVIEW,
     310             :         PROPERTYNAME_VISIBLE_DRAWVIEW,
     311       10668 :     };
     312             : 
     313             :     // Initialize return sequence with these list and run
     314       10668 :     return Sequence< OUString >( pProperties, SAL_N_ELEMENTS( pProperties ) );
     315             : }
     316             : 
     317             : //  initialize static member, see definition for further information
     318             : //  DON'T DO IT IN YOUR HEADER!
     319             : SvtSlideSorterBarOptions_Impl* SvtSlideSorterBarOptions::m_pDataContainer    = NULL  ;
     320             : sal_Int32                      SvtSlideSorterBarOptions::m_nRefCount = 0     ;
     321             : 
     322        1524 : SvtSlideSorterBarOptions::SvtSlideSorterBarOptions()
     323             : {
     324             :     // Global access, must be guarded (multithreading!).
     325        1524 :     MutexGuard aGuard( GetInitMutex() );
     326        1524 :     ++m_nRefCount;
     327             :     // ... and initialize our data container only if it not already exist!
     328        1524 :     if( m_pDataContainer == NULL )
     329             :     {
     330        1524 :        m_pDataContainer = new SvtSlideSorterBarOptions_Impl;
     331        1524 :     }
     332        1524 : }
     333             : 
     334        3048 : SvtSlideSorterBarOptions::~SvtSlideSorterBarOptions()
     335             : {
     336             :     // Global access, must be guarded (multithreading!)
     337        1524 :     MutexGuard aGuard( GetInitMutex() );
     338        1524 :     --m_nRefCount;
     339             :     // If last instance was deleted we must destroy our static data container!
     340        1524 :     if( m_nRefCount <= 0 )
     341             :     {
     342        1524 :         delete m_pDataContainer;
     343        1524 :         m_pDataContainer = NULL;
     344        1524 :     }
     345        1524 : }
     346             : 
     347         127 : bool SvtSlideSorterBarOptions::GetVisibleImpressView() const
     348             : {
     349         127 :     return m_pDataContainer->m_bVisibleImpressView && !comphelper::LibreOfficeKit::isActive();
     350             : }
     351             : 
     352         127 : void SvtSlideSorterBarOptions::SetVisibleImpressView(bool bVisible)
     353             : {
     354         127 :     m_pDataContainer->m_bVisibleImpressView = bVisible;
     355         127 : }
     356             : 
     357         127 : bool SvtSlideSorterBarOptions::GetVisibleOutlineView() const
     358             : {
     359         127 :     return m_pDataContainer->m_bVisibleOutlineView;
     360             : }
     361             : 
     362         127 : void SvtSlideSorterBarOptions::SetVisibleOutlineView(bool bVisible)
     363             : {
     364         127 :     m_pDataContainer->m_bVisibleOutlineView = bVisible;
     365         127 : }
     366             : 
     367         127 : bool SvtSlideSorterBarOptions::GetVisibleNotesView() const
     368             : {
     369         127 :     return m_pDataContainer->m_bVisibleNotesView;
     370             : }
     371             : 
     372         127 : void SvtSlideSorterBarOptions::SetVisibleNotesView(bool bVisible)
     373             : {
     374         127 :     m_pDataContainer->m_bVisibleNotesView = bVisible;
     375         127 : }
     376             : 
     377         127 : bool SvtSlideSorterBarOptions::GetVisibleHandoutView() const
     378             : {
     379         127 :     return m_pDataContainer->m_bVisibleHandoutView;
     380             : }
     381             : 
     382         127 : void SvtSlideSorterBarOptions::SetVisibleHandoutView(bool bVisible)
     383             : {
     384         127 :     m_pDataContainer->m_bVisibleHandoutView = bVisible;
     385         127 : }
     386             : 
     387         127 : bool SvtSlideSorterBarOptions::GetVisibleSlideSorterView() const
     388             : {
     389         127 :     return m_pDataContainer->m_bVisibleSlideSorterView && !comphelper::LibreOfficeKit::isActive();
     390             : }
     391             : 
     392         127 : void SvtSlideSorterBarOptions::SetVisibleSlideSorterView(bool bVisible)
     393             : {
     394         127 :     m_pDataContainer->m_bVisibleSlideSorterView = bVisible;
     395         127 : }
     396             : 
     397         127 : bool SvtSlideSorterBarOptions::GetVisibleDrawView() const
     398             : {
     399         127 :     return m_pDataContainer->m_bVisibleDrawView;
     400             : }
     401             : 
     402         127 : void SvtSlideSorterBarOptions::SetVisibleDrawView(bool bVisible)
     403             : {
     404         127 :     m_pDataContainer->m_bVisibleDrawView = bVisible;
     405         127 : }
     406             : 
     407             : namespace
     408             : {
     409             :     class theSvtSlideSorterBarOptionsMutex :
     410             :         public rtl::Static< osl::Mutex, theSvtSlideSorterBarOptionsMutex > {};
     411             : }
     412             : 
     413        3048 : Mutex & SvtSlideSorterBarOptions::GetInitMutex()
     414             : {
     415        3048 :     return theSvtSlideSorterBarOptionsMutex::get();
     416             : }
     417             : 
     418             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11