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