Use DTM_GETIDEALSIZE to implement wxDateTimePickerCtrl::DoGetBestSize().

If possible, i.e. when running under Vista or later, just ask the control for
its best size instead of trying to approximate it ourselves.

Notice that we still use our own height, to ensure that it's the same as for
the text controls, but it's the width that really counts.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78221 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-12-05 22:17:17 +00:00
parent 9fc78c8167
commit 340d7f67b6

View File

@@ -44,6 +44,10 @@
#define DateTime_SetSystemtime DateTime_SetSystemTime
#endif
#ifndef DTM_GETIDEALSIZE
#define DTM_GETIDEALSIZE 0x100f
#endif
// ============================================================================
// wxDateTimePickerCtrl implementation
// ============================================================================
@@ -108,32 +112,48 @@ wxDateTime wxDateTimePickerCtrl::GetValue() const
wxSize wxDateTimePickerCtrl::DoGetBestSize() const
{
wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this));
// Since Vista, the control can compute its best size itself, just ask it.
wxSize size;
if ( wxGetWinVersion() >= wxWinVersion_Vista )
{
SIZE idealSize;
::SendMessage(m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)&idealSize);
// Use the same native format as the underlying native control.
size = wxSize(idealSize.cx, idealSize.cy);
}
else // Windows XP
{
wxClientDC dc(const_cast<wxDateTimePickerCtrl *>(this));
// Use the same native format as the underlying native control.
#if wxUSE_INTL
wxString s = wxDateTime::Now().Format(wxLocale::GetOSInfo(MSWGetFormat()));
wxString s = wxDateTime::Now().Format(wxLocale::GetOSInfo(MSWGetFormat()));
#else // !wxUSE_INTL
wxString s("XXX-YYY-ZZZZ");
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 += wxT("WW");
// 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 += wxT("WW");
int x, y;
dc.GetTextExtent(s, &x, &y);
size = dc.GetTextExtent(s);
// account for the drop-down arrow or spin arrows
x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X);
// account for the drop-down arrow or spin arrows
size.x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X);
}
// and for the checkbox if we have it
// 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.
if ( MSWAllowsNone() )
x += 3*GetCharWidth();
size.x += 3*GetCharWidth();
return wxSize(x, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y));
// In any case, adjust the height to be the same as for the text controls.
size.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(size.y);
return size;
}
bool