add change flag to help with cached values

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@516 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-02-06 18:45:50 +00:00
parent 3288c2fe2b
commit 5a36e8771b
5 changed files with 84 additions and 24 deletions

View File

@ -22,6 +22,7 @@ void xaccInitBasicCell (BasicCell *cell)
cell->width = 0;
cell->alignment = 0;
cell->value = 0x0;
cell->changed = 0;
cell->set_value = NULL;
cell->enter_cell = NULL;
cell->modify_verify = NULL;

View File

@ -114,11 +114,12 @@
typedef struct _BasicCell {
short width; /* column width, in chars, not pixels */
short alignment; /* column text alignment */
char input_output; /* zero if output-only */
short width; /* column width, in chars, not pixels */
short alignment; /* column text alignment */
char input_output; /* zero if output-only */
char * value; /* current value */
char * value; /* current value */
unsigned int changed; /* 2^32-1 if value modified */
/* "virtual", overloaded set-value method */
void (*set_value) (struct _BasicCell *,

View File

@ -41,7 +41,7 @@
#define MAX_COLS 8
/* ================================= */
/* ============================================== */
BasicRegister * xaccMallocBasicRegister (void)
{
@ -51,7 +51,7 @@ BasicRegister * xaccMallocBasicRegister (void)
return reg;
}
/* ================================= */
/* ============================================== */
void xaccInitBasicRegister (BasicRegister *reg)
{
@ -188,4 +188,28 @@ void xaccInitBasicRegister (BasicRegister *reg)
reg->table = table;
}
/* ============================================== */
unsigned int
xaccGetChangeFlag (BasicRegister *reg)
{
unsigned int changed = 0;
changed |= MOD_DATE && reg->dateCell->cell.changed;
changed |= MOD_NUM && reg->numCell->changed;
changed |= MOD_DESC && reg->descCell->cell.changed;
changed |= MOD_RECN && reg->recnCell->changed;
changed |= MOD_AMNT && reg->creditCell->cell.changed;
changed |= MOD_AMNT && reg->debitCell->cell.changed;
/* changed |= MOD_SHRS && reg->xxxxxxCell->cell.changed; */
/* changed |= MOD_PRIC && reg->xxxxxxCell->cell.changed; */
changed |= MOD_MEMO && reg->memoCell->changed;
changed |= MOD_ACTN && reg->actionCell->cell.changed;
changed |= MOD_XFRM && reg->xfrmCell->cell.changed;
/* changed |= MOD_XTO && reg->xtoCell->cell.changed; */
return changed;
}
/* ============ END OF FILE ===================== */

View File

@ -15,19 +15,36 @@
#include "recncell.h"
#include "textcell.h"
/* modified flags -- indicate how values have been modified */
#define MOD_NONE 0x000
#define MOD_DATE 0x001
#define MOD_NUM 0x002
#define MOD_DESC 0x004
#define MOD_RECN 0x008
#define MOD_AMNT 0x010
#define MOD_SHRS 0x020
#define MOD_PRIC 0x040
#define MOD_MEMO 0x080
#define MOD_ACTN 0x100
#define MOD_XFRM 0x200
#define MOD_XTO 0x400
#define MOD_NEW 0x800
#define MOD_ALL 0xfff
typedef struct _BasicRegister {
Table * table;
CellBlock * cursor;
CellBlock * header;
DateCell * dateCell;
BasicCell * numCell;
ComboCell * actionCell;
ComboCell * xfrmCell;
QuickFillCell * descCell;
BasicCell * memoCell;
BasicCell * recnCell;
PriceCell * creditCell;
PriceCell * debitCell;
BasicCell * memoCell;
ComboCell * actionCell;
ComboCell * xfrmCell;
PriceCell * balanceCell;
} BasicRegister;
@ -35,6 +52,8 @@ typedef struct _BasicRegister {
BasicRegister * xaccMallocBasicRegister (void);
void xaccInitBasicRegister (BasicRegister *);
unsigned int xaccGetChangeFlag (BasicRegister *);
#endif __XACC_REGISTER_H__
/* ============ END OF FILE ===================== */

View File

@ -354,6 +354,7 @@ void xaccMoveCursor (Table *table, int virt_row, int virt_col)
if (cell) {
jphys = j + table->current_cursor_col * table->tile_width;
xaccSetBasicCellValue (cell, table->entries[iphys][jphys]);
cell->changed = 0;
}
}
}
@ -385,6 +386,7 @@ void xaccMoveCursorGUI (Table *table, int virt_row, int virt_col)
for (j=0; j<table->tile_width; j++) {
cell = table->cursor->cells[i][j];
if (cell) {
cell->changed = 0;
if (cell->move) {
(cell->move) (cell, -1, -1);
}
@ -476,11 +478,6 @@ verifyCursorPosition (Table *table, int phys_row, int phys_col)
if ((virt_row != table->current_cursor_row) ||
(virt_col != table->current_cursor_col)) {
printf ("verify cursor bad cur %d %d new %d %d \n",
table->current_cursor_row,
table->current_cursor_col,
virt_row, virt_col);
/* before leaving, the current virtual position,
* commit any edits that have been accumulated
* in the cursor */
@ -655,7 +652,7 @@ enterCB (Widget mw, XtPointer cd, XtPointer cb)
rel_row %= (arr->numRows);
rel_col %= (arr->numCols);
printf ("enter %d %d \n", row, col);
printf ("enter %d %d \n", row, col);
/* since we are here, there must be a cell handler.
* therefore, we accept entry into the cell by default,
@ -675,6 +672,7 @@ enterCB (Widget mw, XtPointer cd, XtPointer cb)
if (val != retval) {
if (table->entries[row][col]) free (table->entries[row][col]);
table->entries[row][col] = retval;
(arr->cells[rel_row][rel_col])->changed = 0xffffffff;
XbaeMatrixSetCell (mw, row, col, retval);
XbaeMatrixRefreshCell (mw, row, col);
@ -752,6 +750,7 @@ modifyCB (Widget mw, XtPointer cd, XtPointer cb)
/* update data. bounds check done earlier */
free (table->entries[row][col]);
table->entries[row][col] = (char *) retval;
(arr->cells[rel_row][rel_col])->changed = 0xffffffff;
/* if the callback modified the display string,
* update the display cell as well */
@ -806,9 +805,9 @@ leaveCB (Widget mw, XtPointer cd, XtPointer cb)
rel_row %= (arr->numRows);
rel_col %= (arr->numCols);
printf ("leave %d %d \n", row, col);
printf ("leave %d %d \n", row, col);
/* by default, accept whateve the final roposed edit is */
/* by default, accept whatever the final proposed edit is */
cbs->doit = True;
/* OK, if there is a callback for this cell, call it */
@ -820,16 +819,32 @@ leaveCB (Widget mw, XtPointer cd, XtPointer cb)
retval = leave (arr->cells[rel_row][rel_col], val);
newval = (char *) retval;
if (val == retval) newval = strdup (val);
if (NULL == retval) newval = strdup (val);
if (val == retval) newval = strdup (val);
/* if the leave() routine declared a new string, lets use it */
if ( retval && (retval != val)) {
cbs->value = strdup (retval);
}
/* save whatever was returned */
if (table->entries[row][col]) free (table->entries[row][col]);
table->entries[row][col] = newval;
cbs->value = strdup (newval);
} else {
if (table->entries[row][col]) free (table->entries[row][col]);
table->entries[row][col] = strdup (cbs->value);
newval = strdup (cbs->value);
}
/* save whatever was returned; but lets check for
* changes to avoid roiling the cells too much */
if (table->entries[row][col]) {
if (strcmp (table->entries[row][col], newval)) {
free (table->entries[row][col]);
table->entries[row][col] = newval;
(arr->cells[rel_row][rel_col])->changed = 0xffffffff;
} else {
/* leave() allocated memory, which we will not be using ... */
free (newval);
}
} else {
table->entries[row][col] = newval;
(arr->cells[rel_row][rel_col])->changed = 0xffffffff;
}
}