From 49809dd90405f90f402a129ae6e6ebee7196ccbb Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Thu, 4 Jul 2002 14:24:50 +0000 Subject: [PATCH] * business-options: (new files) implement owner/customer/vendor options to plug into the options dialog. * businessmod-gnome: initialize business options * business-utils: pack into box FALSE, not TRUE * owner-report: put the company into the options dialog instead of hiding it. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7084 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 13 + src/business/business-gnome/Makefile.am | 2 + .../business-gnome/business-options.c | 296 ++++++++++++++++++ .../business-gnome/business-options.h | 13 + src/business/business-gnome/business-utils.c | 2 +- .../business-gnome/businessmod-gnome.c | 2 + .../business-reports/owner-report.scm | 22 +- 7 files changed, 340 insertions(+), 10 deletions(-) create mode 100644 src/business/business-gnome/business-options.c create mode 100644 src/business/business-gnome/business-options.h diff --git a/ChangeLog b/ChangeLog index 1ea3e39eba..ea4700dca5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2002-07-04 Derek Atkins + + * option-util.c: add gnc_option_get_option_data() function + * dialog-options: publish gnc_options_dialog_changed_internal() so + pluggible options can set the flag, too. + + * business-options: (new files) implement owner/customer/vendor + options to plug into the options dialog. + * businessmod-gnome: initialize business options + * business-utils: pack into box FALSE, not TRUE + * owner-report: put the company into the options dialog instead of + hiding it. + 2002-07-03 Derek Atkins * moved receivable and payable aging reports to business-reports; diff --git a/src/business/business-gnome/Makefile.am b/src/business/business-gnome/Makefile.am index 6ddd768175..10a4ee5ce8 100644 --- a/src/business/business-gnome/Makefile.am +++ b/src/business/business-gnome/Makefile.am @@ -28,6 +28,7 @@ AM_CFLAGS = \ libgncmod_business_gnome_la_SOURCES = \ businessmod-gnome.c \ + business-options.c \ business-urls.c \ business-utils.c \ dialog-billterms.c \ @@ -43,6 +44,7 @@ libgncmod_business_gnome_la_SOURCES = \ gnc-business-utils.c noinst_HEADERS = \ + business-options.h \ business-urls.h \ business-utils.h \ dialog-billterms.h \ diff --git a/src/business/business-gnome/business-options.c b/src/business/business-gnome/business-options.c new file mode 100644 index 0000000000..6420a1b23c --- /dev/null +++ b/src/business/business-gnome/business-options.c @@ -0,0 +1,296 @@ +/* + * business-options.c -- Initialize Business Options + * + * Written By: Derek Atkins + * Copyright (C) 2002 Derek Atkins + */ + +#include "config.h" + +#include +#include +#include + +#include "gnc-ui-util.h" +#include "gnc-engine-util.h" +#include "option-util.h" + +#include "dialog-options.h" +#include "business-options.h" +#include "business-utils.h" + +static int +owner_changed_cb (GtkWidget *widget, gpointer data) +{ + GNCOption *option = data; + + gnc_option_set_changed (option, TRUE); + gnc_option_call_option_widget_changed_proc (option); + gnc_options_dialog_changed_internal (widget); + + return FALSE; +} + +static GtkWidget * +create_owner_widget (GNCOption *option, GncOwnerType type, GtkWidget *hbox) +{ + GtkWidget *widget; + GncOwner owner; + + switch (type) { + case GNC_OWNER_CUSTOMER: + gncOwnerInitCustomer (&owner, NULL); + break; + case GNC_OWNER_VENDOR: + gncOwnerInitVendor (&owner, NULL); + break; + case GNC_OWNER_JOB: + gncOwnerInitJob (&owner, NULL); + break; + default: + return NULL; + } + + widget = gnc_owner_select_create (NULL, hbox, + gnc_get_current_book (), &owner); + gnc_option_set_widget (option, widget); + + gtk_signal_connect (GTK_OBJECT (widget), "changed", + GTK_SIGNAL_FUNC (owner_changed_cb), option); + + return widget; +} + +static GtkWidget * +make_name_label (char *name) +{ + GtkWidget *label; + gchar *colon_name; + + colon_name = g_strconcat (name, ":", NULL); + label = gtk_label_new (colon_name); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + g_free (colon_name); + + return label; +} + +/********************************************************************/ +/* "Owner" Option functions */ + + +static GncOwnerType +get_owner_type_from_option (GNCOption *option) +{ + SCM odata = gnc_option_get_option_data (option); + SCM conv_func; + + conv_func = gh_eval_str ("gw:enum--val->int"); + odata = gh_call1 (conv_func, odata); + + return gh_scm2long (odata); +} + + +/* Function to set the UI widget based upon the option */ +static GtkWidget * +owner_set_widget (GNCOption *option, GtkBox *page_box, + GtkTooltips *tooltips, + char *name, char *documentation, + /* Return values */ + GtkWidget **enclosing, gboolean *packed) +{ + GtkWidget *value; + GtkWidget *label; + + *enclosing = gtk_hbox_new (FALSE, 5); + label = make_name_label (name); + gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0); + + value = create_owner_widget (option, get_owner_type_from_option (option), + *enclosing); + + gnc_option_set_ui_value (option, FALSE); + + gtk_widget_show_all (*enclosing); + return value; +} + +/* Function to set the UI Value for a particular option */ +static gboolean +owner_set_value (GNCOption *option, gboolean use_default, + GtkWidget *widget, SCM value) +{ + GncOwner owner_def; + GncOwner *owner; + + if (!gw_wcp_p (value)) + scm_misc_error("business_options:owner_set_value", + "Item is not a gw:wcp.", value); + + owner = gw_wcp_get_ptr (value); + + /* XXX: should we verify that the owner type is correct? */ + if (!owner) { + owner_def.type = get_owner_type_from_option (option); + owner_def.owner.undefined = NULL; + owner = &owner_def; + } + + widget = gnc_option_get_widget (option); + gnc_owner_set_owner (widget, owner); + return FALSE; +} + +/* Function to get the UI Value for a particular option */ +static SCM +owner_get_value (GNCOption *option, GtkWidget *widget) +{ + static GncOwner owner; /* XXX: might cause trouble? */ + GncOwnerType type; + + type = get_owner_type_from_option (option); + owner.type = type; + gnc_owner_get_owner (widget, &owner); + + return gw_wcp_assimilate_ptr (&owner, gh_eval_str("")); +} + + +/********************************************************************/ +/* "Customer" Option functions */ + + +/* Function to set the UI widget based upon the option */ +static GtkWidget * +customer_set_widget (GNCOption *option, GtkBox *page_box, + GtkTooltips *tooltips, + char *name, char *documentation, + /* Return values */ + GtkWidget **enclosing, gboolean *packed) +{ + GtkWidget *value; + GtkWidget *label; + + *enclosing = gtk_hbox_new (FALSE, 5); + label = make_name_label (name); + gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0); + + value = create_owner_widget (option, GNC_OWNER_CUSTOMER, *enclosing); + + gnc_option_set_ui_value (option, FALSE); + + gtk_widget_show_all (*enclosing); + return value; +} + +/* Function to set the UI Value for a particular option */ +static gboolean +customer_set_value (GNCOption *option, gboolean use_default, + GtkWidget *widget, SCM value) +{ + GncOwner owner; + GncCustomer *customer; + + if (!gw_wcp_p (value)) + scm_misc_error("business_options:customer_set_value", + "Item is not a gw:wcp.", value); + + customer = gw_wcp_get_ptr (value); + gncOwnerInitCustomer (&owner, customer); + + widget = gnc_option_get_widget (option); + gnc_owner_set_owner (widget, &owner); + return FALSE; +} + +/* Function to get the UI Value for a particular option */ +static SCM +customer_get_value (GNCOption *option, GtkWidget *widget) +{ + GncOwner owner; + + gnc_owner_get_owner (widget, &owner); + + return gw_wcp_assimilate_ptr (owner.owner.undefined, + gh_eval_str("")); +} + + +/********************************************************************/ +/* "Vendor" Option functions */ + + +/* Function to set the UI widget based upon the option */ +static GtkWidget * +vendor_set_widget (GNCOption *option, GtkBox *page_box, + GtkTooltips *tooltips, + char *name, char *documentation, + /* Return values */ + GtkWidget **enclosing, gboolean *packed) +{ + GtkWidget *value; + GtkWidget *label; + + *enclosing = gtk_hbox_new (FALSE, 5); + label = make_name_label (name); + gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0); + + value = create_owner_widget (option, GNC_OWNER_VENDOR, *enclosing); + + gnc_option_set_ui_value (option, FALSE); + + gtk_widget_show_all (*enclosing); + return value; +} + +/* Function to set the UI Value for a particular option */ +static gboolean +vendor_set_value (GNCOption *option, gboolean use_default, + GtkWidget *widget, SCM value) +{ + GncOwner owner; + GncVendor *vendor; + + if (!gw_wcp_p (value)) + scm_misc_error("business_options:vendor_set_value", + "Item is not a gw:wcp.", value); + + vendor = gw_wcp_get_ptr (value); + gncOwnerInitVendor (&owner, vendor); + + widget = gnc_option_get_widget (option); + gnc_owner_set_owner (widget, &owner); + return FALSE; +} + +/* Function to get the UI Value for a particular option */ +static SCM +vendor_get_value (GNCOption *option, GtkWidget *widget) +{ + GncOwner owner; + + gnc_owner_get_owner (widget, &owner); + + return gw_wcp_assimilate_ptr (owner.owner.undefined, + gh_eval_str("")); +} + + + + +void +gnc_business_options_initialize (void) +{ + int i; + static GNCOptionDef_t options[] = { + { "owner", owner_set_widget, owner_set_value, owner_get_value }, + { "customer", customer_set_widget, customer_set_value, + customer_get_value }, + { "vendor", vendor_set_widget, vendor_set_value, vendor_get_value }, + { NULL } + }; + + for (i = 0; options[i].option_name; i++) + gnc_options_ui_register_option (&(options[i])); +} diff --git a/src/business/business-gnome/business-options.h b/src/business/business-gnome/business-options.h new file mode 100644 index 0000000000..6ac18d860e --- /dev/null +++ b/src/business/business-gnome/business-options.h @@ -0,0 +1,13 @@ +/* + * business-options.h -- Initialize the Business Options + * + * Written By: Derek Atkins + * Copyright (C) 2002 + */ + +#ifndef GNC_BUSINESS_OPTIONS_H_ +#define GNC_BUSINESS_OPTIONS_H_ + +void gnc_business_options_initialize (void); + +#endif /* GNC_BUSINESS_OPTIONS_H_ */ diff --git a/src/business/business-gnome/business-utils.c b/src/business/business-gnome/business-utils.c index 57d5955eec..048c0a4a9e 100644 --- a/src/business/business-gnome/business-utils.c +++ b/src/business/business-gnome/business-utils.c @@ -89,7 +89,7 @@ static GtkWidget * gnc_owner_new (GtkWidget *label, GtkWidget *hbox, gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit), owner->owner.undefined); - gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0); if (label) gtk_label_set_text (GTK_LABEL (label), gncObjectGetTypeLabel (type_name)); diff --git a/src/business/business-gnome/businessmod-gnome.c b/src/business/business-gnome/businessmod-gnome.c index 99cb2a70e1..c562838c79 100644 --- a/src/business/business-gnome/businessmod-gnome.c +++ b/src/business/business-gnome/businessmod-gnome.c @@ -16,6 +16,7 @@ #include "search-core-type.h" #include "search-owner.h" #include "gncOwner.h" +#include "business-options.h" #include "business-urls.h" /* version of the gnc module system interface we require */ @@ -78,6 +79,7 @@ libgncmod_business_gnome_LTX_gnc_module_init(int refcount) gnc_search_core_register_type (GNC_OWNER_MODULE_NAME, (GNCSearchCoreNew) gnc_search_owner_new); gnc_business_urls_initialize (); + gnc_business_options_initialize (); } return TRUE; diff --git a/src/business/business-reports/owner-report.scm b/src/business/business-reports/owner-report.scm index cbc4b7b8b5..3c62bd95b8 100644 --- a/src/business/business-reports/owner-report.scm +++ b/src/business/business-reports/owner-report.scm @@ -20,6 +20,7 @@ (define acct-string (N_ "Account")) (define owner-string (N_ "Company")) +(define owner-page gnc:pagename-general) (define-macro (addto! alist element) `(set! ,alist (cons ,element ,alist))) @@ -257,8 +258,9 @@ (gnc:register-option gnc:*report-options* new-option)) (gnc:register-inv-option - (gnc:make-owner-option "__reg" owner-string "" "" - (lambda () #f) #f owner-type)) + (gnc:make-owner-option owner-page owner-string "v" + (N_ "The company for this report") + (lambda () #f) #f owner-type)) (gnc:register-inv-option (gnc:make-account-list-limited-option acct-string acct-string "" "" @@ -295,8 +297,8 @@ (gnc:register-inv-option (gnc:make-string-option - (N_ "Display") (N_ "Today Date Format") - "v" (N_ "The format for the date->string conversion for today's date.") + gnc:pagename-general (N_ "Today Date Format") + "p" (N_ "The format for the date->string conversion for today's date.") "~B ~e, ~Y")) (gnc:options-set-default-section gnc:*report-options* "General") @@ -429,7 +431,7 @@ (query (gnc:malloc-query)) (account-list (opt-val acct-string acct-string)) (account #f) - (owner (opt-val "__reg" owner-string)) + (owner (opt-val owner-page owner-string)) (report-date (gnc:timepair-end-day-time (gnc:date-option-absolute-time (opt-val gnc:pagename-general (N_ "To"))))) @@ -477,7 +479,7 @@ (gnc:html-document-add-object! document - (make-myname-table (opt-val "Display" "Today Date Format"))) + (make-myname-table (opt-val gnc:pagename-general (N_ "Today Date Format")))) (gnc:html-document-add-object! document @@ -534,20 +536,22 @@ (gnc:define-report 'version 1 'name (N_ "Customer Report") + 'menu-path (list gnc:menuname-business-reports) 'options-generator customer-options-generator 'renderer reg-renderer - 'in-menu? #f) + 'in-menu? #t) (gnc:define-report 'version 1 'name (N_ "Vendor Report") + 'menu-path (list gnc:menuname-business-reports) 'options-generator vendor-options-generator 'renderer reg-renderer - 'in-menu? #f) + 'in-menu? #t) (define (owner-report-create-internal report-name owner account) (let* ((options (gnc:make-report-options report-name)) - (owner-op (gnc:lookup-option options "__reg" owner-string)) + (owner-op (gnc:lookup-option options owner-page owner-string)) (account-op (gnc:lookup-option options acct-string acct-string))) (gnc:option-set-value owner-op owner)