1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unotools/viewoptions.hxx>
21 #include <com/sun/star/uno/Any.hxx>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/container/XNameContainer.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <rtl/ustrbuf.hxx>
28 #include <osl/diagnose.h>
29 #include <unotools/configpaths.hxx>
30 #include <comphelper/configurationhelper.hxx>
31 #include <comphelper/processfactory.hxx>
33 #include "itemholder1.hxx"
35 #define PACKAGE_VIEWS "org.openoffice.Office.Views"
37 #define LIST_DIALOGS "Dialogs"
38 #define LIST_TABDIALOGS "TabDialogs"
39 #define LIST_TABPAGES "TabPages"
40 #define LIST_WINDOWS "Windows"
42 #define PROPERTY_WINDOWSTATE "WindowState"
43 #define PROPERTY_PAGEID "PageID"
44 #define PROPERTY_VISIBLE "Visible"
45 #define PROPERTY_USERDATA "UserData"
47 //#define DEBUG_VIEWOPTIONS
49 #ifdef DEBUG_VIEWOPTIONS
50 #define _LOG_COUNTER_( _SVIEW_, _NREAD_, _NWRITE_ ) \
52 FILE* pFile = fopen( "viewdbg.txt", "a" ); \
53 fprintf( pFile, "%s[%d, %d]\n", OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
56 #endif // DEBUG_VIEWOPTIONS
58 #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION) \
60 OUStringBuffer sMsg(256); \
61 sMsg.appendAscii("Unexpected exception catched. Original message was:\n\"" ); \
62 sMsg.append (SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION.Message); \
63 sMsg.appendAscii("\"" ); \
68 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_Dialogs
= NULL
;
69 sal_Int32
SvtViewOptions::m_nRefCount_Dialogs
= 0 ;
70 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_TabDialogs
= NULL
;
71 sal_Int32
SvtViewOptions::m_nRefCount_TabDialogs
= 0 ;
72 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_TabPages
= NULL
;
73 sal_Int32
SvtViewOptions::m_nRefCount_TabPages
= 0 ;
74 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_Windows
= NULL
;
75 sal_Int32
SvtViewOptions::m_nRefCount_Windows
= 0 ;
77 /*-************************************************************************************************************
78 @descr Implement base data container for view options elements.
79 Every item support ALL possible configuration information.
80 But not every superclass should use them! Because some view types don't
83 @attention We implement a write-througt-cache! We use it for reading - but write all changes directly to
84 configuration. (changes are made on internal cache too!). So it's easier to distinguish
85 between added/changed/removed elements without any complex mask or bool flag information.
86 Caches from configuration and our own one are synchronized every time - if we do so.
87 *//*-*************************************************************************************************************/
88 class SvtViewOptionsBase_Impl
92 enum State
{ STATE_NONE
, STATE_FALSE
, STATE_TRUE
};
94 SvtViewOptionsBase_Impl ( const OUString
& sList
);
95 virtual ~SvtViewOptionsBase_Impl ( );
96 bool Exists ( const OUString
& sName
);
97 bool Delete ( const OUString
& sName
);
98 OUString
GetWindowState ( const OUString
& sName
);
99 void SetWindowState ( const OUString
& sName
,
100 const OUString
& sState
);
101 css::uno::Sequence
< css::beans::NamedValue
> GetUserData ( const OUString
& sName
);
102 void SetUserData ( const OUString
& sName
,
103 const css::uno::Sequence
< css::beans::NamedValue
>& lData
);
104 sal_Int32
GetPageID ( const OUString
& sName
);
105 void SetPageID ( const OUString
& sName
,
107 State
GetVisible ( const OUString
& sName
);
108 void SetVisible ( const OUString
& sName
,
110 css::uno::Any
GetUserItem ( const OUString
& sName
,
111 const OUString
& sItem
);
112 void SetUserItem ( const OUString
& sName
,
113 const OUString
& sItem
,
114 const css::uno::Any
& aValue
);
117 css::uno::Reference
< css::uno::XInterface
> impl_getSetNode( const OUString
& sNode
,
118 bool bCreateIfMissing
);
121 OUString m_sListName
;
122 css::uno::Reference
< css::container::XNameAccess
> m_xRoot
;
123 css::uno::Reference
< css::container::XNameAccess
> m_xSet
;
125 #ifdef DEBUG_VIEWOPTIONS
126 sal_Int32 m_nReadCount
;
127 sal_Int32 m_nWriteCount
;
131 /*-************************************************************************************************************
132 @descr Implement the base data container.
133 *//*-*************************************************************************************************************/
135 /*-************************************************************************************************************
137 @descr We use it to open right configuration file and let configuration objects fill her caches.
138 Then we read all existing entries from right list and cached it inside our object too.
139 Normally we should enable notifications for changes on these values too ... but these feature
140 isn't full implemented in the moment.
142 @seealso baseclass ::utl::ConfigItem
143 @seealso method Notify()
144 *//*-*************************************************************************************************************/
145 SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const OUString
& sList
)
146 : m_sListName ( sList
) // we must know, which view type we must support
147 #ifdef DEBUG_VIEWOPTIONS
154 m_xRoot
= css::uno::Reference
< css::container::XNameAccess
>(
155 ::comphelper::ConfigurationHelper::openConfig(
156 ::comphelper::getProcessComponentContext(),
158 ::comphelper::ConfigurationHelper::E_STANDARD
),
159 css::uno::UNO_QUERY
);
161 m_xRoot
->getByName(sList
) >>= m_xSet
;
163 catch(const css::uno::Exception
& ex
)
168 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
172 /*-************************************************************************************************************
174 @descr clean up something
176 @attention We implement a write through cache! So we mustn't do it really. All changes was written to cfg directly.
177 Commit isn't necessary then.
179 @seealso baseclass ::utl::ConfigItem
180 @seealso method IsModified()
181 @seealso method SetModified()
182 @seealso method Commit()
183 *//*-*************************************************************************************************************/
184 SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
186 // dont flush configuration changes here to m_xRoot.
187 // That must be done inside every SetXXX() method already !
188 // Here its to late - DisposedExceptions from used configuration access can occur otherwise.
193 #ifdef DEBUG_VIEWOPTIONS
194 _LOG_COUNTER_( m_sListName
, m_nReadCount
, m_nWriteCount
)
195 #endif // DEBUG_VIEWOPTIONS
198 /*-************************************************************************************************************
199 @short checks for already existing entries
200 @descr If user don't know, if an entry already exist - he can get this information by calling this method.
202 @seealso member m_aList
204 @param "sName", name of entry to check exist state
205 @return true , if item exist
207 *//*-*************************************************************************************************************/
208 bool SvtViewOptionsBase_Impl::Exists( const OUString
& sName
)
210 bool bExists
= false;
215 bExists
= m_xSet
->hasByName(sName
);
217 catch(const css::uno::Exception
& ex
)
220 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
226 /*-************************************************************************************************************
228 @descr Use it to delete set entry by given name.
230 @seealso member m_aList
232 @param "sName", name of entry to delete it
233 @return true , if item not exist(!) or could be deleted (should be the same!)
235 *//*-*************************************************************************************************************/
236 bool SvtViewOptionsBase_Impl::Delete( const OUString
& sName
)
238 #ifdef DEBUG_VIEWOPTIONS
242 bool bDeleted
= false;
245 css::uno::Reference
< css::container::XNameContainer
> xSet(m_xSet
, css::uno::UNO_QUERY_THROW
);
246 xSet
->removeByName(sName
);
248 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
250 catch(const css::container::NoSuchElementException
&)
252 catch(const css::uno::Exception
& ex
)
255 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
261 /*-************************************************************************************************************
262 @short read/write access to cache view items and her properties
263 @descr Follow methods support read/write access to all cache view items.
265 @seealso member m_sList
266 *//*-*************************************************************************************************************/
267 OUString
SvtViewOptionsBase_Impl::GetWindowState( const OUString
& sName
)
269 #ifdef DEBUG_VIEWOPTIONS
273 OUString sWindowState
;
276 css::uno::Reference
< css::beans::XPropertySet
> xNode(
277 impl_getSetNode(sName
, false),
278 css::uno::UNO_QUERY
);
280 xNode
->getPropertyValue(PROPERTY_WINDOWSTATE
) >>= sWindowState
;
282 catch(const css::uno::Exception
& ex
)
284 sWindowState
.clear();
285 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
291 void SvtViewOptionsBase_Impl::SetWindowState( const OUString
& sName
,
292 const OUString
& sState
)
294 #ifdef DEBUG_VIEWOPTIONS
300 css::uno::Reference
< css::beans::XPropertySet
> xNode(
301 impl_getSetNode(sName
, true),
302 css::uno::UNO_QUERY_THROW
);
303 xNode
->setPropertyValue(PROPERTY_WINDOWSTATE
, css::uno::makeAny(sState
));
304 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
306 catch(const css::uno::Exception
& ex
)
308 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
312 css::uno::Sequence
< css::beans::NamedValue
> SvtViewOptionsBase_Impl::GetUserData( const OUString
& sName
)
314 #ifdef DEBUG_VIEWOPTIONS
320 css::uno::Reference
< css::container::XNameAccess
> xNode(
321 impl_getSetNode(sName
, false),
322 css::uno::UNO_QUERY
); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
323 css::uno::Reference
< css::container::XNameAccess
> xUserData
;
325 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
328 const css::uno::Sequence
<OUString
> lNames
= xUserData
->getElementNames();
329 const OUString
* pNames
= lNames
.getConstArray();
330 sal_Int32 c
= lNames
.getLength();
332 css::uno::Sequence
< css::beans::NamedValue
> lUserData(c
);
336 lUserData
[i
].Name
= pNames
[i
];
337 lUserData
[i
].Value
= xUserData
->getByName(pNames
[i
]);
343 catch(const css::uno::Exception
& ex
)
345 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
348 return css::uno::Sequence
< css::beans::NamedValue
>();
351 void SvtViewOptionsBase_Impl::SetUserData( const OUString
& sName
,
352 const css::uno::Sequence
< css::beans::NamedValue
>& lData
)
354 #ifdef DEBUG_VIEWOPTIONS
360 css::uno::Reference
< css::container::XNameAccess
> xNode(
361 impl_getSetNode(sName
, true),
362 css::uno::UNO_QUERY_THROW
);
363 css::uno::Reference
< css::container::XNameContainer
> xUserData
;
364 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
367 const css::beans::NamedValue
* pData
= lData
.getConstArray();
368 sal_Int32 c
= lData
.getLength();
372 if (xUserData
->hasByName(pData
[i
].Name
))
373 xUserData
->replaceByName(pData
[i
].Name
, pData
[i
].Value
);
375 xUserData
->insertByName(pData
[i
].Name
, pData
[i
].Value
);
378 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
380 catch(const css::uno::Exception
& ex
)
382 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
386 css::uno::Any
SvtViewOptionsBase_Impl::GetUserItem( const OUString
& sName
,
387 const OUString
& sItem
)
389 #ifdef DEBUG_VIEWOPTIONS
396 css::uno::Reference
< css::container::XNameAccess
> xNode(
397 impl_getSetNode(sName
, false),
398 css::uno::UNO_QUERY
);
399 css::uno::Reference
< css::container::XNameAccess
> xUserData
;
401 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
403 aItem
= xUserData
->getByName(sItem
);
405 catch(const css::container::NoSuchElementException
&)
407 catch(const css::uno::Exception
& ex
)
410 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
416 void SvtViewOptionsBase_Impl::SetUserItem( const OUString
& sName
,
417 const OUString
& sItem
,
418 const css::uno::Any
& aValue
)
420 #ifdef DEBUG_VIEWOPTIONS
426 css::uno::Reference
< css::container::XNameAccess
> xNode(
427 impl_getSetNode(sName
, true),
428 css::uno::UNO_QUERY_THROW
);
429 css::uno::Reference
< css::container::XNameContainer
> xUserData
;
430 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
433 if (xUserData
->hasByName(sItem
))
434 xUserData
->replaceByName(sItem
, aValue
);
436 xUserData
->insertByName(sItem
, aValue
);
438 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
440 catch(const css::uno::Exception
& ex
)
442 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
446 sal_Int32
SvtViewOptionsBase_Impl::GetPageID( const OUString
& sName
)
448 #ifdef DEBUG_VIEWOPTIONS
455 css::uno::Reference
< css::beans::XPropertySet
> xNode(
456 impl_getSetNode(sName
, false),
457 css::uno::UNO_QUERY
);
459 xNode
->getPropertyValue(PROPERTY_PAGEID
) >>= nID
;
461 catch(const css::uno::Exception
& ex
)
464 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
470 void SvtViewOptionsBase_Impl::SetPageID( const OUString
& sName
,
473 #ifdef DEBUG_VIEWOPTIONS
479 css::uno::Reference
< css::beans::XPropertySet
> xNode(
480 impl_getSetNode(sName
, true),
481 css::uno::UNO_QUERY_THROW
);
482 xNode
->setPropertyValue(PROPERTY_PAGEID
, css::uno::makeAny(nID
));
483 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
485 catch(const css::uno::Exception
& ex
)
487 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
491 SvtViewOptionsBase_Impl::State
SvtViewOptionsBase_Impl::GetVisible( const OUString
& sName
)
493 #ifdef DEBUG_VIEWOPTIONS
497 State eState
= STATE_NONE
;
500 css::uno::Reference
< css::beans::XPropertySet
> xNode(
501 impl_getSetNode(sName
, false),
502 css::uno::UNO_QUERY
);
505 bool bVisible
= false;
506 if (xNode
->getPropertyValue(PROPERTY_VISIBLE
) >>= bVisible
)
508 eState
= bVisible
? STATE_TRUE
: STATE_FALSE
;
512 catch(const css::uno::Exception
& ex
)
514 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
520 void SvtViewOptionsBase_Impl::SetVisible( const OUString
& sName
,
523 #ifdef DEBUG_VIEWOPTIONS
529 css::uno::Reference
< css::beans::XPropertySet
> xNode(
530 impl_getSetNode(sName
, true),
531 css::uno::UNO_QUERY_THROW
);
532 xNode
->setPropertyValue(PROPERTY_VISIBLE
, css::uno::makeAny(bVisible
));
533 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
535 catch(const css::uno::Exception
& ex
)
537 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
541 /*-************************************************************************************************************
542 @short create new set node with default values on disk
543 @descr To create a new UserData item - the super node of these property must already exist!
544 You can call this method to create these new entry with default values and change UserData then.
546 @seealso method impl_writeDirectProp()
548 @param "sNode", name of new entry
549 *//*-*************************************************************************************************************/
550 css::uno::Reference
< css::uno::XInterface
> SvtViewOptionsBase_Impl::impl_getSetNode( const OUString
& sNode
,
551 bool bCreateIfMissing
)
553 css::uno::Reference
< css::uno::XInterface
> xNode
;
557 if (bCreateIfMissing
)
558 xNode
= ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot
, m_sListName
, sNode
);
561 if (m_xSet
.is() && m_xSet
->hasByName(sNode
) )
562 m_xSet
->getByName(sNode
) >>= xNode
;
565 catch(const css::container::NoSuchElementException
&)
567 catch(const css::uno::Exception
& ex
)
570 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
578 SvtViewOptions::SvtViewOptions( EViewType eType
,
579 const OUString
& sViewName
)
580 : m_eViewType ( eType
)
581 , m_sViewName ( sViewName
)
583 // Global access, must be guarded (multithreading!)
584 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
586 // Search for right dat container for this view type and initialize right data container or set right ref count!
590 // Increase ref count for dialog data container first.
591 ++m_nRefCount_Dialogs
;
592 // If these instance the first user of the dialog data container - create these impl static container!
593 if( m_nRefCount_Dialogs
== 1 )
595 //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
596 m_pDataContainer_Dialogs
= new SvtViewOptionsBase_Impl( LIST_DIALOGS
);
597 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG
);
602 // Increase ref count for tab-dialog data container first.
603 ++m_nRefCount_TabDialogs
;
604 // If these instance the first user of the tab-dialog data container - create these impl static container!
605 if( m_nRefCount_TabDialogs
== 1 )
607 m_pDataContainer_TabDialogs
= new SvtViewOptionsBase_Impl( LIST_TABDIALOGS
);
608 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG
);
613 // Increase ref count for tab-page data container first.
614 ++m_nRefCount_TabPages
;
615 // If these instance the first user of the tab-page data container - create these impl static container!
616 if( m_nRefCount_TabPages
== 1 )
618 m_pDataContainer_TabPages
= new SvtViewOptionsBase_Impl( LIST_TABPAGES
);
619 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE
);
624 // Increase ref count for window data container first.
625 ++m_nRefCount_Windows
;
626 // If these instance the first user of the window data container - create these impl static container!
627 if( m_nRefCount_Windows
== 1 )
629 m_pDataContainer_Windows
= new SvtViewOptionsBase_Impl( LIST_WINDOWS
);
630 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW
);
634 default : OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
640 SvtViewOptions::~SvtViewOptions()
642 // Global access, must be guarded (multithreading!)
643 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
645 // Search for right dat container for this view type and deinitialize right data container or set right ref count!
646 switch( m_eViewType
)
649 // Decrease ref count for dialog data container first.
650 --m_nRefCount_Dialogs
;
651 // If these instance the last user of the dialog data container - delete these impl static container!
652 if( m_nRefCount_Dialogs
== 0 )
654 delete m_pDataContainer_Dialogs
;
655 m_pDataContainer_Dialogs
= NULL
;
660 // Decrease ref count for tab-dialog data container first.
661 --m_nRefCount_TabDialogs
;
662 // If these instance the last user of the tab-dialog data container - delete these impl static container!
663 if( m_nRefCount_TabDialogs
== 0 )
665 delete m_pDataContainer_TabDialogs
;
666 m_pDataContainer_TabDialogs
= NULL
;
671 // Decrease ref count for tab-page data container first.
672 --m_nRefCount_TabPages
;
673 // If these instance the last user of the tab-page data container - delete these impl static container!
674 if( m_nRefCount_TabPages
== 0 )
676 delete m_pDataContainer_TabPages
;
677 m_pDataContainer_TabPages
= NULL
;
682 // Decrease ref count for window data container first.
683 --m_nRefCount_Windows
;
684 // If these instance the last user of the window data container - delete these impl static container!
685 if( m_nRefCount_Windows
== 0 )
687 delete m_pDataContainer_Windows
;
688 m_pDataContainer_Windows
= NULL
;
697 bool SvtViewOptions::Exists() const
699 // Ready for multithreading
700 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
702 bool bExists
= false;
703 switch( m_eViewType
)
706 bExists
= m_pDataContainer_Dialogs
->Exists( m_sViewName
);
710 bExists
= m_pDataContainer_TabDialogs
->Exists( m_sViewName
);
714 bExists
= m_pDataContainer_TabPages
->Exists( m_sViewName
);
718 bExists
= m_pDataContainer_Windows
->Exists( m_sViewName
);
727 bool SvtViewOptions::Delete()
729 // Ready for multithreading
730 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
733 switch( m_eViewType
)
736 bState
= m_pDataContainer_Dialogs
->Delete( m_sViewName
);
740 bState
= m_pDataContainer_TabDialogs
->Delete( m_sViewName
);
744 bState
= m_pDataContainer_TabPages
->Delete( m_sViewName
);
748 bState
= m_pDataContainer_Windows
->Delete( m_sViewName
);
757 OUString
SvtViewOptions::GetWindowState() const
759 // Ready for multithreading
760 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
763 switch( m_eViewType
)
766 sState
= m_pDataContainer_Dialogs
->GetWindowState( m_sViewName
);
770 sState
= m_pDataContainer_TabDialogs
->GetWindowState( m_sViewName
);
774 sState
= m_pDataContainer_TabPages
->GetWindowState( m_sViewName
);
778 sState
= m_pDataContainer_Windows
->GetWindowState( m_sViewName
);
787 void SvtViewOptions::SetWindowState( const OUString
& sState
)
789 // Ready for multithreading
790 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
792 switch( m_eViewType
)
795 m_pDataContainer_Dialogs
->SetWindowState( m_sViewName
, sState
);
799 m_pDataContainer_TabDialogs
->SetWindowState( m_sViewName
, sState
);
803 m_pDataContainer_TabPages
->SetWindowState( m_sViewName
, sState
);
807 m_pDataContainer_Windows
->SetWindowState( m_sViewName
, sState
);
815 sal_Int32
SvtViewOptions::GetPageID() const
817 // Ready for multithreading
818 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
820 // Safe impossible cases.
821 // These call isn't allowed for dialogs, tab-pages or windows!
822 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" );
825 if( m_eViewType
== E_TABDIALOG
)
826 nID
= m_pDataContainer_TabDialogs
->GetPageID( m_sViewName
);
832 void SvtViewOptions::SetPageID( sal_Int32 nID
)
834 // Ready for multithreading
835 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
837 // Safe impossible cases.
838 // These call isn't allowed for dialogs, tab-pages or windows!
839 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" );
841 if( m_eViewType
== E_TABDIALOG
)
842 m_pDataContainer_TabDialogs
->SetPageID( m_sViewName
, nID
);
847 bool SvtViewOptions::IsVisible() const
849 // Ready for multithreading
850 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
852 // Safe impossible cases.
853 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
854 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" );
857 if( m_eViewType
== E_WINDOW
)
858 bState
= m_pDataContainer_Windows
->GetVisible( m_sViewName
) == SvtViewOptionsBase_Impl::STATE_TRUE
;
865 void SvtViewOptions::SetVisible( bool bState
)
867 // Ready for multithreading
868 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
870 // Safe impossible cases.
871 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
872 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" );
874 if( m_eViewType
== E_WINDOW
)
875 m_pDataContainer_Windows
->SetVisible( m_sViewName
, bState
);
880 bool SvtViewOptions::HasVisible() const
882 // Ready for multithreading
883 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
885 // Safe impossible cases.
886 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
887 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" );
890 if( m_eViewType
== E_WINDOW
)
891 bState
= m_pDataContainer_Windows
->GetVisible( m_sViewName
) != SvtViewOptionsBase_Impl::STATE_NONE
;
896 css::uno::Sequence
< css::beans::NamedValue
> SvtViewOptions::GetUserData() const
898 // Ready for multithreading
899 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
901 css::uno::Sequence
< css::beans::NamedValue
> lData
;
902 switch( m_eViewType
)
905 lData
= m_pDataContainer_Dialogs
->GetUserData( m_sViewName
);
909 lData
= m_pDataContainer_TabDialogs
->GetUserData( m_sViewName
);
913 lData
= m_pDataContainer_TabPages
->GetUserData( m_sViewName
);
917 lData
= m_pDataContainer_Windows
->GetUserData( m_sViewName
);
924 void SvtViewOptions::SetUserData( const css::uno::Sequence
< css::beans::NamedValue
>& lData
)
926 // Ready for multithreading
927 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
929 switch( m_eViewType
)
932 m_pDataContainer_Dialogs
->SetUserData( m_sViewName
, lData
);
936 m_pDataContainer_TabDialogs
->SetUserData( m_sViewName
, lData
);
940 m_pDataContainer_TabPages
->SetUserData( m_sViewName
, lData
);
944 m_pDataContainer_Windows
->SetUserData( m_sViewName
, lData
);
950 css::uno::Any
SvtViewOptions::GetUserItem( const OUString
& sName
) const
952 // Ready for multithreading
953 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
956 switch( m_eViewType
)
959 aItem
= m_pDataContainer_Dialogs
->GetUserItem( m_sViewName
, sName
);
963 aItem
= m_pDataContainer_TabDialogs
->GetUserItem( m_sViewName
, sName
);
967 aItem
= m_pDataContainer_TabPages
->GetUserItem( m_sViewName
, sName
);
971 aItem
= m_pDataContainer_Windows
->GetUserItem( m_sViewName
, sName
);
978 void SvtViewOptions::SetUserItem( const OUString
& sName
,
979 const css::uno::Any
& aValue
)
981 // Ready for multithreading
982 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
984 switch( m_eViewType
)
987 m_pDataContainer_Dialogs
->SetUserItem( m_sViewName
, sName
, aValue
);
991 m_pDataContainer_TabDialogs
->SetUserItem( m_sViewName
, sName
, aValue
);
995 m_pDataContainer_TabPages
->SetUserItem( m_sViewName
, sName
, aValue
);
999 m_pDataContainer_Windows
->SetUserItem( m_sViewName
, sName
, aValue
);
1007 class theViewOptionsMutex
: public rtl::Static
<osl::Mutex
, theViewOptionsMutex
>{};
1012 ::osl::Mutex
& SvtViewOptions::GetOwnStaticMutex()
1014 return theViewOptionsMutex::get();
1017 void SvtViewOptions::AcquireOptions()
1019 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1020 if( ++m_nRefCount_Dialogs
== 1 )
1022 m_pDataContainer_Dialogs
= new SvtViewOptionsBase_Impl( LIST_DIALOGS
);
1023 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG
);
1025 if( ++m_nRefCount_TabDialogs
== 1 )
1027 m_pDataContainer_TabDialogs
= new SvtViewOptionsBase_Impl( LIST_TABDIALOGS
);
1028 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG
);
1030 if( ++m_nRefCount_TabPages
== 1 )
1032 m_pDataContainer_TabPages
= new SvtViewOptionsBase_Impl( LIST_TABPAGES
);
1033 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE
);
1035 if( ++m_nRefCount_Windows
== 1 )
1037 m_pDataContainer_Windows
= new SvtViewOptionsBase_Impl( LIST_WINDOWS
);
1038 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW
);
1042 void SvtViewOptions::ReleaseOptions()
1044 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1045 if( --m_nRefCount_Dialogs
== 0 )
1047 delete m_pDataContainer_Dialogs
;
1048 m_pDataContainer_Dialogs
= NULL
;
1050 if( --m_nRefCount_TabDialogs
== 0 )
1052 delete m_pDataContainer_TabDialogs
;
1053 m_pDataContainer_TabDialogs
= NULL
;
1055 if( --m_nRefCount_TabPages
== 0 )
1057 delete m_pDataContainer_TabPages
;
1058 m_pDataContainer_TabPages
= NULL
;
1060 if( --m_nRefCount_Windows
== 0 )
1062 delete m_pDataContainer_Windows
;
1063 m_pDataContainer_Windows
= NULL
;
1067 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */