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