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