From 8348efbfaddc4e8ec52b5e5ff8759a9a075d029b Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 2 Feb 1998 01:17:38 +0000 Subject: [PATCH] misc bug & core dump fixes git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@485 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/AdjBWindow.c | 2 +- src/Ledger.c | 27 ++++++++++++++++++--------- src/RecnWindow.c | 4 +++- src/RegWindow.c | 21 +++++++++++++++------ src/XferWindow.c | 23 ++++++++--------------- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/AdjBWindow.c b/src/AdjBWindow.c index 04aa10666e..6f376b3f4e 100644 --- a/src/AdjBWindow.c +++ b/src/AdjBWindow.c @@ -322,7 +322,7 @@ adjBOkCB( Widget mw, XtPointer cd, XtPointer cb ) xaccSetAmount (&(trans->credit_split), dcurrAmount - themount); /* Refresh the account register window */ - regRefresh(acc); + accRefresh(acc); /* Refresh the account reconcile window */ recnRefresh (acc); diff --git a/src/Ledger.c b/src/Ledger.c index 97be1c30e3..4a3e76abd6 100644 --- a/src/Ledger.c +++ b/src/Ledger.c @@ -7,6 +7,7 @@ */ #include "Ledger.h" +#include "messages.h" #include "register.h" #include "Transaction.h" @@ -63,20 +64,27 @@ xaccSaveRegEntry (BasicRegister *reg) /* ======================================================== */ -static Account * -GetPeerAcc (Split *split) +static char * +GetPeerAccName (Split *split) { - Account *acc; + Account *acc = NULL; Transaction *trans; trans = (Transaction *) (split->parent); - /* hack alert -- this is incorrect for splits in general */ if (split != &(trans->credit_split)) { acc = (Account *) trans->credit_split.acc; } else { - acc = (Account *) trans->debit_splits[0]->acc; + if (trans->debit_splits) { + /* if only one split, then use that */ + if (NULL == trans->debit_splits[1]) { + acc = (Account *) trans->debit_splits[0]->acc; + } else { + return SPLIT_STR; + } + } } - return acc; + if (acc) return acc->accountName; + return ""; } /* ======================================================== */ @@ -85,7 +93,7 @@ void xaccLoadRegEntry (BasicRegister *reg, Split *split) { Transaction *trans; - Account *acc; + char *accname; char buff[2]; if (!split) return; @@ -105,8 +113,9 @@ xaccLoadRegEntry (BasicRegister *reg, Split *split) xaccSetBasicCellValue (reg->recnCell, buff); /* the transfer account */ - acc = GetPeerAcc (split); - xaccSetBasicCellValue (&(reg->xfrmCell->cell), acc->accountName); + /* hack alert -- this is incorrect for splits in general */ + accname = GetPeerAccName (split); + xaccSetBasicCellValue (&(reg->xfrmCell->cell), accname); xaccSetDebCredCellValue (reg->debitCell, reg->creditCell, split->damount); diff --git a/src/RecnWindow.c b/src/RecnWindow.c index 2934738dcc..595da08b0e 100644 --- a/src/RecnWindow.c +++ b/src/RecnWindow.c @@ -147,6 +147,8 @@ recnRefresh (Account *acc) XbaeMatrixSetRowUserData( recnData->credit,nrows, (XtPointer)split ); } } + i++; + split = acc->splits[i]; } recnRecalculateBalance(recnData); @@ -841,7 +843,7 @@ recnOkCB( Widget mw, XtPointer cd, XtPointer cb ) } /* refresh the register window */ - regRefresh(recnData->acc); + accRefresh(recnData->acc); } /********************************************************************\ diff --git a/src/RegWindow.c b/src/RegWindow.c index bcf7ccb768..eac03a11a9 100644 --- a/src/RegWindow.c +++ b/src/RegWindow.c @@ -90,7 +90,7 @@ static RegWindow **fullList = NULL; /* all registers */ /** PROTOTYPES ******************************************************/ RegWindow * regWindowLedger( Widget parent, Account *lead, Account **acclist, int type); -void regRefresh (Account *acc); +void accRefresh (Account *acc); static void closeRegWindow( Widget mw, XtPointer cd, XtPointer cb ); static void startRecnCB( Widget mw, XtPointer cd, XtPointer cb ); @@ -466,7 +466,7 @@ regWindowLedger( Widget parent, Account *lead_acc, Account **acclist, int ledger activityMenu[4].subitems = reportMenu; /* can't adjust the balance on a ledger window */ - if (1 != regData->numAcc) { + if (1 < regData->numAcc) { activityMenu[2].sensitive = False; activityMenu[3].sensitive = False; } @@ -632,8 +632,7 @@ regWindowLedger( Widget parent, Account *lead_acc, Account **acclist, int ledger /******************************************************************/ XtManageChild(pane); - /* hack alert -- if no leader, should be refreshing from list */ - regRefresh (regData->leader); + accRefresh (regData->leader); XtPopup( regData->dialog, XtGrabNone ); @@ -642,11 +641,21 @@ regWindowLedger( Widget parent, Account *lead_acc, Account **acclist, int ledger return regData; } +/********************************************************************\ + * refresh only the indicated register window * +\********************************************************************/ + +void regRefresh (RegWindow *regData) +{ + /* hack alert -- should be recomputing the list of splits */ + xaccLoadRegister (regData->ledger, regData->leader->splits); +} + /********************************************************************\ * refresh *all* register windows which contain this account * \********************************************************************/ -void regRefresh (Account *acc) +void accRefresh (Account *acc) { RegWindow *regData; int n; @@ -665,7 +674,7 @@ void regRefresh (Account *acc) if (got_one) { /* hack alert -- should be recomputing the list of splits */ /* and problbly the balance too */ - xaccLoadRegister (regData->ledger, acc->splits); + regRefresh (regData); } n++; regData = fullList[n]; diff --git a/src/XferWindow.c b/src/XferWindow.c index c1a88ad1b0..6a8b985f67 100644 --- a/src/XferWindow.c +++ b/src/XferWindow.c @@ -476,23 +476,16 @@ xferCB( Widget mw, XtPointer cd, XtPointer cb ) xaccTransSetReconcile (trans, NREC); /* make note of which accounts this was transfered from & to */ - split->acc = (struct _account *) getAccount(grp,xferData->from); - trans->credit_split.acc = (struct _account *) getAccount(grp,xferData->to); - - /* insert transaction into from acount */ - xaccInsertSplit (((Account *) (split->acc)), split); - - /* Refresh the "from" account register window */ - regRefresh(acc); - /* Refresh the "from" account reconcile window */ + acc = getAccount(grp,xferData->from); + split->acc = (struct _account *) acc; + xaccInsertSplit (acc, split); + accRefresh(acc); recnRefresh(acc); - - /* insert transaction into to acount */ - xaccInsertSplit (((Account *) (trans->credit_split.acc)), &(trans->credit_split)); - /* Refresh the "to" account register window */ - regRefresh(acc); - /* Refresh the "to" account reconcile window */ + acc = getAccount(grp,xferData->to); + trans->credit_split.acc = (struct _account *) acc; + xaccInsertSplit (acc, &(trans->credit_split)); + accRefresh(acc); recnRefresh(acc); refreshMainWindow();