LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/config - printoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 325 0.0 %
Date: 2012-12-27 Functions: 0 60 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10