28 #include <glib/gi18n.h>
29 #include "swig-runtime.h"
33 #include "dialog-utils.h"
35 #include "option-util.h"
36 #include "gnc-general-search.h"
38 #include "dialog-options.h"
39 #include "business-options-gnome.h"
40 #include "business-gnome-utils.h"
41 #include "dialog-invoice.h"
43 #define FUNC_NAME G_STRFUNC
46 create_owner_widget (
GNCOption *option, GncOwnerType type, GtkWidget *hbox)
53 case GNC_OWNER_CUSTOMER:
54 gncOwnerInitCustomer (&owner, NULL);
56 case GNC_OWNER_VENDOR:
57 gncOwnerInitVendor (&owner, NULL);
59 case GNC_OWNER_EMPLOYEE:
60 gncOwnerInitEmployee (&owner, NULL);
63 gncOwnerInitJob (&owner, NULL);
69 widget = gnc_owner_select_create (NULL, hbox,
70 gnc_get_current_book (), &owner);
71 gnc_option_set_widget (option, widget);
73 g_signal_connect (G_OBJECT (widget),
"changed",
74 G_CALLBACK (gnc_option_changed_option_cb), option);
80 make_name_label (
char *name)
85 colon_name = g_strconcat (name,
":", (
char *)NULL);
86 label = gtk_label_new (colon_name);
87 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
98 get_owner_type_from_option (
GNCOption *option)
100 SCM odata = gnc_option_get_option_data (option);
103 return (GncOwnerType) scm_to_int(odata);
109 owner_set_widget (
GNCOption *option, GtkBox *page_box,
110 char *name,
char *documentation,
112 GtkWidget **enclosing, gboolean *packed)
117 *enclosing = gtk_hbox_new (FALSE, 5);
118 label = make_name_label (name);
119 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
121 value = create_owner_widget (option, get_owner_type_from_option (option),
124 gnc_option_set_ui_value (option, FALSE);
126 gtk_widget_show_all (*enclosing);
132 owner_set_value (
GNCOption *option, gboolean use_default,
133 GtkWidget *widget, SCM value)
138 if (!SWIG_IsPointer (value))
139 scm_misc_error(
"business_options:owner_set_value",
140 "SCM is not a wrapped pointer.", value);
142 owner = SWIG_MustGetPtr(value, SWIG_TypeQuery(
"_p__gncOwner"), 1, 0);
147 owner_def.type = get_owner_type_from_option (option);
148 owner_def.owner.undefined = NULL;
152 widget = gnc_option_get_gtk_widget (option);
153 gnc_owner_set_owner (widget, owner);
159 owner_get_value (
GNCOption *option, GtkWidget *widget)
164 type = get_owner_type_from_option (option);
166 gnc_owner_get_owner (widget, &owner);
168 return SWIG_NewPointerObj(&owner, SWIG_TypeQuery(
"_p__gncOwner"), 0);
178 customer_set_widget (
GNCOption *option, GtkBox *page_box,
179 char *name,
char *documentation,
181 GtkWidget **enclosing, gboolean *packed)
186 *enclosing = gtk_hbox_new (FALSE, 5);
187 label = make_name_label (name);
188 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
190 value = create_owner_widget (option, GNC_OWNER_CUSTOMER, *enclosing);
192 gnc_option_set_ui_value (option, FALSE);
194 gtk_widget_show_all (*enclosing);
200 customer_set_value (
GNCOption *option, gboolean use_default,
201 GtkWidget *widget, SCM value)
206 if (!SWIG_IsPointer (value))
207 scm_misc_error(
"business_options:customer_set_value",
208 "SCM is not a wrapped pointer.", value);
210 customer = SWIG_MustGetPtr(value, SWIG_TypeQuery(
"_p__gncCustomer"), 1, 0);
211 gncOwnerInitCustomer (&owner, customer);
213 widget = gnc_option_get_gtk_widget (option);
214 gnc_owner_set_owner (widget, &owner);
220 customer_get_value (
GNCOption *option, GtkWidget *widget)
224 gnc_owner_get_owner (widget, &owner);
225 return SWIG_NewPointerObj(owner.owner.undefined,
226 SWIG_TypeQuery(
"_p__gncCustomer"), 0);
236 vendor_set_widget (
GNCOption *option, GtkBox *page_box,
237 char *name,
char *documentation,
239 GtkWidget **enclosing, gboolean *packed)
244 *enclosing = gtk_hbox_new (FALSE, 5);
245 label = make_name_label (name);
246 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
248 value = create_owner_widget (option, GNC_OWNER_VENDOR, *enclosing);
250 gnc_option_set_ui_value (option, FALSE);
252 gtk_widget_show_all (*enclosing);
258 vendor_set_value (
GNCOption *option, gboolean use_default,
259 GtkWidget *widget, SCM value)
264 if (!SWIG_IsPointer (value))
265 scm_misc_error(
"business_options:vendor_set_value",
266 "SCM is not a wrapped pointer.", value);
268 vendor = SWIG_MustGetPtr(value, SWIG_TypeQuery(
"_p__gncVendor"), 1, 0);
269 gncOwnerInitVendor (&owner, vendor);
271 widget = gnc_option_get_gtk_widget (option);
272 gnc_owner_set_owner (widget, &owner);
278 vendor_get_value (
GNCOption *option, GtkWidget *widget)
282 gnc_owner_get_owner (widget, &owner);
283 return SWIG_NewPointerObj(owner.owner.undefined,
284 SWIG_TypeQuery(
"_p__gncVendor"), 0);
293 employee_set_widget (
GNCOption *option, GtkBox *page_box,
294 char *name,
char *documentation,
296 GtkWidget **enclosing, gboolean *packed)
301 *enclosing = gtk_hbox_new (FALSE, 5);
302 label = make_name_label (name);
303 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
305 value = create_owner_widget (option, GNC_OWNER_EMPLOYEE, *enclosing);
307 gnc_option_set_ui_value (option, FALSE);
309 gtk_widget_show_all (*enclosing);
315 employee_set_value (
GNCOption *option, gboolean use_default,
316 GtkWidget *widget, SCM value)
321 if (!SWIG_IsPointer (value))
322 scm_misc_error(
"business_options:employee_set_value",
323 "SCM is not a wrapped pointer.", value);
325 employee = SWIG_MustGetPtr(value, SWIG_TypeQuery(
"_p__gncEmployee"), 1, 0);
326 gncOwnerInitEmployee (&owner, employee);
328 widget = gnc_option_get_gtk_widget (option);
329 gnc_owner_set_owner (widget, &owner);
335 employee_get_value (
GNCOption *option, GtkWidget *widget)
339 gnc_owner_get_owner (widget, &owner);
341 return SWIG_NewPointerObj(owner.owner.undefined,
342 SWIG_TypeQuery(
"_p__gncEmployee"), 0);
350 create_invoice_widget (
GNCOption *option, GtkWidget *hbox)
355 widget = gnc_invoice_select_create (hbox, gnc_get_current_book(),
358 gnc_option_set_widget (option, widget);
359 g_signal_connect (G_OBJECT (widget),
"changed",
360 G_CALLBACK (gnc_option_changed_option_cb), option);
367 invoice_set_widget (
GNCOption *option, GtkBox *page_box,
368 char *name,
char *documentation,
370 GtkWidget **enclosing, gboolean *packed)
375 *enclosing = gtk_hbox_new (FALSE, 5);
376 label = make_name_label (name);
377 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
379 value = create_invoice_widget (option, *enclosing);
381 gnc_option_set_ui_value (option, FALSE);
383 gtk_widget_show_all (*enclosing);
389 invoice_set_value (
GNCOption *option, gboolean use_default,
390 GtkWidget *widget, SCM value)
394 if (!SWIG_IsPointer (value))
395 scm_misc_error(
"business_options:invoice_set_value",
396 "SCM is not a wrapped pointer.", value);
398 invoice = SWIG_MustGetPtr(value, SWIG_TypeQuery(
"_p__gncInvoice"), 1, 0);
400 widget = gnc_option_get_gtk_widget (option);
401 gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
407 invoice_get_value (
GNCOption *option, GtkWidget *widget)
411 invoice = gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
412 return SWIG_NewPointerObj(invoice, SWIG_TypeQuery(
"_p__gncInvoice"), 0);
421 create_taxtable_widget (
GNCOption *option, GtkWidget *hbox)
426 builder = gtk_builder_new();
427 gnc_builder_add_from_file (builder,
"business-options-gnome.glade",
"taxtable_store");
428 gnc_builder_add_from_file (builder,
"business-options-gnome.glade",
"taxtable_menu");
430 widget = GTK_WIDGET (gtk_builder_get_object (builder,
"taxtable_menu"));
431 gnc_taxtables_combo (GTK_COMBO_BOX(widget), gnc_get_current_book (), TRUE, NULL);
432 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
434 gnc_option_set_widget (option, widget);
436 g_signal_connect (widget,
"changed",
437 G_CALLBACK (gnc_option_changed_option_cb), option);
439 g_object_unref(G_OBJECT(builder));
445 taxtable_set_widget (
GNCOption *option, GtkBox *page_box,
446 char *name,
char *documentation,
448 GtkWidget **enclosing, gboolean *packed)
453 *enclosing = gtk_hbox_new (FALSE, 5);
454 label = make_name_label (name);
455 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
457 value = create_taxtable_widget (option, *enclosing);
459 gnc_option_set_ui_value (option, FALSE);
461 gtk_widget_show_all (*enclosing);
467 taxtable_set_value (
GNCOption *option, gboolean use_default,
468 GtkWidget *widget, SCM value)
472 if (!SWIG_IsPointer (value))
473 scm_misc_error(
"business_options:taxtable_set_value",
474 "SCM is not a wrapped pointer.", value);
476 taxtable = SWIG_MustGetPtr(value, SWIG_TypeQuery(
"_p__gncTaxTable"), 1, 0);
478 widget = gnc_option_get_gtk_widget (option);
479 gnc_simple_combo_set_value (GTK_COMBO_BOX(widget), taxtable);
485 taxtable_get_value (
GNCOption *option, GtkWidget *widget)
489 taxtable = gnc_simple_combo_get_value (GTK_COMBO_BOX(widget));
490 return SWIG_NewPointerObj(taxtable, SWIG_TypeQuery(
"_p__gncTaxTable"), 0);
497 gnc_business_options_gnome_initialize (
void)
502 {
"owner", owner_set_widget, owner_set_value, owner_get_value },
504 "customer", customer_set_widget, customer_set_value,
507 {
"vendor", vendor_set_widget, vendor_set_value, vendor_get_value },
508 {
"employee", employee_set_widget, employee_set_value, employee_get_value },
509 {
"invoice", invoice_set_widget, invoice_set_value, invoice_get_value },
510 {
"taxtable", taxtable_set_widget, taxtable_set_value, taxtable_get_value },
514 SWIG_GetModule(NULL);
515 for (i = 0; options[i].option_name; i++)
516 gnc_options_ui_register_option (&(options[i]));
utility functions for the GnuCash UI