Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <unotools/viewoptions.hxx>
21 : #include <com/sun/star/uno/Any.hxx>
22 :
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>
32 :
33 : #include <itemholder1.hxx>
34 :
35 : #define PACKAGE_VIEWS "org.openoffice.Office.Views"
36 :
37 : #define LIST_DIALOGS "Dialogs"
38 : #define LIST_TABDIALOGS "TabDialogs"
39 : #define LIST_TABPAGES "TabPages"
40 : #define LIST_WINDOWS "Windows"
41 :
42 : #define PROPERTY_WINDOWSTATE "WindowState"
43 : #define PROPERTY_PAGEID "PageID"
44 : #define PROPERTY_VISIBLE "Visible"
45 : #define PROPERTY_USERDATA "UserData"
46 :
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
51 :
52 : //#define DEBUG_VIEWOPTIONS
53 :
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 ); \
60 : }
61 : #endif // DEBUG_VIEWOPTIONS
62 :
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("\"" ); \
69 : }
70 :
71 : //_________________________________________________________________________________________________________________
72 : // initialization!
73 : //_________________________________________________________________________________________________________________
74 :
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 ;
83 :
84 : //_________________________________________________________________________________________________________________
85 : // private declarations!
86 : //_________________________________________________________________________________________________________________
87 :
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
103 : {
104 : public:
105 : //---------------------------------------------------------------------------------------------------------
106 : // create "default" item
107 : IMPL_TViewData()
108 : {
109 : m_sWindowState = DEFAULT_WINDOWSTATE ;
110 : m_lUserData = DEFAULT_USERDATA ;
111 : m_nPageID = DEFAULT_PAGEID ;
112 : m_bVisible = DEFAULT_VISIBLE ;
113 :
114 : m_bDefault = sal_True ;
115 : }
116 :
117 : //---------------------------------------------------------------------------------------------------------
118 : // write access - with reseting of default state
119 : void setWindowState( const OUString& sValue )
120 : {
121 : m_bDefault = (
122 : ( m_bDefault == sal_True ) &&
123 : ( sValue == DEFAULT_WINDOWSTATE )
124 : );
125 : m_sWindowState = sValue;
126 : }
127 :
128 : //---------------------------------------------------------------------------------------------------------
129 : void setUserData( const css::uno::Sequence< css::beans::NamedValue >& lValue )
130 : {
131 : m_bDefault = (
132 : ( m_bDefault == sal_True ) &&
133 : ( lValue == DEFAULT_USERDATA )
134 : );
135 : m_lUserData = lValue;
136 : }
137 :
138 : //---------------------------------------------------------------------------------------------------------
139 : void setPageID( sal_Int32 nValue )
140 : {
141 : m_bDefault = (
142 : ( m_bDefault == sal_True ) &&
143 : ( nValue == DEFAULT_PAGEID )
144 : );
145 : m_nPageID = nValue;
146 : }
147 :
148 : //---------------------------------------------------------------------------------------------------------
149 : void setVisible( sal_Bool bValue )
150 : {
151 : m_bDefault = (
152 : ( m_bDefault == sal_True ) &&
153 : ( bValue == DEFAULT_VISIBLE )
154 : );
155 : m_bVisible = bValue;
156 : }
157 :
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 ; }
164 :
165 : //---------------------------------------------------------------------------------------------------------
166 : // special operation for easy access on user data
167 : void setUserItem( const OUString& sName ,
168 : const css::uno::Any& aValue )
169 : {
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;
174 :
175 : sal_Bool bExist = sal_False;
176 : sal_Int32 nCount = m_lUserData.getLength();
177 :
178 : // change it, if it already exist ...
179 : for( sal_Int32 nStep=0; nStep<nCount; ++nStep )
180 : {
181 : if( m_lUserData[nStep].Name == sName )
182 : {
183 : m_lUserData[nStep].Value = aValue ;
184 : bExist = sal_True;
185 : break;
186 : }
187 : }
188 :
189 : // ... or create new list item
190 : if( bExist == sal_False )
191 : {
192 : m_lUserData.realloc( nCount+1 );
193 : m_lUserData[nCount].Name = sName ;
194 : m_lUserData[nCount].Value = aValue ;
195 : }
196 : }
197 :
198 : //---------------------------------------------------------------------------------------------------------
199 : css::uno::Any getUserItem( const OUString& sName )
200 : {
201 : // default value - if item not exist!
202 : css::uno::Any aValue;
203 :
204 : sal_Int32 nCount = m_lUserData.getLength();
205 : for( sal_Int32 nStep=0; nStep<nCount; ++nStep )
206 : {
207 : if( m_lUserData[nStep].Name == sName )
208 : {
209 : aValue = m_lUserData[nStep].Value;
210 : break;
211 : }
212 : }
213 : return aValue;
214 : }
215 :
216 : //---------------------------------------------------------------------------------------------------------
217 : // check for default items
218 : sal_Bool isDefault() { return m_bDefault; }
219 :
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 ;
225 :
226 : sal_Bool m_bDefault ;
227 : };
228 :
229 : struct IMPL_TStringHashCode
230 : {
231 : size_t operator()(const OUString& sString) const
232 : {
233 : return sString.hashCode();
234 : }
235 : };
236 :
237 : typedef ::boost::unordered_map< OUString ,
238 : IMPL_TViewData ,
239 : IMPL_TStringHashCode ,
240 : ::std::equal_to< OUString > > IMPL_TViewHash;
241 :
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.
247 :
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
254 : {
255 : //-------------------------------------------------------------------------------------------------------------
256 : public:
257 : enum State { STATE_NONE, STATE_FALSE, STATE_TRUE };
258 :
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 );
280 :
281 : //-------------------------------------------------------------------------------------------------------------
282 : private:
283 : css::uno::Reference< css::uno::XInterface > impl_getSetNode( const OUString& sNode ,
284 : sal_Bool bCreateIfMissing);
285 :
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;
291 :
292 : #ifdef DEBUG_VIEWOPTIONS
293 : sal_Int32 m_nReadCount ;
294 : sal_Int32 m_nWriteCount ;
295 : #endif
296 : };
297 :
298 : /*-************************************************************************************************************//**
299 : @descr Implement the base data container.
300 : *//*-*************************************************************************************************************/
301 :
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.
308 :
309 : @seealso baseclass ::utl::ConfigItem
310 : @seealso method Notify()
311 :
312 : @param -
313 : @return -
314 : *//*-*************************************************************************************************************/
315 532 : SvtViewOptionsBase_Impl::SvtViewOptionsBase_Impl( const OUString& sList )
316 532 : : 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
321 : {
322 : try
323 : {
324 1064 : m_xRoot = css::uno::Reference< css::container::XNameAccess >(
325 : ::comphelper::ConfigurationHelper::openConfig(
326 : ::comphelper::getProcessComponentContext(),
327 : PACKAGE_VIEWS,
328 : ::comphelper::ConfigurationHelper::E_STANDARD),
329 532 : css::uno::UNO_QUERY);
330 532 : if (m_xRoot.is())
331 532 : m_xRoot->getByName(sList) >>= m_xSet;
332 : }
333 0 : catch(const css::uno::Exception& ex)
334 : {
335 0 : m_xRoot.clear();
336 0 : m_xSet.clear();
337 :
338 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
339 : }
340 532 : }
341 :
342 : /*-************************************************************************************************************//**
343 : @short dtor
344 : @descr clean up something
345 :
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.
348 :
349 : @seealso baseclass ::utl::ConfigItem
350 : @seealso method IsModified()
351 : @seealso method SetModified()
352 : @seealso method Commit()
353 :
354 : @param -
355 : @return -
356 : *//*-*************************************************************************************************************/
357 996 : SvtViewOptionsBase_Impl::~SvtViewOptionsBase_Impl()
358 : {
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.
362 :
363 332 : m_xRoot.clear();
364 332 : m_xSet.clear();
365 :
366 : #ifdef DEBUG_VIEWOPTIONS
367 : _LOG_COUNTER_( m_sListName, m_nReadCount, m_nWriteCount )
368 : #endif // DEBUG_VIEWOPTIONS
369 664 : }
370 :
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.
374 :
375 : @seealso member m_aList
376 :
377 : @param "sName", name of entry to check exist state
378 : @return true , if item exist
379 : false, otherwise
380 : *//*-*************************************************************************************************************/
381 34584 : sal_Bool SvtViewOptionsBase_Impl::Exists( const OUString& sName )
382 : {
383 34584 : sal_Bool bExists = sal_False;
384 :
385 : try
386 : {
387 34584 : if (m_xSet.is())
388 34584 : bExists = m_xSet->hasByName(sName);
389 : }
390 0 : catch(const css::uno::Exception& ex)
391 : {
392 0 : bExists = sal_False;
393 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
394 : }
395 :
396 34584 : return bExists;
397 : }
398 :
399 : /*-************************************************************************************************************//**
400 : @short delete entry
401 : @descr Use it to delete set entry by given name.
402 :
403 : @seealso member m_aList
404 :
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 0 : sal_Bool SvtViewOptionsBase_Impl::Delete( const OUString& sName )
410 : {
411 : #ifdef DEBUG_VIEWOPTIONS
412 : ++m_nWriteCount;
413 : #endif
414 :
415 0 : sal_Bool bDeleted = sal_False;
416 : try
417 : {
418 0 : css::uno::Reference< css::container::XNameContainer > xSet(m_xSet, css::uno::UNO_QUERY_THROW);
419 0 : xSet->removeByName(sName);
420 0 : bDeleted = sal_True;
421 0 : ::comphelper::ConfigurationHelper::flush(m_xRoot);
422 : }
423 0 : catch(const css::container::NoSuchElementException&)
424 0 : { bDeleted = sal_True; }
425 0 : catch(const css::uno::Exception& ex)
426 : {
427 0 : bDeleted = sal_False;
428 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
429 : }
430 :
431 0 : return bDeleted;
432 : }
433 :
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.
437 :
438 : @seealso member m_sList
439 :
440 : @param -
441 : @return -
442 : *//*-*************************************************************************************************************/
443 34584 : OUString SvtViewOptionsBase_Impl::GetWindowState( const OUString& sName )
444 : {
445 : #ifdef DEBUG_VIEWOPTIONS
446 : ++m_nReadCount;
447 : #endif
448 :
449 34584 : OUString sWindowState;
450 : try
451 : {
452 : css::uno::Reference< css::beans::XPropertySet > xNode(
453 : impl_getSetNode(sName, sal_False),
454 34584 : css::uno::UNO_QUERY);
455 34584 : if (xNode.is())
456 2281 : xNode->getPropertyValue(PROPERTY_WINDOWSTATE) >>= sWindowState;
457 : }
458 0 : catch(const css::uno::Exception& ex)
459 : {
460 0 : sWindowState = OUString();
461 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
462 : }
463 :
464 34584 : return sWindowState;
465 : }
466 :
467 : //*****************************************************************************************************************
468 1491 : void SvtViewOptionsBase_Impl::SetWindowState( const OUString& sName ,
469 : const OUString& sState )
470 : {
471 : #ifdef DEBUG_VIEWOPTIONS
472 : ++m_nWriteCount;
473 : #endif
474 :
475 : try
476 : {
477 : css::uno::Reference< css::beans::XPropertySet > xNode(
478 : impl_getSetNode(sName, sal_True),
479 1491 : css::uno::UNO_QUERY_THROW);
480 1491 : xNode->setPropertyValue(PROPERTY_WINDOWSTATE, css::uno::makeAny(sState));
481 1491 : ::comphelper::ConfigurationHelper::flush(m_xRoot);
482 : }
483 0 : catch(const css::uno::Exception& ex)
484 : {
485 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
486 : }
487 1491 : }
488 :
489 : //*****************************************************************************************************************
490 34584 : css::uno::Sequence< css::beans::NamedValue > SvtViewOptionsBase_Impl::GetUserData( const OUString& sName )
491 : {
492 : #ifdef DEBUG_VIEWOPTIONS
493 : ++m_nReadCount;
494 : #endif
495 :
496 : try
497 : {
498 : css::uno::Reference< css::container::XNameAccess > xNode(
499 : impl_getSetNode(sName, sal_False),
500 34584 : css::uno::UNO_QUERY); // no _THROW ! because we dont create missing items here. So we have to live with zero references .-)
501 66887 : css::uno::Reference< css::container::XNameAccess > xUserData;
502 34584 : if (xNode.is())
503 2281 : xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
504 34584 : if (xUserData.is())
505 : {
506 2281 : const css::uno::Sequence< OUString > lNames = xUserData->getElementNames();
507 2281 : const OUString* pNames = lNames.getConstArray();
508 2281 : sal_Int32 c = lNames.getLength();
509 2281 : sal_Int32 i = 0;
510 4562 : css::uno::Sequence< css::beans::NamedValue > lUserData(c);
511 :
512 3578 : for (i=0; i<c; ++i)
513 : {
514 1297 : lUserData[i].Name = pNames[i];
515 1297 : lUserData[i].Value = xUserData->getByName(pNames[i]);
516 : }
517 :
518 4562 : return lUserData;
519 32303 : }
520 : }
521 0 : catch(const css::uno::Exception& ex)
522 : {
523 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
524 : }
525 :
526 32303 : return css::uno::Sequence< css::beans::NamedValue >();
527 : }
528 :
529 : //*****************************************************************************************************************
530 1491 : void SvtViewOptionsBase_Impl::SetUserData( const OUString& sName ,
531 : const css::uno::Sequence< css::beans::NamedValue >& lData )
532 : {
533 : #ifdef DEBUG_VIEWOPTIONS
534 : ++m_nWriteCount;
535 : #endif
536 :
537 : try
538 : {
539 : css::uno::Reference< css::container::XNameAccess > xNode(
540 : impl_getSetNode(sName, sal_True),
541 1491 : css::uno::UNO_QUERY_THROW);
542 2982 : css::uno::Reference< css::container::XNameContainer > xUserData;
543 1491 : xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
544 1491 : if (xUserData.is())
545 : {
546 1491 : const css::beans::NamedValue* pData = lData.getConstArray();
547 1491 : sal_Int32 c = lData.getLength();
548 1491 : sal_Int32 i = 0;
549 2982 : for (i=0; i<c; ++i)
550 : {
551 1491 : if (xUserData->hasByName(pData[i].Name))
552 1401 : xUserData->replaceByName(pData[i].Name, pData[i].Value);
553 : else
554 90 : xUserData->insertByName(pData[i].Name, pData[i].Value);
555 : }
556 : }
557 2982 : ::comphelper::ConfigurationHelper::flush(m_xRoot);
558 : }
559 0 : catch(const css::uno::Exception& ex)
560 : {
561 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
562 : }
563 1491 : }
564 :
565 : //*****************************************************************************************************************
566 4328 : css::uno::Any SvtViewOptionsBase_Impl::GetUserItem( const OUString& sName ,
567 : const OUString& sItem )
568 : {
569 : #ifdef DEBUG_VIEWOPTIONS
570 : ++m_nReadCount;
571 : #endif
572 :
573 4328 : css::uno::Any aItem;
574 : try
575 : {
576 : css::uno::Reference< css::container::XNameAccess > xNode(
577 : impl_getSetNode(sName, sal_False),
578 4328 : css::uno::UNO_QUERY);
579 8656 : css::uno::Reference< css::container::XNameAccess > xUserData;
580 4328 : if (xNode.is())
581 4116 : xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
582 4328 : if (xUserData.is())
583 8444 : aItem = xUserData->getByName(sItem);
584 : }
585 0 : catch(const css::container::NoSuchElementException&)
586 0 : { aItem.clear(); }
587 0 : catch(const css::uno::Exception& ex)
588 : {
589 0 : aItem.clear();
590 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
591 : }
592 :
593 4328 : return aItem;
594 : }
595 :
596 : //*****************************************************************************************************************
597 4321 : void SvtViewOptionsBase_Impl::SetUserItem( const OUString& sName ,
598 : const OUString& sItem ,
599 : const css::uno::Any& aValue )
600 : {
601 : #ifdef DEBUG_VIEWOPTIONS
602 : ++m_nWriteCount;
603 : #endif
604 :
605 : try
606 : {
607 : css::uno::Reference< css::container::XNameAccess > xNode(
608 : impl_getSetNode(sName, sal_True),
609 4321 : css::uno::UNO_QUERY_THROW);
610 8642 : css::uno::Reference< css::container::XNameContainer > xUserData;
611 4321 : xNode->getByName(PROPERTY_USERDATA) >>= xUserData;
612 4321 : if (xUserData.is())
613 : {
614 4321 : if (xUserData->hasByName(sItem))
615 4141 : xUserData->replaceByName(sItem, aValue);
616 : else
617 180 : xUserData->insertByName(sItem, aValue);
618 : }
619 8642 : ::comphelper::ConfigurationHelper::flush(m_xRoot);
620 : }
621 0 : catch(const css::uno::Exception& ex)
622 : {
623 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
624 : }
625 4321 : }
626 :
627 : //*****************************************************************************************************************
628 0 : sal_Int32 SvtViewOptionsBase_Impl::GetPageID( const OUString& sName )
629 : {
630 : #ifdef DEBUG_VIEWOPTIONS
631 : ++m_nReadCount;
632 : #endif
633 :
634 0 : sal_Int32 nID = 0;
635 : try
636 : {
637 : css::uno::Reference< css::beans::XPropertySet > xNode(
638 : impl_getSetNode(sName, sal_False),
639 0 : css::uno::UNO_QUERY);
640 0 : if (xNode.is())
641 0 : xNode->getPropertyValue(PROPERTY_PAGEID) >>= nID;
642 : }
643 0 : catch(const css::uno::Exception& ex)
644 : {
645 0 : nID = 0;
646 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
647 : }
648 :
649 0 : return nID;
650 : }
651 :
652 : //*****************************************************************************************************************
653 0 : void SvtViewOptionsBase_Impl::SetPageID( const OUString& sName ,
654 : sal_Int32 nID )
655 : {
656 : #ifdef DEBUG_VIEWOPTIONS
657 : ++m_nWriteCount;
658 : #endif
659 :
660 : try
661 : {
662 : css::uno::Reference< css::beans::XPropertySet > xNode(
663 : impl_getSetNode(sName, sal_True),
664 0 : css::uno::UNO_QUERY_THROW);
665 0 : xNode->setPropertyValue(PROPERTY_PAGEID, css::uno::makeAny(nID));
666 0 : ::comphelper::ConfigurationHelper::flush(m_xRoot);
667 : }
668 0 : catch(const css::uno::Exception& ex)
669 : {
670 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
671 : }
672 0 : }
673 :
674 : //*****************************************************************************************************************
675 3325 : SvtViewOptionsBase_Impl::State SvtViewOptionsBase_Impl::GetVisible( const OUString& sName )
676 : {
677 : #ifdef DEBUG_VIEWOPTIONS
678 : ++m_nReadCount;
679 : #endif
680 :
681 3325 : State eState = STATE_NONE;
682 : try
683 : {
684 : css::uno::Reference< css::beans::XPropertySet > xNode(
685 : impl_getSetNode(sName, sal_False),
686 3325 : css::uno::UNO_QUERY);
687 3325 : if (xNode.is())
688 : {
689 3325 : sal_Bool bVisible = sal_False;
690 3325 : if (xNode->getPropertyValue(PROPERTY_VISIBLE) >>= bVisible)
691 : {
692 2088 : eState = bVisible ? STATE_TRUE : STATE_FALSE;
693 : }
694 3325 : }
695 : }
696 0 : catch(const css::uno::Exception& ex)
697 : {
698 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
699 : }
700 :
701 3325 : return eState;
702 : }
703 :
704 : //*****************************************************************************************************************
705 0 : void SvtViewOptionsBase_Impl::SetVisible( const OUString& sName ,
706 : sal_Bool bVisible )
707 : {
708 : #ifdef DEBUG_VIEWOPTIONS
709 : ++m_nWriteCount;
710 : #endif
711 :
712 : try
713 : {
714 : css::uno::Reference< css::beans::XPropertySet > xNode(
715 : impl_getSetNode(sName, sal_True),
716 0 : css::uno::UNO_QUERY_THROW);
717 0 : xNode->setPropertyValue(PROPERTY_VISIBLE, css::uno::makeAny(bVisible));
718 0 : ::comphelper::ConfigurationHelper::flush(m_xRoot);
719 : }
720 0 : catch(const css::uno::Exception& ex)
721 : {
722 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
723 : }
724 0 : }
725 :
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.
730 :
731 : @seealso method impl_writeDirectProp()
732 :
733 : @param "sNode", name of new entry
734 : @return -
735 : *//*-*************************************************************************************************************/
736 84124 : css::uno::Reference< css::uno::XInterface > SvtViewOptionsBase_Impl::impl_getSetNode( const OUString& sNode ,
737 : sal_Bool bCreateIfMissing)
738 : {
739 84124 : css::uno::Reference< css::uno::XInterface > xNode;
740 :
741 : try
742 : {
743 84124 : if (bCreateIfMissing)
744 7303 : xNode = ::comphelper::ConfigurationHelper::makeSureSetNodeExists(m_xRoot, m_sListName, sNode);
745 : else
746 : {
747 76821 : if (m_xSet.is() && m_xSet->hasByName(sNode) )
748 12003 : m_xSet->getByName(sNode) >>= xNode;
749 : }
750 : }
751 0 : catch(const css::container::NoSuchElementException&)
752 0 : { xNode.clear(); }
753 0 : catch(const css::uno::Exception& ex)
754 : {
755 0 : xNode.clear();
756 0 : SVTVIEWOPTIONS_LOG_UNEXPECTED_EXCEPTION(ex)
757 : }
758 :
759 84124 : return xNode;
760 : }
761 :
762 : //*****************************************************************************************************************
763 : // constructor
764 : //*****************************************************************************************************************
765 45256 : SvtViewOptions::SvtViewOptions( EViewType eType ,
766 : const OUString& sViewName )
767 : : m_eViewType ( eType )
768 45256 : , m_sViewName ( sViewName )
769 : {
770 : // Global access, must be guarded (multithreading!)
771 45256 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
772 :
773 : // Search for right dat container for this view type and initialize right data container or set right ref count!
774 45256 : switch( eType )
775 : {
776 : case E_DIALOG : {
777 : // Increase ref count for dialog data container first.
778 133 : ++m_nRefCount_Dialogs;
779 : // If these instance the first user of the dialog data container - create these impl static container!
780 133 : if( m_nRefCount_Dialogs == 1 )
781 : {
782 : //m_pDataContainer_Dialogs = new SvtViewDialogOptions_Impl( LIST_DIALOGS );
783 0 : m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
784 0 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
785 : }
786 : }
787 133 : break;
788 : case E_TABDIALOG : {
789 : // Increase ref count for tab-dialog data container first.
790 133 : ++m_nRefCount_TabDialogs;
791 : // If these instance the first user of the tab-dialog data container - create these impl static container!
792 133 : if( m_nRefCount_TabDialogs == 1 )
793 : {
794 0 : m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
795 0 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
796 : }
797 : }
798 133 : break;
799 : case E_TABPAGE : {
800 : // Increase ref count for tab-page data container first.
801 133 : ++m_nRefCount_TabPages;
802 : // If these instance the first user of the tab-page data container - create these impl static container!
803 133 : if( m_nRefCount_TabPages == 1 )
804 : {
805 0 : m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
806 0 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
807 : }
808 : }
809 133 : break;
810 : case E_WINDOW : {
811 : // Increase ref count for window data container first.
812 44857 : ++m_nRefCount_Windows;
813 : // If these instance the first user of the window data container - create these impl static container!
814 44857 : if( m_nRefCount_Windows == 1 )
815 : {
816 0 : m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
817 0 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
818 : }
819 : }
820 44857 : break;
821 : default : OSL_FAIL( "SvtViewOptions::SvtViewOptions()\nThese view type is unknown! All following calls at these instance will do nothing!\n" );
822 45256 : }
823 45256 : }
824 :
825 : //*****************************************************************************************************************
826 : // destructor
827 : //*****************************************************************************************************************
828 91032 : SvtViewOptions::~SvtViewOptions()
829 : {
830 : // Global access, must be guarded (multithreading!)
831 45252 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
832 :
833 : // Search for right dat container for this view type and deinitialize right data container or set right ref count!
834 45252 : switch( m_eViewType )
835 : {
836 : case E_DIALOG : {
837 : // Decrease ref count for dialog data container first.
838 132 : --m_nRefCount_Dialogs;
839 : // If these instance the last user of the dialog data container - delete these impl static container!
840 132 : if( m_nRefCount_Dialogs == 0 )
841 : {
842 83 : delete m_pDataContainer_Dialogs;
843 83 : m_pDataContainer_Dialogs = NULL;
844 : }
845 : }
846 132 : break;
847 : case E_TABDIALOG : {
848 : // Decrease ref count for tab-dialog data container first.
849 132 : --m_nRefCount_TabDialogs;
850 : // If these instance the last user of the tab-dialog data container - delete these impl static container!
851 132 : if( m_nRefCount_TabDialogs == 0 )
852 : {
853 83 : delete m_pDataContainer_TabDialogs;
854 83 : m_pDataContainer_TabDialogs = NULL;
855 : }
856 : }
857 132 : break;
858 : case E_TABPAGE : {
859 : // Decrease ref count for tab-page data container first.
860 132 : --m_nRefCount_TabPages;
861 : // If these instance the last user of the tab-page data container - delete these impl static container!
862 132 : if( m_nRefCount_TabPages == 0 )
863 : {
864 83 : delete m_pDataContainer_TabPages;
865 83 : m_pDataContainer_TabPages = NULL;
866 : }
867 : }
868 132 : break;
869 : case E_WINDOW : {
870 : // Decrease ref count for window data container first.
871 44856 : --m_nRefCount_Windows;
872 : // If these instance the last user of the window data container - delete these impl static container!
873 44856 : if( m_nRefCount_Windows == 0 )
874 : {
875 83 : delete m_pDataContainer_Windows;
876 83 : m_pDataContainer_Windows = NULL;
877 : }
878 : }
879 44856 : break;
880 45252 : }
881 45780 : }
882 :
883 : //*****************************************************************************************************************
884 : // public method
885 : //*****************************************************************************************************************
886 34584 : sal_Bool SvtViewOptions::Exists() const
887 : {
888 : // Ready for multithreading
889 34584 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
890 :
891 34584 : sal_Bool bExists = sal_False;
892 34584 : switch( m_eViewType )
893 : {
894 : case E_DIALOG : {
895 0 : bExists = m_pDataContainer_Dialogs->Exists( m_sViewName );
896 : }
897 0 : break;
898 : case E_TABDIALOG : {
899 0 : bExists = m_pDataContainer_TabDialogs->Exists( m_sViewName );
900 : }
901 0 : break;
902 : case E_TABPAGE : {
903 0 : bExists = m_pDataContainer_TabPages->Exists( m_sViewName );
904 : }
905 0 : break;
906 : case E_WINDOW : {
907 34584 : bExists = m_pDataContainer_Windows->Exists( m_sViewName );
908 : }
909 34584 : break;
910 : }
911 34584 : return bExists;
912 : }
913 :
914 : //*****************************************************************************************************************
915 : // public method
916 : //*****************************************************************************************************************
917 0 : sal_Bool SvtViewOptions::Delete()
918 : {
919 : // Ready for multithreading
920 0 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
921 :
922 0 : sal_Bool bState = sal_False;
923 0 : switch( m_eViewType )
924 : {
925 : case E_DIALOG : {
926 0 : bState = m_pDataContainer_Dialogs->Delete( m_sViewName );
927 : }
928 0 : break;
929 : case E_TABDIALOG : {
930 0 : bState = m_pDataContainer_TabDialogs->Delete( m_sViewName );
931 : }
932 0 : break;
933 : case E_TABPAGE : {
934 0 : bState = m_pDataContainer_TabPages->Delete( m_sViewName );
935 : }
936 0 : break;
937 : case E_WINDOW : {
938 0 : bState = m_pDataContainer_Windows->Delete( m_sViewName );
939 : }
940 0 : break;
941 : }
942 0 : return bState;
943 : }
944 :
945 : //*****************************************************************************************************************
946 : // public method
947 : //*****************************************************************************************************************
948 34584 : OUString SvtViewOptions::GetWindowState() const
949 : {
950 : // Ready for multithreading
951 34584 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
952 :
953 34584 : OUString sState;
954 34584 : switch( m_eViewType )
955 : {
956 : case E_DIALOG : {
957 0 : sState = m_pDataContainer_Dialogs->GetWindowState( m_sViewName );
958 : }
959 0 : break;
960 : case E_TABDIALOG : {
961 0 : sState = m_pDataContainer_TabDialogs->GetWindowState( m_sViewName );
962 : }
963 0 : break;
964 : case E_TABPAGE : {
965 0 : sState = m_pDataContainer_TabPages->GetWindowState( m_sViewName );
966 : }
967 0 : break;
968 : case E_WINDOW : {
969 34584 : sState = m_pDataContainer_Windows->GetWindowState( m_sViewName );
970 : }
971 34584 : break;
972 : }
973 34584 : return sState;
974 : }
975 :
976 : //*****************************************************************************************************************
977 : // public method
978 : //*****************************************************************************************************************
979 1491 : void SvtViewOptions::SetWindowState( const OUString& sState )
980 : {
981 : // Ready for multithreading
982 1491 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
983 :
984 1491 : switch( m_eViewType )
985 : {
986 : case E_DIALOG : {
987 0 : m_pDataContainer_Dialogs->SetWindowState( m_sViewName, sState );
988 : }
989 0 : break;
990 : case E_TABDIALOG : {
991 0 : m_pDataContainer_TabDialogs->SetWindowState( m_sViewName, sState );
992 : }
993 0 : break;
994 : case E_TABPAGE : {
995 0 : m_pDataContainer_TabPages->SetWindowState( m_sViewName, sState );
996 : }
997 0 : break;
998 : case E_WINDOW : {
999 1491 : m_pDataContainer_Windows->SetWindowState( m_sViewName, sState );
1000 : }
1001 1491 : break;
1002 1491 : }
1003 1491 : }
1004 :
1005 : //*****************************************************************************************************************
1006 : // public method
1007 : //*****************************************************************************************************************
1008 0 : sal_Int32 SvtViewOptions::GetPageID() const
1009 : {
1010 : // Ready for multithreading
1011 0 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1012 :
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" );
1016 :
1017 0 : sal_Int32 nID = 0;
1018 0 : if( m_eViewType == E_TABDIALOG )
1019 0 : nID = m_pDataContainer_TabDialogs->GetPageID( m_sViewName );
1020 0 : return nID;
1021 : }
1022 :
1023 : //*****************************************************************************************************************
1024 : // public method
1025 : //*****************************************************************************************************************
1026 0 : void SvtViewOptions::SetPageID( sal_Int32 nID )
1027 : {
1028 : // Ready for multithreading
1029 0 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1030 :
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" );
1034 :
1035 0 : if( m_eViewType == E_TABDIALOG )
1036 0 : m_pDataContainer_TabDialogs->SetPageID( m_sViewName, nID );
1037 0 : }
1038 :
1039 : //*****************************************************************************************************************
1040 : // public method
1041 : //*****************************************************************************************************************
1042 1044 : sal_Bool SvtViewOptions::IsVisible() const
1043 : {
1044 : // Ready for multithreading
1045 1044 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1046 :
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" );
1050 :
1051 1044 : sal_Bool bState = sal_False;
1052 1044 : if( m_eViewType == E_WINDOW )
1053 1044 : bState = m_pDataContainer_Windows->GetVisible( m_sViewName ) == SvtViewOptionsBase_Impl::STATE_TRUE;
1054 :
1055 1044 : return bState;
1056 : }
1057 :
1058 : //*****************************************************************************************************************
1059 : // public method
1060 : //*****************************************************************************************************************
1061 0 : void SvtViewOptions::SetVisible( sal_Bool bState )
1062 : {
1063 : // Ready for multithreading
1064 0 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1065 :
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" );
1069 :
1070 0 : if( m_eViewType == E_WINDOW )
1071 0 : m_pDataContainer_Windows->SetVisible( m_sViewName, bState );
1072 0 : }
1073 :
1074 : //*****************************************************************************************************************
1075 : // public method
1076 : //*****************************************************************************************************************
1077 2281 : bool SvtViewOptions::HasVisible() const
1078 : {
1079 : // Ready for multithreading
1080 2281 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1081 :
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" );
1085 :
1086 2281 : bool bState = false;
1087 2281 : if( m_eViewType == E_WINDOW )
1088 2281 : bState = m_pDataContainer_Windows->GetVisible( m_sViewName ) != SvtViewOptionsBase_Impl::STATE_NONE;
1089 :
1090 2281 : return bState;
1091 : }
1092 :
1093 : //*****************************************************************************************************************
1094 34584 : css::uno::Sequence< css::beans::NamedValue > SvtViewOptions::GetUserData() const
1095 : {
1096 : // Ready for multithreading
1097 34584 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1098 :
1099 34584 : css::uno::Sequence< css::beans::NamedValue > lData;
1100 34584 : switch( m_eViewType )
1101 : {
1102 : case E_DIALOG : {
1103 0 : lData = m_pDataContainer_Dialogs->GetUserData( m_sViewName );
1104 : }
1105 0 : break;
1106 : case E_TABDIALOG : {
1107 0 : lData = m_pDataContainer_TabDialogs->GetUserData( m_sViewName );
1108 : }
1109 0 : break;
1110 : case E_TABPAGE : {
1111 0 : lData = m_pDataContainer_TabPages->GetUserData( m_sViewName );
1112 : }
1113 0 : break;
1114 : case E_WINDOW : {
1115 34584 : lData = m_pDataContainer_Windows->GetUserData( m_sViewName );
1116 : }
1117 34584 : break;
1118 : }
1119 34584 : return lData;
1120 : }
1121 :
1122 : //*****************************************************************************************************************
1123 1491 : void SvtViewOptions::SetUserData( const css::uno::Sequence< css::beans::NamedValue >& lData )
1124 : {
1125 : // Ready for multithreading
1126 1491 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1127 :
1128 1491 : switch( m_eViewType )
1129 : {
1130 : case E_DIALOG : {
1131 0 : m_pDataContainer_Dialogs->SetUserData( m_sViewName, lData );
1132 : }
1133 0 : break;
1134 : case E_TABDIALOG : {
1135 0 : m_pDataContainer_TabDialogs->SetUserData( m_sViewName, lData );
1136 : }
1137 0 : break;
1138 : case E_TABPAGE : {
1139 0 : m_pDataContainer_TabPages->SetUserData( m_sViewName, lData );
1140 : }
1141 0 : break;
1142 : case E_WINDOW : {
1143 1491 : m_pDataContainer_Windows->SetUserData( m_sViewName, lData );
1144 : }
1145 1491 : break;
1146 1491 : }
1147 1491 : }
1148 :
1149 : //*****************************************************************************************************************
1150 4328 : css::uno::Any SvtViewOptions::GetUserItem( const OUString& sName ) const
1151 : {
1152 : // Ready for multithreading
1153 4328 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1154 :
1155 4328 : css::uno::Any aItem;
1156 4328 : switch( m_eViewType )
1157 : {
1158 : case E_DIALOG : {
1159 0 : aItem = m_pDataContainer_Dialogs->GetUserItem( m_sViewName, sName );
1160 : }
1161 0 : break;
1162 : case E_TABDIALOG : {
1163 0 : aItem = m_pDataContainer_TabDialogs->GetUserItem( m_sViewName, sName );
1164 : }
1165 0 : break;
1166 : case E_TABPAGE : {
1167 0 : aItem = m_pDataContainer_TabPages->GetUserItem( m_sViewName, sName );
1168 : }
1169 0 : break;
1170 : case E_WINDOW : {
1171 4328 : aItem = m_pDataContainer_Windows->GetUserItem( m_sViewName, sName );
1172 : }
1173 4328 : break;
1174 : }
1175 4328 : return aItem;
1176 : }
1177 :
1178 : //*****************************************************************************************************************
1179 4321 : void SvtViewOptions::SetUserItem( const OUString& sName ,
1180 : const css::uno::Any& aValue )
1181 : {
1182 : // Ready for multithreading
1183 4321 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1184 :
1185 4321 : switch( m_eViewType )
1186 : {
1187 : case E_DIALOG : {
1188 0 : m_pDataContainer_Dialogs->SetUserItem( m_sViewName, sName, aValue );
1189 : }
1190 0 : break;
1191 : case E_TABDIALOG : {
1192 0 : m_pDataContainer_TabDialogs->SetUserItem( m_sViewName, sName, aValue );
1193 : }
1194 0 : break;
1195 : case E_TABPAGE : {
1196 0 : m_pDataContainer_TabPages->SetUserItem( m_sViewName, sName, aValue );
1197 : }
1198 0 : break;
1199 : case E_WINDOW : {
1200 4321 : m_pDataContainer_Windows->SetUserItem( m_sViewName, sName, aValue );
1201 : }
1202 4321 : break;
1203 4321 : }
1204 4321 : }
1205 :
1206 : namespace
1207 : {
1208 : class theViewOptionsMutex : public rtl::Static<osl::Mutex, theViewOptionsMutex>{};
1209 : }
1210 :
1211 : //*****************************************************************************************************************
1212 : // private method
1213 : //*****************************************************************************************************************
1214 209432 : ::osl::Mutex& SvtViewOptions::GetOwnStaticMutex()
1215 : {
1216 209432 : return theViewOptionsMutex::get();
1217 : }
1218 :
1219 133 : void SvtViewOptions::AcquireOptions()
1220 : {
1221 133 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1222 133 : if( ++m_nRefCount_Dialogs == 1 )
1223 : {
1224 133 : m_pDataContainer_Dialogs = new SvtViewOptionsBase_Impl( LIST_DIALOGS );
1225 133 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_DIALOG);
1226 : }
1227 133 : if( ++m_nRefCount_TabDialogs == 1 )
1228 : {
1229 133 : m_pDataContainer_TabDialogs = new SvtViewOptionsBase_Impl( LIST_TABDIALOGS );
1230 133 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABDIALOG);
1231 : }
1232 133 : if( ++m_nRefCount_TabPages == 1 )
1233 : {
1234 133 : m_pDataContainer_TabPages = new SvtViewOptionsBase_Impl( LIST_TABPAGES );
1235 133 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_TABPAGE);
1236 : }
1237 133 : if( ++m_nRefCount_Windows == 1 )
1238 : {
1239 133 : m_pDataContainer_Windows = new SvtViewOptionsBase_Impl( LIST_WINDOWS );
1240 133 : ItemHolder1::holdConfigItem(E_VIEWOPTIONS_WINDOW);
1241 133 : }
1242 133 : }
1243 :
1244 83 : void SvtViewOptions::ReleaseOptions()
1245 : {
1246 83 : ::osl::MutexGuard aGuard( GetOwnStaticMutex() );
1247 83 : if( --m_nRefCount_Dialogs == 0 )
1248 : {
1249 0 : delete m_pDataContainer_Dialogs;
1250 0 : m_pDataContainer_Dialogs = NULL;
1251 : }
1252 83 : if( --m_nRefCount_TabDialogs == 0 )
1253 : {
1254 0 : delete m_pDataContainer_TabDialogs;
1255 0 : m_pDataContainer_TabDialogs = NULL;
1256 : }
1257 83 : if( --m_nRefCount_TabPages == 0 )
1258 : {
1259 0 : delete m_pDataContainer_TabPages;
1260 0 : m_pDataContainer_TabPages = NULL;
1261 : }
1262 83 : if( --m_nRefCount_Windows == 0 )
1263 : {
1264 0 : delete m_pDataContainer_Windows;
1265 0 : m_pDataContainer_Windows = NULL;
1266 83 : }
1267 83 : }
1268 :
1269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|