/* Copyright 2010 Grégory Soutadé This file is part of KissCount. KissCount is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. KissCount is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with KissCount. If not, see . */ #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(); _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+1, _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+1, _month+1, _year)) ; } wxString CalendarEditor::GetValue() const { return wxString::Format(wxT("%02d/%02d/%d"), _day+1, _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(); }