gui-indep pieces done, maybe.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@653 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-03-17 07:56:57 +00:00
parent 4f12668d61
commit 7113e84458
4 changed files with 64 additions and 106 deletions

View File

@ -257,10 +257,12 @@ void xaccMoveCursor (Table *table, int new_phys_row, int new_phys_col)
}
/* record the new virtual position ... */
table->current_cursor_row = new_virt_row;
table->current_cursor_col = new_virt_col;
table->current_cursor_virt_row = new_virt_row;
table->current_cursor_virt_col = new_virt_col;
/* invalidate the cursor for now; we'll set it the the correct values below */
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->current_cursor->user_data = NULL;
table->current_cursor = NULL;
@ -281,6 +283,9 @@ void xaccMoveCursor (Table *table, int new_phys_row, int new_phys_col)
phys_col_origin = new_phys_col;
phys_col_origin -= table->locators[new_phys_row][new_phys_col]->phys_col_offset;
table->current_cursor_phys_row = phys_col_origin;
table->current_cursor_phys_col = phys_row_origin;
/* update the cell values to reflect the new position */
for (i=0; i<curs->numRows; i++) {
for (j=0; j<curs->numCols; j++) {
@ -323,12 +328,14 @@ void xaccMoveCursorGUI (Table *table, int new_phys_row, int new_phys_col)
}
/* record the new virtual position ... */
table->current_cursor_row = new_virt_row;
table->current_cursor_col = new_virt_col;
table->current_cursor_virt_row = new_virt_row;
table->current_cursor_virt_col = new_virt_col;
curs = table->current_cursor;
/* invalidate the cursor for now; we'll set it the the correct values below */
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->current_cursor->user_data = NULL;
table->current_cursor = NULL;
@ -366,6 +373,9 @@ void xaccMoveCursorGUI (Table *table, int new_phys_row, int new_phys_col)
phys_col_origin = new_phys_col;
phys_col_origin -= table->locators[new_phys_row][new_phys_col]->phys_col_offset;
table->current_cursor_phys_row = phys_col_origin;
table->current_cursor_phys_col = phys_row_origin;
/* update the cell values to reflect the new position */
for (i=0; i<curs->numRows; i++) {
for (j=0; j<curs->numCols; j++) {
@ -393,25 +403,28 @@ void xaccMoveCursorGUI (Table *table, int new_phys_row, int new_phys_col)
void xaccCommitCursor (Table *table)
{
int i,j;
int iphys,jphys;
BasicCell *cell;
int virt_row, virt_col;
CellBlock *curs;
virt_row = table->current_cursor_row;
virt_col = table->current_cursor_col;
curs = table->current_cursor;
if (!curs) return;
virt_row = table->current_cursor_virt_row;
virt_col = table->current_cursor_virt_col;
/* cant commit if cursor is bad */
if ((0 > virt_row) || (0 > virt_col)) return;
if (virt_row >= table->num_rows) return;
if (virt_col >= table->num_cols) return;
if (virt_row >= table->num_virt_rows) return;
if (virt_col >= table->num_virt_cols) return;
for (i=0; i<table->tile_height; i++) {
iphys = i + virt_row * table->tile_height;
iphys += table->num_header_rows;
for (j=0; j<table->tile_width; j++) {
for (i=0; i<curs->numRows; i++) {
for (j=0; j<curs->numCols; j++) {
BasicCell *cell;
cell = table->cursor->cells[i][j];
cell = curs->cells[i][j];
if (cell) {
jphys = j + virt_col * table->tile_width;
int iphys = i + table->current_cursor_phys_row;
int jphys = j + table->current_cursor_phys_col;
if (table->entries[iphys][jphys]) {
free (table->entries[iphys][jphys]);
}
@ -420,7 +433,7 @@ void xaccCommitCursor (Table *table)
}
}
table->user_data[virt_row][virt_col] = table->cursor->user_data;
table->user_data[virt_row][virt_col] = curs->user_data;
}
/* ==================================================== */
@ -429,21 +442,17 @@ void xaccCommitCursor (Table *table)
* the cursor if necessary.
*/
static void
verifyCursorPosition (Table *table, int phys_row, int phys_col)
void
xaccVerifyCursorPosition (Table *table, int phys_row, int phys_col)
{
int virt_row, virt_col;
/* compute the virtual position */
virt_row = phys_row;
virt_row -= table->num_header_rows;
virt_row /= table->tile_height;
virt_row = table->locators[phys_row][phys_col]->virt_row;
virt_col = table->locators[phys_row][phys_col]->virt_col;
virt_col = phys_col;
virt_col /= table->tile_width;
if ((virt_row != table->current_cursor_row) ||
(virt_col != table->current_cursor_col)) {
if ((virt_row != table->current_cursor_virt_row) ||
(virt_col != table->current_cursor_virt_col)) {
/* before leaving, the current virtual position,
* commit any edits that have been accumulated

View File

@ -59,6 +59,17 @@ void xaccMoveCursor (Table *, int phys_row, int phys_col);
/* move the cursor GUI to the indicated location. */
void xaccMoveCursorGUI (Table *, int phys_row, int phys_col);
/* copy text in the cursor cells to the table */
void xaccCommitCursor (Table *);
/* xaccVerifyCursorPosition checks the location of the cursor
* with respect to a physical row/column position, and if the
* resulting virtual position has changed, commits the changes in the
* old position, and the repositions the cursor & gui to the new position.
*/
void
xaccVerifyCursorPosition (Table *table, int phys_row, int phys_col);
#endif /* __XACC_TABLE_ALLGUI_H__ */

View File

@ -73,8 +73,10 @@ xaccInitTable (Table * table)
table->num_virt_cols = 0;
table->current_cursor = NULL;
table->current_cursor_row = -1;
table->current_cursor_col = -1;
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->move_cursor = NULL;
table->client_data = NULL;
@ -102,78 +104,16 @@ xaccSetTableSize (Table * table, int phys_rows, int phys_cols,
table->prev_phys_traverse_col = -1;
/* invalidate the current cursor position, if needed */
if ((table->current_cursor_row >= table->num_virt_rows) ||
(table->current_cursor_col >= table->num_virt_cols)) {
table->current_cursor_row = -1;
table->current_cursor_col = -1;
if ((table->current_cursor_virt_row >= table->num_virt_rows) ||
(table->current_cursor_virt_col >= table->num_virt_cols)) {
table->current_cursor_virt_row = -1;
table->current_cursor_virt_col = -1;
table->current_cursor_phys_row = -1;
table->current_cursor_phys_col = -1;
table->current_cursor = NULL;
}
}
/* ==================================================== */
void xaccCommitCursor (Table *table)
{
int i,j;
int iphys,jphys;
BasicCell *cell;
int virt_row, virt_col;
virt_row = table->current_cursor_row;
virt_col = table->current_cursor_col;
if ((0 > virt_row) || (0 > virt_col)) return;
if (virt_row >= table->num_rows) return;
if (virt_col >= table->num_cols) return;
for (i=0; i<table->tile_height; i++) {
iphys = i + virt_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 + virt_col * table->tile_width;
if (table->entries[iphys][jphys]) {
free (table->entries[iphys][jphys]);
}
table->entries[iphys][jphys] = strdup (cell->value);
}
}
}
table->user_data[virt_row][virt_col] = table->cursor->user_data;
}
/* ==================================================== */
/* verifyCursorPosition checks the location of the cursor
* with respect to a row/column position, and repositions
* the cursor if necessary.
*/
static void
verifyCursorPosition (Table *table, int phys_row, int phys_col)
{
int virt_row, virt_col;
/* compute the virtual position */
virt_row = phys_row;
virt_row -= table->num_header_rows;
virt_row /= table->tile_height;
virt_col = phys_col;
virt_col /= table->tile_width;
if ((virt_row != table->current_cursor_row) ||
(virt_col != table->current_cursor_col)) {
/* before leaving, the current virtual position,
* commit any edits that have been accumulated
* in the cursor */
xaccCommitCursor (table);
xaccMoveCursorGUI (table, virt_row, virt_col);
}
}
/* ==================================================== */
/* hack alert -- will core dump if numrows has changed, etc. */
@ -300,7 +240,7 @@ cellCB (Widget mw, XtPointer cd, XtPointer cb)
* this cell. Dispatch for processing. */
switch (cbs->reason) {
case XbaeEnterCellReason: {
verifyCursorPosition (table, row, col);
xaccVerifyCursorPosition (table, row, col);
enterCB (mw, cd, cb);
break;
}
@ -581,7 +521,7 @@ traverseCB (Widget mw, XtPointer cd, XtPointer cb)
}
}
verifyCursorPosition (table, row, col);
xaccVerifyCursorPosition (table, row, col);
/* compute the cell location */
rel_row = row - table->num_header_rows;

View File

@ -72,11 +72,12 @@ typedef struct _Table {
int num_virt_rows;
int num_virt_cols;
CellBlock *header;
/* the current cursor row/col is the virt row/col */
CellBlock *current_cursor;
int current_cursor_row;
int current_cursor_col;
int current_cursor_phys_row;
int current_cursor_phys_col;
int current_cursor_virt_row;
int current_cursor_virt_col;
/* callback that is called when the cursor is moved */
/* hack alert -- this should be a callback list, actually */
@ -139,8 +140,5 @@ void xaccDestroyTable (Table *);
/* redraw the table GUI */
void xaccRefreshTableGUI (Table *);
/* copy text in the cursor cells to the table */
void xaccCommitCursor (Table *);
#endif __XACC_TABLE_H__
/* ================== end of file ======================= */