mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add cell "self" pointer to callback
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@421 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
18c6477fa9
commit
eeed9a13d9
@ -63,11 +63,14 @@ typedef struct _SingleCell {
|
||||
/* private data */
|
||||
char * value; /* current value */
|
||||
|
||||
const char * (*enter_cell) (const char * current);
|
||||
const char * (*modify_verify) (const char *old,
|
||||
const char * (*enter_cell) (struct _SingleCell *,
|
||||
const char * current);
|
||||
const char * (*modify_verify) (struct _SingleCell *,
|
||||
const char *old,
|
||||
const char *add,
|
||||
const char *new);
|
||||
const char * (*leave_cell) (const char * current);
|
||||
const char * (*leave_cell) (struct _SingleCell *,
|
||||
const char * current);
|
||||
|
||||
struct _CellBlock *block; /* back-pointer to parent container */
|
||||
} SingleCell;
|
||||
|
@ -68,19 +68,18 @@ void xaccParseDate (struct tm *parsed, const char * datestr)
|
||||
/* ================================================ */
|
||||
|
||||
static const char *
|
||||
DateEnter (const char * curr)
|
||||
DateEnter (struct _SingleCell *_cell, const char * curr)
|
||||
{
|
||||
char * sep;
|
||||
struct tm celldate;
|
||||
DateCell *cell = (DateCell *) _cell;
|
||||
|
||||
/* OK, we just entered a newval cell. Find out
|
||||
* what date that cell thinks it has.
|
||||
*/
|
||||
|
||||
xaccParseDate (&celldate, curr);
|
||||
xaccParseDate (&(cell->date), curr);
|
||||
|
||||
printf ("parse %d %d %d \n", celldate.tm_mday, celldate.tm_mon+1,
|
||||
celldate.tm_year+1900);
|
||||
printf ("parse %d %d %d \n", cell->date.tm_mday, cell->date.tm_mon+1,
|
||||
cell->date.tm_year+1900);
|
||||
|
||||
return curr;
|
||||
}
|
||||
@ -88,8 +87,12 @@ celldate.tm_year+1900);
|
||||
/* ================================================ */
|
||||
|
||||
static const char *
|
||||
DateMV (const char * oldval, const char *change, const char *newval)
|
||||
DateMV (struct _SingleCell *_cell,
|
||||
const char * oldval,
|
||||
const char *change,
|
||||
const char *newval)
|
||||
{
|
||||
DateCell *cell = (DateCell *) _cell;
|
||||
int accel=0;
|
||||
short day, month, year;
|
||||
char * datestr;
|
||||
|
@ -71,7 +71,7 @@ void xaccInitBasicRegister (BasicRegister *reg)
|
||||
header = xaccMallocCellBlock (1, MAX_COLS);
|
||||
reg->header = header;
|
||||
|
||||
cell = xaccMallocDateCell();
|
||||
cell = (SingleCell *) xaccMallocDateCell();
|
||||
cell->width = 9;
|
||||
xaccAddCell (header, cell, 0, DATE_CELL_C);
|
||||
xaccSetSingleCellValue (cell, "Date");
|
||||
@ -106,7 +106,7 @@ void xaccInitBasicRegister (BasicRegister *reg)
|
||||
curs = xaccMallocCellBlock (2, MAX_COLS);
|
||||
reg->cursor = curs;
|
||||
|
||||
cell = xaccMallocDateCell();
|
||||
cell = (SingleCell *) xaccMallocDateCell();
|
||||
cell->width = 9;
|
||||
xaccAddCell (curs, cell, DATE_CELL_R, DATE_CELL_C);
|
||||
reg->dateCell = cell;
|
||||
|
@ -11,26 +11,29 @@
|
||||
* decimal point in them */
|
||||
|
||||
static const char *
|
||||
PriceMV (const char * old, const char *change, const char *new)
|
||||
PriceMV (struct _SingleCell *_cell,
|
||||
const char * oldval,
|
||||
const char *change,
|
||||
const char *newval)
|
||||
{
|
||||
if (change) {
|
||||
/* if change is a decimal point, then count decimal points */
|
||||
if (DECIMAL_PT == change[0]) {
|
||||
int i, count=0;
|
||||
for (i=0; 0 != new[i]; i++) {
|
||||
if (DECIMAL_PT == new[i]) count ++;
|
||||
for (i=0; 0 != newval[i]; i++) {
|
||||
if (DECIMAL_PT == newval[i]) count ++;
|
||||
}
|
||||
if (1 >= count) return new;
|
||||
if (1 >= count) return newval;
|
||||
return NULL;
|
||||
|
||||
} else {
|
||||
/* accept numeric, reject non-alpha edits */
|
||||
if (isdigit (change[0])) return new;
|
||||
if (isdigit (change[0])) return newval;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
/* accept the new string if user action was delete, etc. */
|
||||
return new;
|
||||
/* accept the newval string if user action was delete, etc. */
|
||||
return newval;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
/* ================================================ */
|
||||
|
||||
static const char *
|
||||
ToggleRecn (const char *cur_val)
|
||||
ToggleRecn (struct _SingleCell *_cell, const char *cur_val)
|
||||
{
|
||||
char buff[2];
|
||||
|
||||
|
@ -238,7 +238,7 @@ enterCB (Widget mw, XtPointer cd, XtPointer cb)
|
||||
XbaeMatrixEnterCellCallbackStruct *cbs;
|
||||
int row, col;
|
||||
int rel_row, rel_col;
|
||||
const char * (*enter) (const char *);
|
||||
const char * (*enter) (struct _SingleCell *, const char *);
|
||||
|
||||
table = (Table *) cd;
|
||||
arr = table->cursor;
|
||||
@ -266,7 +266,7 @@ enterCB (Widget mw, XtPointer cd, XtPointer cb)
|
||||
const char *val, *retval;
|
||||
|
||||
val = table->entries[row][col];
|
||||
retval = enter (val);
|
||||
retval = enter (arr->cells[rel_row][rel_col], val);
|
||||
if (val != retval) {
|
||||
if (table->entries[row][col]) free (table->entries[row][col]);
|
||||
table->entries[row][col] = (char *) retval;
|
||||
@ -291,7 +291,10 @@ modifyCB (Widget mw, XtPointer cd, XtPointer cb)
|
||||
XbaeMatrixModifyVerifyCallbackStruct *cbs;
|
||||
int row, col;
|
||||
int rel_row, rel_col;
|
||||
const char * (*mv) (const char *, const char *, const char *);
|
||||
const char * (*mv) (struct _SingleCell *,
|
||||
const char *,
|
||||
const char *,
|
||||
const char *);
|
||||
const char *oldval, *change;
|
||||
char *newval;
|
||||
const char *retval;
|
||||
@ -331,7 +334,7 @@ modifyCB (Widget mw, XtPointer cd, XtPointer cb)
|
||||
/* OK, if there is a callback for this cell, call it */
|
||||
mv = arr->cells[rel_row][rel_col]->modify_verify;
|
||||
if (mv) {
|
||||
retval = (*mv) (oldval, change, newval);
|
||||
retval = (*mv) (arr->cells[rel_row][rel_col], oldval, change, newval);
|
||||
|
||||
/* if the callback returned a non-null value, allow the edit */
|
||||
if (retval) {
|
||||
@ -381,7 +384,7 @@ leaveCB (Widget mw, XtPointer cd, XtPointer cb)
|
||||
XbaeMatrixLeaveCellCallbackStruct *cbs;
|
||||
int row, col;
|
||||
int rel_row, rel_col;
|
||||
const char * (*leave) (const char *);
|
||||
const char * (*leave) (struct _SingleCell *, const char *);
|
||||
|
||||
table = (Table *) cd;
|
||||
arr = table->cursor;
|
||||
@ -406,7 +409,7 @@ leaveCB (Widget mw, XtPointer cd, XtPointer cb)
|
||||
const char *val, *retval;
|
||||
|
||||
val = cbs->value;
|
||||
retval = leave (val);
|
||||
retval = leave (arr->cells[rel_row][rel_col], val);
|
||||
|
||||
if (NULL == retval) retval = "";
|
||||
|
||||
|
@ -9,9 +9,12 @@
|
||||
* all modifications */
|
||||
|
||||
static const char *
|
||||
TextMV (const char * old, const char *change, const char *new)
|
||||
TextMV (struct _SingleCell *_cell,
|
||||
const char *oldval,
|
||||
const char *change,
|
||||
const char *newval)
|
||||
{
|
||||
return new;
|
||||
return newval;
|
||||
}
|
||||
|
||||
/* ================================================ */
|
||||
|
Loading…
Reference in New Issue
Block a user