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