xref: /aoo41x/main/unotools/source/config/misccfg.cxx (revision cdf0e10c)
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 
31*cdf0e10cSrcweir #include <unotools/misccfg.hxx>
32*cdf0e10cSrcweir #include "rtl/instance.hxx"
33*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
34*cdf0e10cSrcweir #include <unotools/configitem.hxx>
35*cdf0e10cSrcweir #include <tools/debug.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
37*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
38*cdf0e10cSrcweir #include <vos/mutex.hxx>
39*cdf0e10cSrcweir #include <osl/mutex.hxx>
40*cdf0e10cSrcweir #include <rtl/logfile.hxx>
41*cdf0e10cSrcweir #include "itemholder1.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #define DEFAULT_TAB 2000
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #define DEF_INCH	2540L
46*cdf0e10cSrcweir #define DEF_RELTWIP	1440L
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace rtl;
49*cdf0e10cSrcweir using namespace com::sun::star::uno;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace utl
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir static SfxMiscCfg* pOptions = NULL;
57*cdf0e10cSrcweir static sal_Int32 nRefCount = 0;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir class SfxMiscCfg : public utl::ConfigItem
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir 	sal_Bool			bPaperSize;     // printer warnings
62*cdf0e10cSrcweir 	sal_Bool			bPaperOrientation;
63*cdf0e10cSrcweir 	sal_Bool			bNotFound;
64*cdf0e10cSrcweir 	sal_Int32		nYear2000;		// two digit year representation
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 	const com::sun::star::uno::Sequence<rtl::OUString>& GetPropertyNames();
67*cdf0e10cSrcweir 	void					Load();
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir public:
70*cdf0e10cSrcweir 	SfxMiscCfg( );
71*cdf0e10cSrcweir 	~SfxMiscCfg( );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	virtual void 			Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames);
74*cdf0e10cSrcweir 	virtual void			Commit();
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	sal_Bool		IsNotFoundWarning() 	const {return bNotFound;}
77*cdf0e10cSrcweir 	void		SetNotFoundWarning(	sal_Bool bSet);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	sal_Bool		IsPaperSizeWarning() 	const {return bPaperSize;}
80*cdf0e10cSrcweir 	void		SetPaperSizeWarning(sal_Bool bSet);
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	sal_Bool		IsPaperOrientationWarning() 	const {return bPaperOrientation;}
83*cdf0e10cSrcweir 	void		SetPaperOrientationWarning(	sal_Bool bSet);
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 				// 0 ... 99
86*cdf0e10cSrcweir 	sal_Int32	GetYear2000()			const { return nYear2000; }
87*cdf0e10cSrcweir     void        SetYear2000( sal_Int32 nSet );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir };
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir /*--------------------------------------------------------------------
92*cdf0e10cSrcweir 	 Beschreibung:
93*cdf0e10cSrcweir  --------------------------------------------------------------------*/
94*cdf0e10cSrcweir SfxMiscCfg::SfxMiscCfg() :
95*cdf0e10cSrcweir 	ConfigItem(C2U("Office.Common") ),
96*cdf0e10cSrcweir 	bPaperSize(sal_False),
97*cdf0e10cSrcweir 	bPaperOrientation (sal_False),
98*cdf0e10cSrcweir 	bNotFound (sal_False),
99*cdf0e10cSrcweir 	nYear2000( 1930 )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT(aLog, "svl SfxMiscCfg::SfxMiscCfg()");
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	Load();
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
108*cdf0e10cSrcweir SfxMiscCfg::~SfxMiscCfg()
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir /*--------------------------------------------------------------------
112*cdf0e10cSrcweir 	 Beschreibung:
113*cdf0e10cSrcweir  --------------------------------------------------------------------*/
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir void SfxMiscCfg::SetNotFoundWarning( sal_Bool bSet)
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir 	if(bNotFound != bSet)
118*cdf0e10cSrcweir 		SetModified();
119*cdf0e10cSrcweir 	bNotFound = bSet;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir /*--------------------------------------------------------------------
123*cdf0e10cSrcweir 	 Beschreibung:
124*cdf0e10cSrcweir  --------------------------------------------------------------------*/
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir void SfxMiscCfg::SetPaperSizeWarning( sal_Bool bSet)
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	if(bPaperSize != bSet)
129*cdf0e10cSrcweir 		SetModified();
130*cdf0e10cSrcweir 	bPaperSize = bSet;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir /*--------------------------------------------------------------------
134*cdf0e10cSrcweir 	 Beschreibung:
135*cdf0e10cSrcweir  --------------------------------------------------------------------*/
136*cdf0e10cSrcweir void SfxMiscCfg::SetPaperOrientationWarning( sal_Bool bSet)
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	if(bPaperOrientation != bSet)
139*cdf0e10cSrcweir 		SetModified();
140*cdf0e10cSrcweir 	bPaperOrientation = bSet;
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir /*--------------------------------------------------------------------
143*cdf0e10cSrcweir 	 Beschreibung:
144*cdf0e10cSrcweir  --------------------------------------------------------------------*/
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir void SfxMiscCfg::SetYear2000( sal_Int32 nSet )
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	if(nYear2000 != nSet)
149*cdf0e10cSrcweir 		SetModified();
150*cdf0e10cSrcweir 	nYear2000 = nSet;
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
155*cdf0e10cSrcweir const Sequence<OUString>& SfxMiscCfg::GetPropertyNames()
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	static Sequence<OUString> aNames;
158*cdf0e10cSrcweir 	if(!aNames.getLength())
159*cdf0e10cSrcweir 	{
160*cdf0e10cSrcweir 		static const char* aPropNames[] =
161*cdf0e10cSrcweir 		{
162*cdf0e10cSrcweir    			"Print/Warning/PaperSize",				//  0
163*cdf0e10cSrcweir    			"Print/Warning/PaperOrientation",		//  1
164*cdf0e10cSrcweir    			"Print/Warning/NotFound",				//  2
165*cdf0e10cSrcweir 			"DateFormat/TwoDigitYear",            	//  3
166*cdf0e10cSrcweir 		};
167*cdf0e10cSrcweir         const int nCount = 4;
168*cdf0e10cSrcweir 		aNames.realloc(nCount);
169*cdf0e10cSrcweir 		OUString* pNames = aNames.getArray();
170*cdf0e10cSrcweir 		for(int i = 0; i < nCount; i++)
171*cdf0e10cSrcweir 			pNames[i] = OUString::createFromAscii(aPropNames[i]);
172*cdf0e10cSrcweir 	}
173*cdf0e10cSrcweir 	return aNames;
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
178*cdf0e10cSrcweir void SfxMiscCfg::Load()
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir 	const Sequence<OUString>& aNames = GetPropertyNames();
181*cdf0e10cSrcweir 	Sequence<Any> aValues = GetProperties(aNames);
182*cdf0e10cSrcweir 	EnableNotification(aNames);
183*cdf0e10cSrcweir 	const Any* pValues = aValues.getConstArray();
184*cdf0e10cSrcweir 	DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
185*cdf0e10cSrcweir 	if(aValues.getLength() == aNames.getLength())
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		for(int nProp = 0; nProp < aNames.getLength(); nProp++)
188*cdf0e10cSrcweir 		{
189*cdf0e10cSrcweir 			if(pValues[nProp].hasValue())
190*cdf0e10cSrcweir 			{
191*cdf0e10cSrcweir 				switch(nProp)
192*cdf0e10cSrcweir 				{
193*cdf0e10cSrcweir 					case  0: bPaperSize 	   = *(sal_Bool*)pValues[nProp].getValue(); break;		//"Print/Warning/PaperSize",
194*cdf0e10cSrcweir                     case  1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue();  break;     //"Print/Warning/PaperOrientation",
195*cdf0e10cSrcweir                     case  2: bNotFound         = *(sal_Bool*)pValues[nProp].getValue()  ;  break;   //"Print/Warning/NotFound",
196*cdf0e10cSrcweir 					case  3: pValues[nProp] >>= nYear2000;break;                                    //"DateFormat/TwoDigitYear",
197*cdf0e10cSrcweir 				}
198*cdf0e10cSrcweir 			}
199*cdf0e10cSrcweir 		}
200*cdf0e10cSrcweir 	}
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
205*cdf0e10cSrcweir void SfxMiscCfg::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	Load();
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
212*cdf0e10cSrcweir void SfxMiscCfg::Commit()
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	const Sequence<OUString>& aNames = GetPropertyNames();
215*cdf0e10cSrcweir 	Sequence<Any> aValues(aNames.getLength());
216*cdf0e10cSrcweir 	Any* pValues = aValues.getArray();
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	const Type& rType = ::getBooleanCppuType();
219*cdf0e10cSrcweir 	for(int nProp = 0; nProp < aNames.getLength(); nProp++)
220*cdf0e10cSrcweir 	{
221*cdf0e10cSrcweir 		switch(nProp)
222*cdf0e10cSrcweir 		{
223*cdf0e10cSrcweir 			case  0: pValues[nProp].setValue(&bPaperSize, rType);break;	 //"Print/Warning/PaperSize",
224*cdf0e10cSrcweir 			case  1: pValues[nProp].setValue(&bPaperOrientation, rType);break;     //"Print/Warning/PaperOrientation",
225*cdf0e10cSrcweir 			case  2: pValues[nProp].setValue(&bNotFound, rType);break;   //"Print/Warning/NotFound",
226*cdf0e10cSrcweir 			case  3: pValues[nProp] <<= nYear2000;break;                 //"DateFormat/TwoDigitYear",
227*cdf0e10cSrcweir 		}
228*cdf0e10cSrcweir 	}
229*cdf0e10cSrcweir 	PutProperties(aNames, aValues);
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir // -----------------------------------------------------------------------
232*cdf0e10cSrcweir namespace
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir     };
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir MiscCfg::MiscCfg( )
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
242*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( LocalSingleton::get() );
243*cdf0e10cSrcweir     if ( !pOptions )
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) SfxMiscCfg::ctor()");
246*cdf0e10cSrcweir         pOptions = new SfxMiscCfg;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_MISCCFG);
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     ++nRefCount;
252*cdf0e10cSrcweir     pImpl = pOptions;
253*cdf0e10cSrcweir     pImpl->AddListener(this);
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir MiscCfg::~MiscCfg( )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
259*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( LocalSingleton::get() );
260*cdf0e10cSrcweir     pImpl->RemoveListener(this);
261*cdf0e10cSrcweir     if ( !--nRefCount )
262*cdf0e10cSrcweir 	{
263*cdf0e10cSrcweir 		if ( pOptions->IsModified() )
264*cdf0e10cSrcweir 			pOptions->Commit();
265*cdf0e10cSrcweir         DELETEZ( pOptions );
266*cdf0e10cSrcweir 	}
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir sal_Bool MiscCfg::IsNotFoundWarning() 	const
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	return pImpl->IsNotFoundWarning();
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void MiscCfg::SetNotFoundWarning(	sal_Bool bSet)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir 	pImpl->SetNotFoundWarning( bSet );
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir sal_Bool MiscCfg::IsPaperSizeWarning() 	const
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	return pImpl->IsPaperSizeWarning();
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir void MiscCfg::SetPaperSizeWarning(sal_Bool bSet)
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir 	pImpl->SetPaperSizeWarning( bSet );
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir sal_Bool MiscCfg::IsPaperOrientationWarning() 	const
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir 	return pImpl->IsPaperOrientationWarning();
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir void MiscCfg::SetPaperOrientationWarning(	sal_Bool bSet)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir 	pImpl->SetPaperOrientationWarning( bSet );
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir sal_Int32 MiscCfg::GetYear2000() const
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir 	return pImpl->GetYear2000();
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir void MiscCfg::SetYear2000( sal_Int32 nSet )
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir 	pImpl->SetYear2000( nSet );
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311