merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / colorcfg.cxx
blob3e27b03977dfa9eda51f3ddb237237001c246dd3
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: colorcfg.cxx,v $
10 * $Revision: 1.20.82.1 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #ifdef SVL_DLLIMPLEMENTATION
35 #undef SVL_DLLIMPLEMENTATION
36 #endif
37 #define SVT_DLLIMPLEMENTATION
39 #include <svtools/colorcfg.hxx>
40 #include <com/sun/star/uno/Any.hxx>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <com/sun/star/lang/Locale.hpp>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <tools/color.hxx>
45 #include <tools/debug.hxx>
46 #include <unotools/configitem.hxx>
47 #include <unotools/configpathes.hxx>
48 #include <com/sun/star/uno/Sequence.h>
49 #include <svtools/poolitem.hxx> //Any2Bool
50 #include <svtools/smplhint.hxx>
51 #include <vos/mutex.hxx>
53 #include <itemholder2.hxx>
55 /* #100822# ----
56 #include <vcl/wrkwin.hxx>
57 ------------- */
58 #include <vcl/svapp.hxx>
59 #include <vcl/event.hxx>
60 #include <rtl/instance.hxx>
62 //-----------------------------------------------------------------------------
63 using namespace utl;
64 using namespace rtl;
65 using namespace com::sun::star;
67 namespace svtools
70 #define C2U(cChar) OUString::createFromAscii(cChar)
71 static const sal_Char cColor[] = "/Color";
72 static const sal_Char cColorSchemes[] = "ColorSchemes/";
73 sal_Int32 nColorRefCount_Impl = 0;
74 namespace
76 struct ColorMutex_Impl
77 : public rtl::Static< ::osl::Mutex, ColorMutex_Impl > {};
80 ColorConfig_Impl* ColorConfig::m_pImpl = NULL;
82 /* -----------------------------16.01.01 15:36--------------------------------
83 ---------------------------------------------------------------------------*/
84 class ColorConfig_Impl : public utl::ConfigItem, public SfxBroadcaster
86 ColorConfigValue m_aConfigValues[ColorConfigEntryCount];
87 sal_Bool m_bEditMode;
88 rtl::OUString m_sIsVisible;
89 rtl::OUString m_sLoadedScheme;
90 sal_Bool m_bIsBroadcastEnabled;
91 static sal_Bool m_bLockBroadcast;
92 static sal_Bool m_bBroadcastWhenUnlocked;
94 uno::Sequence< ::rtl::OUString> GetPropertyNames(const rtl::OUString& rScheme);
95 public:
96 ColorConfig_Impl(sal_Bool bEditMode = sal_False);
97 virtual ~ColorConfig_Impl();
99 void Load(const rtl::OUString& rScheme);
100 void CommitCurrentSchemeName();
101 //changes the name of the current scheme but doesn't load it!
102 void SetCurrentSchemeName(const rtl::OUString& rSchemeName) {m_sLoadedScheme = rSchemeName;}
103 virtual void Commit();
104 virtual void Notify( const uno::Sequence<rtl::OUString>& aPropertyNames);
106 const ColorConfigValue& GetColorConfigValue(ColorConfigEntry eValue)
107 {return m_aConfigValues[eValue];}
108 void SetColorConfigValue(ColorConfigEntry eValue,
109 const ColorConfigValue& rValue );
111 const rtl::OUString& GetLoadedScheme() const {return m_sLoadedScheme;}
113 uno::Sequence< ::rtl::OUString> GetSchemeNames();
115 sal_Bool AddScheme(const rtl::OUString& rNode);
116 sal_Bool RemoveScheme(const rtl::OUString& rNode);
117 void SetModified(){ConfigItem::SetModified();}
118 void ClearModified(){ConfigItem::ClearModified();}
119 void SettingsChanged();
121 static void DisableBroadcast();
122 static void EnableBroadcast();
123 static sal_Bool IsEnableBroadcast();
125 static void LockBroadcast();
126 static void UnlockBroadcast();
128 // #100822#
129 DECL_LINK( DataChangedEventListener, VclWindowEvent* );
131 void ImplUpdateApplicationSettings();
134 /* -----------------------------16.01.01 15:36--------------------------------
136 ---------------------------------------------------------------------------*/
137 uno::Sequence< OUString> ColorConfig_Impl::GetPropertyNames(const rtl::OUString& rScheme)
139 uno::Sequence<OUString> aNames(2 * ColorConfigEntryCount);
140 OUString* pNames = aNames.getArray();
141 struct ColorConfigEntryData_Impl
143 const sal_Char* cName;
144 sal_Int32 nLength;
145 rtl_TextEncoding eEncoding;
146 sal_Bool bCanBeVisible;
148 static const ColorConfigEntryData_Impl cNames[] =
150 { RTL_CONSTASCII_USTRINGPARAM("/DocColor") ,sal_False },
151 { RTL_CONSTASCII_USTRINGPARAM("/DocBoundaries") ,sal_True },
152 { RTL_CONSTASCII_USTRINGPARAM("/AppBackground") ,sal_False },
153 { RTL_CONSTASCII_USTRINGPARAM("/ObjectBoundaries"),sal_True },
154 { RTL_CONSTASCII_USTRINGPARAM("/TableBoundaries") ,sal_True },
155 { RTL_CONSTASCII_USTRINGPARAM("/FontColor") ,sal_False },
156 { RTL_CONSTASCII_USTRINGPARAM("/Links") ,sal_True },
157 { RTL_CONSTASCII_USTRINGPARAM("/LinksVisited") ,sal_True },
158 { RTL_CONSTASCII_USTRINGPARAM("/Anchor") ,sal_False },
159 { RTL_CONSTASCII_USTRINGPARAM("/Spell") ,sal_False },
160 { RTL_CONSTASCII_USTRINGPARAM("/SmartTags") ,sal_False },
161 { RTL_CONSTASCII_USTRINGPARAM("/WriterTextGrid") ,sal_False },
162 { RTL_CONSTASCII_USTRINGPARAM("/WriterFieldShadings"),sal_True },
163 { RTL_CONSTASCII_USTRINGPARAM("/WriterIdxShadings") ,sal_True },
164 { RTL_CONSTASCII_USTRINGPARAM("/WriterDirectCursor") ,sal_True },
165 { RTL_CONSTASCII_USTRINGPARAM("/WriterScriptIndicator") ,sal_False },
166 { RTL_CONSTASCII_USTRINGPARAM("/WriterSectionBoundaries") ,sal_True },
167 { RTL_CONSTASCII_USTRINGPARAM("/WriterPageBreaks") ,sal_False },
168 { RTL_CONSTASCII_USTRINGPARAM("/HTMLSGML") ,sal_False },
169 { RTL_CONSTASCII_USTRINGPARAM("/HTMLComment") ,sal_False },
170 { RTL_CONSTASCII_USTRINGPARAM("/HTMLKeyword") ,sal_False },
171 { RTL_CONSTASCII_USTRINGPARAM("/HTMLUnknown") ,sal_False },
172 { RTL_CONSTASCII_USTRINGPARAM("/CalcGrid") ,sal_False },
173 { RTL_CONSTASCII_USTRINGPARAM("/CalcPageBreak"), sal_False },
174 { RTL_CONSTASCII_USTRINGPARAM("/CalcPageBreakManual"), sal_False },
175 { RTL_CONSTASCII_USTRINGPARAM("/CalcPageBreakAutomatic"), sal_False },
176 { RTL_CONSTASCII_USTRINGPARAM("/CalcDetective") ,sal_False },
177 { RTL_CONSTASCII_USTRINGPARAM("/CalcDetectiveError") ,sal_False },
178 { RTL_CONSTASCII_USTRINGPARAM("/CalcReference") ,sal_False },
179 { RTL_CONSTASCII_USTRINGPARAM("/CalcNotesBackground") ,sal_False },
180 { RTL_CONSTASCII_USTRINGPARAM("/DrawGrid") ,sal_True },
181 { RTL_CONSTASCII_USTRINGPARAM("/DrawDrawing") ,sal_False },
182 { RTL_CONSTASCII_USTRINGPARAM("/DrawFill") ,sal_False },
183 { RTL_CONSTASCII_USTRINGPARAM("/BASICIdentifier"), sal_False },
184 { RTL_CONSTASCII_USTRINGPARAM("/BASICComment") , sal_False },
185 { RTL_CONSTASCII_USTRINGPARAM("/BASICNumber") , sal_False },
186 { RTL_CONSTASCII_USTRINGPARAM("/BASICString") , sal_False },
187 { RTL_CONSTASCII_USTRINGPARAM("/BASICOperator") , sal_False },
188 { RTL_CONSTASCII_USTRINGPARAM("/BASICKeyword") , sal_False },
189 { RTL_CONSTASCII_USTRINGPARAM("/BASICError"), sal_False },
190 { RTL_CONSTASCII_USTRINGPARAM("/SQLIdentifier"), sal_False },
191 { RTL_CONSTASCII_USTRINGPARAM("/SQLNumber"), sal_False },
192 { RTL_CONSTASCII_USTRINGPARAM("/SQLString"), sal_False },
193 { RTL_CONSTASCII_USTRINGPARAM("/SQLOperator"), sal_False },
194 { RTL_CONSTASCII_USTRINGPARAM("/SQLKeyword"), sal_False },
195 { RTL_CONSTASCII_USTRINGPARAM("/SQLParameter"), sal_False },
196 { RTL_CONSTASCII_USTRINGPARAM("/SQLComment"), sal_False }
198 int nIndex = 0;
199 OUString sColor = C2U(cColor);
200 OUString sBase(C2U(cColorSchemes));
201 sBase += utl::wrapConfigurationElementName(rScheme);
202 const int nCount = ColorConfigEntryCount;
203 for(sal_Int32 i = 0; i < 4 * nCount; i+= 4)
205 rtl::OUString sBaseName(sBase);
206 sal_Int32 nPos = i / 4;
207 sBaseName += OUString(cNames[nPos].cName, cNames[nPos].nLength, cNames[nPos].eEncoding);
208 pNames[nIndex] += sBaseName;
209 pNames[nIndex++] += sColor;
210 if(cNames[nPos].bCanBeVisible)
212 pNames[nIndex] += sBaseName;
213 pNames[nIndex++] += m_sIsVisible;
216 aNames.realloc(nIndex);
217 return aNames;
219 /* -----------------------------22.03.2002 14:37------------------------------
221 ---------------------------------------------------------------------------*/
222 sal_Bool ColorConfig_Impl::m_bLockBroadcast = sal_False;
223 sal_Bool ColorConfig_Impl::m_bBroadcastWhenUnlocked = sal_False;
224 ColorConfig_Impl::ColorConfig_Impl(sal_Bool bEditMode) :
225 ConfigItem(C2U("Office.UI/ColorScheme")),
226 m_bEditMode(bEditMode),
227 m_sIsVisible(C2U("/IsVisible")),
228 m_bIsBroadcastEnabled(sal_True)
230 if(!m_bEditMode)
232 //try to register on the root node - if possible
233 uno::Sequence < ::rtl::OUString > aNames(1);
234 EnableNotification( aNames );
236 Load(::rtl::OUString());
238 ImplUpdateApplicationSettings();
240 // #100822#
241 ::Application::AddEventListener( LINK(this, ColorConfig_Impl, DataChangedEventListener) );
244 /* -----------------------------25.03.2002 12:28------------------------------
246 ---------------------------------------------------------------------------*/
247 ColorConfig_Impl::~ColorConfig_Impl()
249 // #100822#
250 ::Application::RemoveEventListener( LINK(this, ColorConfig_Impl, DataChangedEventListener) );
252 // -----------------------------------------------------------------------------
253 void ColorConfig_Impl::DisableBroadcast()
255 if ( ColorConfig::m_pImpl )
256 ColorConfig::m_pImpl->m_bIsBroadcastEnabled = sal_False;
258 // -----------------------------------------------------------------------------
259 void ColorConfig_Impl::EnableBroadcast()
261 if ( ColorConfig::m_pImpl )
262 ColorConfig::m_pImpl->m_bIsBroadcastEnabled = sal_True;
264 // -----------------------------------------------------------------------------
265 sal_Bool ColorConfig_Impl::IsEnableBroadcast()
267 return ColorConfig::m_pImpl ? ColorConfig::m_pImpl->m_bIsBroadcastEnabled : sal_False;
269 /* -----------------------------22.03.2002 14:38------------------------------
271 ---------------------------------------------------------------------------*/
272 void ColorConfig_Impl::Load(const rtl::OUString& rScheme)
274 rtl::OUString sScheme(rScheme);
275 if(!sScheme.getLength())
277 //detect current scheme name
278 uno::Sequence < ::rtl::OUString > aCurrent(1);
279 aCurrent.getArray()[0] = C2U("CurrentColorScheme");
280 uno::Sequence< uno::Any > aCurrentVal = GetProperties( aCurrent );
281 aCurrentVal.getConstArray()[0] >>= sScheme;
283 m_sLoadedScheme = sScheme;
285 uno::Sequence < ::rtl::OUString > aColorNames = GetPropertyNames(sScheme);
286 uno::Sequence< uno::Any > aColors = GetProperties( aColorNames );
287 const uno::Any* pColors = aColors.getConstArray();
288 const ::rtl::OUString* pColorNames = aColorNames.getConstArray();
289 sal_Int32 nIndex = 0;
290 for(int i = 0; i < 2 * ColorConfigEntryCount && aColors.getLength() > nIndex; i+= 2)
292 if(pColors[nIndex].hasValue())
293 pColors[nIndex] >>= m_aConfigValues[i / 2].nColor;
294 else
295 m_aConfigValues[i/2].nColor = COL_AUTO;
296 nIndex++;
297 if(nIndex >= aColors.getLength())
298 break;
299 //test for visibility property
300 if(pColorNames[nIndex].match(m_sIsVisible, pColorNames[nIndex].getLength() - m_sIsVisible.getLength()))
301 m_aConfigValues[i / 2].bIsVisible = Any2Bool(pColors[nIndex++]);
304 /* -----------------------------22.03.2002 14:38------------------------------
306 ---------------------------------------------------------------------------*/
307 void ColorConfig_Impl::Notify( const uno::Sequence<OUString>& )
309 //loading via notification always uses the default setting
310 Load(::rtl::OUString());
312 vos::OGuard aVclGuard( Application::GetSolarMutex() );
314 if(m_bLockBroadcast)
316 m_bBroadcastWhenUnlocked = sal_True;
317 ImplUpdateApplicationSettings();
319 else
320 Broadcast(SfxSimpleHint(SFX_HINT_COLORS_CHANGED));
322 /* -----------------------------22.03.2002 14:38------------------------------
324 ---------------------------------------------------------------------------*/
325 void ColorConfig_Impl::Commit()
327 uno::Sequence < ::rtl::OUString > aColorNames = GetPropertyNames(m_sLoadedScheme);
328 uno::Sequence < beans::PropertyValue > aPropValues(aColorNames.getLength());
329 beans::PropertyValue* pPropValues = aPropValues.getArray();
330 const ::rtl::OUString* pColorNames = aColorNames.getConstArray();
331 sal_Int32 nIndex = 0;
332 const uno::Type& rBoolType = ::getBooleanCppuType();
333 for(int i = 0; i < 2 * ColorConfigEntryCount && aColorNames.getLength() > nIndex; i+= 2)
335 pPropValues[nIndex].Name = pColorNames[nIndex];
336 //save automatic colors as void value
337 if(COL_AUTO != sal::static_int_cast<ColorData>(m_aConfigValues[i/2].nColor))
338 pPropValues[nIndex].Value <<= m_aConfigValues[i/2].nColor;
340 nIndex++;
341 if(nIndex >= aColorNames.getLength())
342 break;
343 //test for visibility property
344 if(pColorNames[nIndex].match(m_sIsVisible, pColorNames[nIndex].getLength() - m_sIsVisible.getLength()))
346 pPropValues[nIndex].Name = pColorNames[nIndex];
347 pPropValues[nIndex].Value.setValue(&m_aConfigValues[i/2].bIsVisible, rBoolType);
348 nIndex++;
351 rtl::OUString sNode(C2U("ColorSchemes"));
352 SetSetProperties(sNode, aPropValues);
354 CommitCurrentSchemeName();
356 /* -----------------11.12.2002 10:42-----------------
358 * --------------------------------------------------*/
359 void ColorConfig_Impl::CommitCurrentSchemeName()
361 //save current scheme name
362 uno::Sequence < ::rtl::OUString > aCurrent(1);
363 aCurrent.getArray()[0] = C2U("CurrentColorScheme");
364 uno::Sequence< uno::Any > aCurrentVal(1);
365 aCurrentVal.getArray()[0] <<= m_sLoadedScheme;
366 PutProperties(aCurrent, aCurrentVal);
368 /* -----------------------------25.03.2002 12:19------------------------------
370 ---------------------------------------------------------------------------*/
371 void ColorConfig_Impl::SetColorConfigValue(ColorConfigEntry eValue, const ColorConfigValue& rValue )
373 if(rValue != m_aConfigValues[eValue])
375 m_aConfigValues[eValue] = rValue;
376 SetModified();
379 /* -----------------------------25.03.2002 15:22------------------------------
381 ---------------------------------------------------------------------------*/
382 uno::Sequence< ::rtl::OUString> ColorConfig_Impl::GetSchemeNames()
384 return GetNodeNames(C2U("ColorSchemes"));
386 /* -----------------------------09.04.2002 17:19------------------------------
388 ---------------------------------------------------------------------------*/
389 sal_Bool ColorConfig_Impl::AddScheme(const rtl::OUString& rScheme)
391 if(ConfigItem::AddNode(C2U("ColorSchemes"), rScheme))
393 m_sLoadedScheme = rScheme;
394 Commit();
395 return sal_True;
397 return sal_False;
399 /* -----------------------------09.04.2002 17:19------------------------------
401 ---------------------------------------------------------------------------*/
402 sal_Bool ColorConfig_Impl::RemoveScheme(const rtl::OUString& rScheme)
404 uno::Sequence< rtl::OUString > aElements(1);
405 aElements.getArray()[0] = rScheme;
406 return ClearNodeElements(C2U("ColorSchemes"), aElements);
408 /* -----------------------------2002/06/20 13:03------------------------------
410 ---------------------------------------------------------------------------*/
411 void ColorConfig_Impl::SettingsChanged()
413 vos::OGuard aVclGuard( Application::GetSolarMutex() );
415 ImplUpdateApplicationSettings();
417 Broadcast( SfxSimpleHint( SFX_HINT_COLORS_CHANGED ) );
419 /* -----------------11.12.2002 09:21-----------------
421 * --------------------------------------------------*/
422 void ColorConfig_Impl::LockBroadcast()
424 m_bLockBroadcast = sal_True;
426 /* -----------------11.12.2002 09:21-----------------
428 * --------------------------------------------------*/
429 void ColorConfig_Impl::UnlockBroadcast()
431 if ( m_bBroadcastWhenUnlocked )
433 m_bBroadcastWhenUnlocked = ColorConfig::m_pImpl != NULL;
434 if ( m_bBroadcastWhenUnlocked )
436 ColorConfig::m_pImpl->ImplUpdateApplicationSettings();
437 if ( ColorConfig::m_pImpl->IsEnableBroadcast() )
439 m_bBroadcastWhenUnlocked = sal_False;
440 ColorConfig::m_pImpl->Broadcast(SfxSimpleHint(SFX_HINT_COLORS_CHANGED));
444 m_bLockBroadcast = sal_False;
446 /* -----------------------------2002/08/16 12:07 -----------------------------
447 #100822#
448 --------------------------------------------------------------------------- */
449 IMPL_LINK( ColorConfig_Impl, DataChangedEventListener, VclWindowEvent*, pEvent )
451 if ( pEvent->GetId() == VCLEVENT_APPLICATION_DATACHANGED )
453 DataChangedEvent* pData = (DataChangedEvent*)(pEvent->GetData());
454 if ( (pData->GetType() == DATACHANGED_SETTINGS) &&
455 (pData->GetFlags() & SETTINGS_STYLE) )
457 SettingsChanged();
458 return 1L;
459 } else
460 return 0L;
461 } else
462 return 0L;
465 // ---------------------------------------------------------------------------
467 /** updates the font color in the vcl window settings */
468 void ColorConfig_Impl::ImplUpdateApplicationSettings()
470 Application* pApp = GetpApp();
471 if( pApp )
473 AllSettings aSettings = pApp->GetSettings();
474 StyleSettings aStyleSettings( aSettings.GetStyleSettings() );
476 ColorConfigValue aRet = GetColorConfigValue(svtools::FONTCOLOR);
477 if(COL_AUTO == sal::static_int_cast<ColorData>(aRet.nColor))
478 aRet.nColor = ColorConfig::GetDefaultColor(svtools::FONTCOLOR).GetColor();
480 Color aFontColor(aRet.nColor);
482 if( aStyleSettings.GetFontColor() != aFontColor )
484 aStyleSettings.SetFontColor( aFontColor );
486 aSettings.SetStyleSettings( aStyleSettings );
487 pApp->SetSettings( aSettings );
492 // ---------------------------------------------------------------------------
494 ColorConfig::ColorConfig()
496 ::osl::MutexGuard aGuard( ColorMutex_Impl::get() );
497 if ( !m_pImpl )
499 m_pImpl = new ColorConfig_Impl;
500 ItemHolder2::holdConfigItem(E_COLORCFG);
502 ++nColorRefCount_Impl;
503 StartListening( *m_pImpl);
505 /* -----------------------------16.01.01 15:36--------------------------------
507 ---------------------------------------------------------------------------*/
508 ColorConfig::~ColorConfig()
510 ::osl::MutexGuard aGuard( ColorMutex_Impl::get() );
511 EndListening( *m_pImpl);
512 if(!--nColorRefCount_Impl)
514 delete m_pImpl;
515 m_pImpl = 0;
518 /* -----------------------------11.04.2002 11:49------------------------------
520 ---------------------------------------------------------------------------*/
521 Color ColorConfig::GetDefaultColor(ColorConfigEntry eEntry)
523 static const sal_Int32 aAutoColors[] =
525 0, // DOCCOLOR
526 0xc0c0c0, // DOCBOUNDARIES
527 0x808080, // APPBACKGROUND
528 0xc0c0c0, // OBJECTBOUNDARIES
529 0xc0c0c0, // TABLEBOUNDARIES
530 0, // FONTCOLOR
531 0xcc, // LINKS
532 0x80, // LINKSVISITED
533 0, // ANCHOR
534 0xff0000, // SPELL
535 COL_LIGHTMAGENTA,// SMARTTAGS
536 0xc0c0c0, // WRITERTEXTGRID
537 0xc0c0c0, // WRITERFIELDSHADIN
538 0xc0c0c0, // WRITERIDXSHADINGS
539 0, // WRITERDIRECTCURSOR
540 COL_GREEN, //WRITERSCRIPTINDICATOR
541 0xc0c0c0, //WRITERSECTIONBOUNDARIES
542 COL_BLUE, //WRITERPAGEBREAKS,
543 COL_LIGHTBLUE, // HTMLSGML
544 COL_LIGHTGREEN, // HTMLCOMMENT
545 COL_LIGHTRED, // HTMLKEYWORD
546 COL_GRAY, // HTMLUNKNOWN
547 COL_LIGHTGRAY, // CALCGRID
548 COL_BLUE, //CALCPAGEBREAK
549 0x2300dc, //CALCPAGEBREAKMANUAL
550 COL_GRAY, //CALCPAGEBREAKAUTOMATIC
551 COL_LIGHTBLUE, // CALCDETECTIVE
552 COL_LIGHTRED, // CALCDETECTIVEERROR
553 COL_LIGHTRED, // CALCREFERENCE
554 0xffffc0, // CALCNOTESBACKGROUND
555 0xc0c0c0, // DRAWGRID
556 0, // DRAWDRAWING
557 0xb8ff, // DRAWFILL
558 COL_GREEN, // BASICIDENTIFIER,
559 COL_GRAY,// BASICCOMMENT ,
560 COL_LIGHTRED,// BASICNUMBER ,
561 COL_LIGHTRED,// BASICSTRING ,
562 COL_BLUE, // BASICOPERATOR ,
563 COL_BLUE, // BASICKEYWORD ,
564 COL_RED, //BASICERROR
565 0x009900, // SQLIDENTIFIER
566 0x000000, // SQLNUMBER
567 0xCE7B00, // SQLSTRING
568 0x000000, // SQLOPERATOR
569 0x0000E6, // SQLKEYWORD
570 0x259D9D, // SQLPARAMTER
571 0x969696,// SQLCOMMENT
573 Color aRet;
574 switch(eEntry)
576 case DOCCOLOR :
577 aRet = Application::GetSettings().GetStyleSettings().GetWindowColor();
578 break;
580 case APPBACKGROUND :
581 aRet = Application::GetSettings().GetStyleSettings().GetWorkspaceColor();
582 break;
584 case SPELL :
585 case DRAWDRAWING :
586 case SMARTTAGS :
588 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
589 aRet = rStyleSettings.GetHighContrastMode() ?
590 rStyleSettings.GetDialogTextColor().GetColor() : aAutoColors[eEntry];
592 break;
594 case DRAWFILL :
595 aRet = /*rStyleSettings.GetHighContrastMode() ?
596 rStyleSettings.OutlineMode??? : */ aAutoColors[eEntry];
597 break;
599 case FONTCOLOR :
600 aRet = Application::GetSettings().GetStyleSettings().GetWindowTextColor();
601 break;
603 case LINKS :
604 aRet = Application::GetSettings().GetStyleSettings().GetLinkColor();
605 break;
607 case LINKSVISITED :
608 aRet = Application::GetSettings().GetStyleSettings().GetVisitedLinkColor();
609 break;
611 default:
612 aRet = aAutoColors[eEntry];
614 return aRet;
616 /* -----------------------------11.04.2002 11:49------------------------------
618 ---------------------------------------------------------------------------*/
619 ColorConfigValue ColorConfig::GetColorValue(ColorConfigEntry eEntry, sal_Bool bSmart)const
621 ColorConfigValue aRet = m_pImpl->GetColorConfigValue(eEntry);
622 if(bSmart)
624 if(COL_AUTO == sal::static_int_cast<ColorData>(aRet.nColor))
625 aRet.nColor = ColorConfig::GetDefaultColor(eEntry).GetColor();
626 //#103495# don't allow grey between 40% and 60% as application background
627 const UINT8 nRed = COLORDATA_RED( aRet.nColor);
628 if(eEntry == APPBACKGROUND &&
629 (nRed == COLORDATA_GREEN( aRet.nColor)) &&
630 (nRed == COLORDATA_BLUE( aRet.nColor)) &&
631 nRed > 102 && nRed < 153 )
633 aRet.nColor = RGB_COLORDATA(153, 153, 153);
637 return aRet;
639 /* -----------------------------12.04.2002 09:25------------------------------
641 ---------------------------------------------------------------------------*/
642 void ColorConfig::Notify( SfxBroadcaster&, const SfxHint& rHint )
644 vos::OGuard aVclGuard( Application::GetSolarMutex() );
646 Broadcast( rHint );
648 /* -----------------------------25.03.2002 12:01------------------------------
650 ---------------------------------------------------------------------------*/
651 EditableColorConfig::EditableColorConfig() :
652 m_pImpl(new ColorConfig_Impl),
653 m_bModified(sal_False)
655 m_pImpl->LockBroadcast();
657 /*-- 25.03.2002 12:03:08---------------------------------------------------
659 -----------------------------------------------------------------------*/
660 EditableColorConfig::~EditableColorConfig()
662 m_pImpl->UnlockBroadcast();
663 if(m_bModified)
664 m_pImpl->SetModified();
665 if(m_pImpl->IsModified())
666 m_pImpl->Commit();
667 delete m_pImpl;
670 /*-- 25.03.2002 12:03:15---------------------------------------------------
672 -----------------------------------------------------------------------*/
673 uno::Sequence< ::rtl::OUString > EditableColorConfig::GetSchemeNames() const
675 return m_pImpl->GetSchemeNames();
677 /*-- 25.03.2002 12:03:16---------------------------------------------------
679 -----------------------------------------------------------------------*/
680 void EditableColorConfig::DeleteScheme(const ::rtl::OUString& rScheme )
682 m_pImpl->RemoveScheme(rScheme);
684 /*-- 25.03.2002 12:03:16---------------------------------------------------
686 -----------------------------------------------------------------------*/
687 void EditableColorConfig::AddScheme(const ::rtl::OUString& rScheme )
689 m_pImpl->AddScheme(rScheme);
691 /*-- 25.03.2002 12:03:16---------------------------------------------------
693 -----------------------------------------------------------------------*/
694 sal_Bool EditableColorConfig::LoadScheme(const ::rtl::OUString& rScheme )
696 if(m_bModified)
697 m_pImpl->SetModified();
698 if(m_pImpl->IsModified())
699 m_pImpl->Commit();
700 m_bModified = sal_False;
701 m_pImpl->Load(rScheme);
702 //the name of the loaded scheme has to be committed separately
703 m_pImpl->CommitCurrentSchemeName();
704 return sal_True;
706 /*-- 25.03.2002 12:03:16---------------------------------------------------
708 -----------------------------------------------------------------------*/
709 const ::rtl::OUString& EditableColorConfig::GetCurrentSchemeName()const
711 return m_pImpl->GetLoadedScheme();
713 /* -----------------11.12.2002 10:56-----------------
714 * changes the name of the current scheme but doesn't load it!
715 * --------------------------------------------------*/
716 void EditableColorConfig::SetCurrentSchemeName(const ::rtl::OUString& rScheme)
718 m_pImpl->SetCurrentSchemeName(rScheme);
719 m_pImpl->CommitCurrentSchemeName();
721 /*-- 25.03.2002 12:03:17---------------------------------------------------
723 -----------------------------------------------------------------------*/
724 const ColorConfigValue& EditableColorConfig::GetColorValue(
725 ColorConfigEntry eEntry)const
727 return m_pImpl->GetColorConfigValue(eEntry);
729 /*-- 25.03.2002 12:03:17---------------------------------------------------
731 -----------------------------------------------------------------------*/
732 void EditableColorConfig::SetColorValue(
733 ColorConfigEntry eEntry, const ColorConfigValue& rValue)
735 m_pImpl->SetColorConfigValue(eEntry, rValue);
736 m_pImpl->ClearModified();
737 m_bModified = sal_True;
739 /* -----------------------------10.04.2002 13:22------------------------------
741 ---------------------------------------------------------------------------*/
742 void EditableColorConfig::SetModified()
744 m_bModified = sal_True;
746 /* -----------------15.10.2002 14:51-----------------
748 * --------------------------------------------------*/
749 void EditableColorConfig::Commit()
751 if(m_bModified)
752 m_pImpl->SetModified();
753 if(m_pImpl->IsModified())
754 m_pImpl->Commit();
755 m_bModified = sal_False;
757 // -----------------------------------------------------------------------------
758 void EditableColorConfig::DisableBroadcast()
760 m_pImpl->DisableBroadcast();
762 // -----------------------------------------------------------------------------
763 void EditableColorConfig::EnableBroadcast()
765 m_pImpl->EnableBroadcast();
767 // -----------------------------------------------------------------------------
769 }//namespace svtools