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>
36 #error "Who define CONST_ASCII before! I use it to create const ascii strings ..."
38 #define CONST_ASCII(SASCIIVALUE) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SASCIIVALUE))
41 #define PACKAGE_VIEWS CONST_ASCII("org.openoffice.Office.Views")
43 #define LIST_DIALOGS CONST_ASCII("Dialogs" )
44 #define LIST_TABDIALOGS CONST_ASCII("TabDialogs")
45 #define LIST_TABPAGES CONST_ASCII("TabPages" )
46 #define LIST_WINDOWS CONST_ASCII("Windows" )
48 #define PROPERTY_WINDOWSTATE CONST_ASCII("WindowState")
49 #define PROPERTY_PAGEID CONST_ASCII("PageID" )
50 #define PROPERTY_VISIBLE CONST_ASCII("Visible" )
51 #define PROPERTY_USERDATA CONST_ASCII("UserData" )
53 #define DEFAULT_WINDOWSTATE ::rtl::OUString()
54 #define DEFAULT_USERDATA css::uno::Sequence< css::beans::NamedValue >()
55 #define DEFAULT_PAGEID 0
56 #define DEFAULT_VISIBLE sal_False
58 //#define DEBUG_VIEWOPTIONS
60 #ifdef DEBUG_VIEWOPTIONS
61 #define _LOG_COUNTER_( _SVIEW_, _NREAD_, _NWRITE_ ) \
63 FILE* pFile = fopen( "viewdbg.txt", "a" ); \
64 fprintf( pFile, "%s[%d, %d]\n", ::rtl::OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
67 #endif // DEBUG_VIEWOPTIONS
69 #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION) \
71 ::rtl::OUStringBuffer sMsg(256); \
72 sMsg.appendAscii("Unexpected exception catched. Original message was:\n\"" ); \
73 sMsg.append (SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION.Message); \
74 sMsg.appendAscii("\"" ); \
77 //_________________________________________________________________________________________________________________
79 //_________________________________________________________________________________________________________________
81 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_Dialogs
= NULL
;
82 sal_Int32
SvtViewOptions::m_nRefCount_Dialogs
= 0 ;
83 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_TabDialogs
= NULL
;
84 sal_Int32
SvtViewOptions::m_nRefCount_TabDialogs
= 0 ;
85 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_TabPages
= NULL
;
86 sal_Int32
SvtViewOptions::m_nRefCount_TabPages
= 0 ;
87 SvtViewOptionsBase_Impl
* SvtViewOptions::m_pDataContainer_Windows
= NULL
;
88 sal_Int32
SvtViewOptions::m_nRefCount_Windows
= 0 ;
90 //_________________________________________________________________________________________________________________
91 // private declarations!
92 //_________________________________________________________________________________________________________________
94 /*-************************************************************************************************************//**
95 @descr declare one configuration item
96 These struct hold information about one view item. But not all member are used for all entries!
97 User must decide which information are usefull and which not. We are a container iztem only and doesnt
98 know anything about the context.
99 But; we support a feature:
100 decision between items with default values (should not realy exist in configuration!)
101 and items with real values - changed by user. So user can suppress saving of realy unused items
102 to disk - because; defaulted items could be restored on runtime without reading from disk!!!
103 And if only items with valid information was written to cfg - we mustn't read so much and save time.
104 So we start with an member m_bDefault=True and reset it to False after first set-call.
105 Deficiencies of these solution - we cant allow direct read/write access to our member. We must
106 support it by set/get-methods ...
107 *//*-*************************************************************************************************************/
111 //---------------------------------------------------------------------------------------------------------
112 // create "default" item
115 m_sWindowState
= DEFAULT_WINDOWSTATE
;
116 m_lUserData
= DEFAULT_USERDATA
;
117 m_nPageID
= DEFAULT_PAGEID
;
118 m_bVisible
= DEFAULT_VISIBLE
;
120 m_bDefault
= sal_True
;
123 //---------------------------------------------------------------------------------------------------------
124 // write access - with reseting of default state
125 void setWindowState( const ::rtl::OUString
& sValue
)
128 ( m_bDefault
== sal_True
) &&
129 ( sValue
== DEFAULT_WINDOWSTATE
)
131 m_sWindowState
= sValue
;
134 //---------------------------------------------------------------------------------------------------------
135 void setUserData( const css::uno::Sequence
< css::beans::NamedValue
>& lValue
)
138 ( m_bDefault
== sal_True
) &&
139 ( lValue
== DEFAULT_USERDATA
)
141 m_lUserData
= lValue
;
144 //---------------------------------------------------------------------------------------------------------
145 void setPageID( sal_Int32 nValue
)
148 ( m_bDefault
== sal_True
) &&
149 ( nValue
== DEFAULT_PAGEID
)
154 //---------------------------------------------------------------------------------------------------------
155 void setVisible( sal_Bool bValue
)
158 ( m_bDefault
== sal_True
) &&
159 ( bValue
== DEFAULT_VISIBLE
)
164 //---------------------------------------------------------------------------------------------------------
166 ::rtl::OUString
getWindowState() { return m_sWindowState
; }
167 css::uno::Sequence
< css::beans::NamedValue
> getUserData () { return m_lUserData
; }
168 sal_Int32
getPageID () { return m_nPageID
; }
169 sal_Bool
getVisible () { return m_bVisible
; }
171 //---------------------------------------------------------------------------------------------------------
172 // special operation for easy access on user data
173 void setUserItem( const ::rtl::OUString
& sName
,
174 const css::uno::Any
& aValue
)
176 // we change UserData in every case!
177 // a) we change already existing item
178 // or b) we add a new one
179 m_bDefault
= sal_False
;
181 sal_Bool bExist
= sal_False
;
182 sal_Int32 nCount
= m_lUserData
.getLength();
184 // change it, if it already exist ...
185 for( sal_Int32 nStep
=0; nStep
<nCount
; ++nStep
)
187 if( m_lUserData
[nStep
].Name
== sName
)
189 m_lUserData
[nStep
].Value
= aValue
;
195 // ... or create new list item
196 if( bExist
== sal_False
)
198 m_lUserData
.realloc( nCount
+1 );
199 m_lUserData
[nCount
].Name
= sName
;
200 m_lUserData
[nCount
].Value
= aValue
;
204 //---------------------------------------------------------------------------------------------------------
205 css::uno::Any
getUserItem( const ::rtl::OUString
& sName
)
207 // default value - if item not exist!
208 css::uno::Any aValue
;
210 sal_Int32 nCount
= m_lUserData
.getLength();
211 for( sal_Int32 nStep
=0; nStep
<nCount
; ++nStep
)
213 if( m_lUserData
[nStep
].Name
== sName
)
215 aValue
= m_lUserData
[nStep
].Value
;
222 //---------------------------------------------------------------------------------------------------------
223 // check for default items
224 sal_Bool
isDefault() { return m_bDefault
; }
227 ::rtl::OUString m_sWindowState
;
228 css::uno::Sequence
< css::beans::NamedValue
> m_lUserData
;
229 sal_Int32 m_nPageID
;
230 sal_Bool m_bVisible
;
232 sal_Bool m_bDefault
;
235 struct IMPL_TStringHashCode
237 size_t operator()(const ::rtl::OUString
& sString
) const
239 return sString
.hashCode();
243 typedef ::boost::unordered_map
< ::rtl::OUString
,
245 IMPL_TStringHashCode
,
246 ::std::equal_to
< ::rtl::OUString
> > IMPL_TViewHash
;
248 /*-************************************************************************************************************//**
249 @descr Implement base data container for view options elements.
250 Every item support ALL possible configuration informations.
251 But not every superclass should use them! Because some view types don't
254 @attention We implement a write-througt-cache! We use it for reading - but write all changes directly to
255 configuration. (changes are made on internal cache too!). So it's easier to distinguish
256 between added/changed/removed elements without any complex mask or bool flag informations.
257 Caches from configuration and our own one are synchronized every time - if we do so.
258 *//*-*************************************************************************************************************/
259 class SvtViewOptionsBase_Impl
261 //-------------------------------------------------------------------------------------------------------------
263 enum State
{ STATE_NONE
, STATE_FALSE
, STATE_TRUE
};
265 SvtViewOptionsBase_Impl ( const ::rtl::OUString
& sList
);
266 virtual ~SvtViewOptionsBase_Impl ( );
267 sal_Bool
Exists ( const ::rtl::OUString
& sName
);
268 sal_Bool
Delete ( const ::rtl::OUString
& sName
);
269 ::rtl::OUString
GetWindowState ( const ::rtl::OUString
& sName
);
270 void SetWindowState ( const ::rtl::OUString
& sName
,
271 const ::rtl::OUString
& sState
);
272 css::uno::Sequence
< css::beans::NamedValue
> GetUserData ( const ::rtl::OUString
& sName
);
273 void SetUserData ( const ::rtl::OUString
& sName
,
274 const css::uno::Sequence
< css::beans::NamedValue
>& lData
);
275 sal_Int32
GetPageID ( const ::rtl::OUString
& sName
);
276 void SetPageID ( const ::rtl::OUString
& sName
,
278 State
GetVisible ( const ::rtl::OUString
& sName
);
279 void SetVisible ( const ::rtl::OUString
& sName
,
281 css::uno::Any
GetUserItem ( const ::rtl::OUString
& sName
,
282 const ::rtl::OUString
& sItem
);
283 void SetUserItem ( const ::rtl::OUString
& sName
,
284 const ::rtl::OUString
& sItem
,
285 const css::uno::Any
& aValue
);
287 //-------------------------------------------------------------------------------------------------------------
289 css::uno::Reference
< css::uno::XInterface
> impl_getSetNode( const ::rtl::OUString
& sNode
,
290 sal_Bool bCreateIfMissing
);
292 //-------------------------------------------------------------------------------------------------------------
294 ::rtl::OUString m_sListName
;
295 css::uno::Reference
< css::container::XNameAccess
> m_xRoot
;
296 css::uno::Reference
< css::container::XNameAccess
> m_xSet
;
298 #ifdef DEBUG_VIEWOPTIONS
299 sal_Int32 m_nReadCount
;
300 sal_Int32 m_nWriteCount
;
304 /*-************************************************************************************************************//**
305 @descr Implement the base data container.
306 *//*-*************************************************************************************************************/
308 /*-************************************************************************************************************//**
310 @descr We use it to open right configuration file and let configuration objects fill her caches.
311 Then we read all existing entries from right list and cached it inside our object too.
312 Normaly we should enable notifications for changes on these values too ... but these feature
313 isn't full implemented in the moment.
315 @seealso baseclass ::utl::ConfigItem
316 @seealso method Notify()
320 *//*-*************************************************************************************************************/
321 SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const ::rtl::OUString
& sList
)
322 : m_sListName ( sList
) // we must know, which view type we must support
323 #ifdef DEBUG_VIEWOPTIONS
330 m_xRoot
= css::uno::Reference
< css::container::XNameAccess
>(
331 ::comphelper::ConfigurationHelper::openConfig(
332 ::comphelper::getProcessComponentContext(),
334 ::comphelper::ConfigurationHelper::E_STANDARD
),
335 css::uno::UNO_QUERY
);
337 m_xRoot
->getByName(sList
) >>= m_xSet
;
339 catch(const css::uno::Exception
& ex
)
344 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
348 /*-************************************************************************************************************//**
350 @descr clean up something
352 @attention We implement a write through cache! So we mustn't do it realy. All changes was written to cfg directly.
353 Commit isn't neccessary then.
355 @seealso baseclass ::utl::ConfigItem
356 @seealso method IsModified()
357 @seealso method SetModified()
358 @seealso method Commit()
362 *//*-*************************************************************************************************************/
363 SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
365 // dont flush configuration changes here to m_xRoot.
366 // That must be done inside every SetXXX() method already !
367 // Here its to late - DisposedExceptions from used configuration access can occure otherwise.
372 #ifdef DEBUG_VIEWOPTIONS
373 _LOG_COUNTER_( m_sListName
, m_nReadCount
, m_nWriteCount
)
374 #endif // DEBUG_VIEWOPTIONS
377 /*-************************************************************************************************************//**
378 @short checks for already existing entries
379 @descr If user don't know, if an entry already exist - he can get this information by calling this method.
381 @seealso member m_aList
383 @param "sName", name of entry to check exist state
384 @return true , if item exist
386 *//*-*************************************************************************************************************/
387 sal_Bool
SvtViewOptionsBase_Impl::Exists( const ::rtl::OUString
& sName
)
389 sal_Bool bExists
= sal_False
;
394 bExists
= m_xSet
->hasByName(sName
);
396 catch(const css::uno::Exception
& ex
)
399 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
405 /*-************************************************************************************************************//**
407 @descr Use it to delete set entry by given name.
409 @seealso member m_aList
411 @param "sName", name of entry to delete it
412 @return true , if item not exist(!) or could be deleted (should be the same!)
414 *//*-*************************************************************************************************************/
415 sal_Bool
SvtViewOptionsBase_Impl::Delete( const ::rtl::OUString
& sName
)
417 #ifdef DEBUG_VIEWOPTIONS
421 sal_Bool bDeleted
= sal_False
;
424 css::uno::Reference
< css::container::XNameContainer
> xSet(m_xSet
, css::uno::UNO_QUERY_THROW
);
425 xSet
->removeByName(sName
);
427 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
429 catch(const css::container::NoSuchElementException
&)
430 { bDeleted
= sal_True
; }
431 catch(const css::uno::Exception
& ex
)
433 bDeleted
= sal_False
;
434 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
440 /*-************************************************************************************************************//**
441 @short read/write access to cache view items and her properties
442 @descr Follow methods support read/write access to all cache view items.
444 @seealso member m_sList
448 *//*-*************************************************************************************************************/
449 ::rtl::OUString
SvtViewOptionsBase_Impl::GetWindowState( const ::rtl::OUString
& sName
)
451 #ifdef DEBUG_VIEWOPTIONS
455 ::rtl::OUString sWindowState
;
458 css::uno::Reference
< css::beans::XPropertySet
> xNode(
459 impl_getSetNode(sName
, sal_False
),
460 css::uno::UNO_QUERY
);
462 xNode
->getPropertyValue(PROPERTY_WINDOWSTATE
) >>= sWindowState
;
464 catch(const css::uno::Exception
& ex
)
466 sWindowState
= ::rtl::OUString();
467 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
473 //*****************************************************************************************************************
474 void SvtViewOptionsBase_Impl::SetWindowState( const ::rtl::OUString
& sName
,
475 const ::rtl::OUString
& sState
)
477 #ifdef DEBUG_VIEWOPTIONS
483 css::uno::Reference
< css::beans::XPropertySet
> xNode(
484 impl_getSetNode(sName
, sal_True
),
485 css::uno::UNO_QUERY_THROW
);
486 xNode
->setPropertyValue(PROPERTY_WINDOWSTATE
, css::uno::makeAny(sState
));
487 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
489 catch(const css::uno::Exception
& ex
)
491 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
495 //*****************************************************************************************************************
496 css::uno::Sequence
< css::beans::NamedValue
> SvtViewOptionsBase_Impl::GetUserData( const ::rtl::OUString
& sName
)
498 #ifdef DEBUG_VIEWOPTIONS
504 css::uno::Reference
< css::container::XNameAccess
> xNode(
505 impl_getSetNode(sName
, sal_False
),
506 css::uno::UNO_QUERY
); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
507 css::uno::Reference
< css::container::XNameAccess
> xUserData
;
509 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
512 const css::uno::Sequence
< ::rtl::OUString
> lNames
= xUserData
->getElementNames();
513 const ::rtl::OUString
* pNames
= lNames
.getConstArray();
514 sal_Int32 c
= lNames
.getLength();
516 css::uno::Sequence
< css::beans::NamedValue
> lUserData(c
);
520 lUserData
[i
].Name
= pNames
[i
];
521 lUserData
[i
].Value
= xUserData
->getByName(pNames
[i
]);
527 catch(const css::uno::Exception
& ex
)
529 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
532 return css::uno::Sequence
< css::beans::NamedValue
>();
535 //*****************************************************************************************************************
536 void SvtViewOptionsBase_Impl::SetUserData( const ::rtl::OUString
& sName
,
537 const css::uno::Sequence
< css::beans::NamedValue
>& lData
)
539 #ifdef DEBUG_VIEWOPTIONS
545 css::uno::Reference
< css::container::XNameAccess
> xNode(
546 impl_getSetNode(sName
, sal_True
),
547 css::uno::UNO_QUERY_THROW
);
548 css::uno::Reference
< css::container::XNameContainer
> xUserData
;
549 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
552 const css::beans::NamedValue
* pData
= lData
.getConstArray();
553 sal_Int32 c
= lData
.getLength();
557 if (xUserData
->hasByName(pData
[i
].Name
))
558 xUserData
->replaceByName(pData
[i
].Name
, pData
[i
].Value
);
560 xUserData
->insertByName(pData
[i
].Name
, pData
[i
].Value
);
563 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
565 catch(const css::uno::Exception
& ex
)
567 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
571 //*****************************************************************************************************************
572 css::uno::Any
SvtViewOptionsBase_Impl::GetUserItem( const ::rtl::OUString
& sName
,
573 const ::rtl::OUString
& sItem
)
575 #ifdef DEBUG_VIEWOPTIONS
582 css::uno::Reference
< css::container::XNameAccess
> xNode(
583 impl_getSetNode(sName
, sal_False
),
584 css::uno::UNO_QUERY
);
585 css::uno::Reference
< css::container::XNameAccess
> xUserData
;
587 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
589 aItem
= xUserData
->getByName(sItem
);
591 catch(const css::container::NoSuchElementException
&)
593 catch(const css::uno::Exception
& ex
)
596 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
602 //*****************************************************************************************************************
603 void SvtViewOptionsBase_Impl::SetUserItem( const ::rtl::OUString
& sName
,
604 const ::rtl::OUString
& sItem
,
605 const css::uno::Any
& aValue
)
607 #ifdef DEBUG_VIEWOPTIONS
613 css::uno::Reference
< css::container::XNameAccess
> xNode(
614 impl_getSetNode(sName
, sal_True
),
615 css::uno::UNO_QUERY_THROW
);
616 css::uno::Reference
< css::container::XNameContainer
> xUserData
;
617 xNode
->getByName(PROPERTY_USERDATA
) >>= xUserData
;
620 if (xUserData
->hasByName(sItem
))
621 xUserData
->replaceByName(sItem
, aValue
);
623 xUserData
->insertByName(sItem
, aValue
);
625 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
627 catch(const css::uno::Exception
& ex
)
629 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
633 //*****************************************************************************************************************
634 sal_Int32
SvtViewOptionsBase_Impl::GetPageID( const ::rtl::OUString
& sName
)
636 #ifdef DEBUG_VIEWOPTIONS
643 css::uno::Reference
< css::beans::XPropertySet
> xNode(
644 impl_getSetNode(sName
, sal_False
),
645 css::uno::UNO_QUERY
);
647 xNode
->getPropertyValue(PROPERTY_PAGEID
) >>= nID
;
649 catch(const css::uno::Exception
& ex
)
652 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
658 //*****************************************************************************************************************
659 void SvtViewOptionsBase_Impl::SetPageID( const ::rtl::OUString
& sName
,
662 #ifdef DEBUG_VIEWOPTIONS
668 css::uno::Reference
< css::beans::XPropertySet
> xNode(
669 impl_getSetNode(sName
, sal_True
),
670 css::uno::UNO_QUERY_THROW
);
671 xNode
->setPropertyValue(PROPERTY_PAGEID
, css::uno::makeAny(nID
));
672 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
674 catch(const css::uno::Exception
& ex
)
676 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
680 //*****************************************************************************************************************
681 SvtViewOptionsBase_Impl::State
SvtViewOptionsBase_Impl::GetVisible( const ::rtl::OUString
& sName
)
683 #ifdef DEBUG_VIEWOPTIONS
687 State eState
= STATE_NONE
;
690 css::uno::Reference
< css::beans::XPropertySet
> xNode(
691 impl_getSetNode(sName
, sal_False
),
692 css::uno::UNO_QUERY
);
695 sal_Bool bVisible
= sal_False
;
696 if (xNode
->getPropertyValue(PROPERTY_VISIBLE
) >>= bVisible
)
698 eState
= bVisible
? STATE_TRUE
: STATE_FALSE
;
702 catch(const css::uno::Exception
& ex
)
704 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
710 //*****************************************************************************************************************
711 void SvtViewOptionsBase_Impl::SetVisible( const ::rtl::OUString
& sName
,
714 #ifdef DEBUG_VIEWOPTIONS
720 css::uno::Reference
< css::beans::XPropertySet
> xNode(
721 impl_getSetNode(sName
, sal_True
),
722 css::uno::UNO_QUERY_THROW
);
723 xNode
->setPropertyValue(PROPERTY_VISIBLE
, css::uno::makeAny(bVisible
));
724 ::comphelper::ConfigurationHelper::flush(m_xRoot
);
726 catch(const css::uno::Exception
& ex
)
728 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
732 /*-************************************************************************************************************//**
733 @short create new set node with default values on disk
734 @descr To create a new UserData item - the super node of these property must already exist!
735 You can call this method to create these new entry with default values and change UserData then.
737 @seealso method impl_writeDirectProp()
739 @param "sNode", name of new entry
741 *//*-*************************************************************************************************************/
742 css::uno::Reference
< css::uno::XInterface
> SvtViewOptionsBase_Impl::impl_getSetNode( const ::rtl::OUString
& sNode
,
743 sal_Bool bCreateIfMissing
)
745 css::uno::Reference
< css::uno::XInterface
> xNode
;
749 if (bCreateIfMissing
)
750 xNode
= ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot
, m_sListName
, sNode
);
753 if (m_xSet
.is() && m_xSet
->hasByName(sNode
) )
754 m_xSet
->getByName(sNode
) >>= xNode
;
757 catch(const css::container::NoSuchElementException
&)
759 catch(const css::uno::Exception
& ex
)
762 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex
)
768 //*****************************************************************************************************************
770 //*****************************************************************************************************************
771 SvtViewOptions::SvtViewOptions( EViewType eType
,
772 const ::rtl::OUString
& sViewName
)
773 : m_eViewType ( eType
)
774 , m_sViewName ( sViewName
)
776 // Global access, must be guarded (multithreading!)
777 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
779 // Search for right dat container for this view type and initialize right data container or set right ref count!
783 // Increase ref count for dialog data container first.
784 ++m_nRefCount_Dialogs
;
785 // If these instance the first user of the dialog data container - create these impl static container!
786 if( m_nRefCount_Dialogs
== 1 )
788 //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
789 m_pDataContainer_Dialogs
= new SvtViewOptionsBase_Impl( LIST_DIALOGS
);
790 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG
);
795 // Increase ref count for tab-dialog data container first.
796 ++m_nRefCount_TabDialogs
;
797 // If these instance the first user of the tab-dialog data container - create these impl static container!
798 if( m_nRefCount_TabDialogs
== 1 )
800 m_pDataContainer_TabDialogs
= new SvtViewOptionsBase_Impl( LIST_TABDIALOGS
);
801 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG
);
806 // Increase ref count for tab-page data container first.
807 ++m_nRefCount_TabPages
;
808 // If these instance the first user of the tab-page data container - create these impl static container!
809 if( m_nRefCount_TabPages
== 1 )
811 m_pDataContainer_TabPages
= new SvtViewOptionsBase_Impl( LIST_TABPAGES
);
812 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE
);
817 // Increase ref count for window data container first.
818 ++m_nRefCount_Windows
;
819 // If these instance the first user of the window data container - create these impl static container!
820 if( m_nRefCount_Windows
== 1 )
822 m_pDataContainer_Windows
= new SvtViewOptionsBase_Impl( LIST_WINDOWS
);
823 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW
);
827 default : OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
831 //*****************************************************************************************************************
833 //*****************************************************************************************************************
834 SvtViewOptions::~SvtViewOptions()
836 // Global access, must be guarded (multithreading!)
837 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
839 // Search for right dat container for this view type and deinitialize right data container or set right ref count!
840 switch( m_eViewType
)
843 // Decrease ref count for dialog data container first.
844 --m_nRefCount_Dialogs
;
845 // If these instance the last user of the dialog data container - delete these impl static container!
846 if( m_nRefCount_Dialogs
== 0 )
848 delete m_pDataContainer_Dialogs
;
849 m_pDataContainer_Dialogs
= NULL
;
854 // Decrease ref count for tab-dialog data container first.
855 --m_nRefCount_TabDialogs
;
856 // If these instance the last user of the tab-dialog data container - delete these impl static container!
857 if( m_nRefCount_TabDialogs
== 0 )
859 delete m_pDataContainer_TabDialogs
;
860 m_pDataContainer_TabDialogs
= NULL
;
865 // Decrease ref count for tab-page data container first.
866 --m_nRefCount_TabPages
;
867 // If these instance the last user of the tab-page data container - delete these impl static container!
868 if( m_nRefCount_TabPages
== 0 )
870 delete m_pDataContainer_TabPages
;
871 m_pDataContainer_TabPages
= NULL
;
876 // Decrease ref count for window data container first.
877 --m_nRefCount_Windows
;
878 // If these instance the last user of the window data container - delete these impl static container!
879 if( m_nRefCount_Windows
== 0 )
881 delete m_pDataContainer_Windows
;
882 m_pDataContainer_Windows
= NULL
;
889 //*****************************************************************************************************************
891 //*****************************************************************************************************************
892 sal_Bool
SvtViewOptions::Exists() const
894 // Ready for multithreading
895 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
897 sal_Bool bExists
= sal_False
;
898 switch( m_eViewType
)
901 bExists
= m_pDataContainer_Dialogs
->Exists( m_sViewName
);
905 bExists
= m_pDataContainer_TabDialogs
->Exists( m_sViewName
);
909 bExists
= m_pDataContainer_TabPages
->Exists( m_sViewName
);
913 bExists
= m_pDataContainer_Windows
->Exists( m_sViewName
);
920 //*****************************************************************************************************************
922 //*****************************************************************************************************************
923 sal_Bool
SvtViewOptions::Delete()
925 // Ready for multithreading
926 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
928 sal_Bool bState
= sal_False
;
929 switch( m_eViewType
)
932 bState
= m_pDataContainer_Dialogs
->Delete( m_sViewName
);
936 bState
= m_pDataContainer_TabDialogs
->Delete( m_sViewName
);
940 bState
= m_pDataContainer_TabPages
->Delete( m_sViewName
);
944 bState
= m_pDataContainer_Windows
->Delete( m_sViewName
);
951 //*****************************************************************************************************************
953 //*****************************************************************************************************************
954 ::rtl::OUString
SvtViewOptions::GetWindowState() const
956 // Ready for multithreading
957 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
959 ::rtl::OUString sState
;
960 switch( m_eViewType
)
963 sState
= m_pDataContainer_Dialogs
->GetWindowState( m_sViewName
);
967 sState
= m_pDataContainer_TabDialogs
->GetWindowState( m_sViewName
);
971 sState
= m_pDataContainer_TabPages
->GetWindowState( m_sViewName
);
975 sState
= m_pDataContainer_Windows
->GetWindowState( m_sViewName
);
982 //*****************************************************************************************************************
984 //*****************************************************************************************************************
985 void SvtViewOptions::SetWindowState( const ::rtl::OUString
& sState
)
987 // Ready for multithreading
988 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
990 switch( m_eViewType
)
993 m_pDataContainer_Dialogs
->SetWindowState( m_sViewName
, sState
);
997 m_pDataContainer_TabDialogs
->SetWindowState( m_sViewName
, sState
);
1001 m_pDataContainer_TabPages
->SetWindowState( m_sViewName
, sState
);
1005 m_pDataContainer_Windows
->SetWindowState( m_sViewName
, sState
);
1011 //*****************************************************************************************************************
1013 //*****************************************************************************************************************
1014 sal_Int32
SvtViewOptions::GetPageID() const
1016 // Ready for multithreading
1017 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1019 // Safe impossible cases.
1020 // These call isn't allowed for dialogs, tab-pages or windows!
1021 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" );
1024 if( m_eViewType
== E_TABDIALOG
)
1025 nID
= m_pDataContainer_TabDialogs
->GetPageID( m_sViewName
);
1029 //*****************************************************************************************************************
1031 //*****************************************************************************************************************
1032 void SvtViewOptions::SetPageID( sal_Int32 nID
)
1034 // Ready for multithreading
1035 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1037 // Safe impossible cases.
1038 // These call isn't allowed for dialogs, tab-pages or windows!
1039 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" );
1041 if( m_eViewType
== E_TABDIALOG
)
1042 m_pDataContainer_TabDialogs
->SetPageID( m_sViewName
, nID
);
1045 //*****************************************************************************************************************
1047 //*****************************************************************************************************************
1048 sal_Bool
SvtViewOptions::IsVisible() const
1050 // Ready for multithreading
1051 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1053 // Safe impossible cases.
1054 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1055 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" );
1057 sal_Bool bState
= sal_False
;
1058 if( m_eViewType
== E_WINDOW
)
1059 bState
= m_pDataContainer_Windows
->GetVisible( m_sViewName
) == SvtViewOptionsBase_Impl::STATE_TRUE
;
1064 //*****************************************************************************************************************
1066 //*****************************************************************************************************************
1067 void SvtViewOptions::SetVisible( sal_Bool bState
)
1069 // Ready for multithreading
1070 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1072 // Safe impossible cases.
1073 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1074 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" );
1076 if( m_eViewType
== E_WINDOW
)
1077 m_pDataContainer_Windows
->SetVisible( m_sViewName
, bState
);
1080 //*****************************************************************************************************************
1082 //*****************************************************************************************************************
1083 bool SvtViewOptions::HasVisible() const
1085 // Ready for multithreading
1086 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1088 // Safe impossible cases.
1089 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1090 OSL_ENSURE( !(m_eViewType
==E_DIALOG
||m_eViewType
==E_TABDIALOG
||m_eViewType
==E_TABPAGE
), "SvtViewOptions::IsVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
1092 bool bState
= false;
1093 if( m_eViewType
== E_WINDOW
)
1094 bState
= m_pDataContainer_Windows
->GetVisible( m_sViewName
) != SvtViewOptionsBase_Impl::STATE_NONE
;
1099 //*****************************************************************************************************************
1100 css::uno::Sequence
< css::beans::NamedValue
> SvtViewOptions::GetUserData() const
1102 // Ready for multithreading
1103 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1105 css::uno::Sequence
< css::beans::NamedValue
> lData
;
1106 switch( m_eViewType
)
1109 lData
= m_pDataContainer_Dialogs
->GetUserData( m_sViewName
);
1112 case E_TABDIALOG
: {
1113 lData
= m_pDataContainer_TabDialogs
->GetUserData( m_sViewName
);
1117 lData
= m_pDataContainer_TabPages
->GetUserData( m_sViewName
);
1121 lData
= m_pDataContainer_Windows
->GetUserData( m_sViewName
);
1128 //*****************************************************************************************************************
1129 void SvtViewOptions::SetUserData( const css::uno::Sequence
< css::beans::NamedValue
>& lData
)
1131 // Ready for multithreading
1132 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1134 switch( m_eViewType
)
1137 m_pDataContainer_Dialogs
->SetUserData( m_sViewName
, lData
);
1140 case E_TABDIALOG
: {
1141 m_pDataContainer_TabDialogs
->SetUserData( m_sViewName
, lData
);
1145 m_pDataContainer_TabPages
->SetUserData( m_sViewName
, lData
);
1149 m_pDataContainer_Windows
->SetUserData( m_sViewName
, lData
);
1155 //*****************************************************************************************************************
1156 css::uno::Any
SvtViewOptions::GetUserItem( const ::rtl::OUString
& sName
) const
1158 // Ready for multithreading
1159 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1161 css::uno::Any aItem
;
1162 switch( m_eViewType
)
1165 aItem
= m_pDataContainer_Dialogs
->GetUserItem( m_sViewName
, sName
);
1168 case E_TABDIALOG
: {
1169 aItem
= m_pDataContainer_TabDialogs
->GetUserItem( m_sViewName
, sName
);
1173 aItem
= m_pDataContainer_TabPages
->GetUserItem( m_sViewName
, sName
);
1177 aItem
= m_pDataContainer_Windows
->GetUserItem( m_sViewName
, sName
);
1184 //*****************************************************************************************************************
1185 void SvtViewOptions::SetUserItem( const ::rtl::OUString
& sName
,
1186 const css::uno::Any
& aValue
)
1188 // Ready for multithreading
1189 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1191 switch( m_eViewType
)
1194 m_pDataContainer_Dialogs
->SetUserItem( m_sViewName
, sName
, aValue
);
1197 case E_TABDIALOG
: {
1198 m_pDataContainer_TabDialogs
->SetUserItem( m_sViewName
, sName
, aValue
);
1202 m_pDataContainer_TabPages
->SetUserItem( m_sViewName
, sName
, aValue
);
1206 m_pDataContainer_Windows
->SetUserItem( m_sViewName
, sName
, aValue
);
1214 class theViewOptionsMutex
: public rtl::Static
<osl::Mutex
, theViewOptionsMutex
>{};
1217 //*****************************************************************************************************************
1219 //*****************************************************************************************************************
1220 ::osl::Mutex
& SvtViewOptions::GetOwnStaticMutex()
1222 return theViewOptionsMutex::get();
1225 void SvtViewOptions::AcquireOptions()
1227 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1228 if( ++m_nRefCount_Dialogs
== 1 )
1230 m_pDataContainer_Dialogs
= new SvtViewOptionsBase_Impl( LIST_DIALOGS
);
1231 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG
);
1233 if( ++m_nRefCount_TabDialogs
== 1 )
1235 m_pDataContainer_TabDialogs
= new SvtViewOptionsBase_Impl( LIST_TABDIALOGS
);
1236 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG
);
1238 if( ++m_nRefCount_TabPages
== 1 )
1240 m_pDataContainer_TabPages
= new SvtViewOptionsBase_Impl( LIST_TABPAGES
);
1241 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE
);
1243 if( ++m_nRefCount_Windows
== 1 )
1245 m_pDataContainer_Windows
= new SvtViewOptionsBase_Impl( LIST_WINDOWS
);
1246 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW
);
1250 void SvtViewOptions::ReleaseOptions()
1252 ::osl::MutexGuard
aGuard( GetOwnStaticMutex() );
1253 if( --m_nRefCount_Dialogs
== 0 )
1255 delete m_pDataContainer_Dialogs
;
1256 m_pDataContainer_Dialogs
= NULL
;
1258 if( --m_nRefCount_TabDialogs
== 0 )
1260 delete m_pDataContainer_TabDialogs
;
1261 m_pDataContainer_TabDialogs
= NULL
;
1263 if( --m_nRefCount_TabPages
== 0 )
1265 delete m_pDataContainer_TabPages
;
1266 m_pDataContainer_TabPages
= NULL
;
1268 if( --m_nRefCount_Windows
== 0 )
1270 delete m_pDataContainer_Windows
;
1271 m_pDataContainer_Windows
= NULL
;
1275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */