Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svtools/printoptions.hxx>
30 : : #include <unotools/configmgr.hxx>
31 : : #include <unotools/configitem.hxx>
32 : : #include <vcl/print.hxx>
33 : : #include <com/sun/star/uno/Any.hxx>
34 : : #include <com/sun/star/uno/Sequence.hxx>
35 : :
36 : : #include <com/sun/star/beans/XPropertySet.hpp>
37 : :
38 : : #include <com/sun/star/container/XNameAccess.hpp>
39 : :
40 : : #include <com/sun/star/container/XNameContainer.hpp>
41 : :
42 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 : :
44 : : #include <comphelper/configurationhelper.hxx>
45 : : #include <comphelper/processfactory.hxx>
46 : : #include <comphelper/string.hxx>
47 : :
48 : : #include <itemholder2.hxx>
49 : :
50 : : #include <sal/macros.h>
51 : : // -----------
52 : : // - statics -
53 : : // -----------
54 : :
55 : : static sal_uInt16 aDPIArray[] = { 72, 96, 150, 200, 300, 600 };
56 : :
57 : : #define DPI_COUNT (SAL_N_ELEMENTS(aDPIArray))
58 : :
59 : : // -----------
60 : : // - Defines -
61 : : // -----------
62 : :
63 : : #define ROOTNODE_START OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Print/Option"))
64 : : #define ROOTNODE_PRINTOPTION OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/Print/Option"))
65 : :
66 : : #define PROPERTYNAME_REDUCETRANSPARENCY OUString(RTL_CONSTASCII_USTRINGPARAM("ReduceTransparency"))
67 : : #define PROPERTYNAME_REDUCEDTRANSPARENCYMODE OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedTransparencyMode"))
68 : : #define PROPERTYNAME_REDUCEGRADIENTS OUString(RTL_CONSTASCII_USTRINGPARAM("ReduceGradients"))
69 : : #define PROPERTYNAME_REDUCEDGRADIENTMODE OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedGradientMode"))
70 : : #define PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedGradientStepCount"))
71 : : #define PROPERTYNAME_REDUCEBITMAPS OUString(RTL_CONSTASCII_USTRINGPARAM("ReduceBitmaps"))
72 : : #define PROPERTYNAME_REDUCEDBITMAPMODE OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedBitmapMode"))
73 : : #define PROPERTYNAME_REDUCEDBITMAPRESOLUTION OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedBitmapResolution"))
74 : : #define PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedBitmapIncludesTransparency"))
75 : : #define PROPERTYNAME_CONVERTTOGREYSCALES OUString(RTL_CONSTASCII_USTRINGPARAM("ConvertToGreyscales"))
76 : :
77 : : // --------------
78 : : // - Namespaces -
79 : : // --------------
80 : :
81 : : using namespace ::utl;
82 : : using namespace ::rtl;
83 : : using namespace ::osl;
84 : : using namespace ::com::sun::star::uno;
85 : : namespace css = com::sun::star;
86 : :
87 : : // -----------
88 : : // - statics -
89 : : // -----------
90 : :
91 : : static SvtPrintOptions_Impl* pPrinterOptionsDataContainer = NULL;
92 : : static SvtPrintOptions_Impl* pPrintFileOptionsDataContainer = NULL;
93 : :
94 : : SvtPrintOptions_Impl* SvtPrinterOptions::m_pStaticDataContainer = NULL;
95 : : sal_Int32 SvtPrinterOptions::m_nRefCount = 0;
96 : :
97 : : SvtPrintOptions_Impl* SvtPrintFileOptions::m_pStaticDataContainer = NULL;
98 : : sal_Int32 SvtPrintFileOptions::m_nRefCount = 0;
99 : :
100 : : // ------------------------
101 : : // - SvtPrintOptions_Impl -
102 : : // ------------------------
103 : :
104 : : class SvtPrintOptions_Impl
105 : : {
106 : : public:
107 : :
108 : : //---------------------------------------------------------------------------------------------------------
109 : : // constructor / destructor
110 : : //---------------------------------------------------------------------------------------------------------
111 : :
112 : : SvtPrintOptions_Impl( const OUString& rConfigRoot );
113 : : ~SvtPrintOptions_Impl();
114 : :
115 : : //---------------------------------------------------------------------------------------------------------
116 : : // public interface
117 : : //---------------------------------------------------------------------------------------------------------
118 : :
119 : : sal_Bool IsReduceTransparency() const ;
120 : : sal_Int16 GetReducedTransparencyMode() const ;
121 : : sal_Bool IsReduceGradients() const ;
122 : : sal_Int16 GetReducedGradientMode() const ;
123 : : sal_Int16 GetReducedGradientStepCount() const ;
124 : : sal_Bool IsReduceBitmaps() const ;
125 : : sal_Int16 GetReducedBitmapMode() const ;
126 : : sal_Int16 GetReducedBitmapResolution() const ;
127 : : sal_Bool IsReducedBitmapIncludesTransparency() const ;
128 : : sal_Bool IsConvertToGreyscales() const;
129 : :
130 : : void SetReduceTransparency( sal_Bool bState ) ;
131 : : void SetReducedTransparencyMode( sal_Int16 nMode ) ;
132 : : void SetReduceGradients( sal_Bool bState ) ;
133 : : void SetReducedGradientMode( sal_Int16 nMode ) ;
134 : : void SetReducedGradientStepCount( sal_Int16 nStepCount ) ;
135 : : void SetReduceBitmaps( sal_Bool bState ) ;
136 : : void SetReducedBitmapMode( sal_Int16 nMode ) ;
137 : : void SetReducedBitmapResolution( sal_Int16 nResolution ) ;
138 : : void SetReducedBitmapIncludesTransparency( sal_Bool bState ) ;
139 : : void SetConvertToGreyscales( sal_Bool bState ) ;
140 : :
141 : : //-------------------------------------------------------------------------------------------------------------
142 : : // private API
143 : : //-------------------------------------------------------------------------------------------------------------
144 : :
145 : : private:
146 : : void impl_setValue (const ::rtl::OUString& sProp,
147 : : ::sal_Bool bNew );
148 : : void impl_setValue (const ::rtl::OUString& sProp,
149 : : ::sal_Int16 nNew );
150 : :
151 : : //-------------------------------------------------------------------------------------------------------------
152 : : // private member
153 : : //-------------------------------------------------------------------------------------------------------------
154 : :
155 : : private:
156 : : css::uno::Reference< css::container::XNameAccess > m_xCfg;
157 : : css::uno::Reference< css::container::XNameAccess > m_xNode;
158 : : };
159 : :
160 : 0 : SvtPrintOptions_Impl::SvtPrintOptions_Impl(const OUString& rConfigRoot)
161 : : {
162 : : try
163 : : {
164 : : m_xCfg = css::uno::Reference< css::container::XNameAccess >(
165 : : ::comphelper::ConfigurationHelper::openConfig(
166 : : comphelper::getProcessServiceFactory(),
167 : : ROOTNODE_PRINTOPTION,
168 : : ::comphelper::ConfigurationHelper::E_STANDARD),
169 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY);
[ # # ][ # # ]
[ # # ]
170 : :
171 [ # # ]: 0 : if (m_xCfg.is())
172 : : {
173 : : using comphelper::string::getTokenCount;
174 : : using comphelper::string::getToken;
175 [ # # ]: 0 : sal_Int32 nTokenCount = getTokenCount(rConfigRoot, '/');
176 : 0 : rtl::OUString sTok = getToken(rConfigRoot, nTokenCount - 1, '/');
177 [ # # ][ # # ]: 0 : m_xCfg->getByName(sTok) >>= m_xNode;
[ # # ][ # # ]
178 : : }
179 : : }
180 [ # # ]: 0 : catch (const css::uno::Exception& ex)
181 : : {
182 : 0 : m_xNode.clear();
183 : 0 : m_xCfg.clear();
184 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
185 : : }
186 : 0 : }
187 : :
188 : 0 : sal_Bool SvtPrintOptions_Impl::IsReduceTransparency() const
189 : : {
190 : 0 : sal_Bool bRet = sal_False;
191 : : try
192 : : {
193 [ # # ]: 0 : if (m_xNode.is())
194 : : {
195 [ # # ]: 0 : css::uno::Reference< css::beans::XPropertySet > xSet(m_xNode, css::uno::UNO_QUERY);
196 [ # # ]: 0 : if (xSet.is())
197 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCETRANSPARENCY) >>= bRet;
[ # # ][ # # ]
198 : : }
199 : : }
200 [ # # ]: 0 : catch (const css::uno::Exception& ex)
201 : : {
202 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
203 : : }
204 : :
205 : 0 : return bRet;
206 : : }
207 : :
208 : 0 : sal_Int16 SvtPrintOptions_Impl::GetReducedTransparencyMode() const
209 : : {
210 : 0 : sal_Int16 nRet = 0;
211 : : try
212 : : {
213 [ # # ]: 0 : if (m_xNode.is())
214 : : {
215 [ # # ]: 0 : css::uno::Reference< css::beans::XPropertySet > xSet(m_xNode, css::uno::UNO_QUERY);
216 [ # # ]: 0 : if (xSet.is())
217 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEDTRANSPARENCYMODE) >>= nRet;
[ # # ][ # # ]
218 : : }
219 : : }
220 [ # # ]: 0 : catch (const css::uno::Exception& ex)
221 : : {
222 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
223 : : }
224 : :
225 : 0 : return nRet;
226 : : }
227 : :
228 : 0 : sal_Bool SvtPrintOptions_Impl::IsReduceGradients() const
229 : : {
230 : 0 : sal_Bool bRet = sal_False;
231 : : try
232 : : {
233 [ # # ]: 0 : if (m_xNode.is())
234 : : {
235 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
236 [ # # ]: 0 : if (xSet.is())
237 : : {
238 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEGRADIENTS) >>= bRet;
[ # # ]
239 [ # # ]: 0 : }
240 : : }
241 : : }
242 [ # # ]: 0 : catch (const css::uno::Exception& ex)
243 : : {
244 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
245 : : }
246 : :
247 : 0 : return bRet;
248 : : }
249 : :
250 : 0 : sal_Int16 SvtPrintOptions_Impl::GetReducedGradientMode() const
251 : : {
252 : 0 : sal_Int16 nRet = 0;
253 : : try
254 : : {
255 [ # # ]: 0 : if (m_xNode.is())
256 : : {
257 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
258 [ # # ]: 0 : if (xSet.is())
259 : : {
260 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTMODE) >>= nRet;
[ # # ]
261 [ # # ]: 0 : }
262 : : }
263 : : }
264 [ # # ]: 0 : catch (const css::uno::Exception& ex)
265 : : {
266 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
267 : : }
268 : :
269 : 0 : return nRet;
270 : : }
271 : :
272 : 0 : sal_Int16 SvtPrintOptions_Impl::GetReducedGradientStepCount() const
273 : : {
274 : 0 : sal_Int16 nRet = 64;
275 : : try
276 : : {
277 [ # # ]: 0 : if (m_xNode.is())
278 : : {
279 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
280 [ # # ]: 0 : if (xSet.is())
281 : : {
282 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT) >>= nRet;
[ # # ]
283 [ # # ]: 0 : }
284 : : }
285 : : }
286 [ # # ]: 0 : catch (const css::uno::Exception& ex)
287 : : {
288 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
289 : : }
290 : :
291 : 0 : return nRet;
292 : : }
293 : :
294 : 0 : sal_Bool SvtPrintOptions_Impl::IsReduceBitmaps() const
295 : : {
296 : 0 : sal_Bool bRet = sal_False;
297 : : try
298 : : {
299 [ # # ]: 0 : if (m_xNode.is())
300 : : {
301 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
302 [ # # ]: 0 : if (xSet.is())
303 : : {
304 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEBITMAPS) >>= bRet;
[ # # ]
305 [ # # ]: 0 : }
306 : : }
307 : : }
308 [ # # ]: 0 : catch (const css::uno::Exception& ex)
309 : : {
310 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
311 : : }
312 : :
313 : 0 : return bRet;
314 : : }
315 : :
316 : 0 : sal_Int16 SvtPrintOptions_Impl::GetReducedBitmapMode() const
317 : : {
318 : 0 : sal_Int16 nRet = 1;
319 : : try
320 : : {
321 [ # # ]: 0 : if (m_xNode.is())
322 : : {
323 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
324 [ # # ]: 0 : if (xSet.is())
325 : : {
326 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPMODE) >>= nRet;
[ # # ]
327 [ # # ]: 0 : }
328 : : }
329 : : }
330 [ # # ]: 0 : catch (const css::uno::Exception& ex)
331 : : {
332 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
333 : : }
334 : :
335 : 0 : return nRet;
336 : : }
337 : :
338 : 0 : sal_Int16 SvtPrintOptions_Impl::GetReducedBitmapResolution() const
339 : : {
340 : 0 : sal_Int16 nRet = 3;
341 : : try
342 : : {
343 [ # # ]: 0 : if (m_xNode.is())
344 : : {
345 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
346 [ # # ]: 0 : if (xSet.is())
347 : : {
348 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPRESOLUTION) >>= nRet;
[ # # ]
349 [ # # ]: 0 : }
350 : : }
351 : : }
352 [ # # ]: 0 : catch (const css::uno::Exception& ex)
353 : : {
354 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
355 : : }
356 : :
357 : 0 : return nRet;
358 : : }
359 : :
360 : 0 : sal_Bool SvtPrintOptions_Impl::IsReducedBitmapIncludesTransparency() const
361 : : {
362 : 0 : sal_Bool bRet = sal_True;
363 : : try
364 : : {
365 [ # # ]: 0 : if (m_xNode.is())
366 : : {
367 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
368 [ # # ]: 0 : if (xSet.is())
369 : : {
370 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY) >>= bRet;
[ # # ]
371 [ # # ]: 0 : }
372 : : }
373 : : }
374 [ # # ]: 0 : catch (const css::uno::Exception& ex)
375 : : {
376 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
377 : : }
378 : :
379 : 0 : return bRet;
380 : : }
381 : :
382 : 0 : sal_Bool SvtPrintOptions_Impl::IsConvertToGreyscales() const
383 : : {
384 : 0 : sal_Bool bRet = sal_False;
385 : : try
386 : : {
387 [ # # ]: 0 : if (m_xNode.is())
388 : : {
389 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
390 [ # # ]: 0 : if (xSet.is())
391 : : {
392 [ # # ][ # # ]: 0 : xSet->getPropertyValue(PROPERTYNAME_CONVERTTOGREYSCALES) >>= bRet;
[ # # ]
393 [ # # ]: 0 : }
394 : : }
395 : : }
396 [ # # ]: 0 : catch (const css::uno::Exception& ex)
397 : : {
398 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
399 : : }
400 : :
401 : 0 : return bRet;
402 : :
403 : : }
404 : :
405 : 0 : void SvtPrintOptions_Impl::SetReduceTransparency(sal_Bool bState)
406 : : {
407 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCETRANSPARENCY, bState);
408 : 0 : }
409 : :
410 : 0 : void SvtPrintOptions_Impl::SetReducedTransparencyMode(sal_Int16 nMode)
411 : : {
412 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEDTRANSPARENCYMODE, nMode);
413 : 0 : }
414 : :
415 : 0 : void SvtPrintOptions_Impl::SetReduceGradients(sal_Bool bState)
416 : : {
417 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEGRADIENTS, bState);
418 : 0 : }
419 : :
420 : 0 : void SvtPrintOptions_Impl::SetReducedGradientMode(sal_Int16 nMode)
421 : : {
422 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEDGRADIENTMODE, nMode);
423 : 0 : }
424 : :
425 : 0 : void SvtPrintOptions_Impl::SetReducedGradientStepCount(sal_Int16 nStepCount )
426 : : {
427 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT, nStepCount);
428 : 0 : }
429 : :
430 : 0 : void SvtPrintOptions_Impl::SetReduceBitmaps(sal_Bool bState )
431 : : {
432 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEBITMAPS, bState);
433 : 0 : }
434 : :
435 : 0 : void SvtPrintOptions_Impl::SetReducedBitmapMode(sal_Int16 nMode )
436 : : {
437 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEDBITMAPMODE, nMode);
438 : 0 : }
439 : :
440 : 0 : void SvtPrintOptions_Impl::SetReducedBitmapResolution(sal_Int16 nResolution )
441 : : {
442 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEDBITMAPRESOLUTION, nResolution);
443 : 0 : }
444 : :
445 : 0 : void SvtPrintOptions_Impl::SetReducedBitmapIncludesTransparency(sal_Bool bState )
446 : : {
447 [ # # ]: 0 : impl_setValue(PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY, bState);
448 : 0 : }
449 : :
450 : 0 : void SvtPrintOptions_Impl::SetConvertToGreyscales(sal_Bool bState)
451 : : {
452 [ # # ]: 0 : impl_setValue(PROPERTYNAME_CONVERTTOGREYSCALES, bState);
453 : 0 : }
454 : :
455 : 0 : SvtPrintOptions_Impl::~SvtPrintOptions_Impl()
456 : : {
457 : 0 : m_xNode.clear();
458 : 0 : m_xCfg.clear();
459 : 0 : }
460 : :
461 : 0 : void SvtPrintOptions_Impl::impl_setValue (const ::rtl::OUString& sProp,
462 : : ::sal_Bool bNew )
463 : : {
464 : : try
465 : : {
466 [ # # ]: 0 : if ( ! m_xNode.is())
467 : : return;
468 : :
469 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
470 [ # # ]: 0 : if ( ! xSet.is())
471 : : return;
472 : :
473 : 0 : ::sal_Bool bOld = ! bNew;
474 [ # # ][ # # ]: 0 : if ( ! (xSet->getPropertyValue(sProp) >>= bOld))
[ # # ]
475 : : return;
476 : :
477 [ # # ]: 0 : if (bOld != bNew)
478 : : {
479 [ # # ][ # # ]: 0 : xSet->setPropertyValue(sProp, css::uno::makeAny(bNew));
[ # # ]
480 [ # # ]: 0 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
481 [ # # ][ # # ]: 0 : }
482 : : }
483 : 0 : catch(const css::uno::Exception& ex)
484 : : {
485 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
486 : : }
487 : : }
488 : :
489 : 0 : void SvtPrintOptions_Impl::impl_setValue (const ::rtl::OUString& sProp,
490 : : ::sal_Int16 nNew )
491 : : {
492 : : try
493 : : {
494 [ # # ]: 0 : if ( ! m_xNode.is())
495 : : return;
496 : :
497 [ # # ]: 0 : css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY);
498 [ # # ]: 0 : if ( ! xSet.is())
499 : : return;
500 : :
501 : 0 : ::sal_Int16 nOld = nNew+1;
502 [ # # ][ # # ]: 0 : if ( ! (xSet->getPropertyValue(sProp) >>= nOld))
[ # # ]
503 : : return;
504 : :
505 [ # # ]: 0 : if (nOld != nNew)
506 : : {
507 [ # # ][ # # ]: 0 : xSet->setPropertyValue(sProp, css::uno::makeAny(nNew));
[ # # ]
508 [ # # ]: 0 : ::comphelper::ConfigurationHelper::flush(m_xCfg);
509 [ # # ][ # # ]: 0 : }
510 : : }
511 : 0 : catch(const css::uno::Exception& ex)
512 : : {
513 : : SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
514 : : }
515 : : }
516 : :
517 : : // -----------------------------------------------------------------------------
518 : :
519 : :
520 : : // -----------------------
521 : : // - SvtBasePrintOptions -
522 : : // -----------------------
523 : :
524 : 0 : SvtBasePrintOptions::SvtBasePrintOptions()
525 : : {
526 : 0 : }
527 : :
528 : : // -----------------------------------------------------------------------------
529 : :
530 : 0 : SvtBasePrintOptions::~SvtBasePrintOptions()
531 : : {
532 [ # # ]: 0 : }
533 : :
534 : : // -----------------------------------------------------------------------------
535 : :
536 : 0 : Mutex& SvtBasePrintOptions::GetOwnStaticMutex()
537 : : {
538 : : // Initialize static mutex only for one time!
539 : : static Mutex* pMutex = NULL;
540 : : // If these method first called (Mutex not already exist!) ...
541 [ # # ]: 0 : if( pMutex == NULL )
542 : : {
543 : : // ... we must create a new one. Protect follow code with the global mutex -
544 : : // It must be - we create a static variable!
545 [ # # ][ # # ]: 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
546 : : // We must check our pointer again - because it can be that another instance of our class will be fastr then these!
547 [ # # ]: 0 : if( pMutex == NULL )
548 : : {
549 : : // Create the new mutex and set it for return on static variable.
550 [ # # ][ # # ]: 0 : static Mutex aMutex;
[ # # ][ # # ]
551 : 0 : pMutex = &aMutex;
552 [ # # ]: 0 : }
553 : : }
554 : : // Return new created or already existing mutex object.
555 : 0 : return *pMutex;
556 : : }
557 : :
558 : : // -----------------------------------------------------------------------------
559 : :
560 : 0 : sal_Bool SvtBasePrintOptions::IsReduceTransparency() const
561 : : {
562 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
563 [ # # ][ # # ]: 0 : return m_pDataContainer->IsReduceTransparency();
564 : : }
565 : :
566 : : // -----------------------------------------------------------------------------
567 : :
568 : 0 : sal_Int16 SvtBasePrintOptions::GetReducedTransparencyMode() const
569 : : {
570 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
571 [ # # ][ # # ]: 0 : return m_pDataContainer->GetReducedTransparencyMode();
572 : : }
573 : :
574 : : // -----------------------------------------------------------------------------
575 : :
576 : 0 : sal_Bool SvtBasePrintOptions::IsReduceGradients() const
577 : : {
578 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
579 [ # # ][ # # ]: 0 : return m_pDataContainer->IsReduceGradients();
580 : : }
581 : :
582 : : // -----------------------------------------------------------------------------
583 : :
584 : 0 : sal_Int16 SvtBasePrintOptions::GetReducedGradientMode() const
585 : : {
586 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
587 [ # # ][ # # ]: 0 : return m_pDataContainer->GetReducedGradientMode();
588 : : }
589 : :
590 : : // -----------------------------------------------------------------------------
591 : :
592 : 0 : sal_Int16 SvtBasePrintOptions::GetReducedGradientStepCount() const
593 : : {
594 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
595 [ # # ][ # # ]: 0 : return m_pDataContainer->GetReducedGradientStepCount();
596 : : }
597 : :
598 : : // -----------------------------------------------------------------------------
599 : :
600 : 0 : sal_Bool SvtBasePrintOptions::IsReduceBitmaps() const
601 : : {
602 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
603 [ # # ][ # # ]: 0 : return m_pDataContainer->IsReduceBitmaps();
604 : : }
605 : :
606 : : // -----------------------------------------------------------------------------
607 : :
608 : 0 : sal_Int16 SvtBasePrintOptions::GetReducedBitmapMode() const
609 : : {
610 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
611 [ # # ][ # # ]: 0 : return m_pDataContainer->GetReducedBitmapMode();
612 : : }
613 : :
614 : : // -----------------------------------------------------------------------------
615 : :
616 : 0 : sal_Int16 SvtBasePrintOptions::GetReducedBitmapResolution() const
617 : : {
618 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
619 [ # # ][ # # ]: 0 : return m_pDataContainer->GetReducedBitmapResolution();
620 : : }
621 : :
622 : : // -----------------------------------------------------------------------------
623 : :
624 : 0 : sal_Bool SvtBasePrintOptions::IsReducedBitmapIncludesTransparency() const
625 : : {
626 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
627 [ # # ][ # # ]: 0 : return m_pDataContainer->IsReducedBitmapIncludesTransparency();
628 : : }
629 : :
630 : : // -----------------------------------------------------------------------------
631 : :
632 : 0 : sal_Bool SvtBasePrintOptions::IsConvertToGreyscales() const
633 : : {
634 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
635 [ # # ][ # # ]: 0 : return m_pDataContainer->IsConvertToGreyscales();
636 : : }
637 : :
638 : : // -----------------------------------------------------------------------------
639 : :
640 : 0 : void SvtBasePrintOptions::SetReduceTransparency( sal_Bool bState )
641 : : {
642 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
643 [ # # ][ # # ]: 0 : m_pDataContainer->SetReduceTransparency( bState ) ;
644 : 0 : }
645 : :
646 : : // -----------------------------------------------------------------------------
647 : :
648 : 0 : void SvtBasePrintOptions::SetReducedTransparencyMode( sal_Int16 nMode )
649 : : {
650 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
651 [ # # ][ # # ]: 0 : m_pDataContainer->SetReducedTransparencyMode( nMode );
652 : 0 : }
653 : :
654 : : // -----------------------------------------------------------------------------
655 : :
656 : 0 : void SvtBasePrintOptions::SetReduceGradients( sal_Bool bState )
657 : : {
658 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
659 [ # # ][ # # ]: 0 : m_pDataContainer->SetReduceGradients( bState );
660 : 0 : }
661 : :
662 : : // -----------------------------------------------------------------------------
663 : :
664 : 0 : void SvtBasePrintOptions::SetReducedGradientMode( sal_Int16 nMode )
665 : : {
666 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
667 [ # # ][ # # ]: 0 : m_pDataContainer->SetReducedGradientMode( nMode );
668 : 0 : }
669 : :
670 : : // -----------------------------------------------------------------------------
671 : :
672 : 0 : void SvtBasePrintOptions::SetReducedGradientStepCount( sal_Int16 nStepCount )
673 : : {
674 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
675 [ # # ][ # # ]: 0 : m_pDataContainer->SetReducedGradientStepCount( nStepCount );
676 : 0 : }
677 : :
678 : : // -----------------------------------------------------------------------------
679 : :
680 : 0 : void SvtBasePrintOptions::SetReduceBitmaps( sal_Bool bState )
681 : : {
682 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
683 [ # # ][ # # ]: 0 : m_pDataContainer->SetReduceBitmaps( bState );
684 : 0 : }
685 : :
686 : : // -----------------------------------------------------------------------------
687 : :
688 : 0 : void SvtBasePrintOptions::SetReducedBitmapMode( sal_Int16 nMode )
689 : : {
690 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
691 [ # # ][ # # ]: 0 : m_pDataContainer->SetReducedBitmapMode( nMode );
692 : 0 : }
693 : :
694 : : // -----------------------------------------------------------------------------
695 : :
696 : 0 : void SvtBasePrintOptions::SetReducedBitmapResolution( sal_Int16 nResolution )
697 : : {
698 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
699 [ # # ][ # # ]: 0 : m_pDataContainer->SetReducedBitmapResolution( nResolution );
700 : 0 : }
701 : :
702 : : // -----------------------------------------------------------------------------
703 : :
704 : 0 : void SvtBasePrintOptions::SetReducedBitmapIncludesTransparency( sal_Bool bState )
705 : : {
706 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
707 [ # # ][ # # ]: 0 : m_pDataContainer->SetReducedBitmapIncludesTransparency( bState );
708 : 0 : }
709 : :
710 : : // -----------------------------------------------------------------------------
711 : :
712 : 0 : void SvtBasePrintOptions::SetConvertToGreyscales( sal_Bool bState )
713 : : {
714 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
715 [ # # ][ # # ]: 0 : m_pDataContainer->SetConvertToGreyscales( bState );
716 : 0 : }
717 : :
718 : : // -----------------------------------------------------------------------------
719 : :
720 : 0 : void SvtBasePrintOptions::GetPrinterOptions( PrinterOptions& rOptions ) const
721 : : {
722 : 0 : rOptions.SetReduceTransparency( IsReduceTransparency() );
723 : 0 : rOptions.SetReducedTransparencyMode( (PrinterTransparencyMode) GetReducedTransparencyMode() );
724 : 0 : rOptions.SetReduceGradients( IsReduceGradients() );
725 : 0 : rOptions.SetReducedGradientMode( (PrinterGradientMode) GetReducedGradientMode() );
726 : 0 : rOptions.SetReducedGradientStepCount( GetReducedGradientStepCount() );
727 : 0 : rOptions.SetReduceBitmaps( IsReduceBitmaps() );
728 : 0 : rOptions.SetReducedBitmapMode( (PrinterBitmapMode) GetReducedBitmapMode() );
729 : 0 : rOptions.SetReducedBitmapResolution( aDPIArray[ Min( (sal_uInt16) GetReducedBitmapResolution(), (sal_uInt16)( DPI_COUNT - 1 ) ) ] );
730 : 0 : rOptions.SetReducedBitmapIncludesTransparency( IsReducedBitmapIncludesTransparency() );
731 : 0 : rOptions.SetConvertToGreyscales( IsConvertToGreyscales() );
732 : 0 : }
733 : :
734 : : // -----------------------------------------------------------------------------
735 : :
736 : 0 : void SvtBasePrintOptions::SetPrinterOptions( const PrinterOptions& rOptions )
737 : : {
738 : 0 : SetReduceTransparency( rOptions.IsReduceTransparency() );
739 : : SetReducedTransparencyMode(
740 : : sal::static_int_cast< sal_Int16 >(
741 : 0 : rOptions.GetReducedTransparencyMode()) );
742 : 0 : SetReduceGradients( rOptions.IsReduceGradients() );
743 : : SetReducedGradientMode(
744 : 0 : sal::static_int_cast< sal_Int16 >(rOptions.GetReducedGradientMode()) );
745 : 0 : SetReducedGradientStepCount( rOptions.GetReducedGradientStepCount() );
746 : 0 : SetReduceBitmaps( rOptions.IsReduceBitmaps() );
747 : : SetReducedBitmapMode(
748 : 0 : sal::static_int_cast< sal_Int16 >(rOptions.GetReducedBitmapMode()) );
749 : 0 : SetReducedBitmapIncludesTransparency( rOptions.IsReducedBitmapIncludesTransparency() );
750 : 0 : SetConvertToGreyscales( rOptions.IsConvertToGreyscales() );
751 : :
752 : 0 : const sal_uInt16 nDPI = rOptions.GetReducedBitmapResolution();
753 : :
754 [ # # ]: 0 : if( nDPI < aDPIArray[ 0 ] )
755 : 0 : SetReducedBitmapResolution( 0 );
756 : : else
757 : : {
758 [ # # ]: 0 : for( long i = ( DPI_COUNT - 1 ); i >= 0; i-- )
759 : : {
760 [ # # ]: 0 : if( nDPI >= aDPIArray[ i ] )
761 : : {
762 : 0 : SetReducedBitmapResolution( (sal_Int16) i );
763 : 0 : i = -1;
764 : : }
765 : : }
766 : : }
767 : 0 : }
768 : :
769 : : // ---------------------
770 : : // - SvtPrinterOptions -
771 : : // ---------------------
772 : :
773 : 0 : SvtPrinterOptions::SvtPrinterOptions()
774 : : {
775 : : // Global access, must be guarded (multithreading!).
776 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
777 : : // Increase our refcount ...
778 : 0 : ++m_nRefCount;
779 : : // ... and initialize our data container only if it not already!
780 [ # # ]: 0 : if( m_pStaticDataContainer == NULL )
781 : : {
782 [ # # ]: 0 : OUString aRootPath( ROOTNODE_START );
783 [ # # ][ # # ]: 0 : m_pStaticDataContainer = new SvtPrintOptions_Impl( aRootPath += OUString( RTL_CONSTASCII_USTRINGPARAM( "/Printer" ) ) );
[ # # ]
784 : 0 : pPrinterOptionsDataContainer = m_pStaticDataContainer;
785 [ # # ]: 0 : svtools::ItemHolder2::holdConfigItem(E_PRINTOPTIONS);
786 : : }
787 : :
788 [ # # ]: 0 : SetDataContainer( m_pStaticDataContainer );
789 : 0 : }
790 : :
791 : : // -----------------------------------------------------------------------------
792 : :
793 : 0 : SvtPrinterOptions::~SvtPrinterOptions()
794 : : {
795 : : // Global access, must be guarded (multithreading!)
796 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
797 : : // Decrease our refcount.
798 : 0 : --m_nRefCount;
799 : : // If last instance was deleted ...
800 : : // we must destroy our static data container!
801 [ # # ]: 0 : if( m_nRefCount <= 0 )
802 : : {
803 [ # # ][ # # ]: 0 : delete m_pStaticDataContainer;
804 : 0 : m_pStaticDataContainer = NULL;
805 : 0 : pPrinterOptionsDataContainer = NULL;
806 [ # # ]: 0 : }
807 [ # # ]: 0 : }
808 : :
809 : : // ---------------------
810 : : // - SvtPrintFileOptions -
811 : : // ---------------------
812 : :
813 : 0 : SvtPrintFileOptions::SvtPrintFileOptions()
814 : : {
815 : : // Global access, must be guarded (multithreading!).
816 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
817 : : // Increase our refcount ...
818 : 0 : ++m_nRefCount;
819 : : // ... and initialize our data container only if it not already!
820 [ # # ]: 0 : if( m_pStaticDataContainer == NULL )
821 : : {
822 [ # # ]: 0 : OUString aRootPath( ROOTNODE_START );
823 [ # # ][ # # ]: 0 : m_pStaticDataContainer = new SvtPrintOptions_Impl( aRootPath += OUString( RTL_CONSTASCII_USTRINGPARAM( "/File" ) ) );
[ # # ]
824 : 0 : pPrintFileOptionsDataContainer = m_pStaticDataContainer;
825 : :
826 [ # # ]: 0 : svtools::ItemHolder2::holdConfigItem(E_PRINTFILEOPTIONS);
827 : : }
828 : :
829 [ # # ]: 0 : SetDataContainer( m_pStaticDataContainer );
830 : 0 : }
831 : :
832 : : // -----------------------------------------------------------------------------
833 : :
834 : 0 : SvtPrintFileOptions::~SvtPrintFileOptions()
835 : : {
836 : : // Global access, must be guarded (multithreading!)
837 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
838 : : // Decrease our refcount.
839 : 0 : --m_nRefCount;
840 : : // If last instance was deleted ...
841 : : // we must destroy our static data container!
842 [ # # ]: 0 : if( m_nRefCount <= 0 )
843 : : {
844 [ # # ][ # # ]: 0 : delete m_pStaticDataContainer;
845 : 0 : m_pStaticDataContainer = NULL;
846 : 0 : pPrintFileOptionsDataContainer = NULL;
847 [ # # ]: 0 : }
848 [ # # ]: 0 : }
849 : :
850 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|