/* 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 "GridAccount.h" #define SET_ROW_COLOR(row, color) for(int i=0; iGetUser(); std::vector::iterator accountIt; std::vector::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; iGetAccountsNumber()]; 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::iterator it; int r, g, b; wxColour color; wxDateTime curDate; wxString description; wxFont font; Category cat ; 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) { cat = user->GetCategory(op->category); SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year)); description = op->description; UNESCAPE_CHARS(description); SetCellValue(line, DESCRIPTION, 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 wxGridCellBoolEditor ()); SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ()); SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ()); color = cat.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); if (cat.font.Length()) { font = user->GetCategoryFont(cat.id); SET_ROW_FONT(line, font); } } 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); AutoSizeRow(line); 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(); }