From 710474c63455116073eb2e79c4fdb1692adae019 Mon Sep 17 00:00:00 2001 From: pavel-t <36256989+pavel-t@users.noreply.github.com> Date: Thu, 21 Jun 2018 09:11:28 +0300 Subject: [PATCH] Allow configuring showing printing dialog in wxHtmlEasyPrinting Add wxHtmlEasyPrinting::SetPromptMode() to allow suppressing the "prompt" shown by wxPrinter::Print() when it's called from this class code. Closes https://github.com/wxWidgets/wxWidgets/pull/838 --- docs/changes.txt | 1 + include/wx/html/htmprint.h | 12 ++++++++++++ interface/wx/html/htmprint.h | 26 ++++++++++++++++++++++++++ src/html/htmprint.cpp | 10 +++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index cd8c9da99a..b314d6abb6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -88,6 +88,7 @@ All (GUI): - Fix bug with missing items in overflowing AUI toolbar (Maarten Bent). - Revert to left-aligning wxSpinCtrl contents by default. - Make wxRibbonButtonBar buttons more customizable (Max Maisel). +- Add wxHtmlEasyPrinting::SetPromptMode() (pavel-t). wxGTK: diff --git a/include/wx/html/htmprint.h b/include/wx/html/htmprint.h index 3c0d12f6ab..0c206ade6c 100644 --- a/include/wx/html/htmprint.h +++ b/include/wx/html/htmprint.h @@ -273,6 +273,16 @@ public: void SetName(const wxString& name) { m_Name = name; } // set the printout name + // Controls showing the dialog when printing: by default, always shown. + enum PromptMode + { + Prompt_Never, + Prompt_Once, + Prompt_Always + }; + + void SetPromptMode(PromptMode promptMode) { m_promptMode = promptMode; } + protected: virtual wxHtmlPrintout *CreatePrintout(); virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2); @@ -296,6 +306,8 @@ private: wxString m_Headers[2], m_Footers[2]; wxWindow *m_ParentWindow; + PromptMode m_promptMode; + wxDECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting); }; diff --git a/interface/wx/html/htmprint.h b/interface/wx/html/htmprint.h index 6e6a0908dc..8e2dfdc9db 100644 --- a/interface/wx/html/htmprint.h +++ b/interface/wx/html/htmprint.h @@ -340,6 +340,32 @@ public: */ void SetParentWindow(wxWindow* window); + /** + Controls when the print dialog should be shown. + + @see SetPromptMode() + + @since 3.1.2 + */ + enum PromptMode + { + Prompt_Never, //!< Do not show the print dialog. + Prompt_Once, //!< Show the print dialog only the first time. + Prompt_Always //!< Show the print dialog every time (default value). + }; + + /** + Enable or disable showing the dialog before printing. + + The prompt mode determines the value of the @c prompt parameter passed + to wxPrinter::Print() when it is called by this class. + + Default prompt mode value is Prompt_Always. + + @since 3.1.2 + */ + void SetPromptMode(PromptMode promptMode); + private: /** Check whether the document fits into the page area. diff --git a/src/html/htmprint.cpp b/src/html/htmprint.cpp index 781c9f4d98..ba1f31b016 100644 --- a/src/html/htmprint.cpp +++ b/src/html/htmprint.cpp @@ -619,6 +619,8 @@ wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxWindow *parentWin m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25)); SetStandardFonts(DEFAULT_PRINT_FONT_SIZE); + + m_promptMode = Prompt_Always; } @@ -709,7 +711,13 @@ bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout *printout) wxPrintDialogData printDialogData(*GetPrintData()); wxPrinter printer(&printDialogData); - if (!printer.Print(m_ParentWindow, printout, true)) + const bool prompt = m_promptMode != Prompt_Never; + if (m_promptMode == Prompt_Once) + { + m_promptMode = Prompt_Never; + } + + if (!printer.Print(m_ParentWindow, printout, prompt)) { return false; }