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