Fix size of wxDateTimePickerCtrl after DPI change

Do not use DateTime_GetIdealSize or DTM_GETIDEALSIZE. They return
incorrect sizes after the DPI of the window has changed. For every DPI
change, the returned size is 4 pixels higher, even if the DPI is
lowered.

Improve the existing method to also take the minimum height of the
scroll-arrows into account.
This commit is contained in:
Maarten Bent
2019-01-13 15:23:31 +01:00
parent 2c6d132efe
commit a98d8448fa

View File

@@ -112,24 +112,11 @@ wxDateTime wxDateTimePickerCtrl::GetValue() const
wxSize wxDateTimePickerCtrl::DoGetBestSize() const wxSize wxDateTimePickerCtrl::DoGetBestSize() const
{ {
// Since Vista, the control can compute its best size itself, just ask it. // Do not use DateTime_GetIdealSize / DTM_GETIDEALSIZE. It returns
wxSize size; // incorrect sizes after the DPI of the window has changed. For every DPI
if ( wxGetWinVersion() >= wxWinVersion_Vista ) // change, the returned size is 4 pixels higher, even if the DPI is
{ // lowered.
SIZE idealSize;
// Work around https://bugs.winehq.org/show_bug.cgi?id=44680 by
// checking for the return value: even if all "real" MSW systems do
// support this message, Wine does not, even when it's configured to
// return Vista or later version to the application.
if ( ::SendMessage(m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)&idealSize) )
{
size = wxSize(idealSize.cx, idealSize.cy);
}
}
if ( !size.x || !size.y )
{
wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this)); wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this));
// Use the same native format as the underlying native control. // Use the same native format as the underlying native control.
@@ -145,17 +132,17 @@ wxSize wxDateTimePickerCtrl::DoGetBestSize() const
// the width of the month string varies a lot, so try to account for it // the width of the month string varies a lot, so try to account for it
s += wxS("W"); s += wxS("W");
size = dc.GetTextExtent(s); wxSize size = dc.GetTextExtent(s);
// account for the drop-down arrow or spin arrows // Account for the drop-down arrow or spin arrows.
size.x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X, m_parent); size.x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X, m_parent);
}
// We need to account for the checkbox, if we have one, ourselves as int scrollY = wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_Y, m_parent);
// DTM_GETIDEALSIZE doesn't seem to take it into account, at least under size.y = wxMax(size.y, scrollY);
// Windows 7.
// We need to account for the checkbox, if we have one.
if ( MSWAllowsNone() ) if ( MSWAllowsNone() )
size.x += 3*GetCharWidth(); size.x += 3 * GetCharWidth();
// In any case, adjust the height to be the same as for the text controls. // In any case, adjust the height to be the same as for the text controls.
size.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(size.y); size.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(size.y);