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