* src/register/gnome/gnucash-sheet.c: if input is cancelled by

user during delete, ignore the insert callback.

	* src/MultiLedger.c: update for new view api

	* src/register/recncell.{ch}: allow setting a parent to be used
	for the dialog.

	* src/gnome/query-user.c (gnc_verify_dialog_parented): handle null
	parent by using gnc_get_ui_data.

	* src/gnome/window-register.c: eliminate calls to
	xaccSRCheckReconciled. confirmation is done in SplitLedger.c now.

	* src/SplitLedger.c: use new data entry confirmation callback
	to confirm changes to a reconciled split.

	* src/register/splitreg.{ch}: mod for table-allgui changes

	* src/register/table-allgui.{ch}: encapsulate 'view' callbacks
	into a struct. add a callback for confiming data entry.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3726 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-03-01 11:06:36 +00:00
parent fa161cd3b5
commit 275142e3c2
14 changed files with 279 additions and 205 deletions

View File

@ -1,3 +1,27 @@
2001-03-01 Dave Peticolas <dave@krondo.com>
* src/register/gnome/gnucash-sheet.c: if input is cancelled by
user during delete, ignore the insert callback.
* src/MultiLedger.c: update for new view api
* src/register/recncell.{ch}: allow setting a parent to be used
for the dialog.
* src/gnome/query-user.c (gnc_verify_dialog_parented): handle null
parent by using gnc_get_ui_data.
* src/gnome/window-register.c: eliminate calls to
xaccSRCheckReconciled. confirmation is done in SplitLedger.c now.
* src/SplitLedger.c: use new data entry confirmation callback
to confirm changes to a reconciled split.
* src/register/splitreg.{ch}: mod for table-allgui changes
* src/register/table-allgui.{ch}: encapsulate 'view' callbacks
into a struct. add a callback for confiming data entry.
2001-03-01 Robert Graham Merkel <rgmerk@mira.net> 2001-03-01 Robert Graham Merkel <rgmerk@mira.net>
* src/scm/report/transaction-report.scm (add-split-row): Now * src/scm/report/transaction-report.scm (add-split-row): Now
@ -27,7 +51,6 @@
for-each-in-order isn't. Probably should make the substitution for-each-in-order isn't. Probably should make the substitution
globally. globally.
2001-02-28 Dave Peticolas <dave@krondo.com> 2001-02-28 Dave Peticolas <dave@krondo.com>
* src/engine/Transaction.c (xaccSplitsComputeValue): fix a bug * src/engine/Transaction.c (xaccSplitsComputeValue): fix a bug
@ -437,8 +460,8 @@
* src/gnome/druid-commodity.c: remove consts from * src/gnome/druid-commodity.c: remove consts from
gnc_commoditities (after consultation with Bill). gnc_commoditities (after consultation with Bill).
* src/gnome/dialog-account.c: remove consts from gnc_commoditities (after * src/gnome/dialog-account.c: remove consts from gnc_commoditities
consultation with Bill). (after consultation with Bill).
* src/gnome/dialog-options.c: remove consts from gnc_commoditities * src/gnome/dialog-options.c: remove consts from gnc_commoditities
(after consultation with Bill). (after consultation with Bill).
@ -455,11 +478,11 @@
* src/gnc-ui-util.c: remove consts from gnc_commoditities (after * src/gnc-ui-util.c: remove consts from gnc_commoditities (after
consultation with Bill). consultation with Bill).
* src/engine/Transaction.h: remove consts from gnc_commoditities (after * src/engine/Transaction.h: remove consts from gnc_commoditities
consultation with Bill). (after consultation with Bill).
* src/engine/Transaction.c: remove consts from gnc_commoditities (after * src/engine/Transaction.c: remove consts from gnc_commoditities
consultation with Bill). (after consultation with Bill).
* src/engine/Scrub.c: remove consts from gnc_commoditities (after * src/engine/Scrub.c: remove consts from gnc_commoditities (after
consultation with Bill). consultation with Bill).
@ -1757,30 +1780,34 @@
2000-09-05 Robert Graham Merkel <rgmerk@mira.net> 2000-09-05 Robert Graham Merkel <rgmerk@mira.net>
* src/scm/date-utilities.scm ((gnc:reldate-initialize)): New function - initialise * src/scm/date-utilities.scm ((gnc:reldate-initialize)): New
explicitly at startup rather than in ad-hoc manner function - initialise explicitly at startup rather than in ad-hoc
manner
2000-08-31 Robert Graham Merkel <rgmerk@mira.net> 2000-08-31 Robert Graham Merkel <rgmerk@mira.net>
* src/scm/report/balance-and-pnl.scm: Bug fixes for new date options. * src/scm/report/balance-and-pnl.scm: Bug fixes for new date
options.
* src/scm/report/transaction-report.scm: Bug fixes for new date options. * src/scm/report/transaction-report.scm: Bug fixes for new date
options.
* src/scm/report/budget-report.scm: Bug fixes for new date options. * src/scm/report/budget-report.scm: Bug fixes for new date options.
2000-08-30 Robert Graham Merkel <rgmerk@mira.net> 2000-08-30 Robert Graham Merkel <rgmerk@mira.net>
* src/scm/report/hello-world.scm: A couple of new functions to test the relative * src/scm/report/hello-world.scm: A couple of new functions to
and combination date style options. test the relative and combination date style options.
* src/scm/report/*.scm: Modified date options to take the new function. Most * src/scm/report/*.scm: Modified date options to take the new
are still using absolute options at this stage, will get modified to use relative function. Most are still using absolute options at this stage,
dates later. will get modified to use relative dates later.
* src/scm/options.scm (gnc:make-option): new argument (option-data-fns) * src/scm/options.scm (gnc:make-option): new argument
for manipulating multi-choice style options. Changes (option-data-fns) for manipulating multi-choice style options.
to option-makers to either support this. Changes to option-makers to either support this.
(gnc:make-date-option): modified to support relative and combination dates. (gnc:make-date-option): modified to support relative and
combination dates.
* src/scm/date-utilities.scm: Extensive additions for manipulating * src/scm/date-utilities.scm: Extensive additions for manipulating
relative dates. relative dates.
@ -1889,7 +1916,8 @@
startup. startup.
(gnc:main): support --evalutate properly. (gnc:main): support --evalutate properly.
* src/scm/engine-utilities.scm (gnc:transaction-map-splits): moved here. * src/scm/engine-utilities.scm (gnc:transaction-map-splits): moved
here.
(gnc:group-map-accounts): moved here. (gnc:group-map-accounts): moved here.
* src/scm/command-line.scm (gnc:*arg-defs*): add --evaluate * src/scm/command-line.scm (gnc:*arg-defs*): add --evaluate

View File

@ -640,6 +640,7 @@ xaccLedgerDisplayInternal (Account *lead_account, Query *q,
xaccLedgerDisplay *ld; xaccLedgerDisplay *ld;
gboolean show_all; gboolean show_all;
const char *class; const char *class;
TableView view;
GList *splits; GList *splits;
switch (ld_type) switch (ld_type)
@ -738,13 +739,16 @@ xaccLedgerDisplayInternal (Account *lead_account, Query *q,
/* xaccMallocSplitRegister will malloc & initialize the register, /* xaccMallocSplitRegister will malloc & initialize the register,
* but will not do the gui init */ * but will not do the gui init */
ld->reg = xaccMallocSplitRegister (reg_type, style, FALSE, view.entry_handler = xaccSRGetEntryHandler;
xaccSRGetEntryHandler, view.label_handler = xaccSRGetLabelHandler;
xaccSRGetLabelHandler, view.io_flag_handler = xaccSRGetIOFlagsHandler;
xaccSRGetIOFlagsHandler, view.fg_color_handler = xaccSRGetFGColorHandler;
xaccSRGetFGColorHandler, view.bg_color_handler = xaccSRGetBGColorHandler;
xaccSRGetBGColorHandler, view.cell_border_handler = xaccSRGetCellBorderHandler;
xaccSRGetCellBorderHandler, view.confirm_handler = xaccSRConfirmHandler;
view.handler_user_data = NULL;
ld->reg = xaccMallocSplitRegister (reg_type, style, FALSE, &view,
xaccMLGUIDMalloc, xaccMLGUIDMalloc,
xaccMLGUIDFree, xaccMLGUIDFree,
xaccMLGUIDCopy); xaccMLGUIDCopy);

