2001-08-20 Dave Peticolas <dave@krondo.com>

* src/app-utils/global-options.[ch]: cleanup

	* src/app-utils/option-util.[ch]: cleanup

	* src/gnome/top-level.c: take out reverse balance implementations

	* src/app-utils/gnc-ui-util.c: take out deprecated api
        implementations. implement reverse balance api calls.

	* src/register/ledger-core/SplitLedger.[ch]: take out reverse
	balance callback. just use app-utils version.

	* src/app-utils/gnc-ui-util.h: remove deprecated api


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5203 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-08-20 10:08:09 +00:00
parent 5658ec9890
commit 4c692441f3
11 changed files with 119 additions and 171 deletions

View File

@ -1,5 +1,19 @@
2001-08-20 Dave Peticolas <dave@krondo.com>
* src/app-utils/global-options.[ch]: cleanup
* src/app-utils/option-util.[ch]: cleanup
* src/gnome/top-level.c: take out reverse balance implementations
* src/app-utils/gnc-ui-util.c: take out deprecated api
implementations. implement reverse balance api calls.
* src/register/ledger-core/SplitLedger.[ch]: take out reverse
balance callback. just use app-utils version.
* src/app-utils/gnc-ui-util.h: remove deprecated api
* src/engine/gnc-book-p.h: add const
* src/engine/gnc-book.c: strdup error message for backend

View File

