add ability to set table values with cursor,

more fleshing out of register


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@433 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-01-15 09:53:08 +00:00
parent d50d3f9191
commit c90abaebff
6 changed files with 148 additions and 24 deletions

View File

@ -17,7 +17,6 @@ typedef struct _CellBlock {
short *widths; /* column widths */
unsigned char *alignments; /* column text alignments */
struct _Table *table; /* back-pointer to table */
} CellBlock;

View File

@ -6,12 +6,48 @@
#include "FileIO.h"
#include "register.h"
#define BUFSIZE 1024
void
xaccLoadRegister (BasicRegister *reg, Account *acc)
xaccLoadRegister (BasicRegister *reg, Split **slist)
{
int i;
Split *split;
Transaction *trans;
char buff[BUFSIZE];
printf ("its %s \n", acc->accountName);
i=0;
split = slist[0];
while (split) {
trans = (Transaction *) (split->parent);
xaccMoveCursor (reg->table, i, 0);
sprintf (buff, "%2d/%2d/%4d", trans->date.day,
trans->date.month,
trans->date.year);
xaccSetBasicCellValue (reg->dateCell, buff);
xaccSetBasicCellValue (reg->numCell, trans->num);
xaccSetBasicCellValue (reg->descCell, trans->description);
xaccSetBasicCellValue (reg->memoCell, split->memo);
buff[0] = split->reconciled;
buff[1] = 0x0;
xaccSetBasicCellValue (reg->recnCell, buff);
xaccCommitEdits (reg->table);
/*
reg->PriceCell
*/
i++;
split = slist[i];
}
/*
xaccRefreshTable (reg->table);
*/
}
/* ================================= */
@ -42,7 +78,7 @@ main (int argc, char *argv[]) {
reg = xaccMallocBasicRegister ();
xaccLoadRegister (reg, grp->account[0]);
xaccLoadRegister (reg, grp->account[0]->splits);
xaccCreateTable (reg->table, actionform, "yodudue");

View File

@ -8,25 +8,34 @@
#define DATE_CELL_C 0
#define DATE_CELL_R 0
#define DESC_CELL_C 2
#define NUM_CELL_C 1
#define NUM_CELL_R 0
#define XFRM_CELL_C 2
#define XFRM_CELL_R 0
#define XTO_CELL_C 2
#define XTO_CELL_R 1
#define DESC_CELL_C 3
#define DESC_CELL_R 0
#define MEMO_CELL_C 2
#define MEMO_CELL_C 3
#define MEMO_CELL_R 1
#define RECN_CELL_C 3
#define RECN_CELL_C 4
#define RECN_CELL_R 0
#define CRED_CELL_C 4
#define CRED_CELL_C 5
#define CRED_CELL_R 0
#define DEBT_CELL_C 5
#define DEBT_CELL_C 6
#define DEBT_CELL_R 0
#define BALN_CELL_C 6
#define BALN_CELL_C 7
#define BALN_CELL_R 0
#define MAX_COLS 7
#define MAX_COLS 8
/* ================================= */
@ -57,7 +66,12 @@ void xaccInitBasicRegister (BasicRegister *reg)
xaccSetBasicCellValue (cell, "Date");
cell = xaccMallocTextCell();
cell->width = 19;
cell->width = 7;
xaccAddCell (header, cell, 0, NUM_CELL_C);
xaccSetBasicCellValue (cell, "Num");
cell = xaccMallocTextCell();
cell->width = 29;
xaccAddCell (header, cell, 0, DESC_CELL_C);
xaccSetBasicCellValue (cell, "Description");
@ -91,6 +105,16 @@ void xaccInitBasicRegister (BasicRegister *reg)
xaccAddCell (curs, cell, DATE_CELL_R, DATE_CELL_C);
reg->dateCell = cell;
cell = xaccMallocTextCell();
cell->width = 7;
xaccAddCell (curs, cell, NUM_CELL_R, NUM_CELL_C);
reg->numCell = cell;
cell = xaccMallocTextCell();
cell->width = 11;
xaccAddCell (curs, cell, XFRM_CELL_R, XFRM_CELL_C);
reg->xferCell = cell;
cell = xaccMallocTextCell();
cell->width = 9;
xaccAddCell (curs, cell, DESC_CELL_R, DESC_CELL_C);
@ -104,7 +128,7 @@ void xaccInitBasicRegister (BasicRegister *reg)
cell = xaccMallocRecnCell();
cell->width = 1;
xaccAddCell (curs, cell, RECN_CELL_R, RECN_CELL_C);
reg->memoCell = cell;
reg->recnCell = cell;
reg->creditCell = xaccMallocPriceCell();
reg->creditCell->cell.width = 9;
@ -114,6 +138,10 @@ void xaccInitBasicRegister (BasicRegister *reg)
reg->debitCell->cell.width = 9;
xaccAddCell (curs, &(reg->debitCell->cell), DEBT_CELL_R, DEBT_CELL_C);
reg->balanceCell = xaccMallocPriceCell();
reg->balanceCell->cell.width = 9;
xaccAddCell (curs, &(reg->balanceCell->cell), BALN_CELL_R, BALN_CELL_C);
table = xaccMallocTable (0, 0);
table -> header = header;
xaccSetCursor (table, curs);

View File

@ -18,11 +18,14 @@ typedef struct _BasicRegister {
CellBlock * cursor;
CellBlock * header;
BasicCell * dateCell;
BasicCell * numCell;
BasicCell * xferCell;
BasicCell * descCell;
BasicCell * memoCell;
BasicCell * recnCell;
PriceCell * creditCell;
PriceCell * debitCell;
PriceCell * balanceCell;
} BasicRegister;

View File

@ -56,16 +56,26 @@ xaccInitTable (Table * table, int tile_rows, int tile_cols)
num_header_rows = table->header->numRows;
num_phys_rows += table->header->numRows;
}
table->tile_height = 0;
table->tile_width = 0;
if (table->cursor) {
table->tile_height = table->cursor->numRows;
table->tile_width = table->cursor->numCols;
num_phys_rows += tile_rows * table->cursor->numRows;
num_phys_cols = tile_cols * table->cursor->numCols;
}
table->num_phys_rows = num_phys_rows;
table->num_phys_cols = num_phys_cols;
table->num_header_rows = num_header_rows;
table->num_tile_rows = tile_rows;
table->num_tile_cols = tile_cols;
table->num_rows = tile_rows;
table->num_cols = tile_cols;
/* set the cursor location */
table->current_cursor_row = 0;
table->current_cursor_col = 0;
/* create an empty table */
if (0 == num_phys_rows) {
@ -91,15 +101,42 @@ 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)
void xaccMoveCursor (Table *table, int virt_row, int virt_col)
{
if ((0 > virt_row) || (0 > virt_col)) return;
if (virt_row >= table->num_rows) return;
if (virt_col >= table->num_cols) return;
table->current_cursor_row = virt_row;
table->current_cursor_col = virt_col;
}
/* ==================================================== */
void xaccCommitEdits (Table *table)
{
int i,j;
int iphys,jphys;
BasicCell *cell;
for (i=0; i<table->tile_height; i++) {
iphys = i + table->current_cursor_row * table->tile_height;
iphys += table->num_header_rows;
for (j=0; j<table->tile_width; j++) {
cell = table->cursor->cells[i][j];
if (cell) {
jphys = j + table->current_cursor_col * table->tile_width;
if (table->entries[iphys][jphys]) {
free (table->entries[iphys][jphys]);
}
table->entries[iphys][jphys] = strdup (cell->value);
}
}
}
}
/* ==================================================== */
@ -469,7 +506,9 @@ xaccCreateTable (Table *table, Widget parent, char * name)
if (!table) return 0;
/* make sure that the table is consistent */
xaccInitTable (table, table->num_tile_rows, table->num_tile_cols);
/* hack alert -- remove for now, since may be inited?
xaccInitTable (table, table->num_rows, table->num_cols);
*/
/* if a header exists, get alignments, widths from there */
alignments = NULL;

