First pass

This commit is contained in:
2011-08-25 17:45:41 +02:00
parent ed6a7a5fef
commit 991486a042
64 changed files with 1257 additions and 8876 deletions

View File

@@ -1,111 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "CalendarEditor.hpp"
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(0), _days(0), _editor(0)
{
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), 0, 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, 0);
}
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
{
return true;
}
void CalendarEditor::OnDateChanged(wxCommandEvent& event)
{
_day = _editor->GetSelection();
}

View File

@@ -1,61 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef CALENDAREDITOR_H
#define CALENDAREDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/calctrl.h>
#include <wx/datetime.h>
#include <wx/event.h>
#include <wx/choice.h>
class CalendarEditor : public wxGridCellChoiceEditor, public wxEvtHandler
{
public:
CalendarEditor(int day, int month, int year);
~CalendarEditor();
void BeginEdit(int row, int col, wxGrid *grid);
wxGridCellEditor* Clone () const;
void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler);
bool EndEdit(int row, int col, wxGrid *grid);
void ApplyEdit(int row, int col, wxGrid *grid);
wxString GetValue() const;
void Reset();
void Show(bool show, wxGridCellAttr *attr=0);
void SetSize (const wxRect &rect);
/* void OnCalendarChange(wxCommandEvent& event); */
void OnDateChanged(wxCommandEvent& event);
void StartingClick();
bool IsAcceptedKey(wxKeyEvent &event);
private:
int _day;
int _month;
int _year;
wxWindow *_parent;
wxString* _days;
int _maxDay;
wxChoice* _editor;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,102 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef GRIDACCOUNT_H
#define GRIDACCOUNT_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <list>
#include <vector>
#include <algorithm>
#include <view/AccountPanel.hpp>
#include <model/model.hpp>
#include <controller/KissCount.hpp>
#include "wxGridCellFastBoolEditor.hpp"
#include "wxGridCellTreeButtonRenderer.hpp"
#include "wxGridCellTreeButtonEditor.hpp"
#include "wxGridCellBitmapRenderer.hpp"
#include "wxGridCellFormulaEditor.hpp"
#include "wxGridCellTabStringRenderer.hpp"
class KissCount;
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
typedef void (*updateOperationFunc)(Operation* op, void** params);
class GridAccount : public wxGrid
{
public:
class OperationNotFound {};
GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id,
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
~GridAccount();
wxPen GetColGridLinePen (int col);
wxPen GetRowGridLinePen (int row);
virtual void ClearGrid();
void LoadOperations(std::vector<Operation>* operations, int month, int year);
void InsertOperationWithWeek(User* user, Operation& op, int line, bool fix, int month, int year) ;
void InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year) ;
void GetSelectedOperations(std::vector<int>* rows);
void MassUpdate(std::vector<int>& rows, updateOperationFunc func, void** params);
void Group();
void UnGroup();
void OnCellLeftClick(wxGridEvent& evt);
void OnOperationModified(wxGridEvent& event);
int _fixCosts;
int _week1, _week2, _week3, _week4;
std::vector<Operation> _displayedOperations;
private:
wxWindow* _parent;
KissCount* _kiss;
bool _displayLines;
bool _canAddOperation, _setWeek;
bool _databaseSynchronization;
wxString* _categories, *_accounts;
std::vector<Operation>* _operations;
bool _loadOperations;
int _curMonth, _curYear;
void SetWeek(int week, int line);
void ResetWeeks();
void ComputeWeeks();
void InsertIntoGrid(Operation& op);
void DeleteOperation(const Operation& op);
void UpdateMeta(Operation& op);
int RemoveMeta(Operation op, int line, bool removeRoot, bool deleteOp);
void CheckMeta(Operation& op, int line, bool check);
Operation& GetOperation(const wxString& id) throw(OperationNotFound);
void UpdateOperation(Operation& op);
int GetDisplayedRow(const wxString& id);
DECLARE_EVENT_TABLE();
};
#endif

View File

@@ -1,43 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellBitmapRenderer.hpp"
wxGridCellBitmapRenderer::wxGridCellBitmapRenderer(wxBitmap& bitmap) : _bitmap(bitmap)
{
}
wxGridCellRenderer* wxGridCellBitmapRenderer::Clone () const
{
wxBitmap bitmap(_bitmap);
return new wxGridCellBitmapRenderer(bitmap);
}
void wxGridCellBitmapRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
dc.DrawBitmap (_bitmap, rect.x + (rect.width-_bitmap.GetWidth())/2, rect.y + (rect.height-_bitmap.GetHeight())/2, true);
}
wxSize wxGridCellBitmapRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
return wxSize(_bitmap.GetWidth(), _bitmap.GetHeight());
}

