bump product version to 4.1.6.2
[LibreOffice.git] / unotools / source / config / printwarningoptions.cxx
blob471b4e10f7f4d957798ee42836583d776cf2a718
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <unotools/printwarningoptions.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <unotools/configitem.hxx>
24 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
28 #include <itemholder1.hxx>
30 //_________________________________________________________________________________________________________________
31 // namespaces
32 //_________________________________________________________________________________________________________________
34 using namespace ::utl ;
35 using namespace ::rtl ;
36 using namespace ::osl ;
37 using namespace ::com::sun::star::uno ;
39 #define ROOTNODE_START OUString("Office.Common/Print")
41 #define PROPERTYNAME_PAPERSIZE OUString("Warning/PaperSize")
42 #define PROPERTYNAME_PAPERORIENTATION OUString("Warning/PaperOrientation")
43 #define PROPERTYNAME_NOTFOUND OUString("Warning/NotFound")
44 #define PROPERTYNAME_TRANSPARENCY OUString("Warning/Transparency")
45 #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString("PrintingModifiesDocument")
47 #define PROPERTYHANDLE_PAPERSIZE 0
48 #define PROPERTYHANDLE_PAPERORIENTATION 1
49 #define PROPERTYHANDLE_NOTFOUND 2
50 #define PROPERTYHANDLE_TRANSPARENCY 3
51 #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT 4
53 #define PROPERTYCOUNT 5
55 class SvtPrintWarningOptions_Impl : public ConfigItem
57 public:
59 //---------------------------------------------------------------------------------------------------------
60 // constructor / destructor
61 //---------------------------------------------------------------------------------------------------------
63 SvtPrintWarningOptions_Impl();
64 ~SvtPrintWarningOptions_Impl();
66 //---------------------------------------------------------------------------------------------------------
67 // overloaded methods of baseclass
68 //---------------------------------------------------------------------------------------------------------
70 virtual void Commit();
71 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames );
73 //---------------------------------------------------------------------------------------------------------
74 // public interface
75 //---------------------------------------------------------------------------------------------------------
77 sal_Bool IsPaperSize() const { return m_bPaperSize; }
78 sal_Bool IsPaperOrientation() const { return m_bPaperOrientation; }
79 sal_Bool IsNotFound() const { return m_bNotFound; }
80 sal_Bool IsTransparency() const { return m_bTransparency; }
81 sal_Bool IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed; }
83 void SetPaperSize( sal_Bool bState ) { m_bPaperSize = bState; SetModified(); }
84 void SetPaperOrientation( sal_Bool bState ) { m_bPaperOrientation = bState; SetModified(); }
85 void SetNotFound( sal_Bool bState ) { m_bNotFound = bState; SetModified(); }
86 void SetTransparency( sal_Bool bState ) { m_bTransparency = bState; SetModified(); }
87 void SetModifyDocumentOnPrintingAllowed( sal_Bool bState ) { m_bModifyDocumentOnPrintingAllowed = bState; SetModified(); }
89 //-------------------------------------------------------------------------------------------------------------
90 // private methods
91 //-------------------------------------------------------------------------------------------------------------
93 private:
95 static Sequence< OUString > impl_GetPropertyNames();
97 //-------------------------------------------------------------------------------------------------------------
98 // private member
99 //-------------------------------------------------------------------------------------------------------------
101 private:
103 sal_Bool m_bPaperSize;
104 sal_Bool m_bPaperOrientation;
105 sal_Bool m_bNotFound;
106 sal_Bool m_bTransparency;
107 sal_Bool m_bModifyDocumentOnPrintingAllowed;
110 //*****************************************************************************************************************
111 // constructor
112 //*****************************************************************************************************************
113 SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
114 ConfigItem( ROOTNODE_START ),
115 m_bPaperSize( sal_False ),
116 m_bPaperOrientation( sal_False ),
117 m_bNotFound( sal_False ),
118 m_bTransparency( sal_True ),
119 m_bModifyDocumentOnPrintingAllowed( sal_True )
121 Sequence< OUString > seqNames( impl_GetPropertyNames() );
122 Sequence< Any > seqValues( GetProperties( seqNames ) );
124 DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
126 // Copy values from list in right order to our internal member.
127 sal_Int32 nPropertyCount = seqValues.getLength();
128 sal_Int32 nProperty = 0;
130 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
132 DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
134 switch( nProperty )
136 case PROPERTYHANDLE_PAPERSIZE:
138 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
139 seqValues[nProperty] >>= m_bPaperSize;
141 break;
143 case PROPERTYHANDLE_PAPERORIENTATION:
145 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
146 seqValues[nProperty] >>= m_bPaperOrientation;
148 break;
150 case PROPERTYHANDLE_NOTFOUND:
152 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
153 seqValues[nProperty] >>= m_bNotFound;
155 break;
157 case PROPERTYHANDLE_TRANSPARENCY:
159 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
160 seqValues[nProperty] >>= m_bTransparency;
162 break;
163 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
165 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
166 seqValues[nProperty] >>= m_bModifyDocumentOnPrintingAllowed;
168 break;
174 //*****************************************************************************************************************
175 // destructor
176 //*****************************************************************************************************************
177 SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
179 if( IsModified() )
180 Commit();
183 //*****************************************************************************************************************
184 // Commit
185 //*****************************************************************************************************************
186 void SvtPrintWarningOptions_Impl::Commit()
188 Sequence< OUString > aSeqNames( impl_GetPropertyNames() );
189 Sequence< Any > aSeqValues( aSeqNames.getLength() );
191 for( sal_Int32 nProperty = 0, nCount = aSeqNames.getLength(); nProperty < nCount; ++nProperty )
193 switch( nProperty )
195 case PROPERTYHANDLE_PAPERSIZE:
196 aSeqValues[nProperty] <<= m_bPaperSize;
197 break;
199 case PROPERTYHANDLE_PAPERORIENTATION:
200 aSeqValues[nProperty] <<= m_bPaperOrientation;
201 break;
203 case PROPERTYHANDLE_NOTFOUND:
204 aSeqValues[nProperty] <<= m_bNotFound;
205 break;
207 case PROPERTYHANDLE_TRANSPARENCY:
208 aSeqValues[nProperty] <<= m_bTransparency;
209 break;
210 case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
211 aSeqValues[nProperty] <<= m_bModifyDocumentOnPrintingAllowed;
212 break;
216 PutProperties( aSeqNames, aSeqValues );
219 void SvtPrintWarningOptions_Impl::Notify( const Sequence< OUString >& )
223 //*****************************************************************************************************************
224 // private method
225 //*****************************************************************************************************************
226 Sequence< OUString > SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
228 // Build list of configuration key names.
229 const OUString pProperties[] =
231 PROPERTYNAME_PAPERSIZE,
232 PROPERTYNAME_PAPERORIENTATION,
233 PROPERTYNAME_NOTFOUND,
234 PROPERTYNAME_TRANSPARENCY,
235 PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
238 // Initialize return sequence with these list ...
239 const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
241 return seqPropertyNames;
244 //*****************************************************************************************************************
245 // initialize static member
246 // DON'T DO IT IN YOUR HEADER!
247 // see definition for further information
248 //*****************************************************************************************************************
249 SvtPrintWarningOptions_Impl* SvtPrintWarningOptions::m_pDataContainer = NULL;
250 sal_Int32 SvtPrintWarningOptions::m_nRefCount = 0;
252 //*****************************************************************************************************************
253 // constructor
254 //*****************************************************************************************************************
255 SvtPrintWarningOptions::SvtPrintWarningOptions()
257 // Global access, must be guarded (multithreading!).
258 MutexGuard aGuard( GetOwnStaticMutex() );
259 // Increase ouer refcount ...
260 ++m_nRefCount;
261 // ... and initialize ouer data container only if it not already!
262 if( m_pDataContainer == NULL )
264 m_pDataContainer = new SvtPrintWarningOptions_Impl();
265 ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS);
269 //*****************************************************************************************************************
270 // destructor
271 //*****************************************************************************************************************
272 SvtPrintWarningOptions::~SvtPrintWarningOptions()
274 // Global access, must be guarded (multithreading!)
275 MutexGuard aGuard( GetOwnStaticMutex() );
276 // Decrease ouer refcount.
277 --m_nRefCount;
278 // If last instance was deleted ...
279 // we must destroy ouer static data container!
280 if( m_nRefCount <= 0 )
282 delete m_pDataContainer;
283 m_pDataContainer = NULL;
287 //*****************************************************************************************************************
288 // public method
289 //*****************************************************************************************************************
290 sal_Bool SvtPrintWarningOptions::IsPaperSize() const
292 MutexGuard aGuard( GetOwnStaticMutex() );
293 return m_pDataContainer->IsPaperSize();
296 //*****************************************************************************************************************
297 // public method
298 //*****************************************************************************************************************
299 sal_Bool SvtPrintWarningOptions::IsPaperOrientation() const
301 MutexGuard aGuard( GetOwnStaticMutex() );
302 return m_pDataContainer->IsPaperOrientation();
305 //*****************************************************************************************************************
306 // public method
307 //*****************************************************************************************************************
308 sal_Bool SvtPrintWarningOptions::IsTransparency() const
310 MutexGuard aGuard( GetOwnStaticMutex() );
311 return m_pDataContainer->IsTransparency();
314 //*****************************************************************************************************************
315 // public method
316 //*****************************************************************************************************************
317 void SvtPrintWarningOptions::SetPaperSize( sal_Bool bState )
319 MutexGuard aGuard( GetOwnStaticMutex() );
320 m_pDataContainer->SetPaperSize( bState );
323 //*****************************************************************************************************************
324 // public method
325 //*****************************************************************************************************************
326 void SvtPrintWarningOptions::SetPaperOrientation( sal_Bool bState )
328 MutexGuard aGuard( GetOwnStaticMutex() );
329 m_pDataContainer->SetPaperOrientation( bState );
332 //*****************************************************************************************************************
333 // public method
334 //*****************************************************************************************************************
335 void SvtPrintWarningOptions::SetTransparency( sal_Bool bState )
337 MutexGuard aGuard( GetOwnStaticMutex() );
338 m_pDataContainer->SetTransparency( bState );
340 // -----------------------------------------------------------------------------
342 sal_Bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
344 MutexGuard aGuard( GetOwnStaticMutex() );
345 return m_pDataContainer->IsModifyDocumentOnPrintingAllowed();
348 // -----------------------------------------------------------------------------
350 void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( sal_Bool bState )
352 MutexGuard aGuard( GetOwnStaticMutex() );
353 m_pDataContainer->SetModifyDocumentOnPrintingAllowed( bState ) ;
356 namespace
358 class thePrintWarningOptionsMutex : public rtl::Static<osl::Mutex, thePrintWarningOptionsMutex>{};
361 //*****************************************************************************************************************
362 // private method
363 //*****************************************************************************************************************
364 Mutex& SvtPrintWarningOptions::GetOwnStaticMutex()
366 return thePrintWarningOptionsMutex::get();
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */