xref: /trunk/main/toolkit/source/awt/vclxprinter.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <toolkit/awt/vclxprinter.hxx>
33*cdf0e10cSrcweir #include <toolkit/helper/macros.hxx>
34*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
35*cdf0e10cSrcweir #include <rtl/memory.h>
36*cdf0e10cSrcweir #include <rtl/uuid.h>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <vcl/print.hxx>
40*cdf0e10cSrcweir #include <vcl/jobset.hxx>
41*cdf0e10cSrcweir #include <vcl/svapp.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <tools/debug.hxx>
44*cdf0e10cSrcweir #include <tools/stream.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <toolkit/awt/vclxdevice.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #define BINARYSETUPMARKER   0x23864691
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #define PROPERTY_Orientation    0
52*cdf0e10cSrcweir #define PROPERTY_Horizontal     1
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir ::com::sun::star::beans::Property* ImplGetProperties( sal_uInt16& rElementCount )
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir     static ::com::sun::star::beans::Property* pProperties = NULL;
57*cdf0e10cSrcweir     static sal_uInt16 nElements = 0;
58*cdf0e10cSrcweir     if( !pProperties )
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
61*cdf0e10cSrcweir         if( !pProperties )
62*cdf0e10cSrcweir         {
63*cdf0e10cSrcweir             static ::com::sun::star::beans::Property __FAR_DATA aPropTable[] =
64*cdf0e10cSrcweir             {
65*cdf0e10cSrcweir                 ::com::sun::star::beans::Property( ::rtl::OUString::createFromAscii( "Orientation" ), PROPERTY_Orientation, ::getCppuType((const sal_Int16*)0), 0 ),
66*cdf0e10cSrcweir                 ::com::sun::star::beans::Property( ::rtl::OUString::createFromAscii( "Horizontal" ), PROPERTY_Horizontal, ::getBooleanCppuType(), 0 )
67*cdf0e10cSrcweir             };
68*cdf0e10cSrcweir             pProperties = aPropTable;
69*cdf0e10cSrcweir             nElements = sizeof( aPropTable ) / sizeof( ::com::sun::star::beans::Property );
70*cdf0e10cSrcweir         }
71*cdf0e10cSrcweir     }
72*cdf0e10cSrcweir     rElementCount = nElements;
73*cdf0e10cSrcweir     return pProperties;
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //  ----------------------------------------------------
77*cdf0e10cSrcweir //  class VCLXPrinterPropertySet
78*cdf0e10cSrcweir //  ----------------------------------------------------
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
81*cdf0e10cSrcweir ::com::sun::star::uno::Any VCLXPrinterPropertySet::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
84*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::beans::XMultiPropertySet*, this ),
85*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::beans::XFastPropertySet*, this ),
86*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::beans::XPropertySet*, (::cppu::OPropertySetHelper*) this ),
87*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::awt::XPrinterPropertySet*, this ),
88*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) );
89*cdf0e10cSrcweir     return (aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface( rType ));
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir // ::com::sun::star::lang::XTypeProvider
93*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_START( VCLXPrinterPropertySet )
94*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>* ) NULL ),
95*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>* ) NULL ),
96*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>* ) NULL ),
97*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinterPropertySet>* ) NULL )
98*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_END
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir VCLXPrinterPropertySet::VCLXPrinterPropertySet( const String& rPrinterName )
101*cdf0e10cSrcweir     : OPropertySetHelper( BrdcstHelper )
102*cdf0e10cSrcweir     , mpPrinter( new Printer( rPrinterName ) )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     mnOrientation = 0;
107*cdf0e10cSrcweir     mbHorizontal = sal_False;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir VCLXPrinterPropertySet::~VCLXPrinterPropertySet()
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir     osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() );
113*cdf0e10cSrcweir     mpPrinter.reset();
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice >  VCLXPrinterPropertySet::GetDevice()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     if ( !mxPrnDevice.is() )
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         VCLXDevice* pDev = new VCLXDevice;
121*cdf0e10cSrcweir         pDev->SetOutputDevice( GetPrinter() );
122*cdf0e10cSrcweir         mxPrnDevice = pDev;
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir     return mxPrnDevice;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > VCLXPrinterPropertySet::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     static ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >  xInfo( createPropertySetInfo( getInfoHelper() ) );
130*cdf0e10cSrcweir     return xInfo;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& VCLXPrinterPropertySet::getInfoHelper()
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     static ::cppu::OPropertyArrayHelper* pPropertyArrayHelper = NULL;
136*cdf0e10cSrcweir     if ( !pPropertyArrayHelper )
137*cdf0e10cSrcweir     {
138*cdf0e10cSrcweir         ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
139*cdf0e10cSrcweir         if( !pPropertyArrayHelper )
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir             sal_uInt16 nElements;
142*cdf0e10cSrcweir             ::com::sun::star::beans::Property* pProps = ImplGetProperties( nElements );
143*cdf0e10cSrcweir             pPropertyArrayHelper = new ::cppu::OPropertyArrayHelper( pProps, nElements, sal_False );
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir     return *pPropertyArrayHelper ;
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 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)
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     sal_Bool bDifferent = sal_False;
154*cdf0e10cSrcweir     switch ( nHandle )
155*cdf0e10cSrcweir     {
156*cdf0e10cSrcweir         case PROPERTY_Orientation:
157*cdf0e10cSrcweir         {
158*cdf0e10cSrcweir             sal_Int16 n;
159*cdf0e10cSrcweir             if( ( rValue >>= n ) && ( n != mnOrientation ) )
160*cdf0e10cSrcweir             {
161*cdf0e10cSrcweir                 rConvertedValue <<= n;
162*cdf0e10cSrcweir                 rOldValue <<= mnOrientation;
163*cdf0e10cSrcweir                 bDifferent = sal_True;
164*cdf0e10cSrcweir             }
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir         break;
167*cdf0e10cSrcweir         case PROPERTY_Horizontal:
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             sal_Bool b;
170*cdf0e10cSrcweir             if( ( rValue >>= b ) && ( b != mbHorizontal ) )
171*cdf0e10cSrcweir             {
172*cdf0e10cSrcweir                 rConvertedValue <<= b;
173*cdf0e10cSrcweir                 rOldValue <<= mbHorizontal;
174*cdf0e10cSrcweir                 bDifferent = sal_True;
175*cdf0e10cSrcweir             }
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir         break;
178*cdf0e10cSrcweir         default:
179*cdf0e10cSrcweir         {
180*cdf0e10cSrcweir             DBG_ERROR( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
181*cdf0e10cSrcweir         }
182*cdf0e10cSrcweir     }
183*cdf0e10cSrcweir     return bDifferent;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir void VCLXPrinterPropertySet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception)
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     switch( nHandle )
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir         case PROPERTY_Orientation:
193*cdf0e10cSrcweir         {
194*cdf0e10cSrcweir             rValue >>= mnOrientation;
195*cdf0e10cSrcweir         }
196*cdf0e10cSrcweir         break;
197*cdf0e10cSrcweir         case PROPERTY_Horizontal:
198*cdf0e10cSrcweir         {
199*cdf0e10cSrcweir             rValue >>= mbHorizontal;
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir         break;
202*cdf0e10cSrcweir         default:
203*cdf0e10cSrcweir         {
204*cdf0e10cSrcweir             DBG_ERROR( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
205*cdf0e10cSrcweir         }
206*cdf0e10cSrcweir     }
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir void VCLXPrinterPropertySet::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( ((VCLXPrinterPropertySet*)this)->Mutex );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     switch( nHandle )
214*cdf0e10cSrcweir     {
215*cdf0e10cSrcweir         case PROPERTY_Orientation:
216*cdf0e10cSrcweir             rValue <<= mnOrientation;
217*cdf0e10cSrcweir         break;
218*cdf0e10cSrcweir         case PROPERTY_Horizontal:
219*cdf0e10cSrcweir             rValue <<= mbHorizontal;
220*cdf0e10cSrcweir         break;
221*cdf0e10cSrcweir         default:
222*cdf0e10cSrcweir         {
223*cdf0e10cSrcweir             DBG_ERROR( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" );
224*cdf0e10cSrcweir         }
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir // ::com::sun::star::awt::XPrinterPropertySet
229*cdf0e10cSrcweir void VCLXPrinterPropertySet::setHorizontal( sal_Bool bHorizontal ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     ::com::sun::star::uno::Any aValue;
234*cdf0e10cSrcweir     aValue <<= bHorizontal;
235*cdf0e10cSrcweir     setFastPropertyValue( PROPERTY_Horizontal, aValue );
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXPrinterPropertySet::getFormDescriptions(  ) throw(::com::sun::star::uno::RuntimeException)
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     sal_uInt16 nPaperBinCount = GetPrinter()->GetPaperBinCount();
243*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString >  aDescriptions( nPaperBinCount );
244*cdf0e10cSrcweir     for ( sal_uInt16 n = 0; n < nPaperBinCount; n++ )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         // Format: <DisplayFormName;FormNameId;DisplayPaperBinName;PaperBinNameId;DisplayPaperName;PaperNameId>
247*cdf0e10cSrcweir         String aDescr( RTL_CONSTASCII_USTRINGPARAM( "*;*;" ) );
248*cdf0e10cSrcweir         aDescr += GetPrinter()->GetPaperBinName( n );
249*cdf0e10cSrcweir         aDescr += ';';
250*cdf0e10cSrcweir         aDescr += n;
251*cdf0e10cSrcweir         aDescr.AppendAscii( ";*;*", 4 );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir         aDescriptions.getArray()[n] = aDescr;
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir     return aDescriptions;
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir void VCLXPrinterPropertySet::selectForm( const ::rtl::OUString& rFormDescription ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     sal_Int32 nIndex = 0;
263*cdf0e10cSrcweir     sal_uInt16 nPaperBin = sal::static_int_cast< sal_uInt16 >(
264*cdf0e10cSrcweir         rFormDescription.getToken( 3, ';', nIndex ).toInt32());
265*cdf0e10cSrcweir     GetPrinter()->SetPaperBin( nPaperBin );
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > VCLXPrinterPropertySet::getBinarySetup(  ) throw(::com::sun::star::uno::RuntimeException)
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     SvMemoryStream aMem;
273*cdf0e10cSrcweir     aMem << BINARYSETUPMARKER;
274*cdf0e10cSrcweir     aMem << GetPrinter()->GetJobSetup();
275*cdf0e10cSrcweir     return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() );
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 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)
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     SvMemoryStream aMem( (char*) data.getConstArray(), data.getLength(), STREAM_READ );
283*cdf0e10cSrcweir     sal_uInt32 nMarker;
284*cdf0e10cSrcweir     aMem >> nMarker;
285*cdf0e10cSrcweir     DBG_ASSERT( nMarker == BINARYSETUPMARKER, "setBinarySetup - invalid!" );
286*cdf0e10cSrcweir     if ( nMarker == BINARYSETUPMARKER )
287*cdf0e10cSrcweir     {
288*cdf0e10cSrcweir         JobSetup aSetup;
289*cdf0e10cSrcweir         aMem >> aSetup;
290*cdf0e10cSrcweir         GetPrinter()->SetJobSetup( aSetup );
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir //  ----------------------------------------------------
296*cdf0e10cSrcweir //  class VCLXPrinter
297*cdf0e10cSrcweir //  ----------------------------------------------------
298*cdf0e10cSrcweir VCLXPrinter::VCLXPrinter( const String& rPrinterName )
299*cdf0e10cSrcweir     : VCLXPrinterPropertySet( rPrinterName )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir VCLXPrinter::~VCLXPrinter()
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
308*cdf0e10cSrcweir ::com::sun::star::uno::Any VCLXPrinter::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
311*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::awt::XPrinter*, this ) );
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     if ( !aRet.hasValue() )
314*cdf0e10cSrcweir         aRet = VCLXPrinterPropertySet::queryInterface( rType );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir // ::com::sun::star::lang::XTypeProvider
320*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_START( VCLXPrinter )
321*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter>* ) NULL ),
322*cdf0e10cSrcweir     VCLXPrinterPropertySet::getTypes()
323*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_END
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir sal_Bool VCLXPrinter::start( const ::rtl::OUString& /*rJobName*/, sal_Int16 /*nCopies*/, sal_Bool /*bCollate*/ ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     sal_Bool bDone = sal_True;
330*cdf0e10cSrcweir     if ( mpListener.get() )
331*cdf0e10cSrcweir     {
332*cdf0e10cSrcweir         maInitJobSetup = mpPrinter->GetJobSetup();
333*cdf0e10cSrcweir         mpListener.reset( new vcl::OldStylePrintAdaptor( mpPrinter ) );
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     return bDone;
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir void VCLXPrinter::end(  ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException)
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     if ( mpListener.get() )
344*cdf0e10cSrcweir     {
345*cdf0e10cSrcweir         Printer::PrintJob( mpListener, maInitJobSetup );
346*cdf0e10cSrcweir         mpListener.reset();
347*cdf0e10cSrcweir     }
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir void VCLXPrinter::terminate(  ) throw(::com::sun::star::uno::RuntimeException)
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     mpListener.reset();
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXPrinter::startPage(  ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException)
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     if ( mpListener.get() )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         mpListener->StartPage();
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir     return GetDevice();
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir void VCLXPrinter::endPage(  ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException)
369*cdf0e10cSrcweir {
370*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir     if ( mpListener.get() )
373*cdf0e10cSrcweir     {
374*cdf0e10cSrcweir         mpListener->EndPage();
375*cdf0e10cSrcweir     }
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir //  ----------------------------------------------------
380*cdf0e10cSrcweir //  class VCLXInfoPrinter
381*cdf0e10cSrcweir //  ----------------------------------------------------
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir VCLXInfoPrinter::VCLXInfoPrinter( const String& rPrinterName )
384*cdf0e10cSrcweir     : VCLXPrinterPropertySet( rPrinterName )
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir VCLXInfoPrinter::~VCLXInfoPrinter()
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
393*cdf0e10cSrcweir ::com::sun::star::uno::Any VCLXInfoPrinter::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
396*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::awt::XInfoPrinter*, this ) );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     if ( !aRet.hasValue() )
399*cdf0e10cSrcweir         aRet = VCLXPrinterPropertySet::queryInterface( rType );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir // ::com::sun::star::lang::XTypeProvider
405*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_START( VCLXInfoPrinter )
406*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter>* ) NULL ),
407*cdf0e10cSrcweir     VCLXPrinterPropertySet::getTypes()
408*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_END
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // ::com::sun::star::awt::XInfoPrinter
411*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXInfoPrinter::createDevice(  ) throw(::com::sun::star::uno::RuntimeException)
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( Mutex );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir     return GetDevice();
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir //  ----------------------------------------------------
419*cdf0e10cSrcweir //  class VCLXPrinterServer
420*cdf0e10cSrcweir //  ----------------------------------------------------
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir // ::com::sun::star::uno::XInterface
423*cdf0e10cSrcweir ::com::sun::star::uno::Any VCLXPrinterServer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
426*cdf0e10cSrcweir                                         SAL_STATIC_CAST( ::com::sun::star::awt::XPrinterServer*, this ) );
427*cdf0e10cSrcweir     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir // ::com::sun::star::lang::XTypeProvider
431*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_START( VCLXPrinterServer )
432*cdf0e10cSrcweir     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinterServer>* ) NULL )
433*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_END
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir // ::com::sun::star::awt::XPrinterServer
436*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXPrinterServer::getPrinterNames(  ) throw(::com::sun::star::uno::RuntimeException)
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir     const std::vector<rtl::OUString>& rQueues = Printer::GetPrinterQueues();
439*cdf0e10cSrcweir     sal_uInt32 nPrinters = rQueues.size();
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString >  aNames( nPrinters );
442*cdf0e10cSrcweir     for ( sal_uInt32 n = 0; n < nPrinters; n++ )
443*cdf0e10cSrcweir         aNames.getArray()[n] = rQueues[n];
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     return aNames;
446*cdf0e10cSrcweir }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > VCLXPrinterServer::createPrinter( const ::rtl::OUString& rPrinterName ) throw(::com::sun::star::uno::RuntimeException)
449*cdf0e10cSrcweir {
450*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > xP;
451*cdf0e10cSrcweir     xP = new VCLXPrinter( rPrinterName );
452*cdf0e10cSrcweir     return xP;
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > VCLXPrinterServer::createInfoPrinter( const ::rtl::OUString& rPrinterName ) throw(::com::sun::star::uno::RuntimeException)
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > xP;
458*cdf0e10cSrcweir     xP = new VCLXInfoPrinter( rPrinterName );
459*cdf0e10cSrcweir     return xP;
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 
464