View File

@ -23,7 +23,7 @@
* SplitLedger.c * SplitLedger.c
* *
* FUNCTION: * FUNCTION:
* copy transaction data from engine into split-register object. * Provide view for SplitRegister object.
* *
* *
* DESIGN NOTES: * DESIGN NOTES:
@ -183,6 +183,10 @@ struct _SRInfo
/* true if we are loading the register for the first time */ /* true if we are loading the register for the first time */
gboolean first_pass; gboolean first_pass;
/* true if the user has already confirmed changes of a reconciled
* split */
gboolean change_confirmed;
/* User data for users of SplitRegisters */ /* User data for users of SplitRegisters */
gpointer user_data; gpointer user_data;
@ -1013,6 +1017,9 @@ LedgerMoveCursor (Table *table, VirtualLocation *p_new_virt_loc)
info->cursor_hint_cursor_class = new_class; info->cursor_hint_cursor_class = new_class;
} }
if (old_split != new_split)
info->change_confirmed = FALSE;
gnc_resume_gui_refresh (); gnc_resume_gui_refresh ();
/* redrawing the register can muck everything up */ /* redrawing the register can muck everything up */
@ -1563,6 +1570,8 @@ LedgerTraverse (Table *table,
switch (result) switch (result)
{ {
case GNC_VERIFY_YES: case GNC_VERIFY_YES:
break;
case GNC_VERIFY_NO: case GNC_VERIFY_NO:
{ {
VirtualCellLocation vcell_loc; VirtualCellLocation vcell_loc;
@ -1570,9 +1579,6 @@ LedgerTraverse (Table *table,
Split *trans_split; Split *trans_split;
CursorClass new_class; CursorClass new_class;
if ((result == GNC_VERIFY_YES) && xaccSRCheckReconciled (reg))
break;
new_split = sr_get_split(reg, virt_loc.vcell_loc); new_split = sr_get_split(reg, virt_loc.vcell_loc);
trans_split = xaccSRGetTransSplit(reg, virt_loc.vcell_loc, NULL); trans_split = xaccSRGetTransSplit(reg, virt_loc.vcell_loc, NULL);
new_class = xaccSplitRegisterGetCursorClass (reg, virt_loc.vcell_loc); new_class = xaccSplitRegisterGetCursorClass (reg, virt_loc.vcell_loc);
@ -4369,6 +4375,55 @@ xaccSRGetBGColorHandler (VirtualLocation virt_loc,
} }
} }
gboolean
xaccSRConfirmHandler (VirtualLocation virt_loc,
gpointer user_data)
{
SplitRegister *reg = user_data;
SRInfo *info = xaccSRGetInfo (reg);
guint32 changed;
Split *split;
char recn;
/* This assumes we reset the flag whenver we change splits.
* This happens in LedgerMoveCursor. */
if (info->change_confirmed)
return TRUE;
split = sr_get_split (reg, virt_loc.vcell_loc);
if (!split)
return TRUE;
changed = xaccSplitRegisterGetChangeFlag (reg);
if (MOD_RECN & changed)
recn = xaccRecnCellGetFlag (reg->recnCell);
else
recn = xaccSplitGetReconcile (split);
if (recn == YREC)
{
gboolean confirm;
char *message = _("You are about to change a reconciled split.\n"
"Are you sure you want to do that?");
confirm = gnc_lookup_boolean_option ("Register",
"Confirm before changing reconciled",
TRUE);
if (!confirm)
return TRUE;
confirm = gnc_verify_dialog_parented (xaccSRGetParent (reg),
message, FALSE);
info->change_confirmed = confirm;
return confirm;
}
return TRUE;
}
/* ======================================================== */ /* ======================================================== */
G_INLINE_FUNC void G_INLINE_FUNC void
@ -4814,6 +4869,9 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist,
xaccComboCellSetCompleteChar (reg->mxfrmCell, account_separator); xaccComboCellSetCompleteChar (reg->mxfrmCell, account_separator);
xaccComboCellSetCompleteChar (reg->xfrmCell, account_separator); xaccComboCellSetCompleteChar (reg->xfrmCell, account_separator);
/* set the dialog parent for the reconcile cell */
xaccRecnCellSetParent (reg->recnCell, xaccSRGetParent (reg));
/* enable callback for cursor user-driven moves */ /* enable callback for cursor user-driven moves */
table->move_cursor = LedgerMoveCursor; table->move_cursor = LedgerMoveCursor;
table->traverse = LedgerTraverse; table->traverse = LedgerTraverse;
@ -4962,38 +5020,6 @@ trans_has_reconciled_splits (Transaction *trans)
return FALSE; return FALSE;
} }
gboolean
xaccSRCheckReconciled (SplitRegister *reg)
{
Transaction *trans;
guint32 changed;
gboolean confirm;
char *message = _("You are about to change a transaction with reconciled\n"
"splits. Are you sure you want to do that?");
if (reg == NULL)
return TRUE;
changed = xaccSplitRegisterGetChangeFlag (reg);
if (!changed)
return TRUE;
trans = xaccSRGetCurrentTrans (reg);
if (trans == NULL)
return TRUE;
if (!trans_has_reconciled_splits (trans))
return TRUE;
confirm = gnc_lookup_boolean_option ("Register",
"Confirm before changing reconciled",
TRUE);
if (!confirm)
return TRUE;
return gnc_verify_dialog_parented (xaccSRGetParent (reg), message, FALSE);
}
/* ======================================================== */ /* ======================================================== */
void void

View File

@ -180,14 +180,6 @@ void xaccSRRedrawReg (SplitRegister *reg);
* has changed cells that have not been committed. */ * has changed cells that have not been committed. */
gboolean xaccSRHasPendingChanges (SplitRegister *reg); gboolean xaccSRHasPendingChanges (SplitRegister *reg);
/* The xaccSRCheckReconciled() method returns TRUE if the current
* cursor has not been changed. It also returns TRUE if it has been
* changed, but the relevant split is not reconciled or frozen. It
* also returns TRUE if it has been changed and it is reconciled and
* the user verifies in a dialog that the split should be changed.
* Otherwise, it returns FALSE. */
gboolean xaccSRCheckReconciled (SplitRegister *reg);
/* If TRUE, visually indicate the demarcation between splits with post /* If TRUE, visually indicate the demarcation between splits with post
* dates prior to the present, and after. This will only make sense if * dates prior to the present, and after. This will only make sense if
* the splits are ordered primarily by post date. */ * the splits are ordered primarily by post date. */
@ -224,5 +216,7 @@ guint32 xaccSRGetBGColorHandler (VirtualLocation virt_loc,
void xaccSRGetCellBorderHandler (VirtualLocation virt_loc, void xaccSRGetCellBorderHandler (VirtualLocation virt_loc,
PhysicalCellBorders *borders, PhysicalCellBorders *borders,
gpointer user_data); gpointer user_data);
gboolean xaccSRConfirmHandler (VirtualLocation virt_loc,
gpointer user_data);
#endif /* __XACC_SPLIT_LEDGER_H__ */ #endif /* __XACC_SPLIT_LEDGER_H__ */

View File

@ -194,6 +194,8 @@ gnc_verify_dialog_parented(gncUIWidget parent, const char *message,
if (parent != NULL) if (parent != NULL)
gnome_dialog_set_parent(GNOME_DIALOG(verify_box), GTK_WINDOW(parent)); gnome_dialog_set_parent(GNOME_DIALOG(verify_box), GTK_WINDOW(parent));
else
gnome_dialog_set_parent(GNOME_DIALOG(verify_box), gnc_get_ui_data());
gnome_dialog_set_default(GNOME_DIALOG(verify_box), yes_is_default ? 0 : 1); gnome_dialog_set_default(GNOME_DIALOG(verify_box), yes_is_default ? 0 : 1);

View File

@ -1081,13 +1081,8 @@ new_trans_cb(GtkWidget *widget, gpointer data)
reg = xaccLedgerDisplayGetSR (regData->ledger); reg = xaccLedgerDisplayGetSR (regData->ledger);
if (xaccSRCheckReconciled (reg))
{
if (xaccSRSaveRegEntry (reg, TRUE)) if (xaccSRSaveRegEntry (reg, TRUE))
xaccSRRedrawReg (reg); xaccSRRedrawReg (reg);
}
else
xaccSRCancelCursorTransChanges (reg);
gnc_register_jump_to_blank (regData); gnc_register_jump_to_blank (regData);
} }
@ -2556,16 +2551,8 @@ recordCB (GtkWidget *w, gpointer data)
trans = xaccSRGetCurrentTrans (reg); trans = xaccSRGetCurrentTrans (reg);
if (xaccSRCheckReconciled (reg))
{
if (!xaccSRSaveRegEntry (reg, TRUE)) if (!xaccSRSaveRegEntry (reg, TRUE))
return; return;
}
else
{
xaccSRCancelCursorTransChanges (reg);
return;
}
if (trans != NULL) if (trans != NULL)
gnc_register_include_date (regData, xaccTransGetDate(trans)); gnc_register_include_date (regData, xaccTransGetDate(trans));

View File

@ -420,7 +420,6 @@ gnucash_sheet_show_row (GnucashSheet *sheet, gint virt_row)
void void
gnucash_sheet_make_cell_visible (GnucashSheet *sheet, VirtualLocation virt_loc) gnucash_sheet_make_cell_visible (GnucashSheet *sheet, VirtualLocation virt_loc)
{ {
g_return_if_fail (sheet != NULL); g_return_if_fail (sheet != NULL);
g_return_if_fail (GNUCASH_IS_SHEET (sheet)); g_return_if_fail (GNUCASH_IS_SHEET (sheet));
@ -656,7 +655,8 @@ gnucash_sheet_modify_current_cell(GnucashSheet *sheet, const gchar *new_text)
new_text_wc, new_text_len, new_text_wc, new_text_len,
new_text_wc, new_text_len, new_text_wc, new_text_len,
&cursor_position, &cursor_position,
&start_sel, &end_sel); &start_sel, &end_sel,
NULL);
g_free (new_text_wc); g_free (new_text_wc);
@ -710,6 +710,13 @@ gnucash_sheet_insert_cb (GtkWidget *widget,
int old_position; int old_position;
int i; int i;
if (sheet->input_cancelled)
{
gtk_signal_emit_stop_by_name (GTK_OBJECT (sheet->entry),
"insert_text");
return;
}
if (insert_text_len <= 0) if (insert_text_len <= 0)
return; return;
@ -782,7 +789,8 @@ gnucash_sheet_insert_cb (GtkWidget *widget,
retval = gnc_table_modify_update (table, virt_loc, retval = gnc_table_modify_update (table, virt_loc,
change_text_w, change_text_len, change_text_w, change_text_len,
new_text_w, new_text_len, new_text_w, new_text_len,
position, &start_sel, &end_sel); position, &start_sel, &end_sel,
&sheet->input_cancelled);
if (retval && if (retval &&
((safe_strcmp (retval, new_text) != 0) || ((safe_strcmp (retval, new_text) != 0) ||
@ -890,7 +898,8 @@ gnucash_sheet_delete_cb (GtkWidget *widget,
NULL, 0, NULL, 0,
new_text_w, new_text_len, new_text_w, new_text_len,
&cursor_position, &cursor_position,
&start_sel, &end_sel); &start_sel, &end_sel,
&sheet->input_cancelled);
if (retval && (safe_strcmp (retval, new_text) != 0)) if (retval && (safe_strcmp (retval, new_text) != 0))
{ {
@ -1583,8 +1592,12 @@ gnucash_sheet_key_press_event (GtkWidget *widget, GdkEventKey *event)
end_sel = 0; end_sel = 0;
} }
sheet->input_cancelled = FALSE;
result = gtk_widget_event (sheet->entry, (GdkEvent *) event); result = gtk_widget_event (sheet->entry, (GdkEvent *) event);
sheet->input_cancelled = FALSE;
new_pos = editable->current_pos; new_pos = editable->current_pos;
if (extend_selection && set_selection) if (extend_selection && set_selection)
@ -2052,6 +2065,8 @@ gnucash_sheet_init (GnucashSheet *sheet)
sheet->num_visible_blocks = 1; sheet->num_visible_blocks = 1;
sheet->num_visible_phys_rows = 1; sheet->num_visible_phys_rows = 1;
sheet->input_cancelled = FALSE;
sheet->num_virt_rows = 0; sheet->num_virt_rows = 0;
sheet->num_virt_cols = 0; sheet->num_virt_cols = 0;
sheet->item_editor = NULL; sheet->item_editor = NULL;

View File

@ -84,6 +84,8 @@ typedef struct
GnomeCanvasItem *item_editor; GnomeCanvasItem *item_editor;
GtkWidget *entry; GtkWidget *entry;
gboolean input_cancelled;
gint top_block; /* maybe not fully visible */ gint top_block; /* maybe not fully visible */
gint bottom_block; gint bottom_block;
gint left_block; gint left_block;

View File

@ -33,6 +33,8 @@
* Copyright (c) 2000 Dave Peticolas * Copyright (c) 2000 Dave Peticolas
*/ */
#include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -95,7 +97,8 @@ RecnEnter (BasicCell *_cell,
const char *message = _("Do you really want to mark this transaction " const char *message = _("Do you really want to mark this transaction "
"not reconciled?\nDoing so might make future " "not reconciled?\nDoing so might make future "
"reconciliation difficult!"); "reconciliation difficult!");
if (!gnc_verify_dialog(message, TRUE))
if (!gnc_verify_dialog_parented (cell->parent, message, TRUE))
return FALSE; return FALSE;
} }
@ -173,6 +176,9 @@ RecnSetValue (BasicCell *_cell, const char *value)
void void
xaccDestroyRecnCell (RecnCell *cell) xaccDestroyRecnCell (RecnCell *cell)
{ {
if (!cell)
return;
xaccDestroyBasicCell (&cell->cell); xaccDestroyBasicCell (&cell->cell);
} }
@ -183,6 +189,8 @@ xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag)
{ {
const char *string; const char *string;
g_return_if_fail (cell != NULL);
cell->reconciled_flag = reconciled_flag; cell->reconciled_flag = reconciled_flag;
string = RecnCellGetString (reconciled_flag); string = RecnCellGetString (reconciled_flag);
@ -195,6 +203,8 @@ xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag)
char char
xaccRecnCellGetFlag (RecnCell *cell) xaccRecnCellGetFlag (RecnCell *cell)
{ {
g_return_val_if_fail (cell != NULL, NREC);
return cell->reconciled_flag; return cell->reconciled_flag;
} }
@ -206,4 +216,14 @@ xaccRecnCellSetStringGetter (RecnCellStringGetter getter)
string_getter = getter; string_getter = getter;
} }
/* ================================================ */
void
xaccRecnCellSetParent (RecnCell *cell, gncUIWidget parent)
{
g_return_if_fail (cell != NULL);
cell->parent = parent;
}
/* --------------- end of file ---------------------- */ /* --------------- end of file ---------------------- */

View File

@ -41,6 +41,7 @@
#define __RECN_CELL_C__ #define __RECN_CELL_C__
#include "basiccell.h" #include "basiccell.h"
#include "gnc-ui.h"
typedef const char * (*RecnCellStringGetter)(char); typedef const char * (*RecnCellStringGetter)(char);
@ -49,6 +50,7 @@ typedef struct _RecnCell
BasicCell cell; BasicCell cell;
char reconciled_flag; /* The actual flag value */ char reconciled_flag; /* The actual flag value */
gncUIWidget parent;
} RecnCell; } RecnCell;
RecnCell * xaccMallocRecnCell (void); RecnCell * xaccMallocRecnCell (void);
@ -57,6 +59,8 @@ void xaccDestroyRecnCell (RecnCell *cell);
void xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag); void xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag);
char xaccRecnCellGetFlag (RecnCell *cell); char xaccRecnCellGetFlag (RecnCell *cell);
void xaccRecnCellSetParent (RecnCell *cell, gncUIWidget parent);
void xaccRecnCellSetStringGetter (RecnCellStringGetter getter); void xaccRecnCellSetStringGetter (RecnCellStringGetter getter);