View File

@@ -1,40 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLBITMAPRENDERER_H
#define WXGRIDCELLBITMAPRENDERER_H
#include <wx/grid.h>
#include <wx/bitmap.h>
#include <wx/dc.h>
class wxGridCellBitmapRenderer : public wxGridCellRenderer
{
public:
wxGridCellBitmapRenderer(wxBitmap& bitmap);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
private:
wxBitmap _bitmap;
};
#endif

View File

@@ -1,94 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellButtonEditor.hpp"
enum {BUTTON_ID = 1} ;
// BEGIN_EVENT_TABLE(wxGridCellButtonEditor, wxEvtHandler)
// EVT_BUTTON(BUTTON_ID, wxGridCellButtonEditor::OnButton)
// END_EVENT_TABLE()
wxGridCellButtonEditor::wxGridCellButtonEditor(const wxString& text) : _text(text), _button(0)
{}
wxGridCellButtonEditor::~wxGridCellButtonEditor()
{
if (_button) delete _button;
}
wxGridCellEditor* wxGridCellButtonEditor::Clone () const
{
return new wxGridCellButtonEditor(_text);
}
void wxGridCellButtonEditor::BeginEdit (int row, int col, wxGrid *grid)
{
_row = row;
_col = col;
_grid = grid;
if (_grid)
{
wxGridEvent event (_grid->GetId(), wxEVT_GRID_CELL_CHANGE, this, _row, _col);
_grid->GetEventHandler()->AddPendingEvent(event);
}
}
void wxGridCellButtonEditor::Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
if (_button) return;
_button = new wxButton(parent, id, _text);
_button->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxGridCellButtonEditor::OnButton), 0, this);
}
bool wxGridCellButtonEditor::EndEdit (int row, int col, /*const*/ wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
return false;
}
void wxGridCellButtonEditor::ApplyEdit (int row, int col, wxGrid *grid)
{}
void wxGridCellButtonEditor::Reset ()
{}
wxString wxGridCellButtonEditor::GetValue() const
{
return wxT("");
}
void wxGridCellButtonEditor::SetSize (const wxRect &rect)
{
if (_button) _button->SetSize(rect);
}
void wxGridCellButtonEditor::Show (bool show, wxGridCellAttr *attr=0)
{
if (_button) _button->Show(show);
}
void wxGridCellButtonEditor::OnButton(wxCommandEvent& evt)
{
if (_grid)
{
wxGridEvent event (_grid->GetId(), wxEVT_GRID_CELL_CHANGE, this, _row, _col);
_grid->GetEventHandler()->AddPendingEvent(event);
}
}

View File

@@ -1,54 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLBUTTONEDITOR_H
#define WXGRIDCELLBUTTONEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellButtonEditor : public wxGridCellEditor, public wxEvtHandler
{
public:
wxGridCellButtonEditor(const wxString& text);
~wxGridCellButtonEditor();
wxGridCellEditor* Clone () const;
void BeginEdit (int row, int col, wxGrid *grid);
void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler);
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
void ApplyEdit (int row, int col, wxGrid *grid);
void Reset () ;
wxString GetValue() const ;
void SetSize (const wxRect &rect);
void Show (bool show, wxGridCellAttr *attr);
void OnButton(wxCommandEvent& event);
private:
wxString _text;
wxButton* _button;
int _row, _col;
wxGrid* _grid;
/* DECLARE_EVENT_TABLE(); */
};
#endif

View File

