KissCount/view/CalendarEditor.cpp
2010-06-05 14:33:19 +02:00

82 lines
2.4 KiB
C++

#include "CalendarEditor.h"
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL), _calendar(NULL)
{
}
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(date);
}
wxGridCellEditor* CalendarEditor::Clone() const
{
return new CalendarEditor(_day, _month, _year);
}
void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
_parent = parent;
_calendar = new wxCalendarCtrl(parent, id);
_calendar->EnableHolidayDisplay(false);
_calendar->EnableMonthChange(false);
_calendar->EnableYearChange(false);
_calendar->SetDate(wxDateTime(_day, _month, _year));
// (void (wxObject::*)(wxEvent&))
Connect((int)id, (int)wxEVT_CALENDAR_SEL_CHANGED, wxCommandEventHandler(CalendarEditor::OnCalendarChange));
//evtHandler->Connect((int)id, (int)wxEVT_CALENDAR_DOUBLECLICKED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange);
//evtHandler->Connect(wxEVT_CALENDAR_DOUBLECLICKED, (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->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)
{
std::cout << "ON CHANGE\n" ;
//wxDateTime date = _calendar->GetDate();
_day = _calendar->GetDate().GetDay();
_calendar->Show(false);
}