merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / sourceviewconfig.cxx
blobe3502ad38ab42a7bb345392b43d18ec00666b0d4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sourceviewconfig.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <svtools/sourceviewconfig.hxx>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <unotools/configitem.hxx>
37 #include <tools/debug.hxx>
38 #include <rtl/instance.hxx>
39 #include <svtools/smplhint.hxx>
41 #include <itemholder1.hxx>
43 using namespace utl;
44 using namespace rtl;
45 using namespace com::sun::star::uno;
46 namespace svt
48 class SourceViewConfig_Impl : public utl::ConfigItem, public SfxBroadcaster
50 private:
51 OUString m_sFontName;
52 sal_Int16 m_nFontHeight;
53 sal_Bool m_bProportionalFontOnly;
55 void Load();
57 static Sequence< OUString > GetPropertyNames();
59 public:
60 SourceViewConfig_Impl();
61 ~SourceViewConfig_Impl();
63 virtual void Notify( const Sequence< rtl::OUString >& aPropertyNames );
64 virtual void Commit();
66 const rtl::OUString& GetFontName() const
67 {return m_sFontName;}
68 void SetFontName(const rtl::OUString& rName)
70 if(rName != m_sFontName)
72 m_sFontName = rName;
73 SetModified();
77 sal_Int16 GetFontHeight() const
78 {return m_nFontHeight;}
79 void SetFontHeight(sal_Int16 nHeight)
81 if(m_nFontHeight != nHeight)
83 m_nFontHeight = nHeight;
84 SetModified();
88 sal_Bool IsShowProportionalFontsOnly() const
89 {return m_bProportionalFontOnly;}
90 void SetShowProportionalFontsOnly(sal_Bool bSet)
92 if(m_bProportionalFontOnly != bSet)
94 m_bProportionalFontOnly = bSet;
95 SetModified();
99 // initialization of static members --------------------------------------
100 SourceViewConfig_Impl* SourceViewConfig::m_pImplConfig = 0;
101 sal_Int32 SourceViewConfig::m_nRefCount = 0;
102 namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
103 /* -----------------------------28.08.2002 16:45------------------------------
105 ---------------------------------------------------------------------------*/
106 SourceViewConfig_Impl::SourceViewConfig_Impl() :
107 ConfigItem(OUString::createFromAscii("Office.Common/Font/SourceViewFont")),
108 m_nFontHeight(12),
109 m_bProportionalFontOnly(sal_False)
111 Load();
113 /* -----------------------------28.08.2002 16:45------------------------------
115 ---------------------------------------------------------------------------*/
116 SourceViewConfig_Impl::~SourceViewConfig_Impl()
119 /* -----------------------------28.08.2002 16:25------------------------------
121 ---------------------------------------------------------------------------*/
122 Sequence< OUString > SourceViewConfig_Impl::GetPropertyNames()
124 //this list needs exactly to mach the enum PropertyNameIndex
125 static const char* aPropNames[] =
127 "FontName" // 0
128 ,"FontHeight" // 1
129 ,"NonProportionalFontsOnly" // 2
131 const int nCount = sizeof( aPropNames ) / sizeof( const char* );
132 Sequence< OUString > aNames( nCount );
133 OUString* pNames = aNames.getArray();
134 for ( int i = 0; i < nCount; i++ )
135 pNames[i] = OUString::createFromAscii( aPropNames[i] );
137 return aNames;
140 /*-- 28.08.2002 16:37:59---------------------------------------------------
142 -----------------------------------------------------------------------*/
143 void SourceViewConfig_Impl::Load()
145 Sequence< OUString > aNames = GetPropertyNames();
146 Sequence< Any > aValues = GetProperties( aNames );
147 EnableNotification( aNames );
148 const Any* pValues = aValues.getConstArray();
149 DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
150 if ( aValues.getLength() == aNames.getLength() )
152 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
154 if ( pValues[nProp].hasValue() )
156 switch( nProp )
158 case 0: pValues[nProp] >>= m_sFontName; break;
159 case 1: pValues[nProp] >>= m_nFontHeight; break;
160 case 2: pValues[nProp] >>= m_bProportionalFontOnly; break;
166 /*-- 28.08.2002 16:38:00---------------------------------------------------
168 -----------------------------------------------------------------------*/
169 void SourceViewConfig_Impl::Notify( const Sequence< OUString >& )
171 Load();
173 /*-- 28.08.2002 16:38:00---------------------------------------------------
175 -----------------------------------------------------------------------*/
176 void SourceViewConfig_Impl::Commit()
178 ClearModified();
179 Sequence< OUString > aNames = GetPropertyNames();
180 Sequence< Any > aValues( aNames.getLength() );
181 Any* pValues = aValues.getArray();
182 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
184 switch( nProp )
186 case 0: pValues[nProp] <<= m_sFontName; break;
187 case 1: pValues[nProp] <<= m_nFontHeight; break;
188 case 2: pValues[nProp] <<= m_bProportionalFontOnly; break;
189 default:
190 DBG_ERRORFILE( "invalid index to save a user token" );
193 PutProperties( aNames, aValues );
195 //notify SfxListener
197 SfxSimpleHint aHint = SfxSimpleHint( SFX_HINT_DATACHANGED );
198 Broadcast(aHint);
201 /*-- 28.08.2002 16:32:19---------------------------------------------------
203 -----------------------------------------------------------------------*/
204 SourceViewConfig::SourceViewConfig()
207 ::osl::MutexGuard aGuard( lclMutex::get() );
208 if(!m_pImplConfig)
210 m_pImplConfig = new SourceViewConfig_Impl;
211 ItemHolder1::holdConfigItem(E_SOURCEVIEWCONFIG);
214 ++m_nRefCount;
216 StartListening( *m_pImplConfig, TRUE );
218 /*-- 28.08.2002 16:32:19---------------------------------------------------
220 -----------------------------------------------------------------------*/
221 SourceViewConfig::~SourceViewConfig()
223 EndListening( *m_pImplConfig, TRUE );
224 ::osl::MutexGuard aGuard( lclMutex::get() );
225 if( !--m_nRefCount )
227 if( m_pImplConfig->IsModified() )
228 m_pImplConfig->Commit();
229 DELETEZ( m_pImplConfig );
232 /*-- 28.08.2002 16:32:19---------------------------------------------------
234 -----------------------------------------------------------------------*/
235 const OUString& SourceViewConfig::GetFontName() const
237 return m_pImplConfig->GetFontName();
239 /*-- 28.08.2002 16:32:20---------------------------------------------------
241 -----------------------------------------------------------------------*/
242 void SourceViewConfig::SetFontName(const OUString& rName)
244 m_pImplConfig->SetFontName(rName);
246 /*-- 28.08.2002 16:32:20---------------------------------------------------
248 -----------------------------------------------------------------------*/
249 sal_Int16 SourceViewConfig::GetFontHeight() const
251 return m_pImplConfig->GetFontHeight();
253 /*-- 28.08.2002 16:32:20---------------------------------------------------
255 -----------------------------------------------------------------------*/
256 void SourceViewConfig::SetFontHeight(sal_Int16 nHeight)
258 m_pImplConfig->SetFontHeight(nHeight);
260 /*-- 28.08.2002 16:32:20---------------------------------------------------
262 -----------------------------------------------------------------------*/
263 sal_Bool SourceViewConfig::IsShowProportionalFontsOnly() const
265 return m_pImplConfig->IsShowProportionalFontsOnly();
267 /*-- 28.08.2002 16:32:20---------------------------------------------------
269 -----------------------------------------------------------------------*/
270 void SourceViewConfig::SetShowProportionalFontsOnly(sal_Bool bSet)
272 m_pImplConfig->SetShowProportionalFontsOnly(bSet);
274 /* -----------------------------30.08.2002 10:40------------------------------
276 ---------------------------------------------------------------------------*/
277 void SourceViewConfig::Notify( SfxBroadcaster&, const SfxHint& rHint )
279 Broadcast( rHint );
281 }//namespace svt