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