26 #ifndef time_textbox_h
27 #define time_textbox_h
31 #include <wx/datetime.h>
32 #include <wx/textctrl.h>
33 #include <wx/msgdlg.h>
34 #include <wx/dateevt.h>
36 #define NO_TIME _T("00:00")
37 #define TIME_FORMAT _T("%H:%M")
41 TimeCtrl(wxWindow *parent, wxWindowID
id,
42 const wxDateTime &value = wxDefaultDateTime,
43 const wxPoint &pos = wxDefaultPosition,
44 const wxSize &size = wxDefaultSize,
long style = 0,
45 const wxValidator &validator = wxDefaultValidator,
46 const wxString &name = wxTextCtrlNameStr)
47 : wxTextCtrl(parent,
id,
48 value.IsValid() ? value.Format(TIME_FORMAT) : NO_TIME, pos,
49 size, style, validator, name) {
50 Bind(wxEVT_KEY_UP, &TimeCtrl::OnChar,
this);
51 Bind(wxEVT_KILL_FOCUS, &TimeCtrl::OnKillFocus,
this);
54 void SetValue(
const wxDateTime val) {
56 wxTextCtrl::SetValue(val.Format(TIME_FORMAT));
58 wxTextCtrl::SetValue(NO_TIME);
62 wxDateTime GetValue() {
64 wxString str = wxTextCtrl::GetValue();
65 wxString::const_iterator end;
66 if (!dt.ParseTime(str, &end)) {
67 return wxInvalidDateTime;
68 }
else if (end == str.end()) {
75 void OnChar(wxKeyEvent &event) {
76 if (GetValue().IsValid()) {
77 wxDateEvent evt(
this, GetValue(), wxEVT_TIME_CHANGED);
78 HandleWindowEvent(evt);
82 void OnKillFocus(wxFocusEvent &event) {
83 wxTextCtrl::SetValue(GetValue().Format(TIME_FORMAT));
86 bool GetTime(
int *hour,
int *min,
int *sec) {
87 const wxDateTime::Tm tm = GetValue().GetTm();