22#include <com/sun/star/document/XDocumentProperties.hpp>
23#include <com/sun/star/view/XRenderable.hpp>
24#include <com/sun/star/view/XSelectionSupplier.hpp>
27#include <officecfg/Office/Common.hxx>
37#include <tools/datetime.hxx>
50#include <sfx2/sfxsids.hrc>
51#include <sfx2/strings.hrc>
85 const Any& i_rViewProp,
87 bool i_bApi,
bool i_bDirect,
89 const uno::Sequence< beans::PropertyValue >& rProps
96 virtual void printPage(
int i_nPage )
const override;
98 virtual void jobFinished( css::view::PrintableState )
override;
104 const Any& i_rViewProp,
106 bool i_bApi,
bool i_bDirect,
108 const uno::Sequence< beans::PropertyValue >& rProps
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 )
120 , m_bTempPrinter( i_rPrinter )
132 for (
const auto& rProp : rProps)
133 setValue( rProp.Name, rProp.Value );
143 for(
const auto& rRenderParm : aRenderParms )
145 if ( rRenderParm.Name ==
"ExtraPrintUIOptions" )
148 rRenderParm.Value >>= aUIProps;
151 else if( rRenderParm.Name ==
"NUp" )
153 setValue( rRenderParm.Name, rRenderParm.Value );
157 catch( lang::IllegalArgumentException& )
173 if ( rHint.
GetId() == SfxHintId::Dying )
185 const beans::PropertyValue* pVal =
getValue( OUString(
"PrintSelectionOnly" ) );
189 pVal->Value >>= bSel;
193 sal_Int32 nChoice = 0;
194 pVal =
getValue( OUString(
"PrintContent" ) );
196 pVal->Value >>= nChoice;
216 return aRenderOptions;
230 catch (lang::DisposedException &)
232 SAL_WARN(
"sfx",
"SfxPrinterController: document disposed while printing");
234 view::PrintableState_JOB_ABORTED);
252 catch( lang::IllegalArgumentException& )
255 catch (lang::DisposedException &)
257 SAL_WARN(
"sfx",
"SfxPrinterController: document disposed while printing");
259 view::PrintableState_JOB_ABORTED);
276 catch( lang::IllegalArgumentException& )
281 catch (lang::DisposedException &)
283 SAL_WARN(
"sfx",
"SfxPrinterController: document disposed while printing");
285 view::PrintableState_JOB_ABORTED);
297 if (
m_bOrigStatus && !officecfg::Office::Common::Print::PrintingModifiesDocument::get())
315 uno::Sequence < beans::PropertyValue > aOpts;
331 bool bCopyJobSetup =
false;
335 case view::PrintableState_JOB_SPOOLING_FAILED :
336 case view::PrintableState_JOB_FAILED :
339 OUString aMsg(
SfxResId(STR_NOSTARTPRINTER) );
343 VclMessageType::Warning, VclButtonsType::Ok,
349 case view::PrintableState_JOB_ABORTED :
358 case view::PrintableState_JOB_SPOOLED :
359 case view::PrintableState_JOB_COMPLETED :
388 pNewPrt->SetJobSetup(
getPrinter()->GetJobSetup() );
411class SfxDialogExecutor_Impl
416 std::unique_ptr<SfxItemSet> _pOptions;
425 const SfxItemSet* GetOptions()
const {
return _pOptions.get(); }
426 void DisableHelp() { _bHelpDisabled =
true; }
433 _pViewSh ( pViewSh ),
434 _rSetupParent ( rParent ),
435 _bHelpDisabled ( false )
481 Orientation eNewOri = pNewPrinter->GetOrientation();
482 Size aNewPgSz = pNewPrinter->GetPaperSizePixel();
485 bool bOriChg = (eOldOri != eNewOri) && bOriToDoc;
486 bool bPgSzChg = ( aOldPgSz.
Height() !=
487 ( bOriChg ? aNewPgSz.
Width() : aNewPgSz.
Height() ) ||
489 ( bOriChg ? aNewPgSz.
Height() : aNewPgSz.
Width() ) ) &&
495 if( bOriChg && bPgSzChg )
497 aMsg =
SfxResId(STR_PRINT_NEWORISIZE);
515 if (bOriChg || bPgSzChg)
518 VclMessageType::Question, VclButtonsType::YesNo,
523 nChangedFlags |= nNewOpt;
529 if ( (pNewPrinter->GetName() != pDocPrinter->
GetName())
530 || (pDocPrinter->
IsDefPrinter() != pNewPrinter->IsDefPrinter()) )
533 if ( ! (pNewPrinter->GetOptions() == pDocPrinter->
GetOptions()) )
538 pDocPrinter = pNewPrinter;
543 if ( ! (pNewPrinter->GetOptions() == pDocPrinter->
GetOptions()) )
546 pDocPrinter->
SetOptions( pNewPrinter->GetOptions() );
551 JobSetup aNewJobSetup = pNewPrinter->GetJobSetup();
553 if ( aNewJobSetup != aOldJobSetup )
570 assert( !
pImpl->m_xPrinterController );
578 aSelection = xSupplier->getSelection();
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())
589 OUString aPrinterName;
590 pVal->Value >>= aPrinterName;
594 std::shared_ptr<vcl::PrinterController> xNewController(std::make_shared<SfxPrinterController>(
605 pImpl->m_xPrinterController = xNewController;
609 css::beans::PropertyValue* pJobNameVal = xNewController->getValue(
"JobName");
614 xNewController->setValue(
"JobName",
Any(pDoc->GetTitle(1)));
631 return pImpl->m_xPrinterController;
636 return pImpl->m_xPrinterController
637 ?
pImpl->m_xPrinterController->getPrinter().get() :
nullptr;
644 bool bSilent =
false;
655 bSilent = pSilentItem && pSilentItem->
GetValue();
662 std::shared_ptr<const SfxFilter> pFilter = pMedium ? pMedium->
GetFilter() :
nullptr;
663 bool bPrintOnHelp = ( pFilter && pFilter->GetFilterName() ==
"writer_web_HTML_help" );
669 case SID_PRINTDOCDIRECT:
685 bool bSelection = ( pSelectItem !=
nullptr && pSelectItem->
GetValue() );
690 uno::Sequence < beans::PropertyValue > aProps;
708 for (
auto& rProp : asNonConstRange(aProps) )
710 if ( rProp.Name ==
"Copies" )
712 rProp.Name =
"CopyCount";
714 else if ( rProp.Name ==
"RangeText" )
716 rProp.Name =
"Pages";
718 else if ( rProp.Name ==
"Asynchron" )
721 bool bAsynchron =
false;
722 rProp.Value >>= bAsynchron;
723 rProp.Value <<= !bAsynchron;
725 else if ( rProp.Name ==
"Silent" )
727 rProp.Name =
"MonitorVisible";
728 bool bPrintSilent =
false;
729 rProp.Value >>= bPrintSilent;
730 rProp.Value <<= !bPrintSilent;
737 sal_Int32 nLen = aProps.getLength();
738 aProps.realloc( nLen + 1 );
739 auto pProps = aProps.getArray();
746 if(
nId == SID_PRINTDOCDIRECT )
748 pProps[nLen].Name =
"PrintSelectionOnly";
749 pProps[nLen].Value <<= bSelection;
754 pProps[nLen].Name =
"HideHelpButton";
755 pProps[nLen].Value <<= bPrintOnHelp;
758 ExecPrint( aProps, bIsAPI, (
nId == SID_PRINTDOCDIRECT) );
765 case SID_PRINTER_NAME:
779 if (!pPrinter->IsKnown())
789 case SID_SETUPPRINTER :
802 if ( !pPrinter->IsKnown() )
809 pPrinter = pDocPrinter;
811 if( !pPrinter || !pPrinter->IsValid() )
817 VclMessageType::Warning, VclButtonsType::Ok,
828 if( pPrinter->IsPrinting() )
834 VclMessageType::Info, VclButtonsType::Ok,
846 std::unique_ptr<SfxDialogExecutor_Impl> pExecutor;
851 pExecutor.reset(
new SfxDialogExecutor_Impl(
this, aPrintSetupDlg));
853 pExecutor->DisableHelp();
858 nDialogRet = aPrintSetupDlg.
run();
860 if (pExecutor && pExecutor->GetOptions())
864 pDlgPrinter->SetOptions(*pExecutor->GetOptions());
867 pPrinter->SetOptions(*pExecutor->GetOptions());
877 if (pPrinter->GetName() != pDlgPrinter->GetName())
889 pDlgPrinter =
nullptr;
void TransformItems(sal_uInt16 nSlotId, const SfxItemSet &rSet, uno::Sequence< beans::PropertyValue > &rArgs, const SfxSlot *pSlot)
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)
void Broadcast(const SfxHint &rHint)
sal_uInt16 GetValue() 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
css::uno::Reference< css::document::XDocumentProperties > getDocProperties() const
bool IsEnableSetModified() const
sal_Int16 QueryHiddenInformation(HiddenWarningFact eFact, weld::Window *pParent)
bool IsUseUserData() const
virtual bool QuerySlotExecutable(sal_uInt16 nSlotId)
SfxMedium * GetMedium() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
void EnableSetModified(bool bEnable=true)
const SfxItemSet & GetOptions() const
virtual short run() override
util::DateTime m_aLastPrinted
OUString m_aLastPrintedBy
virtual void jobFinished(css::view::PrintableState) override
VclPtr< Printer > mpLastPrinter
virtual void printPage(int i_nPage) const override
virtual void jobStarted() override
Sequence< beans::PropertyValue > getMergedOptions() const
SfxObjectShell * mpObjectShell
virtual Sequence< beans::PropertyValue > getPageParameters(int i_nPage) const override
const Any & getSelectionObject() const
Reference< awt::XDevice > mxDevice
virtual void Notify(SfxBroadcaster &, const SfxHint &) override
SfxViewShell * mpViewShell
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)
Reference< view::XRenderable > mxRenderable
virtual int getPageCount() const override
VclPtr< SfxPrinter > Clone() const
void SetOptions(const SfxItemSet &rNewOptions)
const SfxItemSet & GetOptions() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
Templatized access to the individual parameters of the SfxRequest.
void AppendItem(const SfxPoolItem &)
void SetReturnValue(const SfxPoolItem &)
void Done(bool bRemove=false)
virtual SfxInterface * GetInterface() const
With this virtual method, which is automatically overridden by each subclass with its own slots throu...
SfxBindings & GetBindings()
virtual SfxObjectShell * GetObjectShell() override
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
weld::Window * GetFrameWeld() const
virtual SfxPrinter * GetPrinter(bool bCreate=false)
css::uno::Reference< css::frame::XController > GetController() const
std::unique_ptr< struct SfxViewShell_Impl > pImpl
bool mbPrinterSettingsModified
SAL_DLLPRIVATE void SetPrinter_Impl(VclPtr< SfxPrinter > &pNewPrinter)
Internal method for setting the differences between 'pNewPrinter' to the current printer.
SfxViewFrame & GetViewFrame() const
const std::shared_ptr< vcl::PrinterController > & GetPrinterController() const
void StartPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
virtual bool HasPrintOptionsPage() const
SAL_DLLPRIVATE void ExecPrint_Impl(SfxRequest &)
virtual sal_uInt16 SetPrinter(SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags=SFX_PRINTER_ALL)
virtual SfxObjectShell * GetObjectShell() override
virtual css::uno::Reference< css::view::XRenderable > GetRenderable()
get an XRenderable instance that can render this document
void ExecPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
Printer * GetActivePrinter() const
virtual std::unique_ptr< SfxTabPage > CreatePrintOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rOptions)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
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)
void dialogsParentClosing()
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
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
OUString SfxResId(TranslateId aId)
Reference< XController > xController
IMPL_LINK_NOARG(SfxDialogExecutor_Impl, Execute, weld::Button &, void)