Fix a bug with
This commit is contained in:
@@ -24,6 +24,11 @@
|
||||
SetCellBackgroundColour(row, i, color); \
|
||||
}
|
||||
|
||||
#define SET_ROW_FONT(row, font) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||
{ \
|
||||
SetCellFont(row, i, font); \
|
||||
}
|
||||
|
||||
#define UNESCAPE_CHARS(s) { \
|
||||
s.Replace(wxT("\\\""), wxT("\""), true); \
|
||||
s.Replace(wxT("\\\'"), wxT("\'"), true); \
|
||||
@@ -117,6 +122,8 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
||||
wxColour color;
|
||||
wxDateTime curDate;
|
||||
wxString description;
|
||||
wxFont font;
|
||||
Category cat ;
|
||||
|
||||
curDate.SetToCurrent();
|
||||
|
||||
@@ -139,6 +146,8 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
||||
|
||||
if (op)
|
||||
{
|
||||
cat = user->GetCategory(op->category);
|
||||
|
||||
SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
|
||||
description = op->description;
|
||||
UNESCAPE_CHARS(description);
|
||||
@@ -156,7 +165,7 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
||||
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
||||
SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ());
|
||||
|
||||
color = user->GetCategory(op->category).color;
|
||||
color = cat.color;
|
||||
|
||||
if (op->checked)
|
||||
{
|
||||
@@ -168,6 +177,11 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
||||
}
|
||||
|
||||
SET_ROW_COLOR(line, color);
|
||||
if (cat.font.Length())
|
||||
{
|
||||
font = user->GetCategoryFont(cat.id);
|
||||
SET_ROW_FONT(line, font);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,9 +197,13 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
|
||||
if (fix)
|
||||
SET_ROW_COLOR(line, OWN_YELLOW)
|
||||
else
|
||||
SET_ROW_COLOR(line, OWN_GREEN);
|
||||
{
|
||||
SET_ROW_COLOR(line, OWN_YELLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_ROW_COLOR(line, OWN_GREEN);
|
||||
}
|
||||
|
||||
SetReadOnly(line, CHECKED, true);
|
||||
SetReadOnly(line, DELETE, true);
|
||||
@@ -196,6 +214,8 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
||||
SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
|
||||
AutoSizeRow(line);
|
||||
|
||||
Layout();
|
||||
SetMinSize(GetMinSize());
|
||||
}
|
||||
|
||||
94
src/view/grid/wxGridCellButtonEditor.cpp
Normal file
94
src/view/grid/wxGridCellButtonEditor.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "wxGridCellButtonEditor.h"
|
||||
|
||||
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(NULL)
|
||||
{}
|
||||
|
||||
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), NULL, 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=NULL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
54
src/view/grid/wxGridCellButtonEditor.h
Normal file
54
src/view/grid/wxGridCellButtonEditor.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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 <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
|
||||
96
src/view/grid/wxGridCellButtonRenderer.cpp
Normal file
96
src/view/grid/wxGridCellButtonRenderer.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "wxGridCellButtonRenderer.h"
|
||||
|
||||
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
|
||||
}
|
||||
39
src/view/grid/wxGridCellButtonRenderer.h
Normal file
39
src/view/grid/wxGridCellButtonRenderer.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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 <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
|
||||
Reference in New Issue
Block a user