Skip to content

Commit

Permalink
add callback for move of cursor, allowing edits to be commited
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@473 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
linas committed Jan 31, 1998
1 parent af64219 commit 39e17ce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Ledger.c
Expand Up @@ -14,6 +14,16 @@

/* ======================================================== */

static void
LedgerMoveCursor (struct _Table *_table, void * client_data)
{
Table * table = (Table *)_table;
BasicRegister *reg = (BasicRegister *) client_data;
xaccSaveRegEntry (reg);
}

/* ======================================================== */

Split * xaccGetCurrentSplit (BasicRegister *reg)
{
CellBlock *cursor;
Expand Down Expand Up @@ -99,6 +109,9 @@ xaccLoadRegister (BasicRegister *reg, Split **slist)

table = reg->table;

/* disable callback */
table->move_cursor = NULL;

/* set table size to number of items in list */
i=0;
while (slist[i]) i++;
Expand All @@ -116,6 +129,10 @@ xaccLoadRegister (BasicRegister *reg, Split **slist)
split = slist[i];
}
xaccRefreshTableGUI (table);

/* enable callback for cursor moves */
table->move_cursor = LedgerMoveCursor;
table->client_data = (void *) reg;
}

/* ======================================================== */
Expand Down
1 change: 1 addition & 0 deletions src/RegWindow.c
Expand Up @@ -735,6 +735,7 @@ cancelCB( Widget mw, XtPointer cd, XtPointer cb )
/* when cancelling edits, reload the cursor from the transaction */
split = xaccGetCurrentSplit (regData->ledger);
xaccLoadRegEntry (regData->ledger, split);
xaccRefreshTableGUI (regData->ledger->table);
}

/************************** END OF FILE *************************/
13 changes: 13 additions & 0 deletions src/register/table.c
Expand Up @@ -54,6 +54,9 @@ xaccInitTable (Table * table)
table->current_cursor_row = -1;
table->current_cursor_col = -1;

table->move_cursor = NULL;
table->client_data = NULL;

table->header = NULL;
table->cursor = NULL;
table->entries = NULL;
Expand Down Expand Up @@ -327,6 +330,11 @@ void xaccMoveCursor (Table *table, int virt_row, int virt_col)
int iphys,jphys;
BasicCell *cell;

/* call the callback, allowing the app to commit any changes */
if (table->move_cursor) {
(table->move_cursor) (table, table->client_data);
}

table->current_cursor_row = virt_row;
table->current_cursor_col = virt_col;

Expand Down Expand Up @@ -360,6 +368,11 @@ void xaccMoveCursorGUI (Table *table, int virt_row, int virt_col)
int iphys,jphys;
BasicCell *cell;

/* call the callback, allowing the app to commit any changes */
if (table->move_cursor) {
(table->move_cursor) (table, table->client_data);
}

table->current_cursor_row = virt_row;
table->current_cursor_col = virt_col;

Expand Down
5 changes: 5 additions & 0 deletions src/register/table.h
Expand Up @@ -34,6 +34,11 @@ typedef struct _Table {
int current_cursor_row;
int current_cursor_col;

/* callback that is called when the cursor is moved */
/* hack alert -- this should be a callback list, actually */
void (*move_cursor) (struct _Table *, void *client_data);
void * client_data;

/* string values for each cell,
* of dimension num_phys_rows * num_phys_cols */
char ***entries;
Expand Down

0 comments on commit 39e17ce

Please sign in to comment.