From 7002e07cdae9c2383a8b44092dcc110df19e3759 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 17 Mar 1998 06:03:33 +0000 Subject: [PATCH] whoa, I think this may finally be the design we are looking for git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@650 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/table-allgui.c | 72 +++++++++++++++++++++++++------------ src/register/table-allgui.h | 9 ++--- src/register/table-motif.h | 44 +++++++++++++++++------ 3 files changed, 85 insertions(+), 40 deletions(-) diff --git a/src/register/table-allgui.c b/src/register/table-allgui.c index ce8492527f..6df8e7965d 100644 --- a/src/register/table-allgui.c +++ b/src/register/table-allgui.c @@ -30,6 +30,7 @@ #include "cellblock.h" #include "table-allgui.h" + /* ==================================================== */ /* in C, we don't have templates. So cook up a $define that acts like a * template. This one will resize a 2D array. @@ -44,9 +45,6 @@ old_rows = table_rows; \ old_cols = table_cols; \ \ - table_rows = new_rows; \ - table_cols = new_cols; \ - \ /* realloc to get the new table size. Note that the */ \ /* new table may be wider or slimmer, taller or shorter. */ \ if (old_rows >= new_rows) { \ @@ -139,9 +137,28 @@ /* ==================================================== */ -void -xaccTableResizeStringArr (Table * table, int new_phys_rows, int new_phys_cols) +static Locator * +xaccMallocLocator (void) { + Locator *loc; + loc = (Locator *) malloc (sizeof (Locator)); + loc->phys_row_offset = -1; + loc->phys_col_offset = -1; + loc->virt_row = -1; + loc->virt_col = -1; + + return (loc); +} + +/* ==================================================== */ + +void +xaccTableResize (Table * table, + int new_phys_rows, int new_phys_cols, + int new_virt_rows, int new_virt_cols) +{ + + /* resize the string data array */ RESIZE_ARR ((table->num_phys_rows), (table->num_phys_cols), new_phys_rows, @@ -149,13 +166,23 @@ xaccTableResizeStringArr (Table * table, int new_phys_rows, int new_phys_cols) (table->entries), char, (strdup (""))); -} -/* ==================================================== */ + /* resize the locator array */ + RESIZE_ARR ((table->num_phys_rows), + (table->num_phys_cols), + new_phys_rows, + new_phys_cols, + (table->locators), + Locator, + (xaccMallocLocator ())); -void -xaccTableResizeUserData (Table * table, int new_virt_rows, int new_virt_cols) -{ + /* we are done with the physical dimensions. + * record them for posterity. */ + table->num_phys_rows = new_phys_rows; + table->num_phys_cols = new_phys_cols; + + + /* resize the user-data hooks */ RESIZE_ARR ((table->num_virt_rows), (table->num_virt_cols), new_virt_rows, @@ -163,22 +190,21 @@ xaccTableResizeUserData (Table * table, int new_virt_rows, int new_virt_cols) (table->user_data), void, (NULL)); -} -/* ==================================================== */ + /* resize the handler array */ + RESIZE_ARR ((table->num_virt_rows), + (table->num_virt_cols), + new_virt_rows, + new_virt_cols, + (table->handlers), + CellBlock, + (NULL)); -void -xaccTableCount (Table *table, CellBlock *curse) -{ - if (!table) return; - if (!curse) return; - - /* increment rows */ - table->cnt_phys_rows += curse->numRows; - table->cnt_virt_rows ++; + /* we are done with the virtual dimensions. + * record them for posterity. */ + table->num_virt_rows = new_virt_rows; + table->num_virt_cols = new_virt_cols; - /* copy columns */ - table->cnt_phys_cols = curse->numCols; } /* ==================================================== */ diff --git a/src/register/table-allgui.h b/src/register/table-allgui.h index c0b1914407..c817fbaabd 100644 --- a/src/register/table-allgui.h +++ b/src/register/table-allgui.h @@ -42,17 +42,12 @@ #endif extern void -xaccTableResizeStringArr (Table * table, int num_phys_rows, int num_phys_cols); - -extern void -xaccTableResizeUserData (Table * table, int new_virt_rows, int new_virt_cols); +xaccTableResize (Table * table, int num_phys_rows, int num_phys_cols, + int new_virt_rows, int new_virt_cols); extern void xaccAddCursor (Table *table, CellBlock *curs); -/* count the number of phys rows we'll need, in prep for the malloc */ -extern void -xaccTableCount (Table *table, CellBlock *curs); #endif /* __XACC_TABLE_ALLGUI_H__ */ diff --git a/src/register/table-motif.h b/src/register/table-motif.h index c7497d1559..287abd36a9 100644 --- a/src/register/table-motif.h +++ b/src/register/table-motif.h @@ -37,6 +37,27 @@ #include "basiccell.h" #include "cellblock.h" +/* the Locator structure is used provide a mapping from + * the physical array of cells to the logical array of + * virtual cell blocks. + * + * There is one instance of Locator for each physical cell. + * The virt_row and virt_col members identify the corresponding + * cellblock/virtual cell that this physical cell is a member of. + * The two phys_offsets provide the location of the physical cell + * as an offset from the cell block origin. That is, the offsets + * should never be less than zero, or greater than the size of + * the cell block. + */ +struct _Locator { + short phys_row_offset; + short phys_col_offset; + short virt_row; + short virt_col; +}; + +typedef struct _Locator Locator; + typedef struct _Table { /* The number of "physical" rows/cols is the number @@ -66,13 +87,15 @@ typedef struct _Table { * of dimension num_phys_rows * num_phys_cols */ char ***entries; - /* user hooks, of dimension num_rows * num_cols */ + /* handler locators for each cell, + * of dimension num_phys_rows * num_phys_cols */ + Locator ***locators; + + /* user hooks, of dimension num_virt_rows * num_virt_cols */ void ***user_data; - /* protected data -- vital for the implementation, - * but not something we want to generally expose */ - Widget table_widget; /* the XbaeMatrix */ - Widget next_tab_group; /* where to traverse in the end */ + /* cell blocks, of dimension num_virt_rows * num_virt_cols */ + CellBlock ***handlers; /* private data, caches, etc. */ /* This is black-box stuff that no user of this class @@ -87,11 +110,12 @@ typedef struct _Table { int prev_phys_traverse_row; int prev_phys_traverse_col; - /* temporary counters */ - int cnt_phys_rows; - int cnt_phys_cols; - int cnt_virt_rows; - int cnt_virt_cols; + /* Motif-only date below, gui-independent data above */ + + /* protected data -- vital for the implementation, + * but not something we want to generally expose */ + Widget table_widget; /* the XbaeMatrix */ + Widget next_tab_group; /* where to traverse in the end */ } Table;