From b820a3632a86a6d0649e53d719f633cdee810588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 4 Sep 2010 11:54:49 +0200 Subject: [PATCH] * Create a grid directory for grid's components * Fix a bug inside ShowPanels * Add fast comboboxes editing inside grids --- Makefile | 6 ++- TODO | 2 + src/view/AccountPanel.h | 4 +- src/view/{GridAccount.h => GridAccount.} | 6 ++- src/view/PreferencesPanel.cpp | 28 +++++++---- src/view/SearchPanel.h | 4 +- src/view/{ => grid}/GridAccount.cpp | 38 ++++++++++++++- .../{ => grid}/wxGridCellBitmapRenderer.cpp | 0 .../{ => grid}/wxGridCellBitmapRenderer.h | 0 src/view/grid/wxGridCellFastBoolEditor.h | 24 ++++++++++ src/view/grid/wxMyGrid.cpp | 48 +++++++++++++++++++ src/view/grid/wxMyGrid.h | 22 +++++++++ src/view/wxUI.cpp | 4 +- src/view/wxUI.h | 2 + tools/package.sh | 2 +- 15 files changed, 168 insertions(+), 22 deletions(-) rename src/view/{GridAccount.h => GridAccount.} (91%) rename src/view/{ => grid}/GridAccount.cpp (83%) rename src/view/{ => grid}/wxGridCellBitmapRenderer.cpp (100%) rename src/view/{ => grid}/wxGridCellBitmapRenderer.h (100%) create mode 100644 src/view/grid/wxGridCellFastBoolEditor.h create mode 100644 src/view/grid/wxMyGrid.cpp create mode 100644 src/view/grid/wxMyGrid.h diff --git a/Makefile b/Makefile index 5d5b9b5..80e282f 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,12 @@ CXX=g++ SOURCES=$(wildcard src/model/*.cpp) SOURCES+=$(wildcard src/view/*.cpp) +SOURCES+=$(wildcard src/view/grid/*.cpp) SOURCES+=$(wildcard src/controller/*.cpp) SOURCES+=src/main.cpp src/sha1.cpp HEADERS=$(wildcard src/model/*.h) HEADERS+=$(wildcard src/view/*.h) +HEADERS+=$(wildcard src/view/grid/*.h) HEADERS+=$(wildcard src/controller/*.h) HEADERS+=src/main.h src/sha1.h OBJS=$(SOURCES:.cpp=.o) @@ -21,9 +23,9 @@ OBJS=$(SOURCES:.cpp=.o) all: kc clean: - rm -f *~ src/*~ src/*.o src/model/*.o src/model/*~ src/view/*.o src/view/*~ src/controller/*.o src/controller/*~ kc + rm -f *~ src/*~ src/*.o src/model/*.o src/model/*~ src/view/*.o src/view/grid/*.o src/view/grid/*~ src/view/*~ src/controller/*.o src/controller/*~ kc -%.o : src/model/%.cpp src/view/%.cpp src/controller/%.cpp src/%.cpp +%.o : src/model/%.cpp src/view/%.cpp src/view/grid/%.cpp src/controller/%.cpp src/%.cpp $(CXX) $(CXXFLAGS) $< -c kc: $(OBJS) diff --git a/TODO b/TODO index 3fed7a3..5ca7c25 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,7 @@ Documentation (en) Cool for 0.1: Database auto saving at startup Use caches for created panels (avoid destroying/creating panels for nothing) +Add search function to web view =============================================================== Next version @@ -27,6 +28,7 @@ Formulas Import/Export module Undo/redo Printing (maybe in html) +Refactor web view code =============================================================== Will not be implemented diff --git a/src/view/AccountPanel.h b/src/view/AccountPanel.h index 3a0cafe..23d97f4 100644 --- a/src/view/AccountPanel.h +++ b/src/view/AccountPanel.h @@ -27,14 +27,14 @@ #include #include #include "CalendarEditor.h" -#include "wxGridCellBitmapRenderer.h" +#include "grid/wxGridCellBitmapRenderer.h" #include "view.h" #include #include "wxUI.h" #include -#include "GridAccount.h" +#include "grid/GridAccount.h" #include class wxUI; diff --git a/src/view/GridAccount.h b/src/view/GridAccount. similarity index 91% rename from src/view/GridAccount.h rename to src/view/GridAccount. index dee4dff..907019a 100644 --- a/src/view/GridAccount.h +++ b/src/view/GridAccount. @@ -23,9 +23,10 @@ #include #include #include -#include "AccountPanel.h" +#include #include #include +#include "wxGridCellFastBoolEditor.h" class KissCount; @@ -42,11 +43,14 @@ public: void SetWeek(int week, int line); void InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear); + void OnCellLeftClick(wxGridEvent& evt); + int _fixCosts; int _week1, _week2, _week3, _week4; private: KissCount* _kiss; wxString* _categories, *_accounts; + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index f71722a..3e7f482 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -83,7 +83,11 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p // Account staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL); - _accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID); + { + int clicks[] = {ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE}; + + _accountsGrid = new wxMyGrid(this, ACCOUNTS_GRID_ID, clicks, 3); + } InitAccounts(user); @@ -95,7 +99,11 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p // Categories staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL); - _categoriesGrid = new wxGrid(this, CATEGORIES_GRID_ID); + { + int clicks[] = {CATEGORY_COLOR, CATEGORY_FONT, CATEGORY_DELETE}; + + _categoriesGrid = new wxMyGrid(this, CATEGORIES_GRID_ID, clicks, 3); + } staticBoxSizer->Add(_categoriesGrid); @@ -167,11 +175,11 @@ void PreferencesPanel::InitAccounts(User* user) _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); _accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (it->shared)?wxT("1"):wxT("0")); _accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?wxT("1"):wxT("0")); @@ -217,7 +225,7 @@ void PreferencesPanel::InitCategories(User* user) if (curLine) { _categoriesGrid->SetCellRenderer(curLine, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); - _categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellBoolEditor ()); + _categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellFastBoolEditor ()); } _categoriesGrid->SetCellAlignment(curLine, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE); @@ -381,11 +389,11 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) } _accountsGrid->SetCellRenderer(row, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellRenderer(row, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellFastBoolEditor ()); _accountsGrid->SetCellAlignment(row, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(row, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); _accountsGrid->SetCellAlignment(row, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); @@ -494,7 +502,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event) _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false); _categoriesGrid->SetCellRenderer(row, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); - _categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellBoolEditor ()); + _categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellFastBoolEditor ()); _categoriesGrid->SetCellAlignment(row, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE); _categoriesGrid->SetCellAlignment(row, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE); diff --git a/src/view/SearchPanel.h b/src/view/SearchPanel.h index 7ef12fe..82557b8 100644 --- a/src/view/SearchPanel.h +++ b/src/view/SearchPanel.h @@ -25,9 +25,9 @@ #include #include #include "CalendarEditor.h" -#include "wxGridCellBitmapRenderer.h" +#include "grid/wxGridCellBitmapRenderer.h" #include "AccountPanel.h" -#include "GridAccount.h" +#include "grid/GridAccount.h" #include "view.h" #include diff --git a/src/view/GridAccount.cpp b/src/view/grid/GridAccount.cpp similarity index 83% rename from src/view/GridAccount.cpp rename to src/view/grid/GridAccount.cpp index d9ffdff..2aa43e2 100644 --- a/src/view/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -24,6 +24,10 @@ 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) { @@ -140,9 +144,9 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, if (!fix) SetCellValue(line, CATEGORY, user->GetCategoryName(op->category)); SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ()); - SetCellEditor(line, DELETE, new wxGridCellBoolEditor ()); + SetCellEditor(line, DELETE, new wxGridCellFastBoolEditor ()); SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ()); - SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ()); + SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ()); color = user->GetCategory(op->category).color; @@ -187,3 +191,33 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, 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(); +} diff --git a/src/view/wxGridCellBitmapRenderer.cpp b/src/view/grid/wxGridCellBitmapRenderer.cpp similarity index 100% rename from src/view/wxGridCellBitmapRenderer.cpp rename to src/view/grid/wxGridCellBitmapRenderer.cpp diff --git a/src/view/wxGridCellBitmapRenderer.h b/src/view/grid/wxGridCellBitmapRenderer.h similarity index 100% rename from src/view/wxGridCellBitmapRenderer.h rename to src/view/grid/wxGridCellBitmapRenderer.h diff --git a/src/view/grid/wxGridCellFastBoolEditor.h b/src/view/grid/wxGridCellFastBoolEditor.h new file mode 100644 index 0000000..592260b --- /dev/null +++ b/src/view/grid/wxGridCellFastBoolEditor.h @@ -0,0 +1,24 @@ +#ifndef WXGRIDCELLFASTBOOLEDITOR_H +#define WXGRIDCELLFASTBOOLEDITOR_H + +#include +#include + +// 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 diff --git a/src/view/grid/wxMyGrid.cpp b/src/view/grid/wxMyGrid.cpp new file mode 100644 index 0000000..2fb1afa --- /dev/null +++ b/src/view/grid/wxMyGrid.cpp @@ -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::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(); +} diff --git a/src/view/grid/wxMyGrid.h b/src/view/grid/wxMyGrid.h new file mode 100644 index 0000000..d5a3432 --- /dev/null +++ b/src/view/grid/wxMyGrid.h @@ -0,0 +1,22 @@ +#ifndef WXMYGRID_H +#define WXMYGRID_H + +#include +#include +#include + +// 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 _clicks; + + DECLARE_EVENT_TABLE(); +}; + +#endif diff --git a/src/view/wxUI.cpp b/src/view/wxUI.cpp index d9bfe75..996f158 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -185,10 +185,10 @@ void wxUI::LoadUser() void wxUI::ShowPanel(wxPanel* panel) { - int month, year, account=0, preferences=0, search=0, stats=0; + int month, year=-1, account=0, preferences=0, search=0, stats=0; wxShowEvent event; - if (!panel) return; + if (!panel || panel == _curPanel) return; if (_curPanel) { diff --git a/src/view/wxUI.h b/src/view/wxUI.h index 11898ad..91e989d 100644 --- a/src/view/wxUI.h +++ b/src/view/wxUI.h @@ -29,6 +29,8 @@ #include "SearchPanel.h" #include "StatsPanel.h" #include +#include "grid/wxMyGrid.h" +#include "grid/wxGridCellFastBoolEditor.h" class KissCount; class ButtonPanel; diff --git a/tools/package.sh b/tools/package.sh index 1be18af..f0c2c0e 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -12,7 +12,7 @@ fi make || (echo "Compilation failed" ; exit 1) mkdir -p $DIR/lib cp -r lib/freechart/lib/* lib/wxsqlite3-1.9.9/lib/* $DIR/lib -cp -r kc init.sql ressources tools/launch_kc.sh TODO CONTRIBUTORS COPYING README README.fr $DIR +cp -r kc init.sql ressources tools/launch_kc.sh TODO CONTRIBUTORS COPYING README README.fr www $DIR find $DIR -type f -executable -exec strip \{\} \; tar -jcf $FILE $DIR rm -rf $DIR