LibreOffice Module svtools (master) 1
miscopt.cxx
Go to the documentation of this file.
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>
22#include <tools/debug.hxx>
23#include <com/sun/star/uno/Any.hxx>
24#include <com/sun/star/uno/Sequence.hxx>
26#include <tools/link.hxx>
27#include <osl/diagnose.h>
28
29#include "itemholder2.hxx"
30
31#include <svtools/imgdef.hxx>
32#include <vcl/svapp.hxx>
33#include <vcl/settings.hxx>
34#include <officecfg/Office/Common.hxx>
35
36#include <mutex>
37#include <vector>
38
39using namespace ::utl ;
40using namespace ::osl ;
41using namespace ::com::sun::star::uno ;
42using namespace ::com::sun::star;
43
44constexpr OUStringLiteral ROOTNODE_MISC = u"Office.Common/Misc";
45
46// PROPERTYHANDLE defines must be sequential from zero for Commit/Load
47constexpr OUStringLiteral PROPERTYNAME_SYMBOLSET = u"SymbolSet";
48#define PROPERTYHANDLE_SYMBOLSET 0
49constexpr OUStringLiteral PROPERTYNAME_ICONTHEME = u"SymbolStyle";
50#define PROPERTYHANDLE_SYMBOLSTYLE 1
51constexpr OUStringLiteral PROPERTYNAME_SIDEBARICONSIZE = u"SidebarIconSize";
52constexpr OUStringLiteral PROPERTYNAME_NOTEBOOKBARICONSIZE = u"NotebookbarIconSize";
53
54static std::mutex & GetInitMutex()
55{
56 static std::mutex theSvtMiscOptionsMutex;
57 return theSvtMiscOptionsMutex;
58}
59
60
61class SvtMiscOptions_Impl : public ConfigItem
62{
63private:
64 ::std::vector<Link<LinkParamNone*,void>> aList;
65 sal_Int16 m_nSymbolsSize;
69
70 virtual void ImplCommit() override;
71
72public:
73
75 virtual ~SvtMiscOptions_Impl() override;
76
77 /*-****************************************************************************************************
78 @short called for notify of configmanager
79 @descr This method is called from the ConfigManager before the application ends or from the
80 PropertyChangeListener if the sub tree broadcasts changes. You must update your
81 internal values.
82
83 @seealso baseclass ConfigItem
84
85 @param "seqPropertyNames" is the list of properties which should be updated.
86 *//*-*****************************************************************************************************/
87
88 virtual void Notify( const Sequence< OUString >& seqPropertyNames ) override;
89
94 void Load( const Sequence< OUString >& rPropertyNames );
95
96 // public interface
97
98 void SetSymbolsSize( sal_Int16 nSet );
99
100 static OUString GetIconTheme();
101
102 enum class SetModifiedFlag { SET, DONT_SET };
103
116 void
117 SetIconTheme(const OUString &theme, SetModifiedFlag setModified );
118
121
122 void AddListenerLink( const Link<LinkParamNone*,void>& rLink );
124 void CallListeners();
125
126
127 // private methods
128
129
130private:
131
132 /*-****************************************************************************************************
133 @short return list of key names of our configuration management which represent our module tree
134 @descr These methods return a static const list of key names. We need it to get needed values from our
135 configuration management.
136 @return A list of needed configuration keys is returned.
137 *//*-*****************************************************************************************************/
138
139 static Sequence< OUString > GetPropertyNames();
140};
141
142
143// constructor
144
146 // Init baseclasses first
147 : ConfigItem( ROOTNODE_MISC )
148
149 , m_nSymbolsSize( 0 )
150 , m_bIsSymbolsSizeRO( false )
151 , m_bIsSymbolsStyleRO( false )
152 , m_bIconThemeWasSetAutomatically( false )
153{
154 // Use our static list of configuration keys to get his values.
155 Sequence< OUString > seqNames = GetPropertyNames ( );
156 Load( seqNames );
157 Sequence< Any > seqValues = GetProperties ( seqNames );
158 Sequence< sal_Bool > seqRO = GetReadOnlyStates ( seqNames );
159
160 // Safe impossible cases.
161 // We need values from ALL configuration keys.
162 // Follow assignment use order of values in relation to our list of key names!
163 DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtMiscOptions_Impl::SvtMiscOptions_Impl()\nI miss some values of configuration keys!\n" );
164
165 // Copy values from list in right order to our internal member.
166 sal_Int32 nPropertyCount = seqValues.getLength();
167 for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
168 {
169 if (!seqValues[nProperty].hasValue())
170 continue;
171 switch( nProperty )
172 {
174 {
175 if( !(seqValues[nProperty] >>= m_nSymbolsSize) )
176 {
177 OSL_FAIL("Wrong type of \"Misc\\SymbolSet\"!" );
178 }
179 m_bIsSymbolsSizeRO = seqRO[nProperty];
180 break;
181 }
182
184 {
185 OUString aIconTheme;
186 if (seqValues[nProperty] >>= aIconTheme)
188 else
189 OSL_FAIL("Wrong type of \"Misc\\SymbolStyle\"!" );
190
191 m_bIsSymbolsStyleRO = seqRO[nProperty];
192 break;
193 }
194
195 }
196 }
197
198 // Enable notification mechanism of our baseclass.
199 // We need it to get information about changes outside these class on our used configuration keys!
200 EnableNotification( seqNames );
201}
202
203
204// destructor
205
207{
208 assert(!IsModified()); // should have been committed
209}
210
211void SvtMiscOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
212{
213 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
214 Sequence< Any > seqValues = GetProperties( rPropertyNames );
215
216 // Safe impossible cases.
217 // We need values from ALL configuration keys.
218 // Follow assignment use order of values in relation to our list of key names!
219 DBG_ASSERT( !(rPropertyNames.getLength()!=seqValues.getLength()), "SvtSecurityOptions_Impl::SvtSecurityOptions_Impl()\nI miss some values of configuration keys!\n" );
220
221 // Copy values from list in right order to our internal member.
222 sal_Int32 nPropertyCount = seqValues.getLength();
223 for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
224 {
225 if (!seqValues[nProperty].hasValue())
226 continue;
227 switch( comphelper::findValue(aInternalPropertyNames, rPropertyNames[nProperty]) )
228 {
230 if( !(seqValues[nProperty] >>= m_nSymbolsSize) )
231 {
232 OSL_FAIL("Wrong type of \"Misc\\SymbolSet\"!" );
233 }
234 }
235 break;
237 OUString aIconTheme;
238 if (seqValues[nProperty] >>= aIconTheme)
240 else
241 OSL_FAIL("Wrong type of \"Misc\\SymbolStyle\"!" );
242 }
243 break;
244 }
245 }
246}
247
249{
250 aList.push_back( rLink );
251}
252
254{
255 aList.erase(std::remove(aList.begin(), aList.end(), rLink), aList.end());
256}
257
259{
260 for (auto const& elem : aList)
261 elem.Call( nullptr );
262}
263
265{
266 m_nSymbolsSize = nSet;
267 SetModified();
269}
270
272{
274}
275
276void
277SvtMiscOptions_Impl::SetIconTheme(const OUString &rName, SetModifiedFlag setModified)
278{
279 OUString aTheme(rName);
280 if (aTheme.isEmpty() || aTheme == "auto")
281 {
284 }
285 else
287
288 AllSettings aAllSettings = Application::GetSettings();
289 StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
290 aStyleSettings.SetIconTheme(aTheme);
291
292 aAllSettings.SetStyleSettings(aStyleSettings);
293 Application::MergeSystemSettings( aAllSettings );
294 Application::SetSettings(aAllSettings);
295
296 if (setModified == SetModifiedFlag::SET) {
297 SetModified();
298 }
300}
301
302
303// public method
304
305void SvtMiscOptions_Impl::Notify( const Sequence< OUString >& rPropertyNames )
306{
307 Load( rPropertyNames );
309}
310
311
312// public method
313
315{
316 // Get names of supported properties, create a list for values and copy current values to it.
317 Sequence< OUString > seqNames = GetPropertyNames ();
318 sal_Int32 nCount = seqNames.getLength();
319 Sequence< Any > seqValues ( nCount );
320 auto seqValuesRange = asNonConstRange(seqValues);
321 for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
322 {
323 switch( nProperty )
324 {
326 {
327 if ( !m_bIsSymbolsSizeRO )
328 seqValuesRange[nProperty] <<= m_nSymbolsSize;
329 break;
330 }
331
333 {
334 if ( !m_bIsSymbolsStyleRO ) {
335 OUString value;
337 value = "auto";
338 }
339 else {
341 }
342 seqValuesRange[nProperty] <<= value;
343 }
344 break;
345 }
346
347 }
348 }
349 // Set properties in configuration.
350 PutProperties( seqNames, seqValues );
351}
352
353
354// private method
355
357{
358 return Sequence<OUString>
359 {
362 // SidebarIconSize and NotebookbarIconSize so
363 // notifications for their changes are also broadcast
364 // from SvtMiscOptions
367 };
368}
369
370namespace {
371
372std::weak_ptr<SvtMiscOptions_Impl> g_pMiscOptions;
373
374}
375
377{
378 // Global access, must be guarded (multithreading!).
379 std::unique_lock aGuard( GetInitMutex() );
380
381 m_pImpl = g_pMiscOptions.lock();
382 if( !m_pImpl )
383 {
384 m_pImpl = std::make_shared<SvtMiscOptions_Impl>();
385 g_pMiscOptions = m_pImpl;
386 aGuard.unlock(); // because holdConfigItem will call this constructor
387 svtools::ItemHolder2::holdConfigItem(EItem::MiscOptions);
388 }
389}
390
392{
393 // Global access, must be guarded (multithreading!)
394 std::unique_lock aGuard( GetInitMutex() );
395
396 m_pImpl.reset();
397}
398
399
401{
402 return officecfg::Office::Common::Misc::SymbolSet::get();
403}
404
405void SvtMiscOptions::SetSymbolsSize( sal_Int16 nSet )
406{
407 m_pImpl->SetSymbolsSize( nSet );
408}
409
411{
412 sal_Int16 eOptSymbolsSize = GetSymbolsSize();
413
414 if ( eOptSymbolsSize == SFX_SYMBOLS_SIZE_AUTO )
415 {
416 // Use system settings, we have to retrieve the toolbar icon size from the
417 // Application class
419 if (nStyleIconSize == ToolbarIconSize::Size32)
420 eOptSymbolsSize = SFX_SYMBOLS_SIZE_32;
421 else if (nStyleIconSize == ToolbarIconSize::Large)
422 eOptSymbolsSize = SFX_SYMBOLS_SIZE_LARGE;
423 else
424 eOptSymbolsSize = SFX_SYMBOLS_SIZE_SMALL;
425 }
426
427 return eOptSymbolsSize;
428}
429
431{
433}
434
436{
438}
439
440void SvtMiscOptions::SetIconTheme(const OUString& iconTheme)
441{
442 m_pImpl->SetIconTheme(iconTheme, SvtMiscOptions_Impl::SetModifiedFlag::SET);
443}
444
446{
447 m_pImpl->AddListenerLink( rLink );
448}
449
451{
452 m_pImpl->RemoveListenerLink( rLink );
453}
454
455bool
457{
458 return m_pImpl->IconThemeWasSetAutomatically();
459}
460
461/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
void SetStyleSettings(const StyleSettings &rSet)
static void MergeSystemSettings(AllSettings &rSettings)
static const AllSettings & GetSettings()
static void SetSettings(const AllSettings &rSettings)
OUString DetermineIconTheme() const
void SetIconTheme(const OUString &)
OUString GetAutomaticallyChosenIconTheme() const
ToolbarIconSize GetToolbarIconSize() const
::std::vector< Link< LinkParamNone *, void > > aList
Definition: miscopt.cxx:64
void RemoveListenerLink(const Link< LinkParamNone *, void > &rLink)
Definition: miscopt.cxx:253
bool IconThemeWasSetAutomatically() const
Definition: miscopt.cxx:119
static OUString GetIconTheme()
Definition: miscopt.cxx:271
virtual void ImplCommit() override
Definition: miscopt.cxx:314
void SetSymbolsSize(sal_Int16 nSet)
Definition: miscopt.cxx:264
virtual ~SvtMiscOptions_Impl() override
Definition: miscopt.cxx:206
bool m_bIsSymbolsStyleRO
Definition: miscopt.cxx:67
static Sequence< OUString > GetPropertyNames()
Definition: miscopt.cxx:356
void AddListenerLink(const Link< LinkParamNone *, void > &rLink)
Definition: miscopt.cxx:248
void Load(const Sequence< OUString > &rPropertyNames)
loads required data from the configuration.
Definition: miscopt.cxx:211
bool m_bIconThemeWasSetAutomatically
Definition: miscopt.cxx:68
virtual void Notify(const Sequence< OUString > &seqPropertyNames) override
Definition: miscopt.cxx:305
sal_Int16 m_nSymbolsSize
Definition: miscopt.cxx:65
void SetIconTheme(const OUString &theme, SetModifiedFlag setModified)
Set the icon theme.
Definition: miscopt.cxx:277
bool IconThemeWasSetAutomatically() const
Definition: miscopt.cxx:456
static sal_Int16 GetCurrentSymbolsSize()
Definition: miscopt.cxx:410
void RemoveListenerLink(const Link< LinkParamNone *, void > &rLink)
Definition: miscopt.cxx:450
static sal_Int16 GetSymbolsSize()
Definition: miscopt.cxx:400
static bool AreCurrentSymbolsLarge()
Definition: miscopt.cxx:430
void SetIconTheme(const OUString &)
Definition: miscopt.cxx:440
void SetSymbolsSize(sal_Int16 eSet)
Definition: miscopt.cxx:405
virtual ~SvtMiscOptions() override
Definition: miscopt.cxx:391
std::shared_ptr< SvtMiscOptions_Impl > m_pImpl
Definition: miscopt.hxx:66
void AddListenerLink(const Link< LinkParamNone *, void > &rLink)
Definition: miscopt.cxx:445
static OUString GetIconTheme()
Definition: miscopt.cxx:435
static void holdConfigItem(EItem eItem)
Definition: itemholder2.cxx:73
Any value
int nCount
#define DBG_ASSERT(sCon, aError)
float u
@ SFX_SYMBOLS_SIZE_SMALL
Definition: imgdef.hxx:24
@ SFX_SYMBOLS_SIZE_32
Definition: imgdef.hxx:26
@ SFX_SYMBOLS_SIZE_LARGE
Definition: imgdef.hxx:25
@ SFX_SYMBOLS_SIZE_AUTO
Definition: imgdef.hxx:27
constexpr OUStringLiteral ROOTNODE_MISC
Definition: miscopt.cxx:44
static std::mutex & GetInitMutex()
Definition: miscopt.cxx:54
constexpr OUStringLiteral PROPERTYNAME_NOTEBOOKBARICONSIZE
Definition: miscopt.cxx:52
constexpr OUStringLiteral PROPERTYNAME_SYMBOLSET
Definition: miscopt.cxx:47
#define PROPERTYHANDLE_SYMBOLSTYLE
Definition: miscopt.cxx:50
constexpr OUStringLiteral PROPERTYNAME_SIDEBARICONSIZE
Definition: miscopt.cxx:51
constexpr OUStringLiteral PROPERTYNAME_ICONTHEME
Definition: miscopt.cxx:49
#define PROPERTYHANDLE_SYMBOLSET
Definition: miscopt.cxx:48
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
ToolbarIconSize
SET