From e93570f681e1e2de0393682b94c8196df02909b0 Mon Sep 17 00:00:00 2001 From: Stefan Ziegler Date: Mon, 13 Mar 2023 11:47:33 +0100 Subject: [PATCH 01/10] Implement support for printing only selected pages in wxMSW While the user could select to print only the selection in the dialog, there was no way for the program to specify which pages were selected, making this choice impossible to handle. Add new IsPageSelected() function which is now used to query which pages are selected and should actually be printed. Update the printing sample to show how this function is used. --- include/wx/prntbase.h | 1 + interface/wx/print.h | 19 +++++++++++++++++++ samples/printing/printing.cpp | 35 +++++++++++++++++++++++++++++++---- samples/printing/printing.h | 12 ++++++++++-- src/common/prntbase.cpp | 5 +++++ src/msw/printwin.cpp | 11 ++++++++++- 6 files changed, 76 insertions(+), 7 deletions(-) diff --git a/include/wx/prntbase.h b/include/wx/prntbase.h index db7d726e1a..018d5eeff6 100644 --- a/include/wx/prntbase.h +++ b/include/wx/prntbase.h @@ -278,6 +278,7 @@ public: virtual bool HasPage(int page); virtual bool OnPrintPage(int page) = 0; virtual void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo); + virtual bool IsPageSelected(int page); virtual wxString GetTitle() const { return m_printoutTitle; } diff --git a/interface/wx/print.h b/interface/wx/print.h index 416fccc9c6..b21b9afb59 100644 --- a/interface/wx/print.h +++ b/interface/wx/print.h @@ -705,6 +705,11 @@ public: and maximum page values that the user can select, and the required page range to be printed. + If the user chose to print only selected pages in the MSW printing + dialog, then @a pageFrom and @a pageTo are used to limit the page range + and IsPageSelected() is called later to query whether the page is + selected and so should be printed. + By default this returns (1, 32000) for the page minimum and maximum values, and (1, 1) for the required page range. @@ -773,6 +778,20 @@ public: */ virtual bool HasPage(int pageNum); + /** + Should be overridden to return @true if this page is selected, or @false + if not. + + This function is called for all the pages in the valid range when the + user chooses "Selection" in the "Page Range" area of the printing + dialog under MSW. It is not currently called under the other platforms. + + The default implementation always returns @false. + + @since 3.3.0 + */ + virtual bool IsPageSelected(int pageNum); + /** Returns @true if the printout is currently being used for previewing. diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 8222104288..40a48ca526 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -356,9 +356,20 @@ void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) { wxPrintDialogData printDialogData(* g_printData); + printDialogData.EnableSelection(true); + printDialogData.EnablePageNumbers(true); + printDialogData.SetMinPage(1); + printDialogData.SetMaxPage(2); + printDialogData.SetFromPage(1); + printDialogData.SetToPage(2); + printDialogData.SetAllPages(true); wxPrinter printer(&printDialogData); - MyPrintout printout(this, "My printout"); + + // wxPrinter copies printDialogData internally, so we have to pass this + // instance in order to evaluate users inputs. + MyPrintout printout(this, &printer.GetPrintDialogData(), "My printout"); + if (!printer.Print(this, &printout, true /*prompt*/)) { if (wxPrinter::GetLastError() == wxPRINTER_ERROR) @@ -381,7 +392,7 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) // Pass two printout objects: for preview, and possible printing. wxPrintDialogData printDialogData(* g_printData); wxPrintPreview *preview = - new wxPrintPreview(new MyPrintout(this), new MyPrintout(this), &printDialogData); + new wxPrintPreview(new MyPrintout(this, &printDialogData), new MyPrintout(this, &printDialogData), &printDialogData); if (!preview->IsOk()) { delete preview; @@ -412,7 +423,7 @@ void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event)) wxPrintDialogData printDialogData(* g_printData); wxPostScriptPrinter printer(&printDialogData); - MyPrintout printout(this, "My printout"); + MyPrintout printout(this, &printer.GetPrintDialogData(), "My printout"); printer.Print(this, &printout, true/*prompt*/); (*g_printData) = printer.GetPrintDialogData().GetPrintData(); @@ -422,7 +433,7 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) { // Pass two printout objects: for preview, and possible printing. wxPrintDialogData printDialogData(* g_printData); - wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(this), new MyPrintout(this), &printDialogData); + wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(this, &printDialogData), new MyPrintout(this, &printDialogData), &printDialogData); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview"); frame->Initialize(); frame->Centre(wxBOTH); @@ -541,6 +552,16 @@ void MyPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int * *maxPage = 2; *selPageFrom = 1; *selPageTo = 2; + + if (m_printDlgData->GetSelection()) + { + // if the user wants to print the selection, we could set the range via + // selPageFrom and selPageTo, but if the pages are not consecutive, we + // set selPageFrom and selPageTo to the maximum range and we use + // IsPageSelected() to tell the printing system which page is selected. + + // in our example below, only page 2 is selected. + } } bool MyPrintout::HasPage(int pageNum) @@ -548,6 +569,12 @@ bool MyPrintout::HasPage(int pageNum) return (pageNum == 1 || pageNum == 2); } +bool MyPrintout::IsPageSelected(int pageNum) +{ + // to demonstrate selection, we just simulate selection of page 2 + return pageNum == 2; +} + void MyPrintout::DrawPageOne() { // You might use THIS code if you were scaling graphics of known size to fit diff --git a/samples/printing/printing.h b/samples/printing/printing.h index fb60bca57b..5e76330332 100644 --- a/samples/printing/printing.h +++ b/samples/printing/printing.h @@ -86,13 +86,20 @@ private: class MyPrintout: public wxPrintout { public: - MyPrintout(MyFrame* frame, const wxString &title = "My printout") - : wxPrintout(title) { m_frame=frame; } + MyPrintout(MyFrame* frame, + wxPrintDialogData* printDlgData, + const wxString& title = "My printout") + : wxPrintout(title) + { + m_frame = frame; + m_printDlgData = printDlgData; + } virtual bool OnPrintPage(int page) override; virtual bool HasPage(int page) override; virtual bool OnBeginDocument(int startPage, int endPage) override; virtual void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) override; + virtual bool IsPageSelected(int pageNum) override; void DrawPageOne(); void DrawPageTwo(); @@ -102,6 +109,7 @@ public: private: MyFrame *m_frame; + wxPrintDialogData* m_printDlgData; }; diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 3c9f8345c4..564d230c17 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -635,6 +635,11 @@ void wxPrintout::GetPageInfo(int *minPage, int *maxPage, int *fromPage, int *toP *toPage = 1; } +bool wxPrintout::IsPageSelected(int WXUNUSED(page)) +{ + return false; +} + bool wxPrintout::SetUp(wxDC& dc) { wxCHECK_MSG( dc.IsOk(), false, "should have a valid DC to set up" ); diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index b3e529bcd5..c9975b9b74 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -164,7 +164,12 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt int minPageNum = minPage, maxPageNum = maxPage; - if ( !(m_printDialogData.GetAllPages() || m_printDialogData.GetSelection()) ) + if ( m_printDialogData.GetSelection() ) + { + minPageNum = fromPage; + maxPageNum = toPage; + } + else if ( !m_printDialogData.GetAllPages() ) { minPageNum = m_printDialogData.GetFromPage(); maxPageNum = m_printDialogData.GetToPage(); @@ -198,6 +203,10 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt pn <= maxPageNum && printout->HasPage(pn); pn++ ) { + // allow non-consecutive selected pages + if ( m_printDialogData.GetSelection() && !printout->IsPageSelected(pn) ) + continue; + win->SetProgress(pn - minPageNum + 1, maxPageNum - minPageNum + 1, copyCount, maxCopyCount); From f80efc9992f38b7b5cabd8c96d356be80f5862e4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 17:23:25 +0100 Subject: [PATCH 02/10] Show message about cancelling printing less intrusively Getting a message box after cancelling printing was really annoying while testing the printing dialog, so replace it with a status message. --- samples/printing/printing.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 40a48ca526..0d3eb2d4e8 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -370,6 +370,8 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) // instance in order to evaluate users inputs. MyPrintout printout(this, &printer.GetPrintDialogData(), "My printout"); + SetStatusText(""); // clear previous "cancelled" message, if any + if (!printer.Print(this, &printout, true /*prompt*/)) { if (wxPrinter::GetLastError() == wxPRINTER_ERROR) @@ -378,7 +380,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) } else { - wxLogMessage("You canceled printing"); + wxLogStatus("You canceled printing"); } } else From 8d71d304b9141de4f46098d77d2853da510b432a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 17:24:30 +0100 Subject: [PATCH 03/10] Use accelerators for main menu items in the printing sample Allow using Ctrl-P to bring up the "Print" dialog instead of having to select it from the menu every time. And also add an accelerator for the "Page Setup" menu command. And specify both the new accelerators and the existing one for "Print preview" command using the menu items labels instead of calling SetAcceleratorTable() explicitly, as there doesn't seem to be any reason to do it. Finally, slightly improve the help messages for these menu items. --- samples/printing/printing.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 0d3eb2d4e8..1b2d40623b 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -291,25 +291,18 @@ MyFrame::MyFrame(const wxString& title) // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(wxID_PRINT, "&Print...", "Print"); - file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup"); + file_menu->Append(wxID_PRINT, "&Print...\tCtrl+P", "Show \"Print\" dialog"); + file_menu->Append(WXPRINT_PAGE_SETUP, "Page &Setup...\tCtrl+S", "Page setup"); #ifdef __WXMAC__ file_menu->Append(WXPRINT_PAGE_MARGINS, "Page Margins...", "Page margins"); #endif - file_menu->Append(wxID_PREVIEW, "Print Pre&view", "Preview"); + file_menu->Append(wxID_PREVIEW, "Pre&view\tCtrl+V", "Show print preview"); wxMenu * const menuModalKind = new wxMenu; menuModalKind->AppendRadioItem(WXPRINT_FRAME_MODAL_APP, "&App modal"); menuModalKind->AppendRadioItem(WXPRINT_FRAME_MODAL_WIN, "&Window modal"); menuModalKind->AppendRadioItem(WXPRINT_FRAME_MODAL_NON, "&Not modal"); file_menu->AppendSubMenu(menuModalKind, "Preview frame &modal kind"); -#if wxUSE_ACCEL - // Accelerators - wxAcceleratorEntry entries[1]; - entries[0].Set(wxACCEL_CTRL, (int) 'V', wxID_PREVIEW); - wxAcceleratorTable accel(1, entries); - SetAcceleratorTable(accel); -#endif #if wxUSE_POSTSCRIPT file_menu->AppendSeparator(); From d75956d3e6fe6526ad1357063a9cecdb35017b85 Mon Sep 17 00:00:00 2001 From: Stefan Ziegler Date: Fri, 10 Mar 2023 20:38:10 +0100 Subject: [PATCH 04/10] Add support for printing only the current page Add wxPrintDialogData::EnableCurrentPage() and implement support for it under MSW, where it enables selecting the "Current page" radio button in the pages selection area of the native dialog. Update the sample to show the new function. --- include/wx/cmndata.h | 6 +++ interface/wx/cmndata.h | 37 +++++++++++++++++ interface/wx/print.h | 3 ++ samples/printing/printing.cpp | 10 ++++- src/common/cmndata.cpp | 6 +++ src/msw/printdlg.cpp | 75 +++++++++++++++++++++-------------- src/msw/printwin.cpp | 2 +- 7 files changed, 108 insertions(+), 31 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index db647824d7..dbe9cb59d6 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -162,6 +162,7 @@ public: int GetNoCopies() const { return m_printNoCopies; } bool GetAllPages() const { return m_printAllPages; } bool GetSelection() const { return m_printSelection; } + bool GetCurrentPage() const { return m_printCurrentPage; } bool GetCollate() const { return m_printCollate; } bool GetPrintToFile() const { return m_printToFile; } @@ -172,16 +173,19 @@ public: void SetNoCopies(int v) { m_printNoCopies = v; } void SetAllPages(bool flag) { m_printAllPages = flag; } void SetSelection(bool flag) { m_printSelection = flag; } + void SetCurrentPage(bool flag) { m_printCurrentPage = flag; } void SetCollate(bool flag) { m_printCollate = flag; } void SetPrintToFile(bool flag) { m_printToFile = flag; } void EnablePrintToFile(bool flag) { m_printEnablePrintToFile = flag; } void EnableSelection(bool flag) { m_printEnableSelection = flag; } + void EnableCurrentPage(bool flag) { m_printEnableCurrentPage = flag; } void EnablePageNumbers(bool flag) { m_printEnablePageNumbers = flag; } void EnableHelp(bool flag) { m_printEnableHelp = flag; } bool GetEnablePrintToFile() const { return m_printEnablePrintToFile; } bool GetEnableSelection() const { return m_printEnableSelection; } + bool GetEnableCurrentPage() const { return m_printEnableCurrentPage; } bool GetEnablePageNumbers() const { return m_printEnablePageNumbers; } bool GetEnableHelp() const { return m_printEnableHelp; } @@ -205,7 +209,9 @@ private: bool m_printCollate; bool m_printToFile; bool m_printSelection; + bool m_printCurrentPage; bool m_printEnableSelection; + bool m_printEnableCurrentPage; bool m_printEnablePageNumbers; bool m_printEnableHelp; bool m_printEnablePrintToFile; diff --git a/interface/wx/cmndata.h b/interface/wx/cmndata.h index 3375f8dcfe..c06fba3f84 100644 --- a/interface/wx/cmndata.h +++ b/interface/wx/cmndata.h @@ -489,6 +489,18 @@ public: */ void EnableSelection(bool flag); + /** + Allows or disallows selecting printing the "Current Page" in the + dialog. + + This currently only has an effect under MSW, where the native dialog + enables the "Current Page" radio button if this function is called to + allow the user to print the current page only. + + @since 3.3.0 + */ + void EnableCurrentPage(bool flag); + /** Returns @true if the user requested that all pages be printed. */ @@ -535,6 +547,18 @@ public: */ bool GetSelection() const; + /** + Returns @true if the user requested that the current page be printed. + + Note that the "current page" is defined by the application. + + It only makes sense to call this function if EnableCurrentPage() had been + called before, otherwise it always returns @false. + + @since 3.3.0 + */ + bool GetCurrentPage() const; + /** Returns the @e "print to" page number, as entered by the user. */ @@ -590,6 +614,19 @@ public: */ void SetSelection(bool flag); + /** + Selects the "Current Page" radio button when the dialog is initially + shown. + + This function can only be called when EnableCurrentPage() is used as + well. + + @see GetCurrentPage() + + @since 3.3.0 + */ + void SetCurrentPage(bool flag); + /** @deprecated This function has been deprecated since version 2.5.4. diff --git a/interface/wx/print.h b/interface/wx/print.h index b21b9afb59..d2c56bec04 100644 --- a/interface/wx/print.h +++ b/interface/wx/print.h @@ -710,6 +710,9 @@ public: and IsPageSelected() is called later to query whether the page is selected and so should be printed. + If the user chose to print the current page, then @a pageFrom and + @a pageTo should be both set to the current page number. + By default this returns (1, 32000) for the page minimum and maximum values, and (1, 1) for the required page range. diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 1b2d40623b..7c4d7254db 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -351,6 +351,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) wxPrintDialogData printDialogData(* g_printData); printDialogData.EnableSelection(true); printDialogData.EnablePageNumbers(true); + printDialogData.EnableCurrentPage(true); printDialogData.SetMinPage(1); printDialogData.SetMaxPage(2); printDialogData.SetFromPage(1); @@ -548,7 +549,14 @@ void MyPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int * *selPageFrom = 1; *selPageTo = 2; - if (m_printDlgData->GetSelection()) + // check if the user just wants to print the current page and if so, + // we say, that page 1 is the current page in this example. + if (m_printDlgData->GetCurrentPage()) + { + *selPageFrom = 1; + *selPageTo = 1; + } + else if (m_printDlgData->GetSelection()) { // if the user wants to print the selection, we could set the range via // selPageFrom and selPageTo, but if the pages are not consecutive, we diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index 6306facf92..5d9322844e 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -182,7 +182,9 @@ wxPrintDialogData::wxPrintDialogData() m_printCollate = false; m_printToFile = false; m_printSelection = false; + m_printCurrentPage = false; m_printEnableSelection = false; + m_printEnableCurrentPage = false; m_printEnablePageNumbers = true; wxPrintFactory* factory = wxPrintFactory::GetFactory(); @@ -214,7 +216,9 @@ wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) m_printCollate = false; m_printToFile = false; m_printSelection = false; + m_printCurrentPage = false; m_printEnableSelection = false; + m_printEnableCurrentPage = false; m_printEnablePageNumbers = true; m_printEnablePrintToFile = true; m_printEnableHelp = false; @@ -235,7 +239,9 @@ void wxPrintDialogData::operator=(const wxPrintDialogData& data) m_printCollate = data.m_printCollate; m_printToFile = data.m_printToFile; m_printSelection = data.m_printSelection; + m_printCurrentPage = data.m_printCurrentPage; m_printEnableSelection = data.m_printEnableSelection; + m_printEnableCurrentPage = data.m_printEnableCurrentPage; m_printEnablePageNumbers = data.m_printEnablePageNumbers; m_printEnableHelp = data.m_printEnableHelp; m_printEnablePrintToFile = data.m_printEnablePrintToFile; diff --git a/src/msw/printdlg.cpp b/src/msw/printdlg.cpp index 4513568cc7..6325c4dc87 100644 --- a/src/msw/printdlg.cpp +++ b/src/msw/printdlg.cpp @@ -793,9 +793,14 @@ bool wxWindowsPrintDialog::Create(wxWindow *p, wxPrintDialogData* data) wxWindowsPrintDialog::~wxWindowsPrintDialog() { - PRINTDLG *pd = (PRINTDLG *) m_printDlg; + PRINTDLGEX* pd = (PRINTDLGEX*) m_printDlg; + if (pd && pd->hDevMode) GlobalFree(pd->hDevMode); + + if (pd && pd->lpPageRanges) + delete pd->lpPageRanges; + if ( pd ) delete pd; @@ -814,11 +819,11 @@ int wxWindowsPrintDialog::ShowModal() ConvertToNative( m_printDialogData ); - PRINTDLG *pd = (PRINTDLG*) m_printDlg; - + PRINTDLGEX* pd = (PRINTDLGEX*) m_printDlg; pd->hwndOwner = hWndParent; - bool ret = (PrintDlg( pd ) != 0); + HRESULT dlgRes = PrintDlgEx(pd); + bool ret = (dlgRes == S_OK && pd->dwResultAction == PD_RESULT_PRINT); pd->hwndOwner = 0; @@ -852,14 +857,14 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) (wxWindowsPrintNativeData *) data.GetPrintData().GetNativeData(); data.GetPrintData().ConvertToNative(); - PRINTDLG *pd = (PRINTDLG*) m_printDlg; + PRINTDLGEX* pd = (PRINTDLGEX*) m_printDlg; // Shouldn't have been defined anywhere if (pd) return false; - pd = new PRINTDLG; - memset( pd, 0, sizeof(PRINTDLG) ); + pd = new PRINTDLGEX; + memset(pd, 0, sizeof(PRINTDLGEX)); m_printDlg = (void*) pd; pd->hDevMode = static_cast(native_data->GetDevMode()); @@ -871,31 +876,35 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) pd->hDevNames = static_cast(native_data->GetDevNames()); native_data->SetDevNames(nullptr); + pd->nStartPage = START_PAGE_GENERAL; + pd->nMinPage = (DWORD)data.GetMinPage(); + pd->nMaxPage = (DWORD)data.GetMaxPage(); + pd->nCopies = (DWORD)data.GetNoCopies(); - pd->hDC = nullptr; - pd->nFromPage = (WORD)data.GetFromPage(); - pd->nToPage = (WORD)data.GetToPage(); - pd->nMinPage = (WORD)data.GetMinPage(); - pd->nMaxPage = (WORD)data.GetMaxPage(); - pd->nCopies = (WORD)data.GetNoCopies(); + // Required only if PD_NOPAGENUMS flag is not set. + // Currently only one page range is supported. + if ( data.GetEnablePageNumbers() ) + { + pd->nPageRanges = 1; + pd->nMaxPageRanges = 1; + pd->lpPageRanges = new PRINTPAGERANGE[1]; + pd->lpPageRanges[0].nFromPage = (DWORD)data.GetFromPage(); + pd->lpPageRanges[0].nToPage = (DWORD)data.GetToPage(); + + // PrintDlgEx returns E_INVALIDARG if nFromPage is greater than nToPage + if (pd->lpPageRanges[0].nToPage < pd->lpPageRanges[0].nFromPage) + pd->lpPageRanges[0].nToPage = pd->lpPageRanges[0].nFromPage; + } pd->Flags = PD_RETURNDC; - pd->lStructSize = sizeof( PRINTDLG ); - - pd->hwndOwner = nullptr; - pd->hInstance = nullptr; - pd->lCustData = 0; - pd->lpfnPrintHook = nullptr; - pd->lpfnSetupHook = nullptr; - pd->lpPrintTemplateName = nullptr; - pd->lpSetupTemplateName = nullptr; - pd->hPrintTemplate = nullptr; - pd->hSetupTemplate = nullptr; + pd->lStructSize = sizeof(PRINTDLGEX); if ( data.GetAllPages() ) pd->Flags |= PD_ALLPAGES; if ( data.GetSelection() ) pd->Flags |= PD_SELECTION; + if ( data.GetCurrentPage() ) + pd->Flags |= PD_CURRENTPAGE; if ( data.GetCollate() ) pd->Flags |= PD_COLLATE; if ( data.GetPrintToFile() ) @@ -904,9 +913,11 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) pd->Flags |= PD_DISABLEPRINTTOFILE; if ( !data.GetEnableSelection() ) pd->Flags |= PD_NOSELECTION; + if ( !data.GetEnableCurrentPage() ) + pd->Flags |= PD_NOCURRENTPAGE; if ( !data.GetEnablePageNumbers() ) pd->Flags |= PD_NOPAGENUMS; - else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0)) + else if ( (!data.GetAllPages()) && (!data.GetSelection()) && (!data.GetCurrentPage()) && (data.GetFromPage() != 0) && (data.GetToPage() != 0)) pd->Flags |= PD_PAGENUMS; if ( data.GetEnableHelp() ) pd->Flags |= PD_SHOWHELP; @@ -916,7 +927,7 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data ) bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data ) { - PRINTDLG *pd = (PRINTDLG*) m_printDlg; + PRINTDLGEX* pd = (PRINTDLGEX*) m_printDlg; if ( pd == nullptr ) return false; @@ -949,18 +960,24 @@ bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data ) // into wxWidgets form. native_data->TransferTo( data.GetPrintData() ); - data.SetFromPage( pd->nFromPage ); - data.SetToPage( pd->nToPage ); + if ( pd->lpPageRanges ) + { + data.SetFromPage(pd->lpPageRanges[0].nFromPage); + data.SetToPage(pd->lpPageRanges[0].nToPage); + } + data.SetMinPage( pd->nMinPage ); data.SetMaxPage( pd->nMaxPage ); data.SetNoCopies( pd->nCopies ); - data.SetAllPages( (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION)) ); + data.SetAllPages( ((pd->Flags & (PD_PAGENUMS | PD_SELECTION | PD_CURRENTPAGE)) == 0) ); data.SetSelection( ((pd->Flags & PD_SELECTION) == PD_SELECTION) ); + data.SetCurrentPage(((pd->Flags & PD_CURRENTPAGE) == PD_CURRENTPAGE)); data.SetCollate( ((pd->Flags & PD_COLLATE) == PD_COLLATE) ); data.SetPrintToFile( ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE) ); data.EnablePrintToFile( ((pd->Flags & PD_DISABLEPRINTTOFILE) != PD_DISABLEPRINTTOFILE) ); data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) ); + data.EnableCurrentPage(((pd->Flags & PD_NOCURRENTPAGE) != PD_NOCURRENTPAGE)); data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) ); data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) ); diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index c9975b9b74..b671bb1007 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -164,7 +164,7 @@ bool wxWindowsPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt int minPageNum = minPage, maxPageNum = maxPage; - if ( m_printDialogData.GetSelection() ) + if ( m_printDialogData.GetCurrentPage() || m_printDialogData.GetSelection() ) { minPageNum = fromPage; maxPageNum = toPage; From d156af5a3eeddaec242b81efee1e7968deb57ac6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 17:50:40 +0100 Subject: [PATCH 05/10] Initialize wxPrintDialogData fields in their declaration This is more clear as it makes the initializer immediately visible and avoids the need to list all the fields twice, first when declaring and then when initializing them. Also use compiler-generated copy ctor and assignment operators to avoid re-enumerating all the fields again. No real changes, the same initial values are preserved. --- include/wx/cmndata.h | 34 ++++++++++++------------- src/common/cmndata.cpp | 57 ++---------------------------------------- 2 files changed, 19 insertions(+), 72 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index dbe9cb59d6..c2f2fbb4f6 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -151,7 +151,7 @@ class WXDLLIMPEXP_CORE wxPrintDialogData: public wxObject { public: wxPrintDialogData(); - wxPrintDialogData(const wxPrintDialogData& dialogData); + wxPrintDialogData(const wxPrintDialogData& dialogData) = default; wxPrintDialogData(const wxPrintData& printData); virtual ~wxPrintDialogData(); @@ -196,25 +196,25 @@ public: wxPrintData& GetPrintData() { return m_printData; } void SetPrintData(const wxPrintData& printData) { m_printData = printData; } - void operator=(const wxPrintDialogData& data); + wxPrintDialogData& operator=(const wxPrintDialogData& data) = default; void operator=(const wxPrintData& data); // Sets internal m_printData member private: - int m_printFromPage; - int m_printToPage; - int m_printMinPage; - int m_printMaxPage; - int m_printNoCopies; - bool m_printAllPages; - bool m_printCollate; - bool m_printToFile; - bool m_printSelection; - bool m_printCurrentPage; - bool m_printEnableSelection; - bool m_printEnableCurrentPage; - bool m_printEnablePageNumbers; - bool m_printEnableHelp; - bool m_printEnablePrintToFile; + int m_printFromPage = 0; + int m_printToPage = 0; + int m_printMinPage = 0; + int m_printMaxPage = 0; + int m_printNoCopies = 1; + bool m_printAllPages = false; + bool m_printCollate = false; + bool m_printToFile = false; + bool m_printSelection = false; + bool m_printCurrentPage = false; + bool m_printEnableSelection = false; + bool m_printEnableCurrentPage = false; + bool m_printEnablePageNumbers = true; + bool m_printEnableHelp = false; + bool m_printEnablePrintToFile = true; wxPrintData m_printData; private: diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index 5d9322844e..03310a590e 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -173,30 +173,9 @@ bool wxPrintData::IsOk() const wxPrintDialogData::wxPrintDialogData() { - m_printFromPage = 0; - m_printToPage = 0; - m_printMinPage = 0; - m_printMaxPage = 0; - m_printNoCopies = 1; - m_printAllPages = false; - m_printCollate = false; - m_printToFile = false; - m_printSelection = false; - m_printCurrentPage = false; - m_printEnableSelection = false; - m_printEnableCurrentPage = false; - m_printEnablePageNumbers = true; - wxPrintFactory* factory = wxPrintFactory::GetFactory(); - m_printEnablePrintToFile = ! factory->HasOwnPrintToFile(); - - m_printEnableHelp = false; -} - -wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) - : wxObject() -{ - (*this) = dialogData; + if ( factory->HasOwnPrintToFile() ) + m_printEnablePrintToFile = false; } wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) @@ -206,48 +185,16 @@ wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) m_printToPage = 0; m_printMinPage = 1; m_printMaxPage = 9999; - m_printNoCopies = 1; // On Mac the Print dialog always defaults to "All Pages" #ifdef __WXMAC__ m_printAllPages = true; -#else - m_printAllPages = false; #endif - m_printCollate = false; - m_printToFile = false; - m_printSelection = false; - m_printCurrentPage = false; - m_printEnableSelection = false; - m_printEnableCurrentPage = false; - m_printEnablePageNumbers = true; - m_printEnablePrintToFile = true; - m_printEnableHelp = false; } wxPrintDialogData::~wxPrintDialogData() { } -void wxPrintDialogData::operator=(const wxPrintDialogData& data) -{ - m_printFromPage = data.m_printFromPage; - m_printToPage = data.m_printToPage; - m_printMinPage = data.m_printMinPage; - m_printMaxPage = data.m_printMaxPage; - m_printNoCopies = data.m_printNoCopies; - m_printAllPages = data.m_printAllPages; - m_printCollate = data.m_printCollate; - m_printToFile = data.m_printToFile; - m_printSelection = data.m_printSelection; - m_printCurrentPage = data.m_printCurrentPage; - m_printEnableSelection = data.m_printEnableSelection; - m_printEnableCurrentPage = data.m_printEnableCurrentPage; - m_printEnablePageNumbers = data.m_printEnablePageNumbers; - m_printEnableHelp = data.m_printEnableHelp; - m_printEnablePrintToFile = data.m_printEnablePrintToFile; - m_printData = data.m_printData; -} - void wxPrintDialogData::operator=(const wxPrintData& data) { m_printData = data; From 4a10bdd089af06c589b0f5c24c9e04073a7e124c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 17:55:54 +0100 Subject: [PATCH 06/10] Initialize wxPageSetupDialogData fields in their declaration This is similar to the previous commit and does the same thing for wxPageSetupDialogData as was done there for wxPrintDialogData. --- include/wx/cmndata.h | 19 +++++++-------- src/common/cmndata.cpp | 53 ------------------------------------------ 2 files changed, 9 insertions(+), 63 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index c2f2fbb4f6..bccc354232 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -232,9 +232,8 @@ class WXDLLIMPEXP_CORE wxPageSetupDialogData: public wxObject { public: wxPageSetupDialogData(); - wxPageSetupDialogData(const wxPageSetupDialogData& dialogData); + wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) = default; wxPageSetupDialogData(const wxPrintData& printData); - virtual ~wxPageSetupDialogData(); wxSize GetPaperSize() const { return m_paperSize; } wxPaperSize GetPaperId() const { return m_printData.GetPaperId(); } @@ -284,7 +283,7 @@ public: // Use paper id in wxPrintData to set this object's paper size void CalculatePaperSizeFromId(); - wxPageSetupDialogData& operator=(const wxPageSetupDialogData& data); + wxPageSetupDialogData& operator=(const wxPageSetupDialogData& data) = default; wxPageSetupDialogData& operator=(const wxPrintData& data); wxPrintData& GetPrintData() { return m_printData; } @@ -297,13 +296,13 @@ private: wxPoint m_minMarginBottomRight; wxPoint m_marginTopLeft; wxPoint m_marginBottomRight; - bool m_defaultMinMargins; - bool m_enableMargins; - bool m_enableOrientation; - bool m_enablePaper; - bool m_enablePrinter; - bool m_getDefaultInfo; // Equiv. to PSD_RETURNDEFAULT - bool m_enableHelp; + bool m_defaultMinMargins = false; + bool m_enableMargins = true; + bool m_enableOrientation = true; + bool m_enablePaper = true; + bool m_enablePrinter = true; + bool m_getDefaultInfo = false; // Equiv. to PSD_RETURNDEFAULT + bool m_enableHelp = false; wxPrintData m_printData; private: diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index 03310a590e..a66bd0732e 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -207,69 +207,16 @@ void wxPrintDialogData::operator=(const wxPrintData& data) wxPageSetupDialogData::wxPageSetupDialogData() { CalculatePaperSizeFromId(); - - m_minMarginTopLeft = - m_minMarginBottomRight = - m_marginTopLeft = - m_marginBottomRight = wxPoint(0,0); - - // Flags - m_defaultMinMargins = false; - m_enableMargins = true; - m_enableOrientation = true; - m_enablePaper = true; - m_enablePrinter = true; - m_enableHelp = false; - m_getDefaultInfo = false; -} - -wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) - : wxObject() -{ - (*this) = dialogData; } wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) : m_printData(printData) { - // Flags - m_defaultMinMargins = false; - m_enableMargins = true; - m_enableOrientation = true; - m_enablePaper = true; - m_enablePrinter = true; - m_enableHelp = false; - m_getDefaultInfo = false; - // The wxPrintData paper size overrides these values, unless the size cannot // be found. CalculatePaperSizeFromId(); } -wxPageSetupDialogData::~wxPageSetupDialogData() -{ -} - -wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) -{ - m_paperSize = data.m_paperSize; - m_minMarginTopLeft = data.m_minMarginTopLeft; - m_minMarginBottomRight = data.m_minMarginBottomRight; - m_marginTopLeft = data.m_marginTopLeft; - m_marginBottomRight = data.m_marginBottomRight; - m_defaultMinMargins = data.m_defaultMinMargins; - m_enableMargins = data.m_enableMargins; - m_enableOrientation = data.m_enableOrientation; - m_enablePaper = data.m_enablePaper; - m_enablePrinter = data.m_enablePrinter; - m_getDefaultInfo = data.m_getDefaultInfo; - m_enableHelp = data.m_enableHelp; - - m_printData = data.m_printData; - - return *this; -} - wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data) { m_printData = data; From 22a09c2fb52ecbc42acf7353859c5a60aeb14bb3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 18:01:21 +0100 Subject: [PATCH 07/10] Don't manage wxPrintData::m_privData memory manually Use std::vector to do it instead. As a side effect of this change, provide const and non-const overloads of GetPrivData() instead of a const overload returning non-const pointer, which didn't really make sense. --- include/wx/cmndata.h | 10 ++++++---- src/common/cmndata.cpp | 26 ++++++++------------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index bccc354232..c4d01aae17 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -21,6 +21,8 @@ #include "wx/stream.h" #endif +#include + class WXDLLIMPEXP_FWD_CORE wxPrintNativeDataBase; /* @@ -101,8 +103,9 @@ public: wxPrintData& operator=(const wxPrintData& data); - char* GetPrivData() const { return m_privData; } - int GetPrivDataLen() const { return m_privDataLen; } + char* GetPrivData() { return m_privData.empty() ? nullptr : &m_privData[0]; } + const char* GetPrivData() const { return m_privData.empty() ? nullptr : &m_privData[0]; } + int GetPrivDataLen() const { return static_cast(m_privData.size()); } void SetPrivData( char *privData, int len ); @@ -131,8 +134,7 @@ private: wxString m_filename; - char* m_privData; - int m_privDataLen; + std::vector m_privData; wxPrintNativeDataBase *m_nativeData; diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index a66bd0732e..bea2648b6d 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -73,9 +73,6 @@ wxPrintData::wxPrintData() // the default system settings will be used for them m_paperId = wxPAPER_NONE; - m_privData = nullptr; - m_privDataLen = 0; - m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData(); } @@ -83,18 +80,19 @@ wxPrintData::wxPrintData(const wxPrintData& printData) : wxObject() { m_nativeData = nullptr; - m_privData = nullptr; (*this) = printData; } void wxPrintData::SetPrivData( char *privData, int len ) { - wxDELETEA(m_privData); - m_privDataLen = len; - if (m_privDataLen > 0) + if (len > 0) { - m_privData = new char[m_privDataLen]; - memcpy( m_privData, privData, m_privDataLen ); + m_privData.resize(len); + memcpy( &m_privData[0], privData, len ); + } + else + { + m_privData.clear(); } } @@ -103,8 +101,6 @@ wxPrintData::~wxPrintData() m_nativeData->m_ref--; if (m_nativeData->m_ref == 0) delete m_nativeData; - - delete[] m_privData; } void wxPrintData::ConvertToNative() @@ -148,13 +144,7 @@ wxPrintData& wxPrintData::operator=(const wxPrintData& data) m_nativeData = data.GetNativeData(); m_nativeData->m_ref++; - wxDELETEA(m_privData); - m_privDataLen = data.GetPrivDataLen(); - if (m_privDataLen > 0) - { - m_privData = new char[m_privDataLen]; - memcpy( m_privData, data.GetPrivData(), m_privDataLen ); - } + m_privData = data.m_privData; return *this; } From ecf3d73695b2df9783403bb0c5d0e79900d121fd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 18:10:18 +0100 Subject: [PATCH 08/10] Use wxObjectDataPtr to manage wxPrintData::m_nativeData Remove code allocating and freeing this pointer directly and use wxObjectDataPtr instead. This required adding wxRefCounter-like methods to wxPrintData, which can't inherit from wxRefCounter because it uses a different name for its field storing the reference counter, which is public and so can't be renamed without breaking compatibility. --- include/wx/cmndata.h | 4 ++-- include/wx/prntbase.h | 13 ++++++++++--- src/common/cmndata.cpp | 19 ++----------------- src/common/prntbase.cpp | 5 +---- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index c4d01aae17..deac7b41c9 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -113,7 +113,7 @@ public: void ConvertToNative(); void ConvertFromNative(); // Holds the native print data - wxPrintNativeDataBase *GetNativeData() const { return m_nativeData; } + wxPrintNativeDataBase *GetNativeData() const { return m_nativeData.get(); } private: wxPrintBin m_bin; @@ -136,7 +136,7 @@ private: std::vector m_privData; - wxPrintNativeDataBase *m_nativeData; + wxObjectDataPtr m_nativeData; private: wxDECLARE_DYNAMIC_CLASS(wxPrintData); diff --git a/include/wx/prntbase.h b/include/wx/prntbase.h index 018d5eeff6..8796ffdf5e 100644 --- a/include/wx/prntbase.h +++ b/include/wx/prntbase.h @@ -159,8 +159,8 @@ public: class WXDLLIMPEXP_CORE wxPrintNativeDataBase: public wxObject { public: - wxPrintNativeDataBase(); - virtual ~wxPrintNativeDataBase() {} + wxPrintNativeDataBase() = default; + virtual ~wxPrintNativeDataBase(); virtual bool TransferTo( wxPrintData &data ) = 0; virtual bool TransferFrom( const wxPrintData &data ) = 0; @@ -172,7 +172,14 @@ public: virtual bool Ok() const { return IsOk(); } virtual bool IsOk() const = 0; - int m_ref; + // Internal implementation details, do not use. + + // For historical reasons, this class doesn't use wxRefCounter, but provides + // the same methods, so that it could still be used with wxObjectDataPtr. + void IncRef() { m_ref++; } + void DecRef() { if ( !--m_ref) delete this; } + + int m_ref = 1; private: wxDECLARE_CLASS(wxPrintNativeDataBase); diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index bea2648b6d..a8a014fb65 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -79,7 +79,6 @@ wxPrintData::wxPrintData() wxPrintData::wxPrintData(const wxPrintData& printData) : wxObject() { - m_nativeData = nullptr; (*this) = printData; } @@ -96,12 +95,7 @@ void wxPrintData::SetPrivData( char *privData, int len ) } } -wxPrintData::~wxPrintData() -{ - m_nativeData->m_ref--; - if (m_nativeData->m_ref == 0) - delete m_nativeData; -} +wxPrintData::~wxPrintData() = default; void wxPrintData::ConvertToNative() { @@ -133,16 +127,7 @@ wxPrintData& wxPrintData::operator=(const wxPrintData& data) m_printMode = data.m_printMode; m_filename = data.m_filename; - // UnRef old m_nativeData - if (m_nativeData) - { - m_nativeData->m_ref--; - if (m_nativeData->m_ref == 0) - delete m_nativeData; - } - // Set Ref new one - m_nativeData = data.GetNativeData(); - m_nativeData->m_ref++; + m_nativeData = data.m_nativeData; m_privData = data.m_privData; diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 564d230c17..d76e788529 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -288,10 +288,7 @@ wxPrintNativeDataBase *wxNativePrintFactory::CreatePrintNativeData() wxIMPLEMENT_ABSTRACT_CLASS(wxPrintNativeDataBase, wxObject); -wxPrintNativeDataBase::wxPrintNativeDataBase() -{ - m_ref = 1; -} +wxPrintNativeDataBase::~wxPrintNativeDataBase() = default; //---------------------------------------------------------------------------- // wxPrintFactoryModule From 4f1320fbf24e499942fc628b9b701fa1a9083d5d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 18:13:37 +0100 Subject: [PATCH 09/10] Use default implementation for wxPrintData copy and assignment Simplify the code and ensure it doesn't need to be modified in multiple places if/when a new field is added to wxPrintData in the future. No real changes. --- src/common/cmndata.cpp | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index a8a014fb65..1dd0bc0da8 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -76,11 +76,7 @@ wxPrintData::wxPrintData() m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData(); } -wxPrintData::wxPrintData(const wxPrintData& printData) - : wxObject() -{ - (*this) = printData; -} +wxPrintData::wxPrintData(const wxPrintData&) = default; void wxPrintData::SetPrivData( char *privData, int len ) { @@ -107,32 +103,7 @@ void wxPrintData::ConvertFromNative() m_nativeData->TransferTo( *this ) ; } -wxPrintData& wxPrintData::operator=(const wxPrintData& data) -{ - if ( &data == this ) - return *this; - - m_printNoCopies = data.m_printNoCopies; - m_printCollate = data.m_printCollate; - m_printOrientation = data.m_printOrientation; - m_printOrientationReversed = data.m_printOrientationReversed; - m_printerName = data.m_printerName; - m_colour = data.m_colour; - m_duplexMode = data.m_duplexMode; - m_printQuality = data.m_printQuality; - m_paperId = data.m_paperId; - m_paperSize = data.m_paperSize; - m_bin = data.m_bin; - m_media = data.m_media; - m_printMode = data.m_printMode; - m_filename = data.m_filename; - - m_nativeData = data.m_nativeData; - - m_privData = data.m_privData; - - return *this; -} +wxPrintData& wxPrintData::operator=(const wxPrintData&) = default; // Is this data OK for showing the print dialog? bool wxPrintData::IsOk() const From 34b20b83822930108ae74df2ebdbf2ebc39d46f8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Mar 2023 18:16:34 +0100 Subject: [PATCH 10/10] Initialize wxPrintData members in their declaration No real changes, just initialize the members of this class when declaring them too, for consistency with the other classes declared in this header. --- include/wx/cmndata.h | 27 +++++++++++++++------------ src/common/cmndata.cpp | 18 ------------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/include/wx/cmndata.h b/include/wx/cmndata.h index deac7b41c9..101345409d 100644 --- a/include/wx/cmndata.h +++ b/include/wx/cmndata.h @@ -116,21 +116,24 @@ public: wxPrintNativeDataBase *GetNativeData() const { return m_nativeData.get(); } private: - wxPrintBin m_bin; - int m_media; - wxPrintMode m_printMode; + wxPrintBin m_bin = wxPRINTBIN_DEFAULT; + int m_media = wxPRINTMEDIA_DEFAULT; + wxPrintMode m_printMode = wxPRINT_MODE_PRINTER; - int m_printNoCopies; - wxPrintOrientation m_printOrientation; - bool m_printOrientationReversed; - bool m_printCollate; + int m_printNoCopies = 1; + wxPrintOrientation m_printOrientation = wxPORTRAIT; + bool m_printOrientationReversed = false; + bool m_printCollate = false; wxString m_printerName; - bool m_colour; - wxDuplexMode m_duplexMode; - wxPrintQuality m_printQuality; - wxPaperSize m_paperId; - wxSize m_paperSize; + bool m_colour = true; + wxDuplexMode m_duplexMode = wxDUPLEX_SIMPLEX; + wxPrintQuality m_printQuality = wxPRINT_QUALITY_HIGH; + + // we intentionally don't initialize paper id and size at all, like this + // the default system settings will be used for them + wxPaperSize m_paperId = wxPAPER_NONE; + wxSize m_paperSize = wxDefaultSize; wxString m_filename; diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index 1dd0bc0da8..535740c78d 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -54,25 +54,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPageSetupDialogData, wxObject); // ---------------------------------------------------------------------------- wxPrintData::wxPrintData() - : m_paperSize(wxDefaultSize) { - m_bin = wxPRINTBIN_DEFAULT; - m_media = wxPRINTMEDIA_DEFAULT; - m_printMode = wxPRINT_MODE_PRINTER; - m_printOrientation = wxPORTRAIT; - m_printOrientationReversed = false; - m_printNoCopies = 1; - m_printCollate = false; - - // New, 24/3/99 - m_colour = true; - m_duplexMode = wxDUPLEX_SIMPLEX; - m_printQuality = wxPRINT_QUALITY_HIGH; - - // we intentionally don't initialize paper id and size at all, like this - // the default system settings will be used for them - m_paperId = wxPAPER_NONE; - m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData(); }