KissCount/src/view/CalendarEditor.cpp

112 lines
2.9 KiB
C++
Raw Normal View History

2010-07-10 16:34:30 +02:00
/*
Copyright 2010 Grégory Soutadé
2010-07-10 16:34:30 +02:00
This file is part of KissCount.
2010-07-10 16:34:30 +02:00
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.
2010-07-10 16:34:30 +02:00
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.
2010-07-10 16:34:30 +02:00
You should have received a copy of the GNU General Public License
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
2010-07-10 16:34:30 +02:00
*/
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
{
wxDateTime date;
int i;
2010-06-29 21:43:29 +02:00
_maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay()+1;
2010-06-29 21:43:29 +02:00
_days = new wxString[_maxDay];
2010-06-29 21:43:29 +02:00
for (i=0; i<_maxDay; i++)
_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()
{
delete _editor;
delete[] _days;
2010-06-05 14:33:19 +02:00
}
void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid)
{
// wxDateTime date, dateDef;
2010-06-05 14:33:19 +02:00
// if (!grid->GetCellValue(row, col).Len()) return;
2010-06-05 14:33:19 +02:00
// if (date.ParseFormat(grid->GetCellValue(row, col), wxT("%d/%m/%Y"), dateDef))
// _calendar->SetDate(wxDateTime(_day, _month, _year));
2010-06-05 14:33:19 +02:00
}
wxGridCellEditor* CalendarEditor::Clone() const
{
return new CalendarEditor(_day, _month, _year);
2010-06-05 14:33:19 +02:00
}
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);
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+1, _month+1, _year)) ;
2010-06-05 14:33:19 +02:00
return true;
2010-06-05 14:33:19 +02:00
}
void CalendarEditor::ApplyEdit (int row, int col, wxGrid *grid)
{
grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ;
2010-06-05 14:33:19 +02:00
}
wxString CalendarEditor::GetValue() const
{
return wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year);
2010-06-05 14:33:19 +02:00
}
void CalendarEditor::Reset()
{
_editor->Select(_day);
2010-06-05 14:33:19 +02:00
}
void CalendarEditor::Show (bool show, wxGridCellAttr *attr)
{
_editor->Show(show);
2010-06-05 14:33:19 +02:00
}
void CalendarEditor::SetSize (const wxRect &rect)
{
_editor->SetSize(rect);
2010-06-05 14:33:19 +02:00
}
2010-06-27 21:39:49 +02:00
void CalendarEditor::StartingClick()
{
Show(true, NULL);
2010-06-27 21:39:49 +02:00
}
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
{
return true;
2010-06-27 21:39:49 +02:00
}
2010-06-29 21:43:29 +02:00
void CalendarEditor::OnDateChanged(wxCommandEvent& event)
{
_day = _editor->GetSelection();
2010-06-29 21:43:29 +02:00
}