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