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
This commit is contained in:
pavel-t
2018-06-21 09:11:28 +03:00
committed by Vadim Zeitlin
parent 01cd3cc019
commit 710474c634
4 changed files with 48 additions and 1 deletions

View File

@@ -88,6 +88,7 @@ All (GUI):
- Fix bug with missing items in overflowing AUI toolbar (Maarten Bent). - Fix bug with missing items in overflowing AUI toolbar (Maarten Bent).
- Revert to left-aligning wxSpinCtrl contents by default. - Revert to left-aligning wxSpinCtrl contents by default.
- Make wxRibbonButtonBar buttons more customizable (Max Maisel). - Make wxRibbonButtonBar buttons more customizable (Max Maisel).
- Add wxHtmlEasyPrinting::SetPromptMode() (pavel-t).
wxGTK: wxGTK:

View File

@@ -273,6 +273,16 @@ public:
void SetName(const wxString& name) { m_Name = name; } void SetName(const wxString& name) { m_Name = name; }
// set the printout 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: protected:
virtual wxHtmlPrintout *CreatePrintout(); virtual wxHtmlPrintout *CreatePrintout();
virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2); virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
@@ -296,6 +306,8 @@ private:
wxString m_Headers[2], m_Footers[2]; wxString m_Headers[2], m_Footers[2];
wxWindow *m_ParentWindow; wxWindow *m_ParentWindow;
PromptMode m_promptMode;
wxDECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting); wxDECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting);
}; };

View File

@@ -340,6 +340,32 @@ public:
*/ */
void SetParentWindow(wxWindow* window); 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: private:
/** /**
Check whether the document fits into the page area. Check whether the document fits into the page area.

View File

@@ -619,6 +619,8 @@ wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxWindow *parentWin
m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25)); m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25));
SetStandardFonts(DEFAULT_PRINT_FONT_SIZE); SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
m_promptMode = Prompt_Always;
} }
@@ -709,7 +711,13 @@ bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout *printout)
wxPrintDialogData printDialogData(*GetPrintData()); wxPrintDialogData printDialogData(*GetPrintData());
wxPrinter printer(&printDialogData); 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; return false;
} }