From 91a0dc3197522b422aac7b8ec3e20e9c8e623913 Mon Sep 17 00:00:00 2001 From: taler21 Date: Thu, 19 May 2022 16:42:31 +0200 Subject: [PATCH 01/11] Fix insufficient width of zoom combobox in print preview Don't hardcode 70px size for the combobox, but let it determine its own size instead, as 70 may well not be enough, depending on the theme and the font size. Closes #22439. --- src/common/prntbase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 3089d00202..d44e99da15 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1614,7 +1614,7 @@ void wxPreviewControlBar::CreateButtons() }; int n = WXSIZEOF(choices); - m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxSize(FromDIP(70),wxDefaultCoord), n, choices, 0 ); + m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxDefaultSize, n, choices, 0 ); sizer.Add(m_zoomControl); SetZoomControl(m_printPreview->GetZoom()); From 93a6784c5fa238636723cf021dc0876ada554995 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 19 May 2022 17:21:49 +0200 Subject: [PATCH 02/11] Remove unnecessary wxPreviewFrame::Layout() call No real changes, just remove the useless call which was left over the very first version of this code added in 7bcb11d307 (Many changes to the printing classes., 1999-03-25). --- src/common/prntbase.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index d44e99da15..b78cdd73b7 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1794,8 +1794,6 @@ void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) SetWindowStyle((GetWindowStyle() & ~wxMINIMIZE_BOX) | wxFRAME_NO_TASKBAR); } - Layout(); - m_printPreview->AdjustScrollbars(m_previewCanvas); m_previewCanvas->SetFocus(); m_controlBar->SetFocus(); From f0de5a93f8cca76a0a073fc4900e7f37b0b6d624 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 19 May 2022 17:57:03 +0200 Subject: [PATCH 03/11] Use reasonable size for wxPreviewFrame by default Give a reasonable default size to wxPreviewCanvas and fit wxPreviewFrame to its contents. Remove the useless call to Fit() from SizerWithButtons: the size set inside it was just ignored anyhow. This also allows to stop hardcoding the size in the sample, so don't do this any more. See #22439. --- samples/printing/printing.cpp | 6 ++---- src/common/prntbase.cpp | 6 +++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 8d8b4a361d..f2516eed61 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -390,8 +390,7 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) return; } - wxPreviewFrame *frame = - new wxPreviewFrame(preview, this, "Demo Print Preview", wxDefaultPosition, FromDIP(wxSize(600, 700))); + wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview"); frame->Centre(wxBOTH); frame->InitializeWithModality(m_previewModality); frame->Show(); @@ -425,8 +424,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); - wxPreviewFrame *frame = - new wxPreviewFrame(preview, this, "Demo Print Preview", wxDefaultPosition, FromDIP(wxSize(600, 700))); + wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview"); frame->Centre(wxBOTH); frame->Initialize(); frame->Show(); diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index b78cdd73b7..35af2cacde 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -936,6 +936,10 @@ wxScrolledWindow(parent, wxID_ANY, pos, size, style | wxFULL_REPAINT_ON_RESIZE, SetBackgroundColour(wxSystemSettings::GetColour(colourIndex)); SetScrollbars(10, 10, 100, 100); + + // Use some reasonable default size for this window, roughly proportional + // to the paper sheet. + SetInitialSize(wxSize(600, 750)); } wxPreviewCanvas::~wxPreviewCanvas() @@ -1486,7 +1490,6 @@ public: ~SizerWithButtons() { m_parent->SetSizer(m_sizer); - m_sizer->Fit(m_parent); } @@ -1766,6 +1769,7 @@ void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) sizer->Add( m_previewCanvas, wxSizerFlags(1).Expand().Border() ); SetSizer( sizer ); + sizer->Fit(this); m_modalityKind = kind; switch ( m_modalityKind ) From dcf24f5311533cb794bb92a6f1f1a0c1a552d807 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 19 May 2022 17:08:17 +0100 Subject: [PATCH 04/11] Remove unnecessary and ugly borders from wxPreviewFrame Having borders around the controls toolbar and preview canvas not only wasted space, but also let the frame background show through, which looked just ugly under MSW, where it is dark grey and so clashes with the control bar background. Simply remove them to save space and improve appearance too. --- src/common/prntbase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 35af2cacde..48413c05d1 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1765,8 +1765,8 @@ void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) wxBoxSizer* const sizer = new wxBoxSizer( wxVERTICAL ); - sizer->Add( m_controlBar, wxSizerFlags().Expand().Border() ); - sizer->Add( m_previewCanvas, wxSizerFlags(1).Expand().Border() ); + sizer->Add( m_controlBar, wxSizerFlags().Expand() ); + sizer->Add( m_previewCanvas, wxSizerFlags(1).Expand() ); SetSizer( sizer ); sizer->Fit(this); From f96789c1fd1c2f6e44326f25c7036fae1ad8d0de Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 20 May 2022 23:53:38 +0100 Subject: [PATCH 05/11] Don't hardcode wxPreviewFrame size in the documentation This is a bad idea and it's better to let the frame determine its own best size. --- docs/doxygen/overviews/printing.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/doxygen/overviews/printing.h b/docs/doxygen/overviews/printing.h index 19e6c50609..9444464e31 100644 --- a/docs/doxygen/overviews/printing.h +++ b/docs/doxygen/overviews/printing.h @@ -55,9 +55,7 @@ case WXPRINT_PREVIEW: // Pass two printout objects: for preview, and possible printing. wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, - "Demo Print Preview", - wxPoint(100, 100), - wxSize(600, 650)); + "Demo Print Preview"); frame->Centre(wxBOTH); frame->Initialize(); frame->Show(true); From 5be09037d0a4fbc107833cf7a6f84c8b7118e1d2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 May 2022 00:04:03 +0100 Subject: [PATCH 06/11] Disallow shrinking wxPreviewFrame too much horizontally Make it at least as wide as the controls bar to ensure all the buttons are always shown. --- src/common/prntbase.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 48413c05d1..6c40dd5ae5 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1771,6 +1771,13 @@ void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) SetSizer( sizer ); sizer->Fit(this); + // We don't want to restrict shrinking the window vertically as it might be + // too tall (see SetInitialSize() call in wxPreviewCanvas ctor), but we do + // want to make it at least as wide as the control bar, as otherwise the + // buttons wouldn't fit, and restricting it to at least its height + // vertically is also quite reasonable. + SetSizeHints(m_controlBar->GetBestSize()); + m_modalityKind = kind; switch ( m_modalityKind ) { From 4d3bb036f907150cb2954709012bfac4232f7676 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 May 2022 00:08:11 +0100 Subject: [PATCH 07/11] Use GetDefaultBorderFractional() for borders in wxPreviewFrame This is slightly more precise when using non-integral scaling factor than using GetDefaultBorder(). --- src/common/prntbase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 6c40dd5ae5..43c91a5504 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1500,7 +1500,7 @@ public: { m_needsSeparator = false; - m_sizer->AddSpacer(2*wxSizerFlags::GetDefaultBorder()); + m_sizer->AddSpacer(wxRound(2*wxSizerFlags::GetDefaultBorderFractional())); } m_hasContents = true; @@ -1868,7 +1868,7 @@ void wxPrintPreviewBase::Init(wxPrintout *printout, m_currentPage = 1; m_currentZoom = 70; m_topMargin = - m_leftMargin = 2*wxSizerFlags::GetDefaultBorder(); + m_leftMargin = wxRound(2*wxSizerFlags::GetDefaultBorderFractional()); m_pageWidth = 0; m_pageHeight = 0; m_printingPrepared = false; From 1e483f9510889bb2c6d000dc4b63e65483633fef Mon Sep 17 00:00:00 2001 From: taler21 Date: Sat, 21 May 2022 00:11:06 +0100 Subject: [PATCH 08/11] Improve the appearance of "Close" button in wxPreviewFrame Ensure that there is a border at least as wide as between the other button groups before this button. --- src/common/prntbase.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 43c91a5504..e72963a49f 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1528,9 +1528,13 @@ public: // as everything else added after it will be added on the right side too. void AddAtEnd(wxWindow *win) { + // Ensure there is at least the same gap before the final button as + // between the other groups. + m_sizer->AddSpacer(wxRound(2*wxSizerFlags::GetDefaultBorderFractional())); + m_sizer->AddStretchSpacer(); m_sizer->Add(win, - wxSizerFlags().Border(wxTOP | wxBOTTOM | wxRIGHT).Center()); + wxSizerFlags().Border().Center()); } // Indicates the end of a group of buttons, a separator will be added after From 4b9721536cff71a62ed0052568333a33ad72bde6 Mon Sep 17 00:00:00 2001 From: taler21 Date: Sat, 21 May 2022 13:26:38 +0100 Subject: [PATCH 09/11] Center the print preview frame after fully creating it Center the frame correctly in the sample and demonstrate the right way to do it in the documentation. --- docs/doxygen/overviews/printing.h | 2 +- samples/printing/printing.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/doxygen/overviews/printing.h b/docs/doxygen/overviews/printing.h index 9444464e31..caecda75ac 100644 --- a/docs/doxygen/overviews/printing.h +++ b/docs/doxygen/overviews/printing.h @@ -56,8 +56,8 @@ case WXPRINT_PREVIEW: wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview"); - frame->Centre(wxBOTH); frame->Initialize(); + frame->Centre(wxBOTH); frame->Show(true); break; } diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index f2516eed61..a9d847b7b5 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -391,8 +391,8 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) } wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview"); - frame->Centre(wxBOTH); frame->InitializeWithModality(m_previewModality); + frame->Centre(wxBOTH); frame->Show(); } @@ -425,8 +425,8 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) wxPrintDialogData printDialogData(* g_printData); wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(this), new MyPrintout(this), &printDialogData); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview"); - frame->Centre(wxBOTH); frame->Initialize(); + frame->Centre(wxBOTH); frame->Show(); } From fc0a4d4e62e4babc73f22ee4a7c17a0418e5abab Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 May 2022 17:12:50 +0100 Subject: [PATCH 10/11] Correct client/window confusing in wxPreviewFrame code Pass the window size to SetSizeHints() to make sure the window minimum size is set as expected. --- src/common/prntbase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index e72963a49f..5ef94ae7db 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1780,7 +1780,7 @@ void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) // want to make it at least as wide as the control bar, as otherwise the // buttons wouldn't fit, and restricting it to at least its height // vertically is also quite reasonable. - SetSizeHints(m_controlBar->GetBestSize()); + SetSizeHints(ClientToWindowSize(m_controlBar->GetBestSize())); m_modalityKind = kind; switch ( m_modalityKind ) From 663fa1c77b043e4ea0b5c40e9fcfbc152ec57ba3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 May 2022 17:13:49 +0100 Subject: [PATCH 11/11] Still use wxPreviewFrame size if it was explicitly specified Even though it's better to not specify the preview frame size at all, the size should still be used if it was explicitly specified, but this didn't happen any more after the addition of the call to Fit(). Fix this now by only doing the equivalent of Fit() if no size was explicitly given. Also add advice about not setting the size explicitly to the documentation. --- include/wx/prntbase.h | 2 ++ interface/wx/print.h | 3 +++ src/common/prntbase.cpp | 13 +++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/wx/prntbase.h b/include/wx/prntbase.h index b82f967516..c674156dfa 100644 --- a/include/wx/prntbase.h +++ b/include/wx/prntbase.h @@ -444,6 +444,8 @@ protected: private: void OnChar(wxKeyEvent& event); + const wxSize m_initialSize; + wxDECLARE_EVENT_TABLE(); wxDECLARE_CLASS(wxPreviewFrame); wxDECLARE_NO_COPY_CLASS(wxPreviewFrame); diff --git a/interface/wx/print.h b/interface/wx/print.h index 83426cfc17..b86782c885 100644 --- a/interface/wx/print.h +++ b/interface/wx/print.h @@ -195,6 +195,9 @@ public: Pass a print preview object plus other normal frame arguments. The print preview object will be destroyed by the frame when it closes. + + Note that @a size typically should @e not be specified explicitly to + let the frame use its default size, adapted to its contents. */ wxPreviewFrame(wxPrintPreviewBase* preview, wxWindow* parent, const wxString& title = "Print Preview", diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 5ef94ae7db..7655b16ecc 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -1702,7 +1702,8 @@ void wxPreviewFrame::OnChar(wxKeyEvent &event) wxPreviewFrame::wxPreviewFrame(wxPrintPreviewBase *preview, wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name): -wxFrame(parent, wxID_ANY, title, pos, size, style, name) +wxFrame(parent, wxID_ANY, title, pos, size, style, name), + m_initialSize(size) { m_printPreview = preview; m_controlBar = NULL; @@ -1773,7 +1774,15 @@ void wxPreviewFrame::InitializeWithModality(wxPreviewFrameModalityKind kind) sizer->Add( m_previewCanvas, wxSizerFlags(1).Expand() ); SetSizer( sizer ); - sizer->Fit(this); + + // Respect the user-specified size, if any, but use the best appropriate + // size by default if none was explicitly given. + if ( !m_initialSize.IsFullySpecified() ) + { + wxSize size = m_initialSize; + size.SetDefaults(sizer->ComputeFittingWindowSize(this)); + SetSize(size); + } // We don't want to restrict shrinking the window vertically as it might be // too tall (see SetInitialSize() call in wxPreviewCanvas ctor), but we do