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 :
21 : #include <svtools/colorcfg.hxx>
22 : #include <com/sun/star/uno/Any.hxx>
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <com/sun/star/lang/Locale.hpp>
25 : #include <com/sun/star/beans/PropertyValue.hpp>
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 <itemholder2.hxx>
34 :
35 : /* #100822# ----
36 : #include <vcl/wrkwin.hxx>
37 : ------------- */
38 : #include <vcl/svapp.hxx>
39 : #include <vcl/event.hxx>
40 : #include <rtl/instance.hxx>
41 :
42 : //-----------------------------------------------------------------------------
43 : using namespace utl;
44 : using namespace com::sun::star;
45 :
46 : using ::rtl::OUString;
47 :
48 : namespace svtools
49 : {
50 :
51 : #define C2U(cChar) OUString::createFromAscii(cChar)
52 : static const sal_Char cColor[] = "/Color";
53 : static const sal_Char cColorSchemes[] = "ColorSchemes/";
54 : sal_Int32 nColorRefCount_Impl = 0;
55 : namespace
56 : {
57 : struct ColorMutex_Impl
58 : : public rtl::Static< ::osl::Mutex, ColorMutex_Impl > {};
59 : }
60 :
61 : ColorConfig_Impl* ColorConfig::m_pImpl = NULL;
62 :
63 : class ColorConfig_Impl : public utl::ConfigItem
64 : {
65 : ColorConfigValue m_aConfigValues[ColorConfigEntryCount];
66 : sal_Bool m_bEditMode;
67 : rtl::OUString m_sIsVisible;
68 : rtl::OUString m_sLoadedScheme;
69 :
70 : uno::Sequence< ::rtl::OUString> GetPropertyNames(const rtl::OUString& rScheme);
71 : public:
72 : ColorConfig_Impl(sal_Bool bEditMode = sal_False);
73 : virtual ~ColorConfig_Impl();
74 :
75 : void Load(const rtl::OUString& rScheme);
76 : void CommitCurrentSchemeName();
77 : //changes the name of the current scheme but doesn't load it!
78 0 : void SetCurrentSchemeName(const rtl::OUString& rSchemeName) {m_sLoadedScheme = rSchemeName;}
79 : virtual void Commit();
80 : virtual void Notify( const uno::Sequence<rtl::OUString>& aPropertyNames);
81 :
82 32279 : const ColorConfigValue& GetColorConfigValue(ColorConfigEntry eValue)
83 32279 : {return m_aConfigValues[eValue];}
84 : void SetColorConfigValue(ColorConfigEntry eValue,
85 : const ColorConfigValue& rValue );
86 :
87 0 : const rtl::OUString& GetLoadedScheme() const {return m_sLoadedScheme;}
88 :
89 : uno::Sequence< ::rtl::OUString> GetSchemeNames();
90 :
91 : sal_Bool AddScheme(const rtl::OUString& rNode);
92 : sal_Bool RemoveScheme(const rtl::OUString& rNode);
93 0 : void SetModified(){ConfigItem::SetModified();}
94 0 : void ClearModified(){ConfigItem::ClearModified();}
95 : void SettingsChanged();
96 :
97 : // #100822#
98 : DECL_LINK( DataChangedEventListener, VclWindowEvent* );
99 :
100 : void ImplUpdateApplicationSettings();
101 : };
102 :
103 16 : uno::Sequence< OUString> ColorConfig_Impl::GetPropertyNames(const rtl::OUString& rScheme)
104 : {
105 16 : uno::Sequence<OUString> aNames(2 * ColorConfigEntryCount);
106 16 : OUString* pNames = aNames.getArray();
107 : struct ColorConfigEntryData_Impl
108 : {
109 : const sal_Char* cName;
110 : sal_Int32 nLength;
111 : rtl_TextEncoding eEncoding;
112 : sal_Bool bCanBeVisible;
113 : };
114 : static const ColorConfigEntryData_Impl cNames[] =
115 : {
116 : { RTL_CONSTASCII_USTRINGPARAM("/DocColor") ,sal_False },
117 : { RTL_CONSTASCII_USTRINGPARAM("/DocBoundaries") ,sal_True },
118 : { RTL_CONSTASCII_USTRINGPARAM("/AppBackground") ,sal_False },
119 : { RTL_CONSTASCII_USTRINGPARAM("/ObjectBoundaries"),sal_True },
120 : { RTL_CONSTASCII_USTRINGPARAM("/TableBoundaries") ,sal_True },
121 : { RTL_CONSTASCII_USTRINGPARAM("/FontColor") ,sal_False },
122 : { RTL_CONSTASCII_USTRINGPARAM("/Links") ,sal_True },
123 : { RTL_CONSTASCII_USTRINGPARAM("/LinksVisited") ,sal_True },
124 : { RTL_CONSTASCII_USTRINGPARAM("/Spell") ,sal_False },
125 : { RTL_CONSTASCII_USTRINGPARAM("/SmartTags") ,sal_False },
126 : { RTL_CONSTASCII_USTRINGPARAM("/Shadow") , sal_True },
127 : { RTL_CONSTASCII_USTRINGPARAM("/WriterTextGrid") ,sal_False },
128 : { RTL_CONSTASCII_USTRINGPARAM("/WriterFieldShadings"),sal_True },
129 : { RTL_CONSTASCII_USTRINGPARAM("/WriterIdxShadings") ,sal_True },
130 : { RTL_CONSTASCII_USTRINGPARAM("/WriterDirectCursor") ,sal_True },
131 : { RTL_CONSTASCII_USTRINGPARAM("/WriterScriptIndicator") ,sal_False },
132 : { RTL_CONSTASCII_USTRINGPARAM("/WriterSectionBoundaries") ,sal_True },
133 : { RTL_CONSTASCII_USTRINGPARAM("/WriterHeaderFooterMark") ,sal_False },
134 : { RTL_CONSTASCII_USTRINGPARAM("/WriterPageBreaks") ,sal_False },
135 : { RTL_CONSTASCII_USTRINGPARAM("/HTMLSGML") ,sal_False },
136 : { RTL_CONSTASCII_USTRINGPARAM("/HTMLComment") ,sal_False },
137 : { RTL_CONSTASCII_USTRINGPARAM("/HTMLKeyword") ,sal_False },
138 : { RTL_CONSTASCII_USTRINGPARAM("/HTMLUnknown") ,sal_False },
139 : { RTL_CONSTASCII_USTRINGPARAM("/CalcGrid") ,sal_False },
140 : { RTL_CONSTASCII_USTRINGPARAM("/CalcPageBreak"), sal_False },
141 : { RTL_CONSTASCII_USTRINGPARAM("/CalcPageBreakManual"), sal_False },
142 : { RTL_CONSTASCII_USTRINGPARAM("/CalcPageBreakAutomatic"), sal_False },
143 : { RTL_CONSTASCII_USTRINGPARAM("/CalcDetective") ,sal_False },
144 : { RTL_CONSTASCII_USTRINGPARAM("/CalcDetectiveError") ,sal_False },
145 : { RTL_CONSTASCII_USTRINGPARAM("/CalcReference") ,sal_False },
146 : { RTL_CONSTASCII_USTRINGPARAM("/CalcNotesBackground") ,sal_False },
147 : { RTL_CONSTASCII_USTRINGPARAM("/DrawGrid") ,sal_True },
148 : { RTL_CONSTASCII_USTRINGPARAM("/BASICIdentifier"), sal_False },
149 : { RTL_CONSTASCII_USTRINGPARAM("/BASICComment") , sal_False },
150 : { RTL_CONSTASCII_USTRINGPARAM("/BASICNumber") , sal_False },
151 : { RTL_CONSTASCII_USTRINGPARAM("/BASICString") , sal_False },
152 : { RTL_CONSTASCII_USTRINGPARAM("/BASICOperator") , sal_False },
153 : { RTL_CONSTASCII_USTRINGPARAM("/BASICKeyword") , sal_False },
154 : { RTL_CONSTASCII_USTRINGPARAM("/BASICError"), sal_False },
155 : { RTL_CONSTASCII_USTRINGPARAM("/SQLIdentifier"), sal_False },
156 : { RTL_CONSTASCII_USTRINGPARAM("/SQLNumber"), sal_False },
157 : { RTL_CONSTASCII_USTRINGPARAM("/SQLString"), sal_False },
158 : { RTL_CONSTASCII_USTRINGPARAM("/SQLOperator"), sal_False },
159 : { RTL_CONSTASCII_USTRINGPARAM("/SQLKeyword"), sal_False },
160 : { RTL_CONSTASCII_USTRINGPARAM("/SQLParameter"), sal_False },
161 : { RTL_CONSTASCII_USTRINGPARAM("/SQLComment"), sal_False }
162 : };
163 16 : int nIndex = 0;
164 16 : OUString sColor = C2U(cColor);
165 16 : OUString sBase(C2U(cColorSchemes));
166 16 : sBase += utl::wrapConfigurationElementName(rScheme);
167 16 : const int nCount = ColorConfigEntryCount;
168 752 : for(sal_Int32 i = 0; i < 4 * nCount; i+= 4)
169 : {
170 736 : rtl::OUString sBaseName(sBase);
171 736 : sal_Int32 nPos = i / 4;
172 736 : sBaseName += OUString(cNames[nPos].cName, cNames[nPos].nLength, cNames[nPos].eEncoding);
173 736 : pNames[nIndex] += sBaseName;
174 736 : pNames[nIndex++] += sColor;
175 736 : if(cNames[nPos].bCanBeVisible)
176 : {
177 176 : pNames[nIndex] += sBaseName;
178 176 : pNames[nIndex++] += m_sIsVisible;
179 : }
180 736 : }
181 16 : aNames.realloc(nIndex);
182 16 : return aNames;
183 : }
184 :
185 16 : ColorConfig_Impl::ColorConfig_Impl(sal_Bool bEditMode) :
186 : ConfigItem(C2U("Office.UI/ColorScheme")),
187 : m_bEditMode(bEditMode),
188 16 : m_sIsVisible(C2U("/IsVisible"))
189 : {
190 16 : if(!m_bEditMode)
191 : {
192 : //try to register on the root node - if possible
193 16 : uno::Sequence < ::rtl::OUString > aNames(1);
194 16 : EnableNotification( aNames );
195 : }
196 16 : Load(::rtl::OUString());
197 :
198 16 : ImplUpdateApplicationSettings();
199 :
200 : // #100822#
201 16 : ::Application::AddEventListener( LINK(this, ColorConfig_Impl, DataChangedEventListener) );
202 :
203 16 : }
204 :
205 0 : ColorConfig_Impl::~ColorConfig_Impl()
206 : {
207 : // #100822#
208 0 : ::Application::RemoveEventListener( LINK(this, ColorConfig_Impl, DataChangedEventListener) );
209 0 : }
210 :
211 16 : void ColorConfig_Impl::Load(const rtl::OUString& rScheme)
212 : {
213 16 : rtl::OUString sScheme(rScheme);
214 16 : if(sScheme.isEmpty())
215 : {
216 : //detect current scheme name
217 16 : uno::Sequence < ::rtl::OUString > aCurrent(1);
218 16 : aCurrent.getArray()[0] = C2U("CurrentColorScheme");
219 16 : uno::Sequence< uno::Any > aCurrentVal = GetProperties( aCurrent );
220 16 : aCurrentVal.getConstArray()[0] >>= sScheme;
221 : }
222 16 : m_sLoadedScheme = sScheme;
223 : //
224 16 : uno::Sequence < ::rtl::OUString > aColorNames = GetPropertyNames(sScheme);
225 16 : uno::Sequence< uno::Any > aColors = GetProperties( aColorNames );
226 16 : const uno::Any* pColors = aColors.getConstArray();
227 16 : const ::rtl::OUString* pColorNames = aColorNames.getConstArray();
228 16 : sal_Int32 nIndex = 0;
229 736 : for(int i = 0; i < 2 * ColorConfigEntryCount && aColors.getLength() > nIndex; i+= 2)
230 : {
231 736 : if(pColors[nIndex].hasValue())
232 0 : pColors[nIndex] >>= m_aConfigValues[i / 2].nColor;
233 : else
234 736 : m_aConfigValues[i/2].nColor = COL_AUTO;
235 736 : nIndex++;
236 736 : if(nIndex >= aColors.getLength())
237 16 : break;
238 : //test for visibility property
239 720 : if(pColorNames[nIndex].match(m_sIsVisible, pColorNames[nIndex].getLength() - m_sIsVisible.getLength()))
240 176 : m_aConfigValues[i / 2].bIsVisible = Any2Bool(pColors[nIndex++]);
241 16 : }
242 16 : }
243 :
244 0 : void ColorConfig_Impl::Notify( const uno::Sequence<OUString>& )
245 : {
246 : //loading via notification always uses the default setting
247 0 : Load(::rtl::OUString());
248 0 : NotifyListeners(0);
249 0 : }
250 :
251 0 : void ColorConfig_Impl::Commit()
252 : {
253 0 : uno::Sequence < ::rtl::OUString > aColorNames = GetPropertyNames(m_sLoadedScheme);
254 0 : uno::Sequence < beans::PropertyValue > aPropValues(aColorNames.getLength());
255 0 : beans::PropertyValue* pPropValues = aPropValues.getArray();
256 0 : const ::rtl::OUString* pColorNames = aColorNames.getConstArray();
257 0 : sal_Int32 nIndex = 0;
258 0 : const uno::Type& rBoolType = ::getBooleanCppuType();
259 0 : for(int i = 0; i < 2 * ColorConfigEntryCount && aColorNames.getLength() > nIndex; i+= 2)
260 : {
261 0 : pPropValues[nIndex].Name = pColorNames[nIndex];
262 : //save automatic colors as void value
263 0 : if(COL_AUTO != sal::static_int_cast<ColorData>(m_aConfigValues[i/2].nColor))
264 0 : pPropValues[nIndex].Value <<= m_aConfigValues[i/2].nColor;
265 :
266 0 : nIndex++;
267 0 : if(nIndex >= aColorNames.getLength())
268 0 : break;
269 : //test for visibility property
270 0 : if(pColorNames[nIndex].match(m_sIsVisible, pColorNames[nIndex].getLength() - m_sIsVisible.getLength()))
271 : {
272 0 : pPropValues[nIndex].Name = pColorNames[nIndex];
273 0 : pPropValues[nIndex].Value.setValue(&m_aConfigValues[i/2].bIsVisible, rBoolType);
274 0 : nIndex++;
275 : }
276 : }
277 0 : rtl::OUString sNode(C2U("ColorSchemes"));
278 0 : SetSetProperties(sNode, aPropValues);
279 :
280 0 : CommitCurrentSchemeName();
281 0 : }
282 :
283 0 : void ColorConfig_Impl::CommitCurrentSchemeName()
284 : {
285 : //save current scheme name
286 0 : uno::Sequence < ::rtl::OUString > aCurrent(1);
287 0 : aCurrent.getArray()[0] = C2U("CurrentColorScheme");
288 0 : uno::Sequence< uno::Any > aCurrentVal(1);
289 0 : aCurrentVal.getArray()[0] <<= m_sLoadedScheme;
290 0 : PutProperties(aCurrent, aCurrentVal);
291 0 : }
292 :
293 0 : void ColorConfig_Impl::SetColorConfigValue(ColorConfigEntry eValue, const ColorConfigValue& rValue )
294 : {
295 0 : if(rValue != m_aConfigValues[eValue])
296 : {
297 0 : m_aConfigValues[eValue] = rValue;
298 0 : SetModified();
299 : }
300 0 : }
301 :
302 0 : uno::Sequence< ::rtl::OUString> ColorConfig_Impl::GetSchemeNames()
303 : {
304 0 : return GetNodeNames(C2U("ColorSchemes"));
305 : }
306 :
307 0 : sal_Bool ColorConfig_Impl::AddScheme(const rtl::OUString& rScheme)
308 : {
309 0 : if(ConfigItem::AddNode(C2U("ColorSchemes"), rScheme))
310 : {
311 0 : m_sLoadedScheme = rScheme;
312 0 : Commit();
313 0 : return sal_True;
314 : }
315 0 : return sal_False;
316 : }
317 :
318 0 : sal_Bool ColorConfig_Impl::RemoveScheme(const rtl::OUString& rScheme)
319 : {
320 0 : uno::Sequence< rtl::OUString > aElements(1);
321 0 : aElements.getArray()[0] = rScheme;
322 0 : return ClearNodeElements(C2U("ColorSchemes"), aElements);
323 : }
324 :
325 0 : void ColorConfig_Impl::SettingsChanged()
326 : {
327 0 : SolarMutexGuard aVclGuard;
328 :
329 0 : ImplUpdateApplicationSettings();
330 :
331 0 : NotifyListeners(0);
332 0 : }
333 :
334 144010 : IMPL_LINK( ColorConfig_Impl, DataChangedEventListener, VclWindowEvent*, pEvent )
335 : {
336 72005 : if ( pEvent->GetId() == VCLEVENT_APPLICATION_DATACHANGED )
337 : {
338 4 : DataChangedEvent* pData = (DataChangedEvent*)(pEvent->GetData());
339 8 : if ( (pData->GetType() == DATACHANGED_SETTINGS) &&
340 4 : (pData->GetFlags() & SETTINGS_STYLE) )
341 : {
342 0 : SettingsChanged();
343 0 : return 1L;
344 : } else
345 4 : return 0L;
346 : } else
347 72001 : return 0L;
348 : }
349 :
350 : // ---------------------------------------------------------------------------
351 :
352 : /** updates the font color in the vcl window settings */
353 16 : void ColorConfig_Impl::ImplUpdateApplicationSettings()
354 : {
355 16 : Application* pApp = GetpApp();
356 16 : if( pApp )
357 : {
358 16 : AllSettings aSettings = pApp->GetSettings();
359 16 : StyleSettings aStyleSettings( aSettings.GetStyleSettings() );
360 :
361 16 : ColorConfigValue aRet = GetColorConfigValue(svtools::FONTCOLOR);
362 16 : if(COL_AUTO == sal::static_int_cast<ColorData>(aRet.nColor))
363 16 : aRet.nColor = ColorConfig::GetDefaultColor(svtools::FONTCOLOR).GetColor();
364 :
365 16 : Color aFontColor(aRet.nColor);
366 :
367 16 : if( aStyleSettings.GetFontColor() != aFontColor )
368 : {
369 0 : aStyleSettings.SetFontColor( aFontColor );
370 :
371 0 : aSettings.SetStyleSettings( aStyleSettings );
372 0 : pApp->SetSettings( aSettings );
373 16 : }
374 : }
375 16 : }
376 :
377 : // ---------------------------------------------------------------------------
378 :
379 941 : ColorConfig::ColorConfig()
380 : {
381 941 : ::osl::MutexGuard aGuard( ColorMutex_Impl::get() );
382 941 : if ( !m_pImpl )
383 : {
384 16 : m_pImpl = new ColorConfig_Impl;
385 16 : svtools::ItemHolder2::holdConfigItem(E_COLORCFG);
386 : }
387 941 : ++nColorRefCount_Impl;
388 941 : m_pImpl->AddListener(this);
389 941 : }
390 :
391 1148 : ColorConfig::~ColorConfig()
392 : {
393 562 : ::osl::MutexGuard aGuard( ColorMutex_Impl::get() );
394 562 : m_pImpl->RemoveListener(this);
395 562 : if(!--nColorRefCount_Impl)
396 : {
397 0 : delete m_pImpl;
398 0 : m_pImpl = 0;
399 562 : }
400 586 : }
401 :
402 32279 : Color ColorConfig::GetDefaultColor(ColorConfigEntry eEntry)
403 : {
404 : static const sal_Int32 aAutoColors[] =
405 : {
406 : COL_WHITE, // DOCCOLOR
407 : 0xc0c0c0, // DOCBOUNDARIES
408 : 0x808080, // APPBACKGROUND
409 : 0xc0c0c0, // OBJECTBOUNDARIES
410 : 0xc0c0c0, // TABLEBOUNDARIES
411 : COL_BLACK, // FONTCOLOR
412 : 0xcc, // LINKS
413 : 0x80, // LINKSVISITED
414 : 0xff0000, // SPELL
415 : COL_LIGHTMAGENTA,// SMARTTAGS
416 : COL_GRAY, // SHADOWCOLOR
417 : 0xc0c0c0, // WRITERTEXTGRID
418 : 0xc0c0c0, // WRITERFIELDSHADIN
419 : 0xc0c0c0, // WRITERIDXSHADINGS
420 : 0, // WRITERDIRECTCURSOR
421 : COL_GREEN, //WRITERSCRIPTINDICATOR
422 : 0xc0c0c0, //WRITERSECTIONBOUNDARIES
423 : 0x0369a3, //WRITERHEADERFOOTERMARK,
424 : COL_BLUE, //WRITERPAGEBREAKS,
425 : COL_LIGHTBLUE, // HTMLSGML
426 : COL_LIGHTGREEN, // HTMLCOMMENT
427 : COL_LIGHTRED, // HTMLKEYWORD
428 : COL_GRAY, // HTMLUNKNOWN
429 : COL_LIGHTGRAY, // CALCGRID
430 : COL_BLUE, //CALCPAGEBREAK
431 : 0x2300dc, //CALCPAGEBREAKMANUAL
432 : COL_GRAY, //CALCPAGEBREAKAUTOMATIC
433 : COL_LIGHTBLUE, // CALCDETECTIVE
434 : COL_LIGHTRED, // CALCDETECTIVEERROR
435 : COL_LIGHTRED, // CALCREFERENCE
436 : 0xffffc0, // CALCNOTESBACKGROUND
437 : 0xc0c0c0, // DRAWGRID
438 : COL_GREEN, // BASICIDENTIFIER,
439 : COL_GRAY,// BASICCOMMENT ,
440 : COL_LIGHTRED,// BASICNUMBER ,
441 : COL_LIGHTRED,// BASICSTRING ,
442 : COL_BLUE, // BASICOPERATOR ,
443 : COL_BLUE, // BASICKEYWORD ,
444 : COL_RED, //BASICERROR
445 : 0x009900, // SQLIDENTIFIER
446 : 0x000000, // SQLNUMBER
447 : 0xCE7B00, // SQLSTRING
448 : 0x000000, // SQLOPERATOR
449 : 0x0000E6, // SQLKEYWORD
450 : 0x259D9D, // SQLPARAMTER
451 : 0x969696,// SQLCOMMENT
452 : };
453 32279 : Color aRet;
454 32279 : switch(eEntry)
455 : {
456 : case APPBACKGROUND :
457 250 : aRet = Application::GetSettings().GetStyleSettings().GetWorkspaceColor();
458 250 : break;
459 :
460 : case LINKS :
461 10 : aRet = Application::GetSettings().GetStyleSettings().GetLinkColor();
462 10 : break;
463 :
464 : case LINKSVISITED :
465 10 : aRet = Application::GetSettings().GetStyleSettings().GetVisitedLinkColor();
466 10 : break;
467 :
468 : default:
469 32009 : aRet = aAutoColors[eEntry];
470 : }
471 32279 : return aRet;
472 : }
473 :
474 32263 : ColorConfigValue ColorConfig::GetColorValue(ColorConfigEntry eEntry, sal_Bool bSmart)const
475 : {
476 32263 : ColorConfigValue aRet = m_pImpl->GetColorConfigValue(eEntry);
477 32263 : if(bSmart)
478 : {
479 32263 : if(COL_AUTO == sal::static_int_cast<ColorData>(aRet.nColor))
480 32263 : aRet.nColor = ColorConfig::GetDefaultColor(eEntry).GetColor();
481 : }
482 :
483 32263 : return aRet;
484 : }
485 :
486 0 : EditableColorConfig::EditableColorConfig() :
487 0 : m_pImpl(new ColorConfig_Impl),
488 0 : m_bModified(sal_False)
489 : {
490 0 : m_pImpl->BlockBroadcasts(sal_True);
491 0 : }
492 :
493 0 : EditableColorConfig::~EditableColorConfig()
494 : {
495 0 : m_pImpl->BlockBroadcasts(sal_False);
496 0 : if(m_bModified)
497 0 : m_pImpl->SetModified();
498 0 : if(m_pImpl->IsModified())
499 0 : m_pImpl->Commit();
500 0 : delete m_pImpl;
501 0 : }
502 :
503 0 : uno::Sequence< ::rtl::OUString > EditableColorConfig::GetSchemeNames() const
504 : {
505 0 : return m_pImpl->GetSchemeNames();
506 : }
507 :
508 0 : void EditableColorConfig::DeleteScheme(const ::rtl::OUString& rScheme )
509 : {
510 0 : m_pImpl->RemoveScheme(rScheme);
511 0 : }
512 :
513 0 : void EditableColorConfig::AddScheme(const ::rtl::OUString& rScheme )
514 : {
515 0 : m_pImpl->AddScheme(rScheme);
516 0 : }
517 :
518 0 : sal_Bool EditableColorConfig::LoadScheme(const ::rtl::OUString& rScheme )
519 : {
520 0 : if(m_bModified)
521 0 : m_pImpl->SetModified();
522 0 : if(m_pImpl->IsModified())
523 0 : m_pImpl->Commit();
524 0 : m_bModified = sal_False;
525 0 : m_pImpl->Load(rScheme);
526 : //the name of the loaded scheme has to be committed separately
527 0 : m_pImpl->CommitCurrentSchemeName();
528 0 : return sal_True;
529 : }
530 :
531 0 : const ::rtl::OUString& EditableColorConfig::GetCurrentSchemeName()const
532 : {
533 0 : return m_pImpl->GetLoadedScheme();
534 : }
535 :
536 : // Changes the name of the current scheme but doesn't load it!
537 0 : void EditableColorConfig::SetCurrentSchemeName(const ::rtl::OUString& rScheme)
538 : {
539 0 : m_pImpl->SetCurrentSchemeName(rScheme);
540 0 : m_pImpl->CommitCurrentSchemeName();
541 0 : }
542 :
543 0 : const ColorConfigValue& EditableColorConfig::GetColorValue(
544 : ColorConfigEntry eEntry)const
545 : {
546 0 : return m_pImpl->GetColorConfigValue(eEntry);
547 : }
548 :
549 0 : void EditableColorConfig::SetColorValue(
550 : ColorConfigEntry eEntry, const ColorConfigValue& rValue)
551 : {
552 0 : m_pImpl->SetColorConfigValue(eEntry, rValue);
553 0 : m_pImpl->ClearModified();
554 0 : m_bModified = sal_True;
555 0 : }
556 :
557 0 : void EditableColorConfig::SetModified()
558 : {
559 0 : m_bModified = sal_True;
560 0 : }
561 :
562 0 : void EditableColorConfig::Commit()
563 : {
564 0 : if(m_bModified)
565 0 : m_pImpl->SetModified();
566 0 : if(m_pImpl->IsModified())
567 0 : m_pImpl->Commit();
568 0 : m_bModified = sal_False;
569 0 : }
570 : // -----------------------------------------------------------------------------
571 0 : void EditableColorConfig::DisableBroadcast()
572 : {
573 0 : m_pImpl->BlockBroadcasts(sal_True);
574 0 : }
575 : // -----------------------------------------------------------------------------
576 0 : void EditableColorConfig::EnableBroadcast()
577 : {
578 0 : m_pImpl->BlockBroadcasts(sal_False);
579 0 : }
580 : // -----------------------------------------------------------------------------
581 :
582 : }//namespace svtools
583 :
584 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|