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,50 +112,37 @@ 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
|
wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this));
|
||||||
// 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 )
|
// Use the same native format as the underlying native control.
|
||||||
{
|
|
||||||
wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this));
|
|
||||||
|
|
||||||
// Use the same native format as the underlying native control.
|
|
||||||
#if wxUSE_INTL
|
#if wxUSE_INTL
|
||||||
wxString s = wxDateTime::Now().Format(wxLocale::GetOSInfo(MSWGetFormat()));
|
wxString s = wxDateTime::Now().Format(wxLocale::GetOSInfo(MSWGetFormat()));
|
||||||
#else // !wxUSE_INTL
|
#else // !wxUSE_INTL
|
||||||
wxString s("XXX-YYY-ZZZZ");
|
wxString s("XXX-YYY-ZZZZ");
|
||||||
#endif // wxUSE_INTL/!wxUSE_INTL
|
#endif // wxUSE_INTL/!wxUSE_INTL
|
||||||
|
|
||||||
// the best size for the control is bigger than just the string
|
// the best size for the control is bigger than just the string
|
||||||
// representation of the current value because the control must accommodate
|
// representation of the current value because the control must accommodate
|
||||||
// any date and while the widths of all digits are usually about the same,
|
// 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
|
// 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user