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:
parent
2c6d132efe
commit
a98d8448fa
@ -112,24 +112,11 @@ wxDateTime wxDateTimePickerCtrl::GetValue() const
|
||||
|
||||
wxSize wxDateTimePickerCtrl::DoGetBestSize() const
|
||||
{
|
||||
// Since Vista, the control can compute its best size itself, just ask it.
|
||||
wxSize size;
|
||||
if ( wxGetWinVersion() >= wxWinVersion_Vista )
|
||||
{
|
||||
SIZE idealSize;
|
||||
// Do not use DateTime_GetIdealSize / DTM_GETIDEALSIZE. It returns
|
||||
// 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.
|
||||
|
||||
// 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));
|
||||
|
||||
// Use the same native format as the underlying native control.
|
||||
@ -145,15 +132,15 @@ wxSize wxDateTimePickerCtrl::DoGetBestSize() const
|
||||
// the width of the month string varies a lot, so try to account for it
|
||||
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);
|
||||
}
|
||||
|
||||
// We need to account for the checkbox, if we have one, ourselves as
|
||||
// DTM_GETIDEALSIZE doesn't seem to take it into account, at least under
|
||||
// Windows 7.
|
||||
int scrollY = wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_Y, m_parent);
|
||||
size.y = wxMax(size.y, scrollY);
|
||||
|
||||
// We need to account for the checkbox, if we have one.
|
||||
if ( MSWAllowsNone() )
|
||||
size.x += 3 * GetCharWidth();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user