Update ooo320-m1
[ooovba.git] / svtools / source / config / extcolorcfg.cxx
blobae1452ea113d3db335de2f2ac646c0171e5183f5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: extcolorcfg.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifdef SVL_DLLIMPLEMENTATION
32 #undef SVL_DLLIMPLEMENTATION
33 #endif
34 #define SVT_DLLIMPLEMENTATION
36 #include "extcolorcfg.hxx"
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <com/sun/star/lang/Locale.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <tools/color.hxx>
42 #include <tools/debug.hxx>
43 #include <unotools/configitem.hxx>
44 #include <unotools/configpathes.hxx>
45 #include <com/sun/star/uno/Sequence.h>
46 #include <svtools/poolitem.hxx> //Any2Bool
47 #include <svtools/smplhint.hxx>
48 #include <vos/mutex.hxx>
50 /* #100822# ----
51 #include <vcl/wrkwin.hxx>
52 ------------- */
53 #include <vcl/svapp.hxx>
54 #include <vcl/event.hxx>
55 #include <rtl/instance.hxx>
56 #include <rtl/strbuf.hxx>
57 #include <comphelper/stl_types.hxx>
60 //-----------------------------------------------------------------------------
61 using namespace utl;
62 using namespace rtl;
63 using namespace com::sun::star;
65 namespace svtools
68 #define C2U(cChar) OUString::createFromAscii(cChar)
69 sal_Int32 nExtendedColorRefCount_Impl = 0;
70 namespace
72 struct ColorMutex_Impl
73 : public rtl::Static< ::osl::Mutex, ColorMutex_Impl > {};
76 ExtendedColorConfig_Impl* ExtendedColorConfig::m_pImpl = NULL;
78 /* -----------------------------16.01.01 15:36--------------------------------
79 ---------------------------------------------------------------------------*/
80 class ExtendedColorConfig_Impl : public utl::ConfigItem, public SfxBroadcaster
82 DECLARE_STL_USTRINGACCESS_MAP( ::rtl::OUString, TDisplayNames);
83 DECLARE_STL_USTRINGACCESS_MAP(ExtendedColorConfigValue,TConfigValues);
84 typedef ::std::vector<TConfigValues::iterator> TMapPos;
85 typedef ::std::pair< TConfigValues, TMapPos > TComponentMapping;
86 DECLARE_STL_USTRINGACCESS_MAP(TComponentMapping,TComponents);
87 TComponents m_aConfigValues;
88 TDisplayNames m_aComponentDisplayNames;
89 ::std::vector<TComponents::iterator> m_aConfigValuesPos;
91 sal_Bool m_bEditMode;
92 rtl::OUString m_sLoadedScheme;
93 sal_Bool m_bIsBroadcastEnabled;
94 static sal_Bool m_bLockBroadcast;
95 static sal_Bool m_bBroadcastWhenUnlocked;
97 uno::Sequence< ::rtl::OUString> GetPropertyNames(const rtl::OUString& rScheme);
98 void FillComponentColors(uno::Sequence < ::rtl::OUString >& _rComponents,const TDisplayNames& _rDisplayNames);
99 public:
100 ExtendedColorConfig_Impl(sal_Bool bEditMode = sal_False);
101 virtual ~ExtendedColorConfig_Impl();
103 void Load(const rtl::OUString& rScheme);
104 void CommitCurrentSchemeName();
105 //changes the name of the current scheme but doesn't load it!
106 void SetCurrentSchemeName(const rtl::OUString& rSchemeName) {m_sLoadedScheme = rSchemeName;}
107 sal_Bool ExistsScheme(const ::rtl::OUString& _sSchemeName);
108 virtual void Commit();
109 virtual void Notify( const uno::Sequence<rtl::OUString>& aPropertyNames);
111 sal_Int32 GetComponentCount() const;
112 ::rtl::OUString GetComponentName(sal_uInt32 _nPos) const;
113 ::rtl::OUString GetComponentDisplayName(const ::rtl::OUString& _sComponentName) const;
114 sal_Int32 GetComponentColorCount(const ::rtl::OUString& _sName) const;
115 ExtendedColorConfigValue GetComponentColorConfigValue(const ::rtl::OUString& _sName,sal_uInt32 _nPos) const;
117 ExtendedColorConfigValue GetColorConfigValue(const ::rtl::OUString& _sComponentName,const ::rtl::OUString& _sName)
119 TComponents::iterator aFind = m_aConfigValues.find(_sComponentName);
120 if ( aFind != m_aConfigValues.end() )
122 TConfigValues::iterator aFind2 = aFind->second.first.find(_sName);
123 if ( aFind2 != aFind->second.first.end() )
124 return aFind2->second;
126 #if OSL_DEBUG_LEVEL > 0
127 ::rtl::OStringBuffer aMessage( "Could find the required config:\n" );
128 aMessage.append( "component: " );
129 aMessage.append( ::rtl::OUStringToOString( _sComponentName, RTL_TEXTENCODING_UTF8 ) );
130 aMessage.append( "\nname: " );
131 aMessage.append( ::rtl::OUStringToOString( _sName, RTL_TEXTENCODING_UTF8 ) );
132 OSL_ENSURE( 0, aMessage.makeStringAndClear().getStr() );
133 #endif
134 return ExtendedColorConfigValue();
136 void SetColorConfigValue(const ::rtl::OUString& _sName,
137 const ExtendedColorConfigValue& rValue );
139 const rtl::OUString& GetLoadedScheme() const {return m_sLoadedScheme;}
141 uno::Sequence< ::rtl::OUString> GetSchemeNames();
143 sal_Bool AddScheme(const rtl::OUString& rNode);
144 sal_Bool RemoveScheme(const rtl::OUString& rNode);
145 void SetModified(){ConfigItem::SetModified();}
146 void ClearModified(){ConfigItem::ClearModified();}
147 void SettingsChanged();
149 static void DisableBroadcast();
150 static void EnableBroadcast();
151 static sal_Bool IsEnableBroadcast();
153 static void LockBroadcast();
154 static void UnlockBroadcast();
156 // #100822#
157 DECL_LINK( DataChangedEventListener, VclWindowEvent* );
160 /* -----------------------------16.01.01 15:36--------------------------------
162 ---------------------------------------------------------------------------*/
163 uno::Sequence< OUString> ExtendedColorConfig_Impl::GetPropertyNames(const rtl::OUString& rScheme)
165 uno::Sequence< OUString> aNames(GetNodeNames(rScheme));
166 ::rtl::OUString* pIter = aNames.getArray();
167 ::rtl::OUString* pEnd = pIter + aNames.getLength();
168 ::rtl::OUString sSep(RTL_CONSTASCII_USTRINGPARAM("/"));
169 for(;pIter != pEnd;++pIter)
171 *pIter = rScheme + sSep + *pIter;
173 return aNames;
175 // -----------------------------------------------------------------------------
176 sal_Int32 ExtendedColorConfig_Impl::GetComponentCount() const
178 return m_aConfigValues.size();
180 // -----------------------------------------------------------------------------
181 sal_Int32 ExtendedColorConfig_Impl::GetComponentColorCount(const ::rtl::OUString& _sName) const
183 sal_Int32 nSize = 0;
184 TComponents::const_iterator aFind = m_aConfigValues.find(_sName);
185 if ( aFind != m_aConfigValues.end() )
187 nSize = aFind->second.first.size();
189 return nSize;
191 // -----------------------------------------------------------------------------
192 ExtendedColorConfigValue ExtendedColorConfig_Impl::GetComponentColorConfigValue(const ::rtl::OUString& _sName,sal_uInt32 _nPos) const
194 TComponents::const_iterator aFind = m_aConfigValues.find(_sName);
195 if ( aFind != m_aConfigValues.end() )
197 if ( _nPos < aFind->second.second.size() )
199 return aFind->second.second[_nPos]->second;
202 return ExtendedColorConfigValue();
204 // -----------------------------------------------------------------------------
205 ::rtl::OUString ExtendedColorConfig_Impl::GetComponentDisplayName(const ::rtl::OUString& _sComponentName) const
207 ::rtl::OUString sRet;
208 TDisplayNames::const_iterator aFind = m_aComponentDisplayNames.find(_sComponentName);
209 if ( aFind != m_aComponentDisplayNames.end() )
210 sRet = aFind->second;
211 return sRet;
213 // -----------------------------------------------------------------------------
214 ::rtl::OUString ExtendedColorConfig_Impl::GetComponentName(sal_uInt32 _nPos) const
216 ::rtl::OUString sRet;
217 if ( _nPos < m_aConfigValuesPos.size() )
218 sRet = m_aConfigValuesPos[_nPos]->first;
219 return sRet;
221 // -----------------------------------------------------------------------------
222 /* -----------------------------22.03.2002 14:37------------------------------
224 ---------------------------------------------------------------------------*/
225 sal_Bool ExtendedColorConfig_Impl::m_bLockBroadcast = sal_False;
226 sal_Bool ExtendedColorConfig_Impl::m_bBroadcastWhenUnlocked = sal_False;
227 ExtendedColorConfig_Impl::ExtendedColorConfig_Impl(sal_Bool bEditMode) :
228 ConfigItem(C2U("Office.ExtendedColorScheme")),
229 m_bEditMode(bEditMode),
230 m_bIsBroadcastEnabled(sal_True)
232 if(!m_bEditMode)
234 //try to register on the root node - if possible
235 uno::Sequence < ::rtl::OUString > aNames(1);
236 EnableNotification( aNames );
238 Load(::rtl::OUString());
240 // #100822#
241 ::Application::AddEventListener( LINK(this, ExtendedColorConfig_Impl, DataChangedEventListener) );
244 /* -----------------------------25.03.2002 12:28------------------------------
246 ---------------------------------------------------------------------------*/
247 ExtendedColorConfig_Impl::~ExtendedColorConfig_Impl()
249 // #100822#
250 ::Application::RemoveEventListener( LINK(this, ExtendedColorConfig_Impl, DataChangedEventListener) );
252 // -----------------------------------------------------------------------------
253 void ExtendedColorConfig_Impl::DisableBroadcast()
255 if ( ExtendedColorConfig::m_pImpl )
256 ExtendedColorConfig::m_pImpl->m_bIsBroadcastEnabled = sal_False;
258 // -----------------------------------------------------------------------------
259 void ExtendedColorConfig_Impl::EnableBroadcast()
261 if ( ExtendedColorConfig::m_pImpl )
262 ExtendedColorConfig::m_pImpl->m_bIsBroadcastEnabled = sal_True;
264 // -----------------------------------------------------------------------------
265 sal_Bool ExtendedColorConfig_Impl::IsEnableBroadcast()
267 return ExtendedColorConfig::m_pImpl ? ExtendedColorConfig::m_pImpl->m_bIsBroadcastEnabled : sal_False;
269 /* -----------------------------22.03.2002 14:38------------------------------
271 ---------------------------------------------------------------------------*/
272 void lcl_addString(uno::Sequence < ::rtl::OUString >& _rSeq,const ::rtl::OUString& _sAdd)
274 ::rtl::OUString* pIter = _rSeq.getArray();
275 ::rtl::OUString* pEnd = pIter + _rSeq.getLength();
276 for(;pIter != pEnd;++pIter)
277 *pIter += _sAdd;
279 // -----------------------------------------------------------------------------
280 void ExtendedColorConfig_Impl::Load(const rtl::OUString& rScheme)
282 m_aComponentDisplayNames.clear();
283 m_aConfigValuesPos.clear();
284 m_aConfigValues.clear();
286 // fill display names
287 TDisplayNames aDisplayNameMap;
288 ::rtl::OUString sEntryNames(RTL_CONSTASCII_USTRINGPARAM("EntryNames"));
289 uno::Sequence < ::rtl::OUString > aComponentNames = GetPropertyNames(sEntryNames);
290 ::rtl::OUString sDisplayName(RTL_CONSTASCII_USTRINGPARAM("/DisplayName"));
291 ::rtl::OUString* pIter = aComponentNames.getArray();
292 ::rtl::OUString* pEnd = pIter + aComponentNames.getLength();
293 for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
295 uno::Sequence < ::rtl::OUString > aComponentDisplayNames(1);
296 aComponentDisplayNames[0] = *pIter;
297 aComponentDisplayNames[0] += sDisplayName;
298 uno::Sequence< uno::Any > aComponentDisplayNamesValue = GetProperties( aComponentDisplayNames );
299 ::rtl::OUString sComponentDisplayName;
300 if ( aComponentDisplayNamesValue.getLength() && (aComponentDisplayNamesValue[0] >>= sComponentDisplayName) )
302 sal_Int32 nIndex = 0;
303 m_aComponentDisplayNames.insert(TDisplayNames::value_type(pIter->getToken(1,'/',nIndex),sComponentDisplayName));
306 *pIter += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/Entries"));
307 uno::Sequence < ::rtl::OUString > aDisplayNames = GetPropertyNames(*pIter);
308 lcl_addString(aDisplayNames,sDisplayName);
310 uno::Sequence< uno::Any > aDisplayNamesValue = GetProperties( aDisplayNames );
312 const ::rtl::OUString* pDispIter = aDisplayNames.getConstArray();
313 const ::rtl::OUString* pDispEnd = pDispIter + aDisplayNames.getLength();
314 for(sal_Int32 j = 0;pDispIter != pDispEnd;++pDispIter,++j)
316 sal_Int32 nIndex = 0;
317 pDispIter->getToken(0,'/',nIndex);
318 ::rtl::OUString sName = pDispIter->copy(nIndex);
319 sName = sName.copy(0,sName.lastIndexOf(sDisplayName));
320 ::rtl::OUString sCurrentDisplayName;
321 aDisplayNamesValue[j] >>= sCurrentDisplayName;
322 aDisplayNameMap.insert(TDisplayNames::value_type(sName,sCurrentDisplayName));
326 // load color settings
327 rtl::OUString sScheme(rScheme);
329 if(!sScheme.getLength())
331 //detect current scheme name
332 uno::Sequence < ::rtl::OUString > aCurrent(1);
333 aCurrent.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ExtendedColorScheme/CurrentColorScheme"));
334 uno::Sequence< uno::Any > aCurrentVal = GetProperties( aCurrent );
335 aCurrentVal.getConstArray()[0] >>= sScheme;
336 } // if(!sScheme.getLength())
338 m_sLoadedScheme = sScheme;
339 ::rtl::OUString sBase(RTL_CONSTASCII_USTRINGPARAM("ExtendedColorScheme/ColorSchemes/"));
340 sBase += sScheme;
342 sal_Bool bFound = ExistsScheme(sScheme);
343 if ( bFound )
345 aComponentNames = GetPropertyNames(sBase);
346 FillComponentColors(aComponentNames,aDisplayNameMap);
347 } // if ( bFound )
349 if ( !m_sLoadedScheme.getLength() )
350 m_sLoadedScheme = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("default"));
352 if ( !sScheme.equalsAscii("default") )
354 ::rtl::OUString sDefault(RTL_CONSTASCII_USTRINGPARAM("default"));
355 if ( ExistsScheme(sDefault) )
357 ::rtl::OUString sBaseDefault(RTL_CONSTASCII_USTRINGPARAM("ExtendedColorScheme/ColorSchemes/default"));
358 aComponentNames = GetPropertyNames(sBaseDefault);
359 FillComponentColors(aComponentNames,aDisplayNameMap);
361 } // if ( !sScheme.equalsAscii("default") )
362 if ( !bFound && sScheme.getLength() )
364 AddScheme(sScheme);
365 CommitCurrentSchemeName();
368 // -----------------------------------------------------------------------------
369 void ExtendedColorConfig_Impl::FillComponentColors(uno::Sequence < ::rtl::OUString >& _rComponents,const TDisplayNames& _rDisplayNames)
371 const ::rtl::OUString sColorEntries(RTL_CONSTASCII_USTRINGPARAM("/Entries"));
372 ::rtl::OUString* pIter = _rComponents.getArray();
373 ::rtl::OUString* pEnd = pIter + _rComponents.getLength();
374 for(;pIter != pEnd;++pIter)
376 ::rtl::OUString sComponentName = pIter->copy(pIter->lastIndexOf('/')+1);
377 if ( m_aConfigValues.find(sComponentName) == m_aConfigValues.end() )
379 ::rtl::OUString sEntry = *pIter;
380 sEntry += sColorEntries;
382 uno::Sequence < ::rtl::OUString > aColorNames = GetPropertyNames(sEntry);
383 uno::Sequence < ::rtl::OUString > aDefaultColorNames = aColorNames;
385 const ::rtl::OUString sColor(RTL_CONSTASCII_USTRINGPARAM("/Color"));
386 const ::rtl::OUString sDefaultColor(RTL_CONSTASCII_USTRINGPARAM("/DefaultColor"));
387 lcl_addString(aColorNames,sColor);
388 lcl_addString(aDefaultColorNames,sDefaultColor);
389 uno::Sequence< uno::Any > aColors = GetProperties( aColorNames );
390 const uno::Any* pColors = aColors.getConstArray();
392 uno::Sequence< uno::Any > aDefaultColors = GetProperties( aDefaultColorNames );
393 bool bDefaultColorFound = aDefaultColors.getLength() != 0;
394 const uno::Any* pDefaultColors = aDefaultColors.getConstArray();
396 ::rtl::OUString* pColorIter = aColorNames.getArray();
397 ::rtl::OUString* pColorEnd = pColorIter + aColorNames.getLength();
399 m_aConfigValuesPos.push_back(m_aConfigValues.insert(TComponents::value_type(sComponentName,TComponentMapping(TConfigValues(),TMapPos()))).first);
400 TConfigValues& aConfigValues = (*m_aConfigValuesPos.rbegin())->second.first;
401 TMapPos& aConfigValuesPos = (*m_aConfigValuesPos.rbegin())->second.second;
402 for(int i = 0; pColorIter != pColorEnd; ++pColorIter ,++i)
404 if ( aConfigValues.find(*pColorIter) == aConfigValues.end() )
406 sal_Int32 nIndex = 0;
407 pColorIter->getToken(2,'/',nIndex);
408 ::rtl::OUString sName(pColorIter->copy(nIndex)),sDisplayName;
409 ::rtl::OUString sTemp = sName.copy(0,sName.lastIndexOf(sColor));
411 TDisplayNames::const_iterator aFind = _rDisplayNames.find(sTemp);
412 nIndex = 0;
413 sName = sName.getToken(2,'/',nIndex);
414 OSL_ENSURE(aFind != _rDisplayNames.end(),"DisplayName is not in EntryNames config list!");
415 if ( aFind != _rDisplayNames.end() )
416 sDisplayName = aFind->second;
418 OSL_ENSURE(pColors[i].hasValue(),"Color config entry has NIL as color value set!");
419 OSL_ENSURE(pDefaultColors[i].hasValue(),"Color config entry has NIL as color value set!");
420 sal_Int32 nColor = 0,nDefaultColor = 0;
421 pColors[i] >>= nColor;
422 if ( bDefaultColorFound )
423 pDefaultColors[i] >>= nDefaultColor;
424 else
425 nDefaultColor = nColor;
426 ExtendedColorConfigValue aValue(sName,sDisplayName,nColor,nDefaultColor);
427 aConfigValuesPos.push_back(aConfigValues.insert(TConfigValues::value_type(sName,aValue)).first);
429 } // for(int i = 0; pColorIter != pColorEnd; ++pColorIter ,++i)
433 /* -----------------------------22.03.2002 14:38------------------------------
435 ---------------------------------------------------------------------------*/
436 void ExtendedColorConfig_Impl::Notify( const uno::Sequence<OUString>& /*rPropertyNames*/)
438 //loading via notification always uses the default setting
439 Load(::rtl::OUString());
441 vos::OGuard aVclGuard( Application::GetSolarMutex() );
443 if(m_bLockBroadcast)
445 m_bBroadcastWhenUnlocked = sal_True;
447 else
448 Broadcast(SfxSimpleHint(SFX_HINT_COLORS_CHANGED));
450 /* -----------------------------22.03.2002 14:38------------------------------
452 ---------------------------------------------------------------------------*/
453 void ExtendedColorConfig_Impl::Commit()
455 if ( !m_sLoadedScheme.getLength() )
456 return;
457 const ::rtl::OUString sColorEntries(RTL_CONSTASCII_USTRINGPARAM("Entries"));
458 const ::rtl::OUString sColor(RTL_CONSTASCII_USTRINGPARAM("/Color"));
459 const ::rtl::OUString sDefaultColor(RTL_CONSTASCII_USTRINGPARAM("/DefaultColor"));
460 ::rtl::OUString sBase(RTL_CONSTASCII_USTRINGPARAM("ExtendedColorScheme/ColorSchemes/"));
461 const ::rtl::OUString s_sSep(RTL_CONSTASCII_USTRINGPARAM("/"));
462 sBase += m_sLoadedScheme;
464 TComponents::iterator aIter = m_aConfigValues.begin();
465 TComponents::iterator aEnd = m_aConfigValues.end();
466 for( ;aIter != aEnd;++aIter )
468 ::rtl::OUString sEntry = aIter->first;
469 sEntry += sColorEntries;
471 if ( ConfigItem::AddNode(sBase, aIter->first) )
473 rtl::OUString sNode = sBase;
474 sNode += s_sSep;
475 sNode += aIter->first;
476 //ConfigItem::AddNode(sNode, sColorEntries);
477 sNode += s_sSep;
478 sNode += sColorEntries;
480 uno::Sequence < beans::PropertyValue > aPropValues(aIter->second.first.size());
481 beans::PropertyValue* pPropValues = aPropValues.getArray();
482 TConfigValues::iterator aConIter = aIter->second.first.begin();
483 TConfigValues::iterator aConEnd = aIter->second.first.end();
484 for (; aConIter != aConEnd; ++aConIter,++pPropValues)
486 pPropValues->Name = sNode + s_sSep + aConIter->first;
487 ConfigItem::AddNode(sNode, aConIter->first);
488 pPropValues->Name += sColor;
489 pPropValues->Value <<= aConIter->second.getColor();
490 // the default color will never be changed
492 ::rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("ExtendedColorScheme/ColorSchemes"));
493 SetSetProperties(s, aPropValues);
497 CommitCurrentSchemeName();
499 /* -----------------11.12.2002 10:42-----------------
501 * --------------------------------------------------*/
502 void ExtendedColorConfig_Impl::CommitCurrentSchemeName()
504 //save current scheme name
505 uno::Sequence < ::rtl::OUString > aCurrent(1);
506 aCurrent.getArray()[0] = C2U("ExtendedColorScheme/CurrentColorScheme");
507 uno::Sequence< uno::Any > aCurrentVal(1);
508 aCurrentVal.getArray()[0] <<= m_sLoadedScheme;
509 PutProperties(aCurrent, aCurrentVal);
511 // -----------------------------------------------------------------------------
512 sal_Bool ExtendedColorConfig_Impl::ExistsScheme(const ::rtl::OUString& _sSchemeName)
514 ::rtl::OUString sBase(RTL_CONSTASCII_USTRINGPARAM("ExtendedColorScheme/ColorSchemes"));
516 uno::Sequence < ::rtl::OUString > aComponentNames = GetPropertyNames(sBase);
517 sBase += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + _sSchemeName;
518 const ::rtl::OUString* pCompIter = aComponentNames.getConstArray();
519 const ::rtl::OUString* pCompEnd = pCompIter + aComponentNames.getLength();
520 for(;pCompIter != pCompEnd && *pCompIter != sBase;++pCompIter)
522 return pCompIter != pCompEnd;
524 // -----------------------------------------------------------------------------
525 /* -----------------------------25.03.2002 12:19------------------------------
527 ---------------------------------------------------------------------------*/
528 void ExtendedColorConfig_Impl::SetColorConfigValue(const ::rtl::OUString& _sName, const ExtendedColorConfigValue& rValue )
530 TComponents::iterator aFind = m_aConfigValues.find(_sName);
531 if ( aFind != m_aConfigValues.end() )
533 TConfigValues::iterator aFind2 = aFind->second.first.find(rValue.getName());
534 if ( aFind2 != aFind->second.first.end() )
535 aFind2->second = rValue;
536 SetModified();
539 /* -----------------------------25.03.2002 15:22------------------------------
541 ---------------------------------------------------------------------------*/
542 uno::Sequence< ::rtl::OUString> ExtendedColorConfig_Impl::GetSchemeNames()
544 return GetNodeNames(C2U("ExtendedColorScheme/ColorSchemes"));
546 /* -----------------------------09.04.2002 17:19------------------------------
548 ---------------------------------------------------------------------------*/
549 sal_Bool ExtendedColorConfig_Impl::AddScheme(const rtl::OUString& rScheme)
551 if(ConfigItem::AddNode(C2U("ExtendedColorScheme/ColorSchemes"), rScheme))
553 m_sLoadedScheme = rScheme;
554 Commit();
555 return sal_True;
557 return sal_False;
559 /* -----------------------------09.04.2002 17:19------------------------------
561 ---------------------------------------------------------------------------*/
562 sal_Bool ExtendedColorConfig_Impl::RemoveScheme(const rtl::OUString& rScheme)
564 uno::Sequence< rtl::OUString > aElements(1);
565 aElements.getArray()[0] = rScheme;
566 return ClearNodeElements(C2U("ExtendedColorScheme/ColorSchemes"), aElements);
568 /* -----------------------------2002/06/20 13:03------------------------------
570 ---------------------------------------------------------------------------*/
571 void ExtendedColorConfig_Impl::SettingsChanged()
573 vos::OGuard aVclGuard( Application::GetSolarMutex() );
575 Broadcast( SfxSimpleHint( SFX_HINT_COLORS_CHANGED ) );
577 /* -----------------11.12.2002 09:21-----------------
579 * --------------------------------------------------*/
580 void ExtendedColorConfig_Impl::LockBroadcast()
582 m_bLockBroadcast = sal_True;
584 /* -----------------11.12.2002 09:21-----------------
586 * --------------------------------------------------*/
587 void ExtendedColorConfig_Impl::UnlockBroadcast()
589 if ( m_bBroadcastWhenUnlocked )
591 m_bBroadcastWhenUnlocked = ExtendedColorConfig::m_pImpl != NULL;
592 if ( m_bBroadcastWhenUnlocked )
594 if ( ExtendedColorConfig::m_pImpl->IsEnableBroadcast() )
596 m_bBroadcastWhenUnlocked = sal_False;
597 ExtendedColorConfig::m_pImpl->Broadcast(SfxSimpleHint(SFX_HINT_COLORS_CHANGED));
601 m_bLockBroadcast = sal_False;
603 /* -----------------------------2002/08/16 12:07 -----------------------------
604 #100822#
605 --------------------------------------------------------------------------- */
606 IMPL_LINK( ExtendedColorConfig_Impl, DataChangedEventListener, VclWindowEvent*, pEvent )
608 if ( pEvent->GetId() == VCLEVENT_APPLICATION_DATACHANGED )
610 DataChangedEvent* pData = (DataChangedEvent*)(pEvent->GetData());
611 if ( (pData->GetType() == DATACHANGED_SETTINGS) &&
612 (pData->GetFlags() & SETTINGS_STYLE) )
614 SettingsChanged();
615 return 1L;
616 } else
617 return 0L;
618 } else
619 return 0L;
622 // ---------------------------------------------------------------------------
624 // ---------------------------------------------------------------------------
626 ExtendedColorConfig::ExtendedColorConfig()
628 ::osl::MutexGuard aGuard( ColorMutex_Impl::get() );
629 if ( !m_pImpl )
630 m_pImpl = new ExtendedColorConfig_Impl;
631 ++nExtendedColorRefCount_Impl;
632 StartListening( *m_pImpl);
634 /* -----------------------------16.01.01 15:36--------------------------------
636 ---------------------------------------------------------------------------*/
637 ExtendedColorConfig::~ExtendedColorConfig()
639 ::osl::MutexGuard aGuard( ColorMutex_Impl::get() );
640 EndListening( *m_pImpl);
641 if(!--nExtendedColorRefCount_Impl)
643 delete m_pImpl;
644 m_pImpl = 0;
647 /* -----------------------------11.04.2002 11:49------------------------------
649 ---------------------------------------------------------------------------*/
650 ExtendedColorConfigValue ExtendedColorConfig::GetColorValue(const ::rtl::OUString& _sComponentName,const ::rtl::OUString& _sName)const
652 return m_pImpl->GetColorConfigValue(_sComponentName,_sName);
654 // -----------------------------------------------------------------------------
655 sal_Int32 ExtendedColorConfig::GetComponentCount() const
657 return m_pImpl->GetComponentCount();
659 // -----------------------------------------------------------------------------
660 sal_Int32 ExtendedColorConfig::GetComponentColorCount(const ::rtl::OUString& _sName) const
662 return m_pImpl->GetComponentColorCount(_sName);
664 // -----------------------------------------------------------------------------
665 ExtendedColorConfigValue ExtendedColorConfig::GetComponentColorConfigValue(const ::rtl::OUString& _sName,sal_uInt32 _nPos) const
667 return m_pImpl->GetComponentColorConfigValue(_sName,_nPos);
669 // -----------------------------------------------------------------------------
670 ::rtl::OUString ExtendedColorConfig::GetComponentName(sal_uInt32 _nPos) const
672 return m_pImpl->GetComponentName(_nPos);
674 // -----------------------------------------------------------------------------
675 ::rtl::OUString ExtendedColorConfig::GetComponentDisplayName(const ::rtl::OUString& _sComponentName) const
677 return m_pImpl->GetComponentDisplayName(_sComponentName);
679 // -----------------------------------------------------------------------------
680 /* -----------------------------12.04.2002 09:25------------------------------
682 ---------------------------------------------------------------------------*/
683 void ExtendedColorConfig::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
685 vos::OGuard aVclGuard( Application::GetSolarMutex() );
687 Broadcast( rHint );
689 /* -----------------------------25.03.2002 12:01------------------------------
691 ---------------------------------------------------------------------------*/
692 EditableExtendedColorConfig::EditableExtendedColorConfig() :
693 m_pImpl(new ExtendedColorConfig_Impl),
694 m_bModified(sal_False)
696 m_pImpl->LockBroadcast();
698 /*-- 25.03.2002 12:03:08---------------------------------------------------
700 -----------------------------------------------------------------------*/
701 EditableExtendedColorConfig::~EditableExtendedColorConfig()
703 m_pImpl->UnlockBroadcast();
704 if(m_bModified)
705 m_pImpl->SetModified();
706 if(m_pImpl->IsModified())
707 m_pImpl->Commit();
708 delete m_pImpl;
711 /*-- 25.03.2002 12:03:15---------------------------------------------------
713 -----------------------------------------------------------------------*/
714 uno::Sequence< ::rtl::OUString > EditableExtendedColorConfig::GetSchemeNames() const
716 return m_pImpl->GetSchemeNames();
718 /*-- 25.03.2002 12:03:16---------------------------------------------------
720 -----------------------------------------------------------------------*/
721 void EditableExtendedColorConfig::DeleteScheme(const ::rtl::OUString& rScheme )
723 m_pImpl->RemoveScheme(rScheme);
725 /*-- 25.03.2002 12:03:16---------------------------------------------------
727 -----------------------------------------------------------------------*/
728 void EditableExtendedColorConfig::AddScheme(const ::rtl::OUString& rScheme )
730 m_pImpl->AddScheme(rScheme);
732 /*-- 25.03.2002 12:03:16---------------------------------------------------
734 -----------------------------------------------------------------------*/
735 sal_Bool EditableExtendedColorConfig::LoadScheme(const ::rtl::OUString& rScheme )
737 if(m_bModified)
738 m_pImpl->SetModified();
739 if(m_pImpl->IsModified())
740 m_pImpl->Commit();
741 m_bModified = sal_False;
742 m_pImpl->Load(rScheme);
743 //the name of the loaded scheme has to be committed separately
744 m_pImpl->CommitCurrentSchemeName();
745 return sal_True;
747 /*-- 25.03.2002 12:03:16---------------------------------------------------
749 -----------------------------------------------------------------------*/
750 const ::rtl::OUString& EditableExtendedColorConfig::GetCurrentSchemeName()const
752 return m_pImpl->GetLoadedScheme();
754 /* -----------------11.12.2002 10:56-----------------
755 * changes the name of the current scheme but doesn't load it!
756 * --------------------------------------------------*/
757 void EditableExtendedColorConfig::SetCurrentSchemeName(const ::rtl::OUString& rScheme)
759 m_pImpl->SetCurrentSchemeName(rScheme);
760 m_pImpl->CommitCurrentSchemeName();
762 /*-- 25.03.2002 12:03:17---------------------------------------------------
764 -----------------------------------------------------------------------*/
765 ExtendedColorConfigValue EditableExtendedColorConfig::GetColorValue(const ::rtl::OUString& _sComponentName,
766 const ::rtl::OUString& _sName)const
768 return m_pImpl->GetColorConfigValue(_sComponentName,_sName);
770 /*-- 25.03.2002 12:03:17---------------------------------------------------
772 -----------------------------------------------------------------------*/
773 void EditableExtendedColorConfig::SetColorValue(
774 const ::rtl::OUString& _sName, const ExtendedColorConfigValue& rValue)
776 m_pImpl->SetColorConfigValue(_sName, rValue);
777 m_pImpl->ClearModified();
778 m_bModified = sal_True;
780 /* -----------------------------10.04.2002 13:22------------------------------
782 ---------------------------------------------------------------------------*/
783 void EditableExtendedColorConfig::SetModified()
785 m_bModified = sal_True;
787 /* -----------------15.10.2002 14:51-----------------
789 * --------------------------------------------------*/
790 void EditableExtendedColorConfig::Commit()
792 if(m_bModified)
793 m_pImpl->SetModified();
794 if(m_pImpl->IsModified())
795 m_pImpl->Commit();
796 m_bModified = sal_False;
798 // -----------------------------------------------------------------------------
799 void EditableExtendedColorConfig::DisableBroadcast()
801 m_pImpl->DisableBroadcast();
803 // -----------------------------------------------------------------------------
804 void EditableExtendedColorConfig::EnableBroadcast()
806 m_pImpl->EnableBroadcast();
808 // -----------------------------------------------------------------------------
809 sal_Int32 EditableExtendedColorConfig::GetComponentCount() const
811 return m_pImpl->GetComponentCount();
813 // -----------------------------------------------------------------------------
814 sal_Int32 EditableExtendedColorConfig::GetComponentColorCount(const ::rtl::OUString& _sName) const
816 return m_pImpl->GetComponentColorCount(_sName);
818 // -----------------------------------------------------------------------------
819 ExtendedColorConfigValue EditableExtendedColorConfig::GetComponentColorConfigValue(const ::rtl::OUString& _sName,sal_uInt32 _nPos) const
821 return m_pImpl->GetComponentColorConfigValue(_sName,_nPos);
823 // -----------------------------------------------------------------------------
824 ::rtl::OUString EditableExtendedColorConfig::GetComponentName(sal_uInt32 _nPos) const
826 return m_pImpl->GetComponentName(_nPos);
828 // -----------------------------------------------------------------------------
829 ::rtl::OUString EditableExtendedColorConfig::GetComponentDisplayName(const ::rtl::OUString& _sComponentName) const
831 return m_pImpl->GetComponentDisplayName(_sComponentName);
833 }//namespace svtools