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