From 663fa1c77b043e4ea0b5c40e9fcfbc152ec57ba3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 May 2022 17:13:49 +0100 Subject: [PATCH] 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