@@ -1,96 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellButtonRenderer.hpp"
wxGridCellButtonRenderer::wxGridCellButtonRenderer(const wxString& text) : _text(text)
{
}
wxGridCellRenderer* wxGridCellButtonRenderer::Clone () const
{
return new wxGridCellButtonRenderer(_text);
}
void wxGridCellButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected)
{
wxRect rect = _rect;
wxCoord w, h, descent, external_leading;
wxBrush originalBrush = dc.GetBrush();
wxPen originalPen = dc.GetPen();
dc.SetPen(wxPen(*wxLIGHT_GREY));
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
rect.x += 2 ;
rect.y += 2 ;
rect.width -= 6 ;
rect.height -= 6 ;
dc.SetPen(wxPen(*wxWHITE));
dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
dc.SetPen(wxPen(*wxBLACK));
dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width + 1, rect.y + rect.height);
dc.DrawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
dc.SetPen(wxPen(wxColor(0x80, 0x80, 0x80)));
dc.DrawLine(rect.x + 1, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
dc.DrawLine(rect.x + rect.width - 1, rect.y + 1, rect.x + rect.width - 1, rect.y + rect.height);
rect.x += 1 ;
rect.y += 1 ;
rect.width -= 2 ;
rect.height -= 2 ;
dc.SetPen(wxPen(*wxLIGHT_GREY));
dc.SetBrush(wxBrush(*wxLIGHT_GREY));
dc.DrawRectangle(rect);
dc.GetTextExtent(_text, &w, &h, &descent, &external_leading);
if (w < rect.width)
rect.x += (rect.width - w) / 2;
if (h < rect.height)
rect.y += (rect.height - h) / 2;
rect.y -= (external_leading + descent);
dc.SetTextForeground(*wxBLACK);
// dc.SetTextBackground(wxColor(128, 128, 128, 255));
dc.SetTextBackground(*wxLIGHT_GREY);
dc.DrawText(_text, rect.x, rect.y);
dc.SetBrush(originalBrush);
dc.SetPen(originalPen);
}
wxSize wxGridCellButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
wxCoord w, h;
dc.GetTextExtent(_text, &w, &h);
return wxSize(w+14, h+14); // (2 + 2 + 3) * 2
}

View File

@@ -1,39 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLBUTTONRENDERER_H
#define WXGRIDCELLBUTTONRENDERER_H
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellButtonRenderer : public wxGridCellRenderer
{
public:
wxGridCellButtonRenderer(const wxString& text);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
private:
wxString _text;
};
#endif

View File

@@ -1,24 +0,0 @@
#ifndef WXGRIDCELLFASTBOOLEDITOR_H
#define WXGRIDCELLFASTBOOLEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
// From http://wiki.wxwidgets.org/WxGrid
class wxGridCellFastBoolEditor : public wxGridCellBoolEditor
{
public:
void BeginEdit (int row, int col, wxGrid* grid)
{
wxGridCellBoolEditor::BeginEdit(row, col, grid);
wxFocusEvent event (wxEVT_KILL_FOCUS);
if (m_control)
{
m_control->GetEventHandler()->AddPendingEvent(event);
}
}
};
#endif

View File

@@ -1,93 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellFormulaEditor.hpp"
wxGridCellFormulaEditor::wxGridCellFormulaEditor(const wxString& formula) : _formula(formula)
{}
void wxGridCellFormulaEditor::BeginEdit (int row, int col, wxGrid *grid) {
static bool inModification = false;
Operation op;
if (inModification) return ;
inModification = true;
op = ((GridAccount*) grid)->_displayedOperations[row];
if (op.formula.Length())
{
grid->SetCellValue(row, col, op.formula);
_formula = op.formula;
}
wxGridCellTextEditor::BeginEdit(row, col, grid);
inModification = false;
}
bool wxGridCellFormulaEditor::EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
wxString res = GetValue();
Operation op;
char* str, *str2;
struct ParseExp::parse_opt opt, *r;
bool ret;
res = res.Trim();
res.Replace(wxT(","), wxT("."), true);
if (res.StartsWith(wxT("=")))
{
str = (char*) std::string(res.mb_str()).c_str();
str2 = new char[strlen(str)];
strcpy(str2, str+1);
r = &opt;
str = str2;
try {
ParseExp::ParseExp(&str2, r, false);
}
catch(...)
{
wxMessageBox(_("Invalid formula !"), _("Error"), wxICON_ERROR | wxOK);
delete str;
return false;
}
delete str;
_formula = res;
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
grid->SetCellValue(row, col, wxString::Format(wxT("%.2lf"), ParseExp::EvaluateExpr(&opt, true)));
}
else
{
_formula = wxT("");
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
}
return ret;
}
wxString wxGridCellFormulaEditor::GetFormula()
{
return _formula;
}

View File

