1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_unotools.hxx" 30*cdf0e10cSrcweir #include <unotools/sourceviewconfig.hxx> 31*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 33*cdf0e10cSrcweir #include <unotools/configitem.hxx> 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir #include <rtl/instance.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <itemholder1.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace utl; 40*cdf0e10cSrcweir using namespace rtl; 41*cdf0e10cSrcweir using namespace com::sun::star::uno; 42*cdf0e10cSrcweir namespace utl 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir class SourceViewConfig_Impl : public utl::ConfigItem 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir private: 47*cdf0e10cSrcweir OUString m_sFontName; 48*cdf0e10cSrcweir sal_Int16 m_nFontHeight; 49*cdf0e10cSrcweir sal_Bool m_bProportionalFontOnly; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir void Load(); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir static Sequence< OUString > GetPropertyNames(); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir public: 56*cdf0e10cSrcweir SourceViewConfig_Impl(); 57*cdf0e10cSrcweir ~SourceViewConfig_Impl(); 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir virtual void Notify( const Sequence< rtl::OUString >& aPropertyNames ); 60*cdf0e10cSrcweir virtual void Commit(); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir const rtl::OUString& GetFontName() const 63*cdf0e10cSrcweir {return m_sFontName;} 64*cdf0e10cSrcweir void SetFontName(const rtl::OUString& rName) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir if(rName != m_sFontName) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir m_sFontName = rName; 69*cdf0e10cSrcweir SetModified(); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir sal_Int16 GetFontHeight() const 74*cdf0e10cSrcweir {return m_nFontHeight;} 75*cdf0e10cSrcweir void SetFontHeight(sal_Int16 nHeight) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir if(m_nFontHeight != nHeight) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir m_nFontHeight = nHeight; 80*cdf0e10cSrcweir SetModified(); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir sal_Bool IsShowProportionalFontsOnly() const 85*cdf0e10cSrcweir {return m_bProportionalFontOnly;} 86*cdf0e10cSrcweir void SetShowProportionalFontsOnly(sal_Bool bSet) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir if(m_bProportionalFontOnly != bSet) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir m_bProportionalFontOnly = bSet; 91*cdf0e10cSrcweir SetModified(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir // initialization of static members -------------------------------------- 96*cdf0e10cSrcweir SourceViewConfig_Impl* SourceViewConfig::m_pImplConfig = 0; 97*cdf0e10cSrcweir sal_Int32 SourceViewConfig::m_nRefCount = 0; 98*cdf0e10cSrcweir namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; } 99*cdf0e10cSrcweir /* -----------------------------28.08.2002 16:45------------------------------ 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 102*cdf0e10cSrcweir SourceViewConfig_Impl::SourceViewConfig_Impl() : 103*cdf0e10cSrcweir ConfigItem(OUString::createFromAscii("Office.Common/Font/SourceViewFont")), 104*cdf0e10cSrcweir m_nFontHeight(12), 105*cdf0e10cSrcweir m_bProportionalFontOnly(sal_False) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir Load(); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir /* -----------------------------28.08.2002 16:45------------------------------ 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 112*cdf0e10cSrcweir SourceViewConfig_Impl::~SourceViewConfig_Impl() 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir /* -----------------------------28.08.2002 16:25------------------------------ 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 118*cdf0e10cSrcweir Sequence< OUString > SourceViewConfig_Impl::GetPropertyNames() 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir //this list needs exactly to mach the enum PropertyNameIndex 121*cdf0e10cSrcweir static const char* aPropNames[] = 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir "FontName" // 0 124*cdf0e10cSrcweir ,"FontHeight" // 1 125*cdf0e10cSrcweir ,"NonProportionalFontsOnly" // 2 126*cdf0e10cSrcweir }; 127*cdf0e10cSrcweir const int nCount = sizeof( aPropNames ) / sizeof( const char* ); 128*cdf0e10cSrcweir Sequence< OUString > aNames( nCount ); 129*cdf0e10cSrcweir OUString* pNames = aNames.getArray(); 130*cdf0e10cSrcweir for ( int i = 0; i < nCount; i++ ) 131*cdf0e10cSrcweir pNames[i] = OUString::createFromAscii( aPropNames[i] ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir return aNames; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir /*-- 28.08.2002 16:37:59--------------------------------------------------- 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 139*cdf0e10cSrcweir void SourceViewConfig_Impl::Load() 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir Sequence< OUString > aNames = GetPropertyNames(); 142*cdf0e10cSrcweir Sequence< Any > aValues = GetProperties( aNames ); 143*cdf0e10cSrcweir EnableNotification( aNames ); 144*cdf0e10cSrcweir const Any* pValues = aValues.getConstArray(); 145*cdf0e10cSrcweir DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" ); 146*cdf0e10cSrcweir if ( aValues.getLength() == aNames.getLength() ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir for ( int nProp = 0; nProp < aNames.getLength(); nProp++ ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if ( pValues[nProp].hasValue() ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir switch( nProp ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir case 0: pValues[nProp] >>= m_sFontName; break; 155*cdf0e10cSrcweir case 1: pValues[nProp] >>= m_nFontHeight; break; 156*cdf0e10cSrcweir case 2: pValues[nProp] >>= m_bProportionalFontOnly; break; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir /*-- 28.08.2002 16:38:00--------------------------------------------------- 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 165*cdf0e10cSrcweir void SourceViewConfig_Impl::Notify( const Sequence< OUString >& ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir Load(); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir /*-- 28.08.2002 16:38:00--------------------------------------------------- 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 172*cdf0e10cSrcweir void SourceViewConfig_Impl::Commit() 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir ClearModified(); 175*cdf0e10cSrcweir Sequence< OUString > aNames = GetPropertyNames(); 176*cdf0e10cSrcweir Sequence< Any > aValues( aNames.getLength() ); 177*cdf0e10cSrcweir Any* pValues = aValues.getArray(); 178*cdf0e10cSrcweir for ( int nProp = 0; nProp < aNames.getLength(); nProp++ ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir switch( nProp ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir case 0: pValues[nProp] <<= m_sFontName; break; 183*cdf0e10cSrcweir case 1: pValues[nProp] <<= m_nFontHeight; break; 184*cdf0e10cSrcweir case 2: pValues[nProp] <<= m_bProportionalFontOnly; break; 185*cdf0e10cSrcweir default: 186*cdf0e10cSrcweir DBG_ERRORFILE( "invalid index to save a user token" ); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir PutProperties( aNames, aValues ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir NotifyListeners(0); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir /*-- 28.08.2002 16:32:19--------------------------------------------------- 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 196*cdf0e10cSrcweir SourceViewConfig::SourceViewConfig() 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir ::osl::MutexGuard aGuard( lclMutex::get() ); 200*cdf0e10cSrcweir if(!m_pImplConfig) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir m_pImplConfig = new SourceViewConfig_Impl; 203*cdf0e10cSrcweir ItemHolder1::holdConfigItem(E_SOURCEVIEWCONFIG); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir ++m_nRefCount; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir m_pImplConfig->AddListener( this ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir /*-- 28.08.2002 16:32:19--------------------------------------------------- 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 214*cdf0e10cSrcweir SourceViewConfig::~SourceViewConfig() 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir m_pImplConfig->RemoveListener( this ); 217*cdf0e10cSrcweir ::osl::MutexGuard aGuard( lclMutex::get() ); 218*cdf0e10cSrcweir if( !--m_nRefCount ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir if( m_pImplConfig->IsModified() ) 221*cdf0e10cSrcweir m_pImplConfig->Commit(); 222*cdf0e10cSrcweir DELETEZ( m_pImplConfig ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir /*-- 28.08.2002 16:32:19--------------------------------------------------- 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 228*cdf0e10cSrcweir const OUString& SourceViewConfig::GetFontName() const 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir return m_pImplConfig->GetFontName(); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir /*-- 28.08.2002 16:32:20--------------------------------------------------- 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 235*cdf0e10cSrcweir void SourceViewConfig::SetFontName(const OUString& rName) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir m_pImplConfig->SetFontName(rName); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir /*-- 28.08.2002 16:32:20--------------------------------------------------- 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 242*cdf0e10cSrcweir sal_Int16 SourceViewConfig::GetFontHeight() const 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir return m_pImplConfig->GetFontHeight(); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir /*-- 28.08.2002 16:32:20--------------------------------------------------- 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 249*cdf0e10cSrcweir void SourceViewConfig::SetFontHeight(sal_Int16 nHeight) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir m_pImplConfig->SetFontHeight(nHeight); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir /*-- 28.08.2002 16:32:20--------------------------------------------------- 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 256*cdf0e10cSrcweir sal_Bool SourceViewConfig::IsShowProportionalFontsOnly() const 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir return m_pImplConfig->IsShowProportionalFontsOnly(); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir /*-- 28.08.2002 16:32:20--------------------------------------------------- 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir -----------------------------------------------------------------------*/ 263*cdf0e10cSrcweir void SourceViewConfig::SetShowProportionalFontsOnly(sal_Bool bSet) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir m_pImplConfig->SetShowProportionalFontsOnly(bSet); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir // namespace utl 269