bump product version to 4.1.6.2
[LibreOffice.git] / unotools / source / config / viewoptions.cxx
blobc13aa414a5e7fbf6ce871839d34d7c13df341edb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_ ) \
56 { \
57 FILE* pFile = fopen( "viewdbg.txt", "a" ); \
58 fprintf( pFile, "%s[%d, %d]\n", OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
59 fclose( pFile ); \
61 #endif // DEBUG_VIEWOPTIONS
63 #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION) \
64 { \
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 //_________________________________________________________________________________________________________________
72 // initialization!
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 *//*-*************************************************************************************************************/
102 class IMPL_TViewData
104 public:
105 //---------------------------------------------------------------------------------------------------------
106 // create "default" item
107 IMPL_TViewData()
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 )
121 m_bDefault = (
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 )
131 m_bDefault = (
132 ( m_bDefault == sal_True ) &&
133 ( lValue == DEFAULT_USERDATA )
135 m_lUserData = lValue;
138 //---------------------------------------------------------------------------------------------------------
139 void setPageID( sal_Int32 nValue )
141 m_bDefault = (
142 ( m_bDefault == sal_True ) &&
143 ( nValue == DEFAULT_PAGEID )
145 m_nPageID = nValue;
148 //---------------------------------------------------------------------------------------------------------
149 void setVisible( sal_Bool bValue )
151 m_bDefault = (
152 ( m_bDefault == sal_True ) &&
153 ( bValue == DEFAULT_VISIBLE )
155 m_bVisible = bValue;
158 //---------------------------------------------------------------------------------------------------------
159 // read access
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 ;
184 bExist = sal_True;
185 break;
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;
210 break;
213 return aValue;
216 //---------------------------------------------------------------------------------------------------------
217 // check for default items
218 sal_Bool isDefault() { return m_bDefault; }
220 private:
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 ,
238 IMPL_TViewData ,
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
246 have it realy.
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 //-------------------------------------------------------------------------------------------------------------
256 public:
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 ,
271 sal_Int32 nID );
272 State GetVisible ( const OUString& sName );
273 void SetVisible ( const OUString& sName ,
274 sal_Bool bVisible );
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 //-------------------------------------------------------------------------------------------------------------
282 private:
283 css::uno::Reference< css::uno::XInterface > impl_getSetNode( const OUString& sNode ,
284 sal_Bool bCreateIfMissing);
286 //-------------------------------------------------------------------------------------------------------------
287 private:
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 ;
295 #endif
298 /*-************************************************************************************************************//**
299 @descr Implement the base data container.
300 *//*-*************************************************************************************************************/
302 /*-************************************************************************************************************//**
303 @short ctor
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()
312 @param -
313 @return -
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
318 , m_nReadCount ( 0 )
319 , m_nWriteCount( 0 )
320 #endif
324 m_xRoot = css::uno::Reference< css::container::XNameAccess >(
325 ::comphelper::ConfigurationHelper::openConfig(
326 ::comphelper::getProcessComponentContext(),
327 PACKAGE_VIEWS,
328 ::comphelper::ConfigurationHelper::E_STANDARD),
329 css::uno::UNO_QUERY);
330 if (m_xRoot.is())
331 m_xRoot->getByName(sList) >>= m_xSet;
333 catch(const css::uno::Exception& ex)
335 m_xRoot.clear();
336 m_xSet.clear();
338 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
342 /*-************************************************************************************************************//**
343 @short dtor
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()
354 @param -
355 @return -
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.
363 m_xRoot.clear();
364 m_xSet.clear();
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
379 false, otherwise
380 *//*-*************************************************************************************************************/
381 sal_Bool SvtViewOptionsBase_Impl::Exists( const OUString& sName )
383 sal_Bool bExists = sal_False;
387 if (m_xSet.is())
388 bExists = m_xSet->hasByName(sName);
390 catch(const css::uno::Exception& ex)
392 bExists = sal_False;
393 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
396 return bExists;
399 /*-************************************************************************************************************//**
400 @short delete entry
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!)
407 false, otherwise
408 *//*-*************************************************************************************************************/
409 sal_Bool SvtViewOptionsBase_Impl::Delete( const OUString& sName )
411 #ifdef DEBUG_VIEWOPTIONS
412 ++m_nWriteCount;
413 #endif
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);
420 bDeleted = sal_True;
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)
431 return bDeleted;
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
440 @param -
441 @return -
442 *//*-*************************************************************************************************************/
443 OUString SvtViewOptionsBase_Impl::GetWindowState( const OUString& sName )
445 #ifdef DEBUG_VIEWOPTIONS
446 ++m_nReadCount;
447 #endif
449 OUString sWindowState;
452 css::uno::Reference< css::beans::XPropertySet > xNode(
453 impl_getSetNode(sName, sal_False),
454 css::uno::UNO_QUERY);
455 if (xNode.is())
456 xNode->getPropertyValue(PROPERTY_WINDOWSTATE) >>= sWindowState;
458 catch(const css::uno::Exception& ex)
460 sWindowState = OUString();
461 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
464 return sWindowState;
467 //*****************************************************************************************************************
468 void SvtViewOptionsBase_Impl::SetWindowState( const OUString& sName ,
469 const OUString& sState )
471 #ifdef DEBUG_VIEWOPTIONS
472 ++m_nWriteCount;
473 #endif
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
493 ++m_nReadCount;
494 #endif
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;
502 if (xNode.is())
503 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
504 if (xUserData.is())
506 const css::uno::Sequence< OUString > lNames = xUserData->getElementNames();
507 const OUString* pNames = lNames.getConstArray();
508 sal_Int32 c = lNames.getLength();
509 sal_Int32 i = 0;
510 css::uno::Sequence< css::beans::NamedValue > lUserData(c);
512 for (i=0; i<c; ++i)
514 lUserData[i].Name = pNames[i];
515 lUserData[i].Value = xUserData->getByName(pNames[i]);
518 return lUserData;
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
534 ++m_nWriteCount;
535 #endif
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;
544 if (xUserData.is())
546 const css::beans::NamedValue* pData = lData.getConstArray();
547 sal_Int32 c = lData.getLength();
548 sal_Int32 i = 0;
549 for (i=0; i<c; ++i)
551 if (xUserData->hasByName(pData[i].Name))
552 xUserData->replaceByName(pData[i].Name, pData[i].Value);
553 else
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
570 ++m_nReadCount;
571 #endif
573 css::uno::Any aItem;
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;
580 if (xNode.is())
581 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
582 if (xUserData.is())
583 aItem = xUserData->getByName(sItem);
585 catch(const css::container::NoSuchElementException&)
586 { aItem.clear(); }
587 catch(const css::uno::Exception& ex)
589 aItem.clear();
590 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
593 return aItem;
596 //*****************************************************************************************************************
597 void SvtViewOptionsBase_Impl::SetUserItem( const OUString& sName ,
598 const OUString& sItem ,
599 const css::uno::Any& aValue )
601 #ifdef DEBUG_VIEWOPTIONS
602 ++m_nWriteCount;
603 #endif
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;
612 if (xUserData.is())
614 if (xUserData->hasByName(sItem))
615 xUserData->replaceByName(sItem, aValue);
616 else
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
631 ++m_nReadCount;
632 #endif
634 sal_Int32 nID = 0;
637 css::uno::Reference< css::beans::XPropertySet > xNode(
638 impl_getSetNode(sName, sal_False),
639 css::uno::UNO_QUERY);
640 if (xNode.is())
641 xNode->getPropertyValue(PROPERTY_PAGEID) >>= nID;
643 catch(const css::uno::Exception& ex)
645 nID = 0;
646 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
649 return nID;
652 //*****************************************************************************************************************
653 void SvtViewOptionsBase_Impl::SetPageID( const OUString& sName ,
654 sal_Int32 nID )
656 #ifdef DEBUG_VIEWOPTIONS
657 ++m_nWriteCount;
658 #endif
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
678 ++m_nReadCount;
679 #endif
681 State eState = STATE_NONE;
684 css::uno::Reference< css::beans::XPropertySet > xNode(
685 impl_getSetNode(sName, sal_False),
686 css::uno::UNO_QUERY);
687 if (xNode.is())
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)
701 return eState;
704 //*****************************************************************************************************************
705 void SvtViewOptionsBase_Impl::SetVisible( const OUString& sName ,
706 sal_Bool bVisible )
708 #ifdef DEBUG_VIEWOPTIONS
709 ++m_nWriteCount;
710 #endif
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
734 @return -
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);
745 else
747 if (m_xSet.is() && m_xSet->hasByName(sNode) )
748 m_xSet->getByName(sNode) >>= xNode;
751 catch(const css::container::NoSuchElementException&)
752 { xNode.clear(); }
753 catch(const css::uno::Exception& ex)
755 xNode.clear();
756 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
759 return xNode;
762 //*****************************************************************************************************************
763 // constructor
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!
774 switch( eType )
776 case E_DIALOG : {
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);
787 break;
788 case E_TABDIALOG : {
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);
798 break;
799 case E_TABPAGE : {
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);
809 break;
810 case E_WINDOW : {
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);
820 break;
821 default : OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
825 //*****************************************************************************************************************
826 // destructor
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 )
836 case E_DIALOG : {
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;
846 break;
847 case E_TABDIALOG : {
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;
857 break;
858 case E_TABPAGE : {
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;
868 break;
869 case E_WINDOW : {
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;
879 break;
883 //*****************************************************************************************************************
884 // public method
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 )
894 case E_DIALOG : {
895 bExists = m_pDataContainer_Dialogs->Exists( m_sViewName );
897 break;
898 case E_TABDIALOG : {
899 bExists = m_pDataContainer_TabDialogs->Exists( m_sViewName );
901 break;
902 case E_TABPAGE : {
903 bExists = m_pDataContainer_TabPages->Exists( m_sViewName );
905 break;
906 case E_WINDOW : {
907 bExists = m_pDataContainer_Windows->Exists( m_sViewName );
909 break;
911 return bExists;
914 //*****************************************************************************************************************
915 // public method
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 )
925 case E_DIALOG : {
926 bState = m_pDataContainer_Dialogs->Delete( m_sViewName );
928 break;
929 case E_TABDIALOG : {
930 bState = m_pDataContainer_TabDialogs->Delete( m_sViewName );
932 break;
933 case E_TABPAGE : {
934 bState = m_pDataContainer_TabPages->Delete( m_sViewName );
936 break;
937 case E_WINDOW : {
938 bState = m_pDataContainer_Windows->Delete( m_sViewName );
940 break;
942 return bState;
945 //*****************************************************************************************************************
946 // public method
947 //*****************************************************************************************************************
948 OUString SvtViewOptions::GetWindowState() const
950 // Ready for multithreading
951 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
953 OUString sState;
954 switch( m_eViewType )
956 case E_DIALOG : {
957 sState = m_pDataContainer_Dialogs->GetWindowState( m_sViewName );
959 break;
960 case E_TABDIALOG : {
961 sState = m_pDataContainer_TabDialogs->GetWindowState( m_sViewName );
963 break;
964 case E_TABPAGE : {
965 sState = m_pDataContainer_TabPages->GetWindowState( m_sViewName );
967 break;
968 case E_WINDOW : {
969 sState = m_pDataContainer_Windows->GetWindowState( m_sViewName );
971 break;
973 return sState;
976 //*****************************************************************************************************************
977 // public method
978 //*****************************************************************************************************************
979 void SvtViewOptions::SetWindowState( const OUString& sState )
981 // Ready for multithreading
982 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
984 switch( m_eViewType )
986 case E_DIALOG : {
987 m_pDataContainer_Dialogs->SetWindowState( m_sViewName, sState );
989 break;
990 case E_TABDIALOG : {
991 m_pDataContainer_TabDialogs->SetWindowState( m_sViewName, sState );
993 break;
994 case E_TABPAGE : {
995 m_pDataContainer_TabPages->SetWindowState( m_sViewName, sState );
997 break;
998 case E_WINDOW : {
999 m_pDataContainer_Windows->SetWindowState( m_sViewName, sState );
1001 break;
1005 //*****************************************************************************************************************
1006 // public method
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" );
1017 sal_Int32 nID = 0;
1018 if( m_eViewType == E_TABDIALOG )
1019 nID = m_pDataContainer_TabDialogs->GetPageID( m_sViewName );
1020 return nID;
1023 //*****************************************************************************************************************
1024 // public method
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 //*****************************************************************************************************************
1040 // public method
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;
1055 return bState;
1058 //*****************************************************************************************************************
1059 // public method
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 //*****************************************************************************************************************
1075 // public method
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;
1090 return bState;
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 )
1102 case E_DIALOG : {
1103 lData = m_pDataContainer_Dialogs->GetUserData( m_sViewName );
1105 break;
1106 case E_TABDIALOG : {
1107 lData = m_pDataContainer_TabDialogs->GetUserData( m_sViewName );
1109 break;
1110 case E_TABPAGE : {
1111 lData = m_pDataContainer_TabPages->GetUserData( m_sViewName );
1113 break;
1114 case E_WINDOW : {
1115 lData = m_pDataContainer_Windows->GetUserData( m_sViewName );
1117 break;
1119 return lData;
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 )
1130 case E_DIALOG : {
1131 m_pDataContainer_Dialogs->SetUserData( m_sViewName, lData );
1133 break;
1134 case E_TABDIALOG : {
1135 m_pDataContainer_TabDialogs->SetUserData( m_sViewName, lData );
1137 break;
1138 case E_TABPAGE : {
1139 m_pDataContainer_TabPages->SetUserData( m_sViewName, lData );
1141 break;
1142 case E_WINDOW : {
1143 m_pDataContainer_Windows->SetUserData( m_sViewName, lData );
1145 break;
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 )
1158 case E_DIALOG : {
1159 aItem = m_pDataContainer_Dialogs->GetUserItem( m_sViewName, sName );
1161 break;
1162 case E_TABDIALOG : {
1163 aItem = m_pDataContainer_TabDialogs->GetUserItem( m_sViewName, sName );
1165 break;
1166 case E_TABPAGE : {
1167 aItem = m_pDataContainer_TabPages->GetUserItem( m_sViewName, sName );
1169 break;
1170 case E_WINDOW : {
1171 aItem = m_pDataContainer_Windows->GetUserItem( m_sViewName, sName );
1173 break;
1175 return aItem;
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 )
1187 case E_DIALOG : {
1188 m_pDataContainer_Dialogs->SetUserItem( m_sViewName, sName, aValue );
1190 break;
1191 case E_TABDIALOG : {
1192 m_pDataContainer_TabDialogs->SetUserItem( m_sViewName, sName, aValue );
1194 break;
1195 case E_TABPAGE : {
1196 m_pDataContainer_TabPages->SetUserItem( m_sViewName, sName, aValue );
1198 break;
1199 case E_WINDOW : {
1200 m_pDataContainer_Windows->SetUserItem( m_sViewName, sName, aValue );
1202 break;
1206 namespace
1208 class theViewOptionsMutex : public rtl::Static<osl::Mutex, theViewOptionsMutex>{};
1211 //*****************************************************************************************************************
1212 // private method
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: */