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