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