View File

@ -141,12 +141,7 @@ xaccInitSplitRegister (SplitRegister *reg,
SplitRegisterType type, SplitRegisterType type,
SplitRegisterStyle style, SplitRegisterStyle style,
gboolean use_double_line, gboolean use_double_line,
TableGetEntryHandler entry_handler, TableView *view,
TableGetLabelHandler label_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
TableGetCellBorderHandler cell_border_handler,
VirtCellDataAllocator allocator, VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator, VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy); VirtCellDataCopy copy);
@ -555,20 +550,19 @@ SplitRegister *
xaccMallocSplitRegister (SplitRegisterType type, xaccMallocSplitRegister (SplitRegisterType type,
SplitRegisterStyle style, SplitRegisterStyle style,
gboolean use_double_line, gboolean use_double_line,
TableGetEntryHandler entry_handler, TableView *view,
TableGetLabelHandler label_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
TableGetCellBorderHandler cell_border_handler,
VirtCellDataAllocator allocator, VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator, VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy) VirtCellDataCopy copy)
{ {
SplitRegister * reg; SplitRegister * reg;
g_return_val_if_fail (view != NULL, NULL);
reg = g_new0 (SplitRegister, 1); reg = g_new0 (SplitRegister, 1);
view->handler_user_data = reg;
if (type >= NUM_SINGLE_REGISTER_TYPES) if (type >= NUM_SINGLE_REGISTER_TYPES)
style = REG_STYLE_JOURNAL; style = REG_STYLE_JOURNAL;
@ -576,12 +570,7 @@ xaccMallocSplitRegister (SplitRegisterType type,
type, type,
style, style,
use_double_line, use_double_line,
entry_handler, view,
label_handler,
io_flag_handler,
fg_color_handler,
bg_color_handler,
cell_border_handler,
allocator, allocator,
deallocator, deallocator,
copy); copy);
@ -659,12 +648,7 @@ xaccInitSplitRegister (SplitRegister *reg,
SplitRegisterType type, SplitRegisterType type,
SplitRegisterStyle style, SplitRegisterStyle style,
gboolean use_double_line, gboolean use_double_line,
TableGetEntryHandler entry_handler, TableView *view,
TableGetLabelHandler label_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
TableGetCellBorderHandler cell_border_handler,
VirtCellDataAllocator allocator, VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator, VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy) VirtCellDataCopy copy)
@ -817,16 +801,7 @@ xaccInitSplitRegister (SplitRegister *reg,
/* add menu items for the action cell */ /* add menu items for the action cell */
configAction (reg); configAction (reg);
table = gnc_table_new (entry_handler, table = gnc_table_new (view, allocator, deallocator, copy);
label_handler,
io_flag_handler,
fg_color_handler,
bg_color_handler,
cell_border_handler,
reg,
allocator,
deallocator,
copy);
reg->table = table; reg->table = table;

View File

@ -233,12 +233,7 @@ SplitRegister *
xaccMallocSplitRegister (SplitRegisterType type, xaccMallocSplitRegister (SplitRegisterType type,
SplitRegisterStyle style, SplitRegisterStyle style,
gboolean use_double_line, gboolean use_double_line,
TableGetEntryHandler entry_handler, TableView *view,
TableGetLabelHandler label_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
TableGetCellBorderHandler cell_border_handler,
VirtCellDataAllocator allocator, VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator, VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy); VirtCellDataCopy copy);

View File

@ -61,30 +61,20 @@ static void gnc_table_resize (Table * table, int virt_rows, int virt_cols);
/** Implementation *****************************************************/ /** Implementation *****************************************************/
Table * Table *
gnc_table_new (TableGetEntryHandler entry_handler, gnc_table_new (TableView *view,
TableGetLabelHandler label_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
TableGetCellBorderHandler cell_border_handler,
gpointer handler_user_data,
VirtCellDataAllocator allocator, VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator, VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy) VirtCellDataCopy copy)
{ {
Table *table; Table *table;
g_assert (entry_handler != NULL); g_return_val_if_fail (view != NULL, NULL);
g_return_val_if_fail (view->entry_handler, NULL);
table = g_new0 (Table, 1); table = g_new0 (Table, 1);
table->entry_handler = entry_handler; table->view = *view;
table->label_handler = label_handler;
table->io_flag_handler = io_flag_handler;
table->fg_color_handler = fg_color_handler;
table->bg_color_handler = bg_color_handler;
table->cell_border_handler = cell_border_handler;
table->handler_user_data = handler_user_data;
table->vcell_data_allocator = allocator; table->vcell_data_allocator = allocator;
table->vcell_data_deallocator = deallocator; table->vcell_data_deallocator = deallocator;
table->vcell_data_copy = copy; table->vcell_data_copy = copy;
@ -180,9 +170,9 @@ gnc_table_get_entry_internal (Table *table, VirtualLocation virt_loc,
{ {
const char *entry; const char *entry;
entry = table->entry_handler (virt_loc, entry = table->view.entry_handler (virt_loc,
conditionally_changed, conditionally_changed,
table->handler_user_data); table->view.handler_user_data);
if (!entry) if (!entry)
entry = ""; entry = "";
@ -219,7 +209,8 @@ gnc_table_get_entry (Table *table, VirtualLocation virt_loc)
return cb_cell->cell->value; return cb_cell->cell->value;
} }
entry = table->entry_handler (virt_loc, NULL, table->handler_user_data); entry = table->view.entry_handler (virt_loc, NULL,
table->view.handler_user_data);
if (!entry) if (!entry)
entry = ""; entry = "";
@ -231,10 +222,10 @@ gnc_table_get_entry (Table *table, VirtualLocation virt_loc)
CellIOFlags CellIOFlags
gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc) gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc)
{ {
if (!table->io_flag_handler) if (!table->view.io_flag_handler)
return XACC_CELL_ALLOW_NONE; return XACC_CELL_ALLOW_NONE;
return table->io_flag_handler (virt_loc, table->handler_user_data); return table->view.io_flag_handler (virt_loc, table->view.handler_user_data);
} }
/* ==================================================== */ /* ==================================================== */
@ -242,10 +233,10 @@ gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc)
const char * const char *
gnc_table_get_label (Table *table, VirtualLocation virt_loc) gnc_table_get_label (Table *table, VirtualLocation virt_loc)
{ {
if (!table->label_handler) if (!table->view.label_handler)
return ""; return "";
return table->label_handler (virt_loc, table->handler_user_data); return table->view.label_handler (virt_loc, table->view.handler_user_data);
} }
/* ==================================================== */ /* ==================================================== */
@ -253,10 +244,11 @@ gnc_table_get_label (Table *table, VirtualLocation virt_loc)
guint32 guint32
gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc) gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc)
{ {
if (!table->fg_color_handler) if (!table->view.fg_color_handler)
return 0x0; /* black */ return 0x0; /* black */
return table->fg_color_handler (virt_loc, table->handler_user_data); return table->view.fg_color_handler (virt_loc,
table->view.handler_user_data);
} }
/* ==================================================== */ /* ==================================================== */
@ -265,11 +257,11 @@ guint32
gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc, gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc,
gboolean *hatching) gboolean *hatching)
{ {
if (!table->bg_color_handler) if (!table->view.bg_color_handler)
return 0xffffff; /* white */ return 0xffffff; /* white */
return table->bg_color_handler (virt_loc, hatching, return table->view.bg_color_handler (virt_loc, hatching,
table->handler_user_data); table->view.handler_user_data);
} }
/* ==================================================== */ /* ==================================================== */
@ -278,10 +270,11 @@ void
gnc_table_get_borders (Table *table, VirtualLocation virt_loc, gnc_table_get_borders (Table *table, VirtualLocation virt_loc,
PhysicalCellBorders *borders) PhysicalCellBorders *borders)
{ {
if (!table->cell_border_handler) if (!table->view.cell_border_handler)
return; return;
table->cell_border_handler (virt_loc, borders, table->handler_user_data); table->view.cell_border_handler (virt_loc, borders,
table->view.handler_user_data);
} }
/* ==================================================== */ /* ==================================================== */
@ -713,7 +706,7 @@ gnc_table_verify_cursor_position (Table *table, VirtualLocation virt_loc)
/* ==================================================== */ /* ==================================================== */
void * gpointer
gnc_table_get_vcell_data (Table *table, VirtualCellLocation vcell_loc) gnc_table_get_vcell_data (Table *table, VirtualCellLocation vcell_loc)
{ {
VirtualCell *vcell; VirtualCell *vcell;
@ -969,7 +962,8 @@ gnc_table_modify_update(Table *table,
int newval_len, int newval_len,
int *cursor_position, int *cursor_position,
int *start_selection, int *start_selection,
int *end_selection) int *end_selection,
gboolean *cancelled)
{ {
gboolean changed = FALSE; gboolean changed = FALSE;
CellModifyVerifyFunc mv; CellModifyVerifyFunc mv;
@ -990,6 +984,19 @@ gnc_table_modify_update(Table *table,
ENTER ("\n"); ENTER ("\n");
if (table->view.confirm_handler &&
! (table->view.confirm_handler (virt_loc,
table->view.handler_user_data)))
{
if (cancelled)
*cancelled = TRUE;
return NULL;
}
if (cancelled)
*cancelled = FALSE;
/* OK, if there is a callback for this cell, call it */ /* OK, if there is a callback for this cell, call it */
cb_cell = gnc_cellblock_get_cell (cb, cell_row, cell_col); cb_cell = gnc_cellblock_get_cell (cb, cell_row, cell_col);
cell = cb_cell->cell; cell = cb_cell->cell;
@ -1045,7 +1052,7 @@ gnc_table_direct_update(Table *table,
int *cursor_position, int *cursor_position,
int *start_selection, int *start_selection,
int *end_selection, int *end_selection,
void *gui_data) gpointer gui_data)
{ {
CellBlockCell *cb_cell; CellBlockCell *cb_cell;
gboolean result; gboolean result;
@ -1077,10 +1084,21 @@ gnc_table_direct_update(Table *table,
end_selection, gui_data); end_selection, gui_data);
if (safe_strcmp (old_value, cell->value) != 0) if (safe_strcmp (old_value, cell->value) != 0)
{
if (table->view.confirm_handler &&
! (table->view.confirm_handler (virt_loc,
table->view.handler_user_data)))
{
xaccSetBasicCellValue (cell, old_value);
*newval_ptr = NULL;
result = TRUE;
}
else
{ {
cell->changed = GNC_CELL_CHANGED; cell->changed = GNC_CELL_CHANGED;
*newval_ptr = cell->value; *newval_ptr = cell->value;
} }
}
else else
*newval_ptr = NULL; *newval_ptr = NULL;

View File

@ -184,6 +184,22 @@ typedef void (*TableGetCellBorderHandler) (VirtualLocation virt_loc,
PhysicalCellBorders *borders, PhysicalCellBorders *borders,
gpointer user_data); gpointer user_data);
typedef gboolean (*TableConfirmHandler) (VirtualLocation virt_loc,
gpointer user_data);
typedef struct
{
TableGetEntryHandler entry_handler;
TableGetLabelHandler label_handler;
TableGetCellIOFlags io_flag_handler;
TableGetFGColorHandler fg_color_handler;
TableGetBGColorHandler bg_color_handler;
TableGetCellBorderHandler cell_border_handler;
TableConfirmHandler confirm_handler;
gpointer handler_user_data;
} TableView;
typedef gpointer (*VirtCellDataAllocator) (void); typedef gpointer (*VirtCellDataAllocator) (void);
typedef void (*VirtCellDataDeallocator) (gpointer user_data); typedef void (*VirtCellDataDeallocator) (gpointer user_data);
typedef void (*VirtCellDataCopy) (gpointer to, gconstpointer from); typedef void (*VirtCellDataCopy) (gpointer to, gconstpointer from);
@ -210,7 +226,7 @@ struct _Table
/* This value is initialized to NULL and never touched afterwards. /* This value is initialized to NULL and never touched afterwards.
* It can be used by higher-level code. */ * It can be used by higher-level code. */
void * user_data; gpointer user_data;
/* Determines whether the passive background /* Determines whether the passive background
* colors alternate between odd and even virt * colors alternate between odd and even virt
@ -229,16 +245,9 @@ struct _Table
/* The virtual cell table */ /* The virtual cell table */
GTable *virt_cells; GTable *virt_cells;
void * ui_data; gpointer ui_data;
TableGetEntryHandler entry_handler; TableView view;
TableGetLabelHandler label_handler;
TableGetCellIOFlags io_flag_handler;
TableGetFGColorHandler fg_color_handler;
TableGetBGColorHandler bg_color_handler;
TableGetCellBorderHandler cell_border_handler;
gpointer handler_user_data;
TableDestroyFunc destroy; TableDestroyFunc destroy;
@ -249,13 +258,7 @@ struct _Table
/* Functions to create and destroy Tables. */ /* Functions to create and destroy Tables. */
Table * gnc_table_new (TableGetEntryHandler entry_handler, Table * gnc_table_new (TableView *view,
TableGetLabelHandler label_handler,
TableGetCellIOFlags io_flag_handler,
TableGetFGColorHandler fg_color_handler,
TableGetBGColorHandler bg_color_handler,
TableGetCellBorderHandler cell_border_handler,
gpointer handler_user_data,
VirtCellDataAllocator allocator, VirtCellDataAllocator allocator,
VirtCellDataDeallocator deallocator, VirtCellDataDeallocator deallocator,
VirtCellDataCopy copy); VirtCellDataCopy copy);
@ -377,7 +380,7 @@ gboolean gnc_table_find_close_valid_cell (Table *table,
/* UI-specific functions */ /* UI-specific functions */
/* Initialize the GUI from a table */ /* Initialize the GUI from a table */
void gnc_table_init_gui (gncUIWidget widget, void *data); void gnc_table_init_gui (gncUIWidget widget, gpointer data);
/* Refresh the current cursor gui */ /* Refresh the current cursor gui */
void gnc_table_refresh_current_cursor_gui (Table * table, void gnc_table_refresh_current_cursor_gui (Table * table,
@ -424,7 +427,8 @@ const char * gnc_table_modify_update(Table *table,
int newval_len, int newval_len,
int *cursor_position, int *cursor_position,
int *start_selection, int *start_selection,
int *end_selection); int *end_selection,
gboolean *cancelled);
gboolean gnc_table_direct_update(Table *table, gboolean gnc_table_direct_update(Table *table,
VirtualLocation virt_loc, VirtualLocation virt_loc,
@ -432,7 +436,7 @@ gboolean gnc_table_direct_update(Table *table,
int *cursor_position, int *cursor_position,
int *start_selection, int *start_selection,
int *end_selection, int *end_selection,
void *gui_data); gpointer gui_data);
gboolean gnc_table_traverse_update(Table *table, gboolean gnc_table_traverse_update(Table *table,
VirtualLocation virt_loc, VirtualLocation virt_loc,