xref: /AOO41X/main/sfx2/source/doc/printhelper.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_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "printhelper.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/view/XPrintJob.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/view/PaperFormat.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/view/PaperOrientation.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/lang/EventObject.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/view/DuplexMode.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <svl/lstner.hxx>
45*cdf0e10cSrcweir #include <svl/stritem.hxx>
46*cdf0e10cSrcweir #include <svl/intitem.hxx>
47*cdf0e10cSrcweir #include <svl/eitem.hxx>
48*cdf0e10cSrcweir #include <unotools/tempfile.hxx>
49*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
50*cdf0e10cSrcweir #include <osl/file.hxx>
51*cdf0e10cSrcweir #include <osl/thread.hxx>
52*cdf0e10cSrcweir #include <tools/urlobj.hxx>
53*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
54*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
55*cdf0e10cSrcweir #include <vos/mutex.hxx>
56*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
59*cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
60*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
61*cdf0e10cSrcweir #include <sfx2/request.hxx>
62*cdf0e10cSrcweir #include <sfx2/printer.hxx>
63*cdf0e10cSrcweir #include <sfx2/app.hxx>
64*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
65*cdf0e10cSrcweir #include <sfx2/event.hxx>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir using namespace ::com::sun::star;
68*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir struct IMPL_PrintListener_DataContainer : public SfxListener
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     SfxObjectShellRef                               m_pObjectShell;
73*cdf0e10cSrcweir     ::cppu::OMultiTypeInterfaceContainerHelper      m_aInterfaceContainer;
74*cdf0e10cSrcweir     uno::Reference< com::sun::star::view::XPrintJob>     m_xPrintJob;
75*cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aPrintOptions;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     IMPL_PrintListener_DataContainer( ::osl::Mutex& aMutex)
78*cdf0e10cSrcweir             :   m_pObjectShell          ( 0 )
79*cdf0e10cSrcweir             ,   m_aInterfaceContainer   ( aMutex )
80*cdf0e10cSrcweir 	{
81*cdf0e10cSrcweir 	}
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	void Notify(			SfxBroadcaster&	aBC		,
85*cdf0e10cSrcweir 					const	SfxHint&		aHint	) ;
86*cdf0e10cSrcweir };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir awt::Size impl_Size_Object2Struct( const Size& aSize )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir     awt::Size aReturnValue;
91*cdf0e10cSrcweir 	aReturnValue.Width  = aSize.Width()  ;
92*cdf0e10cSrcweir 	aReturnValue.Height = aSize.Height() ;
93*cdf0e10cSrcweir 	return aReturnValue ;
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir Size impl_Size_Struct2Object( const awt::Size& aSize )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	Size aReturnValue;
99*cdf0e10cSrcweir 	aReturnValue.Width()  = aSize.Width  ;
100*cdf0e10cSrcweir 	aReturnValue.Height() = aSize.Height ;
101*cdf0e10cSrcweir 	return aReturnValue ;
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir class SfxPrintJob_Impl : public cppu::WeakImplHelper1
105*cdf0e10cSrcweir <
106*cdf0e10cSrcweir 	com::sun::star::view::XPrintJob
107*cdf0e10cSrcweir >
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir         IMPL_PrintListener_DataContainer* m_pData;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir public:
112*cdf0e10cSrcweir         SfxPrintJob_Impl( IMPL_PrintListener_DataContainer* pData );
113*cdf0e10cSrcweir     	virtual Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPrintOptions(  ) throw (RuntimeException);
114*cdf0e10cSrcweir     	virtual Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPrinter(  ) throw (RuntimeException);
115*cdf0e10cSrcweir     	virtual Reference< ::com::sun::star::view::XPrintable > SAL_CALL getPrintable(  ) throw (RuntimeException);
116*cdf0e10cSrcweir 		virtual void SAL_CALL cancelJob() throw (RuntimeException);
117*cdf0e10cSrcweir };
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir SfxPrintJob_Impl::SfxPrintJob_Impl( IMPL_PrintListener_DataContainer* pData )
120*cdf0e10cSrcweir 	: m_pData( pData )
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SfxPrintJob_Impl::getPrintOptions() throw (RuntimeException)
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir 	return m_pData->m_aPrintOptions;
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SfxPrintJob_Impl::getPrinter() throw (RuntimeException)
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir 	if( m_pData->m_pObjectShell.Is() )
132*cdf0e10cSrcweir 	{
133*cdf0e10cSrcweir 		Reference < view::XPrintable > xPrintable( m_pData->m_pObjectShell->GetModel(), UNO_QUERY );
134*cdf0e10cSrcweir 		if ( xPrintable.is() )
135*cdf0e10cSrcweir 			return xPrintable->getPrinter();
136*cdf0e10cSrcweir 	}
137*cdf0e10cSrcweir 	return Sequence< ::com::sun::star::beans::PropertyValue >();
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir Reference< ::com::sun::star::view::XPrintable > SAL_CALL SfxPrintJob_Impl::getPrintable() throw (RuntimeException)
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir 	Reference < view::XPrintable > xPrintable( m_pData->m_pObjectShell.Is() ? m_pData->m_pObjectShell->GetModel() : NULL, UNO_QUERY );
143*cdf0e10cSrcweir 	return xPrintable;
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir void SAL_CALL SfxPrintJob_Impl::cancelJob() throw (RuntimeException)
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	// FIXME: how to cancel PrintJob via API?!
149*cdf0e10cSrcweir 	if( m_pData->m_pObjectShell.Is() )
150*cdf0e10cSrcweir 		m_pData->m_pObjectShell->Broadcast( SfxPrintingHint( -2 ) );
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir SfxPrintHelper::SfxPrintHelper()
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     m_pData = new IMPL_PrintListener_DataContainer(m_aMutex);
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir void SAL_CALL SfxPrintHelper::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir 	if ( aArguments.getLength() )
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir         com::sun::star::uno::Reference < com::sun::star::frame::XModel > xModel;
163*cdf0e10cSrcweir         aArguments[0] >>= xModel;
164*cdf0e10cSrcweir         uno::Reference < lang::XUnoTunnel > xObj( xModel, uno::UNO_QUERY );
165*cdf0e10cSrcweir         uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
166*cdf0e10cSrcweir         sal_Int64 nHandle = xObj->getSomething( aSeq );
167*cdf0e10cSrcweir         if ( nHandle )
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             m_pData->m_pObjectShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
170*cdf0e10cSrcweir             m_pData->StartListening(*m_pData->m_pObjectShell);
171*cdf0e10cSrcweir         }
172*cdf0e10cSrcweir 	}
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir SfxPrintHelper::~SfxPrintHelper()
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir     delete m_pData;
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir namespace
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     view::PaperFormat convertToPaperFormat(Paper eFormat)
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         view::PaperFormat eRet;
185*cdf0e10cSrcweir         switch (eFormat)
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             case PAPER_A3:
188*cdf0e10cSrcweir                 eRet = view::PaperFormat_A3;
189*cdf0e10cSrcweir                 break;
190*cdf0e10cSrcweir             case PAPER_A4:
191*cdf0e10cSrcweir                 eRet = view::PaperFormat_A4;
192*cdf0e10cSrcweir                 break;
193*cdf0e10cSrcweir             case PAPER_A5:
194*cdf0e10cSrcweir                 eRet = view::PaperFormat_A5;
195*cdf0e10cSrcweir                 break;
196*cdf0e10cSrcweir             case PAPER_B4_ISO:
197*cdf0e10cSrcweir                 eRet = view::PaperFormat_B4;
198*cdf0e10cSrcweir                 break;
199*cdf0e10cSrcweir             case PAPER_B5_ISO:
200*cdf0e10cSrcweir                 eRet = view::PaperFormat_B5;
201*cdf0e10cSrcweir                 break;
202*cdf0e10cSrcweir             case PAPER_LETTER:
203*cdf0e10cSrcweir                 eRet = view::PaperFormat_LETTER;
204*cdf0e10cSrcweir                 break;
205*cdf0e10cSrcweir             case PAPER_LEGAL:
206*cdf0e10cSrcweir                 eRet = view::PaperFormat_LEGAL;
207*cdf0e10cSrcweir                 break;
208*cdf0e10cSrcweir             case PAPER_TABLOID:
209*cdf0e10cSrcweir                 eRet = view::PaperFormat_TABLOID;
210*cdf0e10cSrcweir                 break;
211*cdf0e10cSrcweir             case PAPER_USER:
212*cdf0e10cSrcweir             default:
213*cdf0e10cSrcweir                 eRet = view::PaperFormat_USER;
214*cdf0e10cSrcweir                 break;
215*cdf0e10cSrcweir         }
216*cdf0e10cSrcweir         return eRet;
217*cdf0e10cSrcweir     }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     Paper convertToPaper(view::PaperFormat eFormat)
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir         Paper eRet(PAPER_USER);
222*cdf0e10cSrcweir         switch (eFormat)
223*cdf0e10cSrcweir         {
224*cdf0e10cSrcweir             case view::PaperFormat_A3:
225*cdf0e10cSrcweir                 eRet = PAPER_A3;
226*cdf0e10cSrcweir                 break;
227*cdf0e10cSrcweir             case view::PaperFormat_A4:
228*cdf0e10cSrcweir                 eRet = PAPER_A4;
229*cdf0e10cSrcweir                 break;
230*cdf0e10cSrcweir             case view::PaperFormat_A5:
231*cdf0e10cSrcweir                 eRet = PAPER_A5;
232*cdf0e10cSrcweir                 break;
233*cdf0e10cSrcweir             case view::PaperFormat_B4:
234*cdf0e10cSrcweir                 eRet = PAPER_B4_ISO;
235*cdf0e10cSrcweir                 break;
236*cdf0e10cSrcweir             case view::PaperFormat_B5:
237*cdf0e10cSrcweir                 eRet = PAPER_B5_ISO;
238*cdf0e10cSrcweir                 break;
239*cdf0e10cSrcweir             case view::PaperFormat_LETTER:
240*cdf0e10cSrcweir                 eRet = PAPER_LETTER;
241*cdf0e10cSrcweir                 break;
242*cdf0e10cSrcweir             case view::PaperFormat_LEGAL:
243*cdf0e10cSrcweir                 eRet = PAPER_LEGAL;
244*cdf0e10cSrcweir                 break;
245*cdf0e10cSrcweir             case view::PaperFormat_TABLOID:
246*cdf0e10cSrcweir                 eRet = PAPER_TABLOID;
247*cdf0e10cSrcweir                 break;
248*cdf0e10cSrcweir             case view::PaperFormat_USER:
249*cdf0e10cSrcweir                 eRet = PAPER_USER;
250*cdf0e10cSrcweir                 break;
251*cdf0e10cSrcweir             case view::PaperFormat_MAKE_FIXED_SIZE:
252*cdf0e10cSrcweir                 break;
253*cdf0e10cSrcweir             //deliberate no default to force warn on a new papersize
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir         return eRet;
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir //________________________________________________________________________________________________________
260*cdf0e10cSrcweir //	XPrintable
261*cdf0e10cSrcweir //________________________________________________________________________________________________________
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SAL_CALL SfxPrintHelper::getPrinter() throw(::com::sun::star::uno::RuntimeException)
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     // object already disposed?
266*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     // search for any view of this document that is currently printing
269*cdf0e10cSrcweir     const Printer *pPrinter = NULL;
270*cdf0e10cSrcweir     SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ? SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0;
271*cdf0e10cSrcweir     SfxViewFrame* pFirst = pViewFrm;
272*cdf0e10cSrcweir     while ( pViewFrm && !pPrinter )
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir     	pPrinter = pViewFrm->GetViewShell()->GetActivePrinter();
275*cdf0e10cSrcweir         pViewFrm = SfxViewFrame::GetNext( *pViewFrm, m_pData->m_pObjectShell, sal_False );
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     // if no view is printing currently, use the permanent SfxPrinter instance
279*cdf0e10cSrcweir     if ( !pPrinter && pFirst )
280*cdf0e10cSrcweir     	pPrinter = pFirst->GetViewShell()->GetPrinter(sal_True);
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     if ( !pPrinter )
283*cdf0e10cSrcweir         return uno::Sequence< beans::PropertyValue >();
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aPrinter(8);
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	aPrinter.getArray()[7].Name = DEFINE_CONST_UNICODE( "CanSetPaperSize" );
288*cdf0e10cSrcweir 	aPrinter.getArray()[7].Value <<= ( pPrinter->HasSupport( SUPPORT_SET_PAPERSIZE ) );
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 	aPrinter.getArray()[6].Name = DEFINE_CONST_UNICODE( "CanSetPaperFormat" );
291*cdf0e10cSrcweir 	aPrinter.getArray()[6].Value <<= ( pPrinter->HasSupport( SUPPORT_SET_PAPER ) );
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 	aPrinter.getArray()[5].Name = DEFINE_CONST_UNICODE( "CanSetPaperOrientation" );
294*cdf0e10cSrcweir 	aPrinter.getArray()[5].Value <<= ( pPrinter->HasSupport( SUPPORT_SET_ORIENTATION ) );
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	aPrinter.getArray()[4].Name = DEFINE_CONST_UNICODE( "IsBusy" );
297*cdf0e10cSrcweir 	aPrinter.getArray()[4].Value <<= ( pPrinter->IsPrinting() );
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	aPrinter.getArray()[3].Name = DEFINE_CONST_UNICODE( "PaperSize" );
300*cdf0e10cSrcweir     awt::Size aSize = impl_Size_Object2Struct(pPrinter->GetPaperSize() );
301*cdf0e10cSrcweir 	aPrinter.getArray()[3].Value <<= aSize;
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	aPrinter.getArray()[2].Name = DEFINE_CONST_UNICODE( "PaperFormat" );
304*cdf0e10cSrcweir     view::PaperFormat eFormat = convertToPaperFormat(pPrinter->GetPaper());
305*cdf0e10cSrcweir 	aPrinter.getArray()[2].Value <<= eFormat;
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	aPrinter.getArray()[1].Name = DEFINE_CONST_UNICODE( "PaperOrientation" );
308*cdf0e10cSrcweir     view::PaperOrientation eOrient = (view::PaperOrientation)pPrinter->GetOrientation();
309*cdf0e10cSrcweir 	aPrinter.getArray()[1].Value <<= eOrient;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	aPrinter.getArray()[0].Name = DEFINE_CONST_UNICODE( "Name" );
312*cdf0e10cSrcweir 	String sStringTemp = pPrinter->GetName() ;
313*cdf0e10cSrcweir 	aPrinter.getArray()[0].Value <<= ::rtl::OUString( sStringTemp );
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	return aPrinter;
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir //________________________________________________________________________________________________________
319*cdf0e10cSrcweir //	XPrintable
320*cdf0e10cSrcweir //________________________________________________________________________________________________________
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir void SfxPrintHelper::impl_setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter,SfxPrinter*& pPrinter,sal_uInt16& nChangeFlags,SfxViewShell*& pViewSh)
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir 	// alten Printer beschaffen
326*cdf0e10cSrcweir 	SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ?
327*cdf0e10cSrcweir 								SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0;
328*cdf0e10cSrcweir 	if ( !pViewFrm )
329*cdf0e10cSrcweir 		return;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	pViewSh = pViewFrm->GetViewShell();
332*cdf0e10cSrcweir 	pPrinter = pViewSh->GetPrinter(sal_True);
333*cdf0e10cSrcweir 	if ( !pPrinter )
334*cdf0e10cSrcweir 		return;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	// new Printer-Name available?
337*cdf0e10cSrcweir 	nChangeFlags = 0;
338*cdf0e10cSrcweir     sal_Int32 lDummy = 0;
339*cdf0e10cSrcweir 	for ( int n = 0; n < rPrinter.getLength(); ++n )
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		// get Property-Value from printer description
342*cdf0e10cSrcweir         const beans::PropertyValue &rProp = rPrinter.getConstArray()[n];
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 		// Name-Property?
345*cdf0e10cSrcweir 		if ( rProp.Name.compareToAscii( "Name" ) == 0 )
346*cdf0e10cSrcweir 		{
347*cdf0e10cSrcweir 			::rtl::OUString sTemp;
348*cdf0e10cSrcweir             if ( ( rProp.Value >>= sTemp ) == sal_False )
349*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 			String aPrinterName( sTemp ) ;
352*cdf0e10cSrcweir             if ( aPrinterName != pPrinter->GetName() )
353*cdf0e10cSrcweir             {
354*cdf0e10cSrcweir                 pPrinter = new SfxPrinter( pPrinter->GetOptions().Clone(), aPrinterName );
355*cdf0e10cSrcweir                 nChangeFlags = SFX_PRINTER_PRINTER;
356*cdf0e10cSrcweir             }
357*cdf0e10cSrcweir 			break;
358*cdf0e10cSrcweir 		}
359*cdf0e10cSrcweir 	}
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 	Size aSetPaperSize( 0, 0);
362*cdf0e10cSrcweir     view::PaperFormat nPaperFormat = view::PaperFormat_USER;
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     // other properties
365*cdf0e10cSrcweir 	for ( int i = 0; i < rPrinter.getLength(); ++i )
366*cdf0e10cSrcweir 	{
367*cdf0e10cSrcweir 		// get Property-Value from printer description
368*cdf0e10cSrcweir         const beans::PropertyValue &rProp = rPrinter.getConstArray()[i];
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 		// PaperOrientation-Property?
371*cdf0e10cSrcweir 		if ( rProp.Name.compareToAscii( "PaperOrientation" ) == 0 )
372*cdf0e10cSrcweir 		{
373*cdf0e10cSrcweir             view::PaperOrientation eOrient;
374*cdf0e10cSrcweir             if ( ( rProp.Value >>= eOrient ) == sal_False )
375*cdf0e10cSrcweir             {
376*cdf0e10cSrcweir                 if ( ( rProp.Value >>= lDummy ) == sal_False )
377*cdf0e10cSrcweir                     throw ::com::sun::star::lang::IllegalArgumentException();
378*cdf0e10cSrcweir                 eOrient = ( view::PaperOrientation) lDummy;
379*cdf0e10cSrcweir             }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir             if ( (Orientation) eOrient != pPrinter->GetOrientation() )
382*cdf0e10cSrcweir             {
383*cdf0e10cSrcweir                 pPrinter->SetOrientation( (Orientation) eOrient );
384*cdf0e10cSrcweir                 nChangeFlags |= SFX_PRINTER_CHG_ORIENTATION;
385*cdf0e10cSrcweir             }
386*cdf0e10cSrcweir 		}
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 		// PaperFormat-Property?
389*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "PaperFormat" ) == 0 )
390*cdf0e10cSrcweir 		{
391*cdf0e10cSrcweir 			if ( ( rProp.Value >>= nPaperFormat ) == sal_False )
392*cdf0e10cSrcweir             {
393*cdf0e10cSrcweir                 if ( ( rProp.Value >>= lDummy ) == sal_False )
394*cdf0e10cSrcweir                     throw ::com::sun::star::lang::IllegalArgumentException();
395*cdf0e10cSrcweir                 nPaperFormat = ( view::PaperFormat ) lDummy;
396*cdf0e10cSrcweir             }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir             if ( convertToPaper(nPaperFormat) != pPrinter->GetPaper() )
399*cdf0e10cSrcweir             {
400*cdf0e10cSrcweir                 pPrinter->SetPaper( convertToPaper(nPaperFormat) );
401*cdf0e10cSrcweir                 nChangeFlags |= SFX_PRINTER_CHG_SIZE;
402*cdf0e10cSrcweir             }
403*cdf0e10cSrcweir 		}
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 		// PaperSize-Property?
406*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "PaperSize" ) == 0 )
407*cdf0e10cSrcweir 		{
408*cdf0e10cSrcweir             awt::Size aTempSize ;
409*cdf0e10cSrcweir 			if ( ( rProp.Value >>= aTempSize ) == sal_False )
410*cdf0e10cSrcweir 			{
411*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
412*cdf0e10cSrcweir 			}
413*cdf0e10cSrcweir 			else
414*cdf0e10cSrcweir 			{
415*cdf0e10cSrcweir 				aSetPaperSize = impl_Size_Struct2Object(aTempSize);
416*cdf0e10cSrcweir 			}
417*cdf0e10cSrcweir 		}
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 		// PrinterTray-Property
420*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "PrinterPaperTray" ) == 0 )
421*cdf0e10cSrcweir 		{
422*cdf0e10cSrcweir 			rtl::OUString aTmp;
423*cdf0e10cSrcweir 			if ( ( rProp.Value >>= aTmp ) == sal_False )
424*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
425*cdf0e10cSrcweir 			sal_uInt16 nCount = pPrinter->GetPaperBinCount();
426*cdf0e10cSrcweir             for (sal_uInt16 nBin=0; nBin<nCount; nBin++)
427*cdf0e10cSrcweir 			{
428*cdf0e10cSrcweir                 ::rtl::OUString aName( pPrinter->GetPaperBinName(nBin) );
429*cdf0e10cSrcweir 				if ( aName == aTmp )
430*cdf0e10cSrcweir 				{
431*cdf0e10cSrcweir                     pPrinter->SetPaperBin(nBin);
432*cdf0e10cSrcweir 					break;
433*cdf0e10cSrcweir 				}
434*cdf0e10cSrcweir 			}
435*cdf0e10cSrcweir 		}
436*cdf0e10cSrcweir 	}
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 	//os 12.11.98: die PaperSize darf nur gesetzt werden, wenn tatsaechlich
439*cdf0e10cSrcweir 	//PAPER_USER gilt, sonst koennte vom Treiber ein falsches Format gewaehlt werden
440*cdf0e10cSrcweir     if(nPaperFormat == view::PaperFormat_USER && aSetPaperSize.Width())
441*cdf0e10cSrcweir 	{
442*cdf0e10cSrcweir 		//JP 23.09.98 - Bug 56929 - MapMode von 100mm in die am
443*cdf0e10cSrcweir 		//			Device gesetzten umrechnen. Zusaetzlich nur dann
444*cdf0e10cSrcweir 		//			setzen, wenn sie wirklich veraendert wurden.
445*cdf0e10cSrcweir 		aSetPaperSize = pPrinter->LogicToPixel( aSetPaperSize, MAP_100TH_MM );
446*cdf0e10cSrcweir 		if( aSetPaperSize != pPrinter->GetPaperSizePixel() )
447*cdf0e10cSrcweir 		{
448*cdf0e10cSrcweir 			pPrinter->SetPaperSizeUser( pPrinter->PixelToLogic( aSetPaperSize ) );
449*cdf0e10cSrcweir 			nChangeFlags |= SFX_PRINTER_CHG_SIZE;
450*cdf0e10cSrcweir 		}
451*cdf0e10cSrcweir 	}
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir     // #96772#: wait until printing is done
454*cdf0e10cSrcweir     SfxPrinter* pDocPrinter = pViewSh->GetPrinter();
455*cdf0e10cSrcweir     while ( pDocPrinter->IsPrinting() )
456*cdf0e10cSrcweir         Application::Yield();
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir void SAL_CALL SfxPrintHelper::setPrinter(const uno::Sequence< beans::PropertyValue >& rPrinter)
460*cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir 	// object already disposed?
463*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 	SfxViewShell* pViewSh = NULL;
466*cdf0e10cSrcweir 	SfxPrinter* pPrinter = NULL;
467*cdf0e10cSrcweir 	sal_uInt16 nChangeFlags = 0;
468*cdf0e10cSrcweir 	impl_setPrinter(rPrinter,pPrinter,nChangeFlags,pViewSh);
469*cdf0e10cSrcweir 	// set new printer
470*cdf0e10cSrcweir 	if ( pViewSh && pPrinter )
471*cdf0e10cSrcweir         pViewSh->SetPrinter( pPrinter, nChangeFlags, false );
472*cdf0e10cSrcweir }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir //________________________________________________________________________________________________________
475*cdf0e10cSrcweir //  ImplPrintWatch thread for asynchronous printing with moving temp. file to ucb location
476*cdf0e10cSrcweir //________________________________________________________________________________________________________
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir /* This implements a thread which will be started to wait for asynchronous
479*cdf0e10cSrcweir    print jobs to temp. localy files. If they finish we move the temp. files
480*cdf0e10cSrcweir    to her right locations by using the ucb.
481*cdf0e10cSrcweir  */
482*cdf0e10cSrcweir class ImplUCBPrintWatcher : public ::osl::Thread
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir     private:
485*cdf0e10cSrcweir         /// of course we must know the printer which execute the job
486*cdf0e10cSrcweir         SfxPrinter* m_pPrinter;
487*cdf0e10cSrcweir         /// this describes the target location for the printed temp file
488*cdf0e10cSrcweir         String m_sTargetURL;
489*cdf0e10cSrcweir         /// it holds the temp file alive, till the print job will finish and remove it from disk automaticly if the object die
490*cdf0e10cSrcweir         ::utl::TempFile* m_pTempFile;
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir     public:
493*cdf0e10cSrcweir         /* initialize this watcher but don't start it */
494*cdf0e10cSrcweir         ImplUCBPrintWatcher( SfxPrinter* pPrinter, ::utl::TempFile* pTempFile, const String& sTargetURL )
495*cdf0e10cSrcweir                 : m_pPrinter  ( pPrinter   )
496*cdf0e10cSrcweir                 , m_sTargetURL( sTargetURL )
497*cdf0e10cSrcweir                 , m_pTempFile ( pTempFile  )
498*cdf0e10cSrcweir         {}
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir         /* waits for finishing of the print job and moves the temp file afterwards
501*cdf0e10cSrcweir            Note: Starting of the job is done outside this thread!
502*cdf0e10cSrcweir            But we have to free some of the given ressources on heap!
503*cdf0e10cSrcweir          */
504*cdf0e10cSrcweir         void SAL_CALL run()
505*cdf0e10cSrcweir         {
506*cdf0e10cSrcweir             /* SAFE { */
507*cdf0e10cSrcweir             {
508*cdf0e10cSrcweir                 ::vos::OGuard aGuard( Application::GetSolarMutex() );
509*cdf0e10cSrcweir                 while( m_pPrinter->IsPrinting() )
510*cdf0e10cSrcweir                     Application::Yield();
511*cdf0e10cSrcweir                 m_pPrinter = NULL; // don't delete it! It's borrowed only :-)
512*cdf0e10cSrcweir             }
513*cdf0e10cSrcweir             /* } SAFE */
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir             // lock for further using of our member isn't neccessary - because
516*cdf0e10cSrcweir             // we truns alone by defenition. Nobody join for us nor use us ...
517*cdf0e10cSrcweir             ImplUCBPrintWatcher::moveAndDeleteTemp(&m_pTempFile,m_sTargetURL);
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir             // finishing of this run() method will call onTerminate() automaticly
520*cdf0e10cSrcweir             // kill this thread there!
521*cdf0e10cSrcweir         }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir         /* nobody wait for this thread. We must kill ourself ...
524*cdf0e10cSrcweir          */
525*cdf0e10cSrcweir         void SAL_CALL onTerminated()
526*cdf0e10cSrcweir         {
527*cdf0e10cSrcweir             delete this;
528*cdf0e10cSrcweir         }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir         /* static helper to move the temp. file to the target location by using the ucb
531*cdf0e10cSrcweir            It's static to be useable from outside too. So it's not realy neccessary to start
532*cdf0e10cSrcweir            the thread, if finishing of the job was detected outside this thread.
533*cdf0e10cSrcweir            But it must be called without using a corresponding thread for the given parameter!
534*cdf0e10cSrcweir          */
535*cdf0e10cSrcweir         static void moveAndDeleteTemp( ::utl::TempFile** ppTempFile, const String& sTargetURL )
536*cdf0e10cSrcweir         {
537*cdf0e10cSrcweir             // move the file
538*cdf0e10cSrcweir             try
539*cdf0e10cSrcweir             {
540*cdf0e10cSrcweir 				INetURLObject aSplitter(sTargetURL);
541*cdf0e10cSrcweir 				String		  sFileName = aSplitter.getName(
542*cdf0e10cSrcweir 											INetURLObject::LAST_SEGMENT,
543*cdf0e10cSrcweir 											true,
544*cdf0e10cSrcweir 											INetURLObject::DECODE_WITH_CHARSET);
545*cdf0e10cSrcweir 				if (aSplitter.removeSegment() && sFileName.Len()>0)
546*cdf0e10cSrcweir 				{
547*cdf0e10cSrcweir 					::ucbhelper::Content aSource(
548*cdf0e10cSrcweir 							::rtl::OUString((*ppTempFile)->GetURL()),
549*cdf0e10cSrcweir 							::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >());
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir 					::ucbhelper::Content aTarget(
552*cdf0e10cSrcweir 							::rtl::OUString(aSplitter.GetMainURL(INetURLObject::NO_DECODE)),
553*cdf0e10cSrcweir 							::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >());
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 					aTarget.transferContent(
556*cdf0e10cSrcweir 							aSource,
557*cdf0e10cSrcweir 							::ucbhelper::InsertOperation_COPY,
558*cdf0e10cSrcweir 							::rtl::OUString(sFileName),
559*cdf0e10cSrcweir 							::com::sun::star::ucb::NameClash::OVERWRITE);
560*cdf0e10cSrcweir 				}
561*cdf0e10cSrcweir             }
562*cdf0e10cSrcweir             catch( ::com::sun::star::ucb::ContentCreationException& ) { DBG_ERROR("content create exception"); }
563*cdf0e10cSrcweir             catch( ::com::sun::star::ucb::CommandAbortedException&  ) { DBG_ERROR("command abort exception"); }
564*cdf0e10cSrcweir             catch( ::com::sun::star::uno::RuntimeException&         ) { DBG_ERROR("runtime exception"); }
565*cdf0e10cSrcweir             catch( ::com::sun::star::uno::Exception&                ) { DBG_ERROR("unknown exception"); }
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir             // kill the temp file!
568*cdf0e10cSrcweir             delete *ppTempFile;
569*cdf0e10cSrcweir             *ppTempFile = NULL;
570*cdf0e10cSrcweir         }
571*cdf0e10cSrcweir };
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir //------------------------------------------------
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir //________________________________________________________________________________________________________
576*cdf0e10cSrcweir //  XPrintable
577*cdf0e10cSrcweir //________________________________________________________________________________________________________
578*cdf0e10cSrcweir void SAL_CALL SfxPrintHelper::print(const uno::Sequence< beans::PropertyValue >& rOptions)
579*cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
580*cdf0e10cSrcweir {
581*cdf0e10cSrcweir     if( Application::GetSettings().GetMiscSettings().GetDisablePrinting() )
582*cdf0e10cSrcweir         return;
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 	// object already disposed?
585*cdf0e10cSrcweir 	// object already disposed?
586*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 	// get view for sfx printing capabilities
589*cdf0e10cSrcweir 	SfxViewFrame *pViewFrm = m_pData->m_pObjectShell.Is() ?
590*cdf0e10cSrcweir 								SfxViewFrame::GetFirst( m_pData->m_pObjectShell, sal_False ) : 0;
591*cdf0e10cSrcweir 	if ( !pViewFrm )
592*cdf0e10cSrcweir 		return;
593*cdf0e10cSrcweir 	SfxViewShell* pView = pViewFrm->GetViewShell();
594*cdf0e10cSrcweir 	if ( !pView )
595*cdf0e10cSrcweir 		return;
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir //	SfxAllItemSet aArgs( pView->GetPool() );
598*cdf0e10cSrcweir     sal_Bool bMonitor = sal_False;
599*cdf0e10cSrcweir     // We need this information at the end of this method, if we start the vcl printer
600*cdf0e10cSrcweir     // by executing the slot. Because if it is a ucb relevant URL we must wait for
601*cdf0e10cSrcweir     // finishing the print job and move the temporary local file by using the ucb
602*cdf0e10cSrcweir     // to the right location. But in case of no file name is given or it is already
603*cdf0e10cSrcweir     // a local one we can supress this special handling. Because then vcl makes all
604*cdf0e10cSrcweir     // right for us.
605*cdf0e10cSrcweir     String sUcbUrl;
606*cdf0e10cSrcweir     ::utl::TempFile* pUCBPrintTempFile = NULL;
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 	uno::Sequence < beans::PropertyValue > aCheckedArgs( rOptions.getLength() );
609*cdf0e10cSrcweir 	sal_Int32 nProps = 0;
610*cdf0e10cSrcweir 	sal_Bool  bWaitUntilEnd = sal_False;
611*cdf0e10cSrcweir     sal_Int16 nDuplexMode = ::com::sun::star::view::DuplexMode::UNKNOWN;
612*cdf0e10cSrcweir 	for ( int n = 0; n < rOptions.getLength(); ++n )
613*cdf0e10cSrcweir 	{
614*cdf0e10cSrcweir 		// get Property-Value from options
615*cdf0e10cSrcweir         const beans::PropertyValue &rProp = rOptions.getConstArray()[n];
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 		// FileName-Property?
618*cdf0e10cSrcweir 		if ( rProp.Name.compareToAscii( "FileName" ) == 0 )
619*cdf0e10cSrcweir 		{
620*cdf0e10cSrcweir             // unpack th URL and check for a valid and well known protocol
621*cdf0e10cSrcweir             ::rtl::OUString sTemp;
622*cdf0e10cSrcweir             if (
623*cdf0e10cSrcweir                 ( rProp.Value.getValueType()!=::getCppuType((const ::rtl::OUString*)0))  ||
624*cdf0e10cSrcweir                 (!(rProp.Value>>=sTemp))
625*cdf0e10cSrcweir                )
626*cdf0e10cSrcweir             {
627*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
628*cdf0e10cSrcweir             }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir             String        sPath        ;
631*cdf0e10cSrcweir             String        sURL  (sTemp);
632*cdf0e10cSrcweir             INetURLObject aCheck(sURL );
633*cdf0e10cSrcweir             if (aCheck.GetProtocol()==INET_PROT_NOT_VALID)
634*cdf0e10cSrcweir             {
635*cdf0e10cSrcweir                 // OK - it's not a valid URL. But may it's a simple
636*cdf0e10cSrcweir                 // system path directly. It will be supported for historical
637*cdf0e10cSrcweir                 // reasons. Otherwhise we break to much external code ...
638*cdf0e10cSrcweir                 // We try to convert it to a file URL. If its possible
639*cdf0e10cSrcweir                 // we put the system path to the item set and let vcl work with it.
640*cdf0e10cSrcweir                 // No ucb or thread will be neccessary then. In case it couldnt be
641*cdf0e10cSrcweir                 // converted its not an URL nor a system path. Then we can't accept
642*cdf0e10cSrcweir                 // this parameter and have to throw an exception.
643*cdf0e10cSrcweir                 ::rtl::OUString sSystemPath(sTemp);
644*cdf0e10cSrcweir                 ::rtl::OUString sFileURL;
645*cdf0e10cSrcweir                 if (::osl::FileBase::getFileURLFromSystemPath(sSystemPath,sFileURL)!=::osl::FileBase::E_None)
646*cdf0e10cSrcweir                     throw ::com::sun::star::lang::IllegalArgumentException();
647*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rProp.Name;
648*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= sFileURL;
649*cdf0e10cSrcweir                 // and append the local filename
650*cdf0e10cSrcweir                 aCheckedArgs.realloc( aCheckedArgs.getLength()+1 );
651*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("LocalFileName");
652*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= ::rtl::OUString( sTemp );
653*cdf0e10cSrcweir             }
654*cdf0e10cSrcweir             else
655*cdf0e10cSrcweir             // It's a valid URL. but now we must know, if it is a local one or not.
656*cdf0e10cSrcweir             // It's a question of using ucb or not!
657*cdf0e10cSrcweir             if (::utl::LocalFileHelper::ConvertURLToSystemPath(sURL,sPath))
658*cdf0e10cSrcweir             {
659*cdf0e10cSrcweir                 // it's a local file, we can use vcl without special handling
660*cdf0e10cSrcweir                 // And we have to use the system notation of the incoming URL.
661*cdf0e10cSrcweir                 // But it into the descriptor and let the slot be executed at
662*cdf0e10cSrcweir                 // the end of this method.
663*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rProp.Name;
664*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= sTemp;
665*cdf0e10cSrcweir                 // and append the local filename
666*cdf0e10cSrcweir                 aCheckedArgs.realloc( aCheckedArgs.getLength()+1 );
667*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("LocalFileName");
668*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= ::rtl::OUString( sPath );
669*cdf0e10cSrcweir             }
670*cdf0e10cSrcweir             else
671*cdf0e10cSrcweir             {
672*cdf0e10cSrcweir                 // it's an ucb target. So we must use a temp. file for vcl
673*cdf0e10cSrcweir                 // and move it after printing by using the ucb.
674*cdf0e10cSrcweir                 // Create a temp file on the heap (because it must delete the
675*cdf0e10cSrcweir                 // real file on disk automaticly if it die - bt we have to share it with
676*cdf0e10cSrcweir                 // some other sources ... e.g. the ImplUCBPrintWatcher).
677*cdf0e10cSrcweir                 // And we put the name of this temp file to the descriptor instead
678*cdf0e10cSrcweir                 // of the URL. The URL we save for later using seperatly.
679*cdf0e10cSrcweir                 // Execution of the print job will be done later by executing
680*cdf0e10cSrcweir                 // a slot ...
681*cdf0e10cSrcweir                 pUCBPrintTempFile = new ::utl::TempFile();
682*cdf0e10cSrcweir                 pUCBPrintTempFile->EnableKillingFile();
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir 				//FIXME: does it work?
685*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("LocalFileName");
686*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= ::rtl::OUString( pUCBPrintTempFile->GetFileName() );
687*cdf0e10cSrcweir                 sUcbUrl = sURL;
688*cdf0e10cSrcweir             }
689*cdf0e10cSrcweir 		}
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir 		// CopyCount-Property
692*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "CopyCount" ) == 0 )
693*cdf0e10cSrcweir 		{
694*cdf0e10cSrcweir 			sal_Int32 nCopies = 0;
695*cdf0e10cSrcweir 			if ( ( rProp.Value >>= nCopies ) == sal_False )
696*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 			aCheckedArgs[nProps].Name = rProp.Name;
699*cdf0e10cSrcweir 			aCheckedArgs[nProps++].Value <<= nCopies;
700*cdf0e10cSrcweir 		}
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 		// Collate-Property
703*cdf0e10cSrcweir 		// Sort-Property (deprecated)
704*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "Collate" ) == 0 ||
705*cdf0e10cSrcweir 			    ( rProp.Name.compareToAscii( "Sort" ) == 0 ) )
706*cdf0e10cSrcweir 		{
707*cdf0e10cSrcweir             sal_Bool bTemp = sal_Bool();
708*cdf0e10cSrcweir             if ( rProp.Value >>= bTemp )
709*cdf0e10cSrcweir 			{
710*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rtl::OUString::createFromAscii("Collate");
711*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= bTemp;
712*cdf0e10cSrcweir 			}
713*cdf0e10cSrcweir 			else
714*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
715*cdf0e10cSrcweir 		}
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir 		// Pages-Property
718*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "Pages" ) == 0 )
719*cdf0e10cSrcweir 		{
720*cdf0e10cSrcweir             ::rtl::OUString sTemp;
721*cdf0e10cSrcweir             if( rProp.Value >>= sTemp )
722*cdf0e10cSrcweir 			{
723*cdf0e10cSrcweir 				aCheckedArgs[nProps].Name = rProp.Name;
724*cdf0e10cSrcweir 				aCheckedArgs[nProps++].Value <<= sTemp;
725*cdf0e10cSrcweir 			}
726*cdf0e10cSrcweir 			else
727*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
728*cdf0e10cSrcweir 		}
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir 		// MonitorVisible
731*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "MonitorVisible" ) == 0 )
732*cdf0e10cSrcweir 		{
733*cdf0e10cSrcweir             if( !(rProp.Value >>= bMonitor) )
734*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
735*cdf0e10cSrcweir 			aCheckedArgs[nProps].Name = rProp.Name;
736*cdf0e10cSrcweir 			aCheckedArgs[nProps++].Value <<= bMonitor;
737*cdf0e10cSrcweir 		}
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 		// Wait
740*cdf0e10cSrcweir 		else if ( rProp.Name.compareToAscii( "Wait" ) == 0 )
741*cdf0e10cSrcweir 		{
742*cdf0e10cSrcweir             if ( !(rProp.Value >>= bWaitUntilEnd) )
743*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
744*cdf0e10cSrcweir 			aCheckedArgs[nProps].Name = rProp.Name;
745*cdf0e10cSrcweir 			aCheckedArgs[nProps++].Value <<= bWaitUntilEnd;
746*cdf0e10cSrcweir 		}
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir         else if ( rProp.Name.compareToAscii( "DuplexMode" ) == 0 )
749*cdf0e10cSrcweir         {
750*cdf0e10cSrcweir             if ( !(rProp.Value >>= nDuplexMode ) )
751*cdf0e10cSrcweir                 throw ::com::sun::star::lang::IllegalArgumentException();
752*cdf0e10cSrcweir             aCheckedArgs[nProps].Name = rProp.Name;
753*cdf0e10cSrcweir             aCheckedArgs[nProps++].Value <<= nDuplexMode;
754*cdf0e10cSrcweir         }
755*cdf0e10cSrcweir 	}
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir 	if ( nProps != aCheckedArgs.getLength() )
758*cdf0e10cSrcweir 		aCheckedArgs.realloc(nProps);
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir     // Execute the print request every time.
761*cdf0e10cSrcweir     // It doesn'tmatter if it is a real printer used or we print to a local file
762*cdf0e10cSrcweir     // nor if we print to a temp file and move it afterwards by using the ucb.
763*cdf0e10cSrcweir     // That will be handled later. see pUCBPrintFile below!
764*cdf0e10cSrcweir 	pView->ExecPrint( aCheckedArgs, sal_True, sal_False );
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir     // Ok - may be execution before has finished (or started!) printing.
767*cdf0e10cSrcweir     // And may it was a printing to a file.
768*cdf0e10cSrcweir     // Now we have to check if we can move the file (if neccessary) via ucb to his right location.
769*cdf0e10cSrcweir     // Cases:
770*cdf0e10cSrcweir     //  a) printing finished                        => move the file directly and forget the watcher thread
771*cdf0e10cSrcweir     //  b) printing is asynchron and runs currently => start watcher thread and exit this method
772*cdf0e10cSrcweir     //                                                 This thread make all neccessary things by itself.
773*cdf0e10cSrcweir     if (pUCBPrintTempFile!=NULL)
774*cdf0e10cSrcweir     {
775*cdf0e10cSrcweir         // a)
776*cdf0e10cSrcweir         SfxPrinter* pPrinter = pView->GetPrinter();
777*cdf0e10cSrcweir         if ( ! pPrinter->IsPrinting() )
778*cdf0e10cSrcweir             ImplUCBPrintWatcher::moveAndDeleteTemp(&pUCBPrintTempFile,sUcbUrl);
779*cdf0e10cSrcweir         // b)
780*cdf0e10cSrcweir         else
781*cdf0e10cSrcweir         {
782*cdf0e10cSrcweir             // Note: we create(d) some ressource on the heap. (thread and tep file)
783*cdf0e10cSrcweir             // They will be delected by the thread automaticly if he finish his run() method.
784*cdf0e10cSrcweir             ImplUCBPrintWatcher* pWatcher = new ImplUCBPrintWatcher( pPrinter, pUCBPrintTempFile, sUcbUrl );
785*cdf0e10cSrcweir             pWatcher->create();
786*cdf0e10cSrcweir         }
787*cdf0e10cSrcweir     }
788*cdf0e10cSrcweir }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir void IMPL_PrintListener_DataContainer::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
791*cdf0e10cSrcweir {
792*cdf0e10cSrcweir     if ( &rBC == m_pObjectShell )
793*cdf0e10cSrcweir 	{
794*cdf0e10cSrcweir 		SfxPrintingHint* pPrintHint = PTR_CAST( SfxPrintingHint, &rHint );
795*cdf0e10cSrcweir 		if ( pPrintHint )
796*cdf0e10cSrcweir 		{
797*cdf0e10cSrcweir 			if ( pPrintHint->GetWhich() == com::sun::star::view::PrintableState_JOB_STARTED )
798*cdf0e10cSrcweir 			{
799*cdf0e10cSrcweir                 if ( !m_xPrintJob.is() )
800*cdf0e10cSrcweir                     m_xPrintJob = new SfxPrintJob_Impl( this );
801*cdf0e10cSrcweir 				m_aPrintOptions = pPrintHint->GetOptions();
802*cdf0e10cSrcweir 			}
803*cdf0e10cSrcweir             else if ( pPrintHint->GetWhich() != -2 )    // -2 : CancelPrintJob
804*cdf0e10cSrcweir 			{
805*cdf0e10cSrcweir 				view::PrintJobEvent aEvent;
806*cdf0e10cSrcweir                 aEvent.Source = m_xPrintJob;
807*cdf0e10cSrcweir 				aEvent.State = (com::sun::star::view::PrintableState) pPrintHint->GetWhich();
808*cdf0e10cSrcweir                 ::cppu::OInterfaceContainerHelper* pContainer = m_aInterfaceContainer.getContainer( ::getCppuType( ( const uno::Reference< view::XPrintJobListener >*) NULL ) );
809*cdf0e10cSrcweir 			    if ( pContainer!=NULL )
810*cdf0e10cSrcweir 				{
811*cdf0e10cSrcweir 			        ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
812*cdf0e10cSrcweir 			        while (pIterator.hasMoreElements())
813*cdf0e10cSrcweir 						((view::XPrintJobListener*)pIterator.next())->printJobEvent( aEvent );
814*cdf0e10cSrcweir 				}
815*cdf0e10cSrcweir 			}
816*cdf0e10cSrcweir 		}
817*cdf0e10cSrcweir 	}
818*cdf0e10cSrcweir }
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir void SAL_CALL SfxPrintHelper::addPrintJobListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XPrintJobListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
821*cdf0e10cSrcweir {
822*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
823*cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.addInterface( ::getCppuType((const uno::Reference < view::XPrintJobListener>*)0), xListener );
824*cdf0e10cSrcweir }
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir void SAL_CALL SfxPrintHelper::removePrintJobListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XPrintJobListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
827*cdf0e10cSrcweir {
828*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
829*cdf0e10cSrcweir     m_pData->m_aInterfaceContainer.removeInterface( ::getCppuType((const uno::Reference < view::XPrintJobListener>*)0), xListener );
830*cdf0e10cSrcweir }
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir 
833