1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/document/XDocumentProperties.hpp>
22 #include <com/sun/star/view/PrintableState.hpp>
23 #include "com/sun/star/view/XRenderable.hpp"
25 #include <svl/itempool.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <svtools/prnsetup.hxx>
28 #include <svl/flagitem.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/intitem.hxx>
31 #include <svl/eitem.hxx>
32 #include <sfx2/app.hxx>
33 #include <unotools/useroptions.hxx>
34 #include <unotools/printwarningoptions.hxx>
35 #include <tools/datetime.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/objface.hxx>
38 #include <sfx2/viewsh.hxx>
39 #include "viewimp.hxx"
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/prnmon.hxx>
42 #include "sfx2/sfxresid.hxx"
43 #include <sfx2/request.hxx>
44 #include <sfx2/objsh.hxx>
45 #include "sfxtypes.hxx"
46 #include <sfx2/event.hxx>
47 #include <sfx2/docfile.hxx>
48 #include <sfx2/docfilt.hxx>
50 #include "toolkit/awt/vclxdevice.hxx"
55 using namespace com::sun::star
;
56 using namespace com::sun::star::uno
;
58 TYPEINIT1(SfxPrintingHint
, SfxHint
);
60 // -----------------------------------------------------------------------
61 class SfxPrinterController
: public vcl::PrinterController
, public SfxListener
63 Any maCompleteSelection
;
65 Reference
< view::XRenderable
> mxRenderable
;
66 mutable Printer
* mpLastPrinter
;
67 mutable Reference
<awt::XDevice
> mxDevice
;
68 SfxViewShell
* mpViewShell
;
69 SfxObjectShell
* mpObjectShell
;
70 sal_Bool m_bOrigStatus
;
71 sal_Bool m_bNeedsChange
;
73 sal_Bool m_bTempPrinter
;
74 util::DateTime m_aLastPrinted
;
75 OUString m_aLastPrintedBy
;
77 Sequence
< beans::PropertyValue
> getMergedOptions() const;
78 const Any
& getSelectionObject() const;
80 SfxPrinterController( const boost::shared_ptr
<Printer
>& i_rPrinter
,
81 const Any
& i_rComplete
,
82 const Any
& i_rSelection
,
83 const Any
& i_rViewProp
,
84 const Reference
< view::XRenderable
>& i_xRender
,
85 sal_Bool i_bApi
, sal_Bool i_bDirect
,
87 const uno::Sequence
< beans::PropertyValue
>& rProps
90 virtual ~SfxPrinterController();
91 virtual void Notify( SfxBroadcaster
&, const SfxHint
& );
93 virtual int getPageCount() const;
94 virtual Sequence
< beans::PropertyValue
> getPageParameters( int i_nPage
) const;
95 virtual void printPage( int i_nPage
) const;
96 virtual void jobStarted();
97 virtual void jobFinished( com::sun::star::view::PrintableState
);
100 SfxPrinterController::SfxPrinterController( const boost::shared_ptr
<Printer
>& i_rPrinter
,
101 const Any
& i_rComplete
,
102 const Any
& i_rSelection
,
103 const Any
& i_rViewProp
,
104 const Reference
< view::XRenderable
>& i_xRender
,
105 sal_Bool i_bApi
, sal_Bool i_bDirect
,
107 const uno::Sequence
< beans::PropertyValue
>& rProps
109 : PrinterController( i_rPrinter
)
110 , maCompleteSelection( i_rComplete
)
111 , maSelection( i_rSelection
)
112 , mxRenderable( i_xRender
)
113 , mpLastPrinter( NULL
)
114 , mpViewShell( pView
)
116 , m_bOrigStatus( sal_False
)
117 , m_bNeedsChange( sal_False
)
119 , m_bTempPrinter( i_rPrinter
.get() != NULL
)
123 StartListening( *mpViewShell
);
124 mpObjectShell
= mpViewShell
->GetObjectShell();
125 StartListening( *mpObjectShell
);
128 // initialize extra ui options
129 if( mxRenderable
.is() )
131 for (sal_Int32 nProp
=0; nProp
< rProps
.getLength(); ++nProp
)
132 setValue( rProps
[nProp
].Name
, rProps
[nProp
].Value
);
134 Sequence
< beans::PropertyValue
> aRenderOptions( 3 );
135 aRenderOptions
[0].Name
= OUString( "ExtraPrintUIOptions" );
136 aRenderOptions
[1].Name
= OUString( "View" );
137 aRenderOptions
[1].Value
= i_rViewProp
;
138 aRenderOptions
[2].Name
= OUString( "IsPrinter" );
139 aRenderOptions
[2].Value
<<= sal_True
;
142 Sequence
< beans::PropertyValue
> aRenderParms( mxRenderable
->getRenderer( 0 , getSelectionObject(), aRenderOptions
) );
143 int nProps
= aRenderParms
.getLength();
144 for( int i
= 0; i
< nProps
; i
++ )
146 if ( aRenderParms
[i
].Name
== "ExtraPrintUIOptions" )
148 Sequence
< beans::PropertyValue
> aUIProps
;
149 aRenderParms
[i
].Value
>>= aUIProps
;
150 setUIOptions( aUIProps
);
152 else if( aRenderParms
[i
].Name
== "NUp" )
154 setValue( aRenderParms
[i
].Name
, aRenderParms
[i
].Value
);
158 catch( lang::IllegalArgumentException
& )
160 // the first renderer should always be available for the UI options,
161 // but catch the exception to be safe
165 // set some job parameters
166 setValue( OUString( "IsApi" ), makeAny( i_bApi
) );
167 setValue( OUString( "IsDirect" ), makeAny( i_bDirect
) );
168 setValue( OUString( "IsPrinter" ), makeAny( sal_True
) );
169 setValue( OUString( "View" ), i_rViewProp
);
172 void SfxPrinterController::Notify( SfxBroadcaster
& , const SfxHint
& rHint
)
174 if ( rHint
.IsA(TYPE(SfxSimpleHint
)) )
176 if ( ((SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
178 EndListening(*mpViewShell
);
179 EndListening(*mpObjectShell
);
186 SfxPrinterController::~SfxPrinterController()
190 const Any
& SfxPrinterController::getSelectionObject() const
192 const beans::PropertyValue
* pVal
= getValue( OUString( "PrintSelectionOnly" ) );
195 sal_Bool bSel
= sal_False
;
196 pVal
->Value
>>= bSel
;
197 return bSel
? maSelection
: maCompleteSelection
;
200 sal_Int32 nChoice
= 0;
201 pVal
= getValue( OUString( "PrintContent" ) );
203 pVal
->Value
>>= nChoice
;
204 return (nChoice
> 1) ? maSelection
: maCompleteSelection
;
207 Sequence
< beans::PropertyValue
> SfxPrinterController::getMergedOptions() const
209 boost::shared_ptr
<Printer
> pPrinter( getPrinter() );
210 if( pPrinter
.get() != mpLastPrinter
)
212 mpLastPrinter
= pPrinter
.get();
213 VCLXDevice
* pXDevice
= new VCLXDevice();
214 pXDevice
->SetOutputDevice( mpLastPrinter
);
215 mxDevice
= Reference
< awt::XDevice
>( pXDevice
);
218 Sequence
< beans::PropertyValue
> aRenderOptions( 1 );
219 aRenderOptions
[ 0 ].Name
= OUString( "RenderDevice" );
220 aRenderOptions
[ 0 ].Value
<<= mxDevice
;
222 aRenderOptions
= getJobProperties( aRenderOptions
);
223 return aRenderOptions
;
226 int SfxPrinterController::getPageCount() const
229 boost::shared_ptr
<Printer
> pPrinter( getPrinter() );
230 if( mxRenderable
.is() && pPrinter
)
232 Sequence
< beans::PropertyValue
> aJobOptions( getMergedOptions() );
235 nPages
= mxRenderable
->getRendererCount( getSelectionObject(), aJobOptions
);
237 catch (lang::DisposedException
&)
239 OSL_TRACE("SfxPrinterController: document disposed while printing");
240 const_cast<SfxPrinterController
*>(this)->setJobState(
241 view::PrintableState_JOB_ABORTED
);
247 Sequence
< beans::PropertyValue
> SfxPrinterController::getPageParameters( int i_nPage
) const
249 boost::shared_ptr
<Printer
> pPrinter( getPrinter() );
250 Sequence
< beans::PropertyValue
> aResult
;
252 if( mxRenderable
.is() && pPrinter
)
254 Sequence
< beans::PropertyValue
> aJobOptions( getMergedOptions() );
257 aResult
= mxRenderable
->getRenderer( i_nPage
, getSelectionObject(), aJobOptions
);
259 catch( lang::IllegalArgumentException
& )
262 catch (lang::DisposedException
&)
264 OSL_TRACE("SfxPrinterController: document disposed while printing");
265 const_cast<SfxPrinterController
*>(this)->setJobState(
266 view::PrintableState_JOB_ABORTED
);
272 void SfxPrinterController::printPage( int i_nPage
) const
274 boost::shared_ptr
<Printer
> pPrinter( getPrinter() );
275 if( mxRenderable
.is() && pPrinter
)
277 Sequence
< beans::PropertyValue
> aJobOptions( getMergedOptions() );
280 mxRenderable
->render( i_nPage
, getSelectionObject(), aJobOptions
);
282 catch( lang::IllegalArgumentException
& )
284 // don't care enough about nonexistant page here
285 // to provoke a crash
287 catch (lang::DisposedException
&)
289 OSL_TRACE("SfxPrinterController: document disposed while printing");
290 const_cast<SfxPrinterController
*>(this)->setJobState(
291 view::PrintableState_JOB_ABORTED
);
296 void SfxPrinterController::jobStarted()
300 m_bOrigStatus
= mpObjectShell
->IsEnableSetModified();
302 // check configuration: shall update of printing information in DocInfo set the document to "modified"?
303 if ( m_bOrigStatus
&& !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
305 mpObjectShell
->EnableSetModified( sal_False
);
306 m_bNeedsChange
= sal_True
;
309 // refresh document info
310 uno::Reference
<document::XDocumentProperties
> xDocProps(mpObjectShell
->getDocProperties());
311 m_aLastPrintedBy
= xDocProps
->getPrintedBy();
312 m_aLastPrinted
= xDocProps
->getPrintDate();
314 xDocProps
->setPrintedBy( mpObjectShell
->IsUseUserData()
315 ? OUString( SvtUserOptions().GetFullName() )
317 ::DateTime
now( ::DateTime::SYSTEM
);
319 xDocProps
->setPrintDate( util::DateTime(
320 now
.GetNanoSec(), now
.GetSec(), now
.GetMin(), now
.GetHour(),
321 now
.GetDay(), now
.GetMonth(), now
.GetYear(), false) );
323 SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_PRINTDOC
, GlobalEventConfig::GetEventName( STR_EVENT_PRINTDOC
), mpObjectShell
) );
324 // FIXME: how to get all print options incl. AdditionalOptions easily?
325 uno::Sequence
< beans::PropertyValue
> aOpts
;
326 mpObjectShell
->Broadcast( SfxPrintingHint( view::PrintableState_JOB_STARTED
, aOpts
) );
330 void SfxPrinterController::jobFinished( com::sun::star::view::PrintableState nState
)
334 bool bCopyJobSetup
= false;
335 mpObjectShell
->Broadcast( SfxPrintingHint( nState
) );
338 case view::PrintableState_JOB_FAILED
:
340 // "real" problem (not simply printing cancelled by user)
341 OUString
aMsg( SfxResId(STR_NOSTARTPRINTER
).toString() );
343 ErrorBox( mpViewShell
->GetWindow(), WB_OK
| WB_DEF_OK
, aMsg
).Execute();
344 // intentionally no break
346 case view::PrintableState_JOB_ABORTED
:
348 // printing not successful, reset DocInfo
349 uno::Reference
<document::XDocumentProperties
> xDocProps(mpObjectShell
->getDocProperties());
350 xDocProps
->setPrintedBy(m_aLastPrintedBy
);
351 xDocProps
->setPrintDate(m_aLastPrinted
);
355 case view::PrintableState_JOB_SPOOLED
:
356 case view::PrintableState_JOB_COMPLETED
:
358 SfxBindings
& rBind
= mpViewShell
->GetViewFrame()->GetBindings();
359 rBind
.Invalidate( SID_PRINTDOC
);
360 rBind
.Invalidate( SID_PRINTDOCDIRECT
);
361 rBind
.Invalidate( SID_SETUPPRINTER
);
362 bCopyJobSetup
= ! m_bTempPrinter
;
370 if( bCopyJobSetup
&& mpViewShell
)
373 // Note: this possibly creates a printer that gets immediately replaced
374 // by a new one. The reason for this is that otherwise we would not get
375 // the printer's SfxItemSet here to copy. Awkward, but at the moment there is no
376 // other way here to get the item set.
377 SfxPrinter
* pDocPrt
= mpViewShell
->GetPrinter(sal_True
);
380 if( pDocPrt
->GetName() == getPrinter()->GetName() )
381 pDocPrt
->SetJobSetup( getPrinter()->GetJobSetup() );
384 SfxPrinter
* pNewPrt
= new SfxPrinter( pDocPrt
->GetOptions().Clone(), getPrinter()->GetName() );
385 pNewPrt
->SetJobSetup( getPrinter()->GetJobSetup() );
386 mpViewShell
->SetPrinter( pNewPrt
, SFX_PRINTER_PRINTER
| SFX_PRINTER_JOBSETUP
);
391 if ( m_bNeedsChange
)
392 mpObjectShell
->EnableSetModified( m_bOrigStatus
);
396 mpViewShell
->pImp
->m_pPrinterController
.reset();
401 //====================================================================
403 class SfxDialogExecutor_Impl
407 An instance of this class is created for the life span of the
408 printer dialogue, to create in its click handler for the additions by the
409 virtual method of the derived SfxViewShell generated print options dialogue
410 and to cache the options set there as SfxItemSet.
415 SfxViewShell
* _pViewSh
;
416 PrinterSetupDialog
* _pSetupParent
;
417 SfxItemSet
* _pOptions
;
418 sal_Bool _bHelpDisabled
;
420 DECL_LINK( Execute
, void * );
423 SfxDialogExecutor_Impl( SfxViewShell
* pViewSh
, PrinterSetupDialog
* pParent
);
424 ~SfxDialogExecutor_Impl() { delete _pOptions
; }
426 Link
GetLink() const { return LINK( this, SfxDialogExecutor_Impl
, Execute
); }
427 const SfxItemSet
* GetOptions() const { return _pOptions
; }
428 void DisableHelp() { _bHelpDisabled
= sal_True
; }
431 //--------------------------------------------------------------------
433 SfxDialogExecutor_Impl::SfxDialogExecutor_Impl( SfxViewShell
* pViewSh
, PrinterSetupDialog
* pParent
) :
435 _pViewSh ( pViewSh
),
436 _pSetupParent ( pParent
),
438 _bHelpDisabled ( sal_False
)
443 //--------------------------------------------------------------------
445 IMPL_LINK_NOARG(SfxDialogExecutor_Impl
, Execute
)
447 // Options noted locally
450 DBG_ASSERT( _pSetupParent
, "no dialog parent" );
452 _pOptions
= ( (SfxPrinter
*)_pSetupParent
->GetPrinter() )->GetOptions().Clone();
456 SfxPrintOptionsDialog
* pDlg
= new SfxPrintOptionsDialog( static_cast<Window
*>(_pSetupParent
),
457 _pViewSh
, _pOptions
);
458 if ( _bHelpDisabled
)
460 if ( pDlg
->Execute() == RET_OK
)
463 _pOptions
= pDlg
->GetOptions().Clone();
471 //-------------------------------------------------------------------------
473 SfxPrinter
* SfxViewShell::SetPrinter_Impl( SfxPrinter
*pNewPrinter
)
476 /* Internal method for setting the differences between 'pNewPrinter' to the
477 current printer. pNewPrinter is either taken over or deleted.
481 // get current Printer
482 SfxPrinter
*pDocPrinter
= GetPrinter();
484 // Evaluate Printer Options
485 bool bOriToDoc
= false;
486 bool bSizeToDoc
= false;
487 if ( &pDocPrinter
->GetOptions() )
489 sal_uInt16 nWhich
= GetPool().GetWhich(SID_PRINTER_CHANGESTODOC
);
490 const SfxFlagItem
*pFlagItem
= 0;
491 pDocPrinter
->GetOptions().GetItemState( nWhich
, sal_False
, (const SfxPoolItem
**) &pFlagItem
);
492 bOriToDoc
= pFlagItem
? (pFlagItem
->GetValue() & SFX_PRINTER_CHG_ORIENTATION
) : sal_False
;
493 bSizeToDoc
= pFlagItem
? (pFlagItem
->GetValue() & SFX_PRINTER_CHG_SIZE
) : sal_False
;
496 // Determine the previous format and size
497 Orientation eOldOri
= pDocPrinter
->GetOrientation();
498 Size aOldPgSz
= pDocPrinter
->GetPaperSizePixel();
500 // Determine the new format and size
501 Orientation eNewOri
= pNewPrinter
->GetOrientation();
502 Size aNewPgSz
= pNewPrinter
->GetPaperSizePixel();
504 // Determine the changes in page format
505 sal_Bool bOriChg
= (eOldOri
!= eNewOri
) && bOriToDoc
;
506 sal_Bool bPgSzChg
= ( aOldPgSz
.Height() !=
507 ( bOriChg
? aNewPgSz
.Width() : aNewPgSz
.Height() ) ||
509 ( bOriChg
? aNewPgSz
.Height() : aNewPgSz
.Width() ) ) &&
512 // Message and Flags for page format, summaries changes
514 sal_uInt16 nNewOpt
=0;
515 if( bOriChg
&& bPgSzChg
)
517 aMsg
= SfxResId(STR_PRINT_NEWORISIZE
).toString();
518 nNewOpt
= SFX_PRINTER_CHG_ORIENTATION
| SFX_PRINTER_CHG_SIZE
;
522 aMsg
= SfxResId(STR_PRINT_NEWORI
).toString();
523 nNewOpt
= SFX_PRINTER_CHG_ORIENTATION
;
527 aMsg
= SfxResId(STR_PRINT_NEWSIZE
).toString();
528 nNewOpt
= SFX_PRINTER_CHG_SIZE
;
531 // Summaries in this variable what has been changed.
532 sal_uInt16 nChangedFlags
= 0;
534 // Ask if possible, if page format should be taken over from printer.
535 if ( ( bOriChg
|| bPgSzChg
) &&
536 RET_YES
== QueryBox(0, WB_YES_NO
| WB_DEF_OK
, aMsg
).Execute() )
538 // Flags with changes for <SetPrinter(SfxPrinter*)> are maintained
539 nChangedFlags
|= nNewOpt
;
542 // For the MAC to have its "temporary of class String" in next if()
543 String aTempPrtName
= pNewPrinter
->GetName();
544 String aDocPrtName
= pDocPrinter
->GetName();
546 // Was the printer selection changed from Default to Specific
547 // or the other way around?
548 if ( (aTempPrtName
!= aDocPrtName
) || (pDocPrinter
->IsDefPrinter() != pNewPrinter
->IsDefPrinter()) )
550 nChangedFlags
|= SFX_PRINTER_PRINTER
|SFX_PRINTER_JOBSETUP
;
551 pDocPrinter
= pNewPrinter
;
555 // Compare extra options
556 if ( ! (pNewPrinter
->GetOptions() == pDocPrinter
->GetOptions()) )
558 // Option have changed
559 pDocPrinter
->SetOptions( pNewPrinter
->GetOptions() );
560 nChangedFlags
|= SFX_PRINTER_OPTIONS
;
564 JobSetup aNewJobSetup
= pNewPrinter
->GetJobSetup();
565 JobSetup aOldJobSetup
= pDocPrinter
->GetJobSetup();
566 if ( aNewJobSetup
!= aOldJobSetup
)
568 nChangedFlags
|= SFX_PRINTER_JOBSETUP
;
571 // Keep old changed Printer.
572 pDocPrinter
->SetPrinterProps( pNewPrinter
);
576 if ( 0 != nChangedFlags
)
577 // SetPrinter will delete the old printer if it changes
578 SetPrinter( pDocPrinter
, nChangedFlags
);
582 void SfxViewShell::ExecPrint( const uno::Sequence
< beans::PropertyValue
>& rProps
, sal_Bool bIsAPI
, sal_Bool bIsDirect
)
584 // get the current selection; our controller should know it
585 Reference
< frame::XController
> xController( GetController() );
586 Reference
< view::XSelectionSupplier
> xSupplier( xController
, UNO_QUERY
);
590 aSelection
= xSupplier
->getSelection();
592 aSelection
<<= GetObjectShell()->GetModel();
593 Any
aComplete( makeAny( GetObjectShell()->GetModel() ) );
594 Any
aViewProp( makeAny( xController
) );
595 boost::shared_ptr
<Printer
> aPrt
;
597 const beans::PropertyValue
* pVal
= rProps
.getConstArray();
598 for( sal_Int32 i
= 0; i
< rProps
.getLength(); i
++ )
600 if ( pVal
[i
].Name
== "PrinterName" )
602 OUString aPrinterName
;
603 pVal
[i
].Value
>>= aPrinterName
;
604 aPrt
.reset( new Printer( aPrinterName
) );
609 boost::shared_ptr
<vcl::PrinterController
> pController( new SfxPrinterController(
620 pImp
->m_pPrinterController
= pController
;
622 SfxObjectShell
*pObjShell
= GetObjectShell();
623 pController
->setValue( OUString( "JobName" ),
624 makeAny( OUString( pObjShell
->GetTitle(0) ) ) );
627 SfxPrinter
* pDocPrt
= GetPrinter(sal_False
);
628 JobSetup aJobSetup
= pDocPrt
? pDocPrt
->GetJobSetup() : GetJobSetup();
630 aJobSetup
.SetValue( String( "IsQuickJob" ),
633 Printer::PrintJob( pController
, aJobSetup
);
636 Printer
* SfxViewShell::GetActivePrinter() const
638 return (pImp
->m_pPrinterController
)
639 ? pImp
->m_pPrinterController
->getPrinter().get() : 0;
642 void SfxViewShell::ExecPrint_Impl( SfxRequest
&rReq
)
644 sal_uInt16 nDialogRet
= RET_CANCEL
;
645 SfxPrinter
* pPrinter
= 0;
646 SfxDialogExecutor_Impl
* pExecutor
= 0;
647 bool bSilent
= false;
649 // does the function have been called by the user interface or by an API call
650 sal_Bool bIsAPI
= rReq
.GetArgs() && rReq
.GetArgs()->Count();
653 // the function have been called by the API
655 // Should it be visible on the user interface,
656 // should it launch popup dialogue ?
657 SFX_REQUEST_ARG(rReq
, pSilentItem
, SfxBoolItem
, SID_SILENT
, sal_False
);
658 bSilent
= pSilentItem
&& pSilentItem
->GetValue();
661 // no help button in dialogs if called from the help window
662 // (pressing help button would exchange the current page inside the help
663 // document that is going to be printed!)
664 String
aHelpFilterName( "writer_web_HTML_help" );
665 SfxMedium
* pMedium
= GetViewFrame()->GetObjectShell()->GetMedium();
666 const SfxFilter
* pFilter
= pMedium
? pMedium
->GetFilter() : NULL
;
667 sal_Bool bPrintOnHelp
= ( pFilter
&& pFilter
->GetFilterName() == aHelpFilterName
);
669 const sal_uInt16 nId
= rReq
.GetSlot();
672 case SID_PRINTDOC
: // display the printer selection and properties dialogue : File > Printā¦
673 case SID_PRINTDOCDIRECT
: // Print the document directly, without displaying the dialogue
675 SfxObjectShell
* pDoc
= GetObjectShell();
677 // derived class may decide to abort this
678 if( pDoc
== NULL
|| !pDoc
->QuerySlotExecutable( nId
) )
680 rReq
.SetReturnValue( SfxBoolItem( 0, sal_False
) );
684 if ( !bSilent
&& pDoc
->QueryHiddenInformation( WhenPrinting
, NULL
) != RET_YES
)
687 // should we print only the selection or the whole document
688 SFX_REQUEST_ARG(rReq
, pSelectItem
, SfxBoolItem
, SID_SELECTION
, sal_False
);
689 sal_Bool bSelection
= ( pSelectItem
!= NULL
&& pSelectItem
->GetValue() );
690 // detect non api call from writer ( that adds SID_SELECTION ) and reset bIsAPI
691 if ( pSelectItem
&& rReq
.GetArgs()->Count() == 1 )
694 uno::Sequence
< beans::PropertyValue
> aProps
;
697 // supported properties:
698 // String PrinterName
709 // the TransformItems function overwrite aProps
710 TransformItems( nId
, *rReq
.GetArgs(), aProps
, GetInterface()->GetSlot(nId
) );
712 for ( sal_Int32 nProp
=0; nProp
< aProps
.getLength(); ++nProp
)
714 if ( aProps
[nProp
].Name
== "Copies" )
716 aProps
[nProp
]. Name
= OUString("CopyCount");
718 else if ( aProps
[nProp
].Name
== "RangeText" )
720 aProps
[nProp
]. Name
= OUString("Pages");
722 else if ( aProps
[nProp
].Name
== "Asynchron" )
724 aProps
[nProp
]. Name
= OUString("Wait");
725 sal_Bool bAsynchron
= sal_False
;
726 aProps
[nProp
].Value
>>= bAsynchron
;
727 aProps
[nProp
].Value
<<= (sal_Bool
) (!bAsynchron
);
729 else if ( aProps
[nProp
].Name
== "Silent" )
731 aProps
[nProp
]. Name
= OUString("MonitorVisible");
732 sal_Bool bPrintSilent
= sal_False
;
733 aProps
[nProp
].Value
>>= bPrintSilent
;
734 aProps
[nProp
].Value
<<= (sal_Bool
) (!bPrintSilent
);
739 // we will add the "PrintSelectionOnly" or "HideHelpButton" properties
740 // we have to increase the capacity of aProps
741 sal_Int32 nLen
= aProps
.getLength();
742 aProps
.realloc( nLen
+ 1 );
744 // HACK: writer sets the SID_SELECTION item when printing directly and expects
745 // to get only the selection document in that case (see getSelectionObject)
746 // however it also reacts to the PrintContent property. We need this distinction here, too,
747 // else one of the combinations print / print direct and selection / all will not work.
748 // it would be better if writer handled this internally
749 if( nId
== SID_PRINTDOCDIRECT
)
751 aProps
[nLen
].Name
= OUString( "PrintSelectionOnly" );
752 aProps
[nLen
].Value
= makeAny( bSelection
);
754 else // if nId == SID_PRINTDOC ; nothing to do with the previous HACK
756 // should the printer selection and properties dialogue display an help button
757 aProps
[nLen
].Name
= OUString( "HideHelpButton" );
758 aProps
[nLen
].Value
= makeAny( bPrintOnHelp
);
761 ExecPrint( aProps
, bIsAPI
, (nId
== SID_PRINTDOCDIRECT
) );
767 case SID_SETUPPRINTER
: // display the printer settings dialogue : File > Printer Settingsā¦
768 case SID_PRINTER_NAME
: // only for recorded macros
770 // get printer and printer settings from the document
771 SfxPrinter
*pDocPrinter
= GetPrinter(sal_True
);
773 // look for printer in parameters
774 SFX_REQUEST_ARG( rReq
, pPrinterItem
, SfxStringItem
, SID_PRINTER_NAME
, sal_False
);
777 // use PrinterName parameter to create a printer
778 pPrinter
= new SfxPrinter( pDocPrinter
->GetOptions().Clone(), ((const SfxStringItem
*) pPrinterItem
)->GetValue() );
780 // if printer is unknown, it can't be used - now printer from document will be used
781 if ( !pPrinter
->IsKnown() )
785 if ( SID_PRINTER_NAME
== nId
)
787 // just set a recorded printer name
789 SetPrinter( pPrinter
, SFX_PRINTER_PRINTER
);
793 // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer
795 // use default printer from document
796 pPrinter
= pDocPrinter
;
798 if( !pPrinter
|| !pPrinter
->IsValid() )
800 // no valid printer either in ItemSet or at the document
802 ErrorBox( NULL
, WB_OK
| WB_DEF_OK
, SfxResId(STR_NODEFPRINTER
).toString() ).Execute();
804 rReq
.SetReturnValue(SfxBoolItem(0,sal_False
));
809 // FIXME: printer isn't used for printing anymore!
810 if( pPrinter
->IsPrinting() )
812 // if printer is busy, abort configuration
814 InfoBox( NULL
, SfxResId(STR_ERROR_PRINTER_BUSY
).toString() ).Execute();
815 rReq
.SetReturnValue(SfxBoolItem(0,sal_False
));
820 // if no arguments are given, retrieve them from a dialog
823 // PrinterDialog needs a temporary printer
824 SfxPrinter
* pDlgPrinter
= pPrinter
->Clone();
827 // execute PrinterSetupDialog
828 PrinterSetupDialog
* pPrintSetupDlg
= new PrinterSetupDialog( GetWindow() );
830 if (pImp
->m_bHasPrintOptions
&& HasPrintOptionsPage())
832 // additional controls for dialog
833 pExecutor
= new SfxDialogExecutor_Impl( this, pPrintSetupDlg
);
835 pExecutor
->DisableHelp();
836 pPrintSetupDlg
->SetOptionsHdl( pExecutor
->GetLink() );
839 pPrintSetupDlg
->SetPrinter( pDlgPrinter
);
840 nDialogRet
= pPrintSetupDlg
->Execute();
842 if ( pExecutor
&& pExecutor
->GetOptions() )
844 if ( nDialogRet
== RET_OK
)
845 // remark: have to be recorded if possible!
846 pDlgPrinter
->SetOptions( *pExecutor
->GetOptions() );
849 pPrinter
->SetOptions( *pExecutor
->GetOptions() );
850 SetPrinter( pPrinter
, SFX_PRINTER_OPTIONS
);
854 DELETEZ( pPrintSetupDlg
);
856 // no recording of PrinterSetup except printer name (is printer dependent)
859 if ( nDialogRet
== RET_OK
)
861 if ( pPrinter
->GetName() != pDlgPrinter
->GetName() )
863 // user has changed the printer -> macro recording
864 SfxRequest
aReq( GetViewFrame(), SID_PRINTER_NAME
);
865 aReq
.AppendItem( SfxStringItem( SID_PRINTER_NAME
, pDlgPrinter
->GetName() ) );
869 // take the changes made in the dialog
870 pPrinter
= SetPrinter_Impl( pDlgPrinter
);
872 // forget new printer, it was taken over (as pPrinter) or deleted
878 // PrinterDialog is used to transfer information on printing,
879 // so it will only be deleted here if dialog was cancelled
880 DELETEZ( pDlgPrinter
);
882 if ( SID_PRINTDOC
== nId
)
883 rReq
.SetReturnValue(SfxBoolItem(0,sal_False
));
890 //--------------------------------------------------------------------
892 SfxPrinter
* SfxViewShell::GetPrinter( sal_Bool
/*bCreate*/ )
897 //--------------------------------------------------------------------
899 sal_uInt16
SfxViewShell::SetPrinter( SfxPrinter
* /*pNewPrinter*/, sal_uInt16
/*nDiffFlags*/, bool )
904 //--------------------------------------------------------------------
906 SfxTabPage
* SfxViewShell::CreatePrintOptionsPage
909 const SfxItemSet
& /*rOptions*/
915 bool SfxViewShell::HasPrintOptionsPage() const
920 JobSetup
SfxViewShell::GetJobSetup() const
925 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */