From 4f6cf6da5b7da23e8d757865745a104e7f675c55 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Mar 2021 14:49:54 +0100 Subject: [PATCH] Don't call GetTextExtent() if we don't use its result It's unnecessary to call GetTextExtent() just to discard/overwrite its result immediately with the value returned from DTM_GETIDEALSIZE, so don't do it. This reverts another part of a98d8448fa (Fix size of wxDateTimePickerCtrl after DPI change, 2019-01-13) which wasn't done in 7de85d7470 (Restore correct best width of wxDatePickerCtrl in MSW, 2020-05-24).included This commit is best viewed ignoring whitespace-only changes. --- src/msw/datetimectrl.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/msw/datetimectrl.cpp b/src/msw/datetimectrl.cpp index 25a6ba97d3..aaf8b80dc3 100644 --- a/src/msw/datetimectrl.cpp +++ b/src/msw/datetimectrl.cpp @@ -162,20 +162,7 @@ void wxDateTimePickerCtrl::SetNullText(const wxString& text) wxSize wxDateTimePickerCtrl::DoGetBestSize() const { - // Use the same native format as the underlying native control. -#if wxUSE_INTL - wxString s = wxDateTime::Now().Format(wxLocale::GetOSInfo(MSWGetFormat())); -#else // !wxUSE_INTL - wxString s("XXX-YYY-ZZZZ"); -#endif // wxUSE_INTL/!wxUSE_INTL - - // the best size for the control is bigger than just the string - // representation of the current value because the control must accommodate - // any date and while the widths of all digits are usually about the same, - // the width of the month string varies a lot, so try to account for it - s += wxS("W"); - - wxSize size = GetTextExtent(s); + wxSize size; // We can ask the control itself to compute its ideal size, but we only use // it for the horizontal component: the vertical size is not computed @@ -192,9 +179,25 @@ wxSize wxDateTimePickerCtrl::DoGetBestSize() const && ::SendMessage(m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)&idealSize) ) { size.x = idealSize.cx; + size.y = GetCharHeight(); } - else // Adjust the size ourselves. + else // Compute the size ourselves. { + // Use the same native format as the underlying native control. +#if wxUSE_INTL + wxString s = wxDateTime::Now().Format(wxLocale::GetOSInfo(MSWGetFormat())); +#else // !wxUSE_INTL + wxString s("XXX-YYY-ZZZZ"); +#endif // wxUSE_INTL/!wxUSE_INTL + + // the best size for the control is bigger than just the string + // representation of the current value because the control must accommodate + // any date and while the widths of all digits are usually about the same, + // the width of the month string varies a lot, so try to account for it + s += wxS("W"); + + size = GetTextExtent(s); + // Account for the drop-down arrow or spin arrows. size.x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X, m_parent);