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