assorted infrastructure

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@409 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-01-11 20:24:13 +00:00
parent 6ef3b1590d
commit a8c3d2c0c9
7 changed files with 72 additions and 32 deletions

View File

@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "single.h" #include "single.h"
@ -20,6 +21,16 @@ void xaccInitSingleCell (SingleCell *cell)
cell->alignment = 0; cell->alignment = 0;
cell->value = 0x0; cell->value = 0x0;
cell->modify_verify = NULL; 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 ---------------------- */ /* ------------------ end of file ---------------------- */

View File

@ -43,6 +43,7 @@ typedef struct _SingleCell {
short width; /* column width, in chars, not pixels */ short width; /* column width, in chars, not pixels */
short alignment; /* column text alignment */ short alignment; /* column text alignment */
/* private data */
char * value; /* current value */ char * value; /* current value */
const char * (*modify_verify) (const char *old, const char * (*modify_verify) (const char *old,
@ -50,11 +51,15 @@ typedef struct _SingleCell {
const char *new); const char *new);
struct _CellBlock *block; /* back-pointer to parent container */
void * extdata; /* generic extension mechanism */
} SingleCell; } SingleCell;
SingleCell * xaccMallocSingleCell (void); SingleCell * xaccMallocSingleCell (void);
void xaccInitSingleCell (SingleCell *); void xaccInitSingleCell (SingleCell *);
void xaccSetSingleCellValue (SingleCell *, char *);
#endif /* __XACC_SINGLE_H__ */ #endif /* __XACC_SINGLE_H__ */
/* ------------------ end of file ---------------------- */ /* ------------------ end of file ---------------------- */

View File

@ -59,23 +59,24 @@ xaccInitCellBlock (CellBlock *arr, int numrows, int numcols)
/* =================================================== */ /* =================================================== */
void void
xaccAddCell (CellBlock *arr, SingleCell *cell) xaccAddCell (CellBlock *arr, SingleCell *cell, int row, int col)
{ {
int i,j;
if (!arr) return; if (!arr) return;
if (!cell) return; if (!cell) return;
i = cell->row; cell->row = row;
j = cell->col; cell->col = col;
/* avoid embarrasement if cell incorrectly specified */ /* avoid embarrasement if cell incorrectly specified */
if ((0 > i) || (0 > j)) return; if ((0 > row) || (0 > col)) return;
if ((i >= arr->numRows) || (j >= arr->numCols)) return; if ((row >= arr->numRows) || (col >= arr->numCols)) return;
arr->cells[i][j] = cell; arr->cells[row][col] = cell;
arr->widths[j] = cell->width; arr->widths[col] = cell->width;
arr->alignments[j] = cell->alignment; arr->alignments[col] = cell->alignment;
/* install back-pointer to this container */
cell->block = (struct _CellBlock *) arr;
} }
/* --------------- end of file ----------------- */ /* --------------- end of file ----------------- */

View File

@ -17,6 +17,7 @@ typedef struct _CellBlock {
short *widths; /* column widths */ short *widths; /* column widths */
unsigned char *alignments; /* column text alignments */ unsigned char *alignments; /* column text alignments */
struct _Table *table; /* back-pointer to table */
} CellBlock; } CellBlock;
@ -24,6 +25,6 @@ CellBlock * xaccMallocCellBlock (int numrows, int numcols);
void xaccInitCellBlock (CellBlock *, int numrows, int numcols); void xaccInitCellBlock (CellBlock *, int numrows, int numcols);
/* add a cell to the array */ /* add a cell to the array */
void xaccAddCell (CellBlock *, SingleCell *); void xaccAddCell (CellBlock *, SingleCell *, int row, int col);
#endif __XACC_CELL_H__ #endif __XACC_CELL_H__

View File

@ -20,49 +20,52 @@ CreateReg(Widget parent ) {
CellBlock *curs, *header; CellBlock *curs, *header;
SingleCell *cell; SingleCell *cell;
curs = xaccMallocCellBlock (2, 10);
header = xaccMallocCellBlock (1, 10); header = xaccMallocCellBlock (1, 10);
cell = xaccMallocPriceCell(); cell = xaccMallocDateCell();
cell->row = 0;
cell->col = 3;
cell->width = 9; cell->width = 9;
xaccAddCell (header, cell); xaccAddCell (header, cell, 0, 0);
cell = xaccMallocPriceCell(); cell = xaccMallocPriceCell();
cell->row = 0;
cell->col = 4;
cell->width = 9; cell->width = 9;
xaccAddCell (header, cell); xaccAddCell (header, cell, 0, 3);
cell = xaccMallocPriceCell(); cell = xaccMallocPriceCell();
cell->row = 0;
cell->col = 4;
cell->width = 9; 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 = xaccMallocDateCell();
cell->row = 0;
cell->col = 0;
cell->width = 9; cell->width = 9;
xaccAddCell (curs, cell); xaccAddCell (curs, cell, 0, 0);
cell = xaccMallocTextCell(); cell = xaccMallocTextCell();
cell->row = DESC_CELL_R;
cell->col = DESC_CELL_C;
cell->width = 9; cell->width = 9;
xaccAddCell (curs, cell); xaccAddCell (curs, cell, DESC_CELL_R, DESC_CELL_C);
cell = xaccMallocTextCell(); cell = xaccMallocTextCell();
cell->row = MEMO_CELL_R;
cell->col = MEMO_CELL_C;
cell->width = 9; 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 = xaccMallocTable (0, 0);
table -> cursor = curs;
table -> header = header; table -> header = header;
xaccSetCursor (table, curs);
xaccInitTable (table, 15, 1); xaccInitTable (table, 15, 1);
xaccCreateTable (table, parent, "yodudue"); xaccCreateTable (table, parent, "yodudue");

View File

@ -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. */ /* hack alert -- will core dump if numrows has changed, etc. */

View File

@ -50,5 +50,7 @@ void xaccRefreshTable (Table *);
/* add a cell to the array */ /* add a cell to the array */
void xaccSetCursor (Table *, CellBlock *); void xaccSetCursor (Table *, CellBlock *);
void xaccSetTableValue (Table *, char *);
#endif __XACC_TABLE_H__ #endif __XACC_TABLE_H__
/* ================== end of file ======================= */ /* ================== end of file ======================= */