xref: /core/svtools/source/config/extcolorcfg.cxx (revision 16a90925)
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 <sal/config.h>
21 
22 #include <map>
23 #include <string_view>
24 
25 #include <svtools/extcolorcfg.hxx>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <tools/color.hxx>
30 #include <unotools/configitem.hxx>
31 #include <com/sun/star/uno/Sequence.h>
32 #include <comphelper/sequence.hxx>
33 #include <svl/hint.hxx>
34 #include <mutex>
35 #include <sal/log.hxx>
36 #include <osl/diagnose.h>
37 #include <o3tl/string_view.hxx>
38 
39 #include <vcl/svapp.hxx>
40 #include <vcl/settings.hxx>
41 #include <vcl/event.hxx>
42 
43 
44 using namespace utl;
45 using namespace com::sun::star;
46 
47 
48 namespace svtools
49 {
50 
51 static sal_Int32            nExtendedColorRefCount_Impl = 0;
52 namespace
53 {
ColorMutex_Impl()54     std::mutex& ColorMutex_Impl()
55     {
56         static std::mutex SINGLETON;
57         return SINGLETON;
58     }
59 }
60 
61 ExtendedColorConfig_Impl*    ExtendedColorConfig::m_pImpl = nullptr;
62 
63 class ExtendedColorConfig_Impl : public utl::ConfigItem, public SfxBroadcaster
64 {
65     typedef std::map<OUString, OUString> TDisplayNames;
66     typedef std::map<OUString, ExtendedColorConfigValue> TConfigValues;
67     typedef ::std::vector<TConfigValues::iterator> TMapPos;
68     typedef ::std::pair< TConfigValues, TMapPos > TComponentMapping;
69     typedef std::map<OUString, TComponentMapping> TComponents;
70     TComponents         m_aConfigValues;
71     TDisplayNames       m_aComponentDisplayNames;
72     ::std::vector<TComponents::iterator> m_aConfigValuesPos;
73 
74     OUString        m_sLoadedScheme;
75     bool            m_bIsBroadcastEnabled;
76     static bool     m_bLockBroadcast;
77     static bool     m_bBroadcastWhenUnlocked;
78 
79     uno::Sequence< OUString> GetPropertyNames(const OUString& rScheme);
80     void FillComponentColors(const uno::Sequence < OUString >& _rComponents,const TDisplayNames& _rDisplayNames);
81 
82     virtual void                    ImplCommit() override;
83 
84 public:
85     explicit ExtendedColorConfig_Impl();
86     virtual ~ExtendedColorConfig_Impl() override;
87 
88     void                            Load(const OUString& rScheme);
89     void                            CommitCurrentSchemeName();
90     //changes the name of the current scheme but doesn't load it!
SetCurrentSchemeName(const OUString & rSchemeName)91     void                            SetCurrentSchemeName(const OUString& rSchemeName) {m_sLoadedScheme = rSchemeName;}
92     bool                            ExistsScheme(std::u16string_view _sSchemeName);
93     virtual void                    Notify( const uno::Sequence<OUString>& aPropertyNames) override;
94 
95     sal_Int32                       GetComponentCount() const;
96     OUString                 GetComponentName(sal_uInt32 _nPos) const;
97     OUString                 GetComponentDisplayName(const OUString& _sComponentName) const;
98     sal_Int32                       GetComponentColorCount(const OUString& _sName) const;
99     ExtendedColorConfigValue        GetComponentColorConfigValue(const OUString& _sName,sal_uInt32 _nPos) const;
100 
GetColorConfigValue(const OUString & _sComponentName,const OUString & _sName)101     ExtendedColorConfigValue GetColorConfigValue(const OUString& _sComponentName,const OUString& _sName)
102     {
103         TComponents::iterator aFind = m_aConfigValues.find(_sComponentName);
104         if ( aFind != m_aConfigValues.end() )
105         {
106             TConfigValues::iterator aFind2 = aFind->second.first.find(_sName);
107             if ( aFind2 != aFind->second.first.end() )
108                 return aFind2->second;
109         }
110 #if OSL_DEBUG_LEVEL > 0
111         SAL_WARN( "svtools", "Could find the required config:\n"
112                   "component: " << _sComponentName
113                   << "\nname: " << _sName );
114 #endif
115         return ExtendedColorConfigValue();
116     }
117     void                            SetColorConfigValue(const OUString& _sName,
118                                                             const ExtendedColorConfigValue& rValue );
119 
120     void                            AddScheme(const OUString& rNode);
121     void                            RemoveScheme(const OUString& rNode);
122     using ConfigItem::SetModified;
123     using ConfigItem::ClearModified;
124     void                            SettingsChanged();
125 
126     static void                     DisableBroadcast();
127     static void                     EnableBroadcast();
128 
129     static void                     LockBroadcast();
130     static void                     UnlockBroadcast();
131 
132     DECL_LINK( DataChangedEventListener, VclSimpleEvent&, void );
133 };
134 
GetPropertyNames(const OUString & rScheme)135 uno::Sequence< OUString> ExtendedColorConfig_Impl::GetPropertyNames(const OUString& rScheme)
136 {
137     uno::Sequence< OUString> aNames(GetNodeNames(rScheme));
138     for(OUString & i : asNonConstRange(aNames))
139     {
140         i = rScheme + "/" + i;
141     }
142     return aNames;
143 }
144 
GetComponentCount() const145 sal_Int32 ExtendedColorConfig_Impl::GetComponentCount() const
146 {
147     return m_aConfigValues.size();
148 }
149 
GetComponentColorCount(const OUString & _sName) const150 sal_Int32 ExtendedColorConfig_Impl::GetComponentColorCount(const OUString& _sName) const
151 {
152     sal_Int32 nSize = 0;
153     TComponents::const_iterator aFind = m_aConfigValues.find(_sName);
154     if ( aFind != m_aConfigValues.end() )
155     {
156         nSize = aFind->second.first.size();
157     }
158     return nSize;
159 }
160 
GetComponentColorConfigValue(const OUString & _sName,sal_uInt32 _nPos) const161 ExtendedColorConfigValue ExtendedColorConfig_Impl::GetComponentColorConfigValue(const OUString& _sName,sal_uInt32 _nPos) const
162 {
163     TComponents::const_iterator aFind = m_aConfigValues.find(_sName);
164     if ( aFind != m_aConfigValues.end() )
165     {
166         if ( _nPos < aFind->second.second.size() )
167         {
168             return aFind->second.second[_nPos]->second;
169         }
170     }
171     return ExtendedColorConfigValue();
172 }
173 
GetComponentDisplayName(const OUString & _sComponentName) const174 OUString ExtendedColorConfig_Impl::GetComponentDisplayName(const OUString& _sComponentName) const
175 {
176     OUString sRet;
177     TDisplayNames::const_iterator aFind = m_aComponentDisplayNames.find(_sComponentName);
178     if ( aFind != m_aComponentDisplayNames.end() )
179         sRet = aFind->second;
180     return sRet;
181 }
182 
GetComponentName(sal_uInt32 _nPos) const183 OUString ExtendedColorConfig_Impl::GetComponentName(sal_uInt32 _nPos) const
184 {
185     OUString sRet;
186     if ( _nPos < m_aConfigValuesPos.size() )
187         sRet = m_aConfigValuesPos[_nPos]->first;
188     return sRet;
189 }
190 
191 bool ExtendedColorConfig_Impl::m_bLockBroadcast = false;
192 bool ExtendedColorConfig_Impl::m_bBroadcastWhenUnlocked = false;
ExtendedColorConfig_Impl()193 ExtendedColorConfig_Impl::ExtendedColorConfig_Impl() :
194     ConfigItem(u"Office.ExtendedColorScheme"_ustr),
195     m_bIsBroadcastEnabled(true)
196 {
197     //try to register on the root node - if possible
198     uno::Sequence < OUString > aNames(1);
199     EnableNotification( aNames );
200     Load(OUString());
201 
202     ::Application::AddEventListener( LINK(this, ExtendedColorConfig_Impl, DataChangedEventListener) );
203 
204 }
205 
~ExtendedColorConfig_Impl()206 ExtendedColorConfig_Impl::~ExtendedColorConfig_Impl()
207 {
208     ::Application::RemoveEventListener( LINK(this, ExtendedColorConfig_Impl, DataChangedEventListener) );
209 }
210 
DisableBroadcast()211 void ExtendedColorConfig_Impl::DisableBroadcast()
212 {
213     if ( ExtendedColorConfig::m_pImpl )
214         ExtendedColorConfig::m_pImpl->m_bIsBroadcastEnabled = false;
215 }
216 
EnableBroadcast()217 void ExtendedColorConfig_Impl::EnableBroadcast()
218 {
219     if ( ExtendedColorConfig::m_pImpl )
220         ExtendedColorConfig::m_pImpl->m_bIsBroadcastEnabled = true;
221 }
222 
lcl_addString(uno::Sequence<OUString> & _rSeq,std::u16string_view _sAdd)223 static void lcl_addString(uno::Sequence < OUString >& _rSeq,std::u16string_view _sAdd)
224 {
225     for(OUString & i : asNonConstRange(_rSeq))
226         i += _sAdd;
227 }
228 
Load(const OUString & rScheme)229 void ExtendedColorConfig_Impl::Load(const OUString& rScheme)
230 {
231     m_aComponentDisplayNames.clear();
232     m_aConfigValuesPos.clear();
233     m_aConfigValues.clear();
234 
235     // fill display names
236     TDisplayNames aDisplayNameMap;
237     uno::Sequence < OUString > aComponentNames = GetPropertyNames(u"EntryNames"_ustr);
238     OUString sDisplayName(u"/DisplayName"_ustr);
239     for(OUString & componentName : asNonConstRange(aComponentNames))
240     {
241         uno::Sequence< uno::Any > aComponentDisplayNamesValue = GetProperties( { componentName + sDisplayName } );
242         OUString sComponentDisplayName;
243         if ( aComponentDisplayNamesValue.hasElements() && (aComponentDisplayNamesValue[0] >>= sComponentDisplayName) )
244         {
245             m_aComponentDisplayNames.emplace(componentName.getToken(1, '/'),sComponentDisplayName);
246         }
247 
248         componentName += "/Entries";
249         uno::Sequence < OUString > aDisplayNames = GetPropertyNames(componentName);
250         lcl_addString(aDisplayNames,sDisplayName);
251 
252         uno::Sequence< uno::Any > aDisplayNamesValue = GetProperties( aDisplayNames );
253 
254         const OUString* pDispIter = aDisplayNames.getConstArray();
255         const OUString* pDispEnd  = pDispIter + aDisplayNames.getLength();
256         for(sal_Int32 j = 0;pDispIter != pDispEnd;++pDispIter,++j)
257         {
258             sal_Int32 nIndex = 0;
259             o3tl::getToken(*pDispIter, 0, '/', nIndex);
260             std::u16string_view sName = pDispIter->subView(nIndex);
261             sName = sName.substr(0, sName.rfind(sDisplayName));
262             OUString sCurrentDisplayName;
263             aDisplayNamesValue[j] >>= sCurrentDisplayName;
264             aDisplayNameMap.emplace(OUString(sName),sCurrentDisplayName);
265         }
266     }
267 
268     // load color settings
269     OUString sScheme(rScheme);
270 
271     if(sScheme.isEmpty())
272     {
273         //detect current scheme name
274         uno::Sequence < OUString > aCurrent { u"ExtendedColorScheme/CurrentColorScheme"_ustr };
275         uno::Sequence< uno::Any > aCurrentVal = GetProperties( aCurrent );
276         aCurrentVal.getConstArray()[0] >>= sScheme;
277     } // if(!sScheme.getLength())
278 
279     m_sLoadedScheme = sScheme;
280     OUString sBase = "ExtendedColorScheme/ColorSchemes/"
281                    + sScheme;
282 
283     bool bFound = ExistsScheme(sScheme);
284     if ( bFound )
285     {
286         aComponentNames = GetPropertyNames(sBase);
287         FillComponentColors(aComponentNames,aDisplayNameMap);
288     }
289 
290     if ( m_sLoadedScheme.isEmpty() )
291         m_sLoadedScheme = "default";
292 
293     if ( sScheme != "default" )
294     {
295         if ( ExistsScheme(u"default") )
296         {
297             aComponentNames = GetPropertyNames(u"ExtendedColorScheme/ColorSchemes/default"_ustr);
298             FillComponentColors(aComponentNames,aDisplayNameMap);
299         }
300     }
301     if ( !bFound && !sScheme.isEmpty() )
302     {
303         AddScheme(sScheme);
304         CommitCurrentSchemeName();
305     }
306 }
307 
FillComponentColors(const uno::Sequence<OUString> & _rComponents,const TDisplayNames & _rDisplayNames)308 void ExtendedColorConfig_Impl::FillComponentColors(const uno::Sequence < OUString >& _rComponents,const TDisplayNames& _rDisplayNames)
309 {
310     static constexpr OUStringLiteral sColorEntries(u"/Entries");
311     for(OUString const & component : _rComponents)
312     {
313         OUString sComponentName = component.copy(component.lastIndexOf('/')+1);
314         if ( m_aConfigValues.find(sComponentName) == m_aConfigValues.end() )
315         {
316             OUString sEntry = component + sColorEntries;
317 
318             uno::Sequence < OUString > aColorNames = GetPropertyNames(sEntry);
319             uno::Sequence < OUString > aDefaultColorNames = aColorNames;
320 
321             static constexpr OUString sColor(u"/Color"_ustr);
322             lcl_addString(aColorNames,sColor);
323             lcl_addString(aDefaultColorNames,u"/DefaultColor");
324             uno::Sequence< uno::Any > aColors = GetProperties( aColorNames );
325             const uno::Any* pColors = aColors.getConstArray();
326 
327             uno::Sequence< uno::Any > aDefaultColors = GetProperties( aDefaultColorNames );
328             bool bDefaultColorFound = aDefaultColors.hasElements();
329             const uno::Any* pDefaultColors = aDefaultColors.getConstArray();
330 
331             OUString* pColorIter = aColorNames.getArray();
332             OUString* pColorEnd  = pColorIter + aColorNames.getLength();
333 
334             m_aConfigValuesPos.push_back(m_aConfigValues.emplace(sComponentName,TComponentMapping(TConfigValues(),TMapPos())).first);
335             TConfigValues& aConfigValues = (*m_aConfigValuesPos.rbegin())->second.first;
336             TMapPos& aConfigValuesPos = (*m_aConfigValuesPos.rbegin())->second.second;
337             for(int i = 0; pColorIter != pColorEnd; ++pColorIter ,++i)
338             {
339                 if ( aConfigValues.find(*pColorIter) == aConfigValues.end() )
340                 {
341                     sal_Int32 nIndex = 0;
342                     o3tl::getToken(*pColorIter, 2, '/', nIndex);
343                     OUString sName(pColorIter->copy(nIndex)),sDisplayName;
344                     OUString sTemp = sName.copy(0,sName.lastIndexOf(sColor));
345 
346                     TDisplayNames::const_iterator aFind = _rDisplayNames.find(sTemp);
347                     sName = sName.getToken(2, '/');
348                     OSL_ENSURE(aFind != _rDisplayNames.end(),"DisplayName is not in EntryNames config list!");
349                     if ( aFind != _rDisplayNames.end() )
350                         sDisplayName = aFind->second;
351 
352                     OSL_ENSURE(pColors[i].hasValue(),"Color config entry has NIL as color value set!");
353                     OSL_ENSURE(pDefaultColors[i].hasValue(),"Color config entry has NIL as color value set!");
354                     Color nColor, nDefaultColor;
355                     pColors[i] >>= nColor;
356                     if ( bDefaultColorFound )
357                         pDefaultColors[i] >>= nDefaultColor;
358                     else
359                         nDefaultColor = nColor;
360                     ExtendedColorConfigValue aValue(sName,sDisplayName,nColor,nDefaultColor);
361                     aConfigValuesPos.push_back(aConfigValues.emplace(sName,aValue).first);
362                 }
363             } // for(int i = 0; pColorIter != pColorEnd; ++pColorIter ,++i)
364         }
365     }
366 }
367 
Notify(const uno::Sequence<OUString> &)368 void    ExtendedColorConfig_Impl::Notify( const uno::Sequence<OUString>& /*rPropertyNames*/)
369 {
370     //loading via notification always uses the default setting
371     Load(OUString());
372 
373     SolarMutexGuard aVclGuard;
374 
375     if(m_bLockBroadcast)
376     {
377         m_bBroadcastWhenUnlocked = true;
378     }
379     else
380         Broadcast(SfxHint(SfxHintId::ColorsChanged));
381 }
382 
ImplCommit()383 void ExtendedColorConfig_Impl::ImplCommit()
384 {
385     if ( m_sLoadedScheme.isEmpty() )
386         return;
387     static constexpr OUStringLiteral sColorEntries(u"Entries");
388     static constexpr OUStringLiteral sColor(u"/Color");
389     OUString sBase = "ExtendedColorScheme/ColorSchemes/"
390                    + m_sLoadedScheme;
391     static constexpr OUString s_sSep(u"/"_ustr);
392 
393     for (auto const& configValue : m_aConfigValues)
394     {
395         if ( ConfigItem::AddNode(sBase, configValue.first) )
396         {
397             OUString sNode = sBase
398                            + s_sSep
399                            + configValue.first
400             //ConfigItem::AddNode(sNode, sColorEntries);
401                            + s_sSep
402                            + sColorEntries;
403 
404             uno::Sequence < beans::PropertyValue > aPropValues(configValue.second.first.size());
405             beans::PropertyValue* pPropValues = aPropValues.getArray();
406             for (auto const& elem : configValue.second.first)
407             {
408                 pPropValues->Name = sNode + s_sSep + elem.first;
409                 ConfigItem::AddNode(sNode, elem.first);
410                 pPropValues->Name += sColor;
411                 pPropValues->Value <<= elem.second.getColor();
412                 // the default color will never be changed
413                 ++pPropValues;
414             }
415             SetSetProperties(u"ExtendedColorScheme/ColorSchemes"_ustr, aPropValues);
416         }
417     }
418 
419     CommitCurrentSchemeName();
420 }
421 
CommitCurrentSchemeName()422 void ExtendedColorConfig_Impl::CommitCurrentSchemeName()
423 {
424     //save current scheme name
425     uno::Sequence < OUString > aCurrent { u"ExtendedColorScheme/CurrentColorScheme"_ustr };
426     uno::Sequence< uno::Any > aCurrentVal(1);
427     aCurrentVal.getArray()[0] <<= m_sLoadedScheme;
428     PutProperties(aCurrent, aCurrentVal);
429 }
430 
ExistsScheme(std::u16string_view _sSchemeName)431 bool ExtendedColorConfig_Impl::ExistsScheme(std::u16string_view _sSchemeName)
432 {
433     OUString sBase(u"ExtendedColorScheme/ColorSchemes"_ustr);
434 
435     uno::Sequence < OUString > aComponentNames = GetPropertyNames(sBase);
436     sBase += OUString::Concat("/") + _sSchemeName;
437     return comphelper::findValue(aComponentNames, sBase) != -1;
438 }
439 
SetColorConfigValue(const OUString & _sName,const ExtendedColorConfigValue & rValue)440 void ExtendedColorConfig_Impl::SetColorConfigValue(const OUString& _sName, const ExtendedColorConfigValue& rValue )
441 {
442     TComponents::iterator aFind = m_aConfigValues.find(_sName);
443     if ( aFind != m_aConfigValues.end() )
444     {
445         TConfigValues::iterator aFind2 = aFind->second.first.find(rValue.getName());
446         if ( aFind2 != aFind->second.first.end() )
447             aFind2->second = rValue;
448         SetModified();
449     }
450 }
451 
AddScheme(const OUString & rScheme)452 void ExtendedColorConfig_Impl::AddScheme(const OUString& rScheme)
453 {
454     if(ConfigItem::AddNode(u"ExtendedColorScheme/ColorSchemes"_ustr, rScheme))
455     {
456         m_sLoadedScheme = rScheme;
457         Commit();
458     }
459 }
460 
RemoveScheme(const OUString & rScheme)461 void ExtendedColorConfig_Impl::RemoveScheme(const OUString& rScheme)
462 {
463     uno::Sequence< OUString > aElements { rScheme };
464     ClearNodeElements(u"ExtendedColorScheme/ColorSchemes"_ustr, aElements);
465 }
466 
SettingsChanged()467 void ExtendedColorConfig_Impl::SettingsChanged()
468 {
469     SolarMutexGuard aVclGuard;
470 
471     Broadcast( SfxHint( SfxHintId::ColorsChanged ) );
472 }
473 
LockBroadcast()474 void ExtendedColorConfig_Impl::LockBroadcast()
475 {
476     m_bLockBroadcast = true;
477 }
478 
UnlockBroadcast()479 void ExtendedColorConfig_Impl::UnlockBroadcast()
480 {
481     if ( m_bBroadcastWhenUnlocked )
482     {
483         m_bBroadcastWhenUnlocked = ExtendedColorConfig::m_pImpl != nullptr;
484         if ( m_bBroadcastWhenUnlocked )
485         {
486             if (ExtendedColorConfig::m_pImpl->m_bIsBroadcastEnabled)
487             {
488                 m_bBroadcastWhenUnlocked = false;
489                 ExtendedColorConfig::m_pImpl->Broadcast(SfxHint(SfxHintId::ColorsChanged));
490             }
491         }
492     }
493     m_bLockBroadcast = false;
494 }
495 
IMPL_LINK(ExtendedColorConfig_Impl,DataChangedEventListener,VclSimpleEvent &,rEvent,void)496 IMPL_LINK( ExtendedColorConfig_Impl, DataChangedEventListener, VclSimpleEvent&, rEvent, void )
497 {
498     if ( rEvent.GetId() == VclEventId::ApplicationDataChanged )
499     {
500         DataChangedEvent* pData = static_cast<DataChangedEvent*>(static_cast<VclWindowEvent&>(rEvent).GetData());
501         if ( (pData->GetType() == DataChangedEventType::SETTINGS) &&
502              (pData->GetFlags() & AllSettingsFlags::STYLE) )
503         {
504             SettingsChanged();
505         }
506     }
507 }
508 
509 
ExtendedColorConfig()510 ExtendedColorConfig::ExtendedColorConfig()
511 {
512     std::unique_lock aGuard( ColorMutex_Impl() );
513     if ( !m_pImpl )
514         m_pImpl = new ExtendedColorConfig_Impl;
515     ++nExtendedColorRefCount_Impl;
516     StartListening( *m_pImpl);
517 }
518 
~ExtendedColorConfig()519 ExtendedColorConfig::~ExtendedColorConfig()
520 {
521     std::unique_lock aGuard( ColorMutex_Impl() );
522     EndListening( *m_pImpl);
523     if(!--nExtendedColorRefCount_Impl)
524     {
525         delete m_pImpl;
526         m_pImpl = nullptr;
527     }
528 }
529 
GetColorValue(const OUString & _sComponentName,const OUString & _sName) const530 ExtendedColorConfigValue ExtendedColorConfig::GetColorValue(const OUString& _sComponentName,const OUString& _sName)const
531 {
532     return m_pImpl->GetColorConfigValue(_sComponentName,_sName);
533 }
534 
GetComponentCount() const535 sal_Int32 ExtendedColorConfig::GetComponentCount() const
536 {
537     return m_pImpl->GetComponentCount();
538 }
539 
GetComponentColorCount(const OUString & _sName) const540 sal_Int32 ExtendedColorConfig::GetComponentColorCount(const OUString& _sName) const
541 {
542     return m_pImpl->GetComponentColorCount(_sName);
543 }
544 
GetComponentColorConfigValue(const OUString & _sName,sal_uInt32 _nPos) const545 ExtendedColorConfigValue ExtendedColorConfig::GetComponentColorConfigValue(const OUString& _sName,sal_uInt32 _nPos) const
546 {
547     return m_pImpl->GetComponentColorConfigValue(_sName,_nPos);
548 }
549 
GetComponentName(sal_uInt32 _nPos) const550 OUString ExtendedColorConfig::GetComponentName(sal_uInt32 _nPos) const
551 {
552     return m_pImpl->GetComponentName(_nPos);
553 }
554 
GetComponentDisplayName(const OUString & _sComponentName) const555 OUString ExtendedColorConfig::GetComponentDisplayName(const OUString& _sComponentName) const
556 {
557     return m_pImpl->GetComponentDisplayName(_sComponentName);
558 }
559 
Notify(SfxBroadcaster &,const SfxHint & rHint)560 void ExtendedColorConfig::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
561 {
562     SolarMutexGuard aVclGuard;
563 
564     Broadcast( rHint );
565 }
566 
EditableExtendedColorConfig()567 EditableExtendedColorConfig::EditableExtendedColorConfig() :
568     m_pImpl(new ExtendedColorConfig_Impl),
569     m_bModified(false)
570 {
571     ExtendedColorConfig_Impl::LockBroadcast();
572 }
573 
~EditableExtendedColorConfig()574 EditableExtendedColorConfig::~EditableExtendedColorConfig()
575 {
576     ExtendedColorConfig_Impl::UnlockBroadcast();
577     if(m_bModified)
578         m_pImpl->SetModified();
579     if(m_pImpl->IsModified())
580         m_pImpl->Commit();
581 }
582 
DeleteScheme(const OUString & rScheme)583 void EditableExtendedColorConfig::DeleteScheme(const OUString& rScheme )
584 {
585     m_pImpl->RemoveScheme(rScheme);
586 }
587 
AddScheme(const OUString & rScheme)588 void EditableExtendedColorConfig::AddScheme(const OUString& rScheme )
589 {
590     m_pImpl->AddScheme(rScheme);
591 }
592 
LoadScheme(const OUString & rScheme)593 void EditableExtendedColorConfig::LoadScheme(const OUString& rScheme )
594 {
595     if(m_bModified)
596         m_pImpl->SetModified();
597     if(m_pImpl->IsModified())
598         m_pImpl->Commit();
599     m_bModified = false;
600     m_pImpl->Load(rScheme);
601     //the name of the loaded scheme has to be committed separately
602     m_pImpl->CommitCurrentSchemeName();
603 }
604 
605 // Changes the name of the current scheme but doesn't load it!
SetCurrentSchemeName(const OUString & rScheme)606 void EditableExtendedColorConfig::SetCurrentSchemeName(const OUString& rScheme)
607 {
608     m_pImpl->SetCurrentSchemeName(rScheme);
609     m_pImpl->CommitCurrentSchemeName();
610 }
611 
SetColorValue(const OUString & _sName,const ExtendedColorConfigValue & rValue)612 void EditableExtendedColorConfig::SetColorValue(
613     const OUString& _sName, const ExtendedColorConfigValue& rValue)
614 {
615     m_pImpl->SetColorConfigValue(_sName, rValue);
616     m_pImpl->ClearModified();
617     m_bModified = true;
618 }
619 
SetModified()620 void EditableExtendedColorConfig::SetModified()
621 {
622     m_bModified = true;
623 }
624 
Commit()625 void EditableExtendedColorConfig::Commit()
626 {
627     if(m_bModified)
628         m_pImpl->SetModified();
629     if(m_pImpl->IsModified())
630         m_pImpl->Commit();
631     m_bModified = false;
632 }
633 
DisableBroadcast()634 void EditableExtendedColorConfig::DisableBroadcast()
635 {
636     ExtendedColorConfig_Impl::DisableBroadcast();
637 }
638 
EnableBroadcast()639 void EditableExtendedColorConfig::EnableBroadcast()
640 {
641     ExtendedColorConfig_Impl::EnableBroadcast();
642 }
643 
GetComponentCount() const644 sal_Int32 EditableExtendedColorConfig::GetComponentCount() const
645 {
646     return m_pImpl->GetComponentCount();
647 }
648 
GetComponentColorCount(const OUString & _sName) const649 sal_Int32 EditableExtendedColorConfig::GetComponentColorCount(const OUString& _sName) const
650 {
651     return m_pImpl->GetComponentColorCount(_sName);
652 }
653 
GetComponentColorConfigValue(const OUString & _sName,sal_uInt32 _nPos) const654 ExtendedColorConfigValue EditableExtendedColorConfig::GetComponentColorConfigValue(const OUString& _sName,sal_uInt32 _nPos) const
655 {
656     return m_pImpl->GetComponentColorConfigValue(_sName,_nPos);
657 }
658 
GetComponentName(sal_uInt32 _nPos) const659 OUString EditableExtendedColorConfig::GetComponentName(sal_uInt32 _nPos) const
660 {
661     return m_pImpl->GetComponentName(_nPos);
662 }
663 }//namespace svtools
664 
665 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
666