From 776995673291f0abe29009754afae889b1992193 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sun, 9 Apr 2000 08:01:43 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2170 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 15 +++++++++++++++ src/gnome/account-tree.c | 28 ++++++++++++++++++++++++++-- src/gnome/account-tree.h | 1 + src/gnome/dialog-utils.c | 37 +++++++++++++++++++++++++------------ src/gnome/dialog-utils.h | 6 +++--- src/gnome/window-main.c | 3 +++ src/scm/prefs.scm | 5 +++-- 7 files changed, 76 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6bc8ef7ea..89ff3c614c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-04-09 Dave Peticolas + + * src/scm/prefs.scm: make the default field types be description + and total + + * src/gnome/window-main.c (gnc_configure_account_tree): set the + state of the total field + + * src/gnome/account-tree.c: add in the new total field + + * src/gnome/dialog-utils.c: add the new account field key + ACCOUNT_TOTAL. This key refers to the account's balance plus the + balances of all children. The ACCOUNT_BALANCE key now refers to + the balance of the account itself, without children. + 2000-04-08 Dave Peticolas * src/scm/report/balance-and-pnl.scm: remove the report description. diff --git a/src/gnome/account-tree.c b/src/gnome/account-tree.c index 9dfa40f4f8..302fde9a8b 100644 --- a/src/gnome/account-tree.c +++ b/src/gnome/account-tree.c @@ -131,6 +131,9 @@ gnc_account_tree_init(GNCAccountTree *tree) gtk_clist_set_column_justification(GTK_CLIST(tree), tree->balance_column, GTK_JUSTIFY_RIGHT); + gtk_clist_set_column_justification(GTK_CLIST(tree), + tree->total_column, + GTK_JUSTIFY_RIGHT); { GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(tree)); @@ -697,7 +700,7 @@ gnc_init_account_view_info(AccountViewInfo *avi) avi->show_field[ACCOUNT_NAME] = GNC_T; avi->show_field[ACCOUNT_DESCRIPTION] = GNC_T; - avi->show_field[ACCOUNT_BALANCE] = GNC_T; + avi->show_field[ACCOUNT_TOTAL] = GNC_T; } /********************************************************************\ @@ -736,6 +739,9 @@ gnc_account_tree_set_view_info_real(GNCAccountTree *tree) tree->balance_column = i; tree->column_fields[i++] = ACCOUNT_BALANCE; + tree->total_column = i; + tree->column_fields[i++] = ACCOUNT_TOTAL; + tree->column_fields[i++] = ACCOUNT_NOTES; tree->num_columns = i; @@ -918,8 +924,11 @@ gnc_account_tree_insert_row(GNCAccountTree *tree, return NULL; for (i = 0; i < tree->num_columns; i++) + { text[i] = gnc_ui_get_account_field_value_string(acc, tree->column_fields[i]); + text[i] = g_strdup(text[i]); + } text[tree->num_columns] = NULL; @@ -927,13 +936,16 @@ gnc_account_tree_insert_row(GNCAccountTree *tree, text, 0, NULL, NULL, NULL, NULL, FALSE, FALSE); + for (i = 0; i < tree->num_columns; i++) + g_free(text[i]); + #if !USE_NO_COLOR { GtkStyle *style; double balance; gboolean deficit; - balance = gnc_ui_get_account_full_balance(acc); + balance = gnc_ui_account_get_balance(acc, FALSE); deficit = (balance < 0) && !DEQ(balance, 0); if (deficit) @@ -944,6 +956,18 @@ gnc_account_tree_insert_row(GNCAccountTree *tree, if (style != NULL) gtk_ctree_node_set_cell_style(GTK_CTREE(tree), node, tree->balance_column, style); + + balance = gnc_ui_account_get_balance(acc, TRUE); + deficit = (balance < 0) && !DEQ(balance, 0); + + if (deficit) + style = tree->deficit_style; + else + style = gtk_widget_get_style(GTK_WIDGET(tree)); + + if (style != NULL) + gtk_ctree_node_set_cell_style(GTK_CTREE(tree), node, + tree->total_column, style); } #endif diff --git a/src/gnome/account-tree.h b/src/gnome/account-tree.h index 0bc10d4890..d9ddebbbd5 100644 --- a/src/gnome/account-tree.h +++ b/src/gnome/account-tree.h @@ -59,6 +59,7 @@ struct _GNCAccountTree gint num_columns; gint balance_column; + gint total_column; gint column_fields[NUM_ACCOUNT_FIELDS]; gchar * column_headings[NUM_ACCOUNT_FIELDS + 1]; diff --git a/src/gnome/dialog-utils.c b/src/gnome/dialog-utils.c index 3dc1d4bfe2..74f9378529 100644 --- a/src/gnome/dialog-utils.c +++ b/src/gnome/dialog-utils.c @@ -595,6 +595,9 @@ char * gnc_ui_get_account_field_name(int field) case ACCOUNT_BALANCE : return BALN_STR; break; + case ACCOUNT_TOTAL : + return TOTAL_STR; + break; } assert(0); @@ -603,24 +606,25 @@ char * gnc_ui_get_account_field_name(int field) double -gnc_ui_get_account_full_balance(Account *account) +gnc_ui_account_get_balance(Account *account, gboolean include_children) { - AccountGroup *acc_children; double balance; - int type; - assert(account != NULL); + if (account == NULL) + return 0.0; - acc_children = xaccAccountGetChildren (account); - type = xaccAccountGetType(account); balance = xaccAccountGetBalance (account); - /* if the account has children, add in their balance */ - if (acc_children) - balance += xaccGroupGetBalance(acc_children); + if (include_children) + { + AccountGroup *children; + + children = xaccAccountGetChildren (account); + balance += xaccGroupGetBalance (children); + } /* reverse sign if needed */ - if (gnc_reverse_balance(account)) + if (gnc_reverse_balance (account)) balance = -balance; return balance; @@ -629,7 +633,9 @@ gnc_ui_get_account_full_balance(Account *account) char * gnc_ui_get_account_field_value_string(Account *account, int field) { - assert(account != NULL); + if (account == NULL) + return NULL; + assert((field >= 0) && (field < NUM_ACCOUNT_FIELDS)); switch (field) @@ -657,7 +663,14 @@ char * gnc_ui_get_account_field_value_string(Account *account, int field) break; case ACCOUNT_BALANCE : { - double balance = gnc_ui_get_account_full_balance(account); + double balance = gnc_ui_account_get_balance(account, FALSE); + + return xaccPrintAmount(balance, PRTSYM | PRTSEP); + } + break; + case ACCOUNT_TOTAL : + { + double balance = gnc_ui_account_get_balance(account, TRUE); return xaccPrintAmount(balance, PRTSYM | PRTSEP); } diff --git a/src/gnome/dialog-utils.h b/src/gnome/dialog-utils.h index 844b6e9e17..69f306a27f 100644 --- a/src/gnome/dialog-utils.h +++ b/src/gnome/dialog-utils.h @@ -80,8 +80,8 @@ enum ACCOUNT_NOTES, ACCOUNT_CURRENCY, ACCOUNT_SECURITY, - ACCOUNT_BALANCE, /* including children, with sign reversal - for income/expense */ + ACCOUNT_BALANCE, /* with sign reversal */ + ACCOUNT_TOTAL, /* balance + children's balance with sign reversal */ NUM_ACCOUNT_FIELDS }; @@ -106,7 +106,7 @@ char * gnc_ui_get_account_field_name(int field); char * gnc_ui_get_account_field_value_string(Account *account, int field); -double gnc_ui_get_account_full_balance(Account *account); +double gnc_ui_account_get_balance(Account *account, gboolean include_children); GtkWidget * gnc_ui_notes_frame_create(GtkEditable **notes_entry); diff --git a/src/gnome/window-main.c b/src/gnome/window-main.c index 012760afd0..aeba37782e 100644 --- a/src/gnome/window-main.c +++ b/src/gnome/window-main.c @@ -577,6 +577,9 @@ gnc_configure_account_tree(void *data) else if (safe_strcmp(node->data, "balance") == 0) new_avi.show_field[ACCOUNT_BALANCE] = TRUE; + + else if (safe_strcmp(node->data, "total") == 0) + new_avi.show_field[ACCOUNT_TOTAL] = TRUE; } gnc_free_list_option_value(list); diff --git a/src/scm/prefs.scm b/src/scm/prefs.scm index 90026a4d39..4697e9ada9 100644 --- a/src/scm/prefs.scm +++ b/src/scm/prefs.scm @@ -97,14 +97,15 @@ the account instead of opening a register." #f)) (gnc:make-list-option "Main Window" "Account fields to display" "c" "" - (list 'description 'balance) + (list 'description 'total) (list #(type "Type" "") #(code "Code" "") #(description "Description" "") #(notes "Notes" "") #(currency "Currency" "") #(security "Security" "") - #(balance "Balance" "")))) + #(balance "Balance" "") + #(total "Total" "")))) ;; International options