1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp> 32cdf0e10cSrcweir #include <com/sun/star/view/PrintableState.hpp> 33cdf0e10cSrcweir #include "com/sun/star/view/XRenderable.hpp" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <svl/itempool.hxx> 36cdf0e10cSrcweir #include <vcl/msgbox.hxx> 37cdf0e10cSrcweir #include <svtools/prnsetup.hxx> 38cdf0e10cSrcweir #include <svl/flagitem.hxx> 39cdf0e10cSrcweir #include <svl/stritem.hxx> 40cdf0e10cSrcweir #include <svl/intitem.hxx> 41cdf0e10cSrcweir #include <svl/eitem.hxx> 42cdf0e10cSrcweir #include <sfx2/app.hxx> 43cdf0e10cSrcweir #include <unotools/useroptions.hxx> 44cdf0e10cSrcweir #include <unotools/printwarningoptions.hxx> 45cdf0e10cSrcweir #include <tools/datetime.hxx> 46cdf0e10cSrcweir #include <sfx2/bindings.hxx> 47cdf0e10cSrcweir #include <sfx2/objface.hxx> 48cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 49cdf0e10cSrcweir #include "viewimp.hxx" 50cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 51cdf0e10cSrcweir #include <sfx2/prnmon.hxx> 52cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 53cdf0e10cSrcweir #include <sfx2/request.hxx> 54cdf0e10cSrcweir #include <sfx2/objsh.hxx> 55cdf0e10cSrcweir #include "sfxtypes.hxx" 56cdf0e10cSrcweir #include <sfx2/event.hxx> 57cdf0e10cSrcweir #include <sfx2/docfile.hxx> 58cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 59cdf0e10cSrcweir 60cdf0e10cSrcweir #include "toolkit/awt/vclxdevice.hxx" 61cdf0e10cSrcweir 62cdf0e10cSrcweir #include "view.hrc" 63cdf0e10cSrcweir #include "helpid.hrc" 64cdf0e10cSrcweir 65cdf0e10cSrcweir using namespace com::sun::star; 66cdf0e10cSrcweir using namespace com::sun::star::uno; 67cdf0e10cSrcweir 68cdf0e10cSrcweir TYPEINIT1(SfxPrintingHint, SfxHint); 69cdf0e10cSrcweir 70cdf0e10cSrcweir // ----------------------------------------------------------------------- 71cdf0e10cSrcweir class SfxPrinterController : public vcl::PrinterController, public SfxListener 72cdf0e10cSrcweir { 73cdf0e10cSrcweir Any maCompleteSelection; 74cdf0e10cSrcweir Any maSelection; 75cdf0e10cSrcweir Reference< view::XRenderable > mxRenderable; 76cdf0e10cSrcweir mutable Printer* mpLastPrinter; 77cdf0e10cSrcweir mutable Reference<awt::XDevice> mxDevice; 78cdf0e10cSrcweir SfxViewShell* mpViewShell; 79cdf0e10cSrcweir SfxObjectShell* mpObjectShell; 80cdf0e10cSrcweir sal_Bool m_bOrigStatus; 81cdf0e10cSrcweir sal_Bool m_bNeedsChange; 82cdf0e10cSrcweir sal_Bool m_bApi; 83cdf0e10cSrcweir sal_Bool m_bTempPrinter; 84cdf0e10cSrcweir util::DateTime m_aLastPrinted; 85cdf0e10cSrcweir ::rtl::OUString m_aLastPrintedBy; 86cdf0e10cSrcweir 87cdf0e10cSrcweir Sequence< beans::PropertyValue > getMergedOptions() const; 88cdf0e10cSrcweir const Any& getSelectionObject() const; 89cdf0e10cSrcweir public: 90cdf0e10cSrcweir SfxPrinterController( const boost::shared_ptr<Printer>& i_rPrinter, 91cdf0e10cSrcweir const Any& i_rComplete, 92cdf0e10cSrcweir const Any& i_rSelection, 93cdf0e10cSrcweir const Any& i_rViewProp, 94cdf0e10cSrcweir const Reference< view::XRenderable >& i_xRender, 95cdf0e10cSrcweir sal_Bool i_bApi, sal_Bool i_bDirect, 96cdf0e10cSrcweir SfxViewShell* pView, 97cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rProps 98cdf0e10cSrcweir ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir virtual ~SfxPrinterController(); 101cdf0e10cSrcweir virtual void Notify( SfxBroadcaster&, const SfxHint& ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir virtual int getPageCount() const; 104cdf0e10cSrcweir virtual Sequence< beans::PropertyValue > getPageParameters( int i_nPage ) const; 105cdf0e10cSrcweir virtual void printPage( int i_nPage ) const; 106cdf0e10cSrcweir virtual void jobStarted(); 107cdf0e10cSrcweir virtual void jobFinished( com::sun::star::view::PrintableState ); 108cdf0e10cSrcweir }; 109cdf0e10cSrcweir 110cdf0e10cSrcweir SfxPrinterController::SfxPrinterController( const boost::shared_ptr<Printer>& i_rPrinter, 111cdf0e10cSrcweir const Any& i_rComplete, 112cdf0e10cSrcweir const Any& i_rSelection, 113cdf0e10cSrcweir const Any& i_rViewProp, 114cdf0e10cSrcweir const Reference< view::XRenderable >& i_xRender, 115cdf0e10cSrcweir sal_Bool i_bApi, sal_Bool i_bDirect, 116cdf0e10cSrcweir SfxViewShell* pView, 117cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rProps 118cdf0e10cSrcweir ) 119cdf0e10cSrcweir : PrinterController( i_rPrinter) 120cdf0e10cSrcweir , maCompleteSelection( i_rComplete ) 121cdf0e10cSrcweir , maSelection( i_rSelection ) 122cdf0e10cSrcweir , mxRenderable( i_xRender ) 123cdf0e10cSrcweir , mpLastPrinter( NULL ) 124cdf0e10cSrcweir , mpViewShell( pView ) 125cdf0e10cSrcweir , mpObjectShell(0) 126cdf0e10cSrcweir , m_bOrigStatus( sal_False ) 127cdf0e10cSrcweir , m_bNeedsChange( sal_False ) 128cdf0e10cSrcweir , m_bApi(i_bApi) 129cdf0e10cSrcweir , m_bTempPrinter( i_rPrinter.get() != NULL ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if ( mpViewShell ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir StartListening( *mpViewShell ); 134cdf0e10cSrcweir mpObjectShell = mpViewShell->GetObjectShell(); 135cdf0e10cSrcweir StartListening( *mpObjectShell ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir // initialize extra ui options 139cdf0e10cSrcweir if( mxRenderable.is() ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir for (sal_Int32 nProp=0; nProp<rProps.getLength(); nProp++) 142cdf0e10cSrcweir setValue( rProps[nProp].Name, rProps[nProp].Value ); 143cdf0e10cSrcweir 144cdf0e10cSrcweir Sequence< beans::PropertyValue > aRenderOptions( 3 ); 145cdf0e10cSrcweir aRenderOptions[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ExtraPrintUIOptions" ) ); 146cdf0e10cSrcweir aRenderOptions[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "View" ) ); 147cdf0e10cSrcweir aRenderOptions[1].Value = i_rViewProp; 148cdf0e10cSrcweir aRenderOptions[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsPrinter" ) ); 149cdf0e10cSrcweir aRenderOptions[2].Value <<= sal_True; 150cdf0e10cSrcweir try 151cdf0e10cSrcweir { 152cdf0e10cSrcweir Sequence< beans::PropertyValue > aRenderParms( mxRenderable->getRenderer( 0 , getSelectionObject(), aRenderOptions ) ); 153cdf0e10cSrcweir int nProps = aRenderParms.getLength(); 154cdf0e10cSrcweir for( int i = 0; i < nProps; i++ ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir if( aRenderParms[i].Name.equalsAscii( "ExtraPrintUIOptions" ) ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir Sequence< beans::PropertyValue > aUIProps; 159cdf0e10cSrcweir aRenderParms[i].Value >>= aUIProps; 160cdf0e10cSrcweir setUIOptions( aUIProps ); 161*0dccdc5dSMichael Stahl } 162*0dccdc5dSMichael Stahl else if( aRenderParms[i].Name.compareToAscii( "NUp", 3 ) == 0 ) 163*0dccdc5dSMichael Stahl { 164*0dccdc5dSMichael Stahl setValue( aRenderParms[i].Name, aRenderParms[i].Value ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir catch( lang::IllegalArgumentException& ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir // the first renderer should always be available for the UI options, 171cdf0e10cSrcweir // but catch the exception to be safe 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir // set some job parameters 176cdf0e10cSrcweir setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsApi" ) ), makeAny( i_bApi ) ); 177cdf0e10cSrcweir setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDirect" ) ), makeAny( i_bDirect ) ); 178cdf0e10cSrcweir setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsPrinter" ) ), makeAny( sal_True ) ); 179cdf0e10cSrcweir setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "View" ) ), i_rViewProp ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir void SfxPrinterController::Notify( SfxBroadcaster& , const SfxHint& rHint ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if ( rHint.IsA(TYPE(SfxSimpleHint)) ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir EndListening(*mpViewShell); 189cdf0e10cSrcweir EndListening(*mpObjectShell); 190cdf0e10cSrcweir mpViewShell = 0; 191cdf0e10cSrcweir mpObjectShell = 0; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir SfxPrinterController::~SfxPrinterController() 197cdf0e10cSrcweir { 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir const Any& SfxPrinterController::getSelectionObject() const 201cdf0e10cSrcweir { 202cdf0e10cSrcweir const beans::PropertyValue* pVal = getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintSelectionOnly" ) ) ); 203cdf0e10cSrcweir if( pVal ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir sal_Bool bSel = sal_False; 206cdf0e10cSrcweir pVal->Value >>= bSel; 207cdf0e10cSrcweir return bSel ? maSelection : maCompleteSelection; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir sal_Int32 nChoice = 0; 211cdf0e10cSrcweir pVal = getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintContent" ) ) ); 212cdf0e10cSrcweir if( pVal ) 213cdf0e10cSrcweir pVal->Value >>= nChoice; 214cdf0e10cSrcweir return (nChoice > 1) ? maSelection : maCompleteSelection; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir Sequence< beans::PropertyValue > SfxPrinterController::getMergedOptions() const 218cdf0e10cSrcweir { 219cdf0e10cSrcweir boost::shared_ptr<Printer> pPrinter( getPrinter() ); 220cdf0e10cSrcweir if( pPrinter.get() != mpLastPrinter ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir mpLastPrinter = pPrinter.get(); 223cdf0e10cSrcweir VCLXDevice* pXDevice = new VCLXDevice(); 224cdf0e10cSrcweir pXDevice->SetOutputDevice( mpLastPrinter ); 225cdf0e10cSrcweir mxDevice = Reference< awt::XDevice >( pXDevice ); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir Sequence< beans::PropertyValue > aRenderOptions( 1 ); 229cdf0e10cSrcweir aRenderOptions[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ); 230cdf0e10cSrcweir aRenderOptions[ 0 ].Value <<= mxDevice; 231cdf0e10cSrcweir 232cdf0e10cSrcweir aRenderOptions = getJobProperties( aRenderOptions ); 233cdf0e10cSrcweir return aRenderOptions; 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir int SfxPrinterController::getPageCount() const 237cdf0e10cSrcweir { 238cdf0e10cSrcweir int nPages = 0; 239cdf0e10cSrcweir boost::shared_ptr<Printer> pPrinter( getPrinter() ); 240cdf0e10cSrcweir if( mxRenderable.is() && pPrinter ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() ); 243cdf0e10cSrcweir nPages = mxRenderable->getRendererCount( getSelectionObject(), aJobOptions ); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir return nPages; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir Sequence< beans::PropertyValue > SfxPrinterController::getPageParameters( int i_nPage ) const 249cdf0e10cSrcweir { 250cdf0e10cSrcweir boost::shared_ptr<Printer> pPrinter( getPrinter() ); 251cdf0e10cSrcweir Sequence< beans::PropertyValue > aResult; 252cdf0e10cSrcweir 253cdf0e10cSrcweir if( mxRenderable.is() && pPrinter ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() ); 256cdf0e10cSrcweir try 257cdf0e10cSrcweir { 258cdf0e10cSrcweir aResult = mxRenderable->getRenderer( i_nPage, getSelectionObject(), aJobOptions ); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir catch( lang::IllegalArgumentException& ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir return aResult; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir void SfxPrinterController::printPage( int i_nPage ) const 268cdf0e10cSrcweir { 269cdf0e10cSrcweir boost::shared_ptr<Printer> pPrinter( getPrinter() ); 270cdf0e10cSrcweir if( mxRenderable.is() && pPrinter ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir Sequence< beans::PropertyValue > aJobOptions( getMergedOptions() ); 273cdf0e10cSrcweir try 274cdf0e10cSrcweir { 275cdf0e10cSrcweir mxRenderable->render( i_nPage, getSelectionObject(), aJobOptions ); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir catch( lang::IllegalArgumentException& ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir // don't care enough about nonexistant page here 280cdf0e10cSrcweir // to provoke a crash 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir void SfxPrinterController::jobStarted() 286cdf0e10cSrcweir { 287cdf0e10cSrcweir if ( mpObjectShell ) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir m_bOrigStatus = mpObjectShell->IsEnableSetModified(); 290cdf0e10cSrcweir 291cdf0e10cSrcweir // check configuration: shall update of printing information in DocInfo set the document to "modified"? 292cdf0e10cSrcweir if ( m_bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir mpObjectShell->EnableSetModified( sal_False ); 295cdf0e10cSrcweir m_bNeedsChange = sal_True; 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir // refresh document info 299cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties()); 300cdf0e10cSrcweir m_aLastPrintedBy = xDocProps->getPrintedBy(); 301cdf0e10cSrcweir m_aLastPrinted = xDocProps->getPrintDate(); 302cdf0e10cSrcweir 303cdf0e10cSrcweir xDocProps->setPrintedBy( mpObjectShell->IsUseUserData() 304cdf0e10cSrcweir ? ::rtl::OUString( SvtUserOptions().GetFullName() ) 305cdf0e10cSrcweir : ::rtl::OUString() ); 306cdf0e10cSrcweir ::DateTime now; 307cdf0e10cSrcweir 308cdf0e10cSrcweir xDocProps->setPrintDate( util::DateTime( 309cdf0e10cSrcweir now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(), 310cdf0e10cSrcweir now.GetDay(), now.GetMonth(), now.GetYear() ) ); 311cdf0e10cSrcweir 312cdf0e10cSrcweir // FIXME: how to get all print options incl. AdditionalOptions easily? 313cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aOpts; 314cdf0e10cSrcweir mpObjectShell->Broadcast( SfxPrintingHint( view::PrintableState_JOB_STARTED, aOpts ) ); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir void SfxPrinterController::jobFinished( com::sun::star::view::PrintableState nState ) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir if ( mpObjectShell ) 321cdf0e10cSrcweir { 322cdf0e10cSrcweir bool bCopyJobSetup = false; 323cdf0e10cSrcweir mpObjectShell->Broadcast( SfxPrintingHint( nState ) ); 324cdf0e10cSrcweir switch ( nState ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir case view::PrintableState_JOB_FAILED : 327cdf0e10cSrcweir { 328cdf0e10cSrcweir // "real" problem (not simply printing cancelled by user) 329cdf0e10cSrcweir String aMsg( SfxResId( STR_NOSTARTPRINTER ) ); 330cdf0e10cSrcweir if ( !m_bApi ) 331cdf0e10cSrcweir ErrorBox( mpViewShell->GetWindow(), WB_OK | WB_DEF_OK, aMsg ).Execute(); 332cdf0e10cSrcweir // intentionally no break 333cdf0e10cSrcweir } 334cdf0e10cSrcweir case view::PrintableState_JOB_ABORTED : 335cdf0e10cSrcweir { 336cdf0e10cSrcweir // printing not succesful, reset DocInfo 337cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties()); 338cdf0e10cSrcweir xDocProps->setPrintedBy(m_aLastPrintedBy); 339cdf0e10cSrcweir xDocProps->setPrintDate(m_aLastPrinted); 340cdf0e10cSrcweir break; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir case view::PrintableState_JOB_SPOOLED : 344cdf0e10cSrcweir case view::PrintableState_JOB_COMPLETED : 345cdf0e10cSrcweir { 346cdf0e10cSrcweir SfxBindings& rBind = mpViewShell->GetViewFrame()->GetBindings(); 347cdf0e10cSrcweir rBind.Invalidate( SID_PRINTDOC ); 348cdf0e10cSrcweir rBind.Invalidate( SID_PRINTDOCDIRECT ); 349cdf0e10cSrcweir rBind.Invalidate( SID_SETUPPRINTER ); 350cdf0e10cSrcweir bCopyJobSetup = ! m_bTempPrinter; 351cdf0e10cSrcweir break; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir default: 355cdf0e10cSrcweir break; 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir if( bCopyJobSetup && mpViewShell ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir // #i114306# 361cdf0e10cSrcweir // Note: this possibly creates a printer that gets immediately replaced 362cdf0e10cSrcweir // by a new one. The reason for this is that otherwise we would not get 363cdf0e10cSrcweir // the printer's SfxItemSet here to copy. Awkward, but at the moment there is no 364cdf0e10cSrcweir // other way here to get the item set. 365cdf0e10cSrcweir SfxPrinter* pDocPrt = mpViewShell->GetPrinter(sal_True); 366cdf0e10cSrcweir if( pDocPrt ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir if( pDocPrt->GetName() == getPrinter()->GetName() ) 369cdf0e10cSrcweir pDocPrt->SetJobSetup( getPrinter()->GetJobSetup() ); 370cdf0e10cSrcweir else 371cdf0e10cSrcweir { 372cdf0e10cSrcweir SfxPrinter* pNewPrt = new SfxPrinter( pDocPrt->GetOptions().Clone(), getPrinter()->GetName() ); 373cdf0e10cSrcweir pNewPrt->SetJobSetup( getPrinter()->GetJobSetup() ); 374cdf0e10cSrcweir mpViewShell->SetPrinter( pNewPrt, SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir } 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( m_bNeedsChange ) 380cdf0e10cSrcweir mpObjectShell->EnableSetModified( m_bOrigStatus ); 381cdf0e10cSrcweir 382cdf0e10cSrcweir if ( mpViewShell ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir mpViewShell->pImp->m_pPrinterController.reset(); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir } 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir //==================================================================== 390cdf0e10cSrcweir 391cdf0e10cSrcweir class SfxDialogExecutor_Impl 392cdf0e10cSrcweir 393cdf0e10cSrcweir /* [Beschreibung] 394cdf0e10cSrcweir 395cdf0e10cSrcweir Eine Instanz dieser Klasse wird f"ur die Laufzeit des Printer-Dialogs 396cdf0e10cSrcweir erzeugt, um im dessen Click-Handler f"ur die Zus"atze den per 397cdf0e10cSrcweir virtueller Methode von der abgeleiteten SfxViewShell erzeugten 398cdf0e10cSrcweir Print-Options-Dialog zu erzeugen und die dort eingestellten Optionen 399cdf0e10cSrcweir als SfxItemSet zu zwischenzuspeichern. 400cdf0e10cSrcweir */ 401cdf0e10cSrcweir 402cdf0e10cSrcweir { 403cdf0e10cSrcweir private: 404cdf0e10cSrcweir SfxViewShell* _pViewSh; 405cdf0e10cSrcweir PrinterSetupDialog* _pSetupParent; 406cdf0e10cSrcweir SfxItemSet* _pOptions; 407cdf0e10cSrcweir sal_Bool _bModified; 408cdf0e10cSrcweir sal_Bool _bHelpDisabled; 409cdf0e10cSrcweir 410cdf0e10cSrcweir DECL_LINK( Execute, void * ); 411cdf0e10cSrcweir 412cdf0e10cSrcweir public: 413cdf0e10cSrcweir SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog* pParent ); 414cdf0e10cSrcweir ~SfxDialogExecutor_Impl() { delete _pOptions; } 415cdf0e10cSrcweir 416cdf0e10cSrcweir Link GetLink() const { return LINK( this, SfxDialogExecutor_Impl, Execute); } 417cdf0e10cSrcweir const SfxItemSet* GetOptions() const { return _pOptions; } 418cdf0e10cSrcweir void DisableHelp() { _bHelpDisabled = sal_True; } 419cdf0e10cSrcweir }; 420cdf0e10cSrcweir 421cdf0e10cSrcweir //-------------------------------------------------------------------- 422cdf0e10cSrcweir 423cdf0e10cSrcweir SfxDialogExecutor_Impl::SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog* pParent ) : 424cdf0e10cSrcweir 425cdf0e10cSrcweir _pViewSh ( pViewSh ), 426cdf0e10cSrcweir _pSetupParent ( pParent ), 427cdf0e10cSrcweir _pOptions ( NULL ), 428cdf0e10cSrcweir _bModified ( sal_False ), 429cdf0e10cSrcweir _bHelpDisabled ( sal_False ) 430cdf0e10cSrcweir 431cdf0e10cSrcweir { 432cdf0e10cSrcweir } 433cdf0e10cSrcweir 434cdf0e10cSrcweir //-------------------------------------------------------------------- 435cdf0e10cSrcweir 436cdf0e10cSrcweir IMPL_LINK( SfxDialogExecutor_Impl, Execute, void *, EMPTYARG ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir // Options lokal merken 439cdf0e10cSrcweir if ( !_pOptions ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir DBG_ASSERT( _pSetupParent, "no dialog parent" ); 442cdf0e10cSrcweir if( _pSetupParent ) 443cdf0e10cSrcweir _pOptions = ( (SfxPrinter*)_pSetupParent->GetPrinter() )->GetOptions().Clone(); 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir // Dialog ausf"uhren 447cdf0e10cSrcweir SfxPrintOptionsDialog* pDlg = new SfxPrintOptionsDialog( static_cast<Window*>(_pSetupParent), 448cdf0e10cSrcweir _pViewSh, _pOptions ); 449cdf0e10cSrcweir if ( _bHelpDisabled ) 450cdf0e10cSrcweir pDlg->DisableHelp(); 451cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir delete _pOptions; 454cdf0e10cSrcweir _pOptions = pDlg->GetOptions().Clone(); 455cdf0e10cSrcweir 456cdf0e10cSrcweir } 457cdf0e10cSrcweir delete pDlg; 458cdf0e10cSrcweir 459cdf0e10cSrcweir return 0; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir //------------------------------------------------------------------------- 463cdf0e10cSrcweir 464cdf0e10cSrcweir sal_Bool UseStandardPrinter_Impl( Window* /*pParent*/, SfxPrinter* pDocPrinter ) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir // Optionen abfragen, ob gewarnt werden soll (Doc uebersteuert App) 467cdf0e10cSrcweir sal_Bool bWarn = sal_False; 468cdf0e10cSrcweir const SfxItemSet *pDocOptions = &pDocPrinter->GetOptions(); 469cdf0e10cSrcweir if ( pDocOptions ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir sal_uInt16 nWhich = pDocOptions->GetPool()->GetWhich(SID_PRINTER_NOTFOUND_WARN); 472cdf0e10cSrcweir const SfxBoolItem* pBoolItem = NULL; 473cdf0e10cSrcweir pDocPrinter->GetOptions().GetItemState( nWhich, sal_False, (const SfxPoolItem**) &pBoolItem ); 474cdf0e10cSrcweir if ( pBoolItem ) 475cdf0e10cSrcweir bWarn = pBoolItem->GetValue(); 476cdf0e10cSrcweir } 477cdf0e10cSrcweir /* 478cdf0e10cSrcweir // ggf. den User fragen 479cdf0e10cSrcweir if ( bWarn ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir // Geht nicht mehr ohne OrigJobSetup! 482cdf0e10cSrcweir String aTmp( SfxResId( STR_PRINTER_NOTAVAIL ) ); 483cdf0e10cSrcweir QueryBox aBox( pParent, WB_OK_CANCEL | WB_DEF_OK, aTmp ); 484cdf0e10cSrcweir return RET_OK == aBox.Execute(); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir */ 487cdf0e10cSrcweir // nicht gewarnt => einfach so den StandardDrucker nehmen 488cdf0e10cSrcweir return sal_True; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir //------------------------------------------------------------------------- 491cdf0e10cSrcweir 492cdf0e10cSrcweir SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter ) 493cdf0e10cSrcweir 494cdf0e10cSrcweir /* Interne Methode zum Setzen der Unterschiede von 'pNewPrinter' zum 495cdf0e10cSrcweir aktuellen Printer. pNewPrinter wird entweder "ubernommen oder gel"oscht. 496cdf0e10cSrcweir */ 497cdf0e10cSrcweir 498cdf0e10cSrcweir { 499cdf0e10cSrcweir // aktuellen Printer holen 500cdf0e10cSrcweir SfxPrinter *pDocPrinter = GetPrinter(); 501cdf0e10cSrcweir 502cdf0e10cSrcweir // Printer-Options auswerten 503cdf0e10cSrcweir bool bOriToDoc = false; 504cdf0e10cSrcweir bool bSizeToDoc = false; 505cdf0e10cSrcweir if ( &pDocPrinter->GetOptions() ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir sal_uInt16 nWhich = GetPool().GetWhich(SID_PRINTER_CHANGESTODOC); 508cdf0e10cSrcweir const SfxFlagItem *pFlagItem = 0; 509cdf0e10cSrcweir pDocPrinter->GetOptions().GetItemState( nWhich, sal_False, (const SfxPoolItem**) &pFlagItem ); 510cdf0e10cSrcweir bOriToDoc = pFlagItem ? (pFlagItem->GetValue() & SFX_PRINTER_CHG_ORIENTATION) : sal_False; 511cdf0e10cSrcweir bSizeToDoc = pFlagItem ? (pFlagItem->GetValue() & SFX_PRINTER_CHG_SIZE) : sal_False; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir // vorheriges Format und Size feststellen 515cdf0e10cSrcweir Orientation eOldOri = pDocPrinter->GetOrientation(); 516cdf0e10cSrcweir Size aOldPgSz = pDocPrinter->GetPaperSizePixel(); 517cdf0e10cSrcweir 518cdf0e10cSrcweir // neues Format und Size feststellen 519cdf0e10cSrcweir Orientation eNewOri = pNewPrinter->GetOrientation(); 520cdf0e10cSrcweir Size aNewPgSz = pNewPrinter->GetPaperSizePixel(); 521cdf0e10cSrcweir 522cdf0e10cSrcweir // "Anderungen am Seitenformat feststellen 523cdf0e10cSrcweir sal_Bool bOriChg = (eOldOri != eNewOri) && bOriToDoc; 524cdf0e10cSrcweir sal_Bool bPgSzChg = ( aOldPgSz.Height() != 525cdf0e10cSrcweir ( bOriChg ? aNewPgSz.Width() : aNewPgSz.Height() ) || 526cdf0e10cSrcweir aOldPgSz.Width() != 527cdf0e10cSrcweir ( bOriChg ? aNewPgSz.Height() : aNewPgSz.Width() ) ) && 528cdf0e10cSrcweir bSizeToDoc; 529cdf0e10cSrcweir 530cdf0e10cSrcweir // Message und Flags f"ur Seitenformat-"Anderung zusammenstellen 531cdf0e10cSrcweir String aMsg; 532cdf0e10cSrcweir sal_uInt16 nNewOpt=0; 533cdf0e10cSrcweir if( bOriChg && bPgSzChg ) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir aMsg = String(SfxResId(STR_PRINT_NEWORISIZE)); 536cdf0e10cSrcweir nNewOpt = SFX_PRINTER_CHG_ORIENTATION | SFX_PRINTER_CHG_SIZE; 537cdf0e10cSrcweir } 538cdf0e10cSrcweir else if (bOriChg ) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir aMsg = String(SfxResId(STR_PRINT_NEWORI)); 541cdf0e10cSrcweir nNewOpt = SFX_PRINTER_CHG_ORIENTATION; 542cdf0e10cSrcweir } 543cdf0e10cSrcweir else if (bPgSzChg) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir aMsg = String(SfxResId(STR_PRINT_NEWSIZE)); 546cdf0e10cSrcweir nNewOpt = SFX_PRINTER_CHG_SIZE; 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir // in dieser Variable sammeln, was sich so ge"aendert hat 550cdf0e10cSrcweir sal_uInt16 nChangedFlags = 0; 551cdf0e10cSrcweir 552cdf0e10cSrcweir // ggf. Nachfrage, ob Seitenformat vom Drucker "ubernommen werden soll 553cdf0e10cSrcweir if ( ( bOriChg || bPgSzChg ) && 554cdf0e10cSrcweir RET_YES == QueryBox(0, WB_YES_NO | WB_DEF_OK, aMsg).Execute() ) 555cdf0e10cSrcweir // Flags mit "Anderungen f"ur <SetPrinter(SfxPrinter*)> mitpflegen 556cdf0e10cSrcweir nChangedFlags |= nNewOpt; 557cdf0e10cSrcweir 558cdf0e10cSrcweir // fuer den MAC sein "temporary of class String" im naechsten if() 559cdf0e10cSrcweir String aTempPrtName = pNewPrinter->GetName(); 560cdf0e10cSrcweir String aDocPrtName = pDocPrinter->GetName(); 561cdf0e10cSrcweir 562cdf0e10cSrcweir // Wurde der Drucker gewechselt oder von Default auf Specific 563cdf0e10cSrcweir // oder umgekehrt geaendert? 564cdf0e10cSrcweir if ( (aTempPrtName != aDocPrtName) || (pDocPrinter->IsDefPrinter() != pNewPrinter->IsDefPrinter()) ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir // neuen Printer "ubernehmen 567cdf0e10cSrcweir // pNewPrinter->SetOrigJobSetup( pNewPrinter->GetJobSetup() ); 568cdf0e10cSrcweir nChangedFlags |= SFX_PRINTER_PRINTER|SFX_PRINTER_JOBSETUP; 569cdf0e10cSrcweir pDocPrinter = pNewPrinter; 570cdf0e10cSrcweir } 571cdf0e10cSrcweir else 572cdf0e10cSrcweir { 573cdf0e10cSrcweir // Extra-Optionen vergleichen 574cdf0e10cSrcweir if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir // Options haben sich geaendert 577cdf0e10cSrcweir pDocPrinter->SetOptions( pNewPrinter->GetOptions() ); 578cdf0e10cSrcweir nChangedFlags |= SFX_PRINTER_OPTIONS; 579cdf0e10cSrcweir } 580cdf0e10cSrcweir 581cdf0e10cSrcweir // JobSetups vergleichen 582cdf0e10cSrcweir JobSetup aNewJobSetup = pNewPrinter->GetJobSetup(); 583cdf0e10cSrcweir JobSetup aOldJobSetup = pDocPrinter->GetJobSetup(); 584cdf0e10cSrcweir if ( aNewJobSetup != aOldJobSetup ) 585cdf0e10cSrcweir { 586cdf0e10cSrcweir // JobSetup hat sich geaendert (=> App mu\s neu formatieren) 587cdf0e10cSrcweir // pDocPrinter->SetOrigJobSetup( aNewJobSetup ); 588cdf0e10cSrcweir nChangedFlags |= SFX_PRINTER_JOBSETUP; 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir // alten, ver"anderten Printer behalten 592cdf0e10cSrcweir pDocPrinter->SetPrinterProps( pNewPrinter ); 593cdf0e10cSrcweir delete pNewPrinter; 594cdf0e10cSrcweir } 595cdf0e10cSrcweir 596cdf0e10cSrcweir if ( 0 != nChangedFlags ) 597cdf0e10cSrcweir // SetPrinter will delete the old printer if it changes 598cdf0e10cSrcweir SetPrinter( pDocPrinter, nChangedFlags ); 599cdf0e10cSrcweir return pDocPrinter; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir //------------------------------------------------------------------------- 603cdf0e10cSrcweir // Unter WIN32 tritt leider das Problem auf, dass nichts gedruckt 604cdf0e10cSrcweir // wird, wenn SID_PRINTDOCDIRECT auflaueft; bisher bekannte, 605cdf0e10cSrcweir // einzige Abhilfe ist in diesem Fall das Abschalten der Optimierungen 606cdf0e10cSrcweir // (KA 17.12.95) 607cdf0e10cSrcweir #ifdef _MSC_VER 608cdf0e10cSrcweir #pragma optimize ( "", off ) 609cdf0e10cSrcweir #endif 610cdf0e10cSrcweir 611cdf0e10cSrcweir void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, sal_Bool bIsAPI, sal_Bool bIsDirect ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir // get the current selection; our controller should know it 614cdf0e10cSrcweir Reference< frame::XController > xController( GetController() ); 615cdf0e10cSrcweir Reference< view::XSelectionSupplier > xSupplier( xController, UNO_QUERY ); 616cdf0e10cSrcweir 617cdf0e10cSrcweir Any aSelection; 618cdf0e10cSrcweir if( xSupplier.is() ) 619cdf0e10cSrcweir aSelection = xSupplier->getSelection(); 620cdf0e10cSrcweir else 621cdf0e10cSrcweir aSelection <<= GetObjectShell()->GetModel(); 622cdf0e10cSrcweir Any aComplete( makeAny( GetObjectShell()->GetModel() ) ); 623cdf0e10cSrcweir Any aViewProp( makeAny( xController ) ); 624cdf0e10cSrcweir boost::shared_ptr<Printer> aPrt; 625cdf0e10cSrcweir 626cdf0e10cSrcweir const beans::PropertyValue* pVal = rProps.getConstArray(); 627cdf0e10cSrcweir for( sal_Int32 i = 0; i < rProps.getLength(); i++ ) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir if( pVal[i].Name.equalsAscii( "PrinterName" ) ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir rtl::OUString aPrinterName; 632cdf0e10cSrcweir pVal[i].Value >>= aPrinterName; 633cdf0e10cSrcweir aPrt.reset( new Printer( aPrinterName ) ); 634cdf0e10cSrcweir break; 635cdf0e10cSrcweir } 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir boost::shared_ptr<vcl::PrinterController> pController( new SfxPrinterController( 639cdf0e10cSrcweir aPrt, 640cdf0e10cSrcweir aComplete, 641cdf0e10cSrcweir aSelection, 642cdf0e10cSrcweir aViewProp, 643cdf0e10cSrcweir GetRenderable(), 644cdf0e10cSrcweir bIsAPI, 645cdf0e10cSrcweir bIsDirect, 646cdf0e10cSrcweir this, 647cdf0e10cSrcweir rProps 648cdf0e10cSrcweir ) ); 649cdf0e10cSrcweir pImp->m_pPrinterController = pController; 650cdf0e10cSrcweir 651cdf0e10cSrcweir SfxObjectShell *pObjShell = GetObjectShell(); 652cdf0e10cSrcweir pController->setValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "JobName" ) ), 653cdf0e10cSrcweir makeAny( rtl::OUString( pObjShell->GetTitle(0) ) ) ); 654cdf0e10cSrcweir 655cdf0e10cSrcweir // FIXME: job setup 656cdf0e10cSrcweir SfxPrinter* pDocPrt = GetPrinter(sal_False); 657cdf0e10cSrcweir JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : GetJobSetup(); 658cdf0e10cSrcweir if( bIsDirect ) 659cdf0e10cSrcweir aJobSetup.SetValue( String( RTL_CONSTASCII_USTRINGPARAM( "IsQuickJob" ) ), 660cdf0e10cSrcweir String( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) ); 661cdf0e10cSrcweir 662cdf0e10cSrcweir Printer::PrintJob( pController, aJobSetup ); 663cdf0e10cSrcweir } 664cdf0e10cSrcweir 665cdf0e10cSrcweir Printer* SfxViewShell::GetActivePrinter() const 666cdf0e10cSrcweir { 667cdf0e10cSrcweir return (pImp->m_pPrinterController) 668cdf0e10cSrcweir ? pImp->m_pPrinterController->getPrinter().get() : 0; 669cdf0e10cSrcweir } 670cdf0e10cSrcweir 671cdf0e10cSrcweir void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir // sal_uInt16 nCopies=1; 674cdf0e10cSrcweir sal_uInt16 nDialogRet = RET_CANCEL; 675cdf0e10cSrcweir // sal_Bool bCollate=sal_False; 676cdf0e10cSrcweir SfxPrinter* pPrinter = 0; 677cdf0e10cSrcweir SfxDialogExecutor_Impl* pExecutor = 0; 678cdf0e10cSrcweir bool bSilent = false; 679cdf0e10cSrcweir sal_Bool bIsAPI = rReq.GetArgs() && rReq.GetArgs()->Count(); 680cdf0e10cSrcweir if ( bIsAPI ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False); 683cdf0e10cSrcweir bSilent = pSilentItem && pSilentItem->GetValue(); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir //FIXME: how to transport "bPrintOnHelp"? 687cdf0e10cSrcweir 688cdf0e10cSrcweir // no help button in dialogs if called from the help window 689cdf0e10cSrcweir // (pressing help button would exchange the current page inside the help document that is going to be printed!) 690cdf0e10cSrcweir String aHelpFilterName( DEFINE_CONST_UNICODE("writer_web_HTML_help") ); 691cdf0e10cSrcweir SfxMedium* pMedium = GetViewFrame()->GetObjectShell()->GetMedium(); 692cdf0e10cSrcweir const SfxFilter* pFilter = pMedium ? pMedium->GetFilter() : NULL; 693cdf0e10cSrcweir sal_Bool bPrintOnHelp = ( pFilter && pFilter->GetFilterName() == aHelpFilterName ); 694cdf0e10cSrcweir 695cdf0e10cSrcweir const sal_uInt16 nId = rReq.GetSlot(); 696cdf0e10cSrcweir switch( nId ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 699cdf0e10cSrcweir case SID_PRINTDOC: 700cdf0e10cSrcweir case SID_PRINTDOCDIRECT: 701cdf0e10cSrcweir { 702cdf0e10cSrcweir SfxObjectShell* pDoc = GetObjectShell(); 703cdf0e10cSrcweir 704cdf0e10cSrcweir // derived class may decide to abort this 705cdf0e10cSrcweir if( !pDoc->QuerySlotExecutable( nId ) ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir rReq.SetReturnValue( SfxBoolItem( 0, sal_False ) ); 708cdf0e10cSrcweir return; 709cdf0e10cSrcweir } 710cdf0e10cSrcweir 711cdf0e10cSrcweir bool bDetectHidden = ( !bSilent && pDoc ); 712cdf0e10cSrcweir if ( bDetectHidden && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES ) 713cdf0e10cSrcweir break; 714cdf0e10cSrcweir 715cdf0e10cSrcweir SFX_REQUEST_ARG(rReq, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False); 716cdf0e10cSrcweir sal_Bool bSelection = pSelectItem && pSelectItem->GetValue(); 717cdf0e10cSrcweir if( pSelectItem && rReq.GetArgs()->Count() == 1 ) 718cdf0e10cSrcweir bIsAPI = sal_False; 719cdf0e10cSrcweir 720cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aProps; 721cdf0e10cSrcweir if ( bIsAPI ) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir // supported properties: 724cdf0e10cSrcweir // String PrinterName 725cdf0e10cSrcweir // String FileName 726cdf0e10cSrcweir // Int16 From 727cdf0e10cSrcweir // Int16 To 728cdf0e10cSrcweir // In16 Copies 729cdf0e10cSrcweir // String RangeText 730cdf0e10cSrcweir // bool Selection 731cdf0e10cSrcweir // bool Asynchron 732cdf0e10cSrcweir // bool Collate 733cdf0e10cSrcweir // bool Silent 734cdf0e10cSrcweir TransformItems( nId, *rReq.GetArgs(), aProps, GetInterface()->GetSlot(nId) ); 735cdf0e10cSrcweir for ( sal_Int32 nProp=0; nProp<aProps.getLength(); nProp++ ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir if ( aProps[nProp].Name.equalsAscii("Copies") ) 738cdf0e10cSrcweir aProps[nProp]. Name = rtl::OUString::createFromAscii("CopyCount"); 739cdf0e10cSrcweir else if ( aProps[nProp].Name.equalsAscii("RangeText") ) 740cdf0e10cSrcweir aProps[nProp]. Name = rtl::OUString::createFromAscii("Pages"); 741cdf0e10cSrcweir if ( aProps[nProp].Name.equalsAscii("Asynchron") ) 742cdf0e10cSrcweir { 743cdf0e10cSrcweir aProps[nProp]. Name = rtl::OUString::createFromAscii("Wait"); 744cdf0e10cSrcweir sal_Bool bAsynchron = sal_False; 745cdf0e10cSrcweir aProps[nProp].Value >>= bAsynchron; 746cdf0e10cSrcweir aProps[nProp].Value <<= (sal_Bool) (!bAsynchron); 747cdf0e10cSrcweir } 748cdf0e10cSrcweir if ( aProps[nProp].Name.equalsAscii("Silent") ) 749cdf0e10cSrcweir { 750cdf0e10cSrcweir aProps[nProp]. Name = rtl::OUString::createFromAscii("MonitorVisible"); 751cdf0e10cSrcweir sal_Bool bPrintSilent = sal_False; 752cdf0e10cSrcweir aProps[nProp].Value >>= bPrintSilent; 753cdf0e10cSrcweir aProps[nProp].Value <<= (sal_Bool) (!bPrintSilent); 754cdf0e10cSrcweir } 755cdf0e10cSrcweir } 756cdf0e10cSrcweir } 757cdf0e10cSrcweir // HACK: writer sets the SID_SELECTION item when printing directly and expects 758cdf0e10cSrcweir // to get only the selection document in that case (see getSelectionObject) 759cdf0e10cSrcweir // however it also reacts to the PrintContent property. We need this distinction here, too, 760cdf0e10cSrcweir // else one of the combinations print / print direct and selection / all will not work. 761cdf0e10cSrcweir // it would be better if writer handled this internally 762cdf0e10cSrcweir if( nId == SID_PRINTDOCDIRECT ) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir sal_Int32 nLen = aProps.getLength(); 765cdf0e10cSrcweir aProps.realloc( nLen + 1 ); 766cdf0e10cSrcweir aProps[nLen].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintSelectionOnly" ) ); 767cdf0e10cSrcweir aProps[nLen].Value = makeAny( bSelection ); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir 770cdf0e10cSrcweir ExecPrint( aProps, bIsAPI, (nId == SID_PRINTDOCDIRECT) ); 771cdf0e10cSrcweir 772cdf0e10cSrcweir // FIXME: Recording 773cdf0e10cSrcweir rReq.Done(); 774cdf0e10cSrcweir break; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir case SID_SETUPPRINTER : 778cdf0e10cSrcweir case SID_PRINTER_NAME : // only for recorded macros 779cdf0e10cSrcweir { 780cdf0e10cSrcweir // get printer and printer settings from the document 781cdf0e10cSrcweir SfxPrinter *pDocPrinter = GetPrinter(sal_True); 782cdf0e10cSrcweir 783cdf0e10cSrcweir // look for printer in parameters 784cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pPrinterItem, SfxStringItem, SID_PRINTER_NAME, sal_False ); 785cdf0e10cSrcweir if ( pPrinterItem ) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir // use PrinterName parameter to create a printer 788cdf0e10cSrcweir pPrinter = new SfxPrinter( pDocPrinter->GetOptions().Clone(), ((const SfxStringItem*) pPrinterItem)->GetValue() ); 789cdf0e10cSrcweir 790cdf0e10cSrcweir // if printer is unknown, it can't be used - now printer from document will be used 791cdf0e10cSrcweir if ( !pPrinter->IsOriginal() ) 792cdf0e10cSrcweir DELETEZ(pPrinter); 793cdf0e10cSrcweir } 794cdf0e10cSrcweir 795cdf0e10cSrcweir if ( SID_PRINTER_NAME == nId ) 796cdf0e10cSrcweir { 797cdf0e10cSrcweir // just set a recorded printer name 798cdf0e10cSrcweir if ( pPrinter ) 799cdf0e10cSrcweir SetPrinter( pPrinter, SFX_PRINTER_PRINTER ); 800cdf0e10cSrcweir break; 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer 804cdf0e10cSrcweir if ( !pPrinter ) 805cdf0e10cSrcweir // use default printer from document 806cdf0e10cSrcweir pPrinter = pDocPrinter; 807cdf0e10cSrcweir 808cdf0e10cSrcweir if( !pPrinter || !pPrinter->IsValid() ) 809cdf0e10cSrcweir { 810cdf0e10cSrcweir // no valid printer either in ItemSet or at the document 811cdf0e10cSrcweir if ( bSilent ) 812cdf0e10cSrcweir { 813cdf0e10cSrcweir rReq.SetReturnValue(SfxBoolItem(0,sal_False)); 814cdf0e10cSrcweir break; 815cdf0e10cSrcweir } 816cdf0e10cSrcweir else 817cdf0e10cSrcweir ErrorBox( NULL, WB_OK | WB_DEF_OK, String( SfxResId( STR_NODEFPRINTER ) ) ).Execute(); 818cdf0e10cSrcweir } 819cdf0e10cSrcweir 820cdf0e10cSrcweir if ( !pPrinter->IsOriginal() && rReq.GetArgs() && !UseStandardPrinter_Impl( NULL, pPrinter ) ) 821cdf0e10cSrcweir { 822cdf0e10cSrcweir // printer is not available, but standard printer should not be used 823cdf0e10cSrcweir rReq.SetReturnValue(SfxBoolItem(0,sal_False)); 824cdf0e10cSrcweir break; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir // FIXME: printer isn't used for printing anymore! 828cdf0e10cSrcweir if( pPrinter->IsPrinting() ) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir // if printer is busy, abort printing 831cdf0e10cSrcweir if ( !bSilent ) 832cdf0e10cSrcweir InfoBox( NULL, String( SfxResId( STR_ERROR_PRINTER_BUSY ) ) ).Execute(); 833cdf0e10cSrcweir rReq.SetReturnValue(SfxBoolItem(0,sal_False)); 834cdf0e10cSrcweir break; 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir // if no arguments are given, retrieve them from a dialog 838cdf0e10cSrcweir if ( !bIsAPI ) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir // PrinterDialog needs a temporary printer 841cdf0e10cSrcweir SfxPrinter* pDlgPrinter = pPrinter->Clone(); 842cdf0e10cSrcweir nDialogRet = 0; 843cdf0e10cSrcweir 844cdf0e10cSrcweir // execute PrinterSetupDialog 845cdf0e10cSrcweir PrinterSetupDialog* pPrintSetupDlg = new PrinterSetupDialog( GetWindow() ); 846cdf0e10cSrcweir 847cdf0e10cSrcweir if (pImp->m_bHasPrintOptions) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir // additional controls for dialog 850cdf0e10cSrcweir pExecutor = new SfxDialogExecutor_Impl( this, pPrintSetupDlg ); 851cdf0e10cSrcweir if ( bPrintOnHelp ) 852cdf0e10cSrcweir pExecutor->DisableHelp(); 853cdf0e10cSrcweir pPrintSetupDlg->SetOptionsHdl( pExecutor->GetLink() ); 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir pPrintSetupDlg->SetPrinter( pDlgPrinter ); 857cdf0e10cSrcweir nDialogRet = pPrintSetupDlg->Execute(); 858cdf0e10cSrcweir 859cdf0e10cSrcweir if ( pExecutor && pExecutor->GetOptions() ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir if ( nDialogRet == RET_OK ) 862cdf0e10cSrcweir // remark: have to be recorded if possible! 863cdf0e10cSrcweir pDlgPrinter->SetOptions( *pExecutor->GetOptions() ); 864cdf0e10cSrcweir else 865cdf0e10cSrcweir { 866cdf0e10cSrcweir pPrinter->SetOptions( *pExecutor->GetOptions() ); 867cdf0e10cSrcweir SetPrinter( pPrinter, SFX_PRINTER_OPTIONS ); 868cdf0e10cSrcweir } 869cdf0e10cSrcweir } 870cdf0e10cSrcweir 871cdf0e10cSrcweir DELETEZ( pPrintSetupDlg ); 872cdf0e10cSrcweir 873cdf0e10cSrcweir // no recording of PrinterSetup except printer name (is printer dependent) 874cdf0e10cSrcweir rReq.Ignore(); 875cdf0e10cSrcweir 876cdf0e10cSrcweir if ( nDialogRet == RET_OK ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir if ( pPrinter->GetName() != pDlgPrinter->GetName() ) 879cdf0e10cSrcweir { 880cdf0e10cSrcweir // user has changed the printer -> macro recording 881cdf0e10cSrcweir SfxRequest aReq( GetViewFrame(), SID_PRINTER_NAME ); 882cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_PRINTER_NAME, pDlgPrinter->GetName() ) ); 883cdf0e10cSrcweir aReq.Done(); 884cdf0e10cSrcweir } 885cdf0e10cSrcweir 886cdf0e10cSrcweir // take the changes made in the dialog 887cdf0e10cSrcweir pPrinter = SetPrinter_Impl( pDlgPrinter ); 888cdf0e10cSrcweir 889cdf0e10cSrcweir // forget new printer, it was taken over (as pPrinter) or deleted 890cdf0e10cSrcweir pDlgPrinter = NULL; 891cdf0e10cSrcweir 892cdf0e10cSrcweir } 893cdf0e10cSrcweir else 894cdf0e10cSrcweir { 895cdf0e10cSrcweir // PrinterDialog is used to transfer information on printing, 896cdf0e10cSrcweir // so it will only be deleted here if dialog was cancelled 897cdf0e10cSrcweir DELETEZ( pDlgPrinter ); 898cdf0e10cSrcweir rReq.Ignore(); 899cdf0e10cSrcweir if ( SID_PRINTDOC == nId ) 900cdf0e10cSrcweir rReq.SetReturnValue(SfxBoolItem(0,sal_False)); 901cdf0e10cSrcweir } 902cdf0e10cSrcweir } 903cdf0e10cSrcweir } 904cdf0e10cSrcweir 905cdf0e10cSrcweir break; 906cdf0e10cSrcweir } 907cdf0e10cSrcweir } 908cdf0e10cSrcweir 909cdf0e10cSrcweir // Optimierungen wieder einschalten 910cdf0e10cSrcweir #ifdef _MSC_VER 911cdf0e10cSrcweir #pragma optimize ( "", on ) 912cdf0e10cSrcweir #endif 913cdf0e10cSrcweir 914cdf0e10cSrcweir //-------------------------------------------------------------------- 915cdf0e10cSrcweir 916cdf0e10cSrcweir sal_Bool SfxViewShell::IsPrinterLocked() const 917cdf0e10cSrcweir { 918cdf0e10cSrcweir return pImp->m_nPrinterLocks > 0; 919cdf0e10cSrcweir } 920cdf0e10cSrcweir 921cdf0e10cSrcweir //-------------------------------------------------------------------- 922cdf0e10cSrcweir 923cdf0e10cSrcweir void SfxViewShell::LockPrinter( sal_Bool bLock) 924cdf0e10cSrcweir { 925cdf0e10cSrcweir sal_Bool bChanged = sal_False; 926cdf0e10cSrcweir if ( bLock ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir bChanged = 1 == ++pImp->m_nPrinterLocks; 929cdf0e10cSrcweir } 930cdf0e10cSrcweir else 931cdf0e10cSrcweir { 932cdf0e10cSrcweir bChanged = 0 == --pImp->m_nPrinterLocks; 933cdf0e10cSrcweir } 934cdf0e10cSrcweir 935cdf0e10cSrcweir if ( bChanged ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir Invalidate( SID_PRINTDOC ); 938cdf0e10cSrcweir Invalidate( SID_PRINTDOCDIRECT ); 939cdf0e10cSrcweir Invalidate( SID_SETUPPRINTER ); 940cdf0e10cSrcweir } 941cdf0e10cSrcweir } 942cdf0e10cSrcweir 943cdf0e10cSrcweir //-------------------------------------------------------------------- 944cdf0e10cSrcweir 945cdf0e10cSrcweir SfxPrinter* SfxViewShell::GetPrinter( sal_Bool /*bCreate*/ ) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir return 0; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir 950cdf0e10cSrcweir //-------------------------------------------------------------------- 951cdf0e10cSrcweir 952cdf0e10cSrcweir sal_uInt16 SfxViewShell::SetPrinter( SfxPrinter* /*pNewPrinter*/, sal_uInt16 /*nDiffFlags*/, bool ) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir return 0; 955cdf0e10cSrcweir } 956cdf0e10cSrcweir 957cdf0e10cSrcweir //-------------------------------------------------------------------- 958cdf0e10cSrcweir 959cdf0e10cSrcweir SfxTabPage* SfxViewShell::CreatePrintOptionsPage 960cdf0e10cSrcweir ( 961cdf0e10cSrcweir Window* /*pParent*/, 962cdf0e10cSrcweir const SfxItemSet& /*rOptions*/ 963cdf0e10cSrcweir ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir return 0; 966cdf0e10cSrcweir } 967cdf0e10cSrcweir 968cdf0e10cSrcweir JobSetup SfxViewShell::GetJobSetup() const 969cdf0e10cSrcweir { 970cdf0e10cSrcweir return JobSetup(); 971cdf0e10cSrcweir } 972cdf0e10cSrcweir 973