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 */
|
/* private data */
|
||||||
char * value; /* current value */
|
char * value; /* current value */
|
||||||
|
|
||||||
const char * (*enter_cell) (const char * current);
|
const char * (*enter_cell) (struct _SingleCell *,
|
||||||
const char * (*modify_verify) (const char *old,
|
const char * current);
|
||||||
|
const char * (*modify_verify) (struct _SingleCell *,
|
||||||
|
const char *old,
|
||||||
const char *add,
|
const char *add,
|
||||||
const char *new);
|
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 */
|
struct _CellBlock *block; /* back-pointer to parent container */
|
||||||
} SingleCell;
|
} SingleCell;
|
||||||
|
@ -68,19 +68,18 @@ void xaccParseDate (struct tm *parsed, const char * datestr)
|
|||||||
/* ================================================ */
|
/* ================================================ */
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
DateEnter (const char * curr)
|
DateEnter (struct _SingleCell *_cell, const char * curr)
|
||||||
{
|
{
|
||||||
char * sep;
|
DateCell *cell = (DateCell *) _cell;
|
||||||
struct tm celldate;
|
|
||||||
|
|
||||||
/* OK, we just entered a newval cell. Find out
|
/* OK, we just entered a newval cell. Find out
|
||||||
* what date that cell thinks it has.
|
* 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,
|
printf ("parse %d %d %d \n", cell->date.tm_mday, cell->date.tm_mon+1,
|
||||||
celldate.tm_year+1900);
|
cell->date.tm_year+1900);
|
||||||
|
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
@ -88,8 +87,12 @@ celldate.tm_year+1900);
|
|||||||
/* ================================================ */
|
/* ================================================ */
|
||||||
|
|
||||||
static const char *
|
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;
|
int accel=0;
|
||||||
short day, month, year;
|
short day, month, year;
|
||||||
char * datestr;
|
char * datestr;
|
||||||
|
@ -71,7 +71,7 @@ void xaccInitBasicRegister (BasicRegister *reg)
|
|||||||
header = xaccMallocCellBlock (1, MAX_COLS);
|
header = xaccMallocCellBlock (1, MAX_COLS);
|
||||||
reg->header = header;
|
reg->header = header;
|
||||||
|
|
||||||
cell = xaccMallocDateCell();
|
cell = (SingleCell *) xaccMallocDateCell();
|
||||||
cell->width = 9;
|
cell->width = 9;
|
||||||
xaccAddCell (header, cell, 0, DATE_CELL_C);
|
xaccAddCell (header, cell, 0, DATE_CELL_C);
|
||||||
xaccSetSingleCellValue (cell, "Date");
|
xaccSetSingleCellValue (cell, "Date");
|
||||||
@ -106,7 +106,7 @@ void xaccInitBasicRegister (BasicRegister *reg)
|
|||||||
curs = xaccMallocCellBlock (2, MAX_COLS);
|
curs = xaccMallocCellBlock (2, MAX_COLS);
|
||||||
reg->cursor = curs;
|
reg->cursor = curs;
|
||||||
|
|
||||||
cell = xaccMallocDateCell();
|
cell = (SingleCell *) xaccMallocDateCell();
|
||||||
cell->width = 9;
|
cell->width = 9;
|
||||||
xaccAddCell (curs, cell, DATE_CELL_R, DATE_CELL_C);
|
xaccAddCell (curs, cell, DATE_CELL_R, DATE_CELL_C);
|
||||||
reg->dateCell = cell;
|
reg->dateCell = cell;
|
||||||
|
@ -11,26 +11,29 @@
|
|||||||
* decimal point in them */
|
* decimal point in them */
|
||||||
|
|
||||||
static const char *
|
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) {
|
||||||
/* if change is a decimal point, then count decimal points */
|
/* if change is a decimal point, then count decimal points */
|
||||||
if (DECIMAL_PT == change[0]) {
|
if (DECIMAL_PT == change[0]) {
|
||||||
int i, count=0;
|
int i, count=0;
|
||||||
for (i=0; 0 != new[i]; i++) {
|
for (i=0; 0 != newval[i]; i++) {
|
||||||
if (DECIMAL_PT == new[i]) count ++;
|
if (DECIMAL_PT == newval[i]) count ++;
|
||||||
}
|
}
|
||||||
if (1 >= count) return new;
|
if (1 >= count) return newval;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* accept numeric, reject non-alpha edits */
|
/* accept numeric, reject non-alpha edits */
|
||||||
if (isdigit (change[0])) return new;
|
if (isdigit (change[0])) return newval;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* accept the new string if user action was delete, etc. */
|
/* accept the newval string if user action was delete, etc. */
|
||||||
return new;
|
return newval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
/* ================================================ */
|
/* ================================================ */
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
ToggleRecn (const char *cur_val)
|
ToggleRecn (struct _SingleCell *_cell, const char *cur_val)
|
||||||
{
|
{
|
||||||
char buff[2];
|
char buff[2];
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ enterCB (Widget mw, XtPointer cd, XtPointer cb)
|
|||||||
XbaeMatrixEnterCellCallbackStruct *cbs;
|
XbaeMatrixEnterCellCallbackStruct *cbs;
|
||||||
int row, col;
|
int row, col;
|
||||||
int rel_row, rel_col;
|
int rel_row, rel_col;
|
||||||
const char * (*enter) (const char *);
|
const char * (*enter) (struct _SingleCell *, const char *);
|
||||||
|
|
||||||
table = (Table *) cd;
|
table = (Table *) cd;
|
||||||
arr = table->cursor;
|
arr = table->cursor;
|
||||||
@ -266,7 +266,7 @@ enterCB (Widget mw, XtPointer cd, XtPointer cb)
|
|||||||
const char *val, *retval;
|
const char *val, *retval;
|
||||||
|
|
||||||
val = table->entries[row][col];
|
val = table->entries[row][col];
|
||||||
retval = enter (val);
|
retval = enter (arr->cells[rel_row][rel_col], val);
|
||||||
if (val != retval) {
|
if (val != retval) {
|
||||||
if (table->entries[row][col]) free (table->entries[row][col]);
|
if (table->entries[row][col]) free (table->entries[row][col]);
|
||||||
table->entries[row][col] = (char *) retval;
|
table->entries[row][col] = (char *) retval;
|
||||||
@ -291,7 +291,10 @@ modifyCB (Widget mw, XtPointer cd, XtPointer cb)
|
|||||||
XbaeMatrixModifyVerifyCallbackStruct *cbs;
|
XbaeMatrixModifyVerifyCallbackStruct *cbs;
|
||||||
int row, col;
|
int row, col;
|
||||||
int rel_row, rel_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;
|
const char *oldval, *change;
|
||||||
char *newval;
|
char *newval;
|
||||||
const char *retval;
|
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 */
|
/* OK, if there is a callback for this cell, call it */
|
||||||
mv = arr->cells[rel_row][rel_col]->modify_verify;
|
mv = arr->cells[rel_row][rel_col]->modify_verify;
|
||||||
if (mv) {
|
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 the callback returned a non-null value, allow the edit */
|
||||||
if (retval) {
|
if (retval) {
|
||||||
@ -381,7 +384,7 @@ leaveCB (Widget mw, XtPointer cd, XtPointer cb)
|
|||||||
XbaeMatrixLeaveCellCallbackStruct *cbs;
|
XbaeMatrixLeaveCellCallbackStruct *cbs;
|
||||||
int row, col;
|
int row, col;
|
||||||
int rel_row, rel_col;
|
int rel_row, rel_col;
|
||||||
const char * (*leave) (const char *);
|
const char * (*leave) (struct _SingleCell *, const char *);
|
||||||
|
|
||||||
table = (Table *) cd;
|
table = (Table *) cd;
|
||||||
arr = table->cursor;
|
arr = table->cursor;
|
||||||
@ -406,7 +409,7 @@ leaveCB (Widget mw, XtPointer cd, XtPointer cb)
|
|||||||
const char *val, *retval;
|
const char *val, *retval;
|
||||||
|
|
||||||
val = cbs->value;
|
val = cbs->value;
|
||||||
retval = leave (val);
|
retval = leave (arr->cells[rel_row][rel_col], val);
|
||||||
|
|
||||||
if (NULL == retval) retval = "";
|
if (NULL == retval) retval = "";
|
||||||
|
|
||||||
|
@ -9,9 +9,12 @@
|
|||||||
* all modifications */
|
* all modifications */
|
||||||
|
|
||||||
static const char *
|
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