@@ -1,56 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLFORMULAEDITOR_H
#define WXGRIDCELLFORMULAEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.hpp"
#include "../../ParseExp.hpp"
class wxGridCellFormulaEditor : public wxGridCellTextEditor
{
public:
wxGridCellFormulaEditor(const wxString& formula);
/* ~wxGridCellFormulEeditor(); */
/* wxGridCellEditor* Clone () const; */
void BeginEdit (int row, int col, wxGrid *grid);
/* void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler); */
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
/* void ApplyEdit (int row, int col, wxGrid *grid); */
/* void Reset () ; */
/* wxString GetValue() const ; */
/* void SetSize (const wxRect &rect); */
/* void Show (bool show, wxGridCellAttr *attr); */
wxString GetFormula();
private:
wxString _formula;
wxButton* _button;
int _row, _col;
wxGrid* _grid;
/* DECLARE_EVENT_TABLE(); */
};
#endif

View File

@@ -1,53 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellStarEditor.hpp"
void wxGridCellStarEditor::BeginEdit (int row, int col, wxGrid *grid) {
static bool inModification = false;
wxString value;
if (inModification) return ;
inModification = true;
value = grid->GetCellValue(row, col);
_has_star = (value[value.Length()-1] == '*');
if (_has_star)
grid->SetCellValue(row, col, value.RemoveLast());
wxGridCellTextEditor::BeginEdit(row, col, grid);
inModification = false;
}
bool wxGridCellStarEditor::EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
wxString res = GetValue();
bool ret;
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
if (_has_star)
grid->SetCellValue(row, col, res + wxT("*"));
return ret;
}

View File

@@ -1,37 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLSTAREDITOR_H
#define WXGRIDCELLSTAREDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellStarEditor : public wxGridCellTextEditor
{
public:
void BeginEdit (int row, int col, wxGrid *grid);
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
private:
bool _has_star;
};
#endif

View File

@@ -1,40 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTabStringRenderer.hpp"
void wxGridCellTabStringRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
wxString d;
wxGridTableBase * table ;
if (!((GridAccount*) &grid)->_displayedOperations[row].parent.Length())
{
wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
return;
}
table = grid.GetTable();
d = table->GetValue(row, col).Trim();
table->SetValue(row, col, wxT(" ") + d);
wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
table->SetValue(row, col, d);
}

View File

@@ -1,35 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLTABSTRINGRENDERER_H
#define WXGRIDCELLTABSTRINGRENDERER_H
#include <wx/grid.h>
#include <wx/bitmap.h>
#include <wx/dc.h>
#include "GridAccount.hpp"
class wxGridCellTabStringRenderer : public wxGridCellStringRenderer
{
public:
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
};
#endif

View File

@@ -1,76 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTreeButtonEditor.hpp"
wxGridCellEditor* wxGridCellTreeButtonEditor::Clone () const
{
return new wxGridCellTreeButtonEditor();
}
void wxGridCellTreeButtonEditor::BeginEdit (int row, int col, wxGrid *grid)
{
wxGridEvent evt(0, 0, 0, row, col);
_row = row;
_col = col;
_grid = grid;
wxGridCellRenderer* pRenderer = _grid->GetCellRenderer(_row, _col);
((GridAccount*)_grid)->OnCellLeftClick(evt);
((wxGridCellTreeButtonRenderer*) pRenderer)->Invert();
pRenderer->DecRef();
}
void wxGridCellTreeButtonEditor::Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
}
bool wxGridCellTreeButtonEditor::EndEdit (int row, int col, /*const*/ wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
return true;
}
void wxGridCellTreeButtonEditor::ApplyEdit (int row, int col, wxGrid *grid)
{}
void wxGridCellTreeButtonEditor::Reset ()
{}
wxString wxGridCellTreeButtonEditor::GetValue() const
{
wxGridCellRenderer* pRenderer = _grid->GetCellRenderer(_row, _col);
wxString res = ((wxGridCellTreeButtonRenderer*) pRenderer)->IsCollapsed() ? wxT("1") : wxT("0");
pRenderer->DecRef();
return res;
}
void wxGridCellTreeButtonEditor::SetSize (const wxRect &rect)
{
}
void wxGridCellTreeButtonEditor::Show (bool show, wxGridCellAttr *attr=0)
{
}

View File

@@ -1,50 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLTREEBUTTONEDITOR_H
#define WXGRIDCELLTREEBUTTONEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.hpp"
#include "wxGridCellTreeButtonRenderer.hpp"
class wxGridCellTreeButtonEditor : public wxGridCellEditor
{
public:
wxGridCellEditor* Clone () const;
void BeginEdit (int row, int col, wxGrid *grid);
void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler);
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
void ApplyEdit (int row, int col, wxGrid *grid);
void Reset () ;
wxString GetValue() const ;
void SetSize (const wxRect &rect);
void Show (bool show, wxGridCellAttr *attr);
private:
int _row, _col;
wxGrid* _grid;
};
#endif

