From 80b10f78650476bf1bff7209c7c92ec13486958d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Thu, 29 Jan 1998 06:51:28 +0000 Subject: [PATCH] fixes to traversal. It almost works. I had it working but then broke it again before checking in, and can't emember how to fix it. Artghhh! git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@459 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/RegWindow.c | 16 +++++----- src/register/cellblock.h | 11 +++++++ src/register/combocell.c | 3 +- src/register/register.c | 3 +- src/register/table.c | 66 ++++++++++++++++++++++++++++------------ src/register/table.h | 29 +++++++++++++++--- 6 files changed, 92 insertions(+), 36 deletions(-) diff --git a/src/RegWindow.c b/src/RegWindow.c index bd337e9ace..846ad8b378 100644 --- a/src/RegWindow.c +++ b/src/RegWindow.c @@ -450,10 +450,6 @@ regWindowLedger( Widget parent, Account **acclist, int ledger_type ) XmNnavigationType, XmSTICKY_TAB_GROUP, NULL ); - /* traverse to the buttons, when leaving the table */ - xaccNextTabGroup (regData->ledger->table, buttonform); - - position = 0; /* puts the buttons in the right place */ /* The "Record" button */ @@ -466,13 +462,15 @@ regWindowLedger( Widget parent, Account **acclist, int ledger_type ) XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, position+1, XmNshowAsDefault, True, - XmNnavigationType, XmTAB_GROUP, + XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, NULL ); XtAddCallback( widget, XmNactivateCallback, recordCB, (XtPointer)regData ); regData->record = widget; + /* traverse to the buttons, when leaving the table */ + xaccNextTabGroup (regData->ledger->table, widget); /* The "Cancel" button */ @@ -486,7 +484,8 @@ regWindowLedger( Widget parent, Account **acclist, int ledger_type ) XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, position+1, XmNshowAsDefault, True, - XmNnavigationType, XmTAB_GROUP, + /* XmNnavigationType, XmTAB_GROUP, */ + XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, NULL ); XtAddCallback( widget, XmNactivateCallback, @@ -503,7 +502,8 @@ regWindowLedger( Widget parent, Account **acclist, int ledger_type ) XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, position+1, XmNshowAsDefault, True, - XmNnavigationType, XmTAB_GROUP, + /* XmNnavigationType, XmTAB_GROUP, */ + XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, NULL ); XtAddCallback( widget, XmNactivateCallback, @@ -554,7 +554,7 @@ regWindowLedger( Widget parent, Account **acclist, int ledger_type ) XmNleftPosition, position, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, position+1, - XmNnavigationType, XmNONE, /* don't tab here! */ + XmNnavigationType, XmTAB_GROUP, /* don't tab here! */ NULL ); regData->balance = widget; diff --git a/src/register/cellblock.h b/src/register/cellblock.h index cbc131f085..9d2501be4b 100644 --- a/src/register/cellblock.h +++ b/src/register/cellblock.h @@ -12,6 +12,17 @@ * when the user presses the tab key (and/or uses the arrow * keys). * + * The xaccNextRight() method can be used to declare the + * traversal order from cell to cell. If the indicated cell + * has the current input focus, then the next cell that will + * be traversed to will be the one indicated. Traversing + * to the rright is usally performed with the tab key. + * Special traversal order to the left, up or down are not + * currently implemented. To traverse out of the table entirely, + * the next_row&col should be set to negative values. If + * a traversal back into the table occurs, then the cell that + * will be entered will be the one with the negative values. + * * MEMBERS: * The right_traverse array indicates which cell chould be * traversed to when the tab key is pressed. diff --git a/src/register/combocell.c b/src/register/combocell.c index 1f828504b2..cfc712b597 100644 --- a/src/register/combocell.c +++ b/src/register/combocell.c @@ -301,9 +301,8 @@ static void dropDownCB (Widget w, XtPointer cd, XtPointer cb ) XmComboBoxDropDownCallbackStruct *ddcb = (XmComboBoxDropDownCallbackStruct *) cb; - if (XmCR_HIDE_LIST == ddcb->reason) { - XmProcessTraversal(ab->parent, XmTRAVERSE_CURRENT); + XmProcessTraversal(ab->parent, XmTRAVERSE_CURRENT); } #ifdef USE_COMPLEX_TRAVERSAL_LOGIC diff --git a/src/register/register.c b/src/register/register.c index 4b5f3e35fc..d9fc8c188f 100644 --- a/src/register/register.c +++ b/src/register/register.c @@ -158,6 +158,7 @@ void xaccInitBasicRegister (BasicRegister *reg) /* -------------------------------- */ /* define the traversal order */ + /* negative cells mean "traverse out of table" */ 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); @@ -165,7 +166,7 @@ void xaccInitBasicRegister (BasicRegister *reg) xaccNextRight (curs, CRED_CELL_R, CRED_CELL_C, DEBT_CELL_R, DEBT_CELL_C); xaccNextRight (curs, DEBT_CELL_R, DEBT_CELL_C, ACTN_CELL_R, ACTN_CELL_C); xaccNextRight (curs, ACTN_CELL_R, ACTN_CELL_C, MEMO_CELL_R, MEMO_CELL_C); - xaccNextRight (curs, MEMO_CELL_R, MEMO_CELL_C, -1, -1); + xaccNextRight (curs, MEMO_CELL_R, MEMO_CELL_C, -DATE_CELL_R, -DATE_CELL_C); /* -------------------------------- */ diff --git a/src/register/table.c b/src/register/table.c index 0a21f6c72c..c980a7a133 100644 --- a/src/register/table.c +++ b/src/register/table.c @@ -105,6 +105,10 @@ xaccInitTable (Table * table, int tile_rows, int tile_cols) table->entries[i][j] = strdup (""); } } + + /* invalidate the "previous" traversed cell */ + table->prev_phys_traverse_row = -1; + table->prev_phys_traverse_col = -1; } /* ==================================================== */ @@ -343,11 +347,6 @@ cellCB (Widget mw, XtPointer cd, XtPointer cb) mvcbs->verify->doit = False; break; } - case XbaeTraverseCellReason: { - XbaeMatrixTraverseCellCallbackStruct *tcbs; - tcbs = (XbaeMatrixTraverseCellCallbackStruct *) cbs; - break; - } case XbaeLeaveCellReason: { XbaeMatrixLeaveCellCallbackStruct *lcbs; lcbs = (XbaeMatrixLeaveCellCallbackStruct *) cbs; @@ -375,11 +374,6 @@ cellCB (Widget mw, XtPointer cd, XtPointer cb) leaveCB (mw, cd, cb); break; } - case XbaeTraverseCellReason: { - verifyCursorPosition (table, row, col); - traverseCB (mw, cd, cb); - break; - } } } @@ -598,9 +592,37 @@ traverseCB (Widget mw, XtPointer cd, XtPointer cb) arr = table->cursor; cbs = (XbaeMatrixTraverseCellCallbackStruct *) cb; - /* compute the cell location */ row = cbs->row; col = cbs->column; + + verifyCursorPosition (table, row, col); + + /* If the quark is zero, then it is likely that we are + * here because we traversed out of a cell that had a + * ComboBox in it. The ComboCell is clever enough to put + * us back into the register after tabing out of it. + * However, its not (cannot be) clever enough to pretend + * that it was a tab group in the register. Thus, + * we will emulate that we left a tab group in the register + * to get here. To put it more simply, we just set the + * row and column to that of the ComboCell, which we had + * previously recorded, and continue on as if nothing + * happened. + * BTW -- note that we are emulating a normal, right-moving tab. + * Backwards tabs are broken. + */ + if (NULLQUARK == cbs->qparam) { + if ((0==row) && (0==col)) { + if ((0 <= table->prev_phys_traverse_row) && + (0 <= table->prev_phys_traverse_col)) { + cbs->qparam = QRight; + row = table->prev_phys_traverse_row; + col = table->prev_phys_traverse_col; + } + } + } + + /* compute the cell location */ rel_row = row - table->num_header_rows; rel_col = col; rel_row %= (arr->numRows); @@ -614,20 +636,24 @@ traverseCB (Widget mw, XtPointer cd, XtPointer cb) /* 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; + if ((0 > next_row) || (0 > next_col)) { + /* reverse the sign of next_row, col to be positive. */ + cbs->next_row = row - rel_row - next_row; + cbs->next_column = col - rel_col - next_col; 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; } - } + } + + table->prev_phys_traverse_row = cbs->next_row; + table->prev_phys_traverse_col = cbs->next_column; } @@ -681,13 +707,13 @@ xaccCreateTable (Table *table, Widget parent, char * name) XmNcolumns, table->num_phys_cols, XmNcolumnWidths, widths, XmNcolumnAlignments, alignments, - XmNtraverseFixedCells, False, XmNgridType, XmGRID_SHADOW_IN, XmNshadowType, XmSHADOW_ETCHED_IN, XmNverticalScrollBarDisplayPolicy,XmDISPLAY_STATIC, XmNselectScrollVisible, True, - /* XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, */ - XmNnavigationType, XmSTICKY_TAB_GROUP, + XmNtraverseFixedCells, False, + XmNnavigationType, XmEXCLUSIVE_TAB_GROUP, + /* XmNnavigationType, XmSTICKY_TAB_GROUP, */ NULL); XtManageChild (reg); @@ -696,7 +722,7 @@ xaccCreateTable (Table *table, Widget parent, char * name) XtAddCallback (reg, XmNenterCellCallback, cellCB, (XtPointer)table); XtAddCallback (reg, XmNleaveCellCallback, cellCB, (XtPointer)table); XtAddCallback (reg, XmNmodifyVerifyCallback, cellCB, (XtPointer)table); - XtAddCallback (reg, XmNtraverseCellCallback, cellCB, (XtPointer)table); + XtAddCallback (reg, XmNtraverseCellCallback, traverseCB, (XtPointer)table); table->table_widget = reg; diff --git a/src/register/table.h b/src/register/table.h index 8f9267190f..ad44eaca11 100644 --- a/src/register/table.h +++ b/src/register/table.h @@ -1,3 +1,17 @@ +/* + * FILE: + * table.h + * + * FUNCTION: + * The table is the complete, displayed table. + * It consists of a header, followed by a simple + * list of repeated entries. + * + * It provides the mechanism to handle tab-trversing. + * + * HISTORY: + * Copyright (c) 1998 Linas Vepstas + */ #ifndef __XACC_TABLE_H__ #define __XACC_TABLE_H__ @@ -6,11 +20,6 @@ #include "basiccell.h" #include "cellblock.h" -/* the table is the complete, displayed table. */ -/* It consists of a header, followed by a simple - * list of repeated entries - */ - typedef struct _Table { /* num rows and cols are the number of times the @@ -49,6 +58,16 @@ typedef struct _Table { int num_header_rows; int num_phys_rows; int num_phys_cols; + + /* This class implements tab-key and arrow key + * traversal through the cells of the table. + * To perform this traversal, the location + * of the "previous" cell having input focus + * is required. + */ + int prev_phys_traverse_row; + int prev_phys_traverse_col; + } Table;