* Add formula support

*  Fix a bug (cannot add new operations due to bug in FormulaEditor)
This commit is contained in:
2010-10-14 20:49:49 +02:00
parent effc630650
commit f33f6ab85a
8 changed files with 703 additions and 155 deletions

View File

@@ -47,19 +47,41 @@ bool wxGridCellFormulaEditor::EndEdit (int row, int col, wxGrid *grid/*, const w
{
wxString res = GetValue();
Operation op;
char* str, *str2;
struct parse_opt opt, *r;
bool ret;
res = res.Trim();
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(&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"), EvaluateExpr(&opt, true)));
}
else
{
_formula = wxT("");
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
if (_formula.Length())
grid->SetCellValue(row, col, wxT("0"));
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
}
return ret;
}

View File

@@ -24,7 +24,7 @@
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.h"
#include "../../ParseExp.h"
class wxGridCellFormulaEditor : public wxGridCellTextEditor
{
public: