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

Generated by: LCOV version 1.10