81 lines
2.4 KiB
C++
Executable File
81 lines
2.4 KiB
C++
Executable File
#include "CalendarEditor.h"
|
|
|
|
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL)
|
|
{
|
|
_calendar = new wxCalendarCtrl();
|
|
}
|
|
|
|
CalendarEditor::~CalendarEditor()
|
|
{
|
|
if (_calendar) delete _calendar;
|
|
}
|
|
|
|
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), _("%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;
|
|
_calendar->Create(_parent, id, wxDateTime(_day, _month, _year));
|
|
_calendar->EnableHolidayDisplay(false);
|
|
_calendar->EnableMonthChange(false);
|
|
_calendar->EnableYearChange(false);
|
|
// (void (wxObject::*)(wxEvent&))
|
|
_calendar->Connect((int)id, (int)wxEVT_CALENDAR_SEL_CHANGED, wxCommandEventHandler(CalendarEditor::OnCalendarChange), NULL, this);
|
|
//evtHandler->Connect((int)id, (int)wxEVT_CALENDAR_DOUBLECLICKED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange);
|
|
//_calendar->Connect(wxEVT_CALENDAR_SEL_CHANGED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange);
|
|
//wxGridCellEditor::Create(parent, id, evtHandler);
|
|
}
|
|
|
|
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()
|
|
{
|
|
_calendar->SetDate(wxDateTime(_day, _month, _year));
|
|
}
|
|
|
|
void CalendarEditor::Show (bool show, wxGridCellAttr *attr)
|
|
{
|
|
_calendar->SetDate(wxDateTime(_day, _month, _year));
|
|
_calendar->Show(show);
|
|
}
|
|
|
|
void CalendarEditor::SetSize (const wxRect &rect)
|
|
{
|
|
wxSize size = _calendar->GetMinSize();
|
|
_calendar->SetSize(wxRect(rect.x, rect.y, size.GetWidth(), size.GetHeight()));
|
|
}
|
|
|
|
void CalendarEditor::OnCalendarChange(wxCommandEvent& event)
|
|
{
|
|
_day = _calendar->GetDate().GetDay();
|
|
//_calendar->Show(false);
|
|
}
|