* Create a grid directory for grid's components
* Fix a bug inside ShowPanels * Add fast comboboxes editing inside grids
This commit is contained in:
223
src/view/grid/GridAccount.cpp
Normal file
223
src/view/grid/GridAccount.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
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 "GridAccount.h"
|
||||
|
||||
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||
{ \
|
||||
SetCellBackgroundColour(row, i, color); \
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(GridAccount, wxGrid)
|
||||
EVT_GRID_CELL_LEFT_CLICK(GridAccount::OnCellLeftClick )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id),
|
||||
_fixCosts(0), _week1(0), _week2(0), _week3(0), _week4(0), _kiss(kiss)
|
||||
{
|
||||
wxBitmap deleteBitmap(wxT(DELETE_ICON));
|
||||
wxBitmap checkedBitmap(wxT(CHECKED_ICON));
|
||||
DEFAULT_FONT(font);
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
|
||||
CreateGrid(1, NUMBER_COLS_OPS);
|
||||
SetColLabelSize(0);
|
||||
SetRowLabelSize(0);
|
||||
|
||||
SetColSize (0, GetColSize(0)*3);
|
||||
SetDefaultCellFont(font);
|
||||
|
||||
font.SetWeight(wxFONTWEIGHT_BOLD);
|
||||
wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), wxT(""), wxT("")};
|
||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||
{
|
||||
SetCellValue(0, i, colsName[i]);
|
||||
SetCellBackgroundColour(0, i, OWN_CYAN);
|
||||
SetCellFont(0, i, font);
|
||||
SetReadOnly(0, i, true);
|
||||
SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
}
|
||||
SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(deleteBitmap));
|
||||
SetCellRenderer(0, CHECKED, new wxGridCellBitmapRenderer(checkedBitmap));
|
||||
|
||||
_accounts = new wxString[user->GetAccountsNumber()];
|
||||
for (i=0,
|
||||
accountIt = user->_accounts.begin();
|
||||
accountIt != user->_accounts.end();
|
||||
accountIt++, i++)
|
||||
_accounts[i] = accountIt->name;
|
||||
|
||||
_categories = new wxString[user->GetCategoriesNumber()] ;
|
||||
for(i=0, categoryIt = user->_categories.begin();
|
||||
categoryIt != user->_categories.end();
|
||||
categoryIt++, i++)
|
||||
{
|
||||
_categories[i] = categoryIt->name ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GridAccount::~GridAccount()
|
||||
{
|
||||
delete[] _categories;
|
||||
delete[] _accounts;
|
||||
}
|
||||
|
||||
wxPen GridAccount::GetColGridLinePen (int col)
|
||||
{return wxPen(*wxBLACK, 1, wxSOLID);}
|
||||
|
||||
wxPen GridAccount::GetRowGridLinePen (int row) {
|
||||
if (row == 0 || row == _fixCosts ||
|
||||
row == _week1 ||
|
||||
row == _week2 ||
|
||||
row == _week3 ||
|
||||
row == _week4)
|
||||
return wxPen(*wxBLACK, 1, wxSOLID);
|
||||
|
||||
return GetCellBackgroundColour(row, 0);
|
||||
}
|
||||
|
||||
void GridAccount::SetWeek(int week, int line) {
|
||||
switch (week) {
|
||||
case 1: _week1 = line; break;
|
||||
case 2: _week2 = line; break;
|
||||
case 3: _week3 = line; break;
|
||||
case 4: _week4 = line; break;
|
||||
}
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
int r, g, b;
|
||||
wxColour color;
|
||||
wxDateTime curDate;
|
||||
|
||||
curDate.SetToCurrent();
|
||||
|
||||
if (!op && !user->_accounts.size()) return;
|
||||
|
||||
InsertRows(line, 1);
|
||||
|
||||
SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2));
|
||||
SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2));
|
||||
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
|
||||
SetCellEditor(line, ACCOUNT, accountEditor);
|
||||
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false);
|
||||
SetCellEditor(line, CATEGORY, categoryEditor);
|
||||
|
||||
if (fix)
|
||||
{
|
||||
SetCellValue(line, CATEGORY, _("Fix"));
|
||||
SetReadOnly(line, CATEGORY);
|
||||
}
|
||||
|
||||
if (op)
|
||||
{
|
||||
SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
|
||||
SetCellValue(line, DESCRIPTION, op->description);
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
|
||||
if (op->amount < 0)
|
||||
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
|
||||
else
|
||||
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
|
||||
SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
|
||||
if (!fix)
|
||||
SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
|
||||
SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
|
||||
SetCellEditor(line, DELETE, new wxGridCellFastBoolEditor ());
|
||||
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
||||
SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ());
|
||||
|
||||
color = user->GetCategory(op->category).color;
|
||||
|
||||
if (op->checked)
|
||||
{
|
||||
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
|
||||
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
|
||||
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
|
||||
color.Set(r, g, b, color.Alpha());
|
||||
SetCellValue(line, CHECKED, wxT("1"));
|
||||
}
|
||||
|
||||
SET_ROW_COLOR(line, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
if (!fix &&
|
||||
curDate.GetMonth() == curMonth &&
|
||||
curDate.GetYear() == curYear)
|
||||
{
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear));
|
||||
}
|
||||
else
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
|
||||
if (fix)
|
||||
SET_ROW_COLOR(line, OWN_YELLOW)
|
||||
else
|
||||
SET_ROW_COLOR(line, OWN_GREEN);
|
||||
|
||||
SetReadOnly(line, CHECKED, true);
|
||||
SetReadOnly(line, DELETE, true);
|
||||
}
|
||||
|
||||
SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
|
||||
Layout();
|
||||
SetMinSize(GetMinSize());
|
||||
}
|
||||
|
||||
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
|
||||
void GridAccount::OnCellLeftClick(wxGridEvent& evt)
|
||||
{
|
||||
if (evt.GetCol() != DELETE && evt.GetCol() != CHECKED) { evt.Skip() ; return;}
|
||||
|
||||
// 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 = NULL;
|
||||
}
|
||||
pEditor->DecRef();
|
||||
evt.Skip();
|
||||
}
|
||||
43
src/view/grid/wxGridCellBitmapRenderer.cpp
Normal file
43
src/view/grid/wxGridCellBitmapRenderer.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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 "wxGridCellBitmapRenderer.h"
|
||||
|
||||
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());
|
||||
}
|
||||
40
src/view/grid/wxGridCellBitmapRenderer.h
Normal file
40
src/view/grid/wxGridCellBitmapRenderer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 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
|
||||
24
src/view/grid/wxGridCellFastBoolEditor.h
Normal file
24
src/view/grid/wxGridCellFastBoolEditor.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#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
|
||||
48
src/view/grid/wxMyGrid.cpp
Normal file
48
src/view/grid/wxMyGrid.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "wxMyGrid.h"
|
||||
|
||||
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 = NULL;
|
||||
}
|
||||
pEditor->DecRef();
|
||||
break;
|
||||
}
|
||||
}
|
||||
evt.Skip();
|
||||
}
|
||||
22
src/view/grid/wxMyGrid.h
Normal file
22
src/view/grid/wxMyGrid.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user