00001
00008 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && defined(PKIFRESOURCES_ALLOW_GCC_PRAGMA)
00009 #pragma implementation "TMDDateTimePicker.cpp"
00010 #endif
00011
00012 #include "TMDDateTimePicker.h"
00013
00014 #include "PKIFTime.h"
00015
00016 #include <string>
00017 using namespace std;
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 BEGIN_EVENT_TABLE(TMDDateTimePicker,wxDialog)
00028 END_EVENT_TABLE()
00036 TMDDateTimePicker::TMDDateTimePicker( wxWindow *parent, wxWindowID id, const wxString &title,
00037 const wxPoint &position, const wxSize& size, long style ) :
00038 ResizableDialog( parent, id, title, position, size, style ), m_hoursCtrl(0),
00039 m_minutesCtrl(0), m_secondsCtrl(0)
00040 {
00041
00042
00043
00044
00045 wxBoxSizer * mainSizer = new wxBoxSizer(wxVERTICAL);
00046 SetSizer(mainSizer);
00047
00048
00049 m_cal = new wxCalendarCtrl(this,wxID_ANY);
00050 mainSizer->Add(m_cal,wxSizerFlags().Expand().Border());
00051
00052
00053
00054 wxBoxSizer * dtSizer = new wxBoxSizer(wxHORIZONTAL);
00055 m_hoursCtrl = new wxSpinCtrl(this,wxID_ANY,wxT("00"),wxDefaultPosition,wxDefaultSize,
00056 wxSP_ARROW_KEYS|wxSP_WRAP);
00057 m_minutesCtrl = new wxSpinCtrl(this,wxID_ANY,wxT("00"),wxDefaultPosition,wxDefaultSize,
00058 wxSP_ARROW_KEYS|wxSP_WRAP);
00059 m_secondsCtrl = new wxSpinCtrl(this,wxID_ANY,wxT("00"),wxDefaultPosition,wxDefaultSize,
00060 wxSP_ARROW_KEYS|wxSP_WRAP);
00061
00062
00063 m_hoursCtrl->SetRange(0, 23);
00064 m_hoursCtrl->SetValue(23);
00065 m_hoursCtrl->SetMinSize(wxSize(50,-1));
00066 m_minutesCtrl->SetRange(0, 59);
00067 m_minutesCtrl->SetValue(59);
00068 m_minutesCtrl->SetMinSize(wxSize(50,-1));
00069 m_secondsCtrl->SetRange(0, 59);
00070 m_secondsCtrl->SetValue(59);
00071 m_secondsCtrl->SetMinSize(wxSize(50,-1));
00072
00073
00074 dtSizer->Add(new wxStaticText(this,wxID_ANY,wxT("Time: ")),wxSizerFlags().Center());
00075 dtSizer->Add(m_hoursCtrl);
00076 dtSizer->Add(new wxStaticText(this,wxID_ANY,wxT(" : ")));
00077 dtSizer->Add(m_minutesCtrl);
00078 dtSizer->Add(new wxStaticText(this,wxID_ANY,wxT(" : ")));
00079 dtSizer->Add(m_secondsCtrl);
00080
00081
00082
00083 mainSizer->Add(dtSizer,wxSizerFlags().Expand().Border(wxALL,5));
00084 mainSizer->Add(CreateStdDialogButtonSizer(wxOK|wxCANCEL),wxSizerFlags().Expand().Border());
00085 this->ResizeToFitContents();
00086 }
00094 bool TMDDateTimePicker::Validate()
00095 {
00096
00097 return this->wxDialog::Validate();
00098 }
00106 bool TMDDateTimePicker::TransferDataToWindow()
00107 {
00108
00109 return this->wxDialog::TransferDataToWindow();
00110 }
00118 bool TMDDateTimePicker::TransferDataFromWindow()
00119 {
00120
00121 return this->wxDialog::TransferDataFromWindow();
00122 }
00130 CPKIFTimePtr TMDDateTimePicker::GetDateAsPKIFTime()
00131 {
00132 CPKIFTimePtr rv(new CPKIFTime);
00133
00134 wxDateTime dt = m_cal->GetDate();
00135 rv->set(dt.GetYear() , dt.GetMonth(), dt.GetDay(), m_hoursCtrl->GetValue(), m_minutesCtrl->GetValue(), m_secondsCtrl->GetValue());
00136
00137 return rv;
00138 }
00139
00140
00141
00142
00143
00151 wxDateTime::Month GetMonth(
00153 CPKIFTimePtr& t)
00154 {
00155 switch(t->month())
00156 {
00157 case 0:
00158 return wxDateTime::Jan;
00159 break;
00160 case 1:
00161 return wxDateTime::Feb;
00162 break;
00163 case 2:
00164 return wxDateTime::Mar;
00165 break;
00166 case 3:
00167 return wxDateTime::Apr;
00168 break;
00169 case 4:
00170 return wxDateTime::May;
00171 break;
00172 case 5:
00173 return wxDateTime::Jun;
00174 break;
00175 case 6:
00176 return wxDateTime::Jul;
00177 break;
00178 case 7:
00179 return wxDateTime::Aug;
00180 break;
00181 case 8:
00182 return wxDateTime::Sep;
00183 break;
00184 case 9:
00185 return wxDateTime::Oct;
00186 break;
00187 case 10:
00188 return wxDateTime::Nov;
00189 break;
00190 case 11:
00191 return wxDateTime::Dec;
00192 break;
00193 default:
00194 return wxDateTime::Inv_Month;
00195 }
00196 }
00197
00198
00199
00200 const char* MakeTimePurty(CPKIFTimePtr& t, std::string& s);
00201
00202
00210 wxString TMDDateTimePicker::GetDate(void)
00211 {
00212 CPKIFTimePtr theTime = GetDateAsPKIFTime();
00213
00214 std::string aString;
00215 const char* theTimeBeautified = MakeTimePurty(theTime, aString);
00216
00217 wxString rv(theTimeBeautified,wxConvUTF8);
00218 return rv;
00219 }
00220
00221
00222
00231 void TMDDateTimePicker::SetDate(
00233 CPKIFTimePtr& t)
00234 {
00235 m_hoursCtrl->SetValue(t->hours());
00236 m_minutesCtrl->SetValue(t->minutes());
00237 m_secondsCtrl->SetValue(t->seconds());
00238 wxDateTime dt(t->dayOfMonth(), GetMonth(t), t->year(),t->hours(),t->minutes(),t->seconds());
00239 m_cal->SetDate(dt);
00240 }
00241
00242
00250 void TMDDateTimePicker::SetMorningOrNight(
00252 bool b)
00253 {
00254 if(b)
00255 {
00256 m_hoursCtrl->SetValue(12);
00257 m_minutesCtrl->SetValue(0);
00258 m_secondsCtrl->SetValue(0);
00259 }
00260 else
00261 {
00262 m_hoursCtrl->SetValue(23);
00263 m_minutesCtrl->SetValue(59);
00264 m_secondsCtrl->SetValue(59);
00265 }
00266 }
00267
00268
00269
00270
00271