2010-06-05 14:33:19 +02:00
|
|
|
#include "CalendarEditor.h"
|
|
|
|
|
2010-06-29 21:43:29 +02:00
|
|
|
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL), _days(NULL), _editor(NULL)
|
2010-06-05 14:33:19 +02:00
|
|
|
{
|
2010-06-29 21:43:29 +02:00
|
|
|
wxDateTime date;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
_maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay()+1;
|
|
|
|
|
|
|
|
_days = new wxString[_maxDay];
|
|
|
|
|
|
|
|
for (i=0; i<_maxDay; i++)
|
2010-07-03 11:19:02 +02:00
|
|
|
_days[i] = wxString::Format(wxT("%d"), i+1) ;
|
2010-06-29 21:43:29 +02:00
|
|
|
|
|
|
|
_editor = new wxChoice();
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CalendarEditor::~CalendarEditor()
|
|
|
|
{
|
2010-06-29 21:43:29 +02:00
|
|
|
delete _editor;
|
|
|
|
delete[] _days;
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid)
|
|
|
|
{
|
|
|
|
// wxDateTime date, dateDef;
|
|
|
|
|
|
|
|
// if (!grid->GetCellValue(row, col).Len()) return;
|
|
|
|
|
2010-07-03 11:19:02 +02:00
|
|
|
// if (date.ParseFormat(grid->GetCellValue(row, col), wxT("%d/%m/%Y"), dateDef))
|
2010-06-12 15:01:58 +02:00
|
|
|
// _calendar->SetDate(wxDateTime(_day, _month, _year));
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
wxGridCellEditor* CalendarEditor::Clone() const
|
|
|
|
{
|
|
|
|
return new CalendarEditor(_day, _month, _year);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
|
|
|
|
{
|
|
|
|
_parent = parent;
|
2010-06-29 21:43:29 +02:00
|
|
|
_editor->Create(parent, id, wxDefaultPosition, wxDefaultSize, _maxDay, _days);
|
|
|
|
_editor->Select(_day);
|
|
|
|
_editor->Connect((int)id, (int)wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(CalendarEditor::OnDateChanged), NULL, this);
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CalendarEditor::EndEdit (int row, int col, wxGrid *grid)
|
|
|
|
{
|
|
|
|
grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year)) ;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CalendarEditor::ApplyEdit (int row, int col, wxGrid *grid)
|
|
|
|
{
|
|
|
|
grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year)) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString CalendarEditor::GetValue() const
|
|
|
|
{
|
|
|
|
return wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CalendarEditor::Reset()
|
|
|
|
{
|
2010-06-29 21:43:29 +02:00
|
|
|
_editor->Select(_day);
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CalendarEditor::Show (bool show, wxGridCellAttr *attr)
|
|
|
|
{
|
2010-06-29 21:43:29 +02:00
|
|
|
_editor->Show(show);
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CalendarEditor::SetSize (const wxRect &rect)
|
|
|
|
{
|
2010-06-29 21:43:29 +02:00
|
|
|
_editor->SetSize(rect);
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
2010-06-27 21:39:49 +02:00
|
|
|
|
|
|
|
void CalendarEditor::StartingClick()
|
|
|
|
{
|
2010-06-29 21:43:29 +02:00
|
|
|
Show(true, NULL);
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-29 21:43:29 +02:00
|
|
|
|
|
|
|
void CalendarEditor::OnDateChanged(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
_day = _editor->GetSelection()+1;
|
|
|
|
}
|