implement traversal, at least as first draft.

Somehow, still can't traverse out of the tab group.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@444 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-01-26 10:06:25 +00:00
parent c0388c9881
commit a98324f751
5 changed files with 165 additions and 19 deletions

View File

@ -8,7 +8,12 @@ CellBlock * xaccMallocCellBlock (int numrows, int numcols)
CellBlock *arr;
arr = (CellBlock *) malloc (sizeof (CellBlock));
arr->numRows = 0;
arr->numCols = 0;
arr->cells = NULL;
arr->right_traverse_r = NULL;
arr->right_traverse_c = NULL;
arr->widths = NULL;
arr->alignments = NULL;
xaccInitCellBlock (arr, numrows, numcols);
@ -21,38 +26,77 @@ CellBlock * xaccMallocCellBlock (int numrows, int numcols)
void
xaccInitCellBlock (CellBlock *arr, int numrows, int numcols)
{
int i;
int i, j;
int oldrows, oldcols;
if (!arr) return;
arr->numRows = numrows;
arr->numCols = numcols;
oldrows = arr->numRows;
oldcols = arr->numCols;
/* free old cell array, if any */
if (arr->cells) {
for (i=0; i<numrows; i++) {
for (i=0; i<oldrows; i++) {
if (arr->cells[i]) free (arr->cells[i]);
}
free (arr->cells);
}
/* malloc new cell array */
/* free old traversal chain */
if (arr->right_traverse_r) {
for (i=0; i<oldrows; i++) {
if (arr->right_traverse_r[i]) free (arr->right_traverse_r[i]);
}
}
if (arr->right_traverse_c) {
for (i=0; i<oldrows; i++) {
if (arr->right_traverse_c[i]) free (arr->right_traverse_c[i]);
}
}
/* free old widths, alignments */
if (arr->widths) free (arr->widths);
if (arr->alignments) free (arr->alignments);
/* -------------------------------------------------- */
/* record new size */
arr->numRows = numrows;
arr->numCols = numcols;
/* malloc new cell array */
arr->cells = (BasicCell ***) malloc (numrows * sizeof (BasicCell **));
for (i=0; i<numrows; i++) {
(arr->cells)[i] = (BasicCell **) malloc (numcols * sizeof (BasicCell *));
for (j=0; j<numcols; j++) {
(arr->cells)[i][j] = NULL;
}
}
/* free old widths, alignments */
if (arr->widths) free (arr->widths);
if (arr->alignments) free (arr->alignments);
/* malloc new traversal arrays */
arr->right_traverse_r = (short **) malloc (numrows * sizeof (short *));
arr->right_traverse_c = (short **) malloc (numrows * sizeof (short *));
for (i=0; i<numrows; i++) {
(arr->right_traverse_r)[i] = (short *) malloc (numcols * sizeof (short));
(arr->right_traverse_c)[i] = (short *) malloc (numcols * sizeof (short));
for (j=0; j<numcols-1; j++) {
/* default traversal is same row, next column */
(arr->right_traverse_r)[i][j] = i;
(arr->right_traverse_c)[i][j] = j+1;
}
/* at end of row, wrap to next row */
(arr->right_traverse_r)[i][numcols-1] = i+1;
(arr->right_traverse_c)[i][numcols-1] = 0;
}
/* at end of block, wrap back to begining */
(arr->right_traverse_r)[numrows-1][numcols-1] = 0;
(arr->right_traverse_c)[numrows-1][numcols-1] = 0;
arr->widths = (short *) malloc (numcols * sizeof(short));
arr->alignments = (unsigned char *) malloc (numcols * sizeof(unsigned char));
for (i=0; i<numcols; i++) {
arr->widths[i] = 0;
arr->alignments[i] = 0;
for (j=0; j<numcols; j++) {
arr->widths[j] = 0;
arr->alignments[j] = 0;
}
}
@ -76,4 +120,27 @@ xaccAddCell (CellBlock *arr, BasicCell *cell, int row, int col)
cell->block = (struct _CellBlock *) arr;
}
/* =================================================== */
void
xaccNextRight (CellBlock *arr, int row, int col,
int next_row, int next_col)
{
if (!arr) return;
/* avoid embarrasement if cell incorrectly specified */
if ((0 > row) || (0 > col)) return;
if ((row >= arr->numRows) || (col >= arr->numCols)) return;
/* -1 is a valid value for next ... it signifies
* that traversal should go to next tab group */
/* if ((0 > next_row) || (0 > next_col)) return; */
if ((next_row >= arr->numRows) || (next_col >= arr->numCols)) return;
(arr->right_traverse_r)[row][col] = next_row;
(arr->right_traverse_c)[row][col] = next_col;
}
/* --------------- end of file ----------------- */

View File

@ -4,7 +4,13 @@
#include "basiccell.h"
/* a cell array is a traversal group for one entry in the register */
/*
* The CellBlock is a rectangular grid of cells that define
* a traversal group for one entry in the register
*
* The right_traverse array indicates which cell chould be
* traversed to when the tab key is pressed.
*/
typedef struct _CellBlock {
@ -13,6 +19,9 @@ typedef struct _CellBlock {
BasicCell ***cells; /* row-col array */
short **right_traverse_r;
short **right_traverse_c;
/* private, utility cahced data */
short *widths; /* column widths */
unsigned char *alignments; /* column text alignments */
@ -26,4 +35,8 @@ void xaccInitCellBlock (CellBlock *, int numrows, int numcols);
/* add a cell to the array */
void xaccAddCell (CellBlock *, BasicCell *, int row, int col);
/* define next cell to traverse to */
void xaccNextRight (CellBlock *, int row, int col,
int next_row, int next_col);
#endif __XACC_CELL_BLOCK_H__

View File

@ -142,7 +142,19 @@ void xaccInitBasicRegister (BasicRegister *reg)
reg->balanceCell->cell.width = 9;
reg->balanceCell->cell.input_output = 0;
xaccAddCell (curs, &(reg->balanceCell->cell), BALN_CELL_R, BALN_CELL_C);
/* -------------------------------- */
/* define the traversal order */
xaccNextRight (curs, DATE_CELL_R, DATE_CELL_C, NUM_CELL_R, NUM_CELL_C);
xaccNextRight (curs, NUM_CELL_R, NUM_CELL_C, XFRM_CELL_R, XFRM_CELL_C);
xaccNextRight (curs, XFRM_CELL_R, XFRM_CELL_C, DESC_CELL_R, DESC_CELL_C);
xaccNextRight (curs, DESC_CELL_R, DESC_CELL_C, CRED_CELL_R, CRED_CELL_C);
xaccNextRight (curs, CRED_CELL_R, CRED_CELL_C, DEBT_CELL_R, DEBT_CELL_C);
xaccNextRight (curs, DEBT_CELL_R, DEBT_CELL_C, MEMO_CELL_R, MEMO_CELL_C);
xaccNextRight (curs, MEMO_CELL_R, MEMO_CELL_C, -1, -1);
/* -------------------------------- */
table = xaccMallocTable (0, 0);
table -> header = header;
xaccSetCursor (table, curs);

View File

@ -11,6 +11,15 @@ static void leaveCB (Widget mw, XtPointer cd, XtPointer cb);
static void modifyCB (Widget mw, XtPointer cd, XtPointer cb);
static void traverseCB (Widget mw, XtPointer cd, XtPointer cb);
/* The XrmQuarks are used to figure out the direction of
* traversal from cell to cell */
static XrmQuark QPointer, QLeft, QRight, QUp, QDown;
static Boolean haveQuarks = False;
/* ==================================================== */
Table *
xaccMallocTable (int tile_rows, int tile_cols)
{
@ -32,7 +41,10 @@ xaccInitTable (Table * table, int tile_rows, int tile_cols)
int num_phys_rows;
int num_phys_cols;
int i,j;
table->table_widget = 0;
table->next_tab_group = 0;
/* delete old entries */
num_phys_rows = table->num_phys_rows;
num_phys_cols = table->num_phys_cols;
@ -169,6 +181,14 @@ xaccRefreshHeader (Table *table)
}
}
/* ==================================================== */
void
xaccNextTabGroup (Table *table, Widget w)
{
table->next_tab_group = w;
}
/* ==================================================== */
/* this routine calls the individual cell callbacks */
@ -498,8 +518,28 @@ traverseCB (Widget mw, XtPointer cd, XtPointer cb)
rel_row %= (arr->numRows);
rel_col %= (arr->numCols);
printf ("traverse %d %d \n", row, col);
/* process right-moving traversals */
if (QRight == cbs->qparam) {
int next_row = arr->right_traverse_r[rel_row][rel_col];
int next_col = arr->right_traverse_c[rel_row][rel_col];
/* if we are at the end of the traversal chain,
* hop out of this tab group, and into the next.
*/
if ((-1 == next_row) || (-1 == next_col)) {
cbs->next_row = 0;
cbs->next_column = 0;
cbs->qparam = NULLQUARK;
if (table->next_tab_group) {
XmProcessTraversal (table->next_tab_group,
/* XmTRAVERSE_NEXT_TAB_GROUP); */
XmTRAVERSE_CURRENT);
}
} else {
cbs->next_row = row - rel_row + next_row;
cbs->next_column = col - rel_col + next_col;
}
}
}
@ -514,6 +554,17 @@ xaccCreateTable (Table *table, Widget parent, char * name)
if (!table) return 0;
/* if quarks have not yet been initialized for this
* application, initialize them now. */
if (!haveQuarks) {
QPointer = XrmPermStringToQuark ("Pointer");
QLeft = XrmPermStringToQuark ("Left");
QRight = XrmPermStringToQuark ("Right");
QUp = XrmPermStringToQuark ("Up");
QDown = XrmPermStringToQuark ("Down");
haveQuarks = True;
}
/* make sure that the table is consistent */
/* hack alert -- remove for now, since may be inited?
xaccInitTable (table, table->num_rows, table->num_cols);
@ -550,7 +601,8 @@ xaccCreateTable (Table *table, Widget parent, char * name)
XmNshadowType, XmSHADOW_ETCHED_IN,
XmNverticalScrollBarDisplayPolicy,XmDISPLAY_STATIC,
XmNselectScrollVisible, True,
XmNnavigationType, XmEXCLUSIVE_TAB_GROUP,
/* XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, */
XmNnavigationType, XmSTICKY_TAB_GROUP,
NULL);
XtManageChild (reg);
@ -560,7 +612,7 @@ xaccCreateTable (Table *table, Widget parent, char * name)
XtAddCallback (reg, XmNmodifyVerifyCallback, cellCB, (XtPointer)table);
XtAddCallback (reg, XmNtraverseCellCallback, cellCB, (XtPointer)table);
table->reg = reg;
table->table_widget = reg;
return (reg);
}
@ -569,7 +621,7 @@ xaccCreateTable (Table *table, Widget parent, char * name)
void
xaccRefreshTable (Table * table)
{
XtVaSetValues (table->reg, XmNcells, table->entries, NULL);
XtVaSetValues (table->table_widget, XmNcells, table->entries, NULL);
}
/* ================== end of file ======================= */

View File

@ -29,7 +29,8 @@ typedef struct _Table {
/* protected data -- vital for the implementation,
* but not something we want to generally expose */
Widget reg; /* the XbaeMatrix */
Widget table_widget; /* the XbaeMatrix */
Widget next_tab_group; /* where to traverse in the end */
/* private data, caches, etc. */
/* This is black-box stuff that no user of this class
@ -56,6 +57,7 @@ void xaccInitTable (Table *, int tile_rows, int tile_cols);
/* create the widget */
Widget xaccCreateTable (Table *, Widget parent, char * name);
void xaccNextTabGroup (Table *, Widget);
void xaccDestroyTable (Table *);