From 0473d14ef192226cc78a20aa46f3c55b908cf7f6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Oct 2017 01:34:10 +0200 Subject: [PATCH] Make wxProgressDialog::Fit() work in native MSW version This method is supposed to adjust the dialog size to its contents and while the dialog increases automatically when using native implementation under MSW, it doesn't shrink back on its own and so it's still useful to allow Fit() to do it. Update the sample to test Fit() too. --- include/wx/msw/progdlg.h | 1 + interface/wx/progdlg.h | 3 ++- samples/dialogs/dialogs.cpp | 5 +++++ src/msw/progdlg.cpp | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/progdlg.h b/include/wx/msw/progdlg.h index 4c9dd94d54..9e3e8422d6 100644 --- a/include/wx/msw/progdlg.h +++ b/include/wx/msw/progdlg.h @@ -44,6 +44,7 @@ public: virtual void SetIcons(const wxIconBundle& icons) wxOVERRIDE; virtual void DoMoveWindow(int x, int y, int width, int height) wxOVERRIDE; virtual void DoGetPosition(int *x, int *y) const wxOVERRIDE; + virtual void Fit() wxOVERRIDE; virtual bool Show( bool show = true ) wxOVERRIDE; diff --git a/interface/wx/progdlg.h b/interface/wx/progdlg.h index 001bf37afa..1f69759dfe 100644 --- a/interface/wx/progdlg.h +++ b/interface/wx/progdlg.h @@ -196,7 +196,8 @@ public: conform to the length of the new message if desired. The dialog does not do this automatically, except for the native MSW implementation which does increase the dialog size if necessary (but still doesn't - shrink it back even if the text becomes shorter). + shrink it back even if the text becomes shorter and you need to call + Fit() explicitly if you want this to happen). @param value The new value of the progress meter. It should be less than or equal to diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 58e69fbbde..63be7bef0f 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -360,6 +360,11 @@ bool MyApp::OnInit() case 30: msg = "Back to brevity"; break; + + case 80: + msg = "Back and adjusted"; + dlg.Fit(); + break; } if ( !dlg.Update(i, msg) ) diff --git a/src/msw/progdlg.cpp b/src/msw/progdlg.cpp index 1c7903a241..202a09b360 100644 --- a/src/msw/progdlg.cpp +++ b/src/msw/progdlg.cpp @@ -767,6 +767,24 @@ void wxProgressDialog::DoGetPosition(int *x, int *y) const wxGenericProgressDialog::DoGetPosition(x, y); } +void wxProgressDialog::Fit() +{ +#ifdef wxHAS_MSW_TASKDIALOG + if ( HasNativeTaskDialog() ) + { + wxCriticalSectionLocker locker(m_sharedData->m_cs); + + // Force the task dialog to use this message to adjust it layout. + m_sharedData->m_msgChangeElementText = TDM_SET_ELEMENT_TEXT; + + // Don't change the message, but pretend that it did change. + m_sharedData->m_notifications |= wxSPDD_MESSAGE_CHANGED; + } +#endif // wxHAS_MSW_TASKDIALOG + + wxGenericProgressDialog::Fit(); +} + bool wxProgressDialog::Show(bool show) { #ifdef wxHAS_MSW_TASKDIALOG