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