39 TimeCtrl(wxWindow *parent, wxWindowID
id,
40 const wxDateTime &value = wxDefaultDateTime,
41 const wxPoint &pos = wxDefaultPosition,
42 const wxSize &size = wxDefaultSize,
long style = 0,
43 const wxValidator &validator = wxDefaultValidator,
44 const wxString &name = wxTextCtrlNameStr)
45 : wxTextCtrl(parent,
id,
46 value.IsValid() ? value.Format(TIME_FORMAT) : NO_TIME, pos,
47 size, style, validator, name) {
48 Bind(wxEVT_KEY_UP, &TimeCtrl::OnChar,
this);
49 Bind(wxEVT_KILL_FOCUS, &TimeCtrl::OnKillFocus,
this);
52 void SetValue(
const wxDateTime val) {
54 wxTextCtrl::SetValue(val.Format(TIME_FORMAT));
56 wxTextCtrl::SetValue(NO_TIME);
60 wxDateTime GetValue() {
62 wxString str = wxTextCtrl::GetValue();
63 wxString::const_iterator end;
64 if (!dt.ParseTime(str, &end)) {
65 return wxInvalidDateTime;
66 }
else if (end == str.end()) {
73 void OnChar(wxKeyEvent &event) {
74 if (GetValue().IsValid()) {
75 wxDateEvent evt(
this, GetValue(), wxEVT_TIME_CHANGED);
76 HandleWindowEvent(evt);
80 void OnKillFocus(wxFocusEvent &event) {
81 wxTextCtrl::SetValue(GetValue().Format(TIME_FORMAT));
84 bool GetTime(
int *hour,
int *min,
int *sec) {
85 const wxDateTime::Tm tm = GetValue().GetTm();