xref: /aoo42x/main/unotools/source/config/misccfg.cxx (revision b5088357)
1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <unotools/misccfg.hxx>
28cdf0e10cSrcweir #include "rtl/instance.hxx"
29cdf0e10cSrcweir #include <unotools/configmgr.hxx>
30cdf0e10cSrcweir #include <unotools/configitem.hxx>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
33cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
34cdf0e10cSrcweir #include <vos/mutex.hxx>
35cdf0e10cSrcweir #include <osl/mutex.hxx>
36cdf0e10cSrcweir #include <rtl/logfile.hxx>
37cdf0e10cSrcweir #include "itemholder1.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define DEFAULT_TAB 2000
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #define DEF_INCH	2540L
42cdf0e10cSrcweir #define DEF_RELTWIP	1440L
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace rtl;
45cdf0e10cSrcweir using namespace com::sun::star::uno;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace utl
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir static SfxMiscCfg* pOptions = NULL;
53cdf0e10cSrcweir static sal_Int32 nRefCount = 0;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir class SfxMiscCfg : public utl::ConfigItem
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	sal_Bool			bPaperSize;     // printer warnings
58cdf0e10cSrcweir 	sal_Bool			bPaperOrientation;
59cdf0e10cSrcweir 	sal_Bool			bNotFound;
60cdf0e10cSrcweir 	sal_Int32		nYear2000;		// two digit year representation
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	const com::sun::star::uno::Sequence<rtl::OUString>& GetPropertyNames();
63cdf0e10cSrcweir 	void					Load();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir public:
66cdf0e10cSrcweir 	SfxMiscCfg( );
67cdf0e10cSrcweir 	~SfxMiscCfg( );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	virtual void 			Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames);
70cdf0e10cSrcweir 	virtual void			Commit();
71cdf0e10cSrcweir 
IsNotFoundWarning() const72cdf0e10cSrcweir 	sal_Bool		IsNotFoundWarning() 	const {return bNotFound;}
73cdf0e10cSrcweir 	void		SetNotFoundWarning(	sal_Bool bSet);
74cdf0e10cSrcweir 
IsPaperSizeWarning() const75cdf0e10cSrcweir 	sal_Bool		IsPaperSizeWarning() 	const {return bPaperSize;}
76cdf0e10cSrcweir 	void		SetPaperSizeWarning(sal_Bool bSet);
77cdf0e10cSrcweir 
IsPaperOrientationWarning() const78cdf0e10cSrcweir 	sal_Bool		IsPaperOrientationWarning() 	const {return bPaperOrientation;}
79cdf0e10cSrcweir 	void		SetPaperOrientationWarning(	sal_Bool bSet);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 				// 0 ... 99
GetYear2000() const82cdf0e10cSrcweir 	sal_Int32	GetYear2000()			const { return nYear2000; }
83cdf0e10cSrcweir     void        SetYear2000( sal_Int32 nSet );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir };
86cdf0e10cSrcweir 
87cdf0e10cSrcweir /*--------------------------------------------------------------------
88cdf0e10cSrcweir 	 Beschreibung:
89cdf0e10cSrcweir  --------------------------------------------------------------------*/
SfxMiscCfg()90cdf0e10cSrcweir SfxMiscCfg::SfxMiscCfg() :
91cdf0e10cSrcweir 	ConfigItem(C2U("Office.Common") ),
92cdf0e10cSrcweir 	bPaperSize(sal_False),
93cdf0e10cSrcweir 	bPaperOrientation (sal_False),
94cdf0e10cSrcweir 	bNotFound (sal_False),
95cdf0e10cSrcweir 	nYear2000( 1930 )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT(aLog, "svl SfxMiscCfg::SfxMiscCfg()");
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	Load();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
102cdf0e10cSrcweir 
103cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
~SfxMiscCfg()104cdf0e10cSrcweir SfxMiscCfg::~SfxMiscCfg()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir /*--------------------------------------------------------------------
108cdf0e10cSrcweir 	 Beschreibung:
109cdf0e10cSrcweir  --------------------------------------------------------------------*/
110cdf0e10cSrcweir 
SetNotFoundWarning(sal_Bool bSet)111cdf0e10cSrcweir void SfxMiscCfg::SetNotFoundWarning( sal_Bool bSet)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	if(bNotFound != bSet)
114cdf0e10cSrcweir 		SetModified();
115cdf0e10cSrcweir 	bNotFound = bSet;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir /*--------------------------------------------------------------------
119cdf0e10cSrcweir 	 Beschreibung:
120cdf0e10cSrcweir  --------------------------------------------------------------------*/
121cdf0e10cSrcweir 
SetPaperSizeWarning(sal_Bool bSet)122cdf0e10cSrcweir void SfxMiscCfg::SetPaperSizeWarning( sal_Bool bSet)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	if(bPaperSize != bSet)
125cdf0e10cSrcweir 		SetModified();
126cdf0e10cSrcweir 	bPaperSize = bSet;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir /*--------------------------------------------------------------------
130cdf0e10cSrcweir 	 Beschreibung:
131cdf0e10cSrcweir  --------------------------------------------------------------------*/
SetPaperOrientationWarning(sal_Bool bSet)132cdf0e10cSrcweir void SfxMiscCfg::SetPaperOrientationWarning( sal_Bool bSet)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	if(bPaperOrientation != bSet)
135cdf0e10cSrcweir 		SetModified();
136cdf0e10cSrcweir 	bPaperOrientation = bSet;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir /*--------------------------------------------------------------------
139cdf0e10cSrcweir 	 Beschreibung:
140cdf0e10cSrcweir  --------------------------------------------------------------------*/
141cdf0e10cSrcweir 
SetYear2000(sal_Int32 nSet)142cdf0e10cSrcweir void SfxMiscCfg::SetYear2000( sal_Int32 nSet )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	if(nYear2000 != nSet)
145cdf0e10cSrcweir 		SetModified();
146cdf0e10cSrcweir 	nYear2000 = nSet;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
149cdf0e10cSrcweir 
150cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
GetPropertyNames()151cdf0e10cSrcweir const Sequence<OUString>& SfxMiscCfg::GetPropertyNames()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	static Sequence<OUString> aNames;
154cdf0e10cSrcweir 	if(!aNames.getLength())
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		static const char* aPropNames[] =
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir    			"Print/Warning/PaperSize",				//  0
159cdf0e10cSrcweir    			"Print/Warning/PaperOrientation",		//  1
160cdf0e10cSrcweir    			"Print/Warning/NotFound",				//  2
161cdf0e10cSrcweir 			"DateFormat/TwoDigitYear",            	//  3
162cdf0e10cSrcweir 		};
163cdf0e10cSrcweir         const int nCount = 4;
164cdf0e10cSrcweir 		aNames.realloc(nCount);
165cdf0e10cSrcweir 		OUString* pNames = aNames.getArray();
166cdf0e10cSrcweir 		for(int i = 0; i < nCount; i++)
167cdf0e10cSrcweir 			pNames[i] = OUString::createFromAscii(aPropNames[i]);
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 	return aNames;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
172cdf0e10cSrcweir 
173cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Load()174cdf0e10cSrcweir void SfxMiscCfg::Load()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	const Sequence<OUString>& aNames = GetPropertyNames();
177cdf0e10cSrcweir 	Sequence<Any> aValues = GetProperties(aNames);
178cdf0e10cSrcweir 	EnableNotification(aNames);
179cdf0e10cSrcweir 	const Any* pValues = aValues.getConstArray();
180cdf0e10cSrcweir 	DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
181cdf0e10cSrcweir 	if(aValues.getLength() == aNames.getLength())
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		for(int nProp = 0; nProp < aNames.getLength(); nProp++)
184cdf0e10cSrcweir 		{
185cdf0e10cSrcweir 			if(pValues[nProp].hasValue())
186cdf0e10cSrcweir 			{
187cdf0e10cSrcweir 				switch(nProp)
188cdf0e10cSrcweir 				{
189cdf0e10cSrcweir 					case  0: bPaperSize 	   = *(sal_Bool*)pValues[nProp].getValue(); break;		//"Print/Warning/PaperSize",
190cdf0e10cSrcweir                     case  1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue();  break;     //"Print/Warning/PaperOrientation",
191cdf0e10cSrcweir                     case  2: bNotFound         = *(sal_Bool*)pValues[nProp].getValue()  ;  break;   //"Print/Warning/NotFound",
192cdf0e10cSrcweir 					case  3: pValues[nProp] >>= nYear2000;break;                                    //"DateFormat/TwoDigitYear",
193cdf0e10cSrcweir 				}
194cdf0e10cSrcweir 			}
195cdf0e10cSrcweir 		}
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir }
198cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
199cdf0e10cSrcweir 
200cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Notify(const com::sun::star::uno::Sequence<rtl::OUString> &)201cdf0e10cSrcweir void SfxMiscCfg::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	Load();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir /* -----------------------------02.03.01 15:31--------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
Commit()208cdf0e10cSrcweir void SfxMiscCfg::Commit()
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	const Sequence<OUString>& aNames = GetPropertyNames();
211cdf0e10cSrcweir 	Sequence<Any> aValues(aNames.getLength());
212cdf0e10cSrcweir 	Any* pValues = aValues.getArray();
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	const Type& rType = ::getBooleanCppuType();
215cdf0e10cSrcweir 	for(int nProp = 0; nProp < aNames.getLength(); nProp++)
216cdf0e10cSrcweir 	{
217cdf0e10cSrcweir 		switch(nProp)
218cdf0e10cSrcweir 		{
219cdf0e10cSrcweir 			case  0: pValues[nProp].setValue(&bPaperSize, rType);break;	 //"Print/Warning/PaperSize",
220cdf0e10cSrcweir 			case  1: pValues[nProp].setValue(&bPaperOrientation, rType);break;     //"Print/Warning/PaperOrientation",
221cdf0e10cSrcweir 			case  2: pValues[nProp].setValue(&bNotFound, rType);break;   //"Print/Warning/NotFound",
222cdf0e10cSrcweir 			case  3: pValues[nProp] <<= nYear2000;break;                 //"DateFormat/TwoDigitYear",
223cdf0e10cSrcweir 		}
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir 	PutProperties(aNames, aValues);
226cdf0e10cSrcweir }
227cdf0e10cSrcweir // -----------------------------------------------------------------------
228cdf0e10cSrcweir namespace
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir     };
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
MiscCfg()235cdf0e10cSrcweir MiscCfg::MiscCfg( )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
238cdf0e10cSrcweir     ::osl::MutexGuard aGuard( LocalSingleton::get() );
239cdf0e10cSrcweir     if ( !pOptions )
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) SfxMiscCfg::ctor()");
242cdf0e10cSrcweir         pOptions = new SfxMiscCfg;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_MISCCFG);
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     ++nRefCount;
248cdf0e10cSrcweir     pImpl = pOptions;
249cdf0e10cSrcweir     pImpl->AddListener(this);
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
~MiscCfg()252cdf0e10cSrcweir MiscCfg::~MiscCfg( )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
255cdf0e10cSrcweir     ::osl::MutexGuard aGuard( LocalSingleton::get() );
256cdf0e10cSrcweir     pImpl->RemoveListener(this);
257cdf0e10cSrcweir     if ( !--nRefCount )
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir 		if ( pOptions->IsModified() )
260cdf0e10cSrcweir 			pOptions->Commit();
261cdf0e10cSrcweir         DELETEZ( pOptions );
262cdf0e10cSrcweir 	}
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
IsNotFoundWarning() const265cdf0e10cSrcweir sal_Bool MiscCfg::IsNotFoundWarning() 	const
266cdf0e10cSrcweir {
267cdf0e10cSrcweir 	return pImpl->IsNotFoundWarning();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
SetNotFoundWarning(sal_Bool bSet)270cdf0e10cSrcweir void MiscCfg::SetNotFoundWarning(	sal_Bool bSet)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir 	pImpl->SetNotFoundWarning( bSet );
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
IsPaperSizeWarning() const275cdf0e10cSrcweir sal_Bool MiscCfg::IsPaperSizeWarning() 	const
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	return pImpl->IsPaperSizeWarning();
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
SetPaperSizeWarning(sal_Bool bSet)280cdf0e10cSrcweir void MiscCfg::SetPaperSizeWarning(sal_Bool bSet)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	pImpl->SetPaperSizeWarning( bSet );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
IsPaperOrientationWarning() const285cdf0e10cSrcweir sal_Bool MiscCfg::IsPaperOrientationWarning() 	const
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	return pImpl->IsPaperOrientationWarning();
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
SetPaperOrientationWarning(sal_Bool bSet)290cdf0e10cSrcweir void MiscCfg::SetPaperOrientationWarning(	sal_Bool bSet)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	pImpl->SetPaperOrientationWarning( bSet );
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
GetYear2000() const295cdf0e10cSrcweir sal_Int32 MiscCfg::GetYear2000() const
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	return pImpl->GetYear2000();
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
SetYear2000(sal_Int32 nSet)300cdf0e10cSrcweir void MiscCfg::SetYear2000( sal_Int32 nSet )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 	pImpl->SetYear2000( nSet );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307