merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / viewoptions.cxx
blob4bf630be574e2405f3106fc1a13e9ac36533ce51
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewoptions.cxx,v $
10 * $Revision: 1.29.236.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 //_________________________________________________________________________________________________________________
34 // includes
35 //_________________________________________________________________________________________________________________
37 #include <svtools/viewoptions.hxx>
38 #include <com/sun/star/uno/Any.hxx>
40 #include <hash_map>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/container/XNameContainer.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <rtl/ustrbuf.hxx>
46 #include <unotools/configpathes.hxx>
47 #include <comphelper/configurationhelper.hxx>
48 #include <unotools/processfactory.hxx>
50 #include <itemholder1.hxx>
52 //_________________________________________________________________________________________________________________
53 // namespaces
54 //_________________________________________________________________________________________________________________
56 namespace css = ::com::sun::star;
58 //_________________________________________________________________________________________________________________
59 // const
60 //_________________________________________________________________________________________________________________
62 #ifdef CONST_ASCII
63 #error "Who define CONST_ASCII before! I use it to create const ascii strings ..."
64 #else
65 #define CONST_ASCII(SASCIIVALUE) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SASCIIVALUE))
66 #endif
68 #define PATHSEPERATOR CONST_ASCII("/")
70 #define PACKAGE_VIEWS CONST_ASCII("org.openoffice.Office.Views")
72 #define LIST_DIALOGS CONST_ASCII("Dialogs" )
73 #define LIST_TABDIALOGS CONST_ASCII("TabDialogs")
74 #define LIST_TABPAGES CONST_ASCII("TabPages" )
75 #define LIST_WINDOWS CONST_ASCII("Windows" )
77 #define PROPERTY_WINDOWSTATE CONST_ASCII("WindowState")
78 #define PROPERTY_PAGEID CONST_ASCII("PageID" )
79 #define PROPERTY_VISIBLE CONST_ASCII("Visible" )
80 #define PROPERTY_USERDATA CONST_ASCII("UserData" )
82 #define PROPCOUNT_DIALOGS 1
83 #define PROPCOUNT_TABDIALOGS 2
84 #define PROPCOUNT_TABPAGES 1
85 #define PROPCOUNT_WINDOWS 2
87 #define DEFAULT_WINDOWSTATE ::rtl::OUString()
88 #define DEFAULT_USERDATA css::uno::Sequence< css::beans::NamedValue >()
89 #define DEFAULT_PAGEID 0
90 #define DEFAULT_VISIBLE sal_False
92 //#define DEBUG_VIEWOPTIONS
94 #ifdef DEBUG_VIEWOPTIONS
95 #define _LOG_COUNTER_( _SVIEW_, _NREAD_, _NWRITE_ ) \
96 { \
97 FILE* pFile = fopen( "viewdbg.txt", "a" ); \
98 fprintf( pFile, "%s[%d, %d]\n", ::rtl::OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
99 fclose( pFile ); \
101 #endif // DEBUG_VIEWOPTIONS
103 #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION) \
105 ::rtl::OUStringBuffer sMsg(256); \
106 sMsg.appendAscii("Unexpected exception catched. Original message was:\n\"" ); \
107 sMsg.append (SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION.Message); \
108 sMsg.appendAscii("\"" ); \
109 OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr()); \
112 //_________________________________________________________________________________________________________________
113 // initialization!
114 //_________________________________________________________________________________________________________________
116 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_Dialogs = NULL ;
117 sal_Int32 SvtViewOptions::m_nRefCount_Dialogs = 0 ;
118 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_TabDialogs = NULL ;
119 sal_Int32 SvtViewOptions::m_nRefCount_TabDialogs = 0 ;
120 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_TabPages = NULL ;
121 sal_Int32 SvtViewOptions::m_nRefCount_TabPages = 0 ;
122 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_Windows = NULL ;
123 sal_Int32 SvtViewOptions::m_nRefCount_Windows = 0 ;
125 //_________________________________________________________________________________________________________________
126 // private declarations!
127 //_________________________________________________________________________________________________________________
129 /*-************************************************************************************************************//**
130 @descr declare one configuration item
131 These struct hold information about one view item. But not all member are used for all entries!
132 User must decide which information are usefull and which not. We are a container iztem only and doesnt
133 know anything about the context.
134 But; we support a feature:
135 decision between items with default values (should not realy exist in configuration!)
136 and items with real values - changed by user. So user can suppress saving of realy unused items
137 to disk - because; defaulted items could be restored on runtime without reading from disk!!!
138 And if only items with valid information was written to cfg - we mustn't read so much and save time.
139 So we start with an member m_bDefault=True and reset it to False after first set-call.
140 Deficiencies of these solution - we cant allow direct read/write access to our member. We must
141 support it by set/get-methods ...
142 *//*-*************************************************************************************************************/
143 class IMPL_TViewData
145 public:
146 //---------------------------------------------------------------------------------------------------------
147 // create "default" item
148 IMPL_TViewData()
150 m_sWindowState = DEFAULT_WINDOWSTATE ;
151 m_lUserData = DEFAULT_USERDATA ;
152 m_nPageID = DEFAULT_PAGEID ;
153 m_bVisible = DEFAULT_VISIBLE ;
155 m_bDefault = sal_True ;
158 //---------------------------------------------------------------------------------------------------------
159 // write access - with reseting of default state
160 void setWindowState( const ::rtl::OUString& sValue )
162 m_bDefault = (
163 ( m_bDefault == sal_True ) &&
164 ( sValue == DEFAULT_WINDOWSTATE )
166 m_sWindowState = sValue;
169 //---------------------------------------------------------------------------------------------------------
170 void setUserData( const css::uno::Sequence< css::beans::NamedValue >& lValue )
172 m_bDefault = (
173 ( m_bDefault == sal_True ) &&
174 ( lValue == DEFAULT_USERDATA )
176 m_lUserData = lValue;
179 //---------------------------------------------------------------------------------------------------------
180 void setPageID( sal_Int32 nValue )
182 m_bDefault = (
183 ( m_bDefault == sal_True ) &&
184 ( nValue == DEFAULT_PAGEID )
186 m_nPageID = nValue;
189 //---------------------------------------------------------------------------------------------------------
190 void setVisible( sal_Bool bValue )
192 m_bDefault = (
193 ( m_bDefault == sal_True ) &&
194 ( bValue == DEFAULT_VISIBLE )
196 m_bVisible = bValue;
199 //---------------------------------------------------------------------------------------------------------
200 // read access
201 ::rtl::OUString getWindowState() { return m_sWindowState; }
202 css::uno::Sequence< css::beans::NamedValue > getUserData () { return m_lUserData ; }
203 sal_Int32 getPageID () { return m_nPageID ; }
204 sal_Bool getVisible () { return m_bVisible ; }
206 //---------------------------------------------------------------------------------------------------------
207 // special operation for easy access on user data
208 void setUserItem( const ::rtl::OUString& sName ,
209 const css::uno::Any& aValue )
211 // we change UserData in every case!
212 // a) we change already existing item
213 // or b) we add a new one
214 m_bDefault = sal_False;
216 sal_Bool bExist = sal_False;
217 sal_Int32 nCount = m_lUserData.getLength();
219 // change it, if it already exist ...
220 for( sal_Int32 nStep=0; nStep<nCount; ++nStep )
222 if( m_lUserData[nStep].Name == sName )
224 m_lUserData[nStep].Value = aValue ;
225 bExist = sal_True;
226 break;
230 // ... or create new list item
231 if( bExist == sal_False )
233 m_lUserData.realloc( nCount+1 );
234 m_lUserData[nCount].Name = sName ;
235 m_lUserData[nCount].Value = aValue ;
239 //---------------------------------------------------------------------------------------------------------
240 css::uno::Any getUserItem( const ::rtl::OUString& sName )
242 // default value - if item not exist!
243 css::uno::Any aValue;
245 sal_Int32 nCount = m_lUserData.getLength();
246 for( sal_Int32 nStep=0; nStep<nCount; ++nStep )
248 if( m_lUserData[nStep].Name == sName )
250 aValue = m_lUserData[nStep].Value;
251 break;
254 return aValue;
257 //---------------------------------------------------------------------------------------------------------
258 // check for default items
259 sal_Bool isDefault() { return m_bDefault; }
261 private:
262 ::rtl::OUString m_sWindowState ;
263 css::uno::Sequence< css::beans::NamedValue > m_lUserData ;
264 sal_Int32 m_nPageID ;
265 sal_Bool m_bVisible ;
267 sal_Bool m_bDefault ;
270 struct IMPL_TStringHashCode
272 size_t operator()(const ::rtl::OUString& sString) const
274 return sString.hashCode();
278 typedef ::std::hash_map< ::rtl::OUString ,
279 IMPL_TViewData ,
280 IMPL_TStringHashCode ,
281 ::std::equal_to< ::rtl::OUString > > IMPL_TViewHash;
283 /*-************************************************************************************************************//**
284 @descr Implement base data container for view options elements.
285 Every item support ALL possible configuration informations.
286 But not every superclass should use them! Because some view types don't
287 have it realy.
289 @attention We implement a write-througt-cache! We use it for reading - but write all changes directly to
290 configuration. (changes are made on internal cache too!). So it's easier to distinguish
291 between added/changed/removed elements without any complex mask or bool flag informations.
292 Caches from configuration and our own one are synchronized every time - if we do so.
293 *//*-*************************************************************************************************************/
294 class SvtViewOptionsBase_Impl
296 //-------------------------------------------------------------------------------------------------------------
297 public:
298 SvtViewOptionsBase_Impl ( const ::rtl::OUString& sList );
299 virtual ~SvtViewOptionsBase_Impl ( );
300 sal_Bool Exists ( const ::rtl::OUString& sName );
301 sal_Bool Delete ( const ::rtl::OUString& sName );
302 ::rtl::OUString GetWindowState ( const ::rtl::OUString& sName );
303 void SetWindowState ( const ::rtl::OUString& sName ,
304 const ::rtl::OUString& sState );
305 css::uno::Sequence< css::beans::NamedValue > GetUserData ( const ::rtl::OUString& sName );
306 void SetUserData ( const ::rtl::OUString& sName ,
307 const css::uno::Sequence< css::beans::NamedValue >& lData );
308 sal_Int32 GetPageID ( const ::rtl::OUString& sName );
309 void SetPageID ( const ::rtl::OUString& sName ,
310 sal_Int32 nID );
311 sal_Bool GetVisible ( const ::rtl::OUString& sName );
312 void SetVisible ( const ::rtl::OUString& sName ,
313 sal_Bool bVisible );
314 css::uno::Any GetUserItem ( const ::rtl::OUString& sName ,
315 const ::rtl::OUString& sItem );
316 void SetUserItem ( const ::rtl::OUString& sName ,
317 const ::rtl::OUString& sItem ,
318 const css::uno::Any& aValue );
320 //-------------------------------------------------------------------------------------------------------------
321 private:
322 css::uno::Reference< css::uno::XInterface > impl_getSetNode( const ::rtl::OUString& sNode ,
323 sal_Bool bCreateIfMissing);
325 //-------------------------------------------------------------------------------------------------------------
326 private:
327 ::rtl::OUString m_sListName;
328 css::uno::Reference< css::container::XNameAccess > m_xRoot;
329 css::uno::Reference< css::container::XNameAccess > m_xSet;
331 #ifdef DEBUG_VIEWOPTIONS
332 sal_Int32 m_nReadCount ;
333 sal_Int32 m_nWriteCount ;
334 #endif
337 /*-************************************************************************************************************//**
338 @descr Implement the base data container.
339 *//*-*************************************************************************************************************/
341 /*-************************************************************************************************************//**
342 @short ctor
343 @descr We use it to open right configuration file and let configuration objects fill her caches.
344 Then we read all existing entries from right list and cached it inside our object too.
345 Normaly we should enable notifications for changes on these values too ... but these feature
346 isn't full implemented in the moment.
348 @seealso baseclass ::utl::ConfigItem
349 @seealso method Notify()
351 @param -
352 @return -
354 @last change 19.10.2001 07:54
355 *//*-*************************************************************************************************************/
356 SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const ::rtl::OUString& sList )
357 : m_sListName ( sList ) // we must know, which view type we must support
358 #ifdef DEBUG_VIEWOPTIONS
359 , m_nReadCount ( 0 )
360 , m_nWriteCount( 0 )
361 #endif
365 m_xRoot = css::uno::Reference< css::container::XNameAccess >(
366 ::comphelper::ConfigurationHelper::openConfig(
367 ::utl::getProcessServiceFactory(),
368 PACKAGE_VIEWS,
369 ::comphelper::ConfigurationHelper::E_STANDARD),
370 css::uno::UNO_QUERY);
371 if (m_xRoot.is())
372 m_xRoot->getByName(sList) >>= m_xSet;
374 catch(const css::uno::Exception& ex)
376 m_xRoot.clear();
377 m_xSet.clear();
379 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
383 /*-************************************************************************************************************//**
384 @short dtor
385 @descr clean up something
387 @attention We implement a write through cache! So we mustn't do it realy. All changes was written to cfg directly.
388 Commit isn't neccessary then.
390 @seealso baseclass ::utl::ConfigItem
391 @seealso method IsModified()
392 @seealso method SetModified()
393 @seealso method Commit()
395 @param -
396 @return -
398 @last change 19.10.2001 08:02
399 *//*-*************************************************************************************************************/
400 SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
402 // dont flush configuration changes here to m_xRoot.
403 // That must be done inside every SetXXX() method already !
404 // Here its to late - DisposedExceptions from used configuration access can occure otherwise.
406 m_xRoot.clear();
407 m_xSet.clear();
409 #ifdef DEBUG_VIEWOPTIONS
410 _LOG_COUNTER_( m_sListName, m_nReadCount, m_nWriteCount )
411 #endif // DEBUG_VIEWOPTIONS
414 /*-************************************************************************************************************//**
415 @short checks for already existing entries
416 @descr If user don't know, if an entry already exist - he can get this information by calling this method.
418 @seealso member m_aList
420 @param "sName", name of entry to check exist state
421 @return true , if item exist
422 false, otherwise
423 *//*-*************************************************************************************************************/
424 sal_Bool SvtViewOptionsBase_Impl::Exists( const ::rtl::OUString& sName )
426 sal_Bool bExists = sal_False;
430 if (m_xSet.is())
431 bExists = m_xSet->hasByName(sName);
433 catch(const css::uno::Exception& ex)
435 bExists = sal_False;
436 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
439 return bExists;
442 /*-************************************************************************************************************//**
443 @short delete entry
444 @descr Use it to delete set entry by given name.
446 @seealso member m_aList
448 @param "sName", name of entry to delete it
449 @return true , if item not exist(!) or could be deleted (should be the same!)
450 false, otherwise
451 *//*-*************************************************************************************************************/
452 sal_Bool SvtViewOptionsBase_Impl::Delete( const ::rtl::OUString& sName )
454 #ifdef DEBUG_VIEWOPTIONS
455 ++m_nWriteCount;
456 #endif
458 sal_Bool bDeleted = sal_False;
461 css::uno::Reference< css::container::XNameContainer > xSet(m_xSet, css::uno::UNO_QUERY_THROW);
462 xSet->removeByName(sName);
463 bDeleted = sal_True;
464 ::comphelper::ConfigurationHelper::flush(m_xRoot);
466 catch(const css::container::NoSuchElementException&)
467 { bDeleted = sal_True; }
468 catch(const css::uno::Exception& ex)
470 bDeleted = sal_False;
471 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
474 return bDeleted;
477 /*-************************************************************************************************************//**
478 @short read/write access to cache view items and her properties
479 @descr Follow methods support read/write access to all cache view items.
481 @seealso member m_sList
483 @param -
484 @return -
485 *//*-*************************************************************************************************************/
486 ::rtl::OUString SvtViewOptionsBase_Impl::GetWindowState( const ::rtl::OUString& sName )
488 #ifdef DEBUG_VIEWOPTIONS
489 ++m_nReadCount;
490 #endif
492 ::rtl::OUString sWindowState;
495 css::uno::Reference< css::beans::XPropertySet > xNode(
496 impl_getSetNode(sName, sal_False),
497 css::uno::UNO_QUERY);
498 if (xNode.is())
499 xNode->getPropertyValue(PROPERTY_WINDOWSTATE) >>= sWindowState;
501 catch(const css::uno::Exception& ex)
503 sWindowState = ::rtl::OUString();
504 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
507 return sWindowState;
510 //*****************************************************************************************************************
511 void SvtViewOptionsBase_Impl::SetWindowState( const ::rtl::OUString& sName ,
512 const ::rtl::OUString& sState )
514 #ifdef DEBUG_VIEWOPTIONS
515 ++m_nWriteCount;
516 #endif
520 css::uno::Reference< css::beans::XPropertySet > xNode(
521 impl_getSetNode(sName, sal_True),
522 css::uno::UNO_QUERY_THROW);
523 xNode->setPropertyValue(PROPERTY_WINDOWSTATE, css::uno::makeAny(sState));
524 ::comphelper::ConfigurationHelper::flush(m_xRoot);
526 catch(const css::uno::Exception& ex)
528 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
532 //*****************************************************************************************************************
533 css::uno::Sequence< css::beans::NamedValue > SvtViewOptionsBase_Impl::GetUserData( const ::rtl::OUString& sName )
535 #ifdef DEBUG_VIEWOPTIONS
536 ++m_nReadCount;
537 #endif
541 css::uno::Reference< css::container::XNameAccess > xNode(
542 impl_getSetNode(sName, sal_False),
543 css::uno::UNO_QUERY); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
544 css::uno::Reference< css::container::XNameAccess > xUserData;
545 if (xNode.is())
546 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
547 if (xUserData.is())
549 const css::uno::Sequence< ::rtl::OUString > lNames = xUserData->getElementNames();
550 const ::rtl::OUString* pNames = lNames.getConstArray();
551 sal_Int32 c = lNames.getLength();
552 sal_Int32 i = 0;
553 css::uno::Sequence< css::beans::NamedValue > lUserData(c);
555 for (i=0; i<c; ++i)
557 lUserData[i].Name = pNames[i];
558 lUserData[i].Value = xUserData->getByName(pNames[i]);
561 return lUserData;
564 catch(const css::uno::Exception& ex)
566 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
569 return css::uno::Sequence< css::beans::NamedValue >();
572 //*****************************************************************************************************************
573 void SvtViewOptionsBase_Impl::SetUserData( const ::rtl::OUString& sName ,
574 const css::uno::Sequence< css::beans::NamedValue >& lData )
576 #ifdef DEBUG_VIEWOPTIONS
577 ++m_nWriteCount;
578 #endif
582 css::uno::Reference< css::container::XNameAccess > xNode(
583 impl_getSetNode(sName, sal_True),
584 css::uno::UNO_QUERY_THROW);
585 css::uno::Reference< css::container::XNameContainer > xUserData;
586 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
587 if (xUserData.is())
589 const css::beans::NamedValue* pData = lData.getConstArray();
590 sal_Int32 c = lData.getLength();
591 sal_Int32 i = 0;
592 for (i=0; i<c; ++i)
594 if (xUserData->hasByName(pData[i].Name))
595 xUserData->replaceByName(pData[i].Name, pData[i].Value);
596 else
597 xUserData->insertByName(pData[i].Name, pData[i].Value);
600 ::comphelper::ConfigurationHelper::flush(m_xRoot);
602 catch(const css::uno::Exception& ex)
604 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
608 //*****************************************************************************************************************
609 css::uno::Any SvtViewOptionsBase_Impl::GetUserItem( const ::rtl::OUString& sName ,
610 const ::rtl::OUString& sItem )
612 #ifdef DEBUG_VIEWOPTIONS
613 ++m_nReadCount;
614 #endif
616 css::uno::Any aItem;
619 css::uno::Reference< css::container::XNameAccess > xNode(
620 impl_getSetNode(sName, sal_False),
621 css::uno::UNO_QUERY);
622 css::uno::Reference< css::container::XNameAccess > xUserData;
623 if (xNode.is())
624 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
625 if (xUserData.is())
626 aItem = xUserData->getByName(sItem);
628 catch(const css::container::NoSuchElementException&)
629 { aItem.clear(); }
630 catch(const css::uno::Exception& ex)
632 aItem.clear();
633 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
636 return aItem;
639 //*****************************************************************************************************************
640 void SvtViewOptionsBase_Impl::SetUserItem( const ::rtl::OUString& sName ,
641 const ::rtl::OUString& sItem ,
642 const css::uno::Any& aValue )
644 #ifdef DEBUG_VIEWOPTIONS
645 ++m_nWriteCount;
646 #endif
650 css::uno::Reference< css::container::XNameAccess > xNode(
651 impl_getSetNode(sName, sal_True),
652 css::uno::UNO_QUERY_THROW);
653 css::uno::Reference< css::container::XNameContainer > xUserData;
654 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
655 if (xUserData.is())
657 if (xUserData->hasByName(sItem))
658 xUserData->replaceByName(sItem, aValue);
659 else
660 xUserData->insertByName(sItem, aValue);
662 ::comphelper::ConfigurationHelper::flush(m_xRoot);
664 catch(const css::uno::Exception& ex)
666 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
670 //*****************************************************************************************************************
671 sal_Int32 SvtViewOptionsBase_Impl::GetPageID( const ::rtl::OUString& sName )
673 #ifdef DEBUG_VIEWOPTIONS
674 ++m_nReadCount;
675 #endif
677 sal_Int32 nID = 0;
680 css::uno::Reference< css::beans::XPropertySet > xNode(
681 impl_getSetNode(sName, sal_False),
682 css::uno::UNO_QUERY);
683 if (xNode.is())
684 xNode->getPropertyValue(PROPERTY_PAGEID) >>= nID;
686 catch(const css::uno::Exception& ex)
688 nID = 0;
689 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
692 return nID;
695 //*****************************************************************************************************************
696 void SvtViewOptionsBase_Impl::SetPageID( const ::rtl::OUString& sName ,
697 sal_Int32 nID )
699 #ifdef DEBUG_VIEWOPTIONS
700 ++m_nWriteCount;
701 #endif
705 css::uno::Reference< css::beans::XPropertySet > xNode(
706 impl_getSetNode(sName, sal_True),
707 css::uno::UNO_QUERY_THROW);
708 xNode->setPropertyValue(PROPERTY_PAGEID, css::uno::makeAny(nID));
709 ::comphelper::ConfigurationHelper::flush(m_xRoot);
711 catch(const css::uno::Exception& ex)
713 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
717 //*****************************************************************************************************************
718 sal_Bool SvtViewOptionsBase_Impl::GetVisible( const ::rtl::OUString& sName )
720 #ifdef DEBUG_VIEWOPTIONS
721 ++m_nReadCount;
722 #endif
724 sal_Bool bVisible = sal_False;
727 css::uno::Reference< css::beans::XPropertySet > xNode(
728 impl_getSetNode(sName, sal_False),
729 css::uno::UNO_QUERY);
730 if (xNode.is())
731 xNode->getPropertyValue(PROPERTY_VISIBLE) >>= bVisible;
733 catch(const css::uno::Exception& ex)
735 bVisible = sal_False;
736 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
739 return bVisible;
742 //*****************************************************************************************************************
743 void SvtViewOptionsBase_Impl::SetVisible( const ::rtl::OUString& sName ,
744 sal_Bool bVisible )
746 #ifdef DEBUG_VIEWOPTIONS
747 ++m_nWriteCount;
748 #endif
752 css::uno::Reference< css::beans::XPropertySet > xNode(
753 impl_getSetNode(sName, sal_True),
754 css::uno::UNO_QUERY_THROW);
755 xNode->setPropertyValue(PROPERTY_VISIBLE, css::uno::makeAny(bVisible));
756 ::comphelper::ConfigurationHelper::flush(m_xRoot);
758 catch(const css::uno::Exception& ex)
760 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
764 /*-************************************************************************************************************//**
765 @short create new set node with default values on disk
766 @descr To create a new UserData item - the super node of these property must already exist!
767 You can call this method to create these new entry with default values and change UserData then.
769 @seealso method impl_writeDirectProp()
771 @param "sNode", name of new entry
772 @return -
774 @last change 19.10.2001 08:42
775 *//*-*************************************************************************************************************/
776 css::uno::Reference< css::uno::XInterface > SvtViewOptionsBase_Impl::impl_getSetNode( const ::rtl::OUString& sNode ,
777 sal_Bool bCreateIfMissing)
779 css::uno::Reference< css::uno::XInterface > xNode;
783 if (bCreateIfMissing)
784 xNode = ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot, m_sListName, sNode);
785 else
787 if (m_xSet.is())
788 m_xSet->getByName(sNode) >>= xNode;
791 catch(const css::container::NoSuchElementException&)
792 { xNode.clear(); }
793 catch(const css::uno::Exception& ex)
795 xNode.clear();
796 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
799 return xNode;
802 //_________________________________________________________________________________________________________________
803 // definitions
804 //_________________________________________________________________________________________________________________
806 //*****************************************************************************************************************
807 // constructor
808 //*****************************************************************************************************************
809 SvtViewOptions::SvtViewOptions( EViewType eType ,
810 const ::rtl::OUString& sViewName )
811 : m_eViewType ( eType )
812 , m_sViewName ( sViewName )
814 // Global access, must be guarded (multithreading!)
815 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
817 // Search for right dat container for this view type and initialize right data container or set right ref count!
818 switch( eType )
820 case E_DIALOG : {
821 // Increase ref count for dialog data container first.
822 ++m_nRefCount_Dialogs;
823 // If these instance the first user of the dialog data container - create these impl static container!
824 if( m_nRefCount_Dialogs == 1 )
826 //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
827 m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
828 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
831 break;
832 case E_TABDIALOG : {
833 // Increase ref count for tab-dialog data container first.
834 ++m_nRefCount_TabDialogs;
835 // If these instance the first user of the tab-dialog data container - create these impl static container!
836 if( m_nRefCount_TabDialogs == 1 )
838 m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
839 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
842 break;
843 case E_TABPAGE : {
844 // Increase ref count for tab-page data container first.
845 ++m_nRefCount_TabPages;
846 // If these instance the first user of the tab-page data container - create these impl static container!
847 if( m_nRefCount_TabPages == 1 )
849 m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
850 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
853 break;
854 case E_WINDOW : {
855 // Increase ref count for window data container first.
856 ++m_nRefCount_Windows;
857 // If these instance the first user of the window data container - create these impl static container!
858 if( m_nRefCount_Windows == 1 )
860 m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
861 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
864 break;
865 default : OSL_ENSURE( sal_False, "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
869 //*****************************************************************************************************************
870 // destructor
871 //*****************************************************************************************************************
872 SvtViewOptions::~SvtViewOptions()
874 // Global access, must be guarded (multithreading!)
875 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
877 // Search for right dat container for this view type and deinitialize right data container or set right ref count!
878 switch( m_eViewType )
880 case E_DIALOG : {
881 // Decrease ref count for dialog data container first.
882 --m_nRefCount_Dialogs;
883 // If these instance the last user of the dialog data container - delete these impl static container!
884 if( m_nRefCount_Dialogs == 0 )
886 delete m_pDataContainer_Dialogs;
887 m_pDataContainer_Dialogs = NULL;
890 break;
891 case E_TABDIALOG : {
892 // Decrease ref count for tab-dialog data container first.
893 --m_nRefCount_TabDialogs;
894 // If these instance the last user of the tab-dialog data container - delete these impl static container!
895 if( m_nRefCount_TabDialogs == 0 )
897 delete m_pDataContainer_TabDialogs;
898 m_pDataContainer_TabDialogs = NULL;
901 break;
902 case E_TABPAGE : {
903 // Decrease ref count for tab-page data container first.
904 --m_nRefCount_TabPages;
905 // If these instance the last user of the tab-page data container - delete these impl static container!
906 if( m_nRefCount_TabPages == 0 )
908 delete m_pDataContainer_TabPages;
909 m_pDataContainer_TabPages = NULL;
912 break;
913 case E_WINDOW : {
914 // Decrease ref count for window data container first.
915 --m_nRefCount_Windows;
916 // If these instance the last user of the window data container - delete these impl static container!
917 if( m_nRefCount_Windows == 0 )
919 delete m_pDataContainer_Windows;
920 m_pDataContainer_Windows = NULL;
923 break;
927 //*****************************************************************************************************************
928 // public method
929 //*****************************************************************************************************************
930 sal_Bool SvtViewOptions::Exists() const
932 // Ready for multithreading
933 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
935 sal_Bool bExists = sal_False;
936 switch( m_eViewType )
938 case E_DIALOG : {
939 bExists = m_pDataContainer_Dialogs->Exists( m_sViewName );
941 break;
942 case E_TABDIALOG : {
943 bExists = m_pDataContainer_TabDialogs->Exists( m_sViewName );
945 break;
946 case E_TABPAGE : {
947 bExists = m_pDataContainer_TabPages->Exists( m_sViewName );
949 break;
950 case E_WINDOW : {
951 bExists = m_pDataContainer_Windows->Exists( m_sViewName );
953 break;
955 return bExists;
958 //*****************************************************************************************************************
959 // public method
960 //*****************************************************************************************************************
961 sal_Bool SvtViewOptions::Delete()
963 // Ready for multithreading
964 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
966 sal_Bool bState = sal_False;
967 switch( m_eViewType )
969 case E_DIALOG : {
970 bState = m_pDataContainer_Dialogs->Delete( m_sViewName );
972 break;
973 case E_TABDIALOG : {
974 bState = m_pDataContainer_TabDialogs->Delete( m_sViewName );
976 break;
977 case E_TABPAGE : {
978 bState = m_pDataContainer_TabPages->Delete( m_sViewName );
980 break;
981 case E_WINDOW : {
982 bState = m_pDataContainer_Windows->Delete( m_sViewName );
984 break;
986 return bState;
989 //*****************************************************************************************************************
990 // public method
991 //*****************************************************************************************************************
992 ::rtl::OUString SvtViewOptions::GetWindowState() const
994 // Ready for multithreading
995 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
997 ::rtl::OUString sState;
998 switch( m_eViewType )
1000 case E_DIALOG : {
1001 sState = m_pDataContainer_Dialogs->GetWindowState( m_sViewName );
1003 break;
1004 case E_TABDIALOG : {
1005 sState = m_pDataContainer_TabDialogs->GetWindowState( m_sViewName );
1007 break;
1008 case E_TABPAGE : {
1009 sState = m_pDataContainer_TabPages->GetWindowState( m_sViewName );
1011 break;
1012 case E_WINDOW : {
1013 sState = m_pDataContainer_Windows->GetWindowState( m_sViewName );
1015 break;
1017 return sState;
1020 //*****************************************************************************************************************
1021 // public method
1022 //*****************************************************************************************************************
1023 void SvtViewOptions::SetWindowState( const ::rtl::OUString& sState )
1025 // Ready for multithreading
1026 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1028 switch( m_eViewType )
1030 case E_DIALOG : {
1031 m_pDataContainer_Dialogs->SetWindowState( m_sViewName, sState );
1033 break;
1034 case E_TABDIALOG : {
1035 m_pDataContainer_TabDialogs->SetWindowState( m_sViewName, sState );
1037 break;
1038 case E_TABPAGE : {
1039 m_pDataContainer_TabPages->SetWindowState( m_sViewName, sState );
1041 break;
1042 case E_WINDOW : {
1043 m_pDataContainer_Windows->SetWindowState( m_sViewName, sState );
1045 break;
1049 //*****************************************************************************************************************
1050 // public method
1051 //*****************************************************************************************************************
1052 sal_Int32 SvtViewOptions::GetPageID() const
1054 // Ready for multithreading
1055 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1057 // Safe impossible cases.
1058 // These call isn't allowed for dialogs, tab-pages or windows!
1059 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" );
1061 sal_Int32 nID = 0;
1062 if( m_eViewType == E_TABDIALOG )
1063 nID = m_pDataContainer_TabDialogs->GetPageID( m_sViewName );
1064 return nID;
1067 //*****************************************************************************************************************
1068 // public method
1069 //*****************************************************************************************************************
1070 void SvtViewOptions::SetPageID( sal_Int32 nID )
1072 // Ready for multithreading
1073 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1075 // Safe impossible cases.
1076 // These call isn't allowed for dialogs, tab-pages or windows!
1077 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" );
1079 if( m_eViewType == E_TABDIALOG )
1080 m_pDataContainer_TabDialogs->SetPageID( m_sViewName, nID );
1083 //*****************************************************************************************************************
1084 // public method
1085 //*****************************************************************************************************************
1086 sal_Bool SvtViewOptions::IsVisible() const
1088 // Ready for multithreading
1089 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1091 // Safe impossible cases.
1092 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1093 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" );
1095 sal_Bool bState = sal_False;
1096 if( m_eViewType == E_WINDOW )
1097 bState = m_pDataContainer_Windows->GetVisible( m_sViewName );
1099 return bState;
1102 //*****************************************************************************************************************
1103 // public method
1104 //*****************************************************************************************************************
1105 void SvtViewOptions::SetVisible( sal_Bool bState )
1107 // Ready for multithreading
1108 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1110 // Safe impossible cases.
1111 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
1112 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" );
1114 if( m_eViewType == E_WINDOW )
1115 m_pDataContainer_Windows->SetVisible( m_sViewName, bState );
1118 //*****************************************************************************************************************
1119 css::uno::Sequence< css::beans::NamedValue > SvtViewOptions::GetUserData() const
1121 // Ready for multithreading
1122 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1124 css::uno::Sequence< css::beans::NamedValue > lData;
1125 switch( m_eViewType )
1127 case E_DIALOG : {
1128 lData = m_pDataContainer_Dialogs->GetUserData( m_sViewName );
1130 break;
1131 case E_TABDIALOG : {
1132 lData = m_pDataContainer_TabDialogs->GetUserData( m_sViewName );
1134 break;
1135 case E_TABPAGE : {
1136 lData = m_pDataContainer_TabPages->GetUserData( m_sViewName );
1138 break;
1139 case E_WINDOW : {
1140 lData = m_pDataContainer_Windows->GetUserData( m_sViewName );
1142 break;
1144 return lData;
1147 //*****************************************************************************************************************
1148 void SvtViewOptions::SetUserData( const css::uno::Sequence< css::beans::NamedValue >& lData )
1150 // Ready for multithreading
1151 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1153 switch( m_eViewType )
1155 case E_DIALOG : {
1156 m_pDataContainer_Dialogs->SetUserData( m_sViewName, lData );
1158 break;
1159 case E_TABDIALOG : {
1160 m_pDataContainer_TabDialogs->SetUserData( m_sViewName, lData );
1162 break;
1163 case E_TABPAGE : {
1164 m_pDataContainer_TabPages->SetUserData( m_sViewName, lData );
1166 break;
1167 case E_WINDOW : {
1168 m_pDataContainer_Windows->SetUserData( m_sViewName, lData );
1170 break;
1174 //*****************************************************************************************************************
1175 css::uno::Any SvtViewOptions::GetUserItem( const ::rtl::OUString& sName ) const
1177 // Ready for multithreading
1178 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1180 css::uno::Any aItem;
1181 switch( m_eViewType )
1183 case E_DIALOG : {
1184 aItem = m_pDataContainer_Dialogs->GetUserItem( m_sViewName, sName );
1186 break;
1187 case E_TABDIALOG : {
1188 aItem = m_pDataContainer_TabDialogs->GetUserItem( m_sViewName, sName );
1190 break;
1191 case E_TABPAGE : {
1192 aItem = m_pDataContainer_TabPages->GetUserItem( m_sViewName, sName );
1194 break;
1195 case E_WINDOW : {
1196 aItem = m_pDataContainer_Windows->GetUserItem( m_sViewName, sName );
1198 break;
1200 return aItem;
1203 //*****************************************************************************************************************
1204 void SvtViewOptions::SetUserItem( const ::rtl::OUString& sName ,
1205 const css::uno::Any& aValue )
1207 // Ready for multithreading
1208 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1210 switch( m_eViewType )
1212 case E_DIALOG : {
1213 m_pDataContainer_Dialogs->SetUserItem( m_sViewName, sName, aValue );
1215 break;
1216 case E_TABDIALOG : {
1217 m_pDataContainer_TabDialogs->SetUserItem( m_sViewName, sName, aValue );
1219 break;
1220 case E_TABPAGE : {
1221 m_pDataContainer_TabPages->SetUserItem( m_sViewName, sName, aValue );
1223 break;
1224 case E_WINDOW : {
1225 m_pDataContainer_Windows->SetUserItem( m_sViewName, sName, aValue );
1227 break;
1231 //*****************************************************************************************************************
1232 // private method
1233 //*****************************************************************************************************************
1234 ::osl::Mutex& SvtViewOptions::GetOwnStaticMutex()
1236 // Initialize static mutex only for one time!
1237 static ::osl::Mutex* pMutex = NULL;
1238 // If these method first called (Mutex not already exist!) ...
1239 if( pMutex == NULL )
1241 // ... we must create a new one. Protect follow code with the global mutex -
1242 // It must be - we create a static variable!
1243 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1244 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
1245 if( pMutex == NULL )
1247 // Create the new mutex and set it for return on static variable.
1248 static ::osl::Mutex aMutex;
1249 pMutex = &aMutex;
1252 // Return new created or already existing mutex object.
1253 return *pMutex;
1256 void SvtViewOptions::AcquireOptions()
1258 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1259 if( ++m_nRefCount_Dialogs == 1 )
1261 m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
1262 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
1264 if( ++m_nRefCount_TabDialogs == 1 )
1266 m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
1267 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
1269 if( ++m_nRefCount_TabPages == 1 )
1271 m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
1272 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
1274 if( ++m_nRefCount_Windows == 1 )
1276 m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
1277 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
1281 void SvtViewOptions::ReleaseOptions()
1283 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1284 if( --m_nRefCount_Dialogs == 0 )
1286 delete m_pDataContainer_Dialogs;
1287 m_pDataContainer_Dialogs = NULL;
1289 if( --m_nRefCount_TabDialogs == 0 )
1291 delete m_pDataContainer_TabDialogs;
1292 m_pDataContainer_TabDialogs = NULL;
1294 if( --m_nRefCount_TabPages == 0 )
1296 delete m_pDataContainer_TabPages;
1297 m_pDataContainer_TabPages = NULL;
1299 if( --m_nRefCount_Windows == 0 )
1301 delete m_pDataContainer_Windows;
1302 m_pDataContainer_Windows = NULL;