- wxClientDC dc(const_cast<wxDatePickerCtrl *>(this));
-
- // we can't use FormatDate() here as the CRT doesn't always use the same
- // format as the date picker control
- wxString s;
- for ( int len = 100; ; len *= 2 )
- {
- if ( ::GetDateFormat
- (
- LOCALE_USER_DEFAULT, // the control should use the same
- DATE_SHORTDATE, // the format used by the control
- NULL, // use current date (we don't care)
- NULL, // no custom format
- wxStringBuffer(s, len), // output buffer
- len // and its length
- ) )
- {
- // success
- break;
- }
-
- const DWORD rc = ::GetLastError();
- if ( rc != ERROR_INSUFFICIENT_BUFFER )
- {
- wxLogApiError(wxT("GetDateFormat"), rc);
-
- // fall back on wxDateTime, what else to do?
- s = wxDateTime::Today().FormatDate();
- break;
- }
- }
-
- // the best size for the control is bigger than just the string
- // representation of todays date 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);
-
- // account for the drop-down arrow or spin arrows
- x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X);
-
- // and for the checkbox if we have it
- if ( HasFlag(wxDP_ALLOWNONE) )
- x += 3*GetCharWidth();
-
- wxSize best(x, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y));
- CacheBestSize(best);
- return best;