diff --git a/ChangeLog b/ChangeLog index 873cc5b15c..d44b2a10ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,53 @@ +2001-07-21 Dave Peticolas + + * src/register/cell-factory.[ch]: a new object for creation of + register cells. allows new cell types to be added dynamically. + + * src/register/gnome/gnucash-style.c: fix for removal of + label from cellblock cells. + + * src/register/table-allgui.[ch]: fix for changed flag and + callback changes. + + * src/register/splitreg.[ch]: remove fixed cells, use a dynamic + list. Fix code appropriately. + + * src/register/register-common.[ch]: add wrapper for a global cell + factory. + + * src/register/gnome/datecell-gnome.c: same as below + + * src/register/gnome/combocell-gnome.c: same as below + + * src/register/textcell.[ch]: same as below + + * src/register/recncell.[ch]: same as below + + * src/register/quickfillcell.[ch]: same as below + + * src/register/pricecell.[ch]: same as below + + * src/register/numcell.[ch]: same as below + + * src/register/datecell.h: same as below + + * src/register/combocell.h: make destructor private. + constructor returns 'BasicCell *'. + + * src/register/cellblock.[ch]: remove 'label' members -- no longer + used. + + * src/register/basiccell.[ch]: 'virtualize' destructor. + simplify changed flags. + + * src/register/Makefile.am (SUBDIRS): add cell-factory.[ch] + + * src/gnome/gnc-html.c: fix includes + + * src/SplitLedger.c: update for api changes + + * src/MultiLedger.c: update for api changes + 2001-07-20 James LewisMoss * src/gnome/top-level.c (gnucash_ui_init): remove the \n's frome diff --git a/src/MultiLedger.c b/src/MultiLedger.c index d6f0e7785f..b4bc470352 100644 --- a/src/MultiLedger.c +++ b/src/MultiLedger.c @@ -820,8 +820,7 @@ xaccLedgerDisplayInternal (Account *lead_account, Query *q, model.cell_data_deallocator = xaccMLGUIDFree; model.cell_data_copy = xaccMLGUIDCopy; - ld->reg = xaccMallocSplitRegister (reg_type, style, FALSE, &model, - templateMode); + ld->reg = gnc_register_new (reg_type, style, FALSE, &model, templateMode); xaccSRSetData (ld->reg, ld, xaccLedgerDisplayParent, xaccLedgerDisplaySetHelp); diff --git a/src/SplitLedger.c b/src/SplitLedger.c index f374cdfff7..05df872362 100644 --- a/src/SplitLedger.c +++ b/src/SplitLedger.c @@ -111,6 +111,8 @@ #include "MultiLedger.h" #include "Scrub.h" #include "SplitLedger.h" +#include "combocell.h" +#include "datecell.h" #include "global-options.h" #include "gnc-component-manager.h" #include "gnc-engine-util.h" @@ -118,6 +120,10 @@ #include "gnc-ui.h" #include "guile-util.h" #include "messages.h" +#include "numcell.h" +#include "pricecell.h" +#include "quickfillcell.h" +#include "recncell.h" #include "splitreg.h" #include "table-allgui.h" @@ -195,7 +201,6 @@ struct _SRInfo /* hook to set help string */ SRSetHelpCallback set_help; - }; @@ -231,8 +236,8 @@ static Transaction * xaccSRGetTrans (SplitRegister *reg, VirtualCellLocation vcell_loc); static Split * xaccSRGetCurrentTransSplit (SplitRegister *reg, VirtualCellLocation *vcell_loc); -static void xaccSRActuallySaveChangedCells (SplitRegister *reg, Transaction *trans, - Split *split, guint32 changed ); +static void xaccSRActuallySaveChangedCells (SplitRegister *reg, + Transaction *trans, Split *split); static void xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split); static void xaccSRSaveChangedTemplateCells (SplitRegister *reg, @@ -250,8 +255,7 @@ static void xaccSRSetTransVisible (SplitRegister *reg, gboolean only_blank_split); static gboolean trans_has_reconciled_splits (Transaction *trans); static void sr_set_last_num (SplitRegister *reg, const char *num); -static guint32 sr_split_auto_calc (SplitRegister *reg, Split *split, - guint32 changed); +static void sr_split_auto_calc (SplitRegister *reg, Split *split); /** implementations *******************************************************/ @@ -613,6 +617,7 @@ sr_set_cell_fractions (SplitRegister *reg, Split *split) Account *account; Transaction *trans; gnc_commodity *currency; + PriceCell *cell; int fraction; trans = xaccSplitGetParent (split); @@ -622,19 +627,23 @@ sr_set_cell_fractions (SplitRegister *reg, Split *split) fraction = gnc_commodity_get_fraction (currency); - xaccSetPriceCellFraction (reg->debitCell, fraction); - xaccSetPriceCellFraction (reg->creditCell, fraction); + cell = (PriceCell *) gnc_register_get_cell (reg, DEBT_CELL); + xaccSetPriceCellFraction (cell, fraction); + + cell = (PriceCell *) gnc_register_get_cell (reg, CRED_CELL); + xaccSetPriceCellFraction (cell, fraction); account = xaccSplitGetAccount (split); if (account == NULL) account = sr_get_default_account (reg); + cell = (PriceCell *) gnc_register_get_cell (reg, SHRS_CELL); + if (account) - xaccSetPriceCellFraction (reg->sharesCell, - xaccAccountGetCommoditySCU (account)); + xaccSetPriceCellFraction (cell, xaccAccountGetCommoditySCU (account)); else - xaccSetPriceCellFraction (reg->sharesCell, 10000); + xaccSetPriceCellFraction (cell, 100000); } static CellBlock * @@ -1147,7 +1156,7 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, CellType cell_type; Transaction *trans; gnc_numeric amount; - guint32 changed; + BasicCell *cell; Split *split; /* auto-completion is only triggered by a tab out */ @@ -1161,14 +1170,12 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, cursor_class = xaccSplitRegisterGetCurrentCursorClass (reg); cell_type = xaccSplitRegisterGetCurrentCellType (reg); - changed = xaccSplitRegisterGetChangeFlag (reg); - changed |= xaccSplitRegisterGetConditionalChangeFlag (reg); switch (cursor_class) { case CURSOR_CLASS_TRANS: { Transaction *auto_trans; - char *desc; + const char *desc; /* there must be a blank transaction * */ if (blank_trans == NULL) @@ -1183,15 +1190,22 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, return FALSE; /* nothing but the date, num, and description should be changed */ - if ((changed & ~(MOD_DATE | MOD_NUM | MOD_DESC)) != 0) + if (gnc_register_get_cell_changed (reg, XFRM_CELL, TRUE) || + gnc_register_get_cell_changed (reg, MXFRM_CELL, TRUE) || + gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE) || + gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE) || + gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE) || + gnc_register_get_cell_changed (reg, NOTES_CELL, TRUE) || + gnc_register_get_cell_changed (reg, RECN_CELL, TRUE)) return FALSE; /* and the description should be changed */ - if ((changed & MOD_DESC) == 0) + if (!gnc_register_get_cell_changed (reg, DESC_CELL, TRUE)) return FALSE; /* to a non-empty value */ - desc = reg->descCell->cell.value; + desc = gnc_register_get_cell_value (reg, DESC_CELL); if ((desc == NULL) || (*desc == '\0')) return FALSE; @@ -1218,15 +1232,13 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, if (sr_get_default_account (reg) != NULL) { Account *default_account = sr_get_default_account (reg); - int num_splits; - int i; + GList *node; blank_split = NULL; - num_splits = xaccTransCountSplits(trans); - for (i = 0; i < num_splits; i++) + for (node = xaccTransGetSplitList (trans); node; node = node->next) { - Split *s = xaccTransGetSplit(trans, i); + Split *s = node->data; if (default_account == xaccSplitGetAccount(s)) { @@ -1257,11 +1269,10 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, info->blank_split_edited = TRUE; - if ( reg->template ) { - xaccSRSaveChangedTemplateCells( reg, trans, blank_split ); - } else { - xaccSRSaveChangedCells(reg, trans, blank_split); - } + if ( reg->template ) + xaccSRSaveChangedTemplateCells( reg, trans, blank_split ); + else + xaccSRSaveChangedCells(reg, trans, blank_split); gnc_resume_gui_refresh (); @@ -1276,7 +1287,8 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, break; case CURSOR_CLASS_SPLIT: { - char *memo, *fullname; + char *fullname; + const char *memo; gboolean unit_price; Split *auto_split; @@ -1288,16 +1300,20 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, if (cell_type != MEMO_CELL) return FALSE; - /* nothing but the action memo, and amounts should be changed */ - if ((changed & ~(MOD_ACTN | MOD_MEMO | MOD_AMNT)) != 0) + /* nothing but the action, memo, and amounts should be changed */ + if (gnc_register_get_cell_changed (reg, XFRM_CELL, TRUE) || + gnc_register_get_cell_changed (reg, MXFRM_CELL, TRUE) || + gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE) || + gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE) || + gnc_register_get_cell_changed (reg, RECN_CELL, TRUE)) return FALSE; /* and the memo should be changed */ - if ((changed & MOD_MEMO) == 0) + if (!gnc_register_get_cell_changed (reg, MEMO_CELL, TRUE)) return FALSE; /* to a non-empty value */ - memo = reg->memoCell->cell.value; + memo = gnc_register_get_cell_value (reg, MEMO_CELL); if ((memo == NULL) || (*memo == '\0')) return FALSE; @@ -1322,25 +1338,39 @@ LedgerAutoCompletion(SplitRegister *reg, gncTableTraversalDir dir, /* the auto-complete code below is taken from xaccSRGetEntryHandler */ /* auto-complete the action field if it wasn't changed */ - if (!(MOD_ACTN & changed)) - xaccSetComboCellValue (reg->actionCell, + if (!gnc_register_get_cell_changed (reg, ACTN_CELL, TRUE)) + { + cell = gnc_register_get_cell (reg, ACTN_CELL); + xaccSetComboCellValue ((ComboCell *) cell, xaccSplitGetAction (auto_split)); + } /* auto-complete the account name */ + cell = gnc_register_get_cell (reg, XFRM_CELL); + fullname = xaccAccountGetFullName (xaccSplitGetAccount (auto_split), account_separator); - xaccSetComboCellValue (reg->xfrmCell, fullname); + xaccSetComboCellValue ((ComboCell *) cell, fullname); g_free(fullname); - xaccBasicCellSetChanged(&(reg->xfrmCell->cell), TRUE); + gnc_basic_cell_set_changed (cell, TRUE); - if (!(changed & MOD_AMNT)) + if (!gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) && + !gnc_register_get_cell_changed (reg, CRED_CELL, TRUE)) { + BasicCell *debit_cell; + BasicCell *credit_cell; + amount = xaccSplitGetValue (auto_split); - xaccSetDebCredCellValue (reg->debitCell, reg->creditCell, amount); - xaccBasicCellSetChanged (&(reg->debitCell->cell), TRUE); - xaccBasicCellSetChanged (&(reg->creditCell->cell), TRUE); + debit_cell = gnc_register_get_cell (reg, DEBT_CELL); + credit_cell = gnc_register_get_cell (reg, CRED_CELL); + + xaccSetDebCredCellValue ((PriceCell *) debit_cell, + (PriceCell *) credit_cell, amount); + + gnc_basic_cell_set_changed (debit_cell, TRUE); + gnc_basic_cell_set_changed (credit_cell, TRUE); } /* and refresh the gui */ @@ -1381,7 +1411,7 @@ LedgerTraverse (Table *table, VirtualLocation virt_loc = *p_new_virt_loc; Transaction *trans, *new_trans; GNCVerifyResult result; - guint32 changed; + gboolean changed; Split *split; if (info->first_pass) @@ -1395,7 +1425,7 @@ LedgerTraverse (Table *table, return FALSE; /* no changes, make sure we aren't going off the end */ - changed = xaccSplitRegisterGetChangeFlag (reg); + changed = gnc_register_get_cursor_changed (reg, FALSE); if (!changed && (pending_trans != trans)) { gnc_table_find_close_valid_cell (table, &virt_loc, info->exact_traversal); @@ -1424,13 +1454,13 @@ LedgerTraverse (Table *table, switch (cell_type) { case XFRM_CELL: - if (changed & MOD_XFRM) - cell = reg->xfrmCell; + if (gnc_register_get_cell_changed (reg, XFRM_CELL, FALSE)) + cell = (ComboCell *) gnc_register_get_cell (reg, XFRM_CELL); break; case MXFRM_CELL: - if (changed & MOD_MXFRM) - cell = reg->mxfrmCell; + if (gnc_register_get_cell_changed (reg, MXFRM_CELL, FALSE)) + cell = (ComboCell *) gnc_register_get_cell (reg, MXFRM_CELL); break; default: @@ -1476,7 +1506,7 @@ LedgerTraverse (Table *table, name = xaccAccountGetFullName (account, account_separator); xaccSetComboCellValue (cell, name); - xaccBasicCellSetChanged (&cell->cell, TRUE); + gnc_basic_cell_set_changed (&cell->cell, TRUE); g_free (name); } while (FALSE); @@ -1985,7 +2015,7 @@ xaccSRDuplicateCurrent (SplitRegister *reg) Transaction *trans; Split *return_split; Split *trans_split; - guint32 changed; + gboolean changed; Split *split; split = xaccSRGetCurrentSplit(reg); @@ -2006,7 +2036,7 @@ xaccSRDuplicateCurrent (SplitRegister *reg) if ((split == NULL) && (cursor_class == CURSOR_CLASS_TRANS)) return NULL; - changed = xaccSplitRegisterGetChangeFlag (reg); + changed = gnc_register_get_cursor_changed (reg, FALSE); /* See if we were asked to duplicate an unchanged blank split. * There's no point in doing that! */ @@ -2110,7 +2140,8 @@ xaccSRDuplicateCurrent (SplitRegister *reg) xaccTransSetNum (new_trans, out_num); xaccTransCommitEdit (new_trans); - if (xaccSetNumCellLastNum (reg->numCell, out_num)) + if (xaccSetNumCellLastNum ((NumCell *) + gnc_register_get_cell (reg, NUM_CELL), out_num)) sr_set_last_num (reg, out_num); g_free (out_num); @@ -2145,7 +2176,7 @@ xaccSRCopyCurrentInternal (SplitRegister *reg, gboolean use_cut_semantics) Split *blank_split = xaccSplitLookup(&info->blank_split_guid); CursorClass cursor_class; Transaction *trans; - guint32 changed; + gboolean changed; Split *split; SCM new_item; @@ -2166,7 +2197,7 @@ xaccSRCopyCurrentInternal (SplitRegister *reg, gboolean use_cut_semantics) if ((split == NULL) && (cursor_class == CURSOR_CLASS_TRANS)) return; - changed = xaccSplitRegisterGetChangeFlag(reg); + changed = gnc_register_get_cursor_changed (reg, FALSE); /* See if we were asked to copy an unchanged blank split. Don't. */ if (!changed && ((split == NULL) || (split == blank_split))) @@ -2243,7 +2274,7 @@ xaccSRCutCurrent (SplitRegister *reg) Split *blank_split = xaccSplitLookup(&info->blank_split_guid); CursorClass cursor_class; Transaction *trans; - guint32 changed; + gboolean changed; Split *split; split = xaccSRGetCurrentSplit(reg); @@ -2263,7 +2294,7 @@ xaccSRCutCurrent (SplitRegister *reg) if ((split == NULL) && (cursor_class == CURSOR_CLASS_TRANS)) return; - changed = xaccSplitRegisterGetChangeFlag(reg); + changed = gnc_register_get_cursor_changed (reg, FALSE); /* See if we were asked to cut an unchanged blank split. Don't. */ if (!changed && ((split == NULL) || (split == blank_split))) @@ -2598,7 +2629,6 @@ xaccSREmptyCurrentTrans (SplitRegister *reg) void xaccSRCancelCursorSplitChanges (SplitRegister *reg) { - guint32 changed; VirtualLocation virt_loc; if (reg == NULL) @@ -2606,13 +2636,12 @@ xaccSRCancelCursorSplitChanges (SplitRegister *reg) virt_loc = reg->table->current_cursor_loc; - changed = xaccSplitRegisterGetChangeFlag (reg); - if (!changed) + if (!gnc_register_get_cursor_changed (reg, FALSE)) return; /* We're just cancelling the current split here, not the transaction. * When cancelling edits, reload the cursor from the transaction. */ - xaccSplitRegisterClearChangeFlag (reg); + gnc_register_clear_changes (reg); if (gnc_table_find_close_valid_cell (reg->table, &virt_loc, FALSE)) gnc_table_move_cursor_gui (reg->table, virt_loc); @@ -2669,70 +2698,101 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm, { SCM other_split_scm = SCM_UNDEFINED; Transaction *trans; - guint32 changed; /* use the changed flag to avoid heavy-weight updates * of the split & transaction fields. This will help * cut down on uneccessary register redraws. */ - changed = xaccSplitRegisterGetChangeFlag (reg); - if (!changed) + if (!gnc_register_get_cursor_changed (reg, FALSE)) return FALSE; - changed |= xaccSplitRegisterGetConditionalChangeFlag (reg); - /* get the handle to the current split and transaction */ trans = xaccSRGetCurrentTrans (reg); if (trans == NULL) return FALSE; /* copy the contents from the cursor to the split */ - if (MOD_DATE & changed) + if (gnc_register_get_cell_changed (reg, DATE_CELL, TRUE)) { + BasicCell *cell; Timespec ts; - xaccDateCellGetDate(reg->dateCell, &ts); + cell = gnc_register_get_cell (reg, DATE_CELL); + xaccDateCellGetDate((DateCell *) cell, &ts); + gnc_trans_scm_set_date(trans_scm, &ts); } - if (MOD_NUM & changed) - gnc_trans_scm_set_num(trans_scm, reg->numCell->cell.value); + if (gnc_register_get_cell_changed (reg, NUM_CELL, TRUE)) + { + const char *value; - if (MOD_DESC & changed) - gnc_trans_scm_set_description(trans_scm, reg->descCell->cell.value); + value = gnc_register_get_cell_value (reg, NUM_CELL); + gnc_trans_scm_set_num (trans_scm, value); + } - if (MOD_NOTES & changed) - gnc_trans_scm_set_notes(trans_scm, reg->notesCell->cell.value); + if (gnc_register_get_cell_changed (reg, DESC_CELL, TRUE)) + { + const char *value; - if (MOD_RECN & changed) - gnc_split_scm_set_reconcile_state(split_scm, - xaccRecnCellGetFlag(reg->recnCell)); + value = gnc_register_get_cell_value (reg, DESC_CELL); + gnc_trans_scm_set_description (trans_scm, value); + } - if (MOD_ACTN & changed) - gnc_split_scm_set_action(split_scm, reg->actionCell->cell.value); + if (gnc_register_get_cell_changed (reg, NOTES_CELL, TRUE)) + { + const char *value; - if (MOD_MEMO & changed) - gnc_split_scm_set_memo(split_scm, reg->memoCell->cell.value); + value = gnc_register_get_cell_value (reg, NOTES_CELL); + gnc_trans_scm_set_notes (trans_scm, value); + } - if (MOD_XFRM & changed) + if (gnc_register_get_cell_changed (reg, RECN_CELL, TRUE)) + { + BasicCell *cell; + char flag; + + cell = gnc_register_get_cell (reg, RECN_CELL); + flag = xaccRecnCellGetFlag ((RecnCell *) cell); + + gnc_split_scm_set_reconcile_state(split_scm, flag); + } + + if (gnc_register_get_cell_changed (reg, ACTN_CELL, TRUE)) + { + const char *value; + + value = gnc_register_get_cell_value (reg, ACTN_CELL); + gnc_split_scm_set_action (split_scm, value); + } + + if (gnc_register_get_cell_changed (reg, MEMO_CELL, TRUE)) + { + const char *value; + + value = gnc_register_get_cell_value (reg, MEMO_CELL); + gnc_split_scm_set_memo (split_scm, value); + } + + if (gnc_register_get_cell_changed (reg, XFRM_CELL, TRUE)) { Account *new_account; - char *new_name; + const char *new_name; - new_name = reg->xfrmCell->cell.value; + new_name = gnc_register_get_cell_value (reg, XFRM_CELL); new_account = xaccGetAccountFromFullName (gncGetCurrentGroup (), new_name, account_separator); if (new_account != NULL) - gnc_split_scm_set_account(split_scm, new_account); + gnc_split_scm_set_account (split_scm, new_account); } if (reg->style == REG_STYLE_LEDGER) - other_split_scm = gnc_trans_scm_get_other_split_scm(trans_scm, split_scm); + other_split_scm = gnc_trans_scm_get_other_split_scm (trans_scm, split_scm); - if (MOD_MXFRM & changed) + if (gnc_register_get_cell_changed (reg, MXFRM_CELL, TRUE)) { - other_split_scm = gnc_trans_scm_get_other_split_scm(trans_scm, split_scm); + other_split_scm = gnc_trans_scm_get_other_split_scm (trans_scm, split_scm); if (other_split_scm == SCM_UNDEFINED) { @@ -2741,52 +2801,68 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm, Split *temp_split; temp_split = xaccMallocSplit (); - other_split_scm = gnc_copy_split(temp_split, use_cut_semantics); - xaccSplitDestroy(temp_split); + other_split_scm = gnc_copy_split (temp_split, use_cut_semantics); + xaccSplitDestroy (temp_split); - gnc_trans_scm_append_split_scm(trans_scm, other_split_scm); + gnc_trans_scm_append_split_scm (trans_scm, other_split_scm); } } if (other_split_scm != SCM_UNDEFINED) { Account *new_account; + const char *name; + + name = gnc_register_get_cell_value (reg, MXFRM_CELL); new_account = xaccGetAccountFromFullName (gncGetCurrentGroup (), - reg->mxfrmCell->cell.value, - account_separator); + name, account_separator); if (new_account != NULL) - gnc_split_scm_set_account(other_split_scm, new_account); + gnc_split_scm_set_account (other_split_scm, new_account); } } - if (MOD_AMNT & changed) + if (gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE)) { + BasicCell *cell; gnc_numeric new_value; gnc_numeric credit; gnc_numeric debit; - credit = xaccGetPriceCellValue (reg->creditCell); - debit = xaccGetPriceCellValue (reg->debitCell); + cell = gnc_register_get_cell (reg, CRED_CELL); + credit = xaccGetPriceCellValue ((PriceCell *) cell); + + cell = gnc_register_get_cell (reg, DEBT_CELL); + debit = xaccGetPriceCellValue ((PriceCell *) cell); + new_value = gnc_numeric_sub_fixed (debit, credit); gnc_split_scm_set_value (split_scm, new_value); } - if (MOD_PRIC & changed) + if (gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE)) { /* do nothing for now */ } - if (MOD_SHRS & changed) + if (gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE)) { - gnc_numeric shares = xaccGetPriceCellValue(reg->sharesCell); + BasicCell *cell; + gnc_numeric shares; + + cell = gnc_register_get_cell (reg, SHRS_CELL); + + shares = xaccGetPriceCellValue ((PriceCell *) cell); gnc_split_scm_set_amount (split_scm, shares); } - if ((MOD_AMNT | MOD_PRIC | MOD_SHRS) & changed) + if (gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE) || + gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE) || + gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE)) { if (other_split_scm != SCM_UNDEFINED) { @@ -2815,10 +2891,9 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit) Transaction *pending_trans = xaccTransLookup(&info->pending_trans_guid); Transaction *blank_trans = xaccSplitGetParent(blank_split); Transaction *trans; - guint32 changed; - Split *split; const char *memo; const char *desc; + Split *split; /* get the handle to the current split and transaction */ split = xaccSRGetCurrentSplit (reg); @@ -2829,8 +2904,7 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit) /* use the changed flag to avoid heavy-weight updates * of the split & transaction fields. This will help * cut down on uneccessary register redraws. */ - changed = xaccSplitRegisterGetChangeFlag (reg); - if (!changed) + if (!gnc_register_get_cursor_changed (reg, FALSE)) { if (!do_commit) return FALSE; @@ -2953,7 +3027,7 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit) } } - xaccSplitRegisterClearChangeFlag (reg); + gnc_register_clear_changes (reg); gnc_resume_gui_refresh (); @@ -2976,13 +3050,17 @@ sr_set_last_num (SplitRegister *reg, const char *num) /* ======================================================== */ -static guint32 -sr_split_auto_calc (SplitRegister *reg, Split *split, guint32 changed) +static void +sr_split_auto_calc (SplitRegister *reg, Split *split) { + PriceCell *cell; gboolean recalc_shares = FALSE; gboolean recalc_price = FALSE; gboolean recalc_value = FALSE; GNCAccountType account_type; + gboolean price_changed; + gboolean amount_changed; + gboolean shares_changed; gnc_numeric calc_value; gnc_numeric value; gnc_numeric price; @@ -3000,22 +3078,40 @@ sr_split_auto_calc (SplitRegister *reg, Split *split, guint32 changed) if (account_type != STOCK && account_type != MUTUAL && account_type != CURRENCY) - return changed; + return; - if (MOD_SHRS & changed) - amount = xaccGetPriceCellValue (reg->sharesCell); + price_changed = gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE); + amount_changed = (gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE)); + shares_changed = gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE); + + if (shares_changed) + { + cell = (PriceCell *) gnc_register_get_cell (reg, SHRS_CELL); + amount = xaccGetPriceCellValue (cell); + } else amount = xaccSplitGetAmount (split); - if (MOD_PRIC & changed) - price = xaccGetPriceCellValue (reg->priceCell); + if (price_changed) + { + cell = (PriceCell *) gnc_register_get_cell (reg, PRIC_CELL); + price = xaccGetPriceCellValue (cell); + } else price = xaccSplitGetSharePrice (split); - if (MOD_AMNT & changed) + if (amount_changed) { - gnc_numeric credit = xaccGetPriceCellValue (reg->creditCell); - gnc_numeric debit = xaccGetPriceCellValue (reg->debitCell); + gnc_numeric credit; + gnc_numeric debit; + + cell = (PriceCell *) gnc_register_get_cell (reg, CRED_CELL); + credit = xaccGetPriceCellValue (cell); + + cell = (PriceCell *) gnc_register_get_cell (reg, DEBT_CELL); + debit = xaccGetPriceCellValue (cell); + value = gnc_numeric_sub_fixed (debit, credit); } else @@ -3045,21 +3141,18 @@ sr_split_auto_calc (SplitRegister *reg, Split *split, guint32 changed) (!recalc_price) && (!recalc_value)) { - if (((MOD_PRIC | MOD_AMNT) & changed) == (MOD_PRIC | MOD_AMNT)) + if (price_changed && amount_changed) { - if (!(MOD_SHRS & changed)) + if (!shares_changed) recalc_shares = TRUE; } - else - if (((MOD_SHRS | MOD_AMNT) & changed) == (MOD_SHRS | MOD_AMNT)) - recalc_price = TRUE; - else - if (((MOD_SHRS | MOD_PRIC) & changed) == (MOD_SHRS | MOD_PRIC)) - recalc_value = TRUE; + else if (amount_changed && shares_changed) + recalc_price = TRUE; + else if (price_changed && shares_changed) + recalc_value = TRUE; } - calc_value = gnc_numeric_mul (price, amount, - GNC_DENOM_AUTO, GNC_DENOM_LCD); + calc_value = gnc_numeric_mul (price, amount, GNC_DENOM_AUTO, GNC_DENOM_LCD); denom = gnc_split_get_value_denom (split); @@ -3081,32 +3174,32 @@ sr_split_auto_calc (SplitRegister *reg, Split *split, guint32 changed) "are inconsistent.\nWhich value would you " "like to have recalculated?"); - if (MOD_SHRS & changed) + if (shares_changed) radio_list = g_list_append (radio_list, g_strdup_printf ("%s (%s)", _("Shares"), _("Changed"))); else radio_list = g_list_append (radio_list, g_strdup (_("Shares"))); - if (MOD_PRIC & changed) + if (price_changed) radio_list = g_list_append (radio_list, g_strdup_printf ("%s (%s)", _("Price"), _("Changed"))); else radio_list = g_list_append (radio_list, g_strdup (_("Price"))); - if (MOD_AMNT & changed) + if (amount_changed) radio_list = g_list_append (radio_list, g_strdup_printf ("%s (%s)", _("Value"), _("Changed"))); else radio_list = g_list_append (radio_list, g_strdup (_("Value"))); - if (!(MOD_PRIC & changed)) + if (!price_changed) default_value = 1; - if (!(MOD_SHRS & changed)) + if (!shares_changed) default_value = 0; - else if (!(MOD_AMNT & changed)) + else if (!amount_changed) default_value = 2; else default_value = 1; @@ -3140,44 +3233,67 @@ sr_split_auto_calc (SplitRegister *reg, Split *split, guint32 changed) if (recalc_shares) if (!gnc_numeric_zero_p (price)) { + BasicCell *cell; + denom = gnc_split_get_amount_denom (split); amount = gnc_numeric_div (value, price, denom, GNC_RND_ROUND); - xaccSetPriceCellValue (reg->sharesCell, amount); - changed |= MOD_SHRS; + cell = gnc_register_get_cell (reg, SHRS_CELL); + xaccSetPriceCellValue ((PriceCell *) cell, amount); + gnc_basic_cell_set_changed (cell, TRUE); } if (recalc_price) if (!gnc_numeric_zero_p (amount)) { + BasicCell *price_cell; + price = gnc_numeric_div (value, amount, GNC_DENOM_AUTO, GNC_DENOM_EXACT); if (gnc_numeric_negative_p (price)) { + BasicCell *debit_cell; + BasicCell *credit_cell; + + debit_cell = gnc_register_get_cell (reg, DEBT_CELL); + credit_cell = gnc_register_get_cell (reg, CRED_CELL); + price = gnc_numeric_neg (price); - xaccSetDebCredCellValue (reg->debitCell, reg->creditCell, + + xaccSetDebCredCellValue ((PriceCell *) debit_cell, + (PriceCell *) credit_cell, gnc_numeric_neg (value)); - changed |= MOD_AMNT; + + gnc_basic_cell_set_changed (debit_cell, TRUE); + gnc_basic_cell_set_changed (credit_cell, TRUE); } - xaccSetPriceCellValue (reg->priceCell, price); - changed |= MOD_PRIC; + price_cell = gnc_register_get_cell (reg, PRIC_CELL); + xaccSetPriceCellValue ((PriceCell *) price_cell, price); + gnc_basic_cell_set_changed (price_cell, TRUE); } if (recalc_value) { + BasicCell *debit_cell; + BasicCell *credit_cell; + + debit_cell = gnc_register_get_cell (reg, DEBT_CELL); + credit_cell = gnc_register_get_cell (reg, CRED_CELL); + denom = gnc_split_get_value_denom (split); value = gnc_numeric_mul (price, amount, denom, GNC_RND_ROUND); - xaccSetDebCredCellValue (reg->debitCell, reg->creditCell, value); - changed |= MOD_AMNT; - } + xaccSetDebCredCellValue ((PriceCell *) debit_cell, + (PriceCell *) credit_cell, value); - return changed; + gnc_basic_cell_set_changed (debit_cell, TRUE); + gnc_basic_cell_set_changed (credit_cell, TRUE); + } } /* ======================================================== */ @@ -3187,43 +3303,40 @@ xaccSRSaveChangedTemplateCells( SplitRegister *reg, Transaction *trans, Split *split ) { - SRInfo *info = xaccSRGetInfo( reg ); + SRInfo *info = xaccSRGetInfo( reg ); Split *other_split = NULL; - guint32 changed; kvp_frame *kvpf; AccountGroup *template_ag; - Account *template_acc; + Account *template_acc; kvp_value *tag_val; + BasicCell *cell; - DEBUG( "=== In xaccSRSaveChangedTemplateCells\n" ); + DEBUG (" "); template_acc = reg->templateAcct; - changed = xaccSplitRegisterGetChangeFlag( reg ); - changed |= xaccSplitRegisterGetConditionalChangeFlag( reg ); - if ( (MOD_DATE & changed) || - (MOD_NUM & changed) || - (MOD_RECN & changed) ) + if ( gnc_register_get_cell_changed (reg, DATE_CELL, TRUE) || + gnc_register_get_cell_changed (reg, NUM_CELL, TRUE) || + gnc_register_get_cell_changed (reg, RECN_CELL, TRUE) ) { - PERR( "unexpected changed field in a template register: %32x\n", - changed ); + PERR( "unexpected changed fields in a template register\n" ); } /* We'll be using the Split's KVP frame a lot */ kvpf = xaccSplitGetSlots( split ); - if ( MOD_XFRM & changed ) + if ( gnc_register_get_cell_changed (reg, XFRM_CELL, TRUE) ) { /* FIXME: This should probably do the same checks as xaccSRSaveChangedCells regarding account types [between different currency accounts, mainly] */ - char *new_name; - Account *acct; - AccountGroup *acctGrp; + const char *new_name; + Account *acct; + AccountGroup *acctGrp; const GUID *acctGUID; /* save the account GUID into the kvp_data. */ - new_name = reg->xfrmCell->cell.value; + new_name = gnc_register_get_cell_value (reg, XFRM_CELL); acctGrp = gnc_book_get_group( gncGetCurrentBook() ); acct = xaccGetAccountFromFullName( acctGrp, new_name, gnc_get_account_separator() ); @@ -3235,7 +3348,9 @@ xaccSRSaveChangedTemplateCells( SplitRegister *reg, kvp_frame_set_slot( kvpf, "sched-xaction/xfrm", kvp_value_new_guid( acctGUID ) ); kvpf = xaccSplitGetSlots( split ); - changed ^= MOD_XFRM; + + cell = gnc_register_get_cell (reg, XFRM_CELL); + gnc_basic_cell_set_changed (cell, FALSE); /* DEBUG */ if ( 0 ) { @@ -3250,7 +3365,6 @@ xaccSRSaveChangedTemplateCells( SplitRegister *reg, } } - /* set the actual account to the fake account for these templates */ xaccAccountInsertSplit (template_acc, split); @@ -3267,14 +3381,19 @@ xaccSRSaveChangedTemplateCells( SplitRegister *reg, } } } - if ( MOD_MXFRM & changed ) + + if ( gnc_register_get_cell_changed (reg, MXFRM_CELL, TRUE) ) { - /* DTRT */ - DEBUG( "Template: Got MOD_MXFRM changed\n" ); - changed ^= MOD_MXFRM; + DEBUG( "Template: Got MXFRM changed\n" ); + + cell = gnc_register_get_cell (reg, MXFRM_CELL); + gnc_basic_cell_set_changed (cell, FALSE); } - if ( MOD_AMNT & changed ) + + if ( gnc_register_get_cell_changed (reg, FCRED_CELL, TRUE) || + gnc_register_get_cell_changed (reg, FDEBT_CELL, TRUE) ) { + const char *value; char *amountStr = "x + y/42"; gnc_numeric new_amount; gnc_numeric credit; @@ -3287,17 +3406,24 @@ xaccSRSaveChangedTemplateCells( SplitRegister *reg, /* FIXME: the credit/debit cells are limited to numeric values by definition [and code]. Blegh. */ DEBUG( "kvp_frame before: %s\n", kvp_frame_to_string( kvpf ) ); + /* amountStr = gnc_numeric_to_string( new_amount ); */ + + value = gnc_register_get_cell_value (reg, FCRED_CELL); kvp_frame_set_slot( kvpf, "sched-xaction/credit_formula", - kvp_value_new_string( reg->formCreditCell->cell.value ) ); + kvp_value_new_string( value ) ); + + value = gnc_register_get_cell_value (reg, FDEBT_CELL); kvp_frame_set_slot( kvpf, "sched-xaction/debit_formula", - kvp_value_new_string( reg->formDebitCell->cell.value ) ); + kvp_value_new_string( value ) ); + DEBUG( "kvp_frame after: %s\n", kvp_frame_to_string( kvpf ) ); - changed ^= MOD_AMNT; + /* set the amount to an innocuous value */ xaccSplitSetValue (split, gnc_numeric_create(0, 1) ); } - if ( MOD_SHRS & changed ) + + if ( gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE) ) { char *sharesStr = "(x + y)/42"; @@ -3312,82 +3438,118 @@ xaccSRSaveChangedTemplateCells( SplitRegister *reg, xaccSplitSetSharePriceAndAmount (split, gnc_numeric_create(0, 1), gnc_numeric_create(0, 1) ); - changed ^= MOD_SHRS; + + cell = gnc_register_get_cell (reg, SHRS_CELL); + gnc_basic_cell_set_changed (cell, FALSE); } - xaccSRActuallySaveChangedCells( reg, trans, split, changed ); + xaccSRActuallySaveChangedCells( reg, trans, split ); } static void -xaccSRActuallySaveChangedCells( SplitRegister *reg, Transaction *trans, Split *split, guint32 changed ) +xaccSRActuallySaveChangedCells (SplitRegister *reg, + Transaction *trans, Split *split) { SRInfo *info = xaccSRGetInfo (reg); Split *other_split = NULL; /* copy the contents from the cursor to the split */ - if (MOD_DATE & changed) + if (gnc_register_get_cell_changed (reg, DATE_CELL, TRUE)) { + BasicCell *cell; + const char *value; Timespec ts; + cell = gnc_register_get_cell (reg, DATE_CELL); + value = gnc_basic_cell_get_value (cell); + /* commit any pending changes */ - xaccCommitDateCell (reg->dateCell); + xaccCommitDateCell ((DateCell *) cell); - DEBUG ("MOD_DATE: %s", - reg->dateCell->cell.value ? reg->dateCell->cell.value : "(null)"); + DEBUG ("DATE: %s", value ? value : "(null)"); - xaccDateCellGetDate (reg->dateCell, &ts); + xaccDateCellGetDate ((DateCell *) cell, &ts); xaccTransSetDatePostedTS (trans, &ts); } - if (MOD_NUM & changed) + + if (gnc_register_get_cell_changed (reg, NUM_CELL, TRUE)) { - DEBUG ("MOD_NUM: %s\n", - reg->numCell->cell.value ? reg->numCell->cell.value : "(null)"); - xaccTransSetNum (trans, reg->numCell->cell.value); - if (xaccSetNumCellLastNum (reg->numCell, reg->numCell->cell.value)) + BasicCell *cell; + const char *value; + + value = gnc_register_get_cell_value (reg, NUM_CELL); + + DEBUG ("NUM: %s\n", value ? value : "(null)"); + + xaccTransSetNum (trans, value); + + cell = gnc_register_get_cell (reg, NUM_CELL); + + if (xaccSetNumCellLastNum ((NumCell *) cell, value)) { SRInfo *info = xaccSRGetInfo (reg); Split *blank_split = xaccSplitLookup(&info->blank_split_guid); Transaction *blank_trans = xaccSplitGetParent (blank_split); if (trans != blank_trans) - sr_set_last_num (reg, reg->numCell->cell.value); + sr_set_last_num (reg, gnc_basic_cell_get_value (cell)); } } - if (MOD_DESC & changed) + if (gnc_register_get_cell_changed (reg, DESC_CELL, TRUE)) { - DEBUG ("MOD_DESC: %s", - reg->descCell->cell.value ? reg->descCell->cell.value : "(null)"); - xaccTransSetDescription (trans, reg->descCell->cell.value); + const char *value; + + value = gnc_register_get_cell_value (reg, DESC_CELL); + + DEBUG ("DESC: %s", value ? value : "(null)"); + + xaccTransSetDescription (trans, value); } - if (MOD_NOTES & changed) + if (gnc_register_get_cell_changed (reg, NOTES_CELL, TRUE)) { - DEBUG ("MOD_NOTES: %s", - reg->notesCell->cell.value ? reg->notesCell->cell.value : "(null)"); - xaccTransSetNotes (trans, reg->notesCell->cell.value); + const char *value; + + value = gnc_register_get_cell_value (reg, NOTES_CELL); + + DEBUG ("NOTES: %s", value ? value : "(null)"); + + xaccTransSetNotes (trans, value); } - if (MOD_RECN & changed) + if (gnc_register_get_cell_changed (reg, RECN_CELL, TRUE)) { - DEBUG ("MOD_RECN: %c", xaccRecnCellGetFlag(reg->recnCell)); - xaccSplitSetReconcile (split, xaccRecnCellGetFlag(reg->recnCell)); + RecnCell *cell; + + cell = (RecnCell *) gnc_register_get_cell (reg, RECN_CELL); + + DEBUG ("RECN: %c", xaccRecnCellGetFlag (cell)); + + xaccSplitSetReconcile (split, xaccRecnCellGetFlag (cell)); } - if (MOD_ACTN & changed) + if (gnc_register_get_cell_changed (reg, ACTN_CELL, TRUE)) { - DEBUG ("MOD_ACTN: %s", - reg->actionCell->cell.value ? - reg->actionCell->cell.value : "(null)"); - xaccSplitSetAction (split, reg->actionCell->cell.value); + const char *value; + + value = gnc_register_get_cell_value (reg, ACTN_CELL); + + DEBUG ("ACTN: %s", value ? value : "(null)"); + + xaccSplitSetAction (split, value); } - if (MOD_MEMO & changed) + if (gnc_register_get_cell_changed (reg, MEMO_CELL, TRUE)) { - DEBUG ("MOD_MEMO: %s", - reg->memoCell->cell.value ? reg->memoCell->cell.value : "(null)"); - xaccSplitSetMemo (split, reg->memoCell->cell.value); + const char *value; + + value = gnc_register_get_cell_value (reg, MEMO_CELL); + + DEBUG ("MEMO: %s", value ? value : "(null)"); + + xaccSplitSetMemo (split, value); } /* -------------------------------------------------------------- */ @@ -3401,21 +3563,20 @@ xaccSRActuallySaveChangedCells( SplitRegister *reg, Transaction *trans, Split *s /* jsled: this is where it starts to get fun. in the template * register, we save the XFRM account in the kvp frame. * also, when loading, we load from the kvp data. */ - if (MOD_XFRM & changed) + if (gnc_register_get_cell_changed (reg, XFRM_CELL, TRUE)) { Account *old_acc; Account *new_acc; - char *new_name; + const char *new_name; - DEBUG ("MOD_XFRM: %s", - reg->xfrmCell->cell.value ? reg->xfrmCell->cell.value : "(null)"); + new_name = gnc_register_get_cell_value (reg, XFRM_CELL); + + DEBUG ("XFRM: %s", new_name ? new_name : "(null)"); /* do some reparenting. Insertion into new account will automatically * delete this split from the old account */ old_acc = xaccSplitGetAccount (split); - new_name = reg->xfrmCell->cell.value; - new_acc = xaccGetAccountFromFullName (gncGetCurrentGroup (), new_name, account_separator); @@ -3426,10 +3587,13 @@ xaccSRActuallySaveChangedCells( SplitRegister *reg, Transaction *trans, Split *s if (reg->style == REG_STYLE_LEDGER && !info->trans_expanded) other_split = xaccSplitGetOtherSplit (split); - if (MOD_MXFRM & changed) + if (gnc_register_get_cell_changed (reg, MXFRM_CELL, TRUE)) { - DEBUG ("MOD_MXFRM: %s", - reg->mxfrmCell->cell.value ? reg->mxfrmCell->cell.value : "(null)"); + const char *name; + + name = gnc_register_get_cell_value (reg, MXFRM_CELL); + + DEBUG ("MXFRM: %s", name ? name : "(null)"); other_split = xaccSplitGetOtherSplit (split); @@ -3461,8 +3625,7 @@ xaccSRActuallySaveChangedCells( SplitRegister *reg, Transaction *trans, Split *s * delete from the old account */ old_acc = xaccSplitGetAccount (other_split); new_acc = xaccGetAccountFromFullName (gncGetCurrentGroup (), - reg->mxfrmCell->cell.value, - account_separator); + name, account_separator); if ((new_acc != NULL) && (old_acc != new_acc)) xaccAccountInsertSplit (new_acc, other_split); @@ -3473,50 +3636,69 @@ xaccSRActuallySaveChangedCells( SplitRegister *reg, Transaction *trans, Split *s * changes have been made to the number of shares, the price, or the * value, then we need to do some calculations to make sure it all * balances properly.*/ - if (((MOD_AMNT | MOD_PRIC | MOD_SHRS) & changed) && + if ((gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE) || + gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE) || + gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE)) && ((STOCK_REGISTER == (reg->type)) || (CURRENCY_REGISTER == (reg->type)) || (PORTFOLIO_LEDGER == (reg->type)))) - changed = sr_split_auto_calc (reg, split, changed); + sr_split_auto_calc (reg, split); - if (MOD_SHRS & changed) + if (gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE)) { - gnc_numeric amount = xaccGetPriceCellValue (reg->sharesCell); - gnc_numeric price = xaccGetPriceCellValue (reg->priceCell); + PriceCell *cell; + gnc_numeric amount; + gnc_numeric price; - DEBUG ("MOD_SHRS"); + cell = (PriceCell *) gnc_register_get_cell (reg, SHRS_CELL); + amount = xaccGetPriceCellValue (cell); + + cell = (PriceCell *) gnc_register_get_cell (reg, PRIC_CELL); + price = xaccGetPriceCellValue (cell); + + DEBUG ("SHRS"); xaccSplitSetAmount (split, amount); xaccSplitSetSharePrice (split, price); } - if (MOD_PRIC & changed) + if (gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE)) { + PriceCell *cell; gnc_numeric price; - price = xaccGetPriceCellValue (reg->priceCell); + cell = (PriceCell *) gnc_register_get_cell (reg, PRIC_CELL); + price = xaccGetPriceCellValue (cell); - DEBUG ("MOD_PRIC"); + DEBUG ("PRIC"); xaccSplitSetSharePrice (split, price); } - if (MOD_AMNT & changed) + if (gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE)) { + PriceCell *cell; gnc_numeric new_amount; gnc_numeric credit; gnc_numeric debit; - credit = xaccGetPriceCellValue(reg->creditCell); - debit = xaccGetPriceCellValue(reg->debitCell); - new_amount = gnc_numeric_sub_fixed (debit, credit); + cell = (PriceCell *) gnc_register_get_cell (reg, CRED_CELL); + credit = xaccGetPriceCellValue (cell); - DEBUG ("MOD_AMNT"); + cell = (PriceCell *) gnc_register_get_cell (reg, DEBT_CELL); + debit = xaccGetPriceCellValue (cell); + + new_amount = gnc_numeric_sub_fixed (debit, credit); xaccSplitSetValue (split, new_amount); } - if ((MOD_AMNT | MOD_PRIC | MOD_SHRS) & changed) + if (gnc_register_get_cell_changed (reg, DEBT_CELL, TRUE) || + gnc_register_get_cell_changed (reg, CRED_CELL, TRUE) || + gnc_register_get_cell_changed (reg, PRIC_CELL, TRUE) || + gnc_register_get_cell_changed (reg, SHRS_CELL, TRUE)) { xaccSplitScrub (split); @@ -3539,14 +3721,8 @@ xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split) { SRInfo *info = xaccSRGetInfo (reg); Split *other_split = NULL; - guint32 changed; - changed = xaccSplitRegisterGetChangeFlag (reg); - changed |= xaccSplitRegisterGetConditionalChangeFlag (reg); - - /* all the code in xaccSRActuallySaveChangedCells was right here, - before. -- jsled */ - xaccSRActuallySaveChangedCells( reg, trans, split, changed ); + xaccSRActuallySaveChangedCells (reg, trans, split); } /* ======================================================== */ @@ -3643,13 +3819,14 @@ use_security_cells (SplitRegister *reg, VirtualLocation virt_loc) account = NULL; if (virt_cell_loc_equal (virt_loc.vcell_loc, - reg->table->current_cursor_loc.vcell_loc)) + reg->table->current_cursor_loc.vcell_loc) && + gnc_register_get_cell_changed (reg, XFRM_CELL, FALSE)) { - guint32 changed = xaccSplitRegisterGetChangeFlag (reg); - if (MOD_XFRM & changed) - account = xaccGetAccountFromFullName (gncGetCurrentGroup (), - reg->xfrmCell->cell.value, - account_separator); + const char *name; + + name = gnc_register_get_cell_value (reg, XFRM_CELL); + account = xaccGetAccountFromFullName (gncGetCurrentGroup (), + name, account_separator); } if (!account) @@ -4346,7 +4523,8 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data) if (cell_type == TSHRS_CELL) shares = get_trans_total_amount (reg, trans); else if (is_current) - shares = xaccGetPriceCellValue (reg->sharesCell); + shares = xaccGetPriceCellValue + ((PriceCell *) gnc_register_get_cell (reg, SHRS_CELL)); else shares = xaccSplitGetAmount (split); @@ -4579,7 +4757,6 @@ xaccSRConfirmHandler (VirtualLocation virt_loc, { SplitRegister *reg = user_data; SRInfo *info = xaccSRGetInfo (reg); - guint32 changed; Split *split; char recn; @@ -4592,10 +4769,9 @@ xaccSRConfirmHandler (VirtualLocation virt_loc, if (!split) return TRUE; - changed = xaccSplitRegisterGetChangeFlag (reg); - - if (MOD_RECN & changed) - recn = xaccRecnCellGetFlag (reg->recnCell); + if (gnc_register_get_cell_changed (reg, RECN_CELL, FALSE)) + recn = xaccRecnCellGetFlag ((RecnCell *) + gnc_register_get_cell (reg, RECN_CELL)); else recn = xaccSplitGetReconcile (split); @@ -4762,7 +4938,7 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, SRInfo *info = xaccSRGetInfo (reg); Split *blank_split = xaccSplitLookup (&info->blank_split_guid); Transaction *pending_trans = xaccTransLookup (&info->pending_trans_guid); - SplitRegisterBuffer *reg_buffer; + RegisterBuffer *reg_buffer; GHashTable *trans_table = NULL; CellBlock *lead_cursor; Transaction *blank_trans; @@ -4785,7 +4961,6 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, VirtualCellLocation vcell_loc; VirtualLocation save_loc; - guint32 changed; int new_trans_split_row = -1; int new_trans_row = -1; int new_split_row = -1; @@ -4846,12 +5021,11 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, /* If the current cursor has changed we save the values for later * possible restoration. */ - changed = xaccSplitRegisterGetChangeFlag (reg); - changed |= xaccSplitRegisterGetConditionalChangeFlag (reg); - if (changed && (find_split == xaccSRGetCurrentSplit (reg))) + if (gnc_register_get_cursor_changed (reg, TRUE) && + (find_split == xaccSRGetCurrentSplit (reg))) { - reg_buffer = xaccMallocSplitRegisterBuffer (); - xaccSplitRegisterSaveCursor (reg, reg_buffer); + reg_buffer = gnc_register_buffer_new (); + gnc_register_save_cursor (reg, reg_buffer); } else reg_buffer = NULL; @@ -4901,7 +5075,10 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, if (last_num) { - xaccSetNumCellLastNum (reg->numCell, last_num); + NumCell *cell; + + cell = (NumCell *) gnc_register_get_cell (reg, NUM_CELL); + xaccSetNumCellLastNum (cell, last_num); has_last_num = TRUE; } } @@ -4950,19 +5127,26 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, { GList *node; - xaccQuickFillAddCompletion (reg->descCell, + xaccQuickFillAddCompletion ((QuickFillCell *) + gnc_register_get_cell (reg, DESC_CELL), xaccTransGetDescription (trans)); - xaccQuickFillAddCompletion (reg->notesCell, + xaccQuickFillAddCompletion ((QuickFillCell *) + gnc_register_get_cell (reg, NOTES_CELL), xaccTransGetNotes (trans)); if (!has_last_num) - xaccSetNumCellLastNum (reg->numCell, xaccTransGetNum (trans)); + xaccSetNumCellLastNum ((NumCell *) + gnc_register_get_cell (reg, NUM_CELL), + xaccTransGetNum (trans)); for (node = xaccTransGetSplitList (trans); node; node = node->next) { Split *s = node->data; - xaccQuickFillAddCompletion (reg->memoCell, xaccSplitGetMemo (s)); + QuickFillCell *cell; + + cell = (QuickFillCell *) gnc_register_get_cell (reg, MEMO_CELL); + xaccQuickFillAddCompletion (cell, xaccSplitGetMemo (s)); } } @@ -5052,12 +5236,12 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, gnc_table_move_cursor_gui (table, save_loc); new_split_row = save_loc.vcell_loc.virt_row; - if (changed && (find_split == xaccSRGetCurrentSplit (reg))) - xaccSplitRegisterRestoreCursorChanged (reg, reg_buffer); + if (find_split == xaccSRGetCurrentSplit (reg)) + gnc_register_restore_cursor (reg, reg_buffer); } if (reg_buffer != NULL) - xaccDestroySplitRegisterBuffer (reg_buffer); + gnc_register_buffer_destroy (reg_buffer); reg_buffer = NULL; } @@ -5091,11 +5275,17 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist, xaccSRShowTrans (reg, table->current_cursor_loc.vcell_loc); /* set the completion character for the xfer cells */ - xaccComboCellSetCompleteChar (reg->mxfrmCell, account_separator); - xaccComboCellSetCompleteChar (reg->xfrmCell, account_separator); + xaccComboCellSetCompleteChar ((ComboCell *) + gnc_register_get_cell (reg, MXFRM_CELL), + account_separator); + xaccComboCellSetCompleteChar ((ComboCell *) + gnc_register_get_cell (reg, XFRM_CELL), + account_separator); /* set the confirmation callback for the reconcile cell */ - xaccRecnCellSetConfirmCB (reg->recnCell, recn_cell_confirm, reg); + xaccRecnCellSetConfirmCB ((RecnCell *) + gnc_register_get_cell (reg, RECN_CELL), + recn_cell_confirm, reg); /* enable callback for cursor user-driven moves */ table->move_cursor = LedgerMoveCursor; @@ -5148,6 +5338,7 @@ void xaccSRLoadXferCells (SplitRegister *reg, Account *base_account) { AccountGroup *group; + ComboCell *cell; group = xaccGetAccountRoot(base_account); if (group == NULL) @@ -5156,11 +5347,13 @@ xaccSRLoadXferCells (SplitRegister *reg, Account *base_account) if (group == NULL) return; - xaccClearComboCellMenu (reg->xfrmCell); - xaccClearComboCellMenu (reg->mxfrmCell); + cell = (ComboCell *) gnc_register_get_cell (reg, XFRM_CELL); + xaccClearComboCellMenu (cell); + LoadXferCell (cell, group); - LoadXferCell (reg->xfrmCell, group); - LoadXferCell (reg->mxfrmCell, group); + cell = (ComboCell *) gnc_register_get_cell (reg, MXFRM_CELL); + xaccClearComboCellMenu (cell); + LoadXferCell (cell, group); } /* ======================================================== */ @@ -5170,13 +5363,11 @@ xaccSRHasPendingChanges (SplitRegister *reg) { SRInfo *info = xaccSRGetInfo(reg); Transaction *pending_trans = xaccTransLookup(&info->pending_trans_guid); - guint32 changed; if (reg == NULL) return FALSE; - changed = xaccSplitRegisterGetChangeFlag (reg); - if (changed) + if (gnc_register_get_cursor_changed (reg, FALSE)) return TRUE; return xaccTransIsOpen(pending_trans); diff --git a/src/gnome/gnc-html.c b/src/gnome/gnc-html.c index 2242fc909b..178f28164c 100644 --- a/src/gnome/gnc-html.c +++ b/src/gnome/gnc-html.c @@ -59,6 +59,7 @@ #include "gnc-html-history.h" #include "gnc-network.h" #include "gnc-ui.h" +#include "gnc-ui-util.h" #include "query-user.h" #include "window-help.h" #include "window-main.h" diff --git a/src/register/Makefile.am b/src/register/Makefile.am index 609d723df5..9dc4b44463 100644 --- a/src/register/Makefile.am +++ b/src/register/Makefile.am @@ -1,9 +1,11 @@ +SUBDIRS = gnome noinst_LIBRARIES = libgncregister.a libgncregister_a_SOURCES = \ QuickFill.c \ basiccell.c \ + cell-factory.c \ cellblock.c \ gtable.c \ numcell.c \ @@ -19,6 +21,7 @@ libgncregister_a_SOURCES = \ noinst_HEADERS = \ QuickFill.h \ basiccell.h \ + cell-factory.h \ cellblock.h \ combocell.h \ datecell.h \ @@ -46,6 +49,3 @@ INCLUDES = \ -I${top_srcdir}/src/register/gnome \ ${GNOME_INCLUDEDIR} \ ${GUILE_INCS} - - -SUBDIRS = gnome diff --git a/src/register/basiccell.c b/src/register/basiccell.c index a2b36ccd0f..6d572a268b 100644 --- a/src/register/basiccell.c +++ b/src/register/basiccell.c @@ -76,8 +76,8 @@ BasicCellHelpValue(BasicCell *cell) static void xaccClearBasicCell (BasicCell *cell) { - cell->changed = 0; - cell->conditionally_changed = 0; + cell->changed = FALSE; + cell->conditionally_changed = FALSE; cell->value = NULL; cell->value_w = NULL; @@ -89,9 +89,9 @@ xaccClearBasicCell (BasicCell *cell) cell->modify_verify = NULL; cell->direct_update = NULL; cell->leave_cell = NULL; - cell->realize = NULL; - cell->move = NULL; - cell->destroy = NULL; + cell->gui_realize = NULL; + cell->gui_move = NULL; + cell->gui_destroy = NULL; cell->get_help_value = NULL; cell->is_popup = FALSE; @@ -114,11 +114,14 @@ xaccInitBasicCell (BasicCell *cell) /* ===================================================== */ void -xaccDestroyBasicCell (BasicCell *cell) +gnc_basic_cell_destroy (BasicCell *cell) { - /* give any gui elements a chance to clean up */ if (cell->destroy) - (*(cell->destroy)) (cell); + cell->destroy (cell); + + /* give any gui elements a chance to clean up */ + if (cell->gui_destroy) + (*(cell->gui_destroy)) (cell); /* free up data strings */ g_free (cell->value); @@ -139,6 +142,16 @@ xaccDestroyBasicCell (BasicCell *cell) /* ===================================================== */ +const char * +gnc_basic_cell_get_value (BasicCell *cell) +{ + g_return_val_if_fail (cell != NULL, NULL); + + return cell->value; +} + +/* ===================================================== */ + void xaccSetBasicCellValue (BasicCell *cell, const char *val) { @@ -157,7 +170,37 @@ xaccSetBasicCellValue (BasicCell *cell, const char *val) xaccSetBasicCellValueInternal (cell, val); } -/* ===================================================== */ +gboolean +gnc_basic_cell_get_changed (BasicCell *cell) +{ + if (!cell) return FALSE; + + return cell->changed; +} + +gboolean +gnc_basic_cell_get_conditionally_changed (BasicCell *cell) +{ + if (!cell) return FALSE; + + return cell->conditionally_changed; +} + +void +gnc_basic_cell_set_changed (BasicCell *cell, gboolean changed) +{ + if (!cell) return; + + cell->changed = changed; +} + +void +gnc_basic_cell_set_conditionally_changed (BasicCell *cell, gboolean changed) +{ + if (!cell) return; + + cell->conditionally_changed = changed; +} void xaccSetBasicCellBlankHelp (BasicCell *cell, const char *blank_help) @@ -189,17 +232,6 @@ xaccBasicCellGetHelp (BasicCell *cell) /* ===================================================== */ -void -xaccBasicCellSetChanged (BasicCell *cell, gboolean changed) -{ - if (cell == NULL) - return; - - cell->changed = changed ? GNC_CELL_CHANGED : 0; -} - -/* ===================================================== */ - void xaccSetBasicCellValueInternal (BasicCell *cell, const char *value) { diff --git a/src/register/basiccell.h b/src/register/basiccell.h index 596bda29fc..8619556f1e 100644 --- a/src/register/basiccell.h +++ b/src/register/basiccell.h @@ -56,24 +56,6 @@ * classes should provide a callback here if they need * to understand special cell formats. * - * MEMBERS: - * The input_output member controls how the cell accepts - * input, and whether it displays its value. It is a - * a flag of OR-ed together values. Flag bits include: - * - * XACC_CELL_ALLOW_INPUT accept keyboard & mouse - * input from the user. - * XACC_CELL_ALLOW_EXACT_ONLY the cell may only be - * entered by 'exact' selection, i.e., not by - * indirect selection by, for example, tabbing. - * Currently, the only exact method of entering - * a cell is via the mouse pointer. - * - * If ALLOW_INPUT is not set, the cell is supposed to - * to only display values, but not accept user input. If - * set, then the callbacks below are used to when the - * cell is entered. - * * USER CALLBACKS: * The enter_cell() callback is called when the user first * makes a move to enter a cell. This might be by clicking @@ -134,14 +116,14 @@ * callbacks that allow the programmer to perform GUI-specific * initialization & changes. * - * The realize() callback will be called when GUI-specific + * The gui_realize() callback will be called when GUI-specific * initialization needs to be done. For Gnome, the second * argument will be cast to the parent widget. * - * The destroy() callback will be called when the GUI associated + * The gui_destroy() callback will be called when the GUI associated * with the cell needs to be destroyed. * - * The move() callback will be called when the GUI element needs + * The gui_move() callback will be called when the GUI element needs * to be positioned to a new location within the table grid. * The second argument is the virtual location the GUI * element should be moved to. @@ -160,15 +142,13 @@ #include #include -#include "gnc-common.h" #include "gnc-ui-common.h" -#include "register-common.h" -#define GNC_CELL_CHANGED 0xffffffff - typedef struct _BasicCell BasicCell; +typedef BasicCell * (*CellCreateFunc) (void); + typedef void (*CellSetValueFunc) (BasicCell *cell, const char * new_value); @@ -196,7 +176,7 @@ typedef void (*CellLeaveFunc) (BasicCell *cell); typedef void (*CellRealizeFunc) (BasicCell *cell, gpointer gui_handle); -typedef void (*CellMoveFunc) (BasicCell *cell, VirtualLocation virt_loc); +typedef void (*CellMoveFunc) (BasicCell *cell); typedef void (*CellDestroyFunc) (BasicCell *cell); @@ -211,11 +191,12 @@ struct _BasicCell gint value_len; /* length of wide chars value */ - guint32 changed; /* 2^32-1 if value modified */ - guint32 conditionally_changed; /* value if modified conditionally */ + gboolean changed; /* true if value modified */ + gboolean conditionally_changed; /* true if value modified conditionally */ - /* "virtual", overloaded set-value method */ + /* "virtual", overloaded methods */ CellSetValueFunc set_value; + CellDestroyFunc destroy; /* cell-editing callbacks */ CellEnterFunc enter_cell; @@ -223,13 +204,13 @@ struct _BasicCell CellDirectUpdateFunc direct_update; CellLeaveFunc leave_cell; - /* private, GUI-specific callbacks */ - CellRealizeFunc realize; - CellMoveFunc move; - CellDestroyFunc destroy; - CellGetHelpFunc get_help_value; + /* private, GUI-specific callbacks */ + CellRealizeFunc gui_realize; + CellMoveFunc gui_move; + CellDestroyFunc gui_destroy; + /* GUI flag indicated is a popup-widget */ gboolean is_popup; @@ -240,15 +221,21 @@ struct _BasicCell BasicCell * xaccMallocBasicCell (void); void xaccInitBasicCell (BasicCell *bcell); -void xaccDestroyBasicCell (BasicCell *bcell); +void gnc_basic_cell_destroy (BasicCell *bcell); +const char * gnc_basic_cell_get_value (BasicCell *cell); void xaccSetBasicCellValue (BasicCell *bcell, const char *value); +gboolean gnc_basic_cell_get_changed (BasicCell *cell); +gboolean gnc_basic_cell_get_conditionally_changed (BasicCell *cell); + +void gnc_basic_cell_set_changed (BasicCell *cell, gboolean changed); +void gnc_basic_cell_set_conditionally_changed (BasicCell *cell, + gboolean changed); + void xaccSetBasicCellBlankHelp (BasicCell *bcell, const char *help); char * xaccBasicCellGetHelp (BasicCell *bcell); -void xaccBasicCellSetChanged (BasicCell *bcell, gboolean changed); - /* for sub-class use only */ void xaccSetBasicCellValueInternal (BasicCell *bcell, const char *value); diff --git a/src/register/cell-factory.c b/src/register/cell-factory.c new file mode 100644 index 0000000000..56f4b6c109 --- /dev/null +++ b/src/register/cell-factory.c @@ -0,0 +1,111 @@ +/********************************************************************\ + * cell-factory.c -- register cell creation object * + * Copyright 2001 Free Software Foundation * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + +#include "config.h" + +#include + +#include "cell-factory.h" +#include "gnc-engine-util.h" + + +typedef struct cell_record +{ + char *cell_type_name; + + CellCreateFunc creator; +} CellRecord; + +struct cell_factory +{ + GHashTable *cell_table; +}; + + +CellFactory * +gnc_cell_factory_new (void) +{ + CellFactory *cf; + + cf = g_new0 (CellFactory, 1); + + cf->cell_table = g_hash_table_new (g_str_hash, g_str_equal); + + return cf; +} + +static void +cell_table_destroy_helper (gpointer key, gpointer value, gpointer user_data) +{ + CellRecord *cr = value; + + g_free (cr->cell_type_name); + g_free (cr); +} + +void +gnc_cell_factory_destroy (CellFactory *cf) +{ + if (!cf) return; + + g_hash_table_foreach (cf->cell_table, cell_table_destroy_helper, NULL); + + g_free (cf); +} + +void +gnc_cell_factory_add_cell_type (CellFactory *cf, + const char *cell_type_name, + CellCreateFunc cell_creator) +{ + CellRecord *cr; + + g_return_if_fail (cell_type_name != NULL); + g_return_if_fail (cell_creator != NULL); + + cr = g_hash_table_lookup (cf->cell_table, cell_type_name); + + if (cr) + g_free (cr->cell_type_name); + else + cr = g_new0 (CellRecord, 1); + + cr->cell_type_name = g_strdup (cell_type_name); + cr->creator = cell_creator; + + g_hash_table_insert (cf->cell_table, cr->cell_type_name, cr); +} + +BasicCell * +gnc_cell_factory_make_cell (CellFactory *cf, const char *cell_type_name) +{ + CellRecord *cr; + + g_return_val_if_fail (cf != NULL, NULL); + g_return_val_if_fail (cell_type_name != NULL, NULL); + + cr = g_hash_table_lookup (cf->cell_table, cell_type_name); + g_return_val_if_fail (cr != NULL, NULL); + + return cr->creator (); +} diff --git a/src/register/cell-factory.h b/src/register/cell-factory.h new file mode 100644 index 0000000000..c7646daba7 --- /dev/null +++ b/src/register/cell-factory.h @@ -0,0 +1,41 @@ +/********************************************************************\ + * cell-factory.h -- register cell creation object * + * Copyright 2001 Free Software Foundation * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + +#ifndef CELL_FACTORY_H +#define CELL_FACTORY_H + +#include "basiccell.h" + +typedef struct cell_factory CellFactory; + +CellFactory * gnc_cell_factory_new (void); +void gnc_cell_factory_destroy (CellFactory *cf); + +void gnc_cell_factory_add_cell_type (CellFactory *cf, + const char *cell_type_name, + CellCreateFunc cell_creator); + +BasicCell * gnc_cell_factory_make_cell (CellFactory *cf, + const char *cell_type_name); + +#endif diff --git a/src/register/cellblock.c b/src/register/cellblock.c index 3af6f29ea2..c50dd53caa 100644 --- a/src/register/cellblock.c +++ b/src/register/cellblock.c @@ -64,8 +64,6 @@ gnc_cellblock_cell_construct (gpointer _cb_cell, gpointer user_data) cb_cell->cell = NULL; cb_cell->cell_type = -1; - cb_cell->label = NULL; - cb_cell->sample_text = NULL; cb_cell->alignment = CELL_ALIGN_LEFT; cb_cell->expandable = FALSE; @@ -85,9 +83,6 @@ gnc_cellblock_cell_destroy (gpointer _cb_cell, gpointer user_data) cb_cell->cell = NULL; cb_cell->cell_type = -1; - g_free(cb_cell->label); - cb_cell->label = NULL; - g_free(cb_cell->sample_text); cb_cell->sample_text = NULL; } diff --git a/src/register/cellblock.h b/src/register/cellblock.h index b4a8d92559..3a6d92b4c9 100644 --- a/src/register/cellblock.h +++ b/src/register/cellblock.h @@ -78,8 +78,6 @@ typedef struct BasicCell *cell; /* cell handler */ short cell_type; /* cell type from splitreg.h */ - char *label; /* cell label for header and hints */ - /* GUI layout information */ char *sample_text; /* sample text for sizing purposes */ CellAlignment alignment; diff --git a/src/register/combocell.h b/src/register/combocell.h index abe093475f..dddd4c8068 100644 --- a/src/register/combocell.h +++ b/src/register/combocell.h @@ -59,9 +59,8 @@ typedef struct _ComboCell } ComboCell; -ComboCell * xaccMallocComboCell (void); +BasicCell * xaccMallocComboCell (void); void xaccInitComboCell (ComboCell *cell); -void xaccDestroyComboCell (ComboCell *cell); void xaccSetComboCellValue (ComboCell *cell, const char *value); diff --git a/src/register/datecell.h b/src/register/datecell.h index fcef88acc1..5746bcfe47 100644 --- a/src/register/datecell.h +++ b/src/register/datecell.h @@ -106,8 +106,7 @@ typedef struct _DateCell } DateCell; /* installs a callback to handle date recording */ -DateCell * xaccMallocDateCell (void); -void xaccDestroyDateCell (DateCell *cell); +BasicCell * xaccMallocDateCell (void); /* days are 1-31, mon is 1-12, year 1900 == 1900 */ void xaccSetDateCellValue (DateCell *cell, int day, int mon, int year); diff --git a/src/register/gnome/combocell-gnome.c b/src/register/gnome/combocell-gnome.c index 778de465a9..d1d9106461 100644 --- a/src/register/gnome/combocell-gnome.c +++ b/src/register/gnome/combocell-gnome.c @@ -36,6 +36,7 @@ #include +#include "QuickFill.h" #include "combocell.h" #include "gnc-engine-util.h" #include "gnc-ui-util.h" @@ -77,14 +78,15 @@ typedef struct _PopBox static void block_list_signals (ComboCell *cell); static void unblock_list_signals (ComboCell *cell); -static void realizeCombo (BasicCell *bcell, gpointer w); -static void moveCombo (BasicCell *bcell, VirtualLocation virt_loc); -static void destroyCombo (BasicCell *bcell); -static gboolean enterCombo (BasicCell *bcell, - int *cursor_position, - int *start_selection, - int *end_selection); -static void leaveCombo (BasicCell *bcell); +static void combo_cell_gui_realize (BasicCell *bcell, gpointer w); +static void combo_cell_gui_move (BasicCell *bcell); +static void combo_cell_gui_destroy (BasicCell *bcell); +static gboolean combo_cell_enter (BasicCell *bcell, + int *cursor_position, + int *start_selection, + int *end_selection); +static void combo_cell_leave (BasicCell *bcell); +static void combo_cell_destroy (BasicCell *bcell); /* This static indicates the debugging module that this .o belongs to. */ static short module = MOD_GTK_REG; @@ -93,7 +95,7 @@ static gboolean auto_pop_combos = FALSE; /* =============================================== */ -ComboCell * +BasicCell * xaccMallocComboCell (void) { ComboCell * cell; @@ -102,7 +104,7 @@ xaccMallocComboCell (void) xaccInitComboCell (cell); - return cell; + return &cell->cell; } void @@ -114,8 +116,10 @@ xaccInitComboCell (ComboCell *cell) cell->cell.is_popup = TRUE; - cell->cell.realize = realizeCombo; - cell->cell.destroy = destroyCombo; + cell->cell.destroy = combo_cell_destroy; + + cell->cell.gui_realize = combo_cell_gui_realize; + cell->cell.gui_destroy = combo_cell_gui_destroy; box = g_new0 (PopBox, 1); @@ -266,12 +270,12 @@ unblock_list_signals (ComboCell *cell) /* =============================================== */ static void -destroyCombo (BasicCell *bcell) +combo_cell_gui_destroy (BasicCell *bcell) { PopBox *box = bcell->gui_private; ComboCell *cell = (ComboCell *) bcell; - if (cell->cell.realize == NULL) + if (cell->cell.gui_realize == NULL) { if (box != NULL && box->item_list != NULL) { @@ -281,11 +285,11 @@ destroyCombo (BasicCell *bcell) } /* allow the widget to be shown again */ - cell->cell.realize = realizeCombo; - cell->cell.move = NULL; + cell->cell.gui_realize = combo_cell_gui_realize; + cell->cell.gui_move = NULL; cell->cell.enter_cell = NULL; cell->cell.leave_cell = NULL; - cell->cell.destroy = NULL; + cell->cell.gui_destroy = NULL; } DEBUG("combo destroyed\n"); @@ -301,12 +305,13 @@ menustring_free (gpointer string, gpointer user_data) /* =============================================== */ -void -xaccDestroyComboCell (ComboCell *cell) +static void +combo_cell_destroy (BasicCell *bcell) { + ComboCell *cell = (ComboCell *) bcell; PopBox *box = cell->cell.gui_private; - destroyCombo(&(cell->cell)); + combo_cell_gui_destroy (&(cell->cell)); if (box != NULL) { @@ -342,9 +347,7 @@ xaccDestroyComboCell (ComboCell *cell) } cell->cell.gui_private = NULL; - cell->cell.realize = NULL; - - xaccDestroyBasicCell(&(cell->cell)); + cell->cell.gui_realize = NULL; } /* =============================================== */ @@ -727,7 +730,7 @@ ComboHelpValue (BasicCell *bcell) /* =============================================== */ static void -realizeCombo (BasicCell *bcell, gpointer data) +combo_cell_gui_realize (BasicCell *bcell, gpointer data) { GnucashSheet *sheet = data; GnomeCanvasItem *item = sheet->item_editor; @@ -743,11 +746,11 @@ realizeCombo (BasicCell *bcell, gpointer data) gtk_object_sink (GTK_OBJECT(box->item_list)); /* to mark cell as realized, remove the realize method */ - cell->cell.realize = NULL; - cell->cell.move = moveCombo; - cell->cell.enter_cell = enterCombo; - cell->cell.leave_cell = leaveCombo; - cell->cell.destroy = destroyCombo; + cell->cell.gui_realize = NULL; + cell->cell.gui_move = combo_cell_gui_move; + cell->cell.enter_cell = combo_cell_enter; + cell->cell.leave_cell = combo_cell_leave; + cell->cell.gui_destroy = combo_cell_gui_destroy; cell->cell.modify_verify = ComboMV; cell->cell.direct_update = ComboDirect; cell->cell.get_help_value = ComboHelpValue; @@ -756,7 +759,7 @@ realizeCombo (BasicCell *bcell, gpointer data) /* =============================================== */ static void -moveCombo (BasicCell *bcell, VirtualLocation virt_loc) +combo_cell_gui_move (BasicCell *bcell) { PopBox *box = bcell->gui_private; @@ -822,10 +825,10 @@ popup_get_width (GnomeCanvasItem *item, } static gboolean -enterCombo (BasicCell *bcell, - int *cursor_position, - int *start_selection, - int *end_selection) +combo_cell_enter (BasicCell *bcell, + int *cursor_position, + int *start_selection, + int *end_selection) { ComboCell *cell = (ComboCell *) bcell; PopBox *box = bcell->gui_private; @@ -862,7 +865,7 @@ enterCombo (BasicCell *bcell, /* =============================================== */ static void -leaveCombo (BasicCell *bcell) +combo_cell_leave (BasicCell *bcell) { PopBox *box = bcell->gui_private; diff --git a/src/register/gnome/datecell-gnome.c b/src/register/gnome/datecell-gnome.c index 5d2d3a4404..4d6960575f 100644 --- a/src/register/gnome/datecell-gnome.c +++ b/src/register/gnome/datecell-gnome.c @@ -67,8 +67,9 @@ static void block_picker_signals (DateCell *cell); static void unblock_picker_signals (DateCell *cell); static void realizeDate (BasicCell *bcell, gpointer w); static void setDateCellValue (BasicCell *bcell, const char *value); -static void moveDate (BasicCell *bcell, VirtualLocation virt_loc); -static void destroyDate (BasicCell *bcell); +static void moveDate (BasicCell *bcell); +static void date_cell_gui_destroy (BasicCell *bcell); +static void date_cell_destroy (BasicCell *bcell); static void DateMV (BasicCell *_cell, const GdkWChar *change, int change_len, @@ -192,8 +193,10 @@ xaccInitDateCell (DateCell *cell) cell->cell.is_popup = TRUE; - cell->cell.realize = realizeDate; - cell->cell.destroy = destroyDate; + cell->cell.destroy = date_cell_destroy; + + cell->cell.gui_realize = realizeDate; + cell->cell.gui_destroy = date_cell_gui_destroy; cell->cell.modify_verify = DateMV; cell->cell.direct_update = DateDirect; cell->cell.set_value = setDateCellValue; @@ -219,7 +222,7 @@ xaccInitDateCell (DateCell *cell) xaccSetBasicCellValueInternal (&cell->cell, buff); } -DateCell * +BasicCell * xaccMallocDateCell (void) { DateCell *cell; @@ -228,7 +231,7 @@ xaccMallocDateCell (void) xaccInitDateCell (cell); - return cell; + return &cell->cell; } /* =============================================== */ @@ -353,12 +356,12 @@ unblock_picker_signals (DateCell *cell) /* =============================================== */ static void -destroyDate (BasicCell *bcell) +date_cell_gui_destroy (BasicCell *bcell) { PopBox *box = bcell->gui_private; DateCell *cell = (DateCell *) bcell; - if (cell->cell.realize == NULL) + if (cell->cell.gui_realize == NULL) { if (box != NULL && box->date_picker != NULL) { @@ -368,11 +371,11 @@ destroyDate (BasicCell *bcell) } /* allow the widget to be shown again */ - cell->cell.realize = realizeDate; - cell->cell.move = NULL; + cell->cell.gui_realize = realizeDate; + cell->cell.gui_move = NULL; cell->cell.enter_cell = NULL; cell->cell.leave_cell = NULL; - cell->cell.destroy = NULL; + cell->cell.gui_destroy = NULL; } DEBUG ("date destroyed\n"); @@ -380,19 +383,18 @@ destroyDate (BasicCell *bcell) /* =============================================== */ -void -xaccDestroyDateCell (DateCell *cell) +static void +date_cell_destroy (BasicCell *bcell) { + DateCell *cell = (DateCell *) bcell; PopBox *box = cell->cell.gui_private; - destroyDate (&(cell->cell)); + date_cell_gui_destroy (&(cell->cell)); g_free (box); cell->cell.gui_private = NULL; - cell->cell.realize = NULL; - - xaccDestroyBasicCell (&(cell->cell)); + cell->cell.gui_realize = NULL; } /* =============================================== */ @@ -800,8 +802,8 @@ realizeDate (BasicCell *bcell, gpointer data) gtk_object_sink (GTK_OBJECT(box->date_picker)); /* to mark cell as realized, remove the realize method */ - cell->cell.realize = NULL; - cell->cell.move = moveDate; + cell->cell.gui_realize = NULL; + cell->cell.gui_move = moveDate; cell->cell.enter_cell = enterDate; cell->cell.leave_cell = leaveDate; } @@ -809,7 +811,7 @@ realizeDate (BasicCell *bcell, gpointer data) /* =============================================== */ static void -moveDate (BasicCell *bcell, VirtualLocation virt_loc) +moveDate (BasicCell *bcell) { PopBox *box = bcell->gui_private; diff --git a/src/register/gnome/gnucash-style.c b/src/register/gnome/gnucash-style.c index 8d215d6bc6..3d3c87083d 100644 --- a/src/register/gnome/gnucash-style.c +++ b/src/register/gnome/gnucash-style.c @@ -207,17 +207,6 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor, else width = 0; - text = cb_cell->label; - if (text) - { - int label_width; - - label_width = gdk_string_width (font, text); - label_width += 2 * CELL_HPADDING; - - width = MAX (width, label_width); - } - if (cb_cell->cell && cb_cell->cell->is_popup) width += item_edit_get_toggle_offset (cd->pixel_height); diff --git a/src/register/numcell.c b/src/register/numcell.c index bbc35118b3..e3740254a3 100644 --- a/src/register/numcell.c +++ b/src/register/numcell.c @@ -159,7 +159,7 @@ NumMV (BasicCell *_cell, } /* ================================================ */ -NumCell * +BasicCell * xaccMallocNumCell (void) { NumCell *cell; @@ -168,14 +168,7 @@ xaccMallocNumCell (void) xaccInitNumCell (cell); - return cell; -} - -/* ================================================ */ -void -xaccDestroyNumCell (NumCell *cell) -{ - xaccDestroyBasicCell (&(cell->cell)); + return &cell->cell; } /* ================================================ */ diff --git a/src/register/numcell.h b/src/register/numcell.h index 4729a74499..1814bdf56e 100644 --- a/src/register/numcell.h +++ b/src/register/numcell.h @@ -29,7 +29,7 @@ * supports a number of accelerator keys for number entry. * * HISTORY: - * Copyright (c) 2000 Dave Peticolas + * Copyright (c) 2000 Dave Peticolas */ #ifndef NUM_CELL_H @@ -44,8 +44,7 @@ typedef struct _NumCell gboolean next_num_set; } NumCell; -NumCell * xaccMallocNumCell (void); -void xaccDestroyNumCell (NumCell *cell); +BasicCell * xaccMallocNumCell (void); void xaccSetNumCellValue (NumCell *cell, const char *str); gboolean xaccSetNumCellLastNum (NumCell *cell, const char *str); diff --git a/src/register/pricecell.c b/src/register/pricecell.c index 014cbbea41..b6676d1630 100644 --- a/src/register/pricecell.c +++ b/src/register/pricecell.c @@ -191,7 +191,7 @@ PriceHelp (BasicCell *bcell) /* ================================================ */ -PriceCell * +BasicCell * xaccMallocPriceCell (void) { PriceCell *cell; @@ -200,7 +200,7 @@ xaccMallocPriceCell (void) xaccInitPriceCell (cell); - return cell; + return &cell->cell; } /* ================================================ */ @@ -229,15 +229,6 @@ xaccInitPriceCell (PriceCell *cell) /* ================================================ */ -void -xaccDestroyPriceCell (PriceCell *cell) -{ - cell->amount = gnc_numeric_zero (); - xaccDestroyBasicCell (&(cell->cell)); -} - -/* ================================================ */ - static const char * xaccPriceCellPrintValue (PriceCell *cell) { diff --git a/src/register/pricecell.h b/src/register/pricecell.h index d04b4828a4..3e2fd17506 100644 --- a/src/register/pricecell.h +++ b/src/register/pricecell.h @@ -32,27 +32,13 @@ * * By default, the PriceCell is an input/output cell. * - * On input, this cell accepts only numeric characters - * and numeric punctuation. The punctuation accepted is *not* - * currently internationalized. Read the source for details. - * - * On output, it will display a numeric value using its current - * format string. The default format string prints two decimal - * places. The format string can be set with the - * xaccSetPriceCellFormat() method. - * - * hack alert -- implement internationalization. - * * On output, it will display negative values in red text. * hack alert -- the actual color (red) should be user configurable. * - * The stored amount is stored as a double-precision floating point - * variable. This should be sufficient precision to store trillions of - * dollars with penny accuracy. - * * HISTORY: * Copyright (c) 1998, 1999, 2000 Linas Vepstas * Copyright (c) 2000 Dave Peticolas + * Copyright (c) 2001 Free Software Foundation */ #ifndef __PRICE_CELL_C__ @@ -79,8 +65,7 @@ typedef struct _PriceCell } PriceCell; /* installs a callback to handle price recording */ -PriceCell * xaccMallocPriceCell (void); -void xaccDestroyPriceCell (PriceCell *cell); +BasicCell * xaccMallocPriceCell (void); /* return the value of a price cell */ gnc_numeric xaccGetPriceCellValue (PriceCell *cell); diff --git a/src/register/quickfillcell.c b/src/register/quickfillcell.c index a3f3537826..004a5d42d2 100644 --- a/src/register/quickfillcell.c +++ b/src/register/quickfillcell.c @@ -247,21 +247,26 @@ quick_leave (BasicCell * _cell) /* ================================================ */ -QuickFillCell * -xaccMallocQuickFillCell (void) +static void +quickfill_cell_destroy (BasicCell *bcell) { - QuickFillCell *cell; + QuickFillCell *cell = (QuickFillCell *) bcell; - cell = g_new0 (QuickFillCell, 1); + gnc_quickfill_destroy (cell->qf); + cell->qf = NULL; - xaccInitQuickFillCell (cell); + g_free (cell->original); + cell->original = NULL; - return cell; + cell->cell.enter_cell = NULL; + cell->cell.modify_verify = NULL; + cell->cell.leave_cell = NULL; + cell->cell.set_value = NULL; } /* ================================================ */ -void +static void xaccInitQuickFillCell (QuickFillCell *cell) { xaccInitBasicCell (&(cell->cell)); @@ -270,6 +275,8 @@ xaccInitQuickFillCell (QuickFillCell *cell) cell->sort = QUICKFILL_LIFO; cell->original = NULL; + cell->cell.destroy = quickfill_cell_destroy; + cell->cell.enter_cell = quick_enter; cell->cell.modify_verify = quick_modify; cell->cell.leave_cell = quick_leave; @@ -280,21 +287,16 @@ xaccInitQuickFillCell (QuickFillCell *cell) /* ================================================ */ -void -xaccDestroyQuickFillCell (QuickFillCell *cell) +BasicCell * +xaccMallocQuickFillCell (void) { - gnc_quickfill_destroy (cell->qf); - cell->qf = NULL; + QuickFillCell *cell; - g_free (cell->original); - cell->original = NULL; + cell = g_new0 (QuickFillCell, 1); - cell->cell.enter_cell = NULL; - cell->cell.modify_verify = NULL; - cell->cell.leave_cell = NULL; - cell->cell.set_value = NULL; + xaccInitQuickFillCell (cell); - xaccDestroyBasicCell (&(cell->cell)); + return &cell->cell; } /* ================================================ */ diff --git a/src/register/quickfillcell.h b/src/register/quickfillcell.h index da39c595f8..5757697e20 100644 --- a/src/register/quickfillcell.h +++ b/src/register/quickfillcell.h @@ -61,9 +61,7 @@ typedef struct _QuickFillCell GdkWChar *original; /* original string entered in original case */ } QuickFillCell; -QuickFillCell * xaccMallocQuickFillCell (void); -void xaccInitQuickFillCell (QuickFillCell *cell); -void xaccDestroyQuickFillCell (QuickFillCell *cell); +BasicCell * xaccMallocQuickFillCell (void); void xaccSetQuickFillCellValue (QuickFillCell *cell, const char *value); diff --git a/src/register/recncell.c b/src/register/recncell.c index 461798d172..fbd17ca59f 100644 --- a/src/register/recncell.c +++ b/src/register/recncell.c @@ -112,7 +112,7 @@ xaccInitRecnCell (RecnCell *cell) cell->cell.set_value = RecnSetValue; } -RecnCell * +BasicCell * xaccMallocRecnCell (void) { RecnCell * cell; @@ -121,7 +121,7 @@ xaccMallocRecnCell (void) xaccInitRecnCell (cell); - return cell; + return &cell->cell; } /* ================================================ */ @@ -160,17 +160,6 @@ RecnSetValue (BasicCell *_cell, const char *value) /* ================================================ */ -void -xaccDestroyRecnCell (RecnCell *cell) -{ - if (!cell) - return; - - xaccDestroyBasicCell (&cell->cell); -} - -/* ================================================ */ - void xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag) { diff --git a/src/register/recncell.h b/src/register/recncell.h index 4e46478fc6..5259de6c81 100644 --- a/src/register/recncell.h +++ b/src/register/recncell.h @@ -57,8 +57,7 @@ typedef struct _RecnCell gpointer confirm_data; } RecnCell; -RecnCell * xaccMallocRecnCell (void); -void xaccDestroyRecnCell (RecnCell *cell); +BasicCell * xaccMallocRecnCell (void); void xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag); char xaccRecnCellGetFlag (RecnCell *cell); diff --git a/src/register/register-common.c b/src/register/register-common.c index 386bc630d4..361826bbb0 100644 --- a/src/register/register-common.c +++ b/src/register/register-common.c @@ -21,8 +21,78 @@ * * \********************************************************************/ -#include "register-common.h" +#include "config.h" +#include "basiccell.h" +#include "cell-factory.h" +#include "combocell.h" +#include "datecell.h" +#include "numcell.h" +#include "pricecell.h" +#include "recncell.h" +#include "register-common.h" +#include "textcell.h" +#include "quickfillcell.h" + + +static gboolean register_inited = FALSE; +static CellFactory *global_factory = NULL; + +void +gnc_register_init (void) +{ + if (register_inited) + return; + + register_inited = TRUE; + + global_factory = gnc_cell_factory_new (); + + gnc_register_add_cell_type (BASIC_CELL_TYPE_NAME, xaccMallocBasicCell); + + gnc_register_add_cell_type (COMBO_CELL_TYPE_NAME, xaccMallocComboCell); + + gnc_register_add_cell_type (DATE_CELL_TYPE_NAME, xaccMallocDateCell); + + gnc_register_add_cell_type (NUM_CELL_TYPE_NAME, xaccMallocNumCell); + + gnc_register_add_cell_type (PRICE_CELL_TYPE_NAME, xaccMallocPriceCell); + + gnc_register_add_cell_type (RECN_CELL_TYPE_NAME, xaccMallocRecnCell); + + gnc_register_add_cell_type (TEXT_CELL_TYPE_NAME, xaccMallocTextCell); + + gnc_register_add_cell_type (QUICKFILL_CELL_TYPE_NAME, + xaccMallocQuickFillCell); +} + +void +gnc_register_shutdown (void) +{ + if (!register_inited) + return; + + gnc_cell_factory_destroy (global_factory); + global_factory = NULL; +} + +void +gnc_register_add_cell_type (const char *cell_type_name, + CellCreateFunc cell_creator) +{ + gnc_register_init (); + + gnc_cell_factory_add_cell_type (global_factory, + cell_type_name, cell_creator); +} + +BasicCell * +gnc_register_make_cell (const char *cell_type_name) +{ + gnc_register_init (); + + return gnc_cell_factory_make_cell (global_factory, cell_type_name); +} gboolean virt_cell_loc_equal (VirtualCellLocation vcl1, VirtualCellLocation vcl2) diff --git a/src/register/register-common.h b/src/register/register-common.h index b23938bafa..956735271a 100644 --- a/src/register/register-common.h +++ b/src/register/register-common.h @@ -26,6 +26,24 @@ #include +#include "basiccell.h" + +#define BASIC_CELL_TYPE_NAME "basic-cell" +#define COMBO_CELL_TYPE_NAME "combo-cell" +#define DATE_CELL_TYPE_NAME "date-cell" +#define NUM_CELL_TYPE_NAME "num-cell" +#define PRICE_CELL_TYPE_NAME "price-cell" +#define RECN_CELL_TYPE_NAME "recn-cell" +#define TEXT_CELL_TYPE_NAME "text-cell" +#define QUICKFILL_CELL_TYPE_NAME "quickfill-cell" + +void gnc_register_init (void); +void gnc_register_shutdown (void); + +void gnc_register_add_cell_type (const char *cell_type_name, + CellCreateFunc cell_creator); +BasicCell * gnc_register_make_cell (const char *cell_type_name); + /* The VirtualCellLocation structure contains the virtual * location of a virtual cell. diff --git a/src/register/splitreg.c b/src/register/splitreg.c index 1baeb15e70..5714d55fcf 100644 --- a/src/register/splitreg.c +++ b/src/register/splitreg.c @@ -46,41 +46,35 @@ #include "gnc-engine-util.h" #include "messages.h" -#include "recncell.h" #include "splitreg.h" #include "table-allgui.h" -#include "textcell.h" +/* FIXME: these shouldn't be here */ +#include "combocell.h" +#include "pricecell.h" +#include "recncell.h" /* This static indicates the debugging module that this .o belongs to. */ static short module = MOD_REGISTER; +typedef struct cell_node +{ + CellType cell_type; + BasicCell *cell; +} CellNode; + typedef struct _CellBuffer CellBuffer; struct _CellBuffer { + CellType cell_type; char * value; guint32 changed; guint32 conditionally_changed; }; -struct _SplitRegisterBuffer +struct _RegisterBuffer { - CellBuffer dateCell; - CellBuffer numCell; - CellBuffer descCell; - CellBuffer recnCell; - CellBuffer balanceCell; - CellBuffer actionCell; - CellBuffer xfrmCell; - CellBuffer memoCell; - CellBuffer creditCell; - CellBuffer debitCell; - CellBuffer priceCell; - CellBuffer sharesCell; - CellBuffer mxfrmCell; - CellBuffer notesCell; - CellBuffer formCreditCell; - CellBuffer formDebitCell; + GList *buffers; }; typedef struct @@ -147,6 +141,114 @@ xaccInitSplitRegister (SplitRegister *reg, gboolean templateMode); +static void +gnc_register_add_cell (SplitRegister *sr, + CellType cell_type, + const char *cell_type_name) +{ + BasicCell *cell; + CellNode *node; + + g_return_if_fail (sr != NULL); + g_return_if_fail (cell_type_name != NULL); + + cell = gnc_register_make_cell (cell_type_name); + + node = g_new0 (CellNode, 1); + + node->cell_type = cell_type; + node->cell = cell; + + sr->cells = g_list_prepend (sr->cells, node); +} + +BasicCell * +gnc_register_get_cell (SplitRegister *sr, CellType cell_type) +{ + GList *node; + + g_return_val_if_fail (sr != NULL, NULL); + + for (node = sr->cells; node; node = node->next) + { + CellNode *cn = node->data; + + if (cn->cell_type == cell_type) + return cn->cell; + } + + return NULL; +} + +const char * +gnc_register_get_cell_value (SplitRegister *sr, CellType cell_type) +{ + BasicCell *cell; + + cell = gnc_register_get_cell (sr, cell_type); + if (!cell) return NULL; + + return gnc_basic_cell_get_value (cell); +} + +gboolean +gnc_register_get_cursor_changed (SplitRegister *sr, + gboolean include_conditional) +{ + GList *node; + + if (!sr) return FALSE; + + for (node = sr->cells; node; node = node->next) + { + CellNode *cn = node->data; + + if (gnc_basic_cell_get_changed (cn->cell)) + return TRUE; + + if (include_conditional && + gnc_basic_cell_get_conditionally_changed (cn->cell)) + return TRUE; + } + + return FALSE; +} + +gboolean +gnc_register_get_cell_changed (SplitRegister *sr, + CellType cell_type, + gboolean include_conditional) +{ + BasicCell *cell; + + if (!sr) return FALSE; + + cell = gnc_register_get_cell (sr, cell_type); + if (!cell) return FALSE; + + if (!include_conditional) + return gnc_basic_cell_get_changed (cell); + else + return (gnc_basic_cell_get_changed (cell) || + gnc_basic_cell_get_conditionally_changed (cell)); +} + +void +gnc_register_clear_changes (SplitRegister *sr) +{ + GList *node; + + if (!sr) return; + + for (node = sr->cells; node; node = node->next) + { + CellNode *cn = node->data; + + gnc_basic_cell_set_changed (cn->cell, FALSE); + gnc_basic_cell_set_conditionally_changed (cn->cell, FALSE); + } +} + /* ============================================== */ /* configAction strings into the action cell */ /* hack alert -- this stuff really, really should be in a config file ... */ @@ -154,95 +256,99 @@ xaccInitSplitRegister (SplitRegister *reg, static void configAction (SplitRegister *reg) { + ComboCell *cell; + + cell = (ComboCell *) gnc_register_get_cell (reg, ACTN_CELL); + /* setup strings in the action pull-down */ switch (reg->type) { case BANK_REGISTER: /* broken ! FIXME bg */ case SEARCH_LEDGER: - xaccAddComboCellMenuItem (reg->actionCell, _("Deposit")); - xaccAddComboCellMenuItem (reg->actionCell, _("Withdraw")); - xaccAddComboCellMenuItem (reg->actionCell, _("Check")); - xaccAddComboCellMenuItem (reg->actionCell, _("Int")); - xaccAddComboCellMenuItem (reg->actionCell, _("ATM")); - xaccAddComboCellMenuItem (reg->actionCell, _("Teller")); + xaccAddComboCellMenuItem (cell, _("Deposit")); + xaccAddComboCellMenuItem (cell, _("Withdraw")); + xaccAddComboCellMenuItem (cell, _("Check")); + xaccAddComboCellMenuItem (cell, _("Int")); + xaccAddComboCellMenuItem (cell, _("ATM")); + xaccAddComboCellMenuItem (cell, _("Teller")); /* Action: Point Of Sale */ - xaccAddComboCellMenuItem (reg->actionCell, _("POS")); - xaccAddComboCellMenuItem (reg->actionCell, _("Phone")); - xaccAddComboCellMenuItem (reg->actionCell, _("Online")); + xaccAddComboCellMenuItem (cell, _("POS")); + xaccAddComboCellMenuItem (cell, _("Phone")); + xaccAddComboCellMenuItem (cell, _("Online")); /* Action: Automatic Deposit ?!? */ - xaccAddComboCellMenuItem (reg->actionCell, _("AutoDep")); - xaccAddComboCellMenuItem (reg->actionCell, _("Wire")); - xaccAddComboCellMenuItem (reg->actionCell, _("Credit")); - xaccAddComboCellMenuItem (reg->actionCell, _("Direct Debit")); - xaccAddComboCellMenuItem (reg->actionCell, _("Transfer")); + xaccAddComboCellMenuItem (cell, _("AutoDep")); + xaccAddComboCellMenuItem (cell, _("Wire")); + xaccAddComboCellMenuItem (cell, _("Credit")); + xaccAddComboCellMenuItem (cell, _("Direct Debit")); + xaccAddComboCellMenuItem (cell, _("Transfer")); break; case CASH_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); break; case ASSET_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); - xaccAddComboCellMenuItem (reg->actionCell, _("Fee")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Fee")); break; case CREDIT_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("ATM")); - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Credit")); - xaccAddComboCellMenuItem (reg->actionCell, _("Fee")); - xaccAddComboCellMenuItem (reg->actionCell, _("Int")); - xaccAddComboCellMenuItem (reg->actionCell, _("Online")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("ATM")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Credit")); + xaccAddComboCellMenuItem (cell, _("Fee")); + xaccAddComboCellMenuItem (cell, _("Int")); + xaccAddComboCellMenuItem (cell, _("Online")); + xaccAddComboCellMenuItem (cell, _("Sell")); break; case LIABILITY_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); - xaccAddComboCellMenuItem (reg->actionCell, _("Loan")); - xaccAddComboCellMenuItem (reg->actionCell, _("Int")); - xaccAddComboCellMenuItem (reg->actionCell, _("Payment")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Loan")); + xaccAddComboCellMenuItem (cell, _("Int")); + xaccAddComboCellMenuItem (cell, _("Payment")); break; case INCOME_LEDGER: case INCOME_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); - xaccAddComboCellMenuItem (reg->actionCell, _("Int")); - xaccAddComboCellMenuItem (reg->actionCell, _("Payment")); - xaccAddComboCellMenuItem (reg->actionCell, _("Rebate")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Int")); + xaccAddComboCellMenuItem (cell, _("Payment")); + xaccAddComboCellMenuItem (cell, _("Rebate")); break; case EXPENSE_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); break; case GENERAL_LEDGER: case EQUITY_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); - xaccAddComboCellMenuItem (reg->actionCell, _("Equity")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Equity")); break; case STOCK_REGISTER: case PORTFOLIO_LEDGER: case CURRENCY_REGISTER: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); - xaccAddComboCellMenuItem (reg->actionCell, _("Price")); - xaccAddComboCellMenuItem (reg->actionCell, _("Fee")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Price")); + xaccAddComboCellMenuItem (cell, _("Fee")); /* Action: Dividend */ - xaccAddComboCellMenuItem (reg->actionCell, _("Div")); - xaccAddComboCellMenuItem (reg->actionCell, _("Int")); + xaccAddComboCellMenuItem (cell, _("Div")); + xaccAddComboCellMenuItem (cell, _("Int")); /* Action: Long Term Capital Gains */ - xaccAddComboCellMenuItem (reg->actionCell, _("LTCG")); + xaccAddComboCellMenuItem (cell, _("LTCG")); /* Action: Short Term Capital Gains */ - xaccAddComboCellMenuItem (reg->actionCell, _("STCG")); - xaccAddComboCellMenuItem (reg->actionCell, _("Income")); + xaccAddComboCellMenuItem (cell, _("STCG")); + xaccAddComboCellMenuItem (cell, _("Income")); /* Action: Distribution */ - xaccAddComboCellMenuItem (reg->actionCell, _("Dist")); - xaccAddComboCellMenuItem (reg->actionCell, _("Split")); + xaccAddComboCellMenuItem (cell, _("Dist")); + xaccAddComboCellMenuItem (cell, _("Split")); break; default: - xaccAddComboCellMenuItem (reg->actionCell, _("Buy")); - xaccAddComboCellMenuItem (reg->actionCell, _("Sell")); + xaccAddComboCellMenuItem (cell, _("Buy")); + xaccAddComboCellMenuItem (cell, _("Sell")); break; } } @@ -254,7 +360,6 @@ set_cell (SplitRegister *reg, CellBlock *cursor, CellType cell_type, short row, short col) { CellBlockCell *cb_cell; - BasicCell *hcell; sample_string *ss; ss = &cell_sample_strings[cell_type]; @@ -265,35 +370,25 @@ set_cell (SplitRegister *reg, CellBlock *cursor, reg->cursor_header->start_col = MIN (reg->cursor_header->start_col, col); reg->cursor_header->stop_col = MAX (reg->cursor_header->stop_col, col); - hcell = reg->header_cells[cell_type]; - cb_cell = gnc_cellblock_get_cell (cursor, row, col); - cb_cell->cell = reg->cells[cell_type]; + cb_cell->cell = gnc_register_get_cell (reg, cell_type); cb_cell->cell_type = cell_type; - cb_cell->label = g_strdup (hcell->value); - cb_cell->sample_text = g_strdup (_(ss->string + ss->offset)); + cb_cell->sample_text = g_strdup (_(ss->string) + ss->offset); cb_cell->alignment = cell_alignments[cell_type]; - cb_cell->expandable = - reg->cells[cell_type] == (BasicCell *) reg->descCell; - cb_cell->span = - reg->cells[cell_type] == (BasicCell *) reg->memoCell || - reg->cells[cell_type] == (BasicCell *) reg->notesCell; + cb_cell->expandable = cell_type == DESC_CELL; + cb_cell->span = cell_type == MEMO_CELL || cell_type == NOTES_CELL; cb_cell = gnc_cellblock_get_cell (reg->cursor_header, row, col); if (cb_cell && (cursor == reg->cursor_ledger_single)) { - cb_cell->cell = reg->cells[cell_type]; + cb_cell->cell = gnc_register_get_cell (reg, cell_type); cb_cell->cell_type = cell_type; - cb_cell->label = g_strdup (hcell->value); - cb_cell->sample_text = g_strdup (_(ss->string + ss->offset)); + cb_cell->sample_text = g_strdup (_(ss->string) + ss->offset); cb_cell->alignment = cell_alignments[cell_type]; - cb_cell->expandable = - reg->cells[cell_type] == (BasicCell *) reg->descCell; - cb_cell->span = - reg->cells[cell_type] == (BasicCell *) reg->memoCell || - reg->cells[cell_type] == (BasicCell *) reg->notesCell; + cb_cell->expandable = cell_type == DESC_CELL; + cb_cell->span = cell_type == MEMO_CELL || cell_type == NOTES_CELL; } } @@ -570,11 +665,11 @@ configLayout (SplitRegister *reg) /* ============================================== */ SplitRegister * -xaccMallocSplitRegister (SplitRegisterType type, - SplitRegisterStyle style, - gboolean use_double_line, - TableModel *model, - gboolean templateMode) +gnc_register_new (SplitRegisterType type, + SplitRegisterStyle style, + gboolean use_double_line, + TableModel *model, + gboolean templateMode) { SplitRegister * reg; @@ -658,10 +753,6 @@ mallocCursors (SplitRegister *reg) /* ============================================== */ -#define NEW(NAME, CN, TYPE) \ - reg->CN##Cell = xaccMalloc##TYPE##Cell(); \ - reg->cells[NAME##_CELL] = (BasicCell *) reg->CN##Cell; - static void xaccInitSplitRegister (SplitRegister *reg, SplitRegisterType type, @@ -685,40 +776,31 @@ xaccInitSplitRegister (SplitRegister *reg, /* define the number of columns in the display, malloc the cursors */ mallocCursors (reg); - /* --------------------------- */ - /* malloc the header (label) cells */ - { - int i; - - for (i = 0; i < CELL_TYPE_COUNT; i++) - reg->header_cells[i] = xaccMallocTextCell (); - } - /* --------------------------- */ /* malloc the workhorse cells */ - reg->nullCell = xaccMallocBasicCell (); + reg->nullCell = gnc_register_make_cell (BASIC_CELL_TYPE_NAME); - NEW (DATE, date, Date); - NEW (NUM, num, Num); - NEW (DESC, desc, QuickFill); - NEW (RECN, recn, Recn); - NEW (BALN, balance, Price); - NEW (XFRM, xfrm, Combo); - NEW (ACTN, action, Combo); - NEW (MEMO, memo, QuickFill); - NEW (CRED, credit, Price); - NEW (DEBT, debit, Price); - NEW (PRIC, price, Price); - NEW (SHRS, shares, Price); - NEW (MXFRM, mxfrm, Combo); - NEW (TCRED, tcredit, Price); - NEW (TDEBT, tdebit, Price); - NEW (TSHRS, tshares, Price); - NEW (TBALN, tbalance, Price); - NEW (NOTES, notes, QuickFill); - NEW (FCRED, formCredit, QuickFill); - NEW (FDEBT, formDebit, QuickFill); + gnc_register_add_cell (reg, DATE_CELL, DATE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, NUM_CELL, NUM_CELL_TYPE_NAME); + gnc_register_add_cell (reg, DESC_CELL, QUICKFILL_CELL_TYPE_NAME); + gnc_register_add_cell (reg, RECN_CELL, RECN_CELL_TYPE_NAME); + gnc_register_add_cell (reg, BALN_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, XFRM_CELL, COMBO_CELL_TYPE_NAME); + gnc_register_add_cell (reg, ACTN_CELL, COMBO_CELL_TYPE_NAME); + gnc_register_add_cell (reg, MEMO_CELL, QUICKFILL_CELL_TYPE_NAME); + gnc_register_add_cell (reg, CRED_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, DEBT_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, PRIC_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, SHRS_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, MXFRM_CELL, COMBO_CELL_TYPE_NAME); + gnc_register_add_cell (reg, TCRED_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, TDEBT_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, TSHRS_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, TBALN_CELL, PRICE_CELL_TYPE_NAME); + gnc_register_add_cell (reg, NOTES_CELL, QUICKFILL_CELL_TYPE_NAME); + gnc_register_add_cell (reg, FCRED_CELL, QUICKFILL_CELL_TYPE_NAME); + gnc_register_add_cell (reg, FDEBT_CELL, QUICKFILL_CELL_TYPE_NAME); /* --------------------------- */ @@ -733,7 +815,7 @@ xaccInitSplitRegister (SplitRegister *reg, xaccSetBasicCellValue (reg->nullCell, ""); /* The num cell is the transaction number */ - xaccSetBasicCellBlankHelp (®->numCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, NUM_CELL), _("Enter the transaction number, such as the " "check number")); @@ -741,15 +823,16 @@ xaccInitSplitRegister (SplitRegister *reg, { const char *help = _("Enter the account to transfer from, or choose " "one from the list"); - xaccSetBasicCellBlankHelp (®->mxfrmCell->cell, help); - xaccSetBasicCellBlankHelp (®->xfrmCell->cell, help); + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, MXFRM_CELL), help); + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, XFRM_CELL), help); } { const char *help = _("This transaction has multiple splits; " "press the Split button to see them all"); - xaccComboCellAddIgnoreString (reg->mxfrmCell, + xaccComboCellAddIgnoreString ((ComboCell *) + gnc_register_get_cell (reg, MXFRM_CELL), _("-- Split Transaction --"), help); } @@ -757,47 +840,48 @@ xaccInitSplitRegister (SplitRegister *reg, const char *help = _("This transaction is a stock split; " "press the Split button to see details"); - xaccComboCellAddIgnoreString (reg->mxfrmCell, + xaccComboCellAddIgnoreString ((ComboCell *) + gnc_register_get_cell (reg, MXFRM_CELL), _("-- Stock Split --"), help); } /* the action cell */ - xaccComboCellSetAutoSize (reg->actionCell, TRUE); + xaccComboCellSetAutoSize ((ComboCell *) + gnc_register_get_cell (reg, ACTN_CELL), TRUE); /* the memo cell */ - xaccSetBasicCellBlankHelp (®->memoCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, MEMO_CELL), _("Enter a description of the split")); /* the desc cell */ - xaccSetBasicCellBlankHelp (®->descCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, DESC_CELL), _("Enter a description of the transaction")); /* the notes cell */ - xaccSetBasicCellBlankHelp (®->notesCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, NOTES_CELL), _("Enter notes for the transaction")); /* the formula cell */ - xaccSetBasicCellBlankHelp( ®->formCreditCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, FCRED_CELL), _("Enter credit formula for real transaction")); - xaccSetBasicCellBlankHelp( ®->formDebitCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, FDEBT_CELL), _("Enter debit formula for real transaction")); /* Use 6 decimal places for prices */ - xaccSetPriceCellFraction (reg->priceCell, 1000000); - - /* Initialize price cells */ - xaccSetPriceCellValue (reg->debitCell, gnc_numeric_zero ()); - xaccSetPriceCellValue (reg->creditCell, gnc_numeric_zero ()); - xaccSetPriceCellValue (reg->sharesCell, gnc_numeric_zero ()); + xaccSetPriceCellFraction ((PriceCell *) + gnc_register_get_cell (reg, PRIC_CELL), 1000000); /* Initialize shares and share balance cells */ xaccSetPriceCellPrintInfo - (reg->sharesCell, gnc_default_share_print_info ()); + ((PriceCell *) gnc_register_get_cell (reg, SHRS_CELL), + gnc_default_share_print_info ()); xaccSetPriceCellPrintInfo - (reg->tsharesCell, gnc_default_share_print_info ()); + ((PriceCell *) gnc_register_get_cell (reg, TSHRS_CELL), + gnc_default_share_print_info ()); /* The action cell should accept strings not in the list */ - xaccComboCellSetStrict (reg->actionCell, FALSE); - xaccSetBasicCellBlankHelp (®->actionCell->cell, + xaccComboCellSetStrict ((ComboCell *) + gnc_register_get_cell (reg, ACTN_CELL), FALSE); + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, ACTN_CELL), _("Enter the type of transaction, or choose " "one from the list")); @@ -807,12 +891,13 @@ xaccInitSplitRegister (SplitRegister *reg, case CURRENCY_REGISTER: case STOCK_REGISTER: case PORTFOLIO_LEDGER: - xaccSetPriceCellPrintInfo (reg->priceCell, + xaccSetPriceCellPrintInfo ((PriceCell *) + gnc_register_get_cell (reg, PRIC_CELL), gnc_default_price_print_info ()); - xaccSetBasicCellBlankHelp (®->priceCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, PRIC_CELL), _("Enter the share price")); - xaccSetBasicCellBlankHelp (®->sharesCell->cell, + xaccSetBasicCellBlankHelp (gnc_register_get_cell (reg, SHRS_CELL), _("Enter the number of shares bought or " "sold")); break; @@ -886,7 +971,7 @@ xaccConfigSplitRegister (SplitRegister *reg, void xaccDestroySplitRegister (SplitRegister *reg) { - int i; + GList *node; /* give the user a chance to clean up */ if (reg->destroy) @@ -912,60 +997,20 @@ xaccDestroySplitRegister (SplitRegister *reg) reg->cursor_journal_double = NULL; reg->cursor_split = NULL; - xaccDestroyBasicCell (reg->nullCell); - xaccDestroyDateCell (reg->dateCell); - xaccDestroyNumCell (reg->numCell); - xaccDestroyQuickFillCell (reg->descCell); - xaccDestroyRecnCell (reg->recnCell); - xaccDestroyPriceCell (reg->balanceCell); - xaccDestroyComboCell (reg->actionCell); - xaccDestroyComboCell (reg->xfrmCell); - xaccDestroyQuickFillCell (reg->memoCell); - xaccDestroyPriceCell (reg->creditCell); - xaccDestroyPriceCell (reg->debitCell); - xaccDestroyPriceCell (reg->priceCell); - xaccDestroyPriceCell (reg->sharesCell); - xaccDestroyComboCell (reg->mxfrmCell); - xaccDestroyPriceCell (reg->tcreditCell); - xaccDestroyPriceCell (reg->tdebitCell); - xaccDestroyPriceCell (reg->tsharesCell); - xaccDestroyPriceCell (reg->tbalanceCell); - xaccDestroyQuickFillCell (reg->notesCell); - xaccDestroyQuickFillCell (reg->formCreditCell); - xaccDestroyQuickFillCell (reg->formDebitCell); + gnc_basic_cell_destroy (reg->nullCell); + reg->nullCell = NULL; - reg->nullCell = NULL; - reg->dateCell = NULL; - reg->numCell = NULL; - reg->descCell = NULL; - reg->recnCell = NULL; - reg->balanceCell = NULL; - reg->actionCell = NULL; - reg->xfrmCell = NULL; - reg->memoCell = NULL; - reg->creditCell = NULL; - reg->debitCell = NULL; - reg->priceCell = NULL; - reg->sharesCell = NULL; - reg->mxfrmCell = NULL; - reg->tcreditCell = NULL; - reg->tdebitCell = NULL; - reg->tsharesCell = NULL; - reg->tbalanceCell = NULL; - reg->notesCell = NULL; - reg->formCreditCell = NULL; - reg->formDebitCell = NULL; - - for (i = 0; i < CELL_TYPE_COUNT; i++) + for (node = reg->cells; node; node = node->next) { - BasicCell *cell; + CellNode *cn = node->data; - cell = reg->header_cells[i]; - if (cell) - xaccDestroyTextCell (cell); - reg->header_cells[i] = NULL; + gnc_basic_cell_destroy (cn->cell); + g_free (cn); } + g_list_free (reg->cells); + reg->cells = NULL; + g_free (reg->debit_str); g_free (reg->tdebit_str); g_free (reg->credit_str); @@ -982,82 +1027,6 @@ xaccDestroySplitRegister (SplitRegister *reg) /* ============================================== */ -guint32 -xaccSplitRegisterGetChangeFlag (SplitRegister *reg) -{ - guint32 changed = 0; - - /* be careful to use bitwise ands and ors to assemble bit flag */ - changed |= MOD_DATE & reg->dateCell->cell.changed; - changed |= MOD_NUM & reg->numCell->cell.changed; - changed |= MOD_DESC & reg->descCell->cell.changed; - changed |= MOD_RECN & reg->recnCell->cell.changed; - changed |= MOD_ACTN & reg->actionCell->cell.changed; - changed |= MOD_XFRM & reg->xfrmCell->cell.changed; - changed |= MOD_MEMO & reg->memoCell->cell.changed; - changed |= MOD_AMNT & reg->creditCell->cell.changed; - changed |= MOD_AMNT & reg->debitCell->cell.changed; - changed |= MOD_PRIC & reg->priceCell->cell.changed; - changed |= MOD_SHRS & reg->sharesCell->cell.changed; - changed |= MOD_MXFRM & reg->mxfrmCell->cell.changed; - changed |= MOD_NOTES & reg->notesCell->cell.changed; - - changed |= MOD_AMNT & reg->formCreditCell->cell.changed; - changed |= MOD_AMNT & reg->formDebitCell->cell.changed; - - return changed; -} - -guint32 -xaccSplitRegisterGetConditionalChangeFlag (SplitRegister *reg) -{ - guint32 changed = 0; - - /* be careful to use bitwise ands and ors to assemble bit flag */ - changed |= MOD_DATE & reg->dateCell->cell.conditionally_changed; - changed |= MOD_NUM & reg->numCell->cell.conditionally_changed; - changed |= MOD_DESC & reg->descCell->cell.conditionally_changed; - changed |= MOD_RECN & reg->recnCell->cell.conditionally_changed; - changed |= MOD_ACTN & reg->actionCell->cell.conditionally_changed; - changed |= MOD_XFRM & reg->xfrmCell->cell.conditionally_changed; - changed |= MOD_MEMO & reg->memoCell->cell.conditionally_changed; - changed |= MOD_AMNT & reg->creditCell->cell.conditionally_changed; - changed |= MOD_AMNT & reg->debitCell->cell.conditionally_changed; - changed |= MOD_PRIC & reg->priceCell->cell.conditionally_changed; - changed |= MOD_SHRS & reg->sharesCell->cell.conditionally_changed; - changed |= MOD_MXFRM & reg->mxfrmCell->cell.conditionally_changed; - changed |= MOD_NOTES & reg->notesCell->cell.conditionally_changed; - - changed |= MOD_AMNT & reg->formCreditCell->cell.conditionally_changed; - changed |= MOD_AMNT & reg->formDebitCell->cell.conditionally_changed; - - return changed; -} - -/* ============================================== */ - -void -xaccSplitRegisterClearChangeFlag (SplitRegister *reg) -{ - reg->dateCell->cell.changed = 0; - reg->numCell->cell.changed = 0; - reg->descCell->cell.changed = 0; - reg->recnCell->cell.changed = 0; - reg->actionCell->cell.changed = 0; - reg->xfrmCell->cell.changed = 0; - reg->memoCell->cell.changed = 0; - reg->creditCell->cell.changed = 0; - reg->debitCell->cell.changed = 0; - reg->priceCell->cell.changed = 0; - reg->sharesCell->cell.changed = 0; - reg->mxfrmCell->cell.changed = 0; - reg->notesCell->cell.changed = 0; - reg->formDebitCell->cell.changed = 0; - reg->formCreditCell->cell.changed = 0; -} - -/* ============================================== */ - static CursorClass sr_cellblock_cursor_class(SplitRegister *reg, CellBlock *cursor) { @@ -1142,14 +1111,18 @@ xaccCursorTypeToClass (CursorType cursor_type) static CellType sr_cell_type (SplitRegister *reg, void * cell) { - int i; + GList *node; if (reg == NULL) return NO_CELL; - for (i = 0; i < CELL_TYPE_COUNT; i++) - if (cell == reg->cells[i]) - return i; + for (node = reg->cells; node; node = node->next) + { + CellNode *cn = node->data; + + if (cell == cn->cell) + return cn->cell_type; + } return NO_CELL; } @@ -1289,97 +1262,107 @@ xaccSplitRegisterGetCurrentCellLoc (SplitRegister *reg, CellType cell_type, /* ============================================== */ -SplitRegisterBuffer * -xaccMallocSplitRegisterBuffer (void) +RegisterBuffer * +gnc_register_buffer_new (void) { - SplitRegisterBuffer *srb; + RegisterBuffer *rb; - srb = g_new0(SplitRegisterBuffer, 1); + rb = g_new0 (RegisterBuffer, 1); - return srb; + return rb; } /* ============================================== */ static void -destroyCellBuffer(CellBuffer *cb) +destroy_cell_buffer (CellBuffer *cb) { if (cb == NULL) return; - g_free(cb->value); + g_free (cb->value); cb->value = NULL; + + g_free (cb); +} + +static void +gnc_register_buffer_clear (RegisterBuffer *rb) +{ + GList *node; + + if (!rb) return; + + for (node = rb->buffers; node; node = node->next) + { + CellBuffer *cb = node->data; + + destroy_cell_buffer (cb); + } + + g_list_free (rb->buffers); + rb->buffers = NULL; } void -xaccDestroySplitRegisterBuffer (SplitRegisterBuffer *srb) +gnc_register_buffer_destroy (RegisterBuffer *rb) { - if (srb == NULL) - return; + if (!rb) return; - destroyCellBuffer(&srb->dateCell); - destroyCellBuffer(&srb->numCell); - destroyCellBuffer(&srb->descCell); - destroyCellBuffer(&srb->recnCell); - destroyCellBuffer(&srb->balanceCell); - destroyCellBuffer(&srb->actionCell); - destroyCellBuffer(&srb->xfrmCell); - destroyCellBuffer(&srb->memoCell); - destroyCellBuffer(&srb->creditCell); - destroyCellBuffer(&srb->debitCell); - destroyCellBuffer(&srb->priceCell); - destroyCellBuffer(&srb->sharesCell); - destroyCellBuffer(&srb->mxfrmCell); - destroyCellBuffer(&srb->notesCell); - destroyCellBuffer(&srb->formCreditCell); - destroyCellBuffer(&srb->formDebitCell); + gnc_register_buffer_clear (rb); - g_free(srb); + g_free (rb); } /* ============================================== */ -static void -saveCell(BasicCell *bcell, CellBuffer *cb) +static CellBuffer * +save_cell (BasicCell *bcell) { - if ((bcell == NULL) || (cb == NULL)) - return; + CellBuffer *cb; - g_free(cb->value); - cb->value = g_strdup(bcell->value); + if (!bcell) + return NULL; + cb = g_new0 (CellBuffer, 1); + + cb->value = g_strdup (bcell->value); cb->changed = bcell->changed; cb->conditionally_changed = bcell->conditionally_changed; + + return cb; } void -xaccSplitRegisterSaveCursor(SplitRegister *sr, SplitRegisterBuffer *srb) +gnc_register_save_cursor (SplitRegister *sr, RegisterBuffer *rb) { - if ((sr == NULL) || (srb == NULL)) + GList *node; + + if ((sr == NULL) || (rb == NULL)) return; - saveCell(&sr->dateCell->cell, &srb->dateCell); - saveCell(&sr->numCell->cell, &srb->numCell); - saveCell(&sr->descCell->cell, &srb->descCell); - saveCell(&sr->recnCell->cell, &srb->recnCell); - saveCell(&sr->balanceCell->cell, &srb->balanceCell); - saveCell(&sr->actionCell->cell, &srb->actionCell); - saveCell(&sr->xfrmCell->cell, &srb->xfrmCell); - saveCell(&sr->memoCell->cell, &srb->memoCell); - saveCell(&sr->creditCell->cell, &srb->creditCell); - saveCell(&sr->debitCell->cell, &srb->debitCell); - saveCell(&sr->priceCell->cell, &srb->priceCell); - saveCell(&sr->sharesCell->cell, &srb->sharesCell); - saveCell(&sr->mxfrmCell->cell, &srb->mxfrmCell); - saveCell(&sr->notesCell->cell, &srb->notesCell); - saveCell(&sr->formCreditCell->cell, &srb->formCreditCell); - saveCell(&sr->formDebitCell->cell, &srb->formDebitCell); + gnc_register_buffer_clear (rb); + + for (node = sr->cells; node; node = node->next) + { + CellNode *cn = node->data; + CellBuffer *cb; + + if (!gnc_basic_cell_get_changed (cn->cell) && + !gnc_basic_cell_get_conditionally_changed (cn->cell)) + continue; + + cb = save_cell (cn->cell); + cb->cell_type = cn->cell_type; + + rb->buffers = g_list_prepend (rb->buffers, cb); + } } /* ============================================== */ static void -restoreCellChanged(BasicCell *bcell, CellBuffer *cb, CellBlock *cursor) +restore_cell (BasicCell *bcell, CellBuffer *cb, CellBlock *cursor) { int r, c; @@ -1410,34 +1393,27 @@ restoreCellChanged(BasicCell *bcell, CellBuffer *cb, CellBlock *cursor) } void -xaccSplitRegisterRestoreCursorChanged(SplitRegister *sr, - SplitRegisterBuffer *srb) +gnc_register_restore_cursor (SplitRegister *sr, RegisterBuffer *rb) { CellBlock *cursor; + GList *node; - if ((sr == NULL) || (sr->table == NULL) || (srb == NULL)) + if ((sr == NULL) || (sr->table == NULL) || (rb == NULL)) return; cursor = sr->table->current_cursor; if (cursor == NULL) return; - restoreCellChanged(&sr->dateCell->cell, &srb->dateCell, cursor); - restoreCellChanged(&sr->numCell->cell, &srb->numCell, cursor); - restoreCellChanged(&sr->descCell->cell, &srb->descCell, cursor); - restoreCellChanged(&sr->recnCell->cell, &srb->recnCell, cursor); - restoreCellChanged(&sr->balanceCell->cell, &srb->balanceCell, cursor); - restoreCellChanged(&sr->actionCell->cell, &srb->actionCell, cursor); - restoreCellChanged(&sr->xfrmCell->cell, &srb->xfrmCell, cursor); - restoreCellChanged(&sr->memoCell->cell, &srb->memoCell, cursor); - restoreCellChanged(&sr->creditCell->cell, &srb->creditCell, cursor); - restoreCellChanged(&sr->debitCell->cell, &srb->debitCell, cursor); - restoreCellChanged(&sr->priceCell->cell, &srb->priceCell, cursor); - restoreCellChanged(&sr->sharesCell->cell, &srb->sharesCell, cursor); - restoreCellChanged(&sr->mxfrmCell->cell, &srb->mxfrmCell, cursor); - restoreCellChanged(&sr->notesCell->cell, &srb->notesCell, cursor); - restoreCellChanged(&sr->formCreditCell->cell, &srb->formCreditCell, cursor); - restoreCellChanged(&sr->formDebitCell->cell, &srb->formDebitCell, cursor); + for (node = rb->buffers; node; node = node->next) + { + CellBuffer *cb = node->data; + BasicCell *cell; + + cell = gnc_register_get_cell (sr, cb->cell_type); + + restore_cell (cell, cb, cursor); + } } /* keep in sync with CellType enum */ @@ -1447,7 +1423,6 @@ static const char *cell_names[] = "num", "description", "reconcile", - "share-balance", "balance", "action", "account", @@ -1459,7 +1434,7 @@ static const char *cell_names[] = "transfer", "trans-credit", "trans-debit", - "trans-share-balance", + "trans-shares", "trans-balance", "notes", "credit formula", diff --git a/src/register/splitreg.h b/src/register/splitreg.h index 224482f3b2..6fb8b445d3 100644 --- a/src/register/splitreg.h +++ b/src/register/splitreg.h @@ -44,14 +44,8 @@ #ifndef XACC_SPLITREG_H #define XACC_SPLITREG_H -#include "basiccell.h" -#include "cellblock.h" -#include "combocell.h" -#include "datecell.h" -#include "quickfillcell.h" -#include "pricecell.h" -#include "numcell.h" -#include "recncell.h" +#include "Account.h" /* FIXME No Engine headers!!! */ + #include "table-allgui.h" /* defined register types. @@ -124,27 +118,6 @@ typedef enum REG_STYLE_JOURNAL } SplitRegisterStyle; -/* modified flags -- indicate which cell values have been modified by user */ -typedef enum -{ - MOD_NONE = 0, - MOD_DATE = 1 << 0, - MOD_NUM = 1 << 1, - MOD_DESC = 1 << 2, - MOD_RECN = 1 << 3, - MOD_ACTN = 1 << 4, - MOD_XFRM = 1 << 5, - MOD_MXFRM = 1 << 6, - MOD_MEMO = 1 << 7, - MOD_AMNT = 1 << 8, - MOD_PRIC = 1 << 9, - MOD_SHRS = 1 << 10, - MOD_NOTES = 1 << 11, - MOD_FCRED = 1 << 12, - MOD_FDEBT = 1 << 13, - MOD_ALL = 0xffff -} CellModifiedFlags; - /* Types of cursors */ typedef enum { @@ -166,7 +139,7 @@ typedef enum NUM_CURSOR_TYPES } CursorType; -typedef struct _SplitRegisterBuffer SplitRegisterBuffer; +typedef struct _RegisterBuffer RegisterBuffer; typedef struct _SplitRegister SplitRegister; typedef void (*SplitRegisterDestroyCB) (SplitRegister *reg); @@ -186,47 +159,24 @@ struct _SplitRegister BasicCell * nullCell; - DateCell * dateCell; - NumCell * numCell; - QuickFillCell * descCell; - RecnCell * recnCell; - PriceCell * balanceCell; - ComboCell * actionCell; - ComboCell * xfrmCell; - QuickFillCell * memoCell; - PriceCell * creditCell; - PriceCell * debitCell; - PriceCell * priceCell; - PriceCell * sharesCell; - ComboCell * mxfrmCell; - PriceCell * tcreditCell; - PriceCell * tdebitCell; - PriceCell * tsharesCell; - PriceCell * tbalanceCell; - QuickFillCell * notesCell; - - QuickFillCell * formCreditCell; - QuickFillCell * formDebitCell; - SplitRegisterType type; SplitRegisterStyle style; gboolean use_double_line; /* some private data; outsiders should not access this */ - BasicCell *header_cells[CELL_TYPE_COUNT]; - BasicCell *cells[CELL_TYPE_COUNT]; + GList *cells; /** * A flag indicating a "template" register. **/ gboolean template; - + /** * The template account which the transactions in a template * splitregister will belong to. **/ - Account *templateAcct; + Account *templateAcct; /* FIXME: this should not be here! */ /* user_data allows users of this object to hang * private data onto it */ @@ -245,11 +195,11 @@ struct _SplitRegister SplitRegister * -xaccMallocSplitRegister (SplitRegisterType type, - SplitRegisterStyle style, - gboolean use_double_line, - TableModel *model, - gboolean templateMode); +gnc_register_new (SplitRegisterType type, + SplitRegisterStyle style, + gboolean use_double_line, + TableModel *model, + gboolean templateMode); void xaccConfigSplitRegister (SplitRegister *reg, SplitRegisterType type, @@ -258,12 +208,16 @@ void xaccConfigSplitRegister (SplitRegister *reg, void xaccDestroySplitRegister (SplitRegister *reg); -/* returns non-zero value if updates have been made to data */ -guint32 xaccSplitRegisterGetChangeFlag (SplitRegister *reg); -guint32 xaccSplitRegisterGetConditionalChangeFlag (SplitRegister *reg); +BasicCell * gnc_register_get_cell (SplitRegister *sr, CellType cell_type); +const char * gnc_register_get_cell_value (SplitRegister *sr, + CellType cell_type); -/* Clears all change flags in the register. Does not alter values */ -void xaccSplitRegisterClearChangeFlag (SplitRegister *reg); +gboolean gnc_register_get_cursor_changed (SplitRegister *sr, + gboolean include_conditional); +gboolean gnc_register_get_cell_changed (SplitRegister *sr, + CellType cell_type, + gboolean include_conditional); +void gnc_register_clear_changes (SplitRegister *sr); /* Returns the type of the current cursor */ CursorClass xaccSplitRegisterGetCurrentCursorClass (SplitRegister *reg); @@ -294,12 +248,11 @@ gboolean xaccSplitRegisterGetCurrentCellLoc (SplitRegister *reg, VirtualLocation *virt_loc); /* Functions for working with split register buffers */ -SplitRegisterBuffer * xaccMallocSplitRegisterBuffer (void); -void xaccDestroySplitRegisterBuffer (SplitRegisterBuffer *srb); +RegisterBuffer * gnc_register_buffer_new (void); +void gnc_register_buffer_destroy (RegisterBuffer *rb); -void xaccSplitRegisterSaveCursor(SplitRegister *sr, SplitRegisterBuffer *srb); -void xaccSplitRegisterRestoreCursorChanged(SplitRegister *sr, - SplitRegisterBuffer *srb); +void gnc_register_save_cursor (SplitRegister *sr, RegisterBuffer *srb); +void gnc_register_restore_cursor (SplitRegister *sr, RegisterBuffer *srb); const char * xaccSplitRegisterGetCellTypeName (CellType type); CellType xaccSplitRegisterGetCellTypeFromName (const char *name); diff --git a/src/register/table-allgui.c b/src/register/table-allgui.c index f1da8768bf..6c6fe7c681 100644 --- a/src/register/table-allgui.c +++ b/src/register/table-allgui.c @@ -572,20 +572,11 @@ gnc_table_move_cursor_internal (Table *table, { BasicCell *cell = cb_cell->cell; - cell->changed = 0; - cell->conditionally_changed = 0; + cell->changed = FALSE; + cell->conditionally_changed = FALSE; - if (cell->move) - { - VirtualLocation vloc; - - vloc.vcell_loc.virt_row = -1; - vloc.vcell_loc.virt_col = -1; - vloc.phys_row_offset = -1; - vloc.phys_col_offset = -1; - - cell->move (cell, vloc); - } + if (cell->gui_move) + cell->gui_move (cell); } } } @@ -631,8 +622,8 @@ gnc_table_move_cursor_internal (Table *table, * the cell value. Otherwise, we'll end up putting the * new values in the old cell locations, and that would * lead to confusion of all sorts. */ - if (do_move_gui && cell->move) - cell->move (cell, virt_loc); + if (do_move_gui && cell->gui_move) + cell->gui_move (cell); /* OK, now copy the string value from the table at large * into the cell handler. */ @@ -647,9 +638,8 @@ gnc_table_move_cursor_internal (Table *table, xaccSetBasicCellValue (cell, entry); - cell->changed = 0; - cell->conditionally_changed = - conditionally_changed ? GNC_CELL_CHANGED : 0; + cell->changed = FALSE; + cell->conditionally_changed = conditionally_changed; } } } @@ -752,8 +742,8 @@ gnc_table_create_cursor (Table * table, CellBlock *curs) cb_cell = gnc_cellblock_get_cell (curs, cell_row, cell_col); - if (cb_cell && cb_cell->cell && cb_cell->cell->realize) - cb_cell->cell->realize (cb_cell->cell, table->ui_data); + if (cb_cell && cb_cell->cell && cb_cell->cell->gui_realize) + cb_cell->cell->gui_realize (cb_cell->cell, table->ui_data); } } @@ -887,7 +877,7 @@ gnc_table_enter_update(Table *table, can_edit = enter(cell, cursor_position, start_selection, end_selection); if (safe_strcmp(old_value, cell->value) != 0) - cell->changed = GNC_CELL_CHANGED; + cell->changed = TRUE; g_free (old_value); } @@ -913,7 +903,6 @@ gnc_table_enter_update(Table *table, void gnc_table_leave_update(Table *table, VirtualLocation virt_loc) { - gboolean changed = FALSE; CellLeaveFunc leave; CellBlockCell *cb_cell; BasicCell *cell; @@ -951,10 +940,7 @@ gnc_table_leave_update(Table *table, VirtualLocation virt_loc) leave (cell); if (safe_strcmp(old_value, cell->value) != 0) - { - changed = TRUE; - cell->changed = GNC_CELL_CHANGED; - } + cell->changed = TRUE; g_free (old_value); } @@ -1043,7 +1029,7 @@ gnc_table_modify_update(Table *table, if (safe_strcmp (old_value, cell->value) != 0) { changed = TRUE; - cell->changed = GNC_CELL_CHANGED; + cell->changed = TRUE; } g_free (old_value); @@ -1123,7 +1109,7 @@ gnc_table_direct_update (Table *table, } else { - cell->changed = GNC_CELL_CHANGED; + cell->changed = TRUE; *newval_ptr = cell->value; } } diff --git a/src/register/table-allgui.h b/src/register/table-allgui.h index 023e1eb46d..0e0cbca460 100644 --- a/src/register/table-allgui.h +++ b/src/register/table-allgui.h @@ -92,6 +92,7 @@ #include #include "gnc-common.h" +#include "register-common.h" #include "basiccell.h" #include "cellblock.h" diff --git a/src/register/textcell.c b/src/register/textcell.c index e989b6bc5e..04c6869b4b 100644 --- a/src/register/textcell.c +++ b/src/register/textcell.c @@ -57,6 +57,14 @@ TextMV (struct _BasicCell *_cell, /* ================================================ */ +static void +xaccInitTextCell (BasicCell *cell) +{ + cell->modify_verify = TextMV; +} + +/* ================================================ */ + BasicCell * xaccMallocTextCell (void) { @@ -68,21 +76,4 @@ xaccMallocTextCell (void) return cell; } -/* ================================================ */ - -void -xaccInitTextCell (BasicCell *cell) -{ - cell->modify_verify = TextMV; -} - -/* ================================================ */ - -void -xaccDestroyTextCell (BasicCell *cell) -{ - cell->modify_verify = NULL; - xaccDestroyBasicCell (cell); -} - /* --------------- end of file ---------------------- */ diff --git a/src/register/textcell.h b/src/register/textcell.h index 220f6329aa..13f009304b 100644 --- a/src/register/textcell.h +++ b/src/register/textcell.h @@ -41,8 +41,6 @@ /* installs a callback to handle text recording */ BasicCell * xaccMallocTextCell (void); -void xaccInitTextCell (BasicCell *cell); -void xaccDestroyTextCell (BasicCell *cell); #endif /* TEXT_CELL_H */