LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxprinter.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 3 175 1.7 %
Date: 2014-11-03 Functions: 3 39 7.7 %
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 <com/sun/star/uno/XComponentContext.hpp>
      21             : #include <toolkit/awt/vclxprinter.hxx>
      22             : #include <toolkit/helper/macros.hxx>
      23             : #include <cppuhelper/typeprovider.hxx>
      24             : #include <rtl/uuid.h>
      25             : 
      26             : 
      27             : #include <vcl/print.hxx>
      28             : #include <vcl/jobset.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : 
      31             : #include <tools/debug.hxx>
      32             : #include <tools/stream.hxx>
      33             : 
      34             : #include <toolkit/awt/vclxdevice.hxx>
      35             : 
      36             : 
      37             : #define BINARYSETUPMARKER       0x23864691
      38             : 
      39             : #define PROPERTY_Orientation    0
      40             : #define PROPERTY_Horizontal     1
      41             : 
      42           0 : ::com::sun::star::beans::Property* ImplGetProperties( sal_uInt16& rElementCount )
      43             : {
      44             :     static ::com::sun::star::beans::Property* pProperties = NULL;
      45             :     static sal_uInt16 nElements = 0;
      46           0 :     if( !pProperties )
      47             :     {
      48           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
      49           0 :         if( !pProperties )
      50             :         {
      51             :             static ::com::sun::star::beans::Property aPropTable[] =
      52             :             {
      53           0 :                 ::com::sun::star::beans::Property( OUString("Orientation"), PROPERTY_Orientation, cppu::UnoType<sal_Int16>::get(), 0 ),
      54           0 :                 ::com::sun::star::beans::Property( OUString("Horizontal"), PROPERTY_Horizontal, ::getBooleanCppuType(), 0 )
      55           0 :             };
      56           0 :             pProperties = aPropTable;
      57           0 :             nElements = sizeof( aPropTable ) / sizeof( ::com::sun::star::beans::Property );
      58           0 :         }
      59             :     }
      60           0 :     rElementCount = nElements;
      61           0 :     return pProperties;
      62             : }
      63             : 
      64             : //    ----------------------------------------------------
      65             : //    class VCLXPrinterPropertySet
      66             : //    ----------------------------------------------------
      67             : 
      68           0 : IMPLEMENT_FORWARD_XINTERFACE2( VCLXPrinterPropertySet, VCLXPrinterPropertySet_Base, OPropertySetHelper )
      69           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXPrinterPropertySet, VCLXPrinterPropertySet_Base, ::cppu::OPropertySetHelper )
      70             : 
      71           0 : VCLXPrinterPropertySet::VCLXPrinterPropertySet( const OUString& rPrinterName )
      72             :     : OPropertySetHelper( BrdcstHelper )
      73           0 :     , mpPrinter( new Printer( rPrinterName ) )
      74             : {
      75           0 :     SolarMutexGuard aSolarGuard;
      76             : 
      77           0 :     mnOrientation = 0;
      78           0 :     mbHorizontal = false;
      79           0 : }
      80             : 
      81           0 : VCLXPrinterPropertySet::~VCLXPrinterPropertySet()
      82             : {
      83           0 :     SolarMutexGuard aSolarGuard;
      84           0 :     mpPrinter.reset();
      85           0 : }
      86             : 
      87           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice >  VCLXPrinterPropertySet::GetDevice()
      88             : {
      89           0 :     if ( !mxPrnDevice.is() )
      90             :     {
      91           0 :         VCLXDevice* pDev = new VCLXDevice;
      92           0 :         pDev->SetOutputDevice( GetPrinter() );
      93           0 :         mxPrnDevice = pDev;
      94             :     }
      95           0 :     return mxPrnDevice;
      96             : }
      97             : 
      98           0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > VCLXPrinterPropertySet::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      99             : {
     100           0 :     static ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >  xInfo( createPropertySetInfo( getInfoHelper() ) );
     101           0 :     return xInfo;
     102             : }
     103             : 
     104           0 : ::cppu::IPropertyArrayHelper& VCLXPrinterPropertySet::getInfoHelper()
     105             : {
     106             :     static ::cppu::OPropertyArrayHelper* pPropertyArrayHelper = NULL;
     107           0 :     if ( !pPropertyArrayHelper )
     108             :     {
     109           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     110           0 :         if( !pPropertyArrayHelper )
     111             :         {
     112             :             sal_uInt16 nElements;
     113           0 :             ::com::sun::star::beans::Property* pProps = ImplGetProperties( nElements );
     114           0 :             pPropertyArrayHelper = new ::cppu::OPropertyArrayHelper( pProps, nElements, sal_False );
     115           0 :         }
     116             :     }
     117           0 :     return *pPropertyArrayHelper ;
     118             : }
     119             : 
     120           0 : sal_Bool VCLXPrinterPropertySet::convertFastPropertyValue( ::com::sun::star::uno::Any & rConvertedValue, ::com::sun::star::uno::Any & rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::lang::IllegalArgumentException)
     121             : {
     122           0 :     ::osl::MutexGuard aGuard( Mutex );
     123             : 
     124           0 :     bool bDifferent = false;
     125           0 :     switch ( nHandle )
     126             :     {
     127             :         case PROPERTY_Orientation:
     128             :         {
     129             :             sal_Int16 n;
     130           0 :             if( ( rValue >>= n ) && ( n != mnOrientation ) )
     131             :             {
     132           0 :                 rConvertedValue <<= n;
     133           0 :                 rOldValue <<= mnOrientation;
     134           0 :                 bDifferent = true;
     135             :             }
     136             :         }
     137           0 :         break;
     138             :         case PROPERTY_Horizontal:
     139             :         {
     140             :             bool b;
     141           0 :             if( ( rValue >>= b ) && ( b != mbHorizontal ) )
     142             :             {
     143           0 :                 rConvertedValue <<= b;
     144           0 :                 rOldValue <<= mbHorizontal;
     145           0 :                 bDifferent = true;
     146             :             }
     147             :         }
     148           0 :         break;
     149             :         default:
     150             :         {
     151             :             OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
     152             :         }
     153             :     }
     154           0 :     return bDifferent;
     155             : }
     156             : 
     157           0 : void VCLXPrinterPropertySet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception, std::exception)
     158             : {
     159           0 :     ::osl::MutexGuard aGuard( Mutex );
     160             : 
     161           0 :     switch( nHandle )
     162             :     {
     163             :         case PROPERTY_Orientation:
     164             :         {
     165           0 :             rValue >>= mnOrientation;
     166             :         }
     167           0 :         break;
     168             :         case PROPERTY_Horizontal:
     169             :         {
     170           0 :             rValue >>= mbHorizontal;
     171             :         }
     172           0 :         break;
     173             :         default:
     174             :         {
     175             :             OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
     176             :         }
     177           0 :     }
     178           0 : }
     179             : 
     180           0 : void VCLXPrinterPropertySet::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const
     181             : {
     182           0 :     ::osl::MutexGuard aGuard( ((VCLXPrinterPropertySet*)this)->Mutex );
     183             : 
     184           0 :     switch( nHandle )
     185             :     {
     186             :         case PROPERTY_Orientation:
     187           0 :             rValue <<= mnOrientation;
     188           0 :         break;
     189             :         case PROPERTY_Horizontal:
     190           0 :             rValue <<= mbHorizontal;
     191           0 :         break;
     192             :         default:
     193             :         {
     194             :             OSL_FAIL( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
     195             :         }
     196           0 :     }
     197           0 : }
     198             : 
     199             : // ::com::sun::star::awt::XPrinterPropertySet
     200           0 : void VCLXPrinterPropertySet::setHorizontal( sal_Bool bHorizontal ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     201             : {
     202           0 :     ::osl::MutexGuard aGuard( Mutex );
     203             : 
     204           0 :     ::com::sun::star::uno::Any aValue;
     205           0 :     aValue <<= bHorizontal;
     206           0 :     setFastPropertyValue( PROPERTY_Horizontal, aValue );
     207           0 : }
     208             : 
     209           0 : ::com::sun::star::uno::Sequence< OUString > VCLXPrinterPropertySet::getFormDescriptions(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     210             : {
     211           0 :     ::osl::MutexGuard aGuard( Mutex );
     212             : 
     213           0 :     sal_uInt16 nPaperBinCount = GetPrinter()->GetPaperBinCount();
     214           0 :     ::com::sun::star::uno::Sequence< OUString > aDescriptions( nPaperBinCount );
     215           0 :     for ( sal_uInt16 n = 0; n < nPaperBinCount; n++ )
     216             :     {
     217             :         // Format: <DisplayFormName;FormNameId;DisplayPaperBinName;PaperBinNameId;DisplayPaperName;PaperNameId>
     218           0 :         OUStringBuffer aDescr( "*;*;" );
     219           0 :         aDescr.append(GetPrinter()->GetPaperBinName( n ));
     220           0 :         aDescr.append(';');
     221           0 :         aDescr.append(OUString::number(n));
     222           0 :         aDescr.append(";*;*");
     223             : 
     224           0 :         aDescriptions.getArray()[n] = aDescr.makeStringAndClear();
     225           0 :     }
     226           0 :     return aDescriptions;
     227             : }
     228             : 
     229           0 : void VCLXPrinterPropertySet::selectForm( const OUString& rFormDescription ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     230             : {
     231           0 :     ::osl::MutexGuard aGuard( Mutex );
     232             : 
     233           0 :     sal_Int32 nIndex = 0;
     234             :     sal_uInt16 nPaperBin = sal::static_int_cast< sal_uInt16 >(
     235           0 :         rFormDescription.getToken( 3, ';', nIndex ).toInt32());
     236           0 :     GetPrinter()->SetPaperBin( nPaperBin );
     237           0 : }
     238             : 
     239           0 : ::com::sun::star::uno::Sequence< sal_Int8 > VCLXPrinterPropertySet::getBinarySetup(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     240             : {
     241           0 :     ::osl::MutexGuard aGuard( Mutex );
     242             : 
     243           0 :     SvMemoryStream aMem;
     244           0 :     aMem.WriteUInt32( BINARYSETUPMARKER );
     245           0 :     WriteJobSetup( aMem, GetPrinter()->GetJobSetup() );
     246           0 :     return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
     247             : }
     248             : 
     249           0 : void VCLXPrinterPropertySet::setBinarySetup( const ::com::sun::star::uno::Sequence< sal_Int8 >& data ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     250             : {
     251           0 :     ::osl::MutexGuard aGuard( Mutex );
     252             : 
     253           0 :     SvMemoryStream aMem( (char*) data.getConstArray(), data.getLength(), STREAM_READ );
     254             :     sal_uInt32 nMarker;
     255           0 :     aMem.ReadUInt32( nMarker );
     256             :     DBG_ASSERT( nMarker == BINARYSETUPMARKER, "setBinarySetup - invalid!" );
     257           0 :     if ( nMarker == BINARYSETUPMARKER )
     258             :     {
     259           0 :         JobSetup aSetup;
     260           0 :         ReadJobSetup( aMem, aSetup );
     261           0 :         GetPrinter()->SetJobSetup( aSetup );
     262           0 :     }
     263           0 : }
     264             : 
     265             : 
     266             : //    ----------------------------------------------------
     267             : //    class VCLXPrinter
     268             : //    ----------------------------------------------------
     269           0 : VCLXPrinter::VCLXPrinter( const OUString& rPrinterName )
     270           0 :     : VCLXPrinter_Base( rPrinterName )
     271             : {
     272           0 : }
     273             : 
     274           0 : VCLXPrinter::~VCLXPrinter()
     275             : {
     276           0 : }
     277             : 
     278           0 : sal_Bool VCLXPrinter::start( const OUString& /*rJobName*/, sal_Int16 /*nCopies*/, sal_Bool /*bCollate*/ ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
     279             : {
     280           0 :     ::osl::MutexGuard aGuard( Mutex );
     281             : 
     282           0 :     bool bDone = true;
     283           0 :     if ( mpPrinter.get() )
     284             :     {
     285           0 :         maInitJobSetup = mpPrinter->GetJobSetup();
     286           0 :         mpListener.reset( new vcl::OldStylePrintAdaptor( mpPrinter ) );
     287             :     }
     288             : 
     289           0 :     return bDone;
     290             : }
     291             : 
     292           0 : void VCLXPrinter::end(  ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException, std::exception)
     293             : {
     294           0 :     ::osl::MutexGuard aGuard( Mutex );
     295             : 
     296           0 :     if ( mpListener.get() )
     297             :     {
     298           0 :         Printer::PrintJob( mpListener, maInitJobSetup );
     299           0 :         mpListener.reset();
     300           0 :     }
     301           0 : }
     302             : 
     303           0 : void VCLXPrinter::terminate(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     304             : {
     305           0 :     ::osl::MutexGuard aGuard( Mutex );
     306             : 
     307           0 :     mpListener.reset();
     308           0 : }
     309             : 
     310           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXPrinter::startPage(  ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException, std::exception)
     311             : {
     312           0 :     ::osl::MutexGuard aGuard( Mutex );
     313             : 
     314           0 :     if ( mpListener.get() )
     315             :     {
     316           0 :         mpListener->StartPage();
     317             :     }
     318           0 :     return GetDevice();
     319             : }
     320             : 
     321           0 : void VCLXPrinter::endPage(  ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException, std::exception)
     322             : {
     323           0 :     ::osl::MutexGuard aGuard( Mutex );
     324             : 
     325           0 :     if ( mpListener.get() )
     326             :     {
     327           0 :         mpListener->EndPage();
     328           0 :     }
     329           0 : }
     330             : 
     331             : 
     332             : //    ----------------------------------------------------
     333             : //    class VCLXInfoPrinter
     334             : //    ----------------------------------------------------
     335             : 
     336           0 : VCLXInfoPrinter::VCLXInfoPrinter( const OUString& rPrinterName )
     337           0 :     : VCLXInfoPrinter_Base( rPrinterName )
     338             : {
     339           0 : }
     340             : 
     341           0 : VCLXInfoPrinter::~VCLXInfoPrinter()
     342             : {
     343           0 : }
     344             : 
     345             : // ::com::sun::star::awt::XInfoPrinter
     346           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXInfoPrinter::createDevice(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     347             : {
     348           0 :     ::osl::MutexGuard aGuard( Mutex );
     349             : 
     350           0 :     return GetDevice();
     351             : }
     352             : 
     353             : //    ----------------------------------------------------
     354             : //    class VCLXPrinterServer
     355             : //    ----------------------------------------------------
     356             : 
     357             : // ::com::sun::star::awt::XPrinterServer
     358           0 : ::com::sun::star::uno::Sequence< OUString > VCLXPrinterServer::getPrinterNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     359             : {
     360           0 :     const std::vector<OUString>& rQueues = Printer::GetPrinterQueues();
     361           0 :     sal_uInt32 nPrinters = rQueues.size();
     362             : 
     363           0 :     ::com::sun::star::uno::Sequence< OUString > aNames( nPrinters );
     364           0 :     for ( sal_uInt32 n = 0; n < nPrinters; n++ )
     365           0 :         aNames.getArray()[n] = rQueues[n];
     366             : 
     367           0 :     return aNames;
     368             : }
     369             : 
     370           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > VCLXPrinterServer::createPrinter( const OUString& rPrinterName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     371             : {
     372           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > xP;
     373           0 :     xP = new VCLXPrinter( rPrinterName );
     374           0 :     return xP;
     375             : }
     376             : 
     377           0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > VCLXPrinterServer::createInfoPrinter( const OUString& rPrinterName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     378             : {
     379           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > xP;
     380           0 :     xP = new VCLXInfoPrinter( rPrinterName );
     381           0 :     return xP;
     382             : }
     383             : 
     384             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     385           2 : stardiv_Toolkit_VCLXPrinterServer_get_implementation(
     386             :     css::uno::XComponentContext *,
     387             :     css::uno::Sequence<css::uno::Any> const &)
     388             : {
     389           2 :     return cppu::acquire(new VCLXPrinterServer());
     390        1227 : }
     391             : 
     392             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10