View File

@@ -1,85 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#include "wxGridCellTreeButtonRenderer.hpp"
wxGridCellTreeButtonRenderer::wxGridCellTreeButtonRenderer(bool collapsed) : _collapsed(collapsed)
{
}
wxGridCellRenderer* wxGridCellTreeButtonRenderer::Clone () const
{
return new wxGridCellTreeButtonRenderer(_collapsed);
}
bool wxGridCellTreeButtonRenderer::IsCollapsed()
{
return _collapsed;
}
void wxGridCellTreeButtonRenderer::Invert()
{
_collapsed = !_collapsed;
}
void wxGridCellTreeButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected)
{
wxRect rect = _rect;
wxBrush originalBrush = dc.GetBrush();
wxPen originalPen = dc.GetPen();
dc.SetPen(wxPen(grid.GetCellBackgroundColour(row, col)));
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
rect.x += 4 ;
rect.y += 4 ;
rect.width -= 8 ;
rect.height -= 8 ;
if (rect.width > rect.height)
rect.width = rect.height;
else if (rect.height > rect.width)
rect.height = rect.width;
dc.SetPen(wxPen(*wxBLACK));
dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width + 1, rect.y + rect.height);
dc.DrawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
rect.x += 2 ;
rect.y += 2 ;
rect.width -= 4 ;
rect.height -= 4 ;
dc.DrawLine(rect.x+1, rect.y + rect.height/2, rect.x + rect.width + 1, rect.y + rect.height/2);
if (!_collapsed)
dc.DrawLine(rect.x + rect.width/2 + 1, rect.y, rect.x + rect.width/2 + 1, rect.y + rect.height);
}
wxSize wxGridCellTreeButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
return wxSize(8, 8);
}

View File

@@ -1,41 +0,0 @@
/*
Copyright 2010-2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef WXGRIDCELLTREEBUTTONRENDERER_H
#define WXGRIDCELLTREEBUTTONRENDERER_H
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellTreeButtonRenderer : public wxGridCellRenderer
{
public:
wxGridCellTreeButtonRenderer(bool collapsed=false);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
bool IsCollapsed();
void Invert();
private:
bool _collapsed;
};
#endif

View File

@@ -1,48 +0,0 @@
#include "wxMyGrid.hpp"
BEGIN_EVENT_TABLE(wxMyGrid, wxGrid)
EVT_GRID_CELL_LEFT_CLICK(wxMyGrid::OnCellLeftClick )
END_EVENT_TABLE()
wxMyGrid::wxMyGrid(wxWindow* parent, int id, int* clicks, int size) : wxGrid(parent, id)
{
for(int i=0; i<size; i++)
_clicks.push_back(clicks[i]);
}
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
void wxMyGrid::OnCellLeftClick(wxGridEvent& evt)
{
std::vector<int>::iterator it;
for(it = _clicks.begin(); it != _clicks.end(); it++)
{
if (*it == evt.GetCol())
{
// This forces the cell to go into edit mode directly
//m_waitForSlowClick = TRUE;
SetGridCursor(evt.GetRow(), evt.GetCol());
// Store the click co-ordinates in the editor if possible
// if an editor has created a ClientData area, we presume it's
// a wxPoint and we store the click co-ordinates
wxGridCellEditor* pEditor = GetCellEditor(evt.GetRow(), evt.GetCol());
wxPoint* pClickPoint = (wxPoint*)pEditor->GetClientData();
if (pClickPoint)
{
*pClickPoint = ClientToScreen(evt.GetPosition());
#ifndef __WINDOWS__
EnableCellEditControl(true);
#endif
}
// hack to prevent selection from being lost when click combobox
if (evt.GetCol() == 0 && IsInSelection(evt.GetRow(), evt.GetCol()))
{
//m_selTemp = m_selection;
m_selection = 0;
}
pEditor->DecRef();
break;
}
}
evt.Skip();
}

View File

@@ -1,22 +0,0 @@
#ifndef WXMYGRID_H
#define WXMYGRID_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <vector>
// From http://wiki.wxwidgets.org/WxGrid
class wxMyGrid : public wxGrid
{
public:
wxMyGrid(wxWindow* parent, int id, int* clicks, int size);
void OnCellLeftClick(wxGridEvent& ev);
private:
std::vector<int> _clicks;
DECLARE_EVENT_TABLE();
};
#endif