Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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>
27 :
28 : #include <itemholder1.hxx>
29 :
30 : //_________________________________________________________________________________________________________________
31 : // namespaces
32 : //_________________________________________________________________________________________________________________
33 :
34 : using namespace ::utl ;
35 : using namespace ::rtl ;
36 : using namespace ::osl ;
37 : using namespace ::com::sun::star::uno ;
38 :
39 : #define ROOTNODE_START OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Print"))
40 :
41 : #define PROPERTYNAME_PAPERSIZE OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/PaperSize"))
42 : #define PROPERTYNAME_PAPERORIENTATION OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/PaperOrientation"))
43 : #define PROPERTYNAME_NOTFOUND OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/NotFound"))
44 : #define PROPERTYNAME_TRANSPARENCY OUString(RTL_CONSTASCII_USTRINGPARAM("Warning/Transparency"))
45 : #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT OUString(RTL_CONSTASCII_USTRINGPARAM("PrintingModifiesDocument"))
46 :
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
52 :
53 : #define PROPERTYCOUNT 5
54 :
55 : class SvtPrintWarningOptions_Impl : public ConfigItem
56 : {
57 : public:
58 :
59 : //---------------------------------------------------------------------------------------------------------
60 : // constructor / destructor
61 : //---------------------------------------------------------------------------------------------------------
62 :
63 : SvtPrintWarningOptions_Impl();
64 : ~SvtPrintWarningOptions_Impl();
65 :
66 : //---------------------------------------------------------------------------------------------------------
67 : // overloaded methods of baseclass
68 : //---------------------------------------------------------------------------------------------------------
69 :
70 : virtual void Commit();
71 : virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
72 :
73 : //---------------------------------------------------------------------------------------------------------
74 : // public interface
75 : //---------------------------------------------------------------------------------------------------------
76 :
77 0 : sal_Bool IsPaperSize() const { return m_bPaperSize; }
78 0 : sal_Bool IsPaperOrientation() const { return m_bPaperOrientation; }
79 : sal_Bool IsNotFound() const { return m_bNotFound; }
80 0 : sal_Bool IsTransparency() const { return m_bTransparency; }
81 0 : sal_Bool IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed; }
82 :
83 0 : void SetPaperSize( sal_Bool bState ) { m_bPaperSize = bState; SetModified(); }
84 0 : void SetPaperOrientation( sal_Bool bState ) { m_bPaperOrientation = bState; SetModified(); }
85 : void SetNotFound( sal_Bool bState ) { m_bNotFound = bState; SetModified(); }
86 0 : void SetTransparency( sal_Bool bState ) { m_bTransparency = bState; SetModified(); }
87 0 : void SetModifyDocumentOnPrintingAllowed( sal_Bool bState ) { m_bModifyDocumentOnPrintingAllowed = bState; SetModified(); }
88 :
89 : //-------------------------------------------------------------------------------------------------------------
90 : // private methods
91 : //-------------------------------------------------------------------------------------------------------------
92 :
93 : private:
94 :
95 : static Sequence< OUString > impl_GetPropertyNames();
96 :
97 : //-------------------------------------------------------------------------------------------------------------
98 : // private member
99 : //-------------------------------------------------------------------------------------------------------------
100 :
101 : private:
102 :
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;
108 : };
109 :
110 : //*****************************************************************************************************************
111 : // constructor
112 : //*****************************************************************************************************************
113 0 : 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 0 : m_bModifyDocumentOnPrintingAllowed( sal_True )
120 : {
121 0 : Sequence< OUString > seqNames( impl_GetPropertyNames() );
122 0 : Sequence< Any > seqValues( GetProperties( seqNames ) );
123 :
124 : DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
125 :
126 : // Copy values from list in right order to our internal member.
127 0 : sal_Int32 nPropertyCount = seqValues.getLength();
128 0 : sal_Int32 nProperty = 0;
129 :
130 0 : for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
131 : {
132 : DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
133 :
134 0 : switch( nProperty )
135 : {
136 : case PROPERTYHANDLE_PAPERSIZE:
137 : {
138 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
139 0 : seqValues[nProperty] >>= m_bPaperSize;
140 : }
141 0 : break;
142 :
143 : case PROPERTYHANDLE_PAPERORIENTATION:
144 : {
145 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
146 0 : seqValues[nProperty] >>= m_bPaperOrientation;
147 : }
148 0 : break;
149 :
150 : case PROPERTYHANDLE_NOTFOUND:
151 : {
152 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
153 0 : seqValues[nProperty] >>= m_bNotFound;
154 : }
155 0 : break;
156 :
157 : case PROPERTYHANDLE_TRANSPARENCY:
158 : {
159 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
160 0 : seqValues[nProperty] >>= m_bTransparency;
161 : }
162 0 : break;
163 : case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
164 : {
165 : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
166 0 : seqValues[nProperty] >>= m_bModifyDocumentOnPrintingAllowed;
167 : }
168 0 : break;
169 :
170 : }
171 0 : }
172 0 : }
173 :
174 : //*****************************************************************************************************************
175 : // destructor
176 : //*****************************************************************************************************************
177 0 : SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
178 : {
179 0 : if( IsModified() )
180 0 : Commit();
181 0 : }
182 :
183 : //*****************************************************************************************************************
184 : // Commit
185 : //*****************************************************************************************************************
186 0 : void SvtPrintWarningOptions_Impl::Commit()
187 : {
188 0 : Sequence< OUString > aSeqNames( impl_GetPropertyNames() );
189 0 : Sequence< Any > aSeqValues( aSeqNames.getLength() );
190 :
191 0 : for( sal_Int32 nProperty = 0, nCount = aSeqNames.getLength(); nProperty < nCount; ++nProperty )
192 : {
193 0 : switch( nProperty )
194 : {
195 : case PROPERTYHANDLE_PAPERSIZE:
196 0 : aSeqValues[nProperty] <<= m_bPaperSize;
197 0 : break;
198 :
199 : case PROPERTYHANDLE_PAPERORIENTATION:
200 0 : aSeqValues[nProperty] <<= m_bPaperOrientation;
201 0 : break;
202 :
203 : case PROPERTYHANDLE_NOTFOUND:
204 0 : aSeqValues[nProperty] <<= m_bNotFound;
205 0 : break;
206 :
207 : case PROPERTYHANDLE_TRANSPARENCY:
208 0 : aSeqValues[nProperty] <<= m_bTransparency;
209 0 : break;
210 : case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
211 0 : aSeqValues[nProperty] <<= m_bModifyDocumentOnPrintingAllowed;
212 0 : break;
213 : }
214 : }
215 :
216 0 : PutProperties( aSeqNames, aSeqValues );
217 0 : }
218 :
219 0 : void SvtPrintWarningOptions_Impl::Notify( const Sequence< rtl::OUString >& )
220 : {
221 0 : }
222 :
223 : //*****************************************************************************************************************
224 : // private method
225 : //*****************************************************************************************************************
226 0 : Sequence< OUString > SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
227 : {
228 : // Build list of configuration key names.
229 : const OUString pProperties[] =
230 : {
231 : PROPERTYNAME_PAPERSIZE,
232 : PROPERTYNAME_PAPERORIENTATION,
233 : PROPERTYNAME_NOTFOUND,
234 : PROPERTYNAME_TRANSPARENCY,
235 : PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
236 0 : };
237 :
238 : // Initialize return sequence with these list ...
239 0 : const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
240 :
241 0 : return seqPropertyNames;
242 : }
243 :
244 : //*****************************************************************************************************************
245 : // initialize static member
246 : // DON'T DO IT IN YOUR HEADER!
247 : // see definition for further informations
248 : //*****************************************************************************************************************
249 : SvtPrintWarningOptions_Impl* SvtPrintWarningOptions::m_pDataContainer = NULL;
250 : sal_Int32 SvtPrintWarningOptions::m_nRefCount = 0;
251 :
252 : //*****************************************************************************************************************
253 : // constructor
254 : //*****************************************************************************************************************
255 0 : SvtPrintWarningOptions::SvtPrintWarningOptions()
256 : {
257 : // Global access, must be guarded (multithreading!).
258 0 : MutexGuard aGuard( GetOwnStaticMutex() );
259 : // Increase ouer refcount ...
260 0 : ++m_nRefCount;
261 : // ... and initialize ouer data container only if it not already!
262 0 : if( m_pDataContainer == NULL )
263 : {
264 0 : m_pDataContainer = new SvtPrintWarningOptions_Impl();
265 0 : ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS);
266 0 : }
267 0 : }
268 :
269 : //*****************************************************************************************************************
270 : // destructor
271 : //*****************************************************************************************************************
272 0 : SvtPrintWarningOptions::~SvtPrintWarningOptions()
273 : {
274 : // Global access, must be guarded (multithreading!)
275 0 : MutexGuard aGuard( GetOwnStaticMutex() );
276 : // Decrease ouer refcount.
277 0 : --m_nRefCount;
278 : // If last instance was deleted ...
279 : // we must destroy ouer static data container!
280 0 : if( m_nRefCount <= 0 )
281 : {
282 0 : delete m_pDataContainer;
283 0 : m_pDataContainer = NULL;
284 0 : }
285 0 : }
286 :
287 : //*****************************************************************************************************************
288 : // public method
289 : //*****************************************************************************************************************
290 0 : sal_Bool SvtPrintWarningOptions::IsPaperSize() const
291 : {
292 0 : MutexGuard aGuard( GetOwnStaticMutex() );
293 0 : return m_pDataContainer->IsPaperSize();
294 : }
295 :
296 : //*****************************************************************************************************************
297 : // public method
298 : //*****************************************************************************************************************
299 0 : sal_Bool SvtPrintWarningOptions::IsPaperOrientation() const
300 : {
301 0 : MutexGuard aGuard( GetOwnStaticMutex() );
302 0 : return m_pDataContainer->IsPaperOrientation();
303 : }
304 :
305 : //*****************************************************************************************************************
306 : // public method
307 : //*****************************************************************************************************************
308 0 : sal_Bool SvtPrintWarningOptions::IsTransparency() const
309 : {
310 0 : MutexGuard aGuard( GetOwnStaticMutex() );
311 0 : return m_pDataContainer->IsTransparency();
312 : }
313 :
314 : //*****************************************************************************************************************
315 : // public method
316 : //*****************************************************************************************************************
317 0 : void SvtPrintWarningOptions::SetPaperSize( sal_Bool bState )
318 : {
319 0 : MutexGuard aGuard( GetOwnStaticMutex() );
320 0 : m_pDataContainer->SetPaperSize( bState );
321 0 : }
322 :
323 : //*****************************************************************************************************************
324 : // public method
325 : //*****************************************************************************************************************
326 0 : void SvtPrintWarningOptions::SetPaperOrientation( sal_Bool bState )
327 : {
328 0 : MutexGuard aGuard( GetOwnStaticMutex() );
329 0 : m_pDataContainer->SetPaperOrientation( bState );
330 0 : }
331 :
332 : //*****************************************************************************************************************
333 : // public method
334 : //*****************************************************************************************************************
335 0 : void SvtPrintWarningOptions::SetTransparency( sal_Bool bState )
336 : {
337 0 : MutexGuard aGuard( GetOwnStaticMutex() );
338 0 : m_pDataContainer->SetTransparency( bState );
339 0 : }
340 : // -----------------------------------------------------------------------------
341 :
342 0 : sal_Bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
343 : {
344 0 : MutexGuard aGuard( GetOwnStaticMutex() );
345 0 : return m_pDataContainer->IsModifyDocumentOnPrintingAllowed();
346 : }
347 :
348 : // -----------------------------------------------------------------------------
349 :
350 0 : void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( sal_Bool bState )
351 : {
352 0 : MutexGuard aGuard( GetOwnStaticMutex() );
353 0 : m_pDataContainer->SetModifyDocumentOnPrintingAllowed( bState ) ;
354 0 : }
355 :
356 : namespace
357 : {
358 : class thePrintWarningOptionsMutex : public rtl::Static<osl::Mutex, thePrintWarningOptionsMutex>{};
359 : }
360 :
361 : //*****************************************************************************************************************
362 : // private method
363 : //*****************************************************************************************************************
364 0 : Mutex& SvtPrintWarningOptions::GetOwnStaticMutex()
365 : {
366 0 : return thePrintWarningOptionsMutex::get();
367 : }
368 :
369 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|