update emoji autocorrect entries from po-files
[LibreOffice.git] / unotools / source / config / viewoptions.cxx
blob9f078e10556e7998007d1b709448aaf39623e4eb
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 <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/container/XNameContainer.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <rtl/ustrbuf.hxx>
28 #include <osl/diagnose.h>
29 #include <unotools/configpaths.hxx>
30 #include <comphelper/configurationhelper.hxx>
31 #include <comphelper/processfactory.hxx>
33 #include "itemholder1.hxx"
35 #define PACKAGE_VIEWS "org.openoffice.Office.Views"
37 #define LIST_DIALOGS "Dialogs"
38 #define LIST_TABDIALOGS "TabDialogs"
39 #define LIST_TABPAGES "TabPages"
40 #define LIST_WINDOWS "Windows"
42 #define PROPERTY_WINDOWSTATE "WindowState"
43 #define PROPERTY_PAGEID "PageID"
44 #define PROPERTY_VISIBLE "Visible"
45 #define PROPERTY_USERDATA "UserData"
47 //#define DEBUG_VIEWOPTIONS
49 #ifdef DEBUG_VIEWOPTIONS
50 #define _LOG_COUNTER_( _SVIEW_, _NREAD_, _NWRITE_ ) \
51 { \
52 FILE* pFile = fopen( "viewdbg.txt", "a" ); \
53 fprintf( pFile, "%s[%d, %d]\n", OUStringToOString(_SVIEW_, RTL_TEXTENCODING_UTF8).getStr(), _NREAD_, _NWRITE_ ); \
54 fclose( pFile ); \
56 #endif // DEBUG_VIEWOPTIONS
58 #define SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION) \
59 { \
60 OUStringBuffer sMsg(256); \
61 sMsg.appendAscii("Unexpected exception catched. Original message was:\n\"" ); \
62 sMsg.append (SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION_PARAM_EXCEPTION.Message); \
63 sMsg.appendAscii("\"" ); \
66 // initialization!
68 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_Dialogs = NULL ;
69 sal_Int32 SvtViewOptions::m_nRefCount_Dialogs = 0 ;
70 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_TabDialogs = NULL ;
71 sal_Int32 SvtViewOptions::m_nRefCount_TabDialogs = 0 ;
72 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_TabPages = NULL ;
73 sal_Int32 SvtViewOptions::m_nRefCount_TabPages = 0 ;
74 SvtViewOptionsBase_Impl* SvtViewOptions::m_pDataContainer_Windows = NULL ;
75 sal_Int32 SvtViewOptions::m_nRefCount_Windows = 0 ;
77 /*-************************************************************************************************************
78 @descr Implement base data container for view options elements.
79 Every item support ALL possible configuration information.
80 But not every superclass should use them! Because some view types don't
81 have it really.
83 @attention We implement a write-througt-cache! We use it for reading - but write all changes directly to
84 configuration. (changes are made on internal cache too!). So it's easier to distinguish
85 between added/changed/removed elements without any complex mask or bool flag information.
86 Caches from configuration and our own one are synchronized every time - if we do so.
87 *//*-*************************************************************************************************************/
88 class SvtViewOptionsBase_Impl
91 public:
92 enum State { STATE_NONE, STATE_FALSE, STATE_TRUE };
94 SvtViewOptionsBase_Impl ( const OUString& sList );
95 virtual ~SvtViewOptionsBase_Impl ( );
96 bool Exists ( const OUString& sName );
97 bool Delete ( const OUString& sName );
98 OUString GetWindowState ( const OUString& sName );
99 void SetWindowState ( const OUString& sName ,
100 const OUString& sState );
101 css::uno::Sequence< css::beans::NamedValue > GetUserData ( const OUString& sName );
102 void SetUserData ( const OUString& sName ,
103 const css::uno::Sequence< css::beans::NamedValue >& lData );
104 sal_Int32 GetPageID ( const OUString& sName );
105 void SetPageID ( const OUString& sName ,
106 sal_Int32 nID );
107 State GetVisible ( const OUString& sName );
108 void SetVisible ( const OUString& sName ,
109 bool bVisible );
110 css::uno::Any GetUserItem ( const OUString& sName ,
111 const OUString& sItem );
112 void SetUserItem ( const OUString& sName ,
113 const OUString& sItem ,
114 const css::uno::Any& aValue );
116 private:
117 css::uno::Reference< css::uno::XInterface > impl_getSetNode( const OUString& sNode ,
118 bool bCreateIfMissing);
120 private:
121 OUString m_sListName;
122 css::uno::Reference< css::container::XNameAccess > m_xRoot;
123 css::uno::Reference< css::container::XNameAccess > m_xSet;
125 #ifdef DEBUG_VIEWOPTIONS
126 sal_Int32 m_nReadCount;
127 sal_Int32 m_nWriteCount;
128 #endif
131 /*-************************************************************************************************************
132 @descr Implement the base data container.
133 *//*-*************************************************************************************************************/
135 /*-************************************************************************************************************
136 @short ctor
137 @descr We use it to open right configuration file and let configuration objects fill her caches.
138 Then we read all existing entries from right list and cached it inside our object too.
139 Normally we should enable notifications for changes on these values too ... but these feature
140 isn't full implemented in the moment.
142 @seealso baseclass ::utl::ConfigItem
143 @seealso method Notify()
144 *//*-*************************************************************************************************************/
145 SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const OUString& sList )
146 : m_sListName ( sList ) // we must know, which view type we must support
147 #ifdef DEBUG_VIEWOPTIONS
148 , m_nReadCount ( 0 )
149 , m_nWriteCount( 0 )
150 #endif
154 m_xRoot = css::uno::Reference< css::container::XNameAccess >(
155 ::comphelper::ConfigurationHelper::openConfig(
156 ::comphelper::getProcessComponentContext(),
157 PACKAGE_VIEWS,
158 ::comphelper::ConfigurationHelper::E_STANDARD),
159 css::uno::UNO_QUERY);
160 if (m_xRoot.is())
161 m_xRoot->getByName(sList) >>= m_xSet;
163 catch(const css::uno::Exception& ex)
165 m_xRoot.clear();
166 m_xSet.clear();
168 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
172 /*-************************************************************************************************************
173 @short dtor
174 @descr clean up something
176 @attention We implement a write through cache! So we mustn't do it really. All changes was written to cfg directly.
177 Commit isn't necessary then.
179 @seealso baseclass ::utl::ConfigItem
180 @seealso method IsModified()
181 @seealso method SetModified()
182 @seealso method Commit()
183 *//*-*************************************************************************************************************/
184 SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
186 // dont flush configuration changes here to m_xRoot.
187 // That must be done inside every SetXXX() method already !
188 // Here its to late - DisposedExceptions from used configuration access can occur otherwise.
190 m_xRoot.clear();
191 m_xSet.clear();
193 #ifdef DEBUG_VIEWOPTIONS
194 _LOG_COUNTER_( m_sListName, m_nReadCount, m_nWriteCount )
195 #endif // DEBUG_VIEWOPTIONS
198 /*-************************************************************************************************************
199 @short checks for already existing entries
200 @descr If user don't know, if an entry already exist - he can get this information by calling this method.
202 @seealso member m_aList
204 @param "sName", name of entry to check exist state
205 @return true , if item exist
206 false, otherwise
207 *//*-*************************************************************************************************************/
208 bool SvtViewOptionsBase_Impl::Exists( const OUString& sName )
210 bool bExists = false;
214 if (m_xSet.is())
215 bExists = m_xSet->hasByName(sName);
217 catch(const css::uno::Exception& ex)
219 bExists = false;
220 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
223 return bExists;
226 /*-************************************************************************************************************
227 @short delete entry
228 @descr Use it to delete set entry by given name.
230 @seealso member m_aList
232 @param "sName", name of entry to delete it
233 @return true , if item not exist(!) or could be deleted (should be the same!)
234 false, otherwise
235 *//*-*************************************************************************************************************/
236 bool SvtViewOptionsBase_Impl::Delete( const OUString& sName )
238 #ifdef DEBUG_VIEWOPTIONS
239 ++m_nWriteCount;
240 #endif
242 bool bDeleted = false;
245 css::uno::Reference< css::container::XNameContainer > xSet(m_xSet, css::uno::UNO_QUERY_THROW);
246 xSet->removeByName(sName);
247 bDeleted = true;
248 ::comphelper::ConfigurationHelper::flush(m_xRoot);
250 catch(const css::container::NoSuchElementException&)
251 { bDeleted = true; }
252 catch(const css::uno::Exception& ex)
254 bDeleted = false;
255 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
258 return bDeleted;
261 /*-************************************************************************************************************
262 @short read/write access to cache view items and her properties
263 @descr Follow methods support read/write access to all cache view items.
265 @seealso member m_sList
266 *//*-*************************************************************************************************************/
267 OUString SvtViewOptionsBase_Impl::GetWindowState( const OUString& sName )
269 #ifdef DEBUG_VIEWOPTIONS
270 ++m_nReadCount;
271 #endif
273 OUString sWindowState;
276 css::uno::Reference< css::beans::XPropertySet > xNode(
277 impl_getSetNode(sName, false),
278 css::uno::UNO_QUERY);
279 if (xNode.is())
280 xNode->getPropertyValue(PROPERTY_WINDOWSTATE) >>= sWindowState;
282 catch(const css::uno::Exception& ex)
284 sWindowState.clear();
285 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
288 return sWindowState;
291 void SvtViewOptionsBase_Impl::SetWindowState( const OUString& sName ,
292 const OUString& sState )
294 #ifdef DEBUG_VIEWOPTIONS
295 ++m_nWriteCount;
296 #endif
300 css::uno::Reference< css::beans::XPropertySet > xNode(
301 impl_getSetNode(sName, true),
302 css::uno::UNO_QUERY_THROW);
303 xNode->setPropertyValue(PROPERTY_WINDOWSTATE, css::uno::makeAny(sState));
304 ::comphelper::ConfigurationHelper::flush(m_xRoot);
306 catch(const css::uno::Exception& ex)
308 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
312 css::uno::Sequence< css::beans::NamedValue > SvtViewOptionsBase_Impl::GetUserData( const OUString& sName )
314 #ifdef DEBUG_VIEWOPTIONS
315 ++m_nReadCount;
316 #endif
320 css::uno::Reference< css::container::XNameAccess > xNode(
321 impl_getSetNode(sName, false),
322 css::uno::UNO_QUERY); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
323 css::uno::Reference< css::container::XNameAccess > xUserData;
324 if (xNode.is())
325 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
326 if (xUserData.is())
328 const css::uno::Sequence<OUString> lNames = xUserData->getElementNames();
329 const OUString* pNames = lNames.getConstArray();
330 sal_Int32 c = lNames.getLength();
331 sal_Int32 i = 0;
332 css::uno::Sequence< css::beans::NamedValue > lUserData(c);
334 for (i=0; i<c; ++i)
336 lUserData[i].Name = pNames[i];
337 lUserData[i].Value = xUserData->getByName(pNames[i]);
340 return lUserData;
343 catch(const css::uno::Exception& ex)
345 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
348 return css::uno::Sequence< css::beans::NamedValue >();
351 void SvtViewOptionsBase_Impl::SetUserData( const OUString& sName ,
352 const css::uno::Sequence< css::beans::NamedValue >& lData )
354 #ifdef DEBUG_VIEWOPTIONS
355 ++m_nWriteCount;
356 #endif
360 css::uno::Reference< css::container::XNameAccess > xNode(
361 impl_getSetNode(sName, true),
362 css::uno::UNO_QUERY_THROW);
363 css::uno::Reference< css::container::XNameContainer > xUserData;
364 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
365 if (xUserData.is())
367 const css::beans::NamedValue* pData = lData.getConstArray();
368 sal_Int32 c = lData.getLength();
369 sal_Int32 i = 0;
370 for (i=0; i<c; ++i)
372 if (xUserData->hasByName(pData[i].Name))
373 xUserData->replaceByName(pData[i].Name, pData[i].Value);
374 else
375 xUserData->insertByName(pData[i].Name, pData[i].Value);
378 ::comphelper::ConfigurationHelper::flush(m_xRoot);
380 catch(const css::uno::Exception& ex)
382 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
386 css::uno::Any SvtViewOptionsBase_Impl::GetUserItem( const OUString& sName ,
387 const OUString& sItem )
389 #ifdef DEBUG_VIEWOPTIONS
390 ++m_nReadCount;
391 #endif
393 css::uno::Any aItem;
396 css::uno::Reference< css::container::XNameAccess > xNode(
397 impl_getSetNode(sName, false),
398 css::uno::UNO_QUERY);
399 css::uno::Reference< css::container::XNameAccess > xUserData;
400 if (xNode.is())
401 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
402 if (xUserData.is())
403 aItem = xUserData->getByName(sItem);
405 catch(const css::container::NoSuchElementException&)
406 { aItem.clear(); }
407 catch(const css::uno::Exception& ex)
409 aItem.clear();
410 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
413 return aItem;
416 void SvtViewOptionsBase_Impl::SetUserItem( const OUString& sName ,
417 const OUString& sItem ,
418 const css::uno::Any& aValue )
420 #ifdef DEBUG_VIEWOPTIONS
421 ++m_nWriteCount;
422 #endif
426 css::uno::Reference< css::container::XNameAccess > xNode(
427 impl_getSetNode(sName, true),
428 css::uno::UNO_QUERY_THROW);
429 css::uno::Reference< css::container::XNameContainer > xUserData;
430 xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
431 if (xUserData.is())
433 if (xUserData->hasByName(sItem))
434 xUserData->replaceByName(sItem, aValue);
435 else
436 xUserData->insertByName(sItem, aValue);
438 ::comphelper::ConfigurationHelper::flush(m_xRoot);
440 catch(const css::uno::Exception& ex)
442 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
446 sal_Int32 SvtViewOptionsBase_Impl::GetPageID( const OUString& sName )
448 #ifdef DEBUG_VIEWOPTIONS
449 ++m_nReadCount;
450 #endif
452 sal_Int32 nID = 0;
455 css::uno::Reference< css::beans::XPropertySet > xNode(
456 impl_getSetNode(sName, false),
457 css::uno::UNO_QUERY);
458 if (xNode.is())
459 xNode->getPropertyValue(PROPERTY_PAGEID) >>= nID;
461 catch(const css::uno::Exception& ex)
463 nID = 0;
464 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
467 return nID;
470 void SvtViewOptionsBase_Impl::SetPageID( const OUString& sName ,
471 sal_Int32 nID )
473 #ifdef DEBUG_VIEWOPTIONS
474 ++m_nWriteCount;
475 #endif
479 css::uno::Reference< css::beans::XPropertySet > xNode(
480 impl_getSetNode(sName, true),
481 css::uno::UNO_QUERY_THROW);
482 xNode->setPropertyValue(PROPERTY_PAGEID, css::uno::makeAny(nID));
483 ::comphelper::ConfigurationHelper::flush(m_xRoot);
485 catch(const css::uno::Exception& ex)
487 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
491 SvtViewOptionsBase_Impl::State SvtViewOptionsBase_Impl::GetVisible( const OUString& sName )
493 #ifdef DEBUG_VIEWOPTIONS
494 ++m_nReadCount;
495 #endif
497 State eState = STATE_NONE;
500 css::uno::Reference< css::beans::XPropertySet > xNode(
501 impl_getSetNode(sName, false),
502 css::uno::UNO_QUERY);
503 if (xNode.is())
505 bool bVisible = false;
506 if (xNode->getPropertyValue(PROPERTY_VISIBLE) >>= bVisible)
508 eState = bVisible ? STATE_TRUE : STATE_FALSE;
512 catch(const css::uno::Exception& ex)
514 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
517 return eState;
520 void SvtViewOptionsBase_Impl::SetVisible( const OUString& sName ,
521 bool bVisible )
523 #ifdef DEBUG_VIEWOPTIONS
524 ++m_nWriteCount;
525 #endif
529 css::uno::Reference< css::beans::XPropertySet > xNode(
530 impl_getSetNode(sName, true),
531 css::uno::UNO_QUERY_THROW);
532 xNode->setPropertyValue(PROPERTY_VISIBLE, css::uno::makeAny(bVisible));
533 ::comphelper::ConfigurationHelper::flush(m_xRoot);
535 catch(const css::uno::Exception& ex)
537 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
541 /*-************************************************************************************************************
542 @short create new set node with default values on disk
543 @descr To create a new UserData item - the super node of these property must already exist!
544 You can call this method to create these new entry with default values and change UserData then.
546 @seealso method impl_writeDirectProp()
548 @param "sNode", name of new entry
549 *//*-*************************************************************************************************************/
550 css::uno::Reference< css::uno::XInterface > SvtViewOptionsBase_Impl::impl_getSetNode( const OUString& sNode ,
551 bool bCreateIfMissing)
553 css::uno::Reference< css::uno::XInterface > xNode;
557 if (bCreateIfMissing)
558 xNode = ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot, m_sListName, sNode);
559 else
561 if (m_xSet.is() && m_xSet->hasByName(sNode) )
562 m_xSet->getByName(sNode) >>= xNode;
565 catch(const css::container::NoSuchElementException&)
566 { xNode.clear(); }
567 catch(const css::uno::Exception& ex)
569 xNode.clear();
570 SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
573 return xNode;
576 // constructor
578 SvtViewOptions::SvtViewOptions( EViewType eType ,
579 const OUString& sViewName )
580 : m_eViewType ( eType )
581 , m_sViewName ( sViewName )
583 // Global access, must be guarded (multithreading!)
584 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
586 // Search for right dat container for this view type and initialize right data container or set right ref count!
587 switch( eType )
589 case E_DIALOG : {
590 // Increase ref count for dialog data container first.
591 ++m_nRefCount_Dialogs;
592 // If these instance the first user of the dialog data container - create these impl static container!
593 if( m_nRefCount_Dialogs == 1 )
595 //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
596 m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
597 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
600 break;
601 case E_TABDIALOG : {
602 // Increase ref count for tab-dialog data container first.
603 ++m_nRefCount_TabDialogs;
604 // If these instance the first user of the tab-dialog data container - create these impl static container!
605 if( m_nRefCount_TabDialogs == 1 )
607 m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
608 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
611 break;
612 case E_TABPAGE : {
613 // Increase ref count for tab-page data container first.
614 ++m_nRefCount_TabPages;
615 // If these instance the first user of the tab-page data container - create these impl static container!
616 if( m_nRefCount_TabPages == 1 )
618 m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
619 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
622 break;
623 case E_WINDOW : {
624 // Increase ref count for window data container first.
625 ++m_nRefCount_Windows;
626 // If these instance the first user of the window data container - create these impl static container!
627 if( m_nRefCount_Windows == 1 )
629 m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
630 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
633 break;
634 default : OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
638 // destructor
640 SvtViewOptions::~SvtViewOptions()
642 // Global access, must be guarded (multithreading!)
643 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
645 // Search for right dat container for this view type and deinitialize right data container or set right ref count!
646 switch( m_eViewType )
648 case E_DIALOG : {
649 // Decrease ref count for dialog data container first.
650 --m_nRefCount_Dialogs;
651 // If these instance the last user of the dialog data container - delete these impl static container!
652 if( m_nRefCount_Dialogs == 0 )
654 delete m_pDataContainer_Dialogs;
655 m_pDataContainer_Dialogs = NULL;
658 break;
659 case E_TABDIALOG : {
660 // Decrease ref count for tab-dialog data container first.
661 --m_nRefCount_TabDialogs;
662 // If these instance the last user of the tab-dialog data container - delete these impl static container!
663 if( m_nRefCount_TabDialogs == 0 )
665 delete m_pDataContainer_TabDialogs;
666 m_pDataContainer_TabDialogs = NULL;
669 break;
670 case E_TABPAGE : {
671 // Decrease ref count for tab-page data container first.
672 --m_nRefCount_TabPages;
673 // If these instance the last user of the tab-page data container - delete these impl static container!
674 if( m_nRefCount_TabPages == 0 )
676 delete m_pDataContainer_TabPages;
677 m_pDataContainer_TabPages = NULL;
680 break;
681 case E_WINDOW : {
682 // Decrease ref count for window data container first.
683 --m_nRefCount_Windows;
684 // If these instance the last user of the window data container - delete these impl static container!
685 if( m_nRefCount_Windows == 0 )
687 delete m_pDataContainer_Windows;
688 m_pDataContainer_Windows = NULL;
691 break;
695 // public method
697 bool SvtViewOptions::Exists() const
699 // Ready for multithreading
700 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
702 bool bExists = false;
703 switch( m_eViewType )
705 case E_DIALOG : {
706 bExists = m_pDataContainer_Dialogs->Exists( m_sViewName );
708 break;
709 case E_TABDIALOG : {
710 bExists = m_pDataContainer_TabDialogs->Exists( m_sViewName );
712 break;
713 case E_TABPAGE : {
714 bExists = m_pDataContainer_TabPages->Exists( m_sViewName );
716 break;
717 case E_WINDOW : {
718 bExists = m_pDataContainer_Windows->Exists( m_sViewName );
720 break;
722 return bExists;
725 // public method
727 bool SvtViewOptions::Delete()
729 // Ready for multithreading
730 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
732 bool bState = false;
733 switch( m_eViewType )
735 case E_DIALOG : {
736 bState = m_pDataContainer_Dialogs->Delete( m_sViewName );
738 break;
739 case E_TABDIALOG : {
740 bState = m_pDataContainer_TabDialogs->Delete( m_sViewName );
742 break;
743 case E_TABPAGE : {
744 bState = m_pDataContainer_TabPages->Delete( m_sViewName );
746 break;
747 case E_WINDOW : {
748 bState = m_pDataContainer_Windows->Delete( m_sViewName );
750 break;
752 return bState;
755 // public method
757 OUString SvtViewOptions::GetWindowState() const
759 // Ready for multithreading
760 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
762 OUString sState;
763 switch( m_eViewType )
765 case E_DIALOG : {
766 sState = m_pDataContainer_Dialogs->GetWindowState( m_sViewName );
768 break;
769 case E_TABDIALOG : {
770 sState = m_pDataContainer_TabDialogs->GetWindowState( m_sViewName );
772 break;
773 case E_TABPAGE : {
774 sState = m_pDataContainer_TabPages->GetWindowState( m_sViewName );
776 break;
777 case E_WINDOW : {
778 sState = m_pDataContainer_Windows->GetWindowState( m_sViewName );
780 break;
782 return sState;
785 // public method
787 void SvtViewOptions::SetWindowState( const OUString& sState )
789 // Ready for multithreading
790 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
792 switch( m_eViewType )
794 case E_DIALOG : {
795 m_pDataContainer_Dialogs->SetWindowState( m_sViewName, sState );
797 break;
798 case E_TABDIALOG : {
799 m_pDataContainer_TabDialogs->SetWindowState( m_sViewName, sState );
801 break;
802 case E_TABPAGE : {
803 m_pDataContainer_TabPages->SetWindowState( m_sViewName, sState );
805 break;
806 case E_WINDOW : {
807 m_pDataContainer_Windows->SetWindowState( m_sViewName, sState );
809 break;
813 // public method
815 sal_Int32 SvtViewOptions::GetPageID() const
817 // Ready for multithreading
818 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
820 // Safe impossible cases.
821 // These call isn't allowed for dialogs, tab-pages or windows!
822 OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABPAGE||m_eViewType==E_WINDOW), "SvtViewOptions::GetPageID()\nCall not allowed for Dialogs, TabPages or Windows! I do nothing!\n" );
824 sal_Int32 nID = 0;
825 if( m_eViewType == E_TABDIALOG )
826 nID = m_pDataContainer_TabDialogs->GetPageID( m_sViewName );
827 return nID;
830 // public method
832 void SvtViewOptions::SetPageID( sal_Int32 nID )
834 // Ready for multithreading
835 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
837 // Safe impossible cases.
838 // These call isn't allowed for dialogs, tab-pages or windows!
839 OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABPAGE||m_eViewType==E_WINDOW), "SvtViewOptions::SetPageID()\nCall not allowed for Dialogs, TabPages or Windows! I do nothing!\n" );
841 if( m_eViewType == E_TABDIALOG )
842 m_pDataContainer_TabDialogs->SetPageID( m_sViewName, nID );
845 // public method
847 bool SvtViewOptions::IsVisible() const
849 // Ready for multithreading
850 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
852 // Safe impossible cases.
853 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
854 OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABDIALOG||m_eViewType==E_TABPAGE), "SvtViewOptions::IsVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
856 bool bState = false;
857 if( m_eViewType == E_WINDOW )
858 bState = m_pDataContainer_Windows->GetVisible( m_sViewName ) == SvtViewOptionsBase_Impl::STATE_TRUE;
860 return bState;
863 // public method
865 void SvtViewOptions::SetVisible( bool bState )
867 // Ready for multithreading
868 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
870 // Safe impossible cases.
871 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
872 OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABDIALOG||m_eViewType==E_TABPAGE), "SvtViewOptions::SetVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
874 if( m_eViewType == E_WINDOW )
875 m_pDataContainer_Windows->SetVisible( m_sViewName, bState );
878 // public method
880 bool SvtViewOptions::HasVisible() const
882 // Ready for multithreading
883 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
885 // Safe impossible cases.
886 // These call isn't allowed for dialogs, tab-dialogs or tab-pages!
887 OSL_ENSURE( !(m_eViewType==E_DIALOG||m_eViewType==E_TABDIALOG||m_eViewType==E_TABPAGE), "SvtViewOptions::IsVisible()\nCall not allowed for Dialogs, TabDialogs or TabPages! I do nothing!\n" );
889 bool bState = false;
890 if( m_eViewType == E_WINDOW )
891 bState = m_pDataContainer_Windows->GetVisible( m_sViewName ) != SvtViewOptionsBase_Impl::STATE_NONE;
893 return bState;
896 css::uno::Sequence< css::beans::NamedValue > SvtViewOptions::GetUserData() const
898 // Ready for multithreading
899 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
901 css::uno::Sequence< css::beans::NamedValue > lData;
902 switch( m_eViewType )
904 case E_DIALOG : {
905 lData = m_pDataContainer_Dialogs->GetUserData( m_sViewName );
907 break;
908 case E_TABDIALOG : {
909 lData = m_pDataContainer_TabDialogs->GetUserData( m_sViewName );
911 break;
912 case E_TABPAGE : {
913 lData = m_pDataContainer_TabPages->GetUserData( m_sViewName );
915 break;
916 case E_WINDOW : {
917 lData = m_pDataContainer_Windows->GetUserData( m_sViewName );
919 break;
921 return lData;
924 void SvtViewOptions::SetUserData( const css::uno::Sequence< css::beans::NamedValue >& lData )
926 // Ready for multithreading
927 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
929 switch( m_eViewType )
931 case E_DIALOG : {
932 m_pDataContainer_Dialogs->SetUserData( m_sViewName, lData );
934 break;
935 case E_TABDIALOG : {
936 m_pDataContainer_TabDialogs->SetUserData( m_sViewName, lData );
938 break;
939 case E_TABPAGE : {
940 m_pDataContainer_TabPages->SetUserData( m_sViewName, lData );
942 break;
943 case E_WINDOW : {
944 m_pDataContainer_Windows->SetUserData( m_sViewName, lData );
946 break;
950 css::uno::Any SvtViewOptions::GetUserItem( const OUString& sName ) const
952 // Ready for multithreading
953 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
955 css::uno::Any aItem;
956 switch( m_eViewType )
958 case E_DIALOG : {
959 aItem = m_pDataContainer_Dialogs->GetUserItem( m_sViewName, sName );
961 break;
962 case E_TABDIALOG : {
963 aItem = m_pDataContainer_TabDialogs->GetUserItem( m_sViewName, sName );
965 break;
966 case E_TABPAGE : {
967 aItem = m_pDataContainer_TabPages->GetUserItem( m_sViewName, sName );
969 break;
970 case E_WINDOW : {
971 aItem = m_pDataContainer_Windows->GetUserItem( m_sViewName, sName );
973 break;
975 return aItem;
978 void SvtViewOptions::SetUserItem( const OUString& sName ,
979 const css::uno::Any& aValue )
981 // Ready for multithreading
982 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
984 switch( m_eViewType )
986 case E_DIALOG : {
987 m_pDataContainer_Dialogs->SetUserItem( m_sViewName, sName, aValue );
989 break;
990 case E_TABDIALOG : {
991 m_pDataContainer_TabDialogs->SetUserItem( m_sViewName, sName, aValue );
993 break;
994 case E_TABPAGE : {
995 m_pDataContainer_TabPages->SetUserItem( m_sViewName, sName, aValue );
997 break;
998 case E_WINDOW : {
999 m_pDataContainer_Windows->SetUserItem( m_sViewName, sName, aValue );
1001 break;
1005 namespace
1007 class theViewOptionsMutex : public rtl::Static<osl::Mutex, theViewOptionsMutex>{};
1010 // private method
1012 ::osl::Mutex& SvtViewOptions::GetOwnStaticMutex()
1014 return theViewOptionsMutex::get();
1017 void SvtViewOptions::AcquireOptions()
1019 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1020 if( ++m_nRefCount_Dialogs == 1 )
1022 m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
1023 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
1025 if( ++m_nRefCount_TabDialogs == 1 )
1027 m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
1028 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
1030 if( ++m_nRefCount_TabPages == 1 )
1032 m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
1033 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
1035 if( ++m_nRefCount_Windows == 1 )
1037 m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
1038 ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
1042 void SvtViewOptions::ReleaseOptions()
1044 ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1045 if( --m_nRefCount_Dialogs == 0 )
1047 delete m_pDataContainer_Dialogs;
1048 m_pDataContainer_Dialogs = NULL;
1050 if( --m_nRefCount_TabDialogs == 0 )
1052 delete m_pDataContainer_TabDialogs;
1053 m_pDataContainer_TabDialogs = NULL;
1055 if( --m_nRefCount_TabPages == 0 )
1057 delete m_pDataContainer_TabPages;
1058 m_pDataContainer_TabPages = NULL;
1060 if( --m_nRefCount_Windows == 0 )
1062 delete m_pDataContainer_Windows;
1063 m_pDataContainer_Windows = NULL;
1067 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */