LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/config - extcolorcfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 368 0.0 %
Date: 2012-12-17 Functions: 0 56 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10