@ -89,7 +89,7 @@ gnc_options_shutdown(void)
\********************************************************************/
SCM
gnc_register_option_change_callback(OptionChangeCallback callback,
void *user_data,
gpointer user_data,
char *section,
char *name)
{

View File

@ -35,7 +35,7 @@ void gnc_options_init(void);
void gnc_options_shutdown(void);
SCM gnc_register_option_change_callback(OptionChangeCallback callback,
void *user_data,
gpointer user_data,
char *section,
char *name);

View File

@ -51,6 +51,10 @@ static short module = MOD_GUI;
static gboolean auto_decimal_enabled = FALSE;
static int auto_decimal_places = 2; /* default, can be changed */
static gboolean reverse_balance_inited = FALSE;
static SCM reverse_balance_callback_id = SCM_UNDEFINED;
static gboolean reverse_type[NUM_ACCOUNT_TYPES];
/********************************************************************\
* gnc_color_deficits *
@ -104,6 +108,97 @@ gnc_get_account_separator (void)
}
static void
gnc_configure_reverse_balance (void)
{
gchar *choice;
gint i;
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
reverse_type[i] = FALSE;
choice = gnc_lookup_multichoice_option ("General",
"Reversed-balance account types",
"credit");
if (safe_strcmp (choice, "income-expense") == 0)
{
reverse_type[INCOME] = TRUE;
reverse_type[EXPENSE] = TRUE;
}
else if (safe_strcmp (choice, "credit") == 0)
{
reverse_type[LIABILITY] = TRUE;
reverse_type[EQUITY] = TRUE;
reverse_type[INCOME] = TRUE;
reverse_type[CREDIT] = TRUE;
}
else if (safe_strcmp (choice, "none") == 0)
{
}
else
{
PERR("bad value\n");
reverse_type[INCOME] = TRUE;
reverse_type[EXPENSE] = TRUE;
}
if (choice != NULL)
free (choice);
}
static void
gnc_configure_reverse_balance_cb (gpointer not_used)
{
gnc_configure_reverse_balance ();
gnc_gui_refresh_all ();
}
static void
gnc_reverse_balance_init (void)
{
gnc_configure_reverse_balance ();
reverse_balance_callback_id =
gnc_register_option_change_callback (gnc_configure_reverse_balance_cb,
NULL, "General",
"Reversed-balance account types");
reverse_balance_inited = (reverse_balance_callback_id != SCM_UNDEFINED);
}
gboolean
gnc_reverse_balance_type (GNCAccountType type)
{
if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
return FALSE;
if (!reverse_balance_inited)
gnc_reverse_balance_init ();
return reverse_type[type];
}
gboolean
gnc_reverse_balance (Account *account)
{
int type;
if (account == NULL)
return FALSE;
type = xaccAccountGetType (account);
if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
return FALSE;
if (!reverse_balance_inited)
gnc_reverse_balance_init ();
return reverse_type[type];
}
const char *
gnc_ui_account_get_field_name (AccountFieldCode field)
{
@ -1358,28 +1453,6 @@ xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
return buf;
}
const char *
DxaccPrintAmount (double dval, GNCPrintAmountInfo info)
{
gnc_numeric val;
val = double_to_gnc_numeric (dval, GNC_DENOM_AUTO,
GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND);
return xaccPrintAmount (val, info);
}
int
DxaccSPrintAmount (char * bufp, double dval, GNCPrintAmountInfo info)
{
gnc_numeric val;
val = double_to_gnc_numeric (dval, GNC_DENOM_AUTO,
GNC_DENOM_SIGFIGS(6) | GNC_RND_ROUND);
return xaccSPrintAmount (bufp, val, info);
}
/********************************************************************\
* xaccParseAmount *
@ -1440,21 +1513,6 @@ multiplier (int num_decimals)
return 1;
}
gboolean
DxaccParseAmount (const char * in_str, gboolean monetary, double *result,
char **endstr)
{
gnc_numeric answer;
if (!xaccParseAmount (in_str, monetary, &answer, endstr))
return FALSE;
if (result)
*result = gnc_numeric_to_double (answer);
return TRUE;
}
gboolean
xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
char **endstr)

View File

@ -180,9 +180,6 @@ GNCPrintAmountInfo gnc_default_price_print_info (void);
GNCPrintAmountInfo gnc_integral_print_info (void);
const char * DxaccPrintAmount (double val, GNCPrintAmountInfo info);
int DxaccSPrintAmount (char *buf, double val, GNCPrintAmountInfo info);
const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
@ -200,8 +197,6 @@ int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
* non-NULL, *endstr will point to in_str. */
gboolean xaccParseAmount (const char * in_str, gboolean monetary,
gnc_numeric *result, char **endstr);
gboolean DxaccParseAmount (const char * in_str, gboolean monetary,
double *result, char **endstr);
/* Automatic decimal place conversion *******************************/

View File

@ -257,7 +257,7 @@ gnc_option_db_destroy(GNCOptionDB *odb)
SCM
gnc_option_db_register_change_callback(GNCOptionDB *odb,
OptionChangeCallback callback,
void *data,
gpointer data,
const char *section,
const char *name)
{

View File

@ -44,7 +44,7 @@ struct _GNCOption
gboolean changed;
/* The widget which is holding this option */
void * widget;
gpointer widget;
};
typedef struct _GNCOptionSection GNCOptionSection;
@ -61,7 +61,7 @@ void gnc_option_db_destroy(GNCOptionDB *odb);
SCM gnc_option_db_register_change_callback(GNCOptionDB *odb,
OptionChangeCallback callback,
void *data,
gpointer data,
const char *section,
const char *name);

View File

@ -81,8 +81,6 @@ static void gnc_configure_register_colors_cb(gpointer);
static void gnc_configure_register_colors(void);
static void gnc_configure_register_borders_cb(gpointer);
static void gnc_configure_register_borders(void);
static void gnc_configure_reverse_balance_cb(gpointer);
static void gnc_configure_reverse_balance(void);
static void gnc_configure_auto_raise_cb(gpointer);
static void gnc_configure_auto_raise(void);
static void gnc_configure_negative_color_cb(gpointer);
@ -111,7 +109,6 @@ static SCM date_callback_id = SCM_UNDEFINED;
static SCM account_separator_callback_id = SCM_UNDEFINED;
static SCM register_colors_callback_id = SCM_UNDEFINED;
static SCM register_borders_callback_id = SCM_UNDEFINED;
static SCM reverse_balance_callback_id = SCM_UNDEFINED;
static SCM auto_raise_callback_id = SCM_UNDEFINED;
static SCM negative_color_callback_id = SCM_UNDEFINED;
static SCM auto_decimal_callback_id = SCM_UNDEFINED;
@ -274,12 +271,6 @@ gnucash_ui_init(void)
gnc_register_option_change_callback(gnc_configure_register_borders_cb,
NULL, "Register", NULL);
gnc_configure_reverse_balance();
reverse_balance_callback_id =
gnc_register_option_change_callback(gnc_configure_reverse_balance_cb,
NULL, "General",
"Reversed-balance account types");
gnc_configure_auto_raise();
auto_raise_callback_id =
gnc_register_option_change_callback(gnc_configure_auto_raise_cb,
@ -375,7 +366,6 @@ gnc_ui_destroy (void)
gnc_unregister_option_change_callback_id(account_separator_callback_id);
gnc_unregister_option_change_callback_id(register_colors_callback_id);
gnc_unregister_option_change_callback_id(register_borders_callback_id);
gnc_unregister_option_change_callback_id(reverse_balance_callback_id);
gnc_unregister_option_change_callback_id(auto_raise_callback_id);
gnc_unregister_option_change_callback_id(negative_color_callback_id);
gnc_unregister_option_change_callback_id(register_font_callback_id);
@ -778,93 +768,6 @@ gnc_configure_negative_color(void)
xaccSetSplitRegisterColorizeNegative (use_red);
}
/* gnc_configure_reverse_balance_cb
* Callback called when options change - sets
* reverse balance info for the callback
*
* Args: Nothing
* Returns: Nothing
*/
static void
gnc_configure_reverse_balance_cb (gpointer not_used)
{
gnc_configure_reverse_balance ();
gnc_gui_refresh_all ();
}
static gboolean reverse_type[NUM_ACCOUNT_TYPES];
gboolean
gnc_reverse_balance_type(GNCAccountType type)
{
if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
return FALSE;
return reverse_type[type];
}
gboolean
gnc_reverse_balance(Account *account)
{
int type;
if (account == NULL)
return FALSE;
type = xaccAccountGetType(account);
if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
return FALSE;
return reverse_type[type];
}
/* gnc_configure_reverse_balance
* sets reverse balance info for the callback
*
* Args: Nothing
* Returns: Nothing
*/
static void
gnc_configure_reverse_balance(void)
{
gchar *choice;
gint i;
xaccSRSetReverseBalanceCallback(gnc_reverse_balance);
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
reverse_type[i] = FALSE;
choice = gnc_lookup_multichoice_option("General",
"Reversed-balance account types",
"credit");
if (safe_strcmp(choice, "income-expense") == 0)
{
reverse_type[INCOME] = TRUE;
reverse_type[EXPENSE] = TRUE;
}
else if (safe_strcmp(choice, "credit") == 0)
{
reverse_type[LIABILITY] = TRUE;
reverse_type[EQUITY] = TRUE;
reverse_type[INCOME] = TRUE;
reverse_type[CREDIT] = TRUE;
}
else if (safe_strcmp(choice, "none") == 0)
{
}
else
{
PERR("bad value\n");
reverse_type[INCOME] = TRUE;
reverse_type[EXPENSE] = TRUE;
}
if (choice != NULL)
free(choice);
}
/* gnc_configure_auto_decimal_cb
* Callback called when options change -

View File

@ -134,9 +134,6 @@
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_LEDGER;
/* The reverse balance callback, if any. */
static SRReverseBalanceCallback reverse_balance = NULL;
/* The copied split or transaction, if any */
static CursorClass copied_class = CURSOR_CLASS_NONE;
static SCM copied_item = SCM_UNDEFINED;
@ -182,12 +179,6 @@ xaccSRSetData (SplitRegister *reg, void *user_data,
info->get_parent = get_parent;
}
void
xaccSRSetReverseBalanceCallback (SRReverseBalanceCallback callback)
{
reverse_balance = callback;
}
static int
gnc_trans_split_index (Transaction *trans, Split *split)
{
@ -2647,29 +2638,26 @@ xaccSRGetEntryHandler (VirtualLocation virt_loc, gboolean translate,
case BALN_CELL:
case TBALN_CELL:
{
SRInfo *info = xaccSRGetInfo(reg);
Split *blank_split = xaccSplitLookup(&info->blank_split_guid);
SRInfo *info = xaccSRGetInfo (reg);
Split *blank_split = xaccSplitLookup (&info->blank_split_guid);
gnc_numeric balance;
if (split == blank_split)
return "";
/* If the reverse_balance callback is present use that.
* Otherwise, reverse income and expense by default. */
if (cell_type == BALN_CELL)
balance = xaccSplitGetBalance (split);
else
balance = get_trans_total_balance (reg, trans);
if (reverse_balance != NULL)
{
Account *account;
account = xaccSplitGetAccount(split);
account = xaccSplitGetAccount (split);
if (account == NULL)
account = sr_get_default_account (reg);
if (reverse_balance(account))
if (gnc_reverse_balance (account))
balance = gnc_numeric_neg (balance);
}
@ -3118,20 +3106,17 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
{
gnc_numeric balance;
/* If the reverse_balance callback is present use that.
* Otherwise, reverse income and expense by default. */
if (cell_type == BALN_CELL)
balance = xaccSplitGetBalance (split);
else
balance = get_trans_total_balance (reg, trans);
if (reverse_balance != NULL)
{
Account *account;
account = xaccSplitGetAccount (split);
if (reverse_balance (account))
if (gnc_reverse_balance (account))
balance = gnc_numeric_neg (balance);
}

View File

@ -55,7 +55,6 @@ struct _SplitRegisterColors
/* Callback function type */
typedef gncUIWidget (*SRGetParentCallback) (gpointer user_data);
typedef void (*SRSetHelpCallback) (gpointer user_data, const char *help_str);
typedef gboolean (*SRReverseBalanceCallback) (Account *account);
/* The xaccSRSetData() method sets the user data and callback
@ -63,11 +62,6 @@ typedef gboolean (*SRReverseBalanceCallback) (Account *account);
void xaccSRSetData(SplitRegister *reg, gpointer user_data,
SRGetParentCallback get_parent);
/* The xaccSRSetReverseBalanceCallback() method sets up
* a callback used to determine whether split balances
* should be reversed. */
void xaccSRSetReverseBalanceCallback(SRReverseBalanceCallback callback);
/* The xaccSRGetCurrentTrans() method returns the transaction
* which is the parent of the current split (see below). */
Transaction * xaccSRGetCurrentTrans (SplitRegister *reg);

View File

@ -66,7 +66,6 @@
(gnc:depend "config-var.scm")
(gnc:depend "utilities.scm")
(gnc:depend "path.scm")
(gnc:depend "options.scm")
(gnc:depend "prefs.scm")
(gnc:depend "command-line.scm")
(gnc:depend "doc.scm")