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