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 <boost/unordered_map.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <rtl/ustrbuf.hxx>
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 DEFAULT_WINDOWSTATE OUString()
48 #define DEFAULT_USERDATA css::uno::Sequence< css::beans::NamedValue >()
49 #define DEFAULT_PAGEID 0
50 #define DEFAULT_VISIBLE sal_False
52 //#define DEBUG_VIEWOPTIONS
54 #ifdef DEBUG_VIEWOPTIONS
55 #define _LOG_COUNTER_( _SVIEW_, _NREAD_, _NWRITE_ ) \
57 FILE* pFile = fopen( "viewdbg.txt", "a" ); \
58 fprintf( pFile, "%s[%d, %d]\n", OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
61 #endif // DEBUG_VIEWOPTIONS
63 #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION) \
65 OUStringBuffer sMsg(256); \
66 sMsg.appendAscii("Unexpected exception catched. Original message was:\n\"" ); \
67 sMsg.append (SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION.Message); \
68 sMsg.appendAscii("\"" ); \
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
75 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_Dialogs
= NULL
;
76 sal_Int32
SvtViewOptions::m_nRefCount_Dialogs
= 0 ;
77 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_TabDialogs
= NULL
;
78 sal_Int32
SvtViewOptions::m_nRefCount_TabDialogs
= 0 ;
79 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_TabPages
= NULL
;
80 sal_Int32
SvtViewOptions::m_nRefCount_TabPages
= 0 ;
81 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_Windows
= NULL
;
82 sal_Int32
SvtViewOptions::m_nRefCount_Windows
= 0 ;
84 //_________________________________________________________________________________________________________________
85 // private declarations!
86 //_________________________________________________________________________________________________________________
88 /*-************************************************************************************************************//**
89 @descr declare one configuration item
90 These struct hold information about one view item. But not all member are used for all entries!
91 User must decide which information are useful and which not. We are a container iztem only and doesnt
92 know anything about the context.
93 But; we support a feature:
94 decision between items with default values (should not realy exist in configuration!)
95 and items with real values - changed by user. So user can suppress saving of realy unused items
96 to disk - because; defaulted items could be restored on runtime without reading from disk!!!
97 And if only items with valid information was written to cfg - we mustn't read so much and save time.
98 So we start with an member m_bDefault=True and reset it to False after first set-call.
99 Deficiencies of these solution - we cant allow direct read/write access to our member. We must
100 support it by set/get-methods ...
101 *//*-*************************************************************************************************************/
105 //---------------------------------------------------------------------------------------------------------
106 // create "default" item
109 m_sWindowState
= DEFAULT_WINDOWSTATE
;
110 m_lUserData
= DEFAULT_USERDATA
;
111 m_nPageID
= DEFAULT_PAGEID
;
112 m_bVisible
= DEFAULT_VISIBLE
;
114 m_bDefault
= sal_True
;
117 //---------------------------------------------------------------------------------------------------------
118 // write access - with reseting of default state
119 void setWindowState( const OUString
& sValue
)
122 ( m_bDefault
== sal_True
) &&
123 ( sValue
== DEFAULT_WINDOWSTATE
)
125 m_sWindowState
= sValue
;
128 //---------------------------------------------------------------------------------------------------------
129 void setUserData( const css::uno::Sequence
< css::beans::NamedValue
>& lValue
)
132 ( m_bDefault
== sal_True
) &&
133 ( lValue
== DEFAULT_USERDATA
)
135 m_lUserData
= lValue
;
138 //---------------------------------------------------------------------------------------------------------
139 void setPageID( sal_Int32 nValue
)
142 ( m_bDefault
== sal_True
) &&
143 ( nValue
== DEFAULT_PAGEID
)
148 //---------------------------------------------------------------------------------------------------------
149 void setVisible( sal_Bool bValue
)
152 ( m_bDefault
== sal_True
) &&
153 ( bValue
== DEFAULT_VISIBLE
)
158 //---------------------------------------------------------------------------------------------------------
160 OUString
getWindowState() { return m_sWindowState
; }
161 css::uno::Sequence
< css::beans::NamedValue
> getUserData () { return m_lUserData
; }
162 sal_Int32
getPageID () { return m_nPageID
; }
163 sal_Bool
getVisible () { return m_bVisible
; }
165 //---------------------------------------------------------------------------------------------------------
166 // special operation for easy access on user data
167 void setUserItem( const OUString
& sName
,
168 const css::uno::Any
& aValue
)
170 // we change UserData in every case!
171 // a) we change already existing item
172 // or b) we add a new one
173 m_bDefault
= sal_False
;
175 sal_Bool bExist
= sal_False
;
176 sal_Int32 nCount
= m_lUserData
.getLength();
178 // change it, if it already exist ...
179 for( sal_Int32 nStep
=0; nStep
<nCount
; ++nStep
)
181 if( m_lUserData
[nStep
].Name
== sName
)
183 m_lUserData
[nStep
].Value
= aValue
;
189 // ... or create new list item
190 if( bExist
== sal_False
)
192 m_lUserData
.realloc( nCount
+1 );
193 m_lUserData
[nCount
].Name
= sName
;
194 m_lUserData
[nCount
].Value
= aValue
;
198 //---------------------------------------------------------------------------------------------------------
199 css::uno::Any
getUserItem( const OUString
& sName
)
201 // default value - if item not exist!
202 css::uno::Any aValue
;
204 sal_Int32 nCount
= m_lUserData
.getLength();
205 for( sal_Int32 nStep
=0; nStep
<nCount
; ++nStep
)
207 if( m_lUserData
[nStep
].Name
== sName
)
209 aValue
= m_lUserData
[nStep
].Value
;
216 //---------------------------------------------------------------------------------------------------------
217 // check for default items
218 sal_Bool
isDefault() { return m_bDefault
; }
221 OUString m_sWindowState
;
222 css::uno::Sequence
< css::beans::NamedValue
> m_lUserData
;
223 sal_Int32 m_nPageID
;
224 sal_Bool m_bVisible
;
226 sal_Bool m_bDefault
;
229 struct IMPL_TStringHashCode
231 size_t operator()(const OUString
& sString
) const
233 return sString
.hashCode();
237 typedef ::boost::unordered_map
< OUString
,
239 IMPL_TStringHashCode
,
240 ::std::equal_to
< OUString
> > IMPL_TViewHash
;
242 /*-************************************************************************************************************//**
243 @descr Implement base data container for view options elements.
244 Every item support ALL possible configuration information.
245 But not every superclass should use them! Because some view types don't
248 @attention We implement a write-througt-cache! We use it for reading - but write all changes directly to
249 configuration. (changes are made on internal cache too!). So it's easier to distinguish
250 between added/changed/removed elements without any complex mask or bool flag information.
251 Caches from configuration and our own one are synchronized every time - if we do so.
252 *//*-*************************************************************************************************************/
253 class SvtViewOptionsBase_Impl
255 //-------------------------------------------------------------------------------------------------------------
257 enum State
{ STATE_NONE
, STATE_FALSE
, STATE_TRUE
};
259 SvtViewOptionsBase_Impl ( const OUString
& sList
);
260 virtual ~SvtViewOptionsBase_Impl ( );
261 sal_Bool
Exists ( const OUString
& sName
);
262 sal_Bool
Delete ( const OUString
& sName
);
263 OUString
GetWindowState ( const OUString
& sName
);
264 void SetWindowState ( const OUString
& sName
,
265 const OUString
& sState
);
266 css::uno::Sequence
< css::beans::NamedValue
> GetUserData ( const OUString
& sName
);
267 void SetUserData ( const OUString
& sName
,
268 const css::uno::Sequence
< css::beans::NamedValue
>& lData
);
269 sal_Int32
GetPageID ( const OUString
& sName
);
270 void SetPageID ( const OUString
& sName
,
272 State
GetVisible ( const OUString
& sName
);
273 void SetVisible ( const OUString
& sName
,
275 css::uno::Any
GetUserItem ( const OUString
& sName
,
276 const OUString
& sItem
);
277 void SetUserItem ( const OUString
& sName
,
278 const OUString
& sItem
,
279 const css::uno::Any
& aValue
);
281 //-------------------------------------------------------------------------------------------------------------
283 css::uno::Reference
< css::uno::XInterface
> impl_getSetNode( const OUString
& sNode
,
284 sal_Bool bCreateIfMissing
);
286 //-------------------------------------------------------------------------------------------------------------
288 OUString m_sListName
;
289 css::uno::Reference
< css::container::XNameAccess
> m_xRoot
;
290 css::uno::Reference
< css::container::XNameAccess
> m_xSet
;
292 #ifdef DEBUG_VIEWOPTIONS
293 sal_Int32 m_nReadCount
;
294 sal_Int32 m_nWriteCount
;
298 /*-************************************************************************************************************//**
299 @descr Implement the base data container.
300 *//*-*************************************************************************************************************/
302 /*-************************************************************************************************************//**
304 @descr We use it to open right configuration file and let configuration objects fill her caches.
305 Then we read all existing entries from right list and cached it inside our object too.
306 Normaly we should enable notifications for changes on these values too ... but these feature
307 isn't full implemented in the moment.
309 @seealso baseclass ::utl::ConfigItem
310 @seealso method Notify()
314 *//*-*************************************************************************************************************/
315 SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const OUString
& sList
)
316 : m_sListName ( sList
) // we must know, which view type we must support
317 #ifdef DEBUG_VIEWOPTIONS
324 m_xRoot
= css::uno::Reference
< css::container::XNameAccess
>(
325 ::comphelper::ConfigurationHelper::openConfig(
326 ::comphelper::getProcessComponentContext(),
328 ::comphelper::ConfigurationHelper::E_STANDARD
),
329 css::uno::UNO_QUERY
);
331 m_xRoot
->getByName(sList
) >>= m_xSet
;
333 catch(const css::uno::Exception
& ex
)
338 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
342 /*-************************************************************************************************************//**
344 @descr clean up something
346 @attention We implement a write through cache! So we mustn't do it realy. All changes was written to cfg directly.
347 Commit isn't neccessary then.
349 @seealso baseclass ::utl::ConfigItem
350 @seealso method IsModified()
351 @seealso method SetModified()
352 @seealso method Commit()
356 *//*-*************************************************************************************************************/
357 SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
359 // dont flush configuration changes here to m_xRoot.
360 // That must be done inside every SetXXX() method already !
361 // Here its to late - DisposedExceptions from used configuration access can occure otherwise.
366 #ifdef DEBUG_VIEWOPTIONS
367 _LOG_COUNTER_( m_sListName
, m_nReadCount
, m_nWriteCount
)
368 #endif // DEBUG_VIEWOPTIONS
371 /*-************************************************************************************************************//**
372 @short checks for already existing entries
373 @descr If user don't know, if an entry already exist - he can get this information by calling this method.
375 @seealso member m_aList
377 @param "sName", name of entry to check exist state
378 @return true , if item exist
380 *//*-*************************************************************************************************************/
381 sal_Bool
SvtViewOptionsBase_Impl::Exists( const OUString
& sName
)
383 sal_Bool bExists
= sal_False
;
388 bExists
= m_xSet
->hasByName(sName
);
390 catch(const css::uno::Exception
& ex
)
393 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
399 /*-************************************************************************************************************//**
401 @descr Use it to delete set entry by given name.
403 @seealso member m_aList
405 @param "sName", name of entry to delete it
406 @return true , if item not exist(!) or could be deleted (should be the same!)
408 *//*-*************************************************************************************************************/
409 sal_Bool
SvtViewOptionsBase_Impl::Delete( const OUString
& sName
)
411 #ifdef DEBUG_VIEWOPTIONS
415 sal_Bool bDeleted
= sal_False
;
418 css::uno::Reference
< css::container::XNameContainer
> xSet(m_xSet
, css::uno::UNO_QUERY_THROW
);
419 xSet
->removeByName(sName
);
421 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
423 catch(const css::container::NoSuchElementException
&)
424 { bDeleted
= sal_True
; }
425 catch(const css::uno::Exception
& ex
)
427 bDeleted
= sal_False
;
428 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
434 /*-************************************************************************************************************//**
435 @short read/write access to cache view items and her properties
436 @descr Follow methods support read/write access to all cache view items.
438 @seealso member m_sList
442 *//*-*************************************************************************************************************/
443 OUString
SvtViewOptionsBase_Impl::GetWindowState( const OUString
& sName
)
445 #ifdef DEBUG_VIEWOPTIONS
449 OUString sWindowState
;
452 css::uno::Reference
< css::beans::XPropertySet
> xNode(
453 impl_getSetNode(sName
, sal_False
),
454 css::uno::UNO_QUERY
);
456 xNode
->getPropertyValue(PROPERTY_WINDOWSTATE
) >>= sWindowState
;
458 catch(const css::uno::Exception
& ex
)
460 sWindowState
= OUString();
461 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
467 //*****************************************************************************************************************
468 void SvtViewOptionsBase_Impl::SetWindowState( const OUString
& sName
,
469 const OUString
& sState
)
471 #ifdef DEBUG_VIEWOPTIONS
477 css::uno::Reference
< css::beans::XPropertySet
> xNode(
478 impl_getSetNode(sName
, sal_True
),
479 css::uno::UNO_QUERY_THROW
);
480 xNode
->setPropertyValue(PROPERTY_WINDOWSTATE
, css::uno::makeAny(sState
));
481 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
483 catch(const css::uno::Exception
& ex
)
485 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
489 //*****************************************************************************************************************
490 css::uno::Sequence
< css::beans::NamedValue
> SvtViewOptionsBase_Impl::GetUserData( const OUString
& sName
)
492 #ifdef DEBUG_VIEWOPTIONS
498 css::uno::Reference
< css::container::XNameAccess
> xNode(
499 impl_getSetNode(sName
, sal_False
),
500 css::uno::UNO_QUERY
); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
501 css::uno::Reference
< css::container::XNameAccess
> xUserData
;
503 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
506 const css::uno::Sequence
< OUString
> lNames
= xUserData
->getElementNames();
507 const OUString
* pNames
= lNames
.getConstArray();
508 sal_Int32 c
= lNames
.getLength();
510 css::uno::Sequence
< css::beans::NamedValue
> lUserData(c
);
514 lUserData
[i
].Name
= pNames
[i
];
515 lUserData
[i
].Value
= xUserData
->getByName(pNames
[i
]);
521 catch(const css::uno::Exception
& ex
)
523 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
526 return css::uno::Sequence
< css::beans::NamedValue
>();
529 //*****************************************************************************************************************
530 void SvtViewOptionsBase_Impl::SetUserData( const OUString
& sName
,
531 const css::uno::Sequence
< css::beans::NamedValue
>& lData
)
533 #ifdef DEBUG_VIEWOPTIONS
539 css::uno::Reference
< css::container::XNameAccess
> xNode(
540 impl_getSetNode(sName
, sal_True
),
541 css::uno::UNO_QUERY_THROW
);
542 css::uno::Reference
< css::container::XNameContainer
> xUserData
;
543 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
546 const css::beans::NamedValue
* pData
= lData
.getConstArray();
547 sal_Int32 c
= lData
.getLength();
551 if (xUserData
->hasByName(pData
[i
].Name
))
552 xUserData
->replaceByName(pData
[i
].Name
, pData
[i
].Value
);
554 xUserData
->insertByName(pData
[i
].Name
, pData
[i
].Value
);
557 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
559 catch(const css::uno::Exception
& ex
)
561 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
565 //*****************************************************************************************************************
566 css::uno::Any
SvtViewOptionsBase_Impl::GetUserItem( const OUString
& sName
,
567 const OUString
& sItem
)
569 #ifdef DEBUG_VIEWOPTIONS
576 css::uno::Reference
< css::container::XNameAccess
> xNode(
577 impl_getSetNode(sName
, sal_False
),
578 css::uno::UNO_QUERY
);
579 css::uno::Reference
< css::container::XNameAccess
> xUserData
;
581 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
583 aItem
= xUserData
->getByName(sItem
);
585 catch(const css::container::NoSuchElementException
&)
587 catch(const css::uno::Exception
& ex
)
590 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
596 //*****************************************************************************************************************
597 void SvtViewOptionsBase_Impl::SetUserItem( const OUString
& sName
,
598 const OUString
& sItem
,
599 const css::uno::Any
& aValue
)
601 #ifdef DEBUG_VIEWOPTIONS
607 css::uno::Reference
< css::container::XNameAccess
> xNode(
608 impl_getSetNode(sName
, sal_True
),
609 css::uno::UNO_QUERY_THROW
);
610 css::uno::Reference
< css::container::XNameContainer
> xUserData
;
611 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
614 if (xUserData
->hasByName(sItem
))
615 xUserData
->replaceByName(sItem
, aValue
);
617 xUserData
->insertByName(sItem
, aValue
);
619 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
621 catch(const css::uno::Exception
& ex
)
623 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
627 //*****************************************************************************************************************
628 sal_Int32
SvtViewOptionsBase_Impl::GetPageID( const OUString
& sName
)
630 #ifdef DEBUG_VIEWOPTIONS
637 css::uno::Reference
< css::beans::XPropertySet
> xNode(
638 impl_getSetNode(sName
, sal_False
),
639 css::uno::UNO_QUERY
);
641 xNode
->getPropertyValue(PROPERTY_PAGEID
) >>= nID
;
643 catch(const css::uno::Exception
& ex
)
646 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
652 //*****************************************************************************************************************
653 void SvtViewOptionsBase_Impl::SetPageID( const OUString
& sName
,
656 #ifdef DEBUG_VIEWOPTIONS
662 css::uno::Reference
< css::beans::XPropertySet
> xNode(
663 impl_getSetNode(sName
, sal_True
),
664 css::uno::UNO_QUERY_THROW
);
665 xNode
->setPropertyValue(PROPERTY_PAGEID
, css::uno::makeAny(nID
));
666 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
668 catch(const css::uno::Exception
& ex
)
670 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
674 //*****************************************************************************************************************
675 SvtViewOptionsBase_Impl::State
SvtViewOptionsBase_Impl::GetVisible( const OUString
& sName
)
677 #ifdef DEBUG_VIEWOPTIONS
681 State eState
= STATE_NONE
;
684 css::uno::Reference
< css::beans::XPropertySet
> xNode(
685 impl_getSetNode(sName
, sal_False
),
686 css::uno::UNO_QUERY
);
689 sal_Bool bVisible
= sal_False
;
690 if (xNode
->getPropertyValue(PROPERTY_VISIBLE
) >>= bVisible
)
692 eState
= bVisible
? STATE_TRUE
: STATE_FALSE
;
696 catch(const css::uno::Exception
& ex
)
698 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
704 //*****************************************************************************************************************
705 void SvtViewOptionsBase_Impl::SetVisible( const OUString
& sName
,
708 #ifdef DEBUG_VIEWOPTIONS
714 css::uno::Reference
< css::beans::XPropertySet
> xNode(
715 impl_getSetNode(sName
, sal_True
),
716 css::uno::UNO_QUERY_THROW
);
717 xNode
->setPropertyValue(PROPERTY_VISIBLE
, css::uno::makeAny(bVisible
));
718 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
720 catch(const css::uno::Exception
& ex
)
722 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
726 /*-************************************************************************************************************//**
727 @short create new set node with default values on disk
728 @descr To create a new UserData item - the super node of these property must already exist!
729 You can call this method to create these new entry with default values and change UserData then.
731 @seealso method impl_writeDirectProp()
733 @param "sNode", name of new entry
735 *//*-*************************************************************************************************************/
736 css::uno::Reference
< css::uno::XInterface
> SvtViewOptionsBase_Impl::impl_getSetNode( const OUString
& sNode
,
737 sal_Bool bCreateIfMissing
)
739 css::uno::Reference
< css::uno::XInterface
> xNode
;
743 if (bCreateIfMissing
)
744 xNode
= ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot
, m_sListName
, sNode
);
747 if (m_xSet
.is() && m_xSet
->hasByName(sNode
) )
748 m_xSet
->getByName(sNode
) >>= xNode
;
751 catch(const css::container::NoSuchElementException
&)
753 catch(const css::uno::Exception
& ex
)
756 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
762 //*****************************************************************************************************************
764 //*****************************************************************************************************************
765 SvtViewOptions::SvtViewOptions( EViewType eType
,
766 const OUString
& sViewName
)
767 : m_eViewType ( eType
)
768 , m_sViewName ( sViewName
)
770 // Global access, must be guarded (multithreading!)
771 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
773 // Search for right dat container for this view type and initialize right data container or set right ref count!
777 // Increase ref count for dialog data container first.
778 ++m_nRefCount_Dialogs
;
779 // If these instance the first user of the dialog data container - create these impl static container!
780 if( m_nRefCount_Dialogs
== 1 )
782 //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
783 m_pDataContainer_Dialogs
= new SvtViewOptionsBase_Impl( LIST_DIALOGS
);
784 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG
);
789 // Increase ref count for tab-dialog data container first.
790 ++m_nRefCount_TabDialogs
;
791 // If these instance the first user of the tab-dialog data container - create these impl static container!
792 if( m_nRefCount_TabDialogs
== 1 )
794 m_pDataContainer_TabDialogs
= new SvtViewOptionsBase_Impl( LIST_TABDIALOGS
);
795 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG
);
800 // Increase ref count for tab-page data container first.
801 ++m_nRefCount_TabPages
;
802 // If these instance the first user of the tab-page data container - create these impl static container!
803 if( m_nRefCount_TabPages
== 1 )
805 m_pDataContainer_TabPages
= new SvtViewOptionsBase_Impl( LIST_TABPAGES
);
806 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE
);
811 // Increase ref count for window data container first.
812 ++m_nRefCount_Windows
;
813 // If these instance the first user of the window data container - create these impl static container!
814 if( m_nRefCount_Windows
== 1 )
816 m_pDataContainer_Windows
= new SvtViewOptionsBase_Impl( LIST_WINDOWS
);
817 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW
);
821 default : OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
825 //*****************************************************************************************************************
827 //*****************************************************************************************************************
828 SvtViewOptions::~SvtViewOptions()
830 // Global access, must be guarded (multithreading!)
831 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
833 // Search for right dat container for this view type and deinitialize right data container or set right ref count!
834 switch( m_eViewType
)
837 // Decrease ref count for dialog data container first.
838 --m_nRefCount_Dialogs
;
839 // If these instance the last user of the dialog data container - delete these impl static container!
840 if( m_nRefCount_Dialogs
== 0 )
842 delete m_pDataContainer_Dialogs
;
843 m_pDataContainer_Dialogs
= NULL
;
848 // Decrease ref count for tab-dialog data container first.
849 --m_nRefCount_TabDialogs
;
850 // If these instance the last user of the tab-dialog data container - delete these impl static container!
851 if( m_nRefCount_TabDialogs
== 0 )
853 delete m_pDataContainer_TabDialogs
;
854 m_pDataContainer_TabDialogs
= NULL
;
859 // Decrease ref count for tab-page data container first.
860 --m_nRefCount_TabPages
;
861 // If these instance the last user of the tab-page data container - delete these impl static container!
862 if( m_nRefCount_TabPages
== 0 )
864 delete m_pDataContainer_TabPages
;
865 m_pDataContainer_TabPages
= NULL
;
870 // Decrease ref count for window data container first.
871 --m_nRefCount_Windows
;
872 // If these instance the last user of the window data container - delete these impl static container!
873 if( m_nRefCount_Windows
== 0 )
875 delete m_pDataContainer_Windows
;
876 m_pDataContainer_Windows
= NULL
;
883 //*****************************************************************************************************************
885 //*****************************************************************************************************************
886 sal_Bool
SvtViewOptions::Exists() const
888 // Ready for multithreading
889 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
891 sal_Bool bExists
= sal_False
;
892 switch( m_eViewType
)
895 bExists
= m_pDataContainer_Dialogs
->Exists( m_sViewName
);
899 bExists
= m_pDataContainer_TabDialogs
->Exists( m_sViewName
);
903 bExists
= m_pDataContainer_TabPages
->Exists( m_sViewName
);
907 bExists
= m_pDataContainer_Windows
->Exists( m_sViewName
);
914 //*****************************************************************************************************************
916 //*****************************************************************************************************************
917 sal_Bool
SvtViewOptions::Delete()
919 // Ready for multithreading
920 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
922 sal_Bool bState
= sal_False
;
923 switch( m_eViewType
)
926 bState
= m_pDataContainer_Dialogs
->Delete( m_sViewName
);
930 bState
= m_pDataContainer_TabDialogs
->Delete( m_sViewName
);
934 bState
= m_pDataContainer_TabPages
->Delete( m_sViewName
);
938 bState
= m_pDataContainer_Windows
->Delete( m_sViewName
);
945 //*****************************************************************************************************************
947 //*****************************************************************************************************************
948 OUString
SvtViewOptions::GetWindowState() const
950 // Ready for multithreading
951 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
954 switch( m_eViewType
)
957 sState
= m_pDataContainer_Dialogs
->GetWindowState( m_sViewName
);
961 sState
= m_pDataContainer_TabDialogs
->GetWindowState( m_sViewName
);
965 sState
= m_pDataContainer_TabPages
->GetWindowState( m_sViewName
);
969 sState
= m_pDataContainer_Windows
->GetWindowState( m_sViewName
);
976 //*****************************************************************************************************************
978 //*****************************************************************************************************************
979 void SvtViewOptions::SetWindowState( const OUString
& sState
)
981 // Ready for multithreading
982 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
984 switch( m_eViewType
)
987 m_pDataContainer_Dialogs
->SetWindowState( m_sViewName
, sState
);
991 m_pDataContainer_TabDialogs
->SetWindowState( m_sViewName
, sState
);
995 m_pDataContainer_TabPages
->SetWindowState( m_sViewName
, sState
);
999 m_pDataContainer_Windows
->SetWindowState( m_sViewName
, sState
);
1005 //*****************************************************************************************************************
1007 //*****************************************************************************************************************
1008 sal_Int32
SvtViewOptions::GetPageID() const
1010 // Ready for multithreading
1011 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1013 // Safe impossible cases.
1014 // These call isn't allowed for dialogs, tab-pages or windows!
1015 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" );
1018 if( m_eViewType
== E_TABDIALOG
)
1019 nID
= m_pDataContainer_TabDialogs
->GetPageID( m_sViewName
);
1023 //*****************************************************************************************************************
1025 //*****************************************************************************************************************
1026 void SvtViewOptions::SetPageID( sal_Int32 nID
)
1028 // Ready for multithreading
1029 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1031 // Safe impossible cases.
1032 // These call isn't allowed for dialogs, tab-pages or windows!
1033 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" );
1035 if( m_eViewType
== E_TABDIALOG
)
1036 m_pDataContainer_TabDialogs
->SetPageID( m_sViewName
, nID
);
1039 //*****************************************************************************************************************
1041 //*****************************************************************************************************************
1042 sal_Bool
SvtViewOptions::IsVisible() const
1044 // Ready for multithreading
1045 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1047 // Safe impossible cases.
1048 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1049 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" );
1051 sal_Bool bState
= sal_False
;
1052 if( m_eViewType
== E_WINDOW
)
1053 bState
= m_pDataContainer_Windows
->GetVisible( m_sViewName
) == SvtViewOptionsBase_Impl::STATE_TRUE
;
1058 //*****************************************************************************************************************
1060 //*****************************************************************************************************************
1061 void SvtViewOptions::SetVisible( sal_Bool bState
)
1063 // Ready for multithreading
1064 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1066 // Safe impossible cases.
1067 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1068 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" );
1070 if( m_eViewType
== E_WINDOW
)
1071 m_pDataContainer_Windows
->SetVisible( m_sViewName
, bState
);
1074 //*****************************************************************************************************************
1076 //*****************************************************************************************************************
1077 bool SvtViewOptions::HasVisible() const
1079 // Ready for multithreading
1080 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1082 // Safe impossible cases.
1083 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1084 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" );
1086 bool bState
= false;
1087 if( m_eViewType
== E_WINDOW
)
1088 bState
= m_pDataContainer_Windows
->GetVisible( m_sViewName
) != SvtViewOptionsBase_Impl::STATE_NONE
;
1093 //*****************************************************************************************************************
1094 css::uno::Sequence
< css::beans::NamedValue
> SvtViewOptions::GetUserData() const
1096 // Ready for multithreading
1097 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1099 css::uno::Sequence
< css::beans::NamedValue
> lData
;
1100 switch( m_eViewType
)
1103 lData
= m_pDataContainer_Dialogs
->GetUserData( m_sViewName
);
1106 case E_TABDIALOG
: {
1107 lData
= m_pDataContainer_TabDialogs
->GetUserData( m_sViewName
);
1111 lData
= m_pDataContainer_TabPages
->GetUserData( m_sViewName
);
1115 lData
= m_pDataContainer_Windows
->GetUserData( m_sViewName
);
1122 //*****************************************************************************************************************
1123 void SvtViewOptions::SetUserData( const css::uno::Sequence
< css::beans::NamedValue
>& lData
)
1125 // Ready for multithreading
1126 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1128 switch( m_eViewType
)
1131 m_pDataContainer_Dialogs
->SetUserData( m_sViewName
, lData
);
1134 case E_TABDIALOG
: {
1135 m_pDataContainer_TabDialogs
->SetUserData( m_sViewName
, lData
);
1139 m_pDataContainer_TabPages
->SetUserData( m_sViewName
, lData
);
1143 m_pDataContainer_Windows
->SetUserData( m_sViewName
, lData
);
1149 //*****************************************************************************************************************
1150 css::uno::Any
SvtViewOptions::GetUserItem( const OUString
& sName
) const
1152 // Ready for multithreading
1153 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1155 css::uno::Any aItem
;
1156 switch( m_eViewType
)
1159 aItem
= m_pDataContainer_Dialogs
->GetUserItem( m_sViewName
, sName
);
1162 case E_TABDIALOG
: {
1163 aItem
= m_pDataContainer_TabDialogs
->GetUserItem( m_sViewName
, sName
);
1167 aItem
= m_pDataContainer_TabPages
->GetUserItem( m_sViewName
, sName
);
1171 aItem
= m_pDataContainer_Windows
->GetUserItem( m_sViewName
, sName
);
1178 //*****************************************************************************************************************
1179 void SvtViewOptions::SetUserItem( const OUString
& sName
,
1180 const css::uno::Any
& aValue
)
1182 // Ready for multithreading
1183 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1185 switch( m_eViewType
)
1188 m_pDataContainer_Dialogs
->SetUserItem( m_sViewName
, sName
, aValue
);
1191 case E_TABDIALOG
: {
1192 m_pDataContainer_TabDialogs
->SetUserItem( m_sViewName
, sName
, aValue
);
1196 m_pDataContainer_TabPages
->SetUserItem( m_sViewName
, sName
, aValue
);
1200 m_pDataContainer_Windows
->SetUserItem( m_sViewName
, sName
, aValue
);
1208 class theViewOptionsMutex
: public rtl::Static
<osl::Mutex
, theViewOptionsMutex
>{};
1211 //*****************************************************************************************************************
1213 //*****************************************************************************************************************
1214 ::osl::Mutex
& SvtViewOptions::GetOwnStaticMutex()
1216 return theViewOptionsMutex::get();
1219 void SvtViewOptions::AcquireOptions()
1221 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1222 if( ++m_nRefCount_Dialogs
== 1 )
1224 m_pDataContainer_Dialogs
= new SvtViewOptionsBase_Impl( LIST_DIALOGS
);
1225 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG
);
1227 if( ++m_nRefCount_TabDialogs
== 1 )
1229 m_pDataContainer_TabDialogs
= new SvtViewOptionsBase_Impl( LIST_TABDIALOGS
);
1230 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG
);
1232 if( ++m_nRefCount_TabPages
== 1 )
1234 m_pDataContainer_TabPages
= new SvtViewOptionsBase_Impl( LIST_TABPAGES
);
1235 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE
);
1237 if( ++m_nRefCount_Windows
== 1 )
1239 m_pDataContainer_Windows
= new SvtViewOptionsBase_Impl( LIST_WINDOWS
);
1240 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW
);
1244 void SvtViewOptions::ReleaseOptions()
1246 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1247 if( --m_nRefCount_Dialogs
== 0 )
1249 delete m_pDataContainer_Dialogs
;
1250 m_pDataContainer_Dialogs
= NULL
;
1252 if( --m_nRefCount_TabDialogs
== 0 )
1254 delete m_pDataContainer_TabDialogs
;
1255 m_pDataContainer_TabDialogs
= NULL
;
1257 if( --m_nRefCount_TabPages
== 0 )
1259 delete m_pDataContainer_TabPages
;
1260 m_pDataContainer_TabPages
= NULL
;
1262 if( --m_nRefCount_Windows
== 0 )
1264 delete m_pDataContainer_Windows
;
1265 m_pDataContainer_Windows
= NULL
;
1269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */