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