From f0de5a93f8cca76a0a073fc4900e7f37b0b6d624 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 19 May 2022 17:57:03 +0200 Subject: [PATCH] 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 )