LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/config - viewoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 202 374 54.0 %
Date: 2012-12-27 Functions: 24 35 68.6 %
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 <unotools/viewoptions.hxx>
      21             : #include <com/sun/star/uno/Any.hxx>
      22             : 
      23             : #include <boost/unordered_map.hpp>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : #include <com/sun/star/container/XNameContainer.hpp>
      26             : #include <com/sun/star/container/XNameAccess.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <rtl/ustrbuf.hxx>
      29             : #include <unotools/configpaths.hxx>
      30             : #include <comphelper/configurationhelper.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : 
      33             : #include <itemholder1.hxx>
      34             : 
      35             : #ifdef CONST_ASCII
      36             :     #error  "Who define CONST_ASCII before! I use it to create const ascii strings ..."
      37             : #else
      38             :     #define CONST_ASCII(SASCIIVALUE)            ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SASCIIVALUE))
      39             : #endif
      40             : 
      41             : #define PACKAGE_VIEWS                           CONST_ASCII("org.openoffice.Office.Views")
      42             : 
      43             : #define LIST_DIALOGS                            CONST_ASCII("Dialogs"   )
      44             : #define LIST_TABDIALOGS                         CONST_ASCII("TabDialogs")
      45             : #define LIST_TABPAGES                           CONST_ASCII("TabPages"  )
      46             : #define LIST_WINDOWS                            CONST_ASCII("Windows"   )
      47             : 
      48             : #define PROPERTY_WINDOWSTATE                    CONST_ASCII("WindowState")
      49             : #define PROPERTY_PAGEID                         CONST_ASCII("PageID"     )
      50             : #define PROPERTY_VISIBLE                        CONST_ASCII("Visible"    )
      51             : #define PROPERTY_USERDATA                       CONST_ASCII("UserData"   )
      52             : 
      53             : #define DEFAULT_WINDOWSTATE                     ::rtl::OUString()
      54             : #define DEFAULT_USERDATA                        css::uno::Sequence< css::beans::NamedValue >()
      55             : #define DEFAULT_PAGEID                          0
      56             : #define DEFAULT_VISIBLE                         sal_False
      57             : 
      58             : //#define DEBUG_VIEWOPTIONS
      59             : 
      60             : #ifdef DEBUG_VIEWOPTIONS
      61             :     #define _LOG_COUNTER_( _SVIEW_, _NREAD_, _NWRITE_ )                                                                                     \
      62             :                 {                                                                                                                           \
      63             :                     FILE* pFile = fopen( "viewdbg.txt", "a" );                                                                              \
      64             :                     fprintf( pFile, "%s[%d, %d]\n", ::rtl::OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
      65             :                     fclose( pFile );                                                                                                        \
      66             :                 }
      67             : #endif // DEBUG_VIEWOPTIONS
      68             : 
      69             : #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION)            \
      70             :     {                                                                                                               \
      71             :         ::rtl::OUStringBuffer sMsg(256);                                                                            \
      72             :         sMsg.appendAscii("Unexpected exception catched. Original message was:\n\""      );                          \
      73             :         sMsg.append     (SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION.Message);                          \
      74             :         sMsg.appendAscii("\""                                                           );                          \
      75             :     }
      76             : 
      77             : //_________________________________________________________________________________________________________________
      78             : //  initialization!
      79             : //_________________________________________________________________________________________________________________
      80             : 
      81             : SvtViewOptionsBase_Impl*     SvtViewOptions::m_pDataContainer_Dialogs    =   NULL    ;
      82             : sal_Int32                    SvtViewOptions::m_nRefCount_Dialogs         =   0       ;
      83             : SvtViewOptionsBase_Impl*     SvtViewOptions::m_pDataContainer_TabDialogs =   NULL    ;
      84             : sal_Int32                    SvtViewOptions::m_nRefCount_TabDialogs      =   0       ;
      85             : SvtViewOptionsBase_Impl*     SvtViewOptions::m_pDataContainer_TabPages   =   NULL    ;
      86             : sal_Int32                    SvtViewOptions::m_nRefCount_TabPages        =   0       ;
      87             : SvtViewOptionsBase_Impl*     SvtViewOptions::m_pDataContainer_Windows    =   NULL    ;
      88             : sal_Int32                    SvtViewOptions::m_nRefCount_Windows         =   0       ;
      89             : 
      90             : //_________________________________________________________________________________________________________________
      91             : //  private declarations!
      92             : //_________________________________________________________________________________________________________________
      93             : 
      94             : /*-************************************************************************************************************//**
      95             :     @descr  declare one configuration item
      96             :             These struct hold information about one view item. But not all member are used for all entries!
      97             :             User must decide which information are usefull and which not. We are a container iztem only and doesnt
      98             :             know anything about the context.
      99             :             But; we support a feature:
     100             :                 decision between items with default values (should not realy exist in configuration!)
     101             :                 and items with real values - changed by user. So user can suppress saving of realy unused items
     102             :                 to disk - because; defaulted items could be restored on runtime without reading from disk!!!
     103             :                 And if only items with valid information was written to cfg - we mustn't read so much and save time.
     104             :             So we start with an member m_bDefault=True and reset it to False after first set-call.
     105             :             Deficiencies of these solution - we cant allow direct read/write access to our member. We must
     106             :             support it by set/get-methods ...
     107             : *//*-*************************************************************************************************************/
     108             : class IMPL_TViewData
     109             : {
     110             :     public:
     111             :         //---------------------------------------------------------------------------------------------------------
     112             :         // create "default" item
     113             :         IMPL_TViewData()
     114             :         {
     115             :             m_sWindowState = DEFAULT_WINDOWSTATE ;
     116             :             m_lUserData    = DEFAULT_USERDATA    ;
     117             :             m_nPageID      = DEFAULT_PAGEID      ;
     118             :             m_bVisible     = DEFAULT_VISIBLE     ;
     119             : 
     120             :             m_bDefault     = sal_True            ;
     121             :         }
     122             : 
     123             :         //---------------------------------------------------------------------------------------------------------
     124             :         // write access - with reseting of default state
     125             :         void setWindowState( const ::rtl::OUString& sValue )
     126             :         {
     127             :             m_bDefault     = (
     128             :                                 ( m_bDefault == sal_True            )    &&
     129             :                                 ( sValue     == DEFAULT_WINDOWSTATE )
     130             :                              );
     131             :             m_sWindowState = sValue;
     132             :         }
     133             : 
     134             :         //---------------------------------------------------------------------------------------------------------
     135             :         void setUserData( const css::uno::Sequence< css::beans::NamedValue >& lValue )
     136             :         {
     137             :             m_bDefault  = (
     138             :                             ( m_bDefault == sal_True         )    &&
     139             :                             ( lValue     == DEFAULT_USERDATA )
     140             :                           );
     141             :             m_lUserData = lValue;
     142             :         }
     143             : 
     144             :         //---------------------------------------------------------------------------------------------------------
     145             :         void setPageID( sal_Int32 nValue )
     146             :         {
     147             :             m_bDefault = (
     148             :                            ( m_bDefault == sal_True       )    &&
     149             :                            ( nValue     == DEFAULT_PAGEID )
     150             :                          );
     151             :             m_nPageID  = nValue;
     152             :         }
     153             : 
     154             :         //---------------------------------------------------------------------------------------------------------
     155             :         void setVisible( sal_Bool bValue )
     156             :         {
     157             :             m_bDefault = (
     158             :                            ( m_bDefault == sal_True        )    &&
     159             :                            ( bValue     == DEFAULT_VISIBLE )
     160             :                          );
     161             :             m_bVisible = bValue;
     162             :         }
     163             : 
     164             :         //---------------------------------------------------------------------------------------------------------
     165             :         // read access
     166             :         ::rtl::OUString                              getWindowState() { return m_sWindowState; }
     167             :         css::uno::Sequence< css::beans::NamedValue > getUserData   () { return m_lUserData   ; }
     168             :         sal_Int32                                    getPageID     () { return m_nPageID     ; }
     169             :         sal_Bool                                     getVisible    () { return m_bVisible    ; }
     170             : 
     171             :         //---------------------------------------------------------------------------------------------------------
     172             :         // special operation for easy access on user data
     173             :         void setUserItem( const ::rtl::OUString& sName  ,
     174             :                           const css::uno::Any&   aValue )
     175             :         {
     176             :             // we change UserData in every case!
     177             :             //    a) we change already existing item
     178             :             // or b) we add a new one
     179             :             m_bDefault = sal_False;
     180             : 
     181             :             sal_Bool  bExist = sal_False;
     182             :             sal_Int32 nCount = m_lUserData.getLength();
     183             : 
     184             :             // change it, if it already exist ...
     185             :             for( sal_Int32 nStep=0; nStep<nCount; ++nStep )
     186             :             {
     187             :                 if( m_lUserData[nStep].Name == sName )
     188             :                 {
     189             :                     m_lUserData[nStep].Value = aValue  ;
     190             :                     bExist                   = sal_True;
     191             :                     break;
     192             :                 }
     193             :             }
     194             : 
     195             :             // ... or create new list item
     196             :             if( bExist == sal_False )
     197             :             {
     198             :                 m_lUserData.realloc( nCount+1 );
     199             :                 m_lUserData[nCount].Name  = sName  ;
     200             :                 m_lUserData[nCount].Value = aValue ;
     201             :             }
     202             :         }
     203             : 
     204             :         //---------------------------------------------------------------------------------------------------------
     205             :         css::uno::Any getUserItem( const ::rtl::OUString& sName )
     206             :         {
     207             :             // default value - if item not exist!
     208             :             css::uno::Any aValue;
     209             : 
     210             :             sal_Int32 nCount = m_lUserData.getLength();
     211             :             for( sal_Int32 nStep=0; nStep<nCount; ++nStep )
     212             :             {
     213             :                 if( m_lUserData[nStep].Name == sName )
     214             :                 {
     215             :                     aValue = m_lUserData[nStep].Value;
     216             :                     break;
     217             :                 }
     218             :             }
     219             :             return aValue;
     220             :         }
     221             : 
     222             :         //---------------------------------------------------------------------------------------------------------
     223             :         // check for default items
     224             :         sal_Bool isDefault() { return m_bDefault; }
     225             : 
     226             :     private:
     227             :         ::rtl::OUString                                 m_sWindowState    ;
     228             :         css::uno::Sequence< css::beans::NamedValue >    m_lUserData       ;
     229             :         sal_Int32                                       m_nPageID         ;
     230             :         sal_Bool                                        m_bVisible        ;
     231             : 
     232             :         sal_Bool                                        m_bDefault        ;
     233             : };
     234             : 
     235             : struct IMPL_TStringHashCode
     236             : {
     237             :     size_t operator()(const ::rtl::OUString& sString) const
     238             :     {
     239             :         return sString.hashCode();
     240             :     }
     241             : };
     242             : 
     243             : typedef ::boost::unordered_map< ::rtl::OUString                    ,
     244             :                          IMPL_TViewData                     ,
     245             :                          IMPL_TStringHashCode               ,
     246             :                          ::std::equal_to< ::rtl::OUString > > IMPL_TViewHash;
     247             : 
     248             : /*-************************************************************************************************************//**
     249             :     @descr          Implement base data container for view options elements.
     250             :                     Every item support ALL possible configuration informations.
     251             :                     But not every superclass should use them! Because some view types don't
     252             :                     have it realy.
     253             : 
     254             :     @attention      We implement a write-througt-cache! We use it for reading - but write all changes directly to
     255             :                     configuration. (changes are made on internal cache too!). So it's easier to distinguish
     256             :                     between added/changed/removed elements without any complex mask or bool flag informations.
     257             :                     Caches from configuration and our own one are synchronized every time - if we do so.
     258             : *//*-*************************************************************************************************************/
     259             : class SvtViewOptionsBase_Impl
     260             : {
     261             :     //-------------------------------------------------------------------------------------------------------------
     262             :     public:
     263             :         enum State { STATE_NONE, STATE_FALSE, STATE_TRUE };
     264             : 
     265             :                                                         SvtViewOptionsBase_Impl ( const ::rtl::OUString&                                sList    );
     266             :         virtual                                        ~SvtViewOptionsBase_Impl (                                                                );
     267             :         sal_Bool                                        Exists                  ( const ::rtl::OUString&                                sName    );
     268             :         sal_Bool                                        Delete                  ( const ::rtl::OUString&                                sName    );
     269             :         ::rtl::OUString                                 GetWindowState          ( const ::rtl::OUString&                                sName    );
     270             :         void                                            SetWindowState          ( const ::rtl::OUString&                                sName    ,
     271             :                                                                                   const ::rtl::OUString&                                sState   );
     272             :         css::uno::Sequence< css::beans::NamedValue >    GetUserData             ( const ::rtl::OUString&                                sName    );
     273             :         void                                            SetUserData             ( const ::rtl::OUString&                                sName    ,
     274             :                                                                                   const css::uno::Sequence< css::beans::NamedValue >&   lData    );
     275             :         sal_Int32                                       GetPageID               ( const ::rtl::OUString&                                sName    );
     276             :         void                                            SetPageID               ( const ::rtl::OUString&                                sName    ,
     277             :                                                                                         sal_Int32                                       nID      );
     278             :         State                                           GetVisible              ( const ::rtl::OUString&                                sName    );
     279             :         void                                            SetVisible              ( const ::rtl::OUString&                                sName    ,
     280             :                                                                                         sal_Bool                                        bVisible );
     281             :         css::uno::Any                                   GetUserItem             ( const ::rtl::OUString&                                sName    ,
     282             :                                                                                   const ::rtl::OUString&                                sItem    );
     283             :         void                                            SetUserItem             ( const ::rtl::OUString&                                sName    ,
     284             :                                                                                   const ::rtl::OUString&                                sItem    ,
     285             :                                                                                   const css::uno::Any&                                  aValue   );
     286             : 
     287             :     //-------------------------------------------------------------------------------------------------------------
     288             :     private:
     289             :         css::uno::Reference< css::uno::XInterface > impl_getSetNode( const ::rtl::OUString& sNode           ,
     290             :                                                                            sal_Bool         bCreateIfMissing);
     291             : 
     292             :     //-------------------------------------------------------------------------------------------------------------
     293             :     private:
     294             :         ::rtl::OUString                                    m_sListName;
     295             :         css::uno::Reference< css::container::XNameAccess > m_xRoot;
     296             :         css::uno::Reference< css::container::XNameAccess > m_xSet;
     297             : 
     298             :         #ifdef DEBUG_VIEWOPTIONS
     299             :         sal_Int32           m_nReadCount    ;
     300             :         sal_Int32           m_nWriteCount   ;
     301             :         #endif
     302             : };
     303             : 
     304             : /*-************************************************************************************************************//**
     305             :     @descr  Implement the base data container.
     306             : *//*-*************************************************************************************************************/
     307             : 
     308             : /*-************************************************************************************************************//**
     309             :     @short          ctor
     310             :     @descr          We use it to open right configuration file and let configuration objects fill her caches.
     311             :                     Then we read all existing entries from right list and cached it inside our object too.
     312             :                     Normaly we should enable notifications for changes on these values too ... but these feature
     313             :                     isn't full implemented in the moment.
     314             : 
     315             :     @seealso        baseclass ::utl::ConfigItem
     316             :     @seealso        method Notify()
     317             : 
     318             :     @param          -
     319             :     @return         -
     320             : *//*-*************************************************************************************************************/
     321          76 : SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const ::rtl::OUString& sList )
     322          76 :         :   m_sListName  ( sList )    // we must know, which view type we must support
     323             :         #ifdef DEBUG_VIEWOPTIONS
     324             :         ,   m_nReadCount ( 0     )
     325             :         ,   m_nWriteCount( 0     )
     326             :         #endif
     327             : {
     328             :     try
     329             :     {
     330             :         m_xRoot = css::uno::Reference< css::container::XNameAccess >(
     331             :                         ::comphelper::ConfigurationHelper::openConfig(
     332             :                             ::comphelper::getProcessComponentContext(),
     333             :                             PACKAGE_VIEWS,
     334             :                             ::comphelper::ConfigurationHelper::E_STANDARD),
     335          76 :                         css::uno::UNO_QUERY);
     336          76 :         if (m_xRoot.is())
     337          76 :             m_xRoot->getByName(sList) >>= m_xSet;
     338             :     }
     339           0 :     catch(const css::uno::Exception& ex)
     340             :         {
     341           0 :             m_xRoot.clear();
     342           0 :             m_xSet.clear();
     343             : 
     344           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     345             :         }
     346          76 : }
     347             : 
     348             : /*-************************************************************************************************************//**
     349             :     @short          dtor
     350             :     @descr          clean up something
     351             : 
     352             :     @attention      We implement a write through cache! So we mustn't do it realy. All changes was written to cfg directly.
     353             :                     Commit isn't neccessary then.
     354             : 
     355             :     @seealso        baseclass ::utl::ConfigItem
     356             :     @seealso        method IsModified()
     357             :     @seealso        method SetModified()
     358             :     @seealso        method Commit()
     359             : 
     360             :     @param          -
     361             :     @return         -
     362             : *//*-*************************************************************************************************************/
     363           0 : SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
     364             : {
     365             :     // dont flush configuration changes here to m_xRoot.
     366             :     // That must be done inside every SetXXX() method already !
     367             :     // Here its to late - DisposedExceptions from used configuration access can occure otherwise.
     368             : 
     369           0 :     m_xRoot.clear();
     370           0 :     m_xSet.clear();
     371             : 
     372             :     #ifdef DEBUG_VIEWOPTIONS
     373             :     _LOG_COUNTER_( m_sListName, m_nReadCount, m_nWriteCount )
     374             :     #endif // DEBUG_VIEWOPTIONS
     375           0 : }
     376             : 
     377             : /*-************************************************************************************************************//**
     378             :     @short          checks for already existing entries
     379             :     @descr          If user don't know, if an entry already exist - he can get this information by calling this method.
     380             : 
     381             :     @seealso        member m_aList
     382             : 
     383             :     @param          "sName", name of entry to check exist state
     384             :     @return         true , if item exist
     385             :                     false, otherwise
     386             : *//*-*************************************************************************************************************/
     387        7543 : sal_Bool SvtViewOptionsBase_Impl::Exists( const ::rtl::OUString& sName )
     388             : {
     389        7543 :     sal_Bool bExists = sal_False;
     390             : 
     391             :     try
     392             :     {
     393        7543 :         if (m_xSet.is())
     394        7543 :             bExists = m_xSet->hasByName(sName);
     395             :     }
     396           0 :     catch(const css::uno::Exception& ex)
     397             :         {
     398           0 :             bExists = sal_False;
     399           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     400             :         }
     401             : 
     402        7543 :     return bExists;
     403             : }
     404             : 
     405             : /*-************************************************************************************************************//**
     406             :     @short          delete entry
     407             :     @descr          Use it to delete set entry by given name.
     408             : 
     409             :     @seealso        member m_aList
     410             : 
     411             :     @param          "sName", name of entry to delete it
     412             :     @return         true , if item not exist(!) or could be deleted (should be the same!)
     413             :                     false, otherwise
     414             : *//*-*************************************************************************************************************/
     415           0 : sal_Bool SvtViewOptionsBase_Impl::Delete( const ::rtl::OUString& sName )
     416             : {
     417             :     #ifdef DEBUG_VIEWOPTIONS
     418             :     ++m_nWriteCount;
     419             :     #endif
     420             : 
     421           0 :     sal_Bool bDeleted = sal_False;
     422             :     try
     423             :     {
     424           0 :         css::uno::Reference< css::container::XNameContainer > xSet(m_xSet, css::uno::UNO_QUERY_THROW);
     425           0 :         xSet->removeByName(sName);
     426           0 :         bDeleted = sal_True;
     427           0 :         ::comphelper::ConfigurationHelper::flush(m_xRoot);
     428             :     }
     429           0 :     catch(const css::container::NoSuchElementException&)
     430           0 :         { bDeleted = sal_True; }
     431           0 :     catch(const css::uno::Exception& ex)
     432             :         {
     433           0 :             bDeleted = sal_False;
     434           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     435             :         }
     436             : 
     437           0 :     return bDeleted;
     438             : }
     439             : 
     440             : /*-************************************************************************************************************//**
     441             :     @short          read/write access to cache view items and her properties
     442             :     @descr          Follow methods support read/write access to all cache view items.
     443             : 
     444             :     @seealso        member m_sList
     445             : 
     446             :     @param          -
     447             :     @return         -
     448             : *//*-*************************************************************************************************************/
     449        7543 : ::rtl::OUString SvtViewOptionsBase_Impl::GetWindowState( const ::rtl::OUString& sName )
     450             : {
     451             :     #ifdef DEBUG_VIEWOPTIONS
     452             :     ++m_nReadCount;
     453             :     #endif
     454             : 
     455        7543 :     ::rtl::OUString sWindowState;
     456             :     try
     457             :     {
     458             :         css::uno::Reference< css::beans::XPropertySet > xNode(
     459             :             impl_getSetNode(sName, sal_False),
     460        7543 :             css::uno::UNO_QUERY);
     461        7543 :         if (xNode.is())
     462         464 :             xNode->getPropertyValue(PROPERTY_WINDOWSTATE) >>= sWindowState;
     463             :     }
     464           0 :     catch(const css::uno::Exception& ex)
     465             :         {
     466           0 :             sWindowState = ::rtl::OUString();
     467           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     468             :         }
     469             : 
     470        7543 :     return sWindowState;
     471             : }
     472             : 
     473             : //*****************************************************************************************************************
     474         236 : void SvtViewOptionsBase_Impl::SetWindowState( const ::rtl::OUString& sName  ,
     475             :                                               const ::rtl::OUString& sState )
     476             : {
     477             :     #ifdef DEBUG_VIEWOPTIONS
     478             :     ++m_nWriteCount;
     479             :     #endif
     480             : 
     481             :     try
     482             :     {
     483             :         css::uno::Reference< css::beans::XPropertySet > xNode(
     484             :             impl_getSetNode(sName, sal_True),
     485         236 :             css::uno::UNO_QUERY_THROW);
     486         236 :         xNode->setPropertyValue(PROPERTY_WINDOWSTATE, css::uno::makeAny(sState));
     487         236 :         ::comphelper::ConfigurationHelper::flush(m_xRoot);
     488             :     }
     489           0 :     catch(const css::uno::Exception& ex)
     490             :         {
     491           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     492             :         }
     493         236 : }
     494             : 
     495             : //*****************************************************************************************************************
     496        7543 : css::uno::Sequence< css::beans::NamedValue > SvtViewOptionsBase_Impl::GetUserData( const ::rtl::OUString& sName )
     497             : {
     498             :     #ifdef DEBUG_VIEWOPTIONS
     499             :     ++m_nReadCount;
     500             :     #endif
     501             : 
     502             :     try
     503             :     {
     504             :         css::uno::Reference< css::container::XNameAccess > xNode(
     505             :             impl_getSetNode(sName, sal_False),
     506        7543 :             css::uno::UNO_QUERY); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
     507        7543 :         css::uno::Reference< css::container::XNameAccess > xUserData;
     508        7543 :         if (xNode.is())
     509         464 :             xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
     510        7543 :         if (xUserData.is())
     511             :         {
     512         464 :             const css::uno::Sequence< ::rtl::OUString >         lNames = xUserData->getElementNames();
     513         464 :             const ::rtl::OUString*                              pNames = lNames.getConstArray();
     514         464 :                   sal_Int32                                     c      = lNames.getLength();
     515         464 :                   sal_Int32                                     i      = 0;
     516         464 :                   css::uno::Sequence< css::beans::NamedValue >  lUserData(c);
     517             : 
     518         692 :             for (i=0; i<c; ++i)
     519             :             {
     520         228 :                 lUserData[i].Name  = pNames[i];
     521         228 :                 lUserData[i].Value = xUserData->getByName(pNames[i]);
     522             :             }
     523             : 
     524         464 :             return lUserData;
     525        7543 :         }
     526             :     }
     527           0 :     catch(const css::uno::Exception& ex)
     528             :         {
     529           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     530             :         }
     531             : 
     532        7079 :     return css::uno::Sequence< css::beans::NamedValue >();
     533             : }
     534             : 
     535             : //*****************************************************************************************************************
     536         236 : void SvtViewOptionsBase_Impl::SetUserData( const ::rtl::OUString&                              sName  ,
     537             :                                            const css::uno::Sequence< css::beans::NamedValue >& lData  )
     538             : {
     539             :     #ifdef DEBUG_VIEWOPTIONS
     540             :     ++m_nWriteCount;
     541             :     #endif
     542             : 
     543             :     try
     544             :     {
     545             :         css::uno::Reference< css::container::XNameAccess > xNode(
     546             :             impl_getSetNode(sName, sal_True),
     547         236 :             css::uno::UNO_QUERY_THROW);
     548         236 :         css::uno::Reference< css::container::XNameContainer > xUserData;
     549         236 :         xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
     550         236 :         if (xUserData.is())
     551             :         {
     552         236 :             const css::beans::NamedValue* pData = lData.getConstArray();
     553         236 :                   sal_Int32               c     = lData.getLength();
     554         236 :                   sal_Int32               i     = 0;
     555         472 :             for (i=0; i<c; ++i)
     556             :             {
     557         236 :                 if (xUserData->hasByName(pData[i].Name))
     558         228 :                     xUserData->replaceByName(pData[i].Name, pData[i].Value);
     559             :                 else
     560           8 :                     xUserData->insertByName(pData[i].Name, pData[i].Value);
     561             :             }
     562             :         }
     563         236 :         ::comphelper::ConfigurationHelper::flush(m_xRoot);
     564             :     }
     565           0 :     catch(const css::uno::Exception& ex)
     566             :         {
     567           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     568             :         }
     569         236 : }
     570             : 
     571             : //*****************************************************************************************************************
     572         960 : css::uno::Any SvtViewOptionsBase_Impl::GetUserItem( const ::rtl::OUString& sName ,
     573             :                                                     const ::rtl::OUString& sItem )
     574             : {
     575             :     #ifdef DEBUG_VIEWOPTIONS
     576             :     ++m_nReadCount;
     577             :     #endif
     578             : 
     579         960 :     css::uno::Any aItem;
     580             :     try
     581             :     {
     582             :         css::uno::Reference< css::container::XNameAccess > xNode(
     583             :             impl_getSetNode(sName, sal_False),
     584         960 :             css::uno::UNO_QUERY);
     585         960 :         css::uno::Reference< css::container::XNameAccess > xUserData;
     586         960 :         if (xNode.is())
     587         428 :             xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
     588         960 :         if (xUserData.is())
     589         428 :             aItem = xUserData->getByName(sItem);
     590             :     }
     591           0 :     catch(const css::container::NoSuchElementException&)
     592           0 :         { aItem.clear(); }
     593           0 :     catch(const css::uno::Exception& ex)
     594             :         {
     595           0 :             aItem.clear();
     596           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     597             :         }
     598             : 
     599         960 :     return aItem;
     600             : }
     601             : 
     602             : //*****************************************************************************************************************
     603         252 : void SvtViewOptionsBase_Impl::SetUserItem( const ::rtl::OUString& sName  ,
     604             :                                            const ::rtl::OUString& sItem  ,
     605             :                                            const css::uno::Any&   aValue )
     606             : {
     607             :     #ifdef DEBUG_VIEWOPTIONS
     608             :     ++m_nWriteCount;
     609             :     #endif
     610             : 
     611             :     try
     612             :     {
     613             :         css::uno::Reference< css::container::XNameAccess > xNode(
     614             :             impl_getSetNode(sName, sal_True),
     615         252 :             css::uno::UNO_QUERY_THROW);
     616         252 :         css::uno::Reference< css::container::XNameContainer > xUserData;
     617         252 :         xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
     618         252 :         if (xUserData.is())
     619             :         {
     620         252 :             if (xUserData->hasByName(sItem))
     621         220 :                 xUserData->replaceByName(sItem, aValue);
     622             :             else
     623          32 :                 xUserData->insertByName(sItem, aValue);
     624             :         }
     625         252 :         ::comphelper::ConfigurationHelper::flush(m_xRoot);
     626             :     }
     627           0 :     catch(const css::uno::Exception& ex)
     628             :         {
     629           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     630             :         }
     631         252 : }
     632             : 
     633             : //*****************************************************************************************************************
     634           0 : sal_Int32 SvtViewOptionsBase_Impl::GetPageID( const ::rtl::OUString& sName )
     635             : {
     636             :     #ifdef DEBUG_VIEWOPTIONS
     637             :     ++m_nReadCount;
     638             :     #endif
     639             : 
     640           0 :     sal_Int32 nID = 0;
     641             :     try
     642             :     {
     643             :         css::uno::Reference< css::beans::XPropertySet > xNode(
     644             :             impl_getSetNode(sName, sal_False),
     645           0 :             css::uno::UNO_QUERY);
     646           0 :         if (xNode.is())
     647           0 :             xNode->getPropertyValue(PROPERTY_PAGEID) >>= nID;
     648             :     }
     649           0 :     catch(const css::uno::Exception& ex)
     650             :         {
     651           0 :             nID = 0;
     652           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     653             :         }
     654             : 
     655           0 :     return nID;
     656             : }
     657             : 
     658             : //*****************************************************************************************************************
     659           0 : void SvtViewOptionsBase_Impl::SetPageID( const ::rtl::OUString& sName ,
     660             :                                                sal_Int32        nID   )
     661             : {
     662             :     #ifdef DEBUG_VIEWOPTIONS
     663             :     ++m_nWriteCount;
     664             :     #endif
     665             : 
     666             :     try
     667             :     {
     668             :         css::uno::Reference< css::beans::XPropertySet > xNode(
     669             :             impl_getSetNode(sName, sal_True),
     670           0 :             css::uno::UNO_QUERY_THROW);
     671           0 :         xNode->setPropertyValue(PROPERTY_PAGEID, css::uno::makeAny(nID));
     672           0 :         ::comphelper::ConfigurationHelper::flush(m_xRoot);
     673             :     }
     674           0 :     catch(const css::uno::Exception& ex)
     675             :         {
     676           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     677             :         }
     678           0 : }
     679             : 
     680             : //*****************************************************************************************************************
     681         700 : SvtViewOptionsBase_Impl::State SvtViewOptionsBase_Impl::GetVisible( const ::rtl::OUString& sName )
     682             : {
     683             :     #ifdef DEBUG_VIEWOPTIONS
     684             :     ++m_nReadCount;
     685             :     #endif
     686             : 
     687         700 :     State eState = STATE_NONE;
     688             :     try
     689             :     {
     690             :         css::uno::Reference< css::beans::XPropertySet > xNode(
     691             :             impl_getSetNode(sName, sal_False),
     692         700 :             css::uno::UNO_QUERY);
     693         700 :         if (xNode.is())
     694             :         {
     695         700 :             sal_Bool bVisible = sal_False;
     696         700 :             if (xNode->getPropertyValue(PROPERTY_VISIBLE) >>= bVisible)
     697             :             {
     698         472 :                 eState = bVisible ? STATE_TRUE : STATE_FALSE;
     699             :             }
     700         700 :         }
     701             :     }
     702           0 :     catch(const css::uno::Exception& ex)
     703             :         {
     704           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     705             :         }
     706             : 
     707         700 :     return eState;
     708             : }
     709             : 
     710             : //*****************************************************************************************************************
     711           0 : void SvtViewOptionsBase_Impl::SetVisible( const ::rtl::OUString& sName    ,
     712             :                                                 sal_Bool         bVisible )
     713             : {
     714             :     #ifdef DEBUG_VIEWOPTIONS
     715             :     ++m_nWriteCount;
     716             :     #endif
     717             : 
     718             :     try
     719             :     {
     720             :         css::uno::Reference< css::beans::XPropertySet > xNode(
     721             :             impl_getSetNode(sName, sal_True),
     722           0 :             css::uno::UNO_QUERY_THROW);
     723           0 :         xNode->setPropertyValue(PROPERTY_VISIBLE, css::uno::makeAny(bVisible));
     724           0 :         ::comphelper::ConfigurationHelper::flush(m_xRoot);
     725             :     }
     726           0 :     catch(const css::uno::Exception& ex)
     727             :         {
     728           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     729             :         }
     730           0 : }
     731             : 
     732             : /*-************************************************************************************************************//**
     733             :     @short          create new set node with default values on disk
     734             :     @descr          To create a new UserData item - the super node of these property must already exist!
     735             :                     You can call this method to create these new entry with default values and change UserData then.
     736             : 
     737             :     @seealso        method impl_writeDirectProp()
     738             : 
     739             :     @param          "sNode", name of new entry
     740             :     @return         -
     741             : *//*-*************************************************************************************************************/
     742       17470 : css::uno::Reference< css::uno::XInterface > SvtViewOptionsBase_Impl::impl_getSetNode( const ::rtl::OUString& sNode           ,
     743             :                                                                                             sal_Bool         bCreateIfMissing)
     744             : {
     745       17470 :     css::uno::Reference< css::uno::XInterface > xNode;
     746             : 
     747             :     try
     748             :     {
     749       17470 :         if (bCreateIfMissing)
     750         724 :             xNode = ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot, m_sListName, sNode);
     751             :         else
     752             :         {
     753       16746 :             if (m_xSet.is() && m_xSet->hasByName(sNode) )
     754        2056 :                 m_xSet->getByName(sNode) >>= xNode;
     755             :         }
     756             :     }
     757           0 :     catch(const css::container::NoSuchElementException&)
     758           0 :         { xNode.clear(); }
     759           0 :     catch(const css::uno::Exception& ex)
     760             :         {
     761           0 :             xNode.clear();
     762           0 :             SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
     763             :         }
     764             : 
     765       17470 :     return xNode;
     766             : }
     767             : 
     768             : //*****************************************************************************************************************
     769             : //  constructor
     770             : //*****************************************************************************************************************
     771        9067 : SvtViewOptions::SvtViewOptions(       EViewType        eType     ,
     772             :                                 const ::rtl::OUString& sViewName )
     773             :     :   m_eViewType ( eType     )
     774        9067 :     ,   m_sViewName ( sViewName )
     775             : {
     776             :     // Global access, must be guarded (multithreading!)
     777        9067 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
     778             : 
     779             :     // Search for right dat container for this view type and initialize right data container or set right ref count!
     780        9067 :     switch( eType )
     781             :     {
     782             :         case E_DIALOG       :   {
     783             :                                     // Increase ref count for dialog data container first.
     784          19 :                                     ++m_nRefCount_Dialogs;
     785             :                                     // If these instance the first user of the dialog data container - create these impl static container!
     786          19 :                                     if( m_nRefCount_Dialogs == 1 )
     787             :                                     {
     788             :                                         //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
     789           0 :                                         m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
     790           0 :                                         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
     791             :                                     }
     792             :                                 }
     793          19 :                                 break;
     794             :         case E_TABDIALOG    :   {
     795             :                                     // Increase ref count for tab-dialog data container first.
     796          19 :                                     ++m_nRefCount_TabDialogs;
     797             :                                     // If these instance the first user of the tab-dialog data container - create these impl static container!
     798          19 :                                     if( m_nRefCount_TabDialogs == 1 )
     799             :                                     {
     800           0 :                                         m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
     801           0 :                                         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
     802             :                                     }
     803             :                                 }
     804          19 :                                 break;
     805             :         case E_TABPAGE      :   {
     806             :                                     // Increase ref count for tab-page data container first.
     807          19 :                                     ++m_nRefCount_TabPages;
     808             :                                     // If these instance the first user of the tab-page data container - create these impl static container!
     809          19 :                                     if( m_nRefCount_TabPages == 1 )
     810             :                                     {
     811           0 :                                         m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
     812           0 :                                         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
     813             :                                     }
     814             :                                 }
     815          19 :                                 break;
     816             :         case E_WINDOW       :   {
     817             :                                     // Increase ref count for window data container first.
     818        9010 :                                     ++m_nRefCount_Windows;
     819             :                                     // If these instance the first user of the window data container - create these impl static container!
     820        9010 :                                     if( m_nRefCount_Windows == 1 )
     821             :                                     {
     822           0 :                                         m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
     823           0 :                                         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
     824             :                                     }
     825             :                                 }
     826        9010 :                                 break;
     827             :         default             :   OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
     828        9067 :     }
     829        9067 : }
     830             : 
     831             : //*****************************************************************************************************************
     832             : //  destructor
     833             : //*****************************************************************************************************************
     834       18210 : SvtViewOptions::~SvtViewOptions()
     835             : {
     836             :     // Global access, must be guarded (multithreading!)
     837        9067 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
     838             : 
     839             :     // Search for right dat container for this view type and deinitialize right data container or set right ref count!
     840        9067 :     switch( m_eViewType )
     841             :     {
     842             :         case E_DIALOG       :   {
     843             :                                     // Decrease ref count for dialog data container first.
     844          19 :                                     --m_nRefCount_Dialogs;
     845             :                                     // If these instance the last user of the dialog data container - delete these impl static container!
     846          19 :                                     if( m_nRefCount_Dialogs == 0 )
     847             :                                     {
     848           0 :                                         delete m_pDataContainer_Dialogs;
     849           0 :                                         m_pDataContainer_Dialogs = NULL;
     850             :                                     }
     851             :                                 }
     852          19 :                                 break;
     853             :         case E_TABDIALOG    :   {
     854             :                                     // Decrease ref count for tab-dialog data container first.
     855          19 :                                     --m_nRefCount_TabDialogs;
     856             :                                     // If these instance the last user of the tab-dialog data container - delete these impl static container!
     857          19 :                                     if( m_nRefCount_TabDialogs == 0 )
     858             :                                     {
     859           0 :                                         delete m_pDataContainer_TabDialogs;
     860           0 :                                         m_pDataContainer_TabDialogs = NULL;
     861             :                                     }
     862             :                                 }
     863          19 :                                 break;
     864             :         case E_TABPAGE      :   {
     865             :                                     // Decrease ref count for tab-page data container first.
     866          19 :                                     --m_nRefCount_TabPages;
     867             :                                     // If these instance the last user of the tab-page data container - delete these impl static container!
     868          19 :                                     if( m_nRefCount_TabPages == 0 )
     869             :                                     {
     870           0 :                                         delete m_pDataContainer_TabPages;
     871           0 :                                         m_pDataContainer_TabPages = NULL;
     872             :                                     }
     873             :                                 }
     874          19 :                                 break;
     875             :         case E_WINDOW       :   {
     876             :                                     // Decrease ref count for window data container first.
     877        9010 :                                     --m_nRefCount_Windows;
     878             :                                     // If these instance the last user of the window data container - delete these impl static container!
     879        9010 :                                     if( m_nRefCount_Windows == 0 )
     880             :                                     {
     881           0 :                                         delete m_pDataContainer_Windows;
     882           0 :                                         m_pDataContainer_Windows = NULL;
     883             :                                     }
     884             :                                 }
     885        9010 :                                 break;
     886        9067 :     }
     887        9143 : }
     888             : 
     889             : //*****************************************************************************************************************
     890             : //  public method
     891             : //*****************************************************************************************************************
     892        7543 : sal_Bool SvtViewOptions::Exists() const
     893             : {
     894             :     // Ready for multithreading
     895        7543 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
     896             : 
     897        7543 :     sal_Bool bExists = sal_False;
     898        7543 :     switch( m_eViewType )
     899             :     {
     900             :         case E_DIALOG       :   {
     901           0 :                                     bExists = m_pDataContainer_Dialogs->Exists( m_sViewName );
     902             :                                 }
     903           0 :                                 break;
     904             :         case E_TABDIALOG    :   {
     905           0 :                                     bExists = m_pDataContainer_TabDialogs->Exists( m_sViewName );
     906             :                                 }
     907           0 :                                 break;
     908             :         case E_TABPAGE      :   {
     909           0 :                                     bExists = m_pDataContainer_TabPages->Exists( m_sViewName );
     910             :                                 }
     911           0 :                                 break;
     912             :         case E_WINDOW       :   {
     913        7543 :                                     bExists = m_pDataContainer_Windows->Exists( m_sViewName );
     914             :                                 }
     915        7543 :                                 break;
     916             :     }
     917        7543 :     return bExists;
     918             : }
     919             : 
     920             : //*****************************************************************************************************************
     921             : //  public method
     922             : //*****************************************************************************************************************
     923           0 : sal_Bool SvtViewOptions::Delete()
     924             : {
     925             :     // Ready for multithreading
     926           0 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
     927             : 
     928           0 :     sal_Bool bState = sal_False;
     929           0 :     switch( m_eViewType )
     930             :     {
     931             :         case E_DIALOG       :   {
     932           0 :                                     bState = m_pDataContainer_Dialogs->Delete( m_sViewName );
     933             :                                 }
     934           0 :                                 break;
     935             :         case E_TABDIALOG    :   {
     936           0 :                                     bState = m_pDataContainer_TabDialogs->Delete( m_sViewName );
     937             :                                 }
     938           0 :                                 break;
     939             :         case E_TABPAGE      :   {
     940           0 :                                     bState = m_pDataContainer_TabPages->Delete( m_sViewName );
     941             :                                 }
     942           0 :                                 break;
     943             :         case E_WINDOW       :   {
     944           0 :                                     bState = m_pDataContainer_Windows->Delete( m_sViewName );
     945             :                                 }
     946           0 :                                 break;
     947             :     }
     948           0 :     return bState;
     949             : }
     950             : 
     951             : //*****************************************************************************************************************
     952             : //  public method
     953             : //*****************************************************************************************************************
     954        7543 : ::rtl::OUString SvtViewOptions::GetWindowState() const
     955             : {
     956             :     // Ready for multithreading
     957        7543 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
     958             : 
     959        7543 :     ::rtl::OUString sState;
     960        7543 :     switch( m_eViewType )
     961             :     {
     962             :         case E_DIALOG       :   {
     963           0 :                                     sState = m_pDataContainer_Dialogs->GetWindowState( m_sViewName );
     964             :                                 }
     965           0 :                                 break;
     966             :         case E_TABDIALOG    :   {
     967           0 :                                     sState = m_pDataContainer_TabDialogs->GetWindowState( m_sViewName );
     968             :                                 }
     969           0 :                                 break;
     970             :         case E_TABPAGE      :   {
     971           0 :                                     sState = m_pDataContainer_TabPages->GetWindowState( m_sViewName );
     972             :                                 }
     973           0 :                                 break;
     974             :         case E_WINDOW       :   {
     975        7543 :                                     sState = m_pDataContainer_Windows->GetWindowState( m_sViewName );
     976             :                                 }
     977        7543 :                                 break;
     978             :     }
     979        7543 :     return sState;
     980             : }
     981             : 
     982             : //*****************************************************************************************************************
     983             : //  public method
     984             : //*****************************************************************************************************************
     985         236 : void SvtViewOptions::SetWindowState( const ::rtl::OUString& sState )
     986             : {
     987             :     // Ready for multithreading
     988         236 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
     989             : 
     990         236 :     switch( m_eViewType )
     991             :     {
     992             :         case E_DIALOG       :   {
     993           0 :                                     m_pDataContainer_Dialogs->SetWindowState( m_sViewName, sState );
     994             :                                 }
     995           0 :                                 break;
     996             :         case E_TABDIALOG    :   {
     997           0 :                                     m_pDataContainer_TabDialogs->SetWindowState( m_sViewName, sState );
     998             :                                 }
     999           0 :                                 break;
    1000             :         case E_TABPAGE      :   {
    1001           0 :                                     m_pDataContainer_TabPages->SetWindowState( m_sViewName, sState );
    1002             :                                 }
    1003           0 :                                 break;
    1004             :         case E_WINDOW       :   {
    1005         236 :                                     m_pDataContainer_Windows->SetWindowState( m_sViewName, sState );
    1006             :                                 }
    1007         236 :                                 break;
    1008         236 :     }
    1009         236 : }
    1010             : 
    1011             : //*****************************************************************************************************************
    1012             : //  public method
    1013             : //*****************************************************************************************************************
    1014           0 : sal_Int32 SvtViewOptions::GetPageID() const
    1015             : {
    1016             :     // Ready for multithreading
    1017           0 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1018             : 
    1019             :     // Safe impossible cases.
    1020             :     // These call isn't allowed for dialogs, tab-pages or windows!
    1021             :     OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABPAGE||m_eViewType==E_WINDOW), "SvtViewOptions::GetPageID()\nCall not allowed for Dialogs, TabPages or Windows! I do nothing!\n" );
    1022             : 
    1023           0 :     sal_Int32 nID = 0;
    1024           0 :     if( m_eViewType == E_TABDIALOG )
    1025           0 :         nID = m_pDataContainer_TabDialogs->GetPageID( m_sViewName );
    1026           0 :     return nID;
    1027             : }
    1028             : 
    1029             : //*****************************************************************************************************************
    1030             : //  public method
    1031             : //*****************************************************************************************************************
    1032           0 : void SvtViewOptions::SetPageID( sal_Int32 nID )
    1033             : {
    1034             :     // Ready for multithreading
    1035           0 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1036             : 
    1037             :     // Safe impossible cases.
    1038             :     // These call isn't allowed for dialogs, tab-pages or windows!
    1039             :     OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABPAGE||m_eViewType==E_WINDOW), "SvtViewOptions::SetPageID()\nCall not allowed for Dialogs, TabPages or Windows! I do nothing!\n" );
    1040             : 
    1041           0 :     if( m_eViewType == E_TABDIALOG )
    1042           0 :         m_pDataContainer_TabDialogs->SetPageID( m_sViewName, nID );
    1043           0 : }
    1044             : 
    1045             : //*****************************************************************************************************************
    1046             : //  public method
    1047             : //*****************************************************************************************************************
    1048         236 : sal_Bool SvtViewOptions::IsVisible() const
    1049             : {
    1050             :     // Ready for multithreading
    1051         236 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1052             : 
    1053             :     // Safe impossible cases.
    1054             :     // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
    1055             :     OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABDIALOG||m_eViewType==E_TABPAGE), "SvtViewOptions::IsVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
    1056             : 
    1057         236 :     sal_Bool bState = sal_False;
    1058         236 :     if( m_eViewType == E_WINDOW )
    1059         236 :         bState = m_pDataContainer_Windows->GetVisible( m_sViewName ) == SvtViewOptionsBase_Impl::STATE_TRUE;
    1060             : 
    1061         236 :     return bState;
    1062             : }
    1063             : 
    1064             : //*****************************************************************************************************************
    1065             : //  public method
    1066             : //*****************************************************************************************************************
    1067           0 : void SvtViewOptions::SetVisible( sal_Bool bState )
    1068             : {
    1069             :     // Ready for multithreading
    1070           0 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1071             : 
    1072             :     // Safe impossible cases.
    1073             :     // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
    1074             :     OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABDIALOG||m_eViewType==E_TABPAGE), "SvtViewOptions::SetVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
    1075             : 
    1076           0 :     if( m_eViewType == E_WINDOW )
    1077           0 :         m_pDataContainer_Windows->SetVisible( m_sViewName, bState );
    1078           0 : }
    1079             : 
    1080             : //*****************************************************************************************************************
    1081             : //  public method
    1082             : //*****************************************************************************************************************
    1083         464 : bool SvtViewOptions::HasVisible() const
    1084             : {
    1085             :     // Ready for multithreading
    1086         464 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1087             : 
    1088             :     // Safe impossible cases.
    1089             :     // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
    1090             :     OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABDIALOG||m_eViewType==E_TABPAGE), "SvtViewOptions::IsVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
    1091             : 
    1092         464 :     bool bState = false;
    1093         464 :     if( m_eViewType == E_WINDOW )
    1094         464 :         bState = m_pDataContainer_Windows->GetVisible( m_sViewName ) != SvtViewOptionsBase_Impl::STATE_NONE;
    1095             : 
    1096         464 :     return bState;
    1097             : }
    1098             : 
    1099             : //*****************************************************************************************************************
    1100        7543 : css::uno::Sequence< css::beans::NamedValue > SvtViewOptions::GetUserData() const
    1101             : {
    1102             :     // Ready for multithreading
    1103        7543 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1104             : 
    1105        7543 :     css::uno::Sequence< css::beans::NamedValue > lData;
    1106        7543 :     switch( m_eViewType )
    1107             :     {
    1108             :         case E_DIALOG       :   {
    1109           0 :                                     lData = m_pDataContainer_Dialogs->GetUserData( m_sViewName );
    1110             :                                 }
    1111           0 :                                 break;
    1112             :         case E_TABDIALOG    :   {
    1113           0 :                                     lData = m_pDataContainer_TabDialogs->GetUserData( m_sViewName );
    1114             :                                 }
    1115           0 :                                 break;
    1116             :         case E_TABPAGE      :   {
    1117           0 :                                     lData = m_pDataContainer_TabPages->GetUserData( m_sViewName );
    1118             :                                 }
    1119           0 :                                 break;
    1120             :         case E_WINDOW       :   {
    1121        7543 :                                     lData = m_pDataContainer_Windows->GetUserData( m_sViewName );
    1122             :                                 }
    1123        7543 :                                 break;
    1124             :     }
    1125        7543 :     return lData;
    1126             : }
    1127             : 
    1128             : //*****************************************************************************************************************
    1129         236 : void SvtViewOptions::SetUserData( const css::uno::Sequence< css::beans::NamedValue >& lData )
    1130             : {
    1131             :     // Ready for multithreading
    1132         236 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1133             : 
    1134         236 :     switch( m_eViewType )
    1135             :     {
    1136             :         case E_DIALOG       :   {
    1137           0 :                                     m_pDataContainer_Dialogs->SetUserData( m_sViewName, lData );
    1138             :                                 }
    1139           0 :                                 break;
    1140             :         case E_TABDIALOG    :   {
    1141           0 :                                     m_pDataContainer_TabDialogs->SetUserData( m_sViewName, lData );
    1142             :                                 }
    1143           0 :                                 break;
    1144             :         case E_TABPAGE      :   {
    1145           0 :                                     m_pDataContainer_TabPages->SetUserData( m_sViewName, lData );
    1146             :                                 }
    1147           0 :                                 break;
    1148             :         case E_WINDOW       :   {
    1149         236 :                                     m_pDataContainer_Windows->SetUserData( m_sViewName, lData );
    1150             :                                 }
    1151         236 :                                 break;
    1152         236 :     }
    1153         236 : }
    1154             : 
    1155             : //*****************************************************************************************************************
    1156         960 : css::uno::Any SvtViewOptions::GetUserItem( const ::rtl::OUString& sName ) const
    1157             : {
    1158             :     // Ready for multithreading
    1159         960 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1160             : 
    1161         960 :     css::uno::Any aItem;
    1162         960 :     switch( m_eViewType )
    1163             :     {
    1164             :         case E_DIALOG       :   {
    1165           0 :                                     aItem = m_pDataContainer_Dialogs->GetUserItem( m_sViewName, sName );
    1166             :                                 }
    1167           0 :                                 break;
    1168             :         case E_TABDIALOG    :   {
    1169           0 :                                     aItem = m_pDataContainer_TabDialogs->GetUserItem( m_sViewName, sName );
    1170             :                                 }
    1171           0 :                                 break;
    1172             :         case E_TABPAGE      :   {
    1173           0 :                                     aItem = m_pDataContainer_TabPages->GetUserItem( m_sViewName, sName );
    1174             :                                 }
    1175           0 :                                 break;
    1176             :         case E_WINDOW       :   {
    1177         960 :                                     aItem = m_pDataContainer_Windows->GetUserItem( m_sViewName, sName );
    1178             :                                 }
    1179         960 :                                 break;
    1180             :     }
    1181         960 :     return aItem;
    1182             : }
    1183             : 
    1184             : //*****************************************************************************************************************
    1185         252 : void SvtViewOptions::SetUserItem( const ::rtl::OUString& sName  ,
    1186             :                                   const css::uno::Any&   aValue )
    1187             : {
    1188             :     // Ready for multithreading
    1189         252 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1190             : 
    1191         252 :     switch( m_eViewType )
    1192             :     {
    1193             :         case E_DIALOG       :   {
    1194           0 :                                     m_pDataContainer_Dialogs->SetUserItem( m_sViewName, sName, aValue );
    1195             :                                 }
    1196           0 :                                 break;
    1197             :         case E_TABDIALOG    :   {
    1198           0 :                                     m_pDataContainer_TabDialogs->SetUserItem( m_sViewName, sName, aValue );
    1199             :                                 }
    1200           0 :                                 break;
    1201             :         case E_TABPAGE      :   {
    1202           0 :                                     m_pDataContainer_TabPages->SetUserItem( m_sViewName, sName, aValue );
    1203             :                                 }
    1204           0 :                                 break;
    1205             :         case E_WINDOW       :   {
    1206         252 :                                     m_pDataContainer_Windows->SetUserItem( m_sViewName, sName, aValue );
    1207             :                                 }
    1208         252 :                                 break;
    1209         252 :     }
    1210         252 : }
    1211             : 
    1212             : namespace
    1213             : {
    1214             :     class theViewOptionsMutex : public rtl::Static<osl::Mutex, theViewOptionsMutex>{};
    1215             : }
    1216             : 
    1217             : //*****************************************************************************************************************
    1218             : //  private method
    1219             : //*****************************************************************************************************************
    1220       43166 : ::osl::Mutex& SvtViewOptions::GetOwnStaticMutex()
    1221             : {
    1222       43166 :     return theViewOptionsMutex::get();
    1223             : }
    1224             : 
    1225          19 : void SvtViewOptions::AcquireOptions()
    1226             : {
    1227          19 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1228          19 :     if( ++m_nRefCount_Dialogs == 1 )
    1229             :     {
    1230          19 :         m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
    1231          19 :         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
    1232             :     }
    1233          19 :     if( ++m_nRefCount_TabDialogs == 1 )
    1234             :     {
    1235          19 :         m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
    1236          19 :         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
    1237             :     }
    1238          19 :     if( ++m_nRefCount_TabPages == 1 )
    1239             :     {
    1240          19 :         m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
    1241          19 :         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
    1242             :     }
    1243          19 :     if( ++m_nRefCount_Windows == 1 )
    1244             :     {
    1245          19 :         m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
    1246          19 :         ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
    1247          19 :     }
    1248          19 : }
    1249             : 
    1250           0 : void SvtViewOptions::ReleaseOptions()
    1251             : {
    1252           0 :     ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
    1253           0 :     if( --m_nRefCount_Dialogs == 0 )
    1254             :     {
    1255           0 :         delete m_pDataContainer_Dialogs;
    1256           0 :         m_pDataContainer_Dialogs = NULL;
    1257             :     }
    1258           0 :     if( --m_nRefCount_TabDialogs == 0 )
    1259             :     {
    1260           0 :         delete m_pDataContainer_TabDialogs;
    1261           0 :         m_pDataContainer_TabDialogs = NULL;
    1262             :     }
    1263           0 :     if( --m_nRefCount_TabPages == 0 )
    1264             :     {
    1265           0 :         delete m_pDataContainer_TabPages;
    1266           0 :         m_pDataContainer_TabPages = NULL;
    1267             :     }
    1268           0 :     if( --m_nRefCount_Windows == 0 )
    1269             :     {
    1270           0 :         delete m_pDataContainer_Windows;
    1271           0 :         m_pDataContainer_Windows = NULL;
    1272           0 :     }
    1273           0 : }
    1274             : 
    1275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10