X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/453535a739f649ce43a65fd7e6b9730363bb1b7c..d8eff331e23435d9d8d6483a40f6fd9997a13f87:/samples/widgets/datepick.cpp diff --git a/samples/widgets/datepick.cpp b/samples/widgets/datepick.cpp index f72112cf8b..80261da8f5 100644 --- a/samples/widgets/datepick.cpp +++ b/samples/widgets/datepick.cpp @@ -156,7 +156,7 @@ void DatePickerWidgetsPage::CreateContent() sizerLeft->Add( CreateSizerWithTextAndLabel( wxT("&Year:"), DatePickerPage_Year , &m_year ), 0, wxALL | wxALIGN_RIGHT , 5 ); - sizerLeft->Add( new wxButton( this, wxID_ANY, wxT("&Set date") ), + sizerLeft->Add( new wxButton( this, DatePickerPage_Set, wxT("&Set date") ), 0, wxALL , 5 ); // right pane @@ -178,8 +178,6 @@ void DatePickerWidgetsPage::CreateContent() Reset(); SetSizer(sizerTop); - - sizerTop->Fit(this); } void DatePickerWidgetsPage::Reset() @@ -187,9 +185,9 @@ void DatePickerWidgetsPage::Reset() const wxDateTime today = wxDateTime::Today(); m_datePicker->SetValue(today); - m_day->SetValue(wxString::Format(_T("%d"), today.GetDay())); - m_month->SetValue(wxString::Format(_T("%d"), today.GetMonth())); - m_year->SetValue(wxString::Format(_T("%d"), today.GetYear())); + m_day->SetValue(wxString::Format(wxT("%d"), today.GetDay())); + m_month->SetValue(wxString::Format(wxT("%d"), today.GetMonth())); + m_year->SetValue(wxString::Format(wxT("%d"), today.GetYear())); } void DatePickerWidgetsPage::CreateDatePicker() @@ -225,6 +223,27 @@ void DatePickerWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) void DatePickerWidgetsPage::OnButtonSet(wxCommandEvent& WXUNUSED(event)) { + long day = 0, + month = 0, + year = 0; + if ( m_day->GetValue().ToLong(&day) && + m_month->GetValue().ToLong(&month) && + m_year->GetValue().ToLong(&year) ) + { + const wxDateTime someDay(day, wxDateTime::Month(month - 1), year); + if ( someDay.IsValid() ) + { + m_datePicker->SetValue(someDay); + } + else + { + wxLogError(wxT("Date is invalid")); + } + } + else + { + wxLogError(wxT("One of inputs is not number")); + } } #endif // wxUSE_DATEPICKCTRL