LibreOffice Module sfx2 (master) 1
viewprn.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21
22#include <com/sun/star/document/XDocumentProperties.hpp>
23#include <com/sun/star/view/XRenderable.hpp>
24#include <com/sun/star/view/XSelectionSupplier.hpp>
25
27#include <officecfg/Office/Common.hxx>
28#include <sal/log.hxx>
29#include <utility>
30#include <vcl/svapp.hxx>
31#include <vcl/weld.hxx>
32#include <svtools/prnsetup.hxx>
33#include <svl/flagitem.hxx>
34#include <svl/stritem.hxx>
35#include <svl/eitem.hxx>
37#include <tools/datetime.hxx>
38#include <sfx2/bindings.hxx>
39#include <sfx2/objface.hxx>
40#include <sfx2/viewsh.hxx>
41#include "viewimp.hxx"
42#include <sfx2/viewfrm.hxx>
43#include <sfx2/printer.hxx>
44#include <sfx2/sfxresid.hxx>
45#include <sfx2/request.hxx>
46#include <sfx2/objsh.hxx>
47#include <sfx2/event.hxx>
48#include <sfx2/docfile.hxx>
49#include <sfx2/docfilt.hxx>
50#include <sfx2/sfxsids.hrc>
51#include <sfx2/strings.hrc>
52#include <sfx2/sfxuno.hxx>
53#include <sfx2/tabdlg.hxx>
54
56
57#include "prnmon.hxx"
58
59using namespace com::sun::star;
60using namespace com::sun::star::uno;
61
63{
73 bool m_bApi;
75 util::DateTime m_aLastPrinted;
77
79 const Any& getSelectionObject() const;
80
81public:
82 SfxPrinterController( const VclPtr<Printer>& i_rPrinter,
83 Any i_Complete,
84 Any i_Selection,
85 const Any& i_rViewProp,
86 const Reference< view::XRenderable >& i_xRender,
87 bool i_bApi, bool i_bDirect,
88 SfxViewShell* pView,
89 const uno::Sequence< beans::PropertyValue >& rProps
90 );
91
92 virtual void Notify( SfxBroadcaster&, const SfxHint& ) override;
93
94 virtual int getPageCount() const override;
95 virtual Sequence< beans::PropertyValue > getPageParameters( int i_nPage ) const override;
96 virtual void printPage( int i_nPage ) const override;
97 virtual void jobStarted() override;
98 virtual void jobFinished( css::view::PrintableState ) override;
99};
100
102 Any i_Complete,
103 Any i_Selection,
104 const Any& i_rViewProp,
105 const Reference< view::XRenderable >& i_xRender,
106 bool i_bApi, bool i_bDirect,
107 SfxViewShell* pView,
108 const uno::Sequence< beans::PropertyValue >& rProps
109 )
110 : PrinterController(i_rPrinter, pView ? pView->GetFrameWeld() : nullptr)
111 , maCompleteSelection(std::move( i_Complete ))
112 , maSelection(std::move( i_Selection ))
113 , mxRenderable( i_xRender )
114 , mpLastPrinter( nullptr )
115 , mpViewShell( pView )
116 , mpObjectShell(nullptr)
117 , m_bOrigStatus( false )
118 , m_bNeedsChange( false )
119 , m_bApi(i_bApi)
120 , m_bTempPrinter( i_rPrinter )
121{
122 if ( mpViewShell )
123 {
127 }
128
129 // initialize extra ui options
130 if( mxRenderable.is() )
131 {
132 for (const auto& rProp : rProps)
133 setValue( rProp.Name, rProp.Value );
134
136 comphelper::makePropertyValue("ExtraPrintUIOptions", Any{}),
137 comphelper::makePropertyValue("View", i_rViewProp),
138 comphelper::makePropertyValue("IsPrinter", true)
139 };
140 try
141 {
142 const Sequence< beans::PropertyValue > aRenderParms( mxRenderable->getRenderer( 0 , getSelectionObject(), aRenderOptions ) );
143 for( const auto& rRenderParm : aRenderParms )
144 {
145 if ( rRenderParm.Name == "ExtraPrintUIOptions" )
146 {
148 rRenderParm.Value >>= aUIProps;
149 setUIOptions( aUIProps );
150 }
151 else if( rRenderParm.Name == "NUp" )
152 {
153 setValue( rRenderParm.Name, rRenderParm.Value );
154 }
155 }
156 }
157 catch( lang::IllegalArgumentException& )
158 {
159 // the first renderer should always be available for the UI options,
160 // but catch the exception to be safe
161 }
162 }
163
164 // set some job parameters
165 setValue( "IsApi", Any( i_bApi ) );
166 setValue( "IsDirect", Any( i_bDirect ) );
167 setValue( "IsPrinter", Any( true ) );
168 setValue( "View", i_rViewProp );
169}
170
172{
173 if ( rHint.GetId() == SfxHintId::Dying )
174 {
178 mpViewShell = nullptr;
179 mpObjectShell = nullptr;
180 }
181}
182
184{
185 const beans::PropertyValue* pVal = getValue( OUString( "PrintSelectionOnly" ) );
186 if( pVal )
187 {
188 bool bSel = false;
189 pVal->Value >>= bSel;
190 return bSel ? maSelection : maCompleteSelection;
191 }
192
193 sal_Int32 nChoice = 0;
194 pVal = getValue( OUString( "PrintContent" ) );
195 if( pVal )
196 pVal->Value >>= nChoice;
197
198 return (nChoice > 1) ? maSelection : maCompleteSelection;
199}
200
202{
203 VclPtr<Printer> xPrinter( getPrinter() );
204 if( xPrinter.get() != mpLastPrinter )
205 {
206 mpLastPrinter = xPrinter.get();
207 rtl::Reference<VCLXDevice> pXDevice = new VCLXDevice();
208 pXDevice->SetOutputDevice( mpLastPrinter );
209 mxDevice.set( pXDevice );
210 }
211
213 "RenderDevice", mxDevice) };
214
215 aRenderOptions = getJobProperties( aRenderOptions );
216 return aRenderOptions;
217}
218
220{
221 int nPages = 0;
222 VclPtr<Printer> xPrinter( getPrinter() );
223 if( mxRenderable.is() && xPrinter )
224 {
226 try
227 {
228 nPages = mxRenderable->getRendererCount( getSelectionObject(), aJobOptions );
229 }
230 catch (lang::DisposedException &)
231 {
232 SAL_WARN("sfx", "SfxPrinterController: document disposed while printing");
233 const_cast<SfxPrinterController*>(this)->setJobState(
234 view::PrintableState_JOB_ABORTED);
235 }
236 }
237 return nPages;
238}
239
241{
242 VclPtr<Printer> xPrinter( getPrinter() );
244
245 if (mxRenderable.is() && xPrinter)
246 {
248 try
249 {
250 aResult = mxRenderable->getRenderer( i_nPage, getSelectionObject(), aJobOptions );
251 }
252 catch( lang::IllegalArgumentException& )
253 {
254 }
255 catch (lang::DisposedException &)
256 {
257 SAL_WARN("sfx", "SfxPrinterController: document disposed while printing");
258 const_cast<SfxPrinterController*>(this)->setJobState(
259 view::PrintableState_JOB_ABORTED);
260 }
261 }
262 return aResult;
263}
264
265void SfxPrinterController::printPage( int i_nPage ) const
266{
267 VclPtr<Printer> xPrinter( getPrinter() );
268 if( !mxRenderable.is() || !xPrinter )
269 return;
270
272 try
273 {
274 mxRenderable->render( i_nPage, getSelectionObject(), aJobOptions );
275 }
276 catch( lang::IllegalArgumentException& )
277 {
278 // don't care enough about nonexistent page here
279 // to provoke a crash
280 }
281 catch (lang::DisposedException &)
282 {
283 SAL_WARN("sfx", "SfxPrinterController: document disposed while printing");
284 const_cast<SfxPrinterController*>(this)->setJobState(
285 view::PrintableState_JOB_ABORTED);
286 }
287}
288
290{
291 if ( !mpObjectShell )
292 return;
293
295
296 // check configuration: shall update of printing information in DocInfo set the document to "modified"?
297 if (m_bOrigStatus && !officecfg::Office::Common::Print::PrintingModifiesDocument::get())
298 {
300 m_bNeedsChange = true;
301 }
302
303 // refresh document info
304 uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
305 m_aLastPrintedBy = xDocProps->getPrintedBy();
306 m_aLastPrinted = xDocProps->getPrintDate();
307
308 xDocProps->setPrintedBy( mpObjectShell->IsUseUserData()
309 ? SvtUserOptions().GetFullName()
310 : OUString() );
312
313 xDocProps->setPrintDate( now.GetUNODateTime() );
314
315 uno::Sequence < beans::PropertyValue > aOpts;
316 aOpts = getJobProperties( aOpts );
317
318 uno::Reference< frame::XController2 > xController;
319 if ( mpViewShell )
320 xController.set( mpViewShell->GetController(), uno::UNO_QUERY );
321
323 view::PrintableState_JOB_STARTED, aOpts, mpObjectShell, xController ) );
324}
325
326void SfxPrinterController::jobFinished( css::view::PrintableState nState )
327{
328 if ( !mpObjectShell )
329 return;
330
331 bool bCopyJobSetup = false;
333 switch ( nState )
334 {
335 case view::PrintableState_JOB_SPOOLING_FAILED :
336 case view::PrintableState_JOB_FAILED :
337 {
338 // "real" problem (not simply printing cancelled by user)
339 OUString aMsg( SfxResId(STR_NOSTARTPRINTER) );
340 if ( !m_bApi )
341 {
342 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(mpViewShell->GetFrameWeld(),
343 VclMessageType::Warning, VclButtonsType::Ok,
344 aMsg));
345 xBox->run();
346 }
347 [[fallthrough]];
348 }
349 case view::PrintableState_JOB_ABORTED :
350 {
351 // printing not successful, reset DocInfo
352 uno::Reference<document::XDocumentProperties> xDocProps(mpObjectShell->getDocProperties());
353 xDocProps->setPrintedBy(m_aLastPrintedBy);
354 xDocProps->setPrintDate(m_aLastPrinted);
355 break;
356 }
357
358 case view::PrintableState_JOB_SPOOLED :
359 case view::PrintableState_JOB_COMPLETED :
360 {
362 rBind.Invalidate( SID_PRINTDOC );
363 rBind.Invalidate( SID_PRINTDOCDIRECT );
364 rBind.Invalidate( SID_SETUPPRINTER );
365 bCopyJobSetup = ! m_bTempPrinter;
366 break;
367 }
368
369 default:
370 break;
371 }
372
373 if( bCopyJobSetup && mpViewShell )
374 {
375 // #i114306#
376 // Note: this possibly creates a printer that gets immediately replaced
377 // by a new one. The reason for this is that otherwise we would not get
378 // the printer's SfxItemSet here to copy. Awkward, but at the moment there is no
379 // other way here to get the item set.
380 SfxPrinter* pDocPrt = mpViewShell->GetPrinter(true);
381 if( pDocPrt )
382 {
383 if( pDocPrt->GetName() == getPrinter()->GetName() )
384 pDocPrt->SetJobSetup( getPrinter()->GetJobSetup() );
385 else
386 {
388 pNewPrt->SetJobSetup( getPrinter()->GetJobSetup() );
390 }
391 }
392 }
393
394 if ( m_bNeedsChange )
396
397 if ( mpViewShell )
398 {
399 mpViewShell->pImpl->m_xPrinterController.reset();
400 }
401}
402
403namespace {
404
411class SfxDialogExecutor_Impl
412{
413private:
414 SfxViewShell* _pViewSh;
415 PrinterSetupDialog& _rSetupParent;
416 std::unique_ptr<SfxItemSet> _pOptions;
417 bool _bHelpDisabled;
418
419 DECL_LINK( Execute, weld::Button&, void );
420
421public:
422 SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog& rParent );
423
424 Link<weld::Button&, void> GetLink() const { return LINK(const_cast<SfxDialogExecutor_Impl*>(this), SfxDialogExecutor_Impl, Execute); }
425 const SfxItemSet* GetOptions() const { return _pOptions.get(); }
426 void DisableHelp() { _bHelpDisabled = true; }
427};
428
429}
430
431SfxDialogExecutor_Impl::SfxDialogExecutor_Impl( SfxViewShell* pViewSh, PrinterSetupDialog& rParent ) :
432
433 _pViewSh ( pViewSh ),
434 _rSetupParent ( rParent ),
435 _bHelpDisabled ( false )
436
437{
438}
439
440IMPL_LINK_NOARG(SfxDialogExecutor_Impl, Execute, weld::Button&, void)
441{
442 // Options noted locally
443 if ( !_pOptions )
444 {
445 _pOptions = static_cast<SfxPrinter*>( _rSetupParent.GetPrinter() )->GetOptions().Clone();
446 }
447
448 assert(_pOptions);
449 if (!_pOptions)
450 return;
451
452 // Create Dialog
453 SfxPrintOptionsDialog aDlg(_rSetupParent.GetFrameWeld(), _pViewSh, _pOptions.get() );
454 if (_bHelpDisabled)
455 aDlg.DisableHelp();
456 if (aDlg.run() == RET_OK)
457 {
458 _pOptions = aDlg.GetOptions().Clone();
459 }
460}
461
467{
468 // get current Printer
469 SfxPrinter *pDocPrinter = GetPrinter();
470
471 // Evaluate Printer Options
472 const SfxFlagItem *pFlagItem = pDocPrinter->GetOptions().GetItemIfSet( SID_PRINTER_CHANGESTODOC, false );
473 bool bOriToDoc = pFlagItem && (static_cast<SfxPrinterChangeFlags>(pFlagItem->GetValue()) & SfxPrinterChangeFlags::CHG_ORIENTATION);
474 bool bSizeToDoc = pFlagItem && (static_cast<SfxPrinterChangeFlags>(pFlagItem->GetValue()) & SfxPrinterChangeFlags::CHG_SIZE);
475
476 // Determine the previous format and size
477 Orientation eOldOri = pDocPrinter->GetOrientation();
478 Size aOldPgSz = pDocPrinter->GetPaperSizePixel();
479
480 // Determine the new format and size
481 Orientation eNewOri = pNewPrinter->GetOrientation();
482 Size aNewPgSz = pNewPrinter->GetPaperSizePixel();
483
484 // Determine the changes in page format
485 bool bOriChg = (eOldOri != eNewOri) && bOriToDoc;
486 bool bPgSzChg = ( aOldPgSz.Height() !=
487 ( bOriChg ? aNewPgSz.Width() : aNewPgSz.Height() ) ||
488 aOldPgSz.Width() !=
489 ( bOriChg ? aNewPgSz.Height() : aNewPgSz.Width() ) ) &&
490 bSizeToDoc;
491
492 // Message and Flags for page format changes
493 OUString aMsg;
495 if( bOriChg && bPgSzChg )
496 {
497 aMsg = SfxResId(STR_PRINT_NEWORISIZE);
499 }
500 else if (bOriChg )
501 {
502 aMsg = SfxResId(STR_PRINT_NEWORI);
504 }
505 else if (bPgSzChg)
506 {
507 aMsg = SfxResId(STR_PRINT_NEWSIZE);
509 }
510
511 // Summarize in this variable what has been changed.
513
514 // Ask if possible, if page format should be taken over from printer.
515 if (bOriChg || bPgSzChg)
516 {
517 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
518 VclMessageType::Question, VclButtonsType::YesNo,
519 aMsg));
520 if (RET_YES == xBox->run())
521 {
522 // Flags with changes for <SetPrinter(SfxPrinter*)> are maintained
523 nChangedFlags |= nNewOpt;
524 }
525 }
526
527 // Was the printer selection changed from Default to Specific
528 // or the other way around?
529 if ( (pNewPrinter->GetName() != pDocPrinter->GetName())
530 || (pDocPrinter->IsDefPrinter() != pNewPrinter->IsDefPrinter()) )
531 {
533 if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) )
534 {
535 nChangedFlags |= SfxPrinterChangeFlags::OPTIONS;
536 }
537
538 pDocPrinter = pNewPrinter;
539 }
540 else
541 {
542 // Compare extra options
543 if ( ! (pNewPrinter->GetOptions() == pDocPrinter->GetOptions()) )
544 {
545 // Option have changed
546 pDocPrinter->SetOptions( pNewPrinter->GetOptions() );
547 nChangedFlags |= SfxPrinterChangeFlags::OPTIONS;
548 }
549
550 // Compare JobSetups
551 JobSetup aNewJobSetup = pNewPrinter->GetJobSetup();
552 JobSetup aOldJobSetup = pDocPrinter->GetJobSetup();
553 if ( aNewJobSetup != aOldJobSetup )
554 {
555 nChangedFlags |= SfxPrinterChangeFlags::JOBSETUP;
556 }
557
558 // Keep old changed Printer.
559 pDocPrinter->SetPrinterProps( pNewPrinter );
560 pNewPrinter.disposeAndClear();
561 }
562
563 if ( SfxPrinterChangeFlags::NONE != nChangedFlags )
564 // SetPrinter will delete the old printer if it changes
565 SetPrinter( pDocPrinter, nChangedFlags );
566}
567
568void SfxViewShell::StartPrint( const uno::Sequence < beans::PropertyValue >& rProps, bool bIsAPI, bool bIsDirect )
569{
570 assert( !pImpl->m_xPrinterController );
571
572 // get the current selection; our controller should know it
575
576 Any aSelection;
577 if( xSupplier.is() )
578 aSelection = xSupplier->getSelection();
579 else
580 aSelection <<= GetObjectShell()->GetModel();
581 Any aComplete( Any( GetObjectShell()->GetModel() ) );
582 Any aViewProp( xController );
583 VclPtr<Printer> aPrt;
584
585 const beans::PropertyValue* pVal = std::find_if(rProps.begin(), rProps.end(),
586 [](const beans::PropertyValue& rVal) { return rVal.Name == "PrinterName"; });
587 if (pVal != rProps.end())
588 {
589 OUString aPrinterName;
590 pVal->Value >>= aPrinterName;
591 aPrt.reset( VclPtr<Printer>::Create( aPrinterName ) );
592 }
593
594 std::shared_ptr<vcl::PrinterController> xNewController(std::make_shared<SfxPrinterController>(
595 aPrt,
596 aComplete,
597 aSelection,
598 aViewProp,
600 bIsAPI,
601 bIsDirect,
602 this,
603 rProps
604 ));
605 pImpl->m_xPrinterController = xNewController;
606
607 // When no JobName was specified via com::sun::star::view::PrintOptions::JobName ,
608 // use the document title as default job name
609 css::beans::PropertyValue* pJobNameVal = xNewController->getValue("JobName");
610 if (!pJobNameVal)
611 {
612 if (SfxObjectShell* pDoc = GetObjectShell())
613 {
614 xNewController->setValue("JobName", Any(pDoc->GetTitle(1)));
615 xNewController->setPrinterModified(mbPrinterSettingsModified);
616 }
617 }
618}
619
620void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, bool bIsAPI, bool bIsDirect )
621{
622 StartPrint( rProps, bIsAPI, bIsDirect );
623 // FIXME: job setup
624 SfxPrinter* pDocPrt = GetPrinter();
625 JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : JobSetup();
627}
628
629const std::shared_ptr< vcl::PrinterController >& SfxViewShell::GetPrinterController() const
630{
631 return pImpl->m_xPrinterController;
632}
633
635{
636 return pImpl->m_xPrinterController
637 ? pImpl->m_xPrinterController->getPrinter().get() : nullptr;
638}
639
641{
642 sal_uInt16 nDialogRet = RET_CANCEL;
643 VclPtr<SfxPrinter> pPrinter;
644 bool bSilent = false;
645
646 // does the function have been called by the user interface or by an API call
647 bool bIsAPI = rReq.GetArgs() && rReq.GetArgs()->Count();
648 if ( bIsAPI )
649 {
650 // the function have been called by the API
651
652 // Should it be visible on the user interface,
653 // should it launch popup dialogue ?
654 const SfxBoolItem* pSilentItem = rReq.GetArg<SfxBoolItem>(SID_SILENT);
655 bSilent = pSilentItem && pSilentItem->GetValue();
656 }
657
658 // no help button in dialogs if called from the help window
659 // (pressing help button would exchange the current page inside the help
660 // document that is going to be printed!)
662 std::shared_ptr<const SfxFilter> pFilter = pMedium ? pMedium->GetFilter() : nullptr;
663 bool bPrintOnHelp = ( pFilter && pFilter->GetFilterName() == "writer_web_HTML_help" );
664
665 const sal_uInt16 nId = rReq.GetSlot();
666 switch( nId )
667 {
668 case SID_PRINTDOC: // display the printer selection and properties dialogue : File > Print...
669 case SID_PRINTDOCDIRECT: // Print the document directly, without displaying the dialogue
670 {
672
673 // derived class may decide to abort this
674 if( pDoc == nullptr || !pDoc->QuerySlotExecutable( nId ) )
675 {
676 rReq.SetReturnValue( SfxBoolItem( 0, false ) );
677 return;
678 }
679
680 if ( !bSilent && pDoc->QueryHiddenInformation( HiddenWarningFact::WhenPrinting, nullptr ) != RET_YES )
681 return;
682
683 // should we print only the selection or the whole document
684 const SfxBoolItem* pSelectItem = rReq.GetArg<SfxBoolItem>(SID_SELECTION);
685 bool bSelection = ( pSelectItem != nullptr && pSelectItem->GetValue() );
686 // detect non api call from writer ( that adds SID_SELECTION ) and reset bIsAPI
687 if ( pSelectItem && rReq.GetArgs()->Count() == 1 )
688 bIsAPI = false;
689
690 uno::Sequence < beans::PropertyValue > aProps;
691 if ( bIsAPI )
692 {
693 // supported properties:
694 // String PrinterName
695 // String FileName
696 // Int16 From
697 // Int16 To
698 // In16 Copies
699 // String RangeText
700 // bool Selection
701 // bool Asynchron
702 // bool Collate
703 // bool Silent
704
705 // the TransformItems function overwrite aProps
706 TransformItems( nId, *rReq.GetArgs(), aProps, GetInterface()->GetSlot(nId) );
707
708 for ( auto& rProp : asNonConstRange(aProps) )
709 {
710 if ( rProp.Name == "Copies" )
711 {
712 rProp.Name = "CopyCount";
713 }
714 else if ( rProp.Name == "RangeText" )
715 {
716 rProp.Name = "Pages";
717 }
718 else if ( rProp.Name == "Asynchron" )
719 {
720 rProp.Name = "Wait";
721 bool bAsynchron = false;
722 rProp.Value >>= bAsynchron;
723 rProp.Value <<= !bAsynchron;
724 }
725 else if ( rProp.Name == "Silent" )
726 {
727 rProp.Name = "MonitorVisible";
728 bool bPrintSilent = false;
729 rProp.Value >>= bPrintSilent;
730 rProp.Value <<= !bPrintSilent;
731 }
732 }
733 }
734
735 // we will add the "PrintSelectionOnly" or "HideHelpButton" properties
736 // we have to increase the capacity of aProps
737 sal_Int32 nLen = aProps.getLength();
738 aProps.realloc( nLen + 1 );
739 auto pProps = aProps.getArray();
740
741 // HACK: writer sets the SID_SELECTION item when printing directly and expects
742 // to get only the selection document in that case (see getSelectionObject)
743 // however it also reacts to the PrintContent property. We need this distinction here, too,
744 // else one of the combinations print / print direct and selection / all will not work.
745 // it would be better if writer handled this internally
746 if( nId == SID_PRINTDOCDIRECT )
747 {
748 pProps[nLen].Name = "PrintSelectionOnly";
749 pProps[nLen].Value <<= bSelection;
750 }
751 else // if nId == SID_PRINTDOC ; nothing to do with the previous HACK
752 {
753 // should the printer selection and properties dialogue display an help button
754 pProps[nLen].Name = "HideHelpButton";
755 pProps[nLen].Value <<= bPrintOnHelp;
756 }
757
758 ExecPrint( aProps, bIsAPI, (nId == SID_PRINTDOCDIRECT) );
759
760 // FIXME: Recording
761 rReq.Done();
762 break;
763 }
764
765 case SID_PRINTER_NAME: // for recorded macros
766 {
767 // get printer and printer settings from the document
768 SfxPrinter* pDocPrinter = GetPrinter(true);
769 const SfxStringItem* pPrinterItem = rReq.GetArg<SfxStringItem>(SID_PRINTER_NAME);
770 if (!pPrinterItem)
771 {
772 rReq.Ignore();
773 break;
774 }
775 // use PrinterName parameter to create a printer
776 pPrinter = VclPtr<SfxPrinter>::Create(pDocPrinter->GetOptions().Clone(),
777 pPrinterItem->GetValue());
778
779 if (!pPrinter->IsKnown())
780 {
781 pPrinter.disposeAndClear();
782 rReq.Ignore();
783 break;
784 }
786 rReq.Done();
787 break;
788 }
789 case SID_SETUPPRINTER : // display the printer settings dialog : File > Printer Settings...
790 {
791 // get printer and printer settings from the document
792 SfxPrinter *pDocPrinter = GetPrinter(true);
793
794 // look for printer in parameters
795 const SfxStringItem* pPrinterItem = rReq.GetArg<SfxStringItem>(SID_PRINTER_NAME);
796 if ( pPrinterItem )
797 {
798 // use PrinterName parameter to create a printer
799 pPrinter = VclPtr<SfxPrinter>::Create( pDocPrinter->GetOptions().Clone(), pPrinterItem->GetValue() );
800
801 // if printer is unknown, it can't be used - now printer from document will be used
802 if ( !pPrinter->IsKnown() )
803 pPrinter.disposeAndClear();
804 }
805
806 // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer
807 if ( !pPrinter )
808 // use default printer from document
809 pPrinter = pDocPrinter;
810
811 if( !pPrinter || !pPrinter->IsValid() )
812 {
813 // no valid printer either in ItemSet or at the document
814 if ( !bSilent )
815 {
816 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
817 VclMessageType::Warning, VclButtonsType::Ok,
818 SfxResId(STR_NODEFPRINTER)));
819 xBox->run();
820 }
821
822 rReq.SetReturnValue(SfxBoolItem(0,false));
823
824 break;
825 }
826
827 // FIXME: printer isn't used for printing anymore!
828 if( pPrinter->IsPrinting() )
829 {
830 // if printer is busy, abort configuration
831 if ( !bSilent )
832 {
833 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
834 VclMessageType::Info, VclButtonsType::Ok,
835 SfxResId(STR_ERROR_PRINTER_BUSY)));
836 xBox->run();
837 }
838 rReq.SetReturnValue(SfxBoolItem(0,false));
839
840 return;
841 }
842
843 // Open Printer Setup dialog (needs a temporary printer)
844 VclPtr<SfxPrinter> pDlgPrinter = pPrinter->Clone();
845 PrinterSetupDialog aPrintSetupDlg(GetFrameWeld());
846 std::unique_ptr<SfxDialogExecutor_Impl> pExecutor;
847
848 if (pImpl->m_bHasPrintOptions && HasPrintOptionsPage())
849 {
850 // additional controls for dialog
851 pExecutor.reset(new SfxDialogExecutor_Impl(this, aPrintSetupDlg));
852 if (bPrintOnHelp)
853 pExecutor->DisableHelp();
854 aPrintSetupDlg.SetOptionsHdl(pExecutor->GetLink());
855 }
856
857 aPrintSetupDlg.SetPrinter(pDlgPrinter);
858 nDialogRet = aPrintSetupDlg.run();
859
860 if (pExecutor && pExecutor->GetOptions())
861 {
862 if (nDialogRet == RET_OK)
863 // remark: have to be recorded if possible!
864 pDlgPrinter->SetOptions(*pExecutor->GetOptions());
865 else
866 {
867 pPrinter->SetOptions(*pExecutor->GetOptions());
869 }
870 }
871
872 // no recording of PrinterSetup except printer name (is printer dependent)
873 rReq.Ignore();
874
875 if (nDialogRet == RET_OK)
876 {
877 if (pPrinter->GetName() != pDlgPrinter->GetName())
878 {
879 // user has changed the printer -> macro recording
880 SfxRequest aReq(GetViewFrame(), SID_PRINTER_NAME);
881 aReq.AppendItem(SfxStringItem(SID_PRINTER_NAME, pDlgPrinter->GetName()));
882 aReq.Done();
883 }
884
885 // take the changes made in the dialog
886 SetPrinter_Impl(pDlgPrinter);
887
888 // forget new printer, it was taken over (as pPrinter) or deleted
889 pDlgPrinter = nullptr;
891 }
892 else
893 {
894 // PrinterDialog is used to transfer information on printing,
895 // so it will only be deleted here if dialog was cancelled
896 pDlgPrinter.disposeAndClear();
897 rReq.Ignore();
898 }
899 break;
900 }
901 }
902}
903
905{
906 return nullptr;
907}
908
909sal_uInt16 SfxViewShell::SetPrinter( SfxPrinter* /*pNewPrinter*/, SfxPrinterChangeFlags /*nDiffFlags*/ )
910{
911 return 0;
912}
913
915{
916 return nullptr;
917}
918
920{
921 return false;
922}
923
924/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void TransformItems(sal_uInt16 nSlotId, const SfxItemSet &rSet, uno::Sequence< beans::PropertyValue > &rArgs, const SfxSlot *pSlot)
Definition: appuno.cxx:908
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const OUString & GetValue() const
css::util::DateTime GetUNODateTime() const
virtual short run() override
Printer * GetPrinter() const
weld::Window * GetFrameWeld() const
void SetOptionsHdl(const Link< weld::Button &, void > &rLink)
void SetPrinter(Printer *pNewPrinter)
bool SetPrinterProps(const Printer *pPrinter)
bool IsDefPrinter() const
bool SetJobSetup(const JobSetup &rSetup)
const OUString & GetName() const
const Size & GetPaperSizePixel() const
const JobSetup & GetJobSetup() const
Orientation GetOrientation() const
static void PrintJob(const std::shared_ptr< vcl::PrinterController > &i_pController, const JobSetup &i_rInitSetup)
void Invalidate(sal_uInt16 nId)
Definition: bindings.cxx:639
bool GetValue() const
void Broadcast(const SfxHint &rHint)
sal_uInt16 GetValue() const
SfxHintId GetId() const
sal_uInt16 Count() const
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
const std::shared_ptr< const SfxFilter > & GetFilter() const
Definition: docfile.cxx:3111
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
Definition: objmisc.cxx:161
bool IsEnableSetModified() const
Definition: objmisc.cxx:248
sal_Int16 QueryHiddenInformation(HiddenWarningFact eFact, weld::Window *pParent)
Definition: objstor.cxx:3084
bool IsUseUserData() const
Definition: objcont.cxx:623
virtual bool QuerySlotExecutable(sal_uInt16 nSlotId)
Definition: objstor.cxx:164
SfxMedium * GetMedium() const
Definition: objsh.hxx:261
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: objxtor.cxx:838
void EnableSetModified(bool bEnable=true)
Definition: objmisc.cxx:241
const SfxItemSet & GetOptions() const
Definition: prnmon.hxx:48
virtual short run() override
Definition: printer.cxx:170
util::DateTime m_aLastPrinted
Definition: viewprn.cxx:75
OUString m_aLastPrintedBy
Definition: viewprn.cxx:76
virtual void jobFinished(css::view::PrintableState) override
Definition: viewprn.cxx:326
VclPtr< Printer > mpLastPrinter
Definition: viewprn.cxx:67
virtual void printPage(int i_nPage) const override
Definition: viewprn.cxx:265
virtual void jobStarted() override
Definition: viewprn.cxx:289
Sequence< beans::PropertyValue > getMergedOptions() const
Definition: viewprn.cxx:201
SfxObjectShell * mpObjectShell
Definition: viewprn.cxx:70
virtual Sequence< beans::PropertyValue > getPageParameters(int i_nPage) const override
Definition: viewprn.cxx:240
const Any & getSelectionObject() const
Definition: viewprn.cxx:183
Reference< awt::XDevice > mxDevice
Definition: viewprn.cxx:68
virtual void Notify(SfxBroadcaster &, const SfxHint &) override
Definition: viewprn.cxx:171
SfxViewShell * mpViewShell
Definition: viewprn.cxx:69
SfxPrinterController(const VclPtr< Printer > &i_rPrinter, Any i_Complete, Any i_Selection, const Any &i_rViewProp, const Reference< view::XRenderable > &i_xRender, bool i_bApi, bool i_bDirect, SfxViewShell *pView, const uno::Sequence< beans::PropertyValue > &rProps)
Definition: viewprn.cxx:101
Reference< view::XRenderable > mxRenderable
Definition: viewprn.cxx:66
virtual int getPageCount() const override
Definition: viewprn.cxx:219
VclPtr< SfxPrinter > Clone() const
Definition: printer.cxx:116
void SetOptions(const SfxItemSet &rNewOptions)
Definition: printer.cxx:143
const SfxItemSet & GetOptions() const
Definition: printer.hxx:54
sal_uInt16 GetSlot() const
Definition: request.hxx:68
void Ignore()
Definition: request.cxx:521
const SfxItemSet * GetArgs() const
Definition: request.hxx:75
const T * GetArg(sal_uInt16 nSlotId) const
Templatized access to the individual parameters of the SfxRequest.
Definition: request.hxx:84
void AppendItem(const SfxPoolItem &)
Definition: request.cxx:404
void SetReturnValue(const SfxPoolItem &)
Definition: request.cxx:422
void Done(bool bRemove=false)
Definition: request.cxx:484
virtual SfxInterface * GetInterface() const
With this virtual method, which is automatically overridden by each subclass with its own slots throu...
Definition: shell.cxx:198
SfxBindings & GetBindings()
Definition: viewfrm.hxx:110
virtual SfxObjectShell * GetObjectShell() override
Definition: viewfrm.cxx:2218
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
Definition: viewsh.hxx:165
weld::Window * GetFrameWeld() const
Definition: viewsh.cxx:2891
virtual SfxPrinter * GetPrinter(bool bCreate=false)
Definition: viewprn.cxx:904
css::uno::Reference< css::frame::XController > GetController() const
Definition: viewsh.cxx:2662
std::unique_ptr< struct SfxViewShell_Impl > pImpl
Definition: viewsh.hxx:170
bool mbPrinterSettingsModified
Definition: viewsh.hxx:174
SAL_DLLPRIVATE void SetPrinter_Impl(VclPtr< SfxPrinter > &pNewPrinter)
Internal method for setting the differences between 'pNewPrinter' to the current printer.
Definition: viewprn.cxx:466
SfxViewFrame & GetViewFrame() const
Definition: viewsh.hxx:290
const std::shared_ptr< vcl::PrinterController > & GetPrinterController() const
Definition: viewprn.cxx:629
void StartPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
Definition: viewprn.cxx:568
virtual bool HasPrintOptionsPage() const
Definition: viewprn.cxx:919
SAL_DLLPRIVATE void ExecPrint_Impl(SfxRequest &)
Definition: viewprn.cxx:640
virtual sal_uInt16 SetPrinter(SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags=SFX_PRINTER_ALL)
Definition: viewprn.cxx:909
virtual SfxObjectShell * GetObjectShell() override
Definition: viewsh.cxx:2591
virtual css::uno::Reference< css::view::XRenderable > GetRenderable()
get an XRenderable instance that can render this document
Definition: viewsh.cxx:2844
void ExecPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
Definition: viewprn.cxx:620
Printer * GetActivePrinter() const
Definition: viewprn.cxx:634
virtual std::unique_ptr< SfxTabPage > CreatePrintOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rOptions)
Definition: viewprn.cxx:914
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void disposeAndClear()
void reset(reference_type *pBody)
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
void setValue(const OUString &i_rPropertyName, const css::uno::Any &i_rValue)
css::uno::Sequence< css::beans::PropertyValue > getJobProperties(const css::uno::Sequence< css::beans::PropertyValue > &i_rMergeList) const
void setUIOptions(const css::uno::Sequence< css::beans::PropertyValue > &)
css::beans::PropertyValue * getValue(const OUString &i_rPropertyName)
const VclPtr< Printer > & getPrinter() const
void setJobState(css::view::PrintableState)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
virtual OUString GetName() const override
sal_Int32 nState
#define SAL_WARN(area, stream)
DateTime now
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
sal_Int16 nId
Orientation
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
Reference< XController > xController
RET_OK
RET_CANCEL
RET_YES
IMPL_LINK_NOARG(SfxDialogExecutor_Impl, Execute, weld::Button &, void)
Definition: viewprn.cxx:440
SfxPrinterChangeFlags
Definition: viewsh.hxx:80