93 lines
2.1 KiB
C++
93 lines
2.1 KiB
C++
#include "CalendarEditor.h"
|
|
|
|
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL), _days(NULL), _editor(NULL)
|
|
{
|
|
wxDateTime date;
|
|
int i;
|
|
|
|
_maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay()+1;
|
|
|
|
_days = new wxString[_maxDay];
|
|
|
|
for (i=0; i<_maxDay; i++)
|
|
_days[i] = wxString::Format(wxT("%d"), i+1) ;
|
|
|
|
_editor = new wxChoice();
|
|
}
|
|
|
|
CalendarEditor::~CalendarEditor()
|
|
{
|
|
delete _editor;
|
|
delete[] _days;
|
|
}
|
|
|
|
void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid)
|
|
{
|
|
// wxDateTime date, dateDef;
|
|
|
|
// if (!grid->GetCellValue(row, col).Len()) return;
|
|
|
|
// if (date.ParseFormat(grid->GetCellValue(row, col), wxT("%d/%m/%Y"), dateDef))
|
|
// _calendar->SetDate(wxDateTime(_day, _month, _year));
|
|
}
|
|
|
|
wxGridCellEditor* CalendarEditor::Clone() const
|
|
{
|
|
return new CalendarEditor(_day, _month, _year);
|
|
}
|
|
|
|
void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
|
|
{
|
|
_parent = parent;
|
|
_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);
|
|
}
|
|
|
|
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()
|
|
{
|
|
_editor->Select(_day);
|
|
}
|
|
|
|
void CalendarEditor::Show (bool show, wxGridCellAttr *attr)
|
|
{
|
|
_editor->Show(show);
|
|
}
|
|
|
|
void CalendarEditor::SetSize (const wxRect &rect)
|
|
{
|
|
_editor->SetSize(rect);
|
|
}
|
|
|
|
void CalendarEditor::StartingClick()
|
|
{
|
|
Show(true, NULL);
|
|
}
|
|
|
|
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void CalendarEditor::OnDateChanged(wxCommandEvent& event)
|
|
{
|
|
_day = _editor->GetSelection()+1;
|
|
}
|