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