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 <svtools/miscopt.hxx>
21 : #include <unotools/configmgr.hxx>
22 : #include <unotools/configitem.hxx>
23 : #include <tools/debug.hxx>
24 : #include <com/sun/star/uno/Any.hxx>
25 : #include <com/sun/star/uno/Sequence.hxx>
26 : #include <tools/link.hxx>
27 :
28 : #include <rtl/instance.hxx>
29 : #include "itemholder2.hxx"
30 :
31 : #include <svtools/imgdef.hxx>
32 : #include <vcl/svapp.hxx>
33 : #include <vcl/settings.hxx>
34 :
35 : #include <list>
36 :
37 : using namespace ::utl ;
38 : using namespace ::rtl ;
39 : using namespace ::osl ;
40 : using namespace ::com::sun::star::uno ;
41 : using namespace ::com::sun::star;
42 :
43 : #define ROOTNODE_MISC "Office.Common/Misc"
44 :
45 : // PROPERTYHANDLE defines must be sequential from zero for Commit/Load
46 : #define PROPERTYNAME_PLUGINSENABLED "PluginsEnabled"
47 : #define PROPERTYHANDLE_PLUGINSENABLED 0
48 : #define PROPERTYNAME_SYMBOLSET "SymbolSet"
49 : #define PROPERTYHANDLE_SYMBOLSET 1
50 : #define PROPERTYNAME_TOOLBOXSTYLE "ToolboxStyle"
51 : #define PROPERTYHANDLE_TOOLBOXSTYLE 2
52 : #define PROPERTYNAME_USESYSTEMFILEDIALOG "UseSystemFileDialog"
53 : #define PROPERTYHANDLE_USESYSTEMFILEDIALOG 3
54 : #define PROPERTYNAME_ICONTHEME "SymbolStyle"
55 : #define PROPERTYHANDLE_SYMBOLSTYLE 4
56 : #define PROPERTYNAME_USESYSTEMPRINTDIALOG "UseSystemPrintDialog"
57 : #define PROPERTYHANDLE_USESYSTEMPRINTDIALOG 5
58 : #define PROPERTYNAME_SHOWLINKWARNINGDIALOG "ShowLinkWarningDialog"
59 : #define PROPERTYHANDLE_SHOWLINKWARNINGDIALOG 6
60 : #define PROPERTYNAME_DISABLEUICUSTOMIZATION "DisableUICustomization"
61 : #define PROPERTYHANDLE_DISABLEUICUSTOMIZATION 7
62 : #define PROPERTYNAME_ALWAYSALLOWSAVE "AlwaysAllowSave"
63 : #define PROPERTYHANDLE_ALWAYSALLOWSAVE 8
64 : #define PROPERTYNAME_EXPERIMENTALMODE "ExperimentalMode"
65 : #define PROPERTYHANDLE_EXPERIMENTALMODE 9
66 : #define PROPERTYNAME_MACRORECORDERMODE "MacroRecorderMode"
67 : #define PROPERTYHANDLE_MACRORECORDERMODE 10
68 :
69 : #define VCL_TOOLBOX_STYLE_FLAT ((sal_uInt16)0x0004) // from <vcl/toolbox.hxx>
70 :
71 : class SvtMiscOptions_Impl : public ConfigItem
72 : {
73 : private:
74 : ::std::list<Link> aList;
75 : bool m_bUseSystemFileDialog;
76 : bool m_bIsUseSystemFileDialogRO;
77 : bool m_bPluginsEnabled;
78 : bool m_bIsPluginsEnabledRO;
79 : sal_Int16 m_nSymbolsSize;
80 : bool m_bIsSymbolsSizeRO;
81 : bool m_bIsSymbolsStyleRO;
82 : sal_Int16 m_nToolboxStyle;
83 : bool m_bIsToolboxStyleRO;
84 : bool m_bUseSystemPrintDialog;
85 : bool m_bIsUseSystemPrintDialogRO;
86 : bool m_bShowLinkWarningDialog;
87 : bool m_bIsShowLinkWarningDialogRO;
88 : bool m_bDisableUICustomization;
89 : bool m_bAlwaysAllowSave;
90 : bool m_bExperimentalMode;
91 : bool m_bMacroRecorderMode;
92 : bool m_bIconThemeWasSetAutomatically;
93 :
94 : public:
95 :
96 : SvtMiscOptions_Impl();
97 : virtual ~SvtMiscOptions_Impl();
98 :
99 : /*-****************************************************************************************************
100 : @short called for notify of configmanager
101 : @descr These method is called from the ConfigManager before application ends or from the
102 : PropertyChangeListener if the sub tree broadcasts changes. You must update your
103 : internal values.
104 :
105 : @seealso baseclass ConfigItem
106 :
107 : @param "seqPropertyNames" is the list of properties which should be updated.
108 : *//*-*****************************************************************************************************/
109 :
110 : virtual void Notify( const Sequence< OUString >& seqPropertyNames ) SAL_OVERRIDE;
111 :
112 : /** loads required data from the configuration. It's called in the constructor to
113 : read all entries and form ::Notify to re-read changed settings
114 :
115 : */
116 : void Load( const Sequence< OUString >& rPropertyNames );
117 :
118 : /*-****************************************************************************************************
119 : @short write changes to configuration
120 : @descr These method writes the changed values into the sub tree
121 : and should always called in our destructor to guarantee consistency of config data.
122 :
123 : @seealso baseclass ConfigItem
124 : *//*-*****************************************************************************************************/
125 :
126 : virtual void Commit() SAL_OVERRIDE;
127 :
128 :
129 : // public interface
130 :
131 :
132 0 : inline bool UseSystemFileDialog() const
133 0 : { return m_bUseSystemFileDialog; }
134 :
135 0 : inline void SetUseSystemFileDialog( bool bSet )
136 0 : { m_bUseSystemFileDialog = bSet; SetModified(); }
137 :
138 0 : inline bool IsUseSystemFileDialogReadOnly() const
139 0 : { return m_bIsUseSystemFileDialogRO; }
140 :
141 0 : inline bool DisableUICustomization() const
142 0 : { return m_bDisableUICustomization; }
143 :
144 0 : inline void SetSaveAlwaysAllowed( bool bSet )
145 0 : { m_bAlwaysAllowSave = bSet; SetModified(); }
146 :
147 0 : inline bool IsSaveAlwaysAllowed() const
148 0 : { return m_bAlwaysAllowSave; }
149 :
150 0 : inline void SetExperimentalMode( bool bSet )
151 0 : { m_bExperimentalMode = bSet; SetModified(); }
152 :
153 0 : inline bool IsExperimentalMode() const
154 0 : { return m_bExperimentalMode; }
155 :
156 0 : inline void SetMacroRecorderMode( bool bSet )
157 0 : { m_bMacroRecorderMode = bSet; SetModified(); }
158 :
159 0 : inline bool IsMacroRecorderMode() const
160 0 : { return m_bMacroRecorderMode; }
161 :
162 0 : inline bool IsPluginsEnabled() const
163 0 : { return m_bPluginsEnabled; }
164 :
165 0 : inline sal_Int16 GetSymbolsSize()
166 0 : { return m_nSymbolsSize; }
167 :
168 : void SetSymbolsSize( sal_Int16 nSet );
169 :
170 : OUString GetIconTheme() const;
171 :
172 : enum SetModifiedFlag { SET_MODIFIED, DONT_SET_MODIFIED };
173 :
174 : /** Set the icon theme
175 : *
176 : * @param theme
177 : * The name of the icon theme to use.
178 : *
179 : * @param setModified
180 : * Whether to call SetModified() and CallListeners().
181 : *
182 : * @internal
183 : * The @p setModified flag was introduced because the unittests fail if we call SetModified()
184 : * during initialization in the constructor.
185 : */
186 : void
187 : SetIconTheme(const OUString &theme, SetModifiedFlag setModified = SET_MODIFIED );
188 :
189 0 : bool IconThemeWasSetAutomatically()
190 0 : {return m_bIconThemeWasSetAutomatically;}
191 :
192 : /** Set the icon theme automatically by detecting the best theme for the desktop environment.
193 : * The parameter setModified controls whether SetModified() will be called.
194 : */
195 : void SetIconThemeAutomatically(SetModifiedFlag = SET_MODIFIED);
196 :
197 : // translate to VCL settings ( "0" = 3D, "1" = FLAT )
198 0 : inline sal_Int16 GetToolboxStyle()
199 0 : { return m_nToolboxStyle ? VCL_TOOLBOX_STYLE_FLAT : 0; }
200 :
201 : // translate from VCL settings
202 : void SetToolboxStyle( sal_Int16 nStyle, bool _bSetModified );
203 :
204 0 : inline bool UseSystemPrintDialog() const
205 0 : { return m_bUseSystemPrintDialog; }
206 :
207 0 : inline void SetUseSystemPrintDialog( bool bSet )
208 0 : { m_bUseSystemPrintDialog = bSet; SetModified(); }
209 :
210 0 : inline bool ShowLinkWarningDialog() const
211 0 : { return m_bShowLinkWarningDialog; }
212 :
213 0 : void SetShowLinkWarningDialog( bool bSet )
214 0 : { m_bShowLinkWarningDialog = bSet; SetModified(); }
215 :
216 0 : bool IsShowLinkWarningDialogReadOnly() const
217 0 : { return m_bIsShowLinkWarningDialogRO; }
218 :
219 : void AddListenerLink( const Link& rLink );
220 : void RemoveListenerLink( const Link& rLink );
221 : void CallListeners();
222 :
223 :
224 : // private methods
225 :
226 :
227 : private:
228 :
229 : /*-****************************************************************************************************
230 : @short return list of key names of our configuration management which represent oue module tree
231 : @descr These methods return a static const list of key names. We need it to get needed values from our
232 : configuration management.
233 : @return A list of needed configuration keys is returned.
234 : *//*-*****************************************************************************************************/
235 :
236 : static Sequence< OUString > GetPropertyNames();
237 : };
238 :
239 :
240 : // constructor
241 :
242 0 : SvtMiscOptions_Impl::SvtMiscOptions_Impl()
243 : // Init baseclasses first
244 : : ConfigItem( ROOTNODE_MISC )
245 :
246 : , m_bUseSystemFileDialog( false )
247 : , m_bIsUseSystemFileDialogRO( false )
248 : , m_bPluginsEnabled( false )
249 : , m_bIsPluginsEnabledRO( false )
250 : , m_nSymbolsSize( 0 )
251 : , m_bIsSymbolsSizeRO( false )
252 : , m_bIsSymbolsStyleRO( false )
253 : , m_nToolboxStyle( 1 )
254 : , m_bIsToolboxStyleRO( false )
255 : , m_bUseSystemPrintDialog( false )
256 : , m_bIsUseSystemPrintDialogRO( false )
257 : , m_bShowLinkWarningDialog( true )
258 : , m_bIsShowLinkWarningDialogRO( false )
259 : , m_bAlwaysAllowSave( false )
260 : , m_bExperimentalMode( false )
261 : , m_bMacroRecorderMode( false )
262 0 : , m_bIconThemeWasSetAutomatically( false )
263 : {
264 : // Use our static list of configuration keys to get his values.
265 0 : Sequence< OUString > seqNames = GetPropertyNames ( );
266 0 : Load( seqNames );
267 0 : Sequence< Any > seqValues = GetProperties ( seqNames );
268 0 : Sequence< sal_Bool > seqRO = GetReadOnlyStates ( seqNames );
269 :
270 : // Safe impossible cases.
271 : // We need values from ALL configuration keys.
272 : // Follow assignment use order of values in relation to our list of key names!
273 : DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtMiscOptions_Impl::SvtMiscOptions_Impl()\nI miss some values of configuration keys!\n" );
274 :
275 : // Copy values from list in right order to our internal member.
276 0 : sal_Int32 nPropertyCount = seqValues.getLength();
277 0 : for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
278 : {
279 0 : if (!seqValues[nProperty].hasValue())
280 0 : continue;
281 0 : switch( nProperty )
282 : {
283 : case PROPERTYHANDLE_PLUGINSENABLED :
284 : {
285 0 : if( !(seqValues[nProperty] >>= m_bPluginsEnabled) )
286 : {
287 : OSL_FAIL("Wrong type of \"Misc\\PluginsEnabled\"!" );
288 : }
289 0 : m_bIsPluginsEnabledRO = seqRO[nProperty];
290 0 : break;
291 : }
292 :
293 : case PROPERTYHANDLE_SYMBOLSET :
294 : {
295 0 : if( !(seqValues[nProperty] >>= m_nSymbolsSize) )
296 : {
297 : OSL_FAIL("Wrong type of \"Misc\\SymbolSet\"!" );
298 : }
299 0 : m_bIsSymbolsSizeRO = seqRO[nProperty];
300 0 : break;
301 : }
302 :
303 : case PROPERTYHANDLE_TOOLBOXSTYLE :
304 : {
305 0 : if( !(seqValues[nProperty] >>= m_nToolboxStyle) )
306 : {
307 : OSL_FAIL("Wrong type of \"Misc\\ToolboxStyle\"!" );
308 : }
309 0 : m_bIsToolboxStyleRO = seqRO[nProperty];
310 0 : break;
311 : }
312 :
313 : case PROPERTYHANDLE_USESYSTEMFILEDIALOG :
314 : {
315 0 : if( !(seqValues[nProperty] >>= m_bUseSystemFileDialog) )
316 : {
317 : OSL_FAIL("Wrong type of \"Misc\\UseSystemFileDialog\"!" );
318 : }
319 0 : m_bIsUseSystemFileDialogRO = seqRO[nProperty];
320 0 : break;
321 : }
322 :
323 : case PROPERTYHANDLE_USESYSTEMPRINTDIALOG :
324 : {
325 0 : if( !(seqValues[nProperty] >>= m_bUseSystemPrintDialog) )
326 : {
327 : OSL_FAIL("Wrong type of \"Misc\\UseSystemPrintDialog\"!" );
328 : }
329 0 : m_bIsUseSystemPrintDialogRO = seqRO[nProperty];
330 0 : break;
331 : }
332 :
333 : case PROPERTYHANDLE_SHOWLINKWARNINGDIALOG :
334 : {
335 0 : if( !(seqValues[nProperty] >>= m_bShowLinkWarningDialog) )
336 : {
337 : OSL_FAIL("Wrong type of \"Misc\\ShowLinkWarningDialog\"!" );
338 : }
339 0 : m_bIsShowLinkWarningDialogRO = seqRO[nProperty];
340 0 : break;
341 : }
342 :
343 : case PROPERTYHANDLE_SYMBOLSTYLE :
344 : {
345 0 : OUString aIconTheme;
346 0 : if( seqValues[nProperty] >>= aIconTheme ) {
347 0 : if (aIconTheme == "auto") {
348 0 : SetIconThemeAutomatically(DONT_SET_MODIFIED);
349 : }
350 : else {
351 0 : SetIconTheme(aIconTheme, DONT_SET_MODIFIED);
352 : }
353 : }
354 : else
355 : {
356 : OSL_FAIL("Wrong type of \"Misc\\SymbolStyle\"!" );
357 : }
358 0 : m_bIsSymbolsStyleRO = seqRO[nProperty];
359 0 : break;
360 : }
361 :
362 : case PROPERTYHANDLE_DISABLEUICUSTOMIZATION :
363 : {
364 0 : if( !(seqValues[nProperty] >>= m_bDisableUICustomization) )
365 : OSL_FAIL("Wrong type of \"Misc\\DisableUICustomization\"!" );
366 0 : break;
367 : }
368 : case PROPERTYHANDLE_ALWAYSALLOWSAVE :
369 : {
370 0 : if( !(seqValues[nProperty] >>= m_bAlwaysAllowSave) )
371 : OSL_FAIL("Wrong type of \"Misc\\AlwaysAllowSave\"!" );
372 0 : break;
373 : }
374 : case PROPERTYHANDLE_EXPERIMENTALMODE :
375 : {
376 0 : if( !(seqValues[nProperty] >>= m_bExperimentalMode) )
377 : OSL_FAIL("Wrong type of \"Misc\\ExperimentalMode\"!" );
378 0 : break;
379 : }
380 : case PROPERTYHANDLE_MACRORECORDERMODE :
381 : {
382 0 : if( !(seqValues[nProperty] >>= m_bMacroRecorderMode) )
383 : OSL_FAIL("Wrong type of \"Misc\\MacroRecorderMode\"!" );
384 0 : break;
385 : }
386 : }
387 : }
388 :
389 : // Enable notification mechanism of our baseclass.
390 : // We need it to get information about changes outside these class on our used configuration keys!
391 0 : EnableNotification( seqNames );
392 0 : }
393 :
394 :
395 : // destructor
396 :
397 0 : SvtMiscOptions_Impl::~SvtMiscOptions_Impl()
398 : {
399 : // We must save our current values .. if user forgets it!
400 0 : if( IsModified() )
401 : {
402 0 : Commit();
403 : }
404 0 : }
405 :
406 0 : static int lcl_MapPropertyName( const OUString& rCompare,
407 : const uno::Sequence< OUString>& aInternalPropertyNames)
408 : {
409 0 : for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
410 : {
411 0 : if( aInternalPropertyNames[nProp] == rCompare )
412 0 : return nProp;
413 : }
414 0 : return -1;
415 : }
416 :
417 0 : void SvtMiscOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
418 : {
419 0 : const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
420 0 : Sequence< Any > seqValues = GetProperties( rPropertyNames );
421 :
422 : // Safe impossible cases.
423 : // We need values from ALL configuration keys.
424 : // Follow assignment use order of values in relation to our list of key names!
425 : DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()), "SvtSecurityOptions_Impl::SvtSecurityOptions_Impl()\nI miss some values of configuration keys!\n" );
426 :
427 : // Copy values from list in right order to our internal member.
428 0 : sal_Int32 nPropertyCount = seqValues.getLength();
429 0 : for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
430 : {
431 0 : if (!seqValues[nProperty].hasValue())
432 0 : continue;
433 0 : switch( lcl_MapPropertyName(rPropertyNames[nProperty], aInternalPropertyNames) )
434 : {
435 : case PROPERTYHANDLE_PLUGINSENABLED : {
436 0 : if( !(seqValues[nProperty] >>= m_bPluginsEnabled) )
437 : {
438 : OSL_FAIL("Wrong type of \"Misc\\PluginsEnabled\"!" );
439 : }
440 : }
441 0 : break;
442 : case PROPERTYHANDLE_SYMBOLSET : {
443 0 : if( !(seqValues[nProperty] >>= m_nSymbolsSize) )
444 : {
445 : OSL_FAIL("Wrong type of \"Misc\\SymbolSet\"!" );
446 : }
447 : }
448 0 : break;
449 : case PROPERTYHANDLE_TOOLBOXSTYLE : {
450 0 : if( !(seqValues[nProperty] >>= m_nToolboxStyle) )
451 : {
452 : OSL_FAIL("Wrong type of \"Misc\\ToolboxStyle\"!" );
453 : }
454 : }
455 0 : break;
456 : case PROPERTYHANDLE_USESYSTEMFILEDIALOG : {
457 0 : if( !(seqValues[nProperty] >>= m_bUseSystemFileDialog) )
458 : {
459 : OSL_FAIL("Wrong type of \"Misc\\UseSystemFileDialog\"!" );
460 : }
461 : }
462 0 : break;
463 : case PROPERTYHANDLE_USESYSTEMPRINTDIALOG : {
464 0 : if( !(seqValues[nProperty] >>= m_bUseSystemPrintDialog) )
465 : {
466 : OSL_FAIL("Wrong type of \"Misc\\UseSystemPrintDialog\"!" );
467 : }
468 : }
469 0 : break;
470 : case PROPERTYHANDLE_SHOWLINKWARNINGDIALOG : {
471 0 : if( !(seqValues[nProperty] >>= m_bShowLinkWarningDialog) )
472 : {
473 : OSL_FAIL("Wrong type of \"Misc\\ShowLinkWarningDialog\"!" );
474 : }
475 : }
476 0 : break;
477 : case PROPERTYHANDLE_SYMBOLSTYLE : {
478 0 : OUString aIconTheme;
479 0 : if( seqValues[nProperty] >>= aIconTheme ) {
480 0 : if (aIconTheme == "auto") {
481 0 : SetIconThemeAutomatically(DONT_SET_MODIFIED);
482 : }
483 : else {
484 0 : SetIconTheme(aIconTheme, DONT_SET_MODIFIED);
485 : }
486 : }
487 : else {
488 : OSL_FAIL("Wrong type of \"Misc\\SymbolStyle\"!" );
489 0 : }
490 : }
491 0 : break;
492 : case PROPERTYHANDLE_DISABLEUICUSTOMIZATION : {
493 0 : if( !(seqValues[nProperty] >>= m_bDisableUICustomization) )
494 : OSL_FAIL("Wrong type of \"Misc\\DisableUICustomization\"!" );
495 : }
496 0 : break;
497 : case PROPERTYHANDLE_ALWAYSALLOWSAVE:
498 : {
499 0 : if( !(seqValues[nProperty] >>= m_bAlwaysAllowSave) )
500 : OSL_FAIL("Wrong type of \"Misc\\AlwaysAllowSave\"!" );
501 : }
502 0 : break;
503 : }
504 0 : }
505 0 : }
506 :
507 0 : void SvtMiscOptions_Impl::AddListenerLink( const Link& rLink )
508 : {
509 0 : aList.push_back( rLink );
510 0 : }
511 :
512 0 : void SvtMiscOptions_Impl::RemoveListenerLink( const Link& rLink )
513 : {
514 0 : for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
515 : {
516 0 : if ( *iter == rLink )
517 : {
518 0 : aList.erase(iter);
519 0 : break;
520 : }
521 : }
522 0 : }
523 :
524 0 : void SvtMiscOptions_Impl::CallListeners()
525 : {
526 0 : for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
527 0 : iter->Call( this );
528 0 : }
529 :
530 0 : void SvtMiscOptions_Impl::SetToolboxStyle( sal_Int16 nStyle, bool _bSetModified )
531 : {
532 0 : m_nToolboxStyle = nStyle ? 1 : 0;
533 0 : if ( _bSetModified )
534 0 : SetModified();
535 0 : CallListeners();
536 0 : }
537 :
538 0 : void SvtMiscOptions_Impl::SetSymbolsSize( sal_Int16 nSet )
539 : {
540 0 : m_nSymbolsSize = nSet;
541 0 : SetModified();
542 0 : CallListeners();
543 0 : }
544 :
545 0 : OUString SvtMiscOptions_Impl::GetIconTheme() const
546 : {
547 0 : return Application::GetSettings().GetStyleSettings().DetermineIconTheme();
548 : }
549 :
550 : void
551 0 : SvtMiscOptions_Impl::SetIconTheme(const OUString &rName, SetModifiedFlag setModified)
552 : {
553 0 : AllSettings aAllSettings = Application::GetSettings();
554 0 : StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
555 0 : aStyleSettings.SetIconTheme( rName );
556 0 : m_bIconThemeWasSetAutomatically = false;
557 :
558 0 : aAllSettings.SetStyleSettings(aStyleSettings);
559 0 : Application::MergeSystemSettings( aAllSettings );
560 0 : Application::SetSettings(aAllSettings);
561 :
562 0 : if (setModified == SET_MODIFIED) {
563 0 : SetModified();
564 : }
565 0 : CallListeners();
566 0 : }
567 :
568 :
569 : // public method
570 :
571 0 : void SvtMiscOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
572 : {
573 0 : Load( rPropertyNames );
574 0 : CallListeners();
575 0 : }
576 :
577 :
578 : // public method
579 :
580 0 : void SvtMiscOptions_Impl::Commit()
581 : {
582 : // Get names of supported properties, create a list for values and copy current values to it.
583 0 : Sequence< OUString > seqNames = GetPropertyNames ();
584 0 : sal_Int32 nCount = seqNames.getLength();
585 0 : Sequence< Any > seqValues ( nCount );
586 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
587 : {
588 0 : switch( nProperty )
589 : {
590 : case PROPERTYHANDLE_PLUGINSENABLED :
591 : {
592 0 : if ( !m_bIsPluginsEnabledRO )
593 0 : seqValues[nProperty] <<= m_bPluginsEnabled;
594 0 : break;
595 : }
596 :
597 : case PROPERTYHANDLE_SYMBOLSET :
598 : {
599 0 : if ( !m_bIsSymbolsSizeRO )
600 0 : seqValues[nProperty] <<= m_nSymbolsSize;
601 0 : break;
602 : }
603 :
604 : case PROPERTYHANDLE_TOOLBOXSTYLE :
605 : {
606 0 : if ( !m_bIsToolboxStyleRO )
607 0 : seqValues[nProperty] <<= m_nToolboxStyle;
608 0 : break;
609 : }
610 :
611 : case PROPERTYHANDLE_USESYSTEMFILEDIALOG :
612 : {
613 0 : if ( !m_bIsUseSystemFileDialogRO )
614 0 : seqValues[nProperty] <<= m_bUseSystemFileDialog;
615 0 : break;
616 : }
617 :
618 : case PROPERTYHANDLE_SYMBOLSTYLE :
619 : {
620 0 : if ( !m_bIsSymbolsStyleRO ) {
621 0 : OUString value;
622 0 : if (m_bIconThemeWasSetAutomatically) {
623 0 : value = "auto";
624 : }
625 : else {
626 0 : value = GetIconTheme();
627 : }
628 0 : seqValues[nProperty] <<= value;
629 : }
630 0 : break;
631 : }
632 :
633 : case PROPERTYHANDLE_USESYSTEMPRINTDIALOG :
634 : {
635 0 : if ( !m_bIsUseSystemPrintDialogRO )
636 0 : seqValues[nProperty] <<= m_bUseSystemPrintDialog;
637 0 : break;
638 : }
639 :
640 : case PROPERTYHANDLE_SHOWLINKWARNINGDIALOG :
641 : {
642 0 : if ( !m_bIsShowLinkWarningDialogRO )
643 0 : seqValues[nProperty] <<= m_bShowLinkWarningDialog;
644 0 : break;
645 : }
646 :
647 : case PROPERTYHANDLE_DISABLEUICUSTOMIZATION :
648 : {
649 0 : seqValues[nProperty] <<= m_bDisableUICustomization;
650 0 : break;
651 : }
652 : case PROPERTYHANDLE_ALWAYSALLOWSAVE :
653 : {
654 0 : seqValues[nProperty] <<= m_bAlwaysAllowSave;
655 0 : break;
656 : }
657 : case PROPERTYHANDLE_EXPERIMENTALMODE :
658 : {
659 0 : seqValues[nProperty] <<= m_bExperimentalMode;
660 0 : break;
661 : }
662 : case PROPERTYHANDLE_MACRORECORDERMODE :
663 : {
664 0 : seqValues[nProperty] <<= m_bMacroRecorderMode;
665 0 : break;
666 : }
667 : }
668 : }
669 : // Set properties in configuration.
670 0 : PutProperties( seqNames, seqValues );
671 0 : }
672 :
673 :
674 : // private method
675 :
676 0 : Sequence< OUString > SvtMiscOptions_Impl::GetPropertyNames()
677 : {
678 : // Build list of configuration key names.
679 : const OUString pProperties[] =
680 : {
681 : OUString(PROPERTYNAME_PLUGINSENABLED),
682 : OUString(PROPERTYNAME_SYMBOLSET),
683 : OUString(PROPERTYNAME_TOOLBOXSTYLE),
684 : OUString(PROPERTYNAME_USESYSTEMFILEDIALOG),
685 : OUString(PROPERTYNAME_ICONTHEME),
686 : OUString(PROPERTYNAME_USESYSTEMPRINTDIALOG),
687 : OUString(PROPERTYNAME_SHOWLINKWARNINGDIALOG),
688 : OUString(PROPERTYNAME_DISABLEUICUSTOMIZATION),
689 : OUString(PROPERTYNAME_ALWAYSALLOWSAVE),
690 : OUString(PROPERTYNAME_EXPERIMENTALMODE),
691 : OUString(PROPERTYNAME_MACRORECORDERMODE)
692 0 : };
693 :
694 : // Initialize return sequence with these list ...
695 0 : const Sequence< OUString > seqPropertyNames( pProperties, SAL_N_ELEMENTS( pProperties ) );
696 : // ... and return it.
697 0 : return seqPropertyNames;
698 : }
699 :
700 :
701 : // initialize static member
702 : // DON'T DO IT IN YOUR HEADER!
703 : // see definition for further information
704 :
705 : SvtMiscOptions_Impl* SvtMiscOptions::m_pDataContainer = NULL ;
706 : sal_Int32 SvtMiscOptions::m_nRefCount = 0 ;
707 :
708 :
709 : // constructor
710 :
711 0 : SvtMiscOptions::SvtMiscOptions()
712 : {
713 : // SvtMiscOptions_Impl ctor indirectly calls code that requires locked
714 : // SolarMutex; lock it first:
715 0 : SolarMutexGuard g;
716 : // Global access, must be guarded (multithreading!).
717 0 : MutexGuard aGuard( GetInitMutex() );
718 : // Increase our refcount ...
719 0 : ++m_nRefCount;
720 : // ... and initialize our data container only if it not already exist!
721 0 : if( m_pDataContainer == NULL )
722 : {
723 0 : m_pDataContainer = new SvtMiscOptions_Impl;
724 0 : svtools::ItemHolder2::holdConfigItem(E_MISCOPTIONS);
725 0 : }
726 0 : }
727 :
728 :
729 : // destructor
730 :
731 0 : SvtMiscOptions::~SvtMiscOptions()
732 : {
733 : // Global access, must be guarded (multithreading!)
734 0 : MutexGuard aGuard( GetInitMutex() );
735 : // Decrease our refcount.
736 0 : --m_nRefCount;
737 : // If last instance was deleted ...
738 : // we must destroy our static data container!
739 0 : if( m_nRefCount <= 0 )
740 : {
741 0 : delete m_pDataContainer;
742 0 : m_pDataContainer = NULL;
743 0 : }
744 0 : }
745 :
746 0 : bool SvtMiscOptions::UseSystemFileDialog() const
747 : {
748 0 : return m_pDataContainer->UseSystemFileDialog();
749 : }
750 :
751 0 : void SvtMiscOptions::SetUseSystemFileDialog( bool bEnable )
752 : {
753 0 : m_pDataContainer->SetUseSystemFileDialog( bEnable );
754 0 : }
755 :
756 0 : bool SvtMiscOptions::IsUseSystemFileDialogReadOnly() const
757 : {
758 0 : return m_pDataContainer->IsUseSystemFileDialogReadOnly();
759 : }
760 :
761 0 : bool SvtMiscOptions::IsPluginsEnabled() const
762 : {
763 0 : return m_pDataContainer->IsPluginsEnabled();
764 : }
765 :
766 0 : sal_Int16 SvtMiscOptions::GetSymbolsSize() const
767 : {
768 0 : return m_pDataContainer->GetSymbolsSize();
769 : }
770 :
771 0 : void SvtMiscOptions::SetSymbolsSize( sal_Int16 nSet )
772 : {
773 0 : m_pDataContainer->SetSymbolsSize( nSet );
774 0 : }
775 :
776 0 : sal_Int16 SvtMiscOptions::GetCurrentSymbolsSize() const
777 : {
778 0 : sal_Int16 eOptSymbolsSize = m_pDataContainer->GetSymbolsSize();
779 :
780 0 : if ( eOptSymbolsSize == SFX_SYMBOLS_SIZE_AUTO )
781 : {
782 : // Use system settings, we have to retrieve the toolbar icon size from the
783 : // Application class
784 0 : sal_uLong nStyleIconSize = Application::GetSettings().GetStyleSettings().GetToolbarIconSize();
785 0 : if ( nStyleIconSize == STYLE_TOOLBAR_ICONSIZE_LARGE )
786 0 : eOptSymbolsSize = SFX_SYMBOLS_SIZE_LARGE;
787 : else
788 0 : eOptSymbolsSize = SFX_SYMBOLS_SIZE_SMALL;
789 : }
790 :
791 0 : return eOptSymbolsSize;
792 : }
793 :
794 0 : bool SvtMiscOptions::AreCurrentSymbolsLarge() const
795 : {
796 0 : return ( GetCurrentSymbolsSize() == SFX_SYMBOLS_SIZE_LARGE );
797 : }
798 :
799 0 : OUString SvtMiscOptions::GetIconTheme() const
800 : {
801 0 : return m_pDataContainer->GetIconTheme();
802 : }
803 :
804 0 : void SvtMiscOptions::SetIconTheme(const OUString& iconTheme)
805 : {
806 0 : m_pDataContainer->SetIconTheme(iconTheme);
807 0 : }
808 :
809 0 : bool SvtMiscOptions::DisableUICustomization() const
810 : {
811 0 : return m_pDataContainer->DisableUICustomization();
812 : }
813 :
814 0 : sal_Int16 SvtMiscOptions::GetToolboxStyle() const
815 : {
816 0 : return m_pDataContainer->GetToolboxStyle();
817 : }
818 :
819 0 : void SvtMiscOptions::SetToolboxStyle( sal_Int16 nStyle )
820 : {
821 0 : m_pDataContainer->SetToolboxStyle( nStyle, true );
822 0 : }
823 :
824 0 : bool SvtMiscOptions::UseSystemPrintDialog() const
825 : {
826 0 : return m_pDataContainer->UseSystemPrintDialog();
827 : }
828 :
829 0 : void SvtMiscOptions::SetUseSystemPrintDialog( bool bEnable )
830 : {
831 0 : m_pDataContainer->SetUseSystemPrintDialog( bEnable );
832 0 : }
833 :
834 0 : bool SvtMiscOptions::ShowLinkWarningDialog() const
835 : {
836 0 : return m_pDataContainer->ShowLinkWarningDialog();
837 : }
838 :
839 0 : void SvtMiscOptions::SetShowLinkWarningDialog( bool bSet )
840 : {
841 0 : m_pDataContainer->SetShowLinkWarningDialog( bSet );
842 0 : }
843 :
844 0 : bool SvtMiscOptions::IsShowLinkWarningDialogReadOnly() const
845 : {
846 0 : return m_pDataContainer->IsShowLinkWarningDialogReadOnly();
847 : }
848 :
849 0 : void SvtMiscOptions::SetSaveAlwaysAllowed( bool bSet )
850 : {
851 0 : m_pDataContainer->SetSaveAlwaysAllowed( bSet );
852 0 : }
853 :
854 0 : bool SvtMiscOptions::IsSaveAlwaysAllowed() const
855 : {
856 0 : return m_pDataContainer->IsSaveAlwaysAllowed();
857 : }
858 :
859 0 : void SvtMiscOptions::SetExperimentalMode( bool bSet )
860 : {
861 0 : m_pDataContainer->SetExperimentalMode( bSet );
862 0 : }
863 :
864 0 : bool SvtMiscOptions::IsExperimentalMode() const
865 : {
866 0 : return m_pDataContainer->IsExperimentalMode();
867 : }
868 :
869 0 : void SvtMiscOptions::SetMacroRecorderMode( bool bSet )
870 : {
871 0 : m_pDataContainer->SetMacroRecorderMode( bSet );
872 0 : }
873 :
874 0 : bool SvtMiscOptions::IsMacroRecorderMode() const
875 : {
876 0 : return m_pDataContainer->IsMacroRecorderMode();
877 : }
878 :
879 : namespace
880 : {
881 : class theSvtMiscOptionsMutex :
882 : public rtl::Static< osl::Mutex, theSvtMiscOptionsMutex > {};
883 : }
884 :
885 0 : Mutex & SvtMiscOptions::GetInitMutex()
886 : {
887 0 : return theSvtMiscOptionsMutex::get();
888 : }
889 :
890 0 : void SvtMiscOptions::AddListenerLink( const Link& rLink )
891 : {
892 0 : m_pDataContainer->AddListenerLink( rLink );
893 0 : }
894 :
895 0 : void SvtMiscOptions::RemoveListenerLink( const Link& rLink )
896 : {
897 0 : m_pDataContainer->RemoveListenerLink( rLink );
898 0 : }
899 :
900 : void
901 0 : SvtMiscOptions_Impl::SetIconThemeAutomatically(enum SetModifiedFlag setModified)
902 : {
903 0 : OUString theme = Application::GetSettings().GetStyleSettings().GetAutomaticallyChosenIconTheme();
904 0 : SetIconTheme(theme, setModified);
905 0 : m_bIconThemeWasSetAutomatically = true;
906 0 : }
907 :
908 : void
909 0 : SvtMiscOptions::SetIconThemeAutomatically()
910 : {
911 0 : m_pDataContainer->SetIconThemeAutomatically();
912 0 : }
913 :
914 : bool
915 0 : SvtMiscOptions::IconThemeWasSetAutomatically()
916 : {
917 0 : return m_pDataContainer->IconThemeWasSetAutomatically();
918 : }
919 :
920 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|