View File

@ -13,17 +13,32 @@
typedef struct _Table {
int num_tile_rows;
int num_tile_cols;
/* num rows and cols are the number of times the
* cursor can tile the table in the vertical and
* horizontal directions */
int num_rows;
int num_cols;
CellBlock *header;
CellBlock *cursor;
int current_cursor_row;
int current_cursor_col;
char ***entries;
/* protected data -- vital for the implementation,
* but not something we want to generally expose */
Widget reg; /* the XbaeMatrix */
/* private data, caches, etc. */
/* This is black-box stuff that no user of this class
* should ever want to access */
/* the "tile size" is the number of rows &
* cols in the cursor */
int tile_width;
int tile_height;
/* the "physical" rows/cols are equal to
* the size of the tile times the number
@ -47,10 +62,14 @@ void xaccDestroyTable (Table *);
/* redraw the table */
void xaccRefreshTable (Table *);
/* add a cell to the array */
/* Make the indicated cell block be the cursor for this table */
void xaccSetCursor (Table *, CellBlock *);
void xaccSetTableValue (Table *, char *);
/* move the cursor to the indicated location. */
void xaccMoveCursor (Table *, int virt_row, int virt_col);
/* copy text in the cursor cells to the table */
void xaccCommitEdits (Table *);
#endif __XACC_TABLE_H__
/* ================== end of file ======================= */