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