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 #define DateTime_SetSystemtime DateTime_SetSystemTime
#endif #endif
#ifndef DTM_GETIDEALSIZE
#define DTM_GETIDEALSIZE 0x100f
#endif
// ============================================================================ // ============================================================================
// wxDateTimePickerCtrl implementation // wxDateTimePickerCtrl implementation
// ============================================================================ // ============================================================================
@@ -108,6 +112,17 @@ 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.
wxSize size;
if ( wxGetWinVersion() >= wxWinVersion_Vista )
{
SIZE idealSize;
::SendMessage(m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)&idealSize);
size = wxSize(idealSize.cx, idealSize.cy);
}
else // Windows XP
{
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.
@@ -123,17 +138,22 @@ 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 += wxT("WW"); s += wxT("WW");
int x, y; size = dc.GetTextExtent(s);
dc.GetTextExtent(s, &x, &y);
// account for the drop-down arrow or spin arrows // account for the drop-down arrow or spin arrows
x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X); 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() ) 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 bool