Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svtools/menuoptions.hxx>
31 : : #include <unotools/configmgr.hxx>
32 : : #include <unotools/configitem.hxx>
33 : : #include <tools/debug.hxx>
34 : : #include <com/sun/star/uno/Any.hxx>
35 : : #include <com/sun/star/uno/Sequence.hxx>
36 : : #include <vcl/svapp.hxx>
37 : :
38 : : #include <rtl/logfile.hxx>
39 : : #include "itemholder2.hxx"
40 : :
41 : : #include <list>
42 : :
43 : : //_________________________________________________________________________________________________________________
44 : : // namespaces
45 : : //_________________________________________________________________________________________________________________
46 : :
47 : : using namespace ::utl ;
48 : : using namespace ::rtl ;
49 : : using namespace ::osl ;
50 : : using namespace ::com::sun::star::uno ;
51 : :
52 : : #define ROOTNODE_MENU OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/View/Menu" ))
53 : : #define DEFAULT_DONTHIDEDISABLEDENTRIES sal_False
54 : : #define DEFAULT_FOLLOWMOUSE sal_True
55 : : #define DEFAULT_MENUICONS 2
56 : :
57 : : #define PROPERTYNAME_DONTHIDEDISABLEDENTRIES OUString(RTL_CONSTASCII_USTRINGPARAM("DontHideDisabledEntry" ))
58 : : #define PROPERTYNAME_FOLLOWMOUSE OUString(RTL_CONSTASCII_USTRINGPARAM("FollowMouse" ))
59 : : #define PROPERTYNAME_SHOWICONSINMENUES OUString(RTL_CONSTASCII_USTRINGPARAM("ShowIconsInMenues" ))
60 : : #define PROPERTYNAME_SYSTEMICONSINMENUES OUString(RTL_CONSTASCII_USTRINGPARAM("IsSystemIconsInMenus" ))
61 : :
62 : : #define PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES 0
63 : : #define PROPERTYHANDLE_FOLLOWMOUSE 1
64 : : #define PROPERTYHANDLE_SHOWICONSINMENUES 2
65 : : #define PROPERTYHANDLE_SYSTEMICONSINMENUES 3
66 : :
67 : : #define PROPERTYCOUNT 4
68 : :
69 : : #include <tools/link.hxx>
70 : :
71 : : //_________________________________________________________________________________________________________________
72 : : // private declarations!
73 : : //_________________________________________________________________________________________________________________
74 : :
75 : : class SvtMenuOptions_Impl : public ConfigItem
76 : : {
77 : : //-------------------------------------------------------------------------------------------------------------
78 : : // private member
79 : : //-------------------------------------------------------------------------------------------------------------
80 : :
81 : : private:
82 : : ::std::list<Link> aList;
83 : : sal_Bool m_bDontHideDisabledEntries ; /// cache "DontHideDisabledEntries" of Menu section
84 : : sal_Bool m_bFollowMouse ; /// cache "FollowMouse" of Menu section
85 : : sal_Int16 m_nMenuIcons ; /// cache "MenuIcons" of Menu section
86 : :
87 : : //-------------------------------------------------------------------------------------------------------------
88 : : // public methods
89 : : //-------------------------------------------------------------------------------------------------------------
90 : :
91 : : public:
92 : :
93 : : //---------------------------------------------------------------------------------------------------------
94 : : // constructor / destructor
95 : : //---------------------------------------------------------------------------------------------------------
96 : :
97 : : SvtMenuOptions_Impl();
98 : : ~SvtMenuOptions_Impl();
99 : :
100 : : void AddListenerLink( const Link& rLink );
101 : : void RemoveListenerLink( const Link& rLink );
102 : :
103 : : //---------------------------------------------------------------------------------------------------------
104 : : // overloaded methods of baseclass
105 : : //---------------------------------------------------------------------------------------------------------
106 : :
107 : : /*-****************************************************************************************************//**
108 : : @short called for notify of configmanager
109 : : @descr These method is called from the ConfigManager before application ends or from the
110 : : PropertyChangeListener if the sub tree broadcasts changes. You must update your
111 : : internal values.
112 : :
113 : : @seealso baseclass ConfigItem
114 : :
115 : : @param "seqPropertyNames" is the list of properties which should be updated.
116 : : @return -
117 : :
118 : : @onerror -
119 : : *//*-*****************************************************************************************************/
120 : :
121 : : virtual void Notify( const Sequence< OUString >& seqPropertyNames );
122 : :
123 : : /*-****************************************************************************************************//**
124 : : @short write changes to configuration
125 : : @descr These method writes the changed values into the sub tree
126 : : and should always called in our destructor to guarantee consistency of config data.
127 : :
128 : : @seealso baseclass ConfigItem
129 : :
130 : : @param -
131 : : @return -
132 : :
133 : : @onerror -
134 : : *//*-*****************************************************************************************************/
135 : :
136 : : virtual void Commit();
137 : :
138 : : //---------------------------------------------------------------------------------------------------------
139 : : // public interface
140 : : //---------------------------------------------------------------------------------------------------------
141 : :
142 : : /*-****************************************************************************************************//**
143 : : @short access method to get internal values
144 : : @descr These methods give us a chance to regulate access to our internal values.
145 : : It's not used in the moment - but it's possible for the future!
146 : :
147 : : @seealso -
148 : :
149 : : @param -
150 : : @return -
151 : :
152 : : @onerror -
153 : : *//*-*****************************************************************************************************/
154 : :
155 : 36 : sal_Bool IsEntryHidingEnabled() const
156 : 36 : { return m_bDontHideDisabledEntries; }
157 : :
158 : : sal_Bool IsFollowMouseEnabled() const
159 : : { return m_bFollowMouse; }
160 : :
161 : 316 : sal_Int16 GetMenuIconsState() const
162 : 316 : { return m_nMenuIcons; }
163 : :
164 : : void SetEntryHidingState ( sal_Bool bState )
165 : : {
166 : : m_bDontHideDisabledEntries = bState;
167 : : SetModified();
168 : : for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
169 : : iter->Call( this );
170 : : Commit();
171 : : }
172 : :
173 : : void SetFollowMouseState ( sal_Bool bState )
174 : : {
175 : : m_bFollowMouse = bState;
176 : : SetModified();
177 : : for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
178 : : iter->Call( this );
179 : : Commit();
180 : : }
181 : :
182 : 0 : void SetMenuIconsState ( sal_Int16 nState )
183 : : {
184 : 0 : m_nMenuIcons = nState;
185 : 0 : SetModified();
186 [ # # ][ # # ]: 0 : for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
[ # # ][ # # ]
[ # # ]
187 [ # # ][ # # ]: 0 : iter->Call( this );
188 : 0 : Commit();
189 : 0 : }
190 : :
191 : : //-------------------------------------------------------------------------------------------------------------
192 : : // private methods
193 : : //-------------------------------------------------------------------------------------------------------------
194 : :
195 : : private:
196 : :
197 : : /*-****************************************************************************************************//**
198 : : @short return list of fix key names of our configuration management which represent our module tree
199 : : @descr These methods return a static const list of key names. We need it to get needed values from our
200 : : configuration management.
201 : :
202 : : @seealso -
203 : :
204 : : @param -
205 : : @return A list of needed configuration keys is returned.
206 : :
207 : : @onerror -
208 : : *//*-*****************************************************************************************************/
209 : :
210 : : static Sequence< OUString > impl_GetPropertyNames();
211 : : };
212 : :
213 : : //*****************************************************************************************************************
214 : : // constructor
215 : : //*****************************************************************************************************************
216 : 158 : SvtMenuOptions_Impl::SvtMenuOptions_Impl()
217 : : // Init baseclasses first
218 : : : ConfigItem ( ROOTNODE_MENU )
219 : : // Init member then.
220 : : , m_bDontHideDisabledEntries ( DEFAULT_DONTHIDEDISABLEDENTRIES )
221 : : , m_bFollowMouse ( DEFAULT_FOLLOWMOUSE )
222 [ + - ][ + - ]: 158 : , m_nMenuIcons ( DEFAULT_MENUICONS )
223 : : {
224 : : // Use our static list of configuration keys to get his values.
225 [ + - ]: 158 : Sequence< OUString > seqNames = impl_GetPropertyNames();
226 [ + - ]: 158 : Sequence< Any > seqValues = GetProperties( seqNames ) ;
227 : :
228 : : // Safe impossible cases.
229 : : // We need values from ALL configuration keys.
230 : : // Follow assignment use order of values in relation to our list of key names!
231 : : DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nI miss some values of configuration keys!\n" );
232 : :
233 : 158 : sal_Bool bMenuIcons = sal_True;
234 : 158 : sal_Bool bSystemMenuIcons = sal_True;
235 [ + - ]: 158 : if (m_nMenuIcons == 2)
236 [ + - ]: 158 : bMenuIcons = (sal_Bool)(Application::GetSettings().GetStyleSettings().GetPreferredUseImagesInMenus());
237 : : else
238 : : {
239 : 0 : bSystemMenuIcons = sal_False;
240 [ # # ]: 0 : bMenuIcons = m_nMenuIcons ? sal_True : sal_False;
241 : : }
242 : :
243 : : // Copy values from list in right order to our internal member.
244 : 158 : sal_Int32 nPropertyCount = seqValues.getLength() ;
245 : 158 : sal_Int32 nProperty = 0 ;
246 [ + + ]: 790 : for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
247 : : {
248 : : // Safe impossible cases.
249 : : // Check any for valid value.
250 : : DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nInvalid property value for property detected!\n" );
251 : :
252 [ + - ][ - + ]: 632 : if (!seqValues[nProperty].hasValue())
253 : 0 : continue;
254 : :
255 [ + + + + : 632 : switch( nProperty )
- ]
256 : : {
257 : : case PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES : {
258 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\DontHideDisabledEntry\"?" );
259 [ + - ]: 158 : seqValues[nProperty] >>= m_bDontHideDisabledEntries;
260 : : }
261 : 158 : break;
262 : :
263 : : case PROPERTYHANDLE_FOLLOWMOUSE : {
264 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\FollowMouse\"?" );
265 [ + - ]: 158 : seqValues[nProperty] >>= m_bFollowMouse;
266 : : }
267 : 158 : break;
268 : : case PROPERTYHANDLE_SHOWICONSINMENUES : {
269 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShowIconsInMenues\"?" );
270 [ + - ]: 158 : seqValues[nProperty] >>= bMenuIcons;
271 : : }
272 : 158 : break;
273 : : case PROPERTYHANDLE_SYSTEMICONSINMENUES : {
274 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\IsSystemIconsInMenus\"?" );
275 [ + - ]: 158 : seqValues[nProperty] >>= bSystemMenuIcons;
276 : : }
277 : 158 : break;
278 : : }
279 : : }
280 : :
281 [ - + ]: 158 : m_nMenuIcons = bSystemMenuIcons ? 2 : bMenuIcons;
282 : :
283 [ + - ][ + - ]: 158 : EnableNotification( seqNames );
[ + - ]
284 : 158 : }
285 : :
286 : : //*****************************************************************************************************************
287 : : // destructor
288 : : //*****************************************************************************************************************
289 : 158 : SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
290 : : {
291 : : // Flush data to configuration!
292 : : // User has no chance to do that.
293 [ + - ][ - + ]: 158 : if( IsModified() == sal_True )
294 : : {
295 [ # # ]: 0 : Commit();
296 : : }
297 [ - + ]: 316 : }
298 : :
299 : : //*****************************************************************************************************************
300 : : // public method
301 : : //*****************************************************************************************************************
302 : 0 : void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
303 : : {
304 : : // Use given list of updated properties to get his values from configuration directly!
305 [ # # ]: 0 : Sequence< Any > seqValues = GetProperties( seqPropertyNames );
306 : : // Safe impossible cases.
307 : : // We need values from ALL notified configuration keys.
308 : : DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtMenuOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
309 : :
310 : 0 : sal_Bool bMenuSettingsChanged = sal_False;
311 : 0 : sal_Bool bMenuIcons = sal_True;
312 : 0 : sal_Bool bSystemMenuIcons = sal_True;
313 [ # # ]: 0 : if (m_nMenuIcons == 2)
314 [ # # ][ # # ]: 0 : bMenuIcons = (sal_Bool)(Application::GetSettings().GetStyleSettings().GetUseImagesInMenus());
315 : : else
316 : : {
317 : 0 : bSystemMenuIcons = sal_False;
318 [ # # ]: 0 : bMenuIcons = m_nMenuIcons ? sal_True : sal_False;
319 : : }
320 : :
321 : : // Step over list of property names and get right value from coreesponding value list to set it on internal members!
322 : 0 : sal_Int32 nCount = seqPropertyNames.getLength();
323 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
324 : : {
325 [ # # ][ # # ]: 0 : if( seqPropertyNames[nProperty] == PROPERTYNAME_DONTHIDEDISABLEDENTRIES )
326 : : {
327 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\View\\Menu\\DontHideDisabledEntry\"?" );
328 [ # # ]: 0 : seqValues[nProperty] >>= m_bDontHideDisabledEntries;
329 : : }
330 [ # # ][ # # ]: 0 : else if( seqPropertyNames[nProperty] == PROPERTYNAME_FOLLOWMOUSE )
331 : : {
332 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\View\\Menu\\FollowMouse\"?" );
333 [ # # ]: 0 : seqValues[nProperty] >>= m_bFollowMouse;
334 : : }
335 [ # # ][ # # ]: 0 : else if( seqPropertyNames[nProperty] == PROPERTYNAME_SHOWICONSINMENUES )
336 : : {
337 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\ShowIconsInMenues\"?" );
338 [ # # ]: 0 : bMenuSettingsChanged |= seqValues[nProperty] >>= bMenuIcons;
339 : : }
340 [ # # ][ # # ]: 0 : else if( seqPropertyNames[nProperty] == PROPERTYNAME_SYSTEMICONSINMENUES )
341 : : {
342 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtMenuOptions_Impl::SvtMenuOptions_Impl()\nWho has changed the value type of \"Office.Common\\View\\Menu\\IsSystemIconsInMenus\"?" );
343 [ # # ]: 0 : bMenuSettingsChanged |= seqValues[nProperty] >>= bSystemMenuIcons;
344 : : }
345 : :
346 : : #if OSL_DEBUG_LEVEL > 1
347 : : else DBG_ASSERT( sal_False, "SvtMenuOptions_Impl::Notify()\nUnkown property detected ... I can't handle these!\n" );
348 : : #endif
349 : : }
350 : :
351 [ # # ]: 0 : if ( bMenuSettingsChanged )
352 [ # # ]: 0 : m_nMenuIcons = bSystemMenuIcons ? 2 : bMenuIcons;
353 : :
354 [ # # ][ # # ]: 0 : for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
[ # # ][ # # ]
[ # # ]
355 [ # # ][ # # ]: 0 : iter->Call( this );
[ # # ]
356 : 0 : }
357 : :
358 : : //*****************************************************************************************************************
359 : : // public method
360 : : //*****************************************************************************************************************
361 : 0 : void SvtMenuOptions_Impl::Commit()
362 : : {
363 : : // Get names of supported properties, create a list for values and copy current values to it.
364 [ # # ]: 0 : Sequence< OUString > seqNames = impl_GetPropertyNames();
365 : 0 : sal_Int32 nCount = seqNames.getLength();
366 [ # # ]: 0 : Sequence< Any > seqValues ( nCount );
367 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
368 : : {
369 [ # # # # : 0 : switch( nProperty )
# ]
370 : : {
371 : : case PROPERTYHANDLE_DONTHIDEDISABLEDENTRIES : {
372 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= m_bDontHideDisabledEntries;
373 : : }
374 : 0 : break;
375 : :
376 : : case PROPERTYHANDLE_FOLLOWMOUSE : {
377 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= m_bFollowMouse;
378 : : }
379 : 0 : break;
380 : : //Output cache of current setting as possibly modified by System Theme for older version
381 : : case PROPERTYHANDLE_SHOWICONSINMENUES : {
382 [ # # ][ # # ]: 0 : sal_Bool bValue = (sal_Bool)(Application::GetSettings().GetStyleSettings().GetUseImagesInMenus());
383 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= bValue;
384 : : }
385 : 0 : break;
386 : : case PROPERTYHANDLE_SYSTEMICONSINMENUES : {
387 [ # # ]: 0 : sal_Bool bValue = (m_nMenuIcons == 2 ? sal_True : sal_False) ;
388 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= bValue;
389 : : }
390 : 0 : break;
391 : : }
392 : : }
393 : : // Set properties in configuration.
394 [ # # ][ # # ]: 0 : PutProperties( seqNames, seqValues );
[ # # ]
395 : 0 : }
396 : :
397 : : //*****************************************************************************************************************
398 : : // private method
399 : : //*****************************************************************************************************************
400 : 158 : Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames()
401 : : {
402 : : // Build static list of configuration key names.
403 : : static const OUString pProperties[] =
404 : : {
405 : : PROPERTYNAME_DONTHIDEDISABLEDENTRIES ,
406 : : PROPERTYNAME_FOLLOWMOUSE ,
407 : : PROPERTYNAME_SHOWICONSINMENUES ,
408 : : PROPERTYNAME_SYSTEMICONSINMENUES
409 [ + - ][ + - ]: 948 : };
[ + - ][ + - ]
[ + - ][ + - ]
[ # # # #
# # ][ + + ]
410 : : // Initialize return sequence with these list ...
411 [ + - ][ + - ]: 158 : static const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
[ + - ][ # # ]
412 : : // ... and return it.
413 : 158 : return seqPropertyNames;
414 : : }
415 : :
416 : 0 : void SvtMenuOptions_Impl::AddListenerLink( const Link& rLink )
417 : : {
418 : 0 : aList.push_back( rLink );
419 : 0 : }
420 : :
421 : 0 : void SvtMenuOptions_Impl::RemoveListenerLink( const Link& rLink )
422 : : {
423 [ # # ][ # # ]: 0 : for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
[ # # ]
424 : : {
425 [ # # ][ # # ]: 0 : if ( *iter == rLink )
[ # # ]
426 : : {
427 [ # # ]: 0 : aList.erase(iter);
428 : 0 : break;
429 : : }
430 : : }
431 : 0 : }
432 : :
433 : : //*****************************************************************************************************************
434 : : // initialize static member
435 : : // DON'T DO IT IN YOUR HEADER!
436 : : // see definition for further informations
437 : : //*****************************************************************************************************************
438 : : SvtMenuOptions_Impl* SvtMenuOptions::m_pDataContainer = NULL ;
439 : : sal_Int32 SvtMenuOptions::m_nRefCount = 0 ;
440 : :
441 : : //*****************************************************************************************************************
442 : : // constructor
443 : : //*****************************************************************************************************************
444 : 510 : SvtMenuOptions::SvtMenuOptions()
445 : : {
446 : : // Global access, must be guarded (multithreading!).
447 [ + - ][ + - ]: 510 : MutexGuard aGuard( GetOwnStaticMutex() );
448 : : // Increase our refcount ...
449 : 510 : ++m_nRefCount;
450 : : // ... and initialize our data container only if it not already!
451 [ + + ]: 510 : if( m_pDataContainer == NULL )
452 : : {
453 : : RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtMenuOptions_Impl::ctor()");
454 [ + - ][ + - ]: 158 : m_pDataContainer = new SvtMenuOptions_Impl();
455 : :
456 [ + - ]: 158 : svtools::ItemHolder2::holdConfigItem(E_MENUOPTIONS);
457 [ + - ]: 510 : }
458 : 510 : }
459 : :
460 : : //*****************************************************************************************************************
461 : : // destructor
462 : : //*****************************************************************************************************************
463 : 510 : SvtMenuOptions::~SvtMenuOptions()
464 : : {
465 : : // Global access, must be guarded (multithreading!)
466 [ + - ][ + - ]: 510 : MutexGuard aGuard( GetOwnStaticMutex() );
467 : : // Decrease our refcount.
468 : 510 : --m_nRefCount;
469 : : // If last instance was deleted ...
470 : : // we must destroy our static data container!
471 [ + + ]: 510 : if( m_nRefCount <= 0 )
472 : : {
473 [ + - ][ + - ]: 158 : delete m_pDataContainer;
474 : 158 : m_pDataContainer = NULL;
475 [ + - ]: 510 : }
476 [ - + ]: 668 : }
477 : :
478 : : //*****************************************************************************************************************
479 : : // public method
480 : : //*****************************************************************************************************************
481 : 36 : sal_Bool SvtMenuOptions::IsEntryHidingEnabled() const
482 : : {
483 [ + - ][ + - ]: 36 : MutexGuard aGuard( GetOwnStaticMutex() );
484 [ + - ]: 36 : return m_pDataContainer->IsEntryHidingEnabled();
485 : : }
486 : :
487 : : //*****************************************************************************************************************
488 : : // public method
489 : : //*****************************************************************************************************************
490 : 316 : sal_Int16 SvtMenuOptions::GetMenuIconsState() const
491 : : {
492 [ + - ][ + - ]: 316 : MutexGuard aGuard( GetOwnStaticMutex() );
493 [ + - ]: 316 : return m_pDataContainer->GetMenuIconsState();
494 : : }
495 : :
496 : : //*****************************************************************************************************************
497 : : // public method
498 : : //*****************************************************************************************************************
499 : 0 : void SvtMenuOptions::SetMenuIconsState( sal_Int16 bState )
500 : : {
501 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
502 [ # # ][ # # ]: 0 : m_pDataContainer->SetMenuIconsState( bState );
503 : 0 : }
504 : :
505 : : //*****************************************************************************************************************
506 : : // private method
507 : : //*****************************************************************************************************************
508 : 1372 : Mutex& SvtMenuOptions::GetOwnStaticMutex()
509 : : {
510 : : // Initialize static mutex only for one time!
511 : : static Mutex* pMutex = NULL;
512 : : // If these method first called (Mutex not already exist!) ...
513 [ + + ]: 1372 : if( pMutex == NULL )
514 : : {
515 : : // ... we must create a new one. Protect follow code with the global mutex -
516 : : // It must be - we create a static variable!
517 [ + - ][ + - ]: 158 : MutexGuard aGuard( Mutex::getGlobalMutex() );
518 : : // We must check our pointer again - because it can be that another instance of our class will be faster than these!
519 [ + - ]: 158 : if( pMutex == NULL )
520 : : {
521 : : // Create the new mutex and set it for return on static variable.
522 [ + - ][ + - ]: 158 : static Mutex aMutex;
[ + - ][ # # ]
523 : 158 : pMutex = &aMutex;
524 [ + - ]: 158 : }
525 : : }
526 : : // Return new created or already existing mutex object.
527 : 1372 : return *pMutex;
528 : : }
529 : :
530 : 0 : void SvtMenuOptions::AddListenerLink( const Link& rLink )
531 : : {
532 : 0 : m_pDataContainer->AddListenerLink( rLink );
533 : 0 : }
534 : :
535 : 0 : void SvtMenuOptions::RemoveListenerLink( const Link& rLink )
536 : : {
537 : 0 : m_pDataContainer->RemoveListenerLink( rLink );
538 : 0 : }
539 : :
540 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|