00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "config.h"
00026
00027 #include <gtk/gtk.h>
00028 #include <glib/gi18n.h>
00029 #include "swig-runtime.h"
00030 #include <libguile.h>
00031
00032 #include "gnc-ui-util.h"
00033 #include "qof.h"
00034 #include "option-util.h"
00035 #include "gnc-general-search.h"
00036
00037 #include "dialog-options.h"
00038 #include "business-options-gnome.h"
00039 #include "business-gnome-utils.h"
00040 #include "dialog-invoice.h"
00041
00042 #define FUNC_NAME G_STRFUNC
00043
00044 static GtkWidget *
00045 create_owner_widget (GNCOption *option, GncOwnerType type, GtkWidget *hbox)
00046 {
00047 GtkWidget *widget;
00048 GncOwner owner;
00049
00050 switch (type)
00051 {
00052 case GNC_OWNER_CUSTOMER:
00053 gncOwnerInitCustomer (&owner, NULL);
00054 break;
00055 case GNC_OWNER_VENDOR:
00056 gncOwnerInitVendor (&owner, NULL);
00057 break;
00058 case GNC_OWNER_EMPLOYEE:
00059 gncOwnerInitEmployee (&owner, NULL);
00060 break;
00061 case GNC_OWNER_JOB:
00062 gncOwnerInitJob (&owner, NULL);
00063 break;
00064 default:
00065 return NULL;
00066 }
00067
00068 widget = gnc_owner_select_create (NULL, hbox,
00069 gnc_get_current_book (), &owner);
00070 gnc_option_set_widget (option, widget);
00071
00072 g_signal_connect (G_OBJECT (widget), "changed",
00073 G_CALLBACK (gnc_option_changed_option_cb), option);
00074
00075 return widget;
00076 }
00077
00078 static GtkWidget *
00079 make_name_label (char *name)
00080 {
00081 GtkWidget *label;
00082 gchar *colon_name;
00083
00084 colon_name = g_strconcat (name, ":", (char *)NULL);
00085 label = gtk_label_new (colon_name);
00086 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
00087 g_free (colon_name);
00088
00089 return label;
00090 }
00091
00092
00093
00094
00095
00096 static GncOwnerType
00097 get_owner_type_from_option (GNCOption *option)
00098 {
00099 SCM odata = gnc_option_get_option_data (option);
00100
00101
00102 return (GncOwnerType) scm_num2int(odata, SCM_ARG1, G_STRFUNC);
00103 }
00104
00105
00106
00107 static GtkWidget *
00108 owner_set_widget (GNCOption *option, GtkBox *page_box,
00109 GtkTooltips *tooltips,
00110 char *name, char *documentation,
00111
00112 GtkWidget **enclosing, gboolean *packed)
00113 {
00114 GtkWidget *value;
00115 GtkWidget *label;
00116
00117 *enclosing = gtk_hbox_new (FALSE, 5);
00118 label = make_name_label (name);
00119 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
00120
00121 value = create_owner_widget (option, get_owner_type_from_option (option),
00122 *enclosing);
00123
00124 gnc_option_set_ui_value (option, FALSE);
00125
00126 gtk_widget_show_all (*enclosing);
00127 return value;
00128 }
00129
00130
00131 static gboolean
00132 owner_set_value (GNCOption *option, gboolean use_default,
00133 GtkWidget *widget, SCM value)
00134 {
00135 GncOwner owner_def;
00136 GncOwner *owner;
00137
00138 if (!SWIG_IsPointer (value))
00139 scm_misc_error("business_options:owner_set_value",
00140 "SCM is not a wrapped pointer.", value);
00141
00142 owner = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncOwner"), 1, 0);
00143
00144
00145 if (!owner)
00146 {
00147 owner_def.type = get_owner_type_from_option (option);
00148 owner_def.owner.undefined = NULL;
00149 owner = &owner_def;
00150 }
00151
00152 widget = gnc_option_get_gtk_widget (option);
00153 gnc_owner_set_owner (widget, owner);
00154 return FALSE;
00155 }
00156
00157
00158 static SCM
00159 owner_get_value (GNCOption *option, GtkWidget *widget)
00160 {
00161 static GncOwner owner;
00162 GncOwnerType type;
00163
00164 type = get_owner_type_from_option (option);
00165 owner.type = type;
00166 gnc_owner_get_owner (widget, &owner);
00167
00168 return SWIG_NewPointerObj(&owner, SWIG_TypeQuery("_p__gncOwner"), 0);
00169 }
00170
00171
00172
00173
00174
00175
00176
00177 static GtkWidget *
00178 customer_set_widget (GNCOption *option, GtkBox *page_box,
00179 GtkTooltips *tooltips,
00180 char *name, char *documentation,
00181
00182 GtkWidget **enclosing, gboolean *packed)
00183 {
00184 GtkWidget *value;
00185 GtkWidget *label;
00186
00187 *enclosing = gtk_hbox_new (FALSE, 5);
00188 label = make_name_label (name);
00189 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
00190
00191 value = create_owner_widget (option, GNC_OWNER_CUSTOMER, *enclosing);
00192
00193 gnc_option_set_ui_value (option, FALSE);
00194
00195 gtk_widget_show_all (*enclosing);
00196 return value;
00197 }
00198
00199
00200 static gboolean
00201 customer_set_value (GNCOption *option, gboolean use_default,
00202 GtkWidget *widget, SCM value)
00203 {
00204 GncOwner owner;
00205 GncCustomer *customer;
00206
00207 if (!SWIG_IsPointer (value))
00208 scm_misc_error("business_options:customer_set_value",
00209 "SCM is not a wrapped pointer.", value);
00210
00211 customer = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0);
00212 gncOwnerInitCustomer (&owner, customer);
00213
00214 widget = gnc_option_get_gtk_widget (option);
00215 gnc_owner_set_owner (widget, &owner);
00216 return FALSE;
00217 }
00218
00219
00220 static SCM
00221 customer_get_value (GNCOption *option, GtkWidget *widget)
00222 {
00223 GncOwner owner;
00224
00225 gnc_owner_get_owner (widget, &owner);
00226 return SWIG_NewPointerObj(owner.owner.undefined,
00227 SWIG_TypeQuery("_p__gncCustomer"), 0);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 static GtkWidget *
00237 vendor_set_widget (GNCOption *option, GtkBox *page_box,
00238 GtkTooltips *tooltips,
00239 char *name, char *documentation,
00240
00241 GtkWidget **enclosing, gboolean *packed)
00242 {
00243 GtkWidget *value;
00244 GtkWidget *label;
00245
00246 *enclosing = gtk_hbox_new (FALSE, 5);
00247 label = make_name_label (name);
00248 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
00249
00250 value = create_owner_widget (option, GNC_OWNER_VENDOR, *enclosing);
00251
00252 gnc_option_set_ui_value (option, FALSE);
00253
00254 gtk_widget_show_all (*enclosing);
00255 return value;
00256 }
00257
00258
00259 static gboolean
00260 vendor_set_value (GNCOption *option, gboolean use_default,
00261 GtkWidget *widget, SCM value)
00262 {
00263 GncOwner owner;
00264 GncVendor *vendor;
00265
00266 if (!SWIG_IsPointer (value))
00267 scm_misc_error("business_options:vendor_set_value",
00268 "SCM is not a wrapped pointer.", value);
00269
00270 vendor = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncVendor"), 1, 0);
00271 gncOwnerInitVendor (&owner, vendor);
00272
00273 widget = gnc_option_get_gtk_widget (option);
00274 gnc_owner_set_owner (widget, &owner);
00275 return FALSE;
00276 }
00277
00278
00279 static SCM
00280 vendor_get_value (GNCOption *option, GtkWidget *widget)
00281 {
00282 GncOwner owner;
00283
00284 gnc_owner_get_owner (widget, &owner);
00285 return SWIG_NewPointerObj(owner.owner.undefined,
00286 SWIG_TypeQuery("_p__gncVendor"), 0);
00287 }
00288
00289
00290
00291
00292
00293
00294 static GtkWidget *
00295 employee_set_widget (GNCOption *option, GtkBox *page_box,
00296 GtkTooltips *tooltips,
00297 char *name, char *documentation,
00298
00299 GtkWidget **enclosing, gboolean *packed)
00300 {
00301 GtkWidget *value;
00302 GtkWidget *label;
00303
00304 *enclosing = gtk_hbox_new (FALSE, 5);
00305 label = make_name_label (name);
00306 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
00307
00308 value = create_owner_widget (option, GNC_OWNER_EMPLOYEE, *enclosing);
00309
00310 gnc_option_set_ui_value (option, FALSE);
00311
00312 gtk_widget_show_all (*enclosing);
00313 return value;
00314 }
00315
00316
00317 static gboolean
00318 employee_set_value (GNCOption *option, gboolean use_default,
00319 GtkWidget *widget, SCM value)
00320 {
00321 GncOwner owner;
00322 GncEmployee *employee;
00323
00324 if (!SWIG_IsPointer (value))
00325 scm_misc_error("business_options:employee_set_value",
00326 "SCM is not a wrapped pointer.", value);
00327
00328 employee = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncEmployee"), 1, 0);
00329 gncOwnerInitEmployee (&owner, employee);
00330
00331 widget = gnc_option_get_gtk_widget (option);
00332 gnc_owner_set_owner (widget, &owner);
00333 return FALSE;
00334 }
00335
00336
00337 static SCM
00338 employee_get_value (GNCOption *option, GtkWidget *widget)
00339 {
00340 GncOwner owner;
00341
00342 gnc_owner_get_owner (widget, &owner);
00343
00344 return SWIG_NewPointerObj(owner.owner.undefined,
00345 SWIG_TypeQuery("_p__gncEmployee"), 0);
00346 }
00347
00348
00349
00350
00351
00352 static GtkWidget *
00353 create_invoice_widget (GNCOption *option, GtkWidget *hbox)
00354 {
00355 GtkWidget *widget;
00356
00357
00358 widget = gnc_invoice_select_create (hbox, gnc_get_current_book(),
00359 NULL, NULL, NULL);
00360
00361 gnc_option_set_widget (option, widget);
00362 g_signal_connect (G_OBJECT (widget), "changed",
00363 G_CALLBACK (gnc_option_changed_option_cb), option);
00364
00365 return widget;
00366 }
00367
00368
00369 static GtkWidget *
00370 invoice_set_widget (GNCOption *option, GtkBox *page_box,
00371 GtkTooltips *tooltips,
00372 char *name, char *documentation,
00373
00374 GtkWidget **enclosing, gboolean *packed)
00375 {
00376 GtkWidget *value;
00377 GtkWidget *label;
00378
00379 *enclosing = gtk_hbox_new (FALSE, 5);
00380 label = make_name_label (name);
00381 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
00382
00383 value = create_invoice_widget (option, *enclosing);
00384
00385 gnc_option_set_ui_value (option, FALSE);
00386
00387 gtk_widget_show_all (*enclosing);
00388 return value;
00389 }
00390
00391
00392 static gboolean
00393 invoice_set_value (GNCOption *option, gboolean use_default,
00394 GtkWidget *widget, SCM value)
00395 {
00396 GncInvoice *invoice;
00397
00398 if (!SWIG_IsPointer (value))
00399 scm_misc_error("business_options:invoice_set_value",
00400 "SCM is not a wrapped pointer.", value);
00401
00402 invoice = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncInvoice"), 1, 0);
00403
00404 widget = gnc_option_get_gtk_widget (option);
00405 gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
00406 return FALSE;
00407 }
00408
00409
00410 static SCM
00411 invoice_get_value (GNCOption *option, GtkWidget *widget)
00412 {
00413 GncInvoice *invoice;
00414
00415 invoice = gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
00416 return SWIG_NewPointerObj(invoice, SWIG_TypeQuery("_p__gncInvoice"), 0);
00417 }
00418
00419
00420
00421
00422
00423
00424 static GtkWidget *
00425 create_taxtable_widget (GNCOption *option, GtkWidget *hbox)
00426 {
00427 GtkWidget *widget;
00428
00429 widget = gtk_option_menu_new ();
00430
00431 gnc_ui_taxtables_optionmenu (widget, gnc_get_current_book (), TRUE, NULL);
00432
00433 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
00434 gnc_option_set_widget (option, widget);
00435
00436 gnc_ui_optionmenu_set_changed_callback (widget,
00437 (void(*)(GtkWidget*, gpointer))gnc_option_changed_option_cb,
00438 option);
00439
00440 return widget;
00441 }
00442
00443
00444 static GtkWidget *
00445 taxtable_set_widget (GNCOption *option, GtkBox *page_box,
00446 GtkTooltips *tooltips,
00447 char *name, char *documentation,
00448
00449 GtkWidget **enclosing, gboolean *packed)
00450 {
00451 GtkWidget *value;
00452 GtkWidget *label;
00453
00454 *enclosing = gtk_hbox_new (FALSE, 5);
00455 label = make_name_label (name);
00456 gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
00457
00458 value = create_taxtable_widget (option, *enclosing);
00459
00460 gnc_option_set_ui_value (option, FALSE);
00461
00462 gtk_widget_show_all (*enclosing);
00463 return value;
00464 }
00465
00466
00467 static gboolean
00468 taxtable_set_value (GNCOption *option, gboolean use_default,
00469 GtkWidget *widget, SCM value)
00470 {
00471 GncTaxTable *taxtable;
00472
00473 if (!SWIG_IsPointer (value))
00474 scm_misc_error("business_options:taxtable_set_value",
00475 "SCM is not a wrapped pointer.", value);
00476
00477 taxtable = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncTaxTable"), 1, 0);
00478
00479 widget = gnc_option_get_gtk_widget (option);
00480 gnc_ui_optionmenu_set_value (widget, taxtable);
00481 return FALSE;
00482 }
00483
00484
00485 static SCM
00486 taxtable_get_value (GNCOption *option, GtkWidget *widget)
00487 {
00488 GncTaxTable *taxtable;
00489
00490 taxtable = gnc_ui_optionmenu_get_value (widget);
00491 return SWIG_NewPointerObj(taxtable, SWIG_TypeQuery("_p__gncTaxTable"), 0);
00492 }
00493
00494
00495
00496
00497 void
00498 gnc_business_options_gnome_initialize (void)
00499 {
00500 int i;
00501 static GNCOptionDef_t options[] =
00502 {
00503 { "owner", owner_set_widget, owner_set_value, owner_get_value },
00504 {
00505 "customer", customer_set_widget, customer_set_value,
00506 customer_get_value
00507 },
00508 { "vendor", vendor_set_widget, vendor_set_value, vendor_get_value },
00509 { "employee", employee_set_widget, employee_set_value, employee_get_value },
00510 { "invoice", invoice_set_widget, invoice_set_value, invoice_get_value },
00511 { "taxtable", taxtable_set_widget, taxtable_set_value, taxtable_get_value },
00512 { NULL }
00513 };
00514
00515 SWIG_GetModule(NULL);
00516 for (i = 0; options[i].option_name; i++)
00517 gnc_options_ui_register_option (&(options[i]));
00518 }