diff --git a/src/register/basiccell.c b/src/register/basiccell.c index b035621468..6a2ffa1ea2 100644 --- a/src/register/basiccell.c +++ b/src/register/basiccell.c @@ -1,5 +1,6 @@ #include +#include #include "single.h" @@ -20,6 +21,16 @@ void xaccInitSingleCell (SingleCell *cell) cell->alignment = 0; cell->value = 0x0; cell->modify_verify = NULL; + cell->extdata = NULL; + cell->block = NULL; +} + +void xaccSetSingleCellValue (SingleCell *cell, char *val) +{ + + if (cell->value) free (cell->value); + cell->value = strdup (val); + } /* ------------------ end of file ---------------------- */ diff --git a/src/register/basiccell.h b/src/register/basiccell.h index 894cc1d0a9..097ee3795c 100644 --- a/src/register/basiccell.h +++ b/src/register/basiccell.h @@ -43,6 +43,7 @@ typedef struct _SingleCell { short width; /* column width, in chars, not pixels */ short alignment; /* column text alignment */ + /* private data */ char * value; /* current value */ const char * (*modify_verify) (const char *old, @@ -50,11 +51,15 @@ typedef struct _SingleCell { const char *new); + struct _CellBlock *block; /* back-pointer to parent container */ + void * extdata; /* generic extension mechanism */ } SingleCell; SingleCell * xaccMallocSingleCell (void); void xaccInitSingleCell (SingleCell *); +void xaccSetSingleCellValue (SingleCell *, char *); + #endif /* __XACC_SINGLE_H__ */ /* ------------------ end of file ---------------------- */ diff --git a/src/register/cellblock.c b/src/register/cellblock.c index 635f9034cf..c8619ae80b 100644 --- a/src/register/cellblock.c +++ b/src/register/cellblock.c @@ -59,23 +59,24 @@ xaccInitCellBlock (CellBlock *arr, int numrows, int numcols) /* =================================================== */ void -xaccAddCell (CellBlock *arr, SingleCell *cell) +xaccAddCell (CellBlock *arr, SingleCell *cell, int row, int col) { - int i,j; - if (!arr) return; if (!cell) return; - i = cell->row; - j = cell->col; + cell->row = row; + cell->col = col; /* avoid embarrasement if cell incorrectly specified */ - if ((0 > i) || (0 > j)) return; - if ((i >= arr->numRows) || (j >= arr->numCols)) return; + if ((0 > row) || (0 > col)) return; + if ((row >= arr->numRows) || (col >= arr->numCols)) return; - arr->cells[i][j] = cell; - arr->widths[j] = cell->width; - arr->alignments[j] = cell->alignment; + arr->cells[row][col] = cell; + arr->widths[col] = cell->width; + arr->alignments[col] = cell->alignment; + + /* install back-pointer to this container */ + cell->block = (struct _CellBlock *) arr; } /* --------------- end of file ----------------- */ diff --git a/src/register/cellblock.h b/src/register/cellblock.h index 43bb96684c..fce3393914 100644 --- a/src/register/cellblock.h +++ b/src/register/cellblock.h @@ -17,6 +17,7 @@ typedef struct _CellBlock { short *widths; /* column widths */ unsigned char *alignments; /* column text alignments */ + struct _Table *table; /* back-pointer to table */ } CellBlock; @@ -24,6 +25,6 @@ CellBlock * xaccMallocCellBlock (int numrows, int numcols); void xaccInitCellBlock (CellBlock *, int numrows, int numcols); /* add a cell to the array */ -void xaccAddCell (CellBlock *, SingleCell *); +void xaccAddCell (CellBlock *, SingleCell *, int row, int col); #endif __XACC_CELL_H__ diff --git a/src/register/main.c b/src/register/main.c index 6054c94d8b..9063a50b49 100644 --- a/src/register/main.c +++ b/src/register/main.c @@ -20,49 +20,52 @@ CreateReg(Widget parent ) { CellBlock *curs, *header; SingleCell *cell; - curs = xaccMallocCellBlock (2, 10); header = xaccMallocCellBlock (1, 10); - cell = xaccMallocPriceCell(); - cell->row = 0; - cell->col = 3; + cell = xaccMallocDateCell(); cell->width = 9; - xaccAddCell (header, cell); + xaccAddCell (header, cell, 0, 0); cell = xaccMallocPriceCell(); - cell->row = 0; - cell->col = 4; cell->width = 9; - xaccAddCell (header, cell); + xaccAddCell (header, cell, 0, 3); cell = xaccMallocPriceCell(); - cell->row = 0; - cell->col = 4; cell->width = 9; - xaccAddCell (curs, cell); + xaccAddCell (header, cell, 0, 4); + + cell = xaccMallocTextCell(); + cell->width = 9; + xaccAddCell (header, cell, DESC_CELL_R, DESC_CELL_C); + + /* --------------------------- */ + curs = xaccMallocCellBlock (2, 10); cell = xaccMallocDateCell(); - cell->row = 0; - cell->col = 0; cell->width = 9; - xaccAddCell (curs, cell); + xaccAddCell (curs, cell, 0, 0); cell = xaccMallocTextCell(); - cell->row = DESC_CELL_R; - cell->col = DESC_CELL_C; cell->width = 9; - xaccAddCell (curs, cell); + xaccAddCell (curs, cell, DESC_CELL_R, DESC_CELL_C); cell = xaccMallocTextCell(); - cell->row = MEMO_CELL_R; - cell->col = MEMO_CELL_C; cell->width = 9; - xaccAddCell (curs, cell); + xaccAddCell (curs, cell, MEMO_CELL_R, MEMO_CELL_C); + + cell = xaccMallocPriceCell(); + cell->width = 9; + xaccAddCell (curs, cell, 0, 3); + + cell = xaccMallocPriceCell(); + cell->width = 9; + xaccAddCell (curs, cell, 0, 4); + table = xaccMallocTable (0, 0); - table -> cursor = curs; table -> header = header; + xaccSetCursor (table, curs); xaccInitTable (table, 15, 1); xaccCreateTable (table, parent, "yodudue"); diff --git a/src/register/table.c b/src/register/table.c index a0613d6865..a0442bb6df 100644 --- a/src/register/table.c +++ b/src/register/table.c @@ -75,6 +75,23 @@ xaccInitTable (Table * table, int tile_rows, int tile_cols) } } +/* ==================================================== */ + +void +xaccSetCursor (Table *table, CellBlock *curs) +{ + table->cursor = curs; + + /* set back-pointer to table */ + curs->table = (struct _Table *) table; +} + +/* ==================================================== */ + +void xaccSetTableValue (Table *table, char * val) +{ +} + /* ==================================================== */ /* hack alert -- will core dump if numrows has changed, etc. */ diff --git a/src/register/table.h b/src/register/table.h index b341204b37..53301804e1 100644 --- a/src/register/table.h +++ b/src/register/table.h @@ -50,5 +50,7 @@ void xaccRefreshTable (Table *); /* add a cell to the array */ void xaccSetCursor (Table *, CellBlock *); +void xaccSetTableValue (Table *, char *); + #endif __XACC_TABLE_H__ /* ================== end of file ======================= */