From 47032f36870d503d90eeadf4df90226237bbd385 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sun, 30 Jan 2011 10:21:48 +0000 Subject: [PATCH] Get rid of gtk dependency in header by storing only a gpointer for the widget. This means the very last part of a gtk-dependency in app-util is in option-util.c in one error message. My goal is to remove gtk completely from app-util so that all code in our dependency chain up to app-util can be packaged into a GUI-independent library, which can then be used by the python wrappers and other GUI frontends alike. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20204 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/option-util.c | 6 +-- src/app-utils/option-util.h | 37 +++++-------------- .../business-gnome/business-options-gnome.c | 12 +++--- src/gnome-utils/dialog-options.c | 36 ++++++++++-------- src/gnome-utils/dialog-options.h | 6 ++- 5 files changed, 44 insertions(+), 53 deletions(-) diff --git a/src/app-utils/option-util.c b/src/app-utils/option-util.c index f6d339ebd3..95205cb326 100644 --- a/src/app-utils/option-util.c +++ b/src/app-utils/option-util.c @@ -56,7 +56,7 @@ struct gnc_option gboolean changed; /* The widget which is holding this option */ - GncOptionWidgetPtr widget; + gpointer widget; /* The option db which holds this option */ GNCOptionDB *odb; @@ -140,7 +140,7 @@ gnc_option_set_changed (GNCOption *option, gboolean changed) option->changed = changed; } -GncOptionWidgetPtr +gpointer gnc_option_get_widget (GNCOption *option) { if (!option) return NULL; @@ -148,7 +148,7 @@ gnc_option_get_widget (GNCOption *option) } void -gnc_option_set_widget (GNCOption *option, GncOptionWidgetPtr widget) +gnc_option_set_widget (GNCOption *option, gpointer widget) { g_return_if_fail (option != NULL); option->widget = widget; diff --git a/src/app-utils/option-util.h b/src/app-utils/option-util.h index aa03336bcc..aa989e8c57 100644 --- a/src/app-utils/option-util.h +++ b/src/app-utils/option-util.h @@ -32,32 +32,6 @@ #include "qof.h" #include "GNCId.h" -#if defined(GNOME) -# include -#endif - -/** This is the opaque pointer to this option's widget. - * - * Note: This option code is still almost GUI-independent because it - * does not deal with the UI implementation of the option's widgets, - * but it stores a pointer to a widget (and incidentally some of the - * implementation might show an error message through the gtk-specific - * message box). Hence, the option code just stores a pointer - * transparently, which is where the GncOptionWidgetPtr typedef comes - * from. We keep this typedef just in this file to underline that the - * code of option-utils.[hc] might still be re-usable in a - * UI-independent usage, even though the only implementation is a gtk - * one. */ -typedef -#if defined(GNOME) -GtkWidget * -#else -/* **** No GUI selected *** */ -void * -#endif -GncOptionWidgetPtr; - - typedef struct gnc_option GNCOption; typedef struct gnc_option_section GNCOptionSection; typedef struct gnc_option_db GNCOptionDB; @@ -76,8 +50,15 @@ typedef void (*GNCOptionChangeCallback) (gpointer user_data); gboolean gnc_option_get_changed (GNCOption *option); void gnc_option_set_changed (GNCOption *option, gboolean changed); -GncOptionWidgetPtr gnc_option_get_widget (GNCOption *option); -void gnc_option_set_widget (GNCOption *option, GncOptionWidgetPtr widget); +/** Returns an opaque pointer to the widget of this option. The actual + * GUI implementation in dialog-options.c will store a GtkWidget* in + * here. */ +gpointer gnc_option_get_widget (GNCOption *option); + +/** Store an opaque pointer to the widget of this option. The actual + * GUI implementation in dialog-options.c will store a GtkWidget* in + * here. */ +void gnc_option_set_widget (GNCOption *option, gpointer widget); SCM gnc_option_get_ui_value(GNCOption *option); void gnc_option_set_ui_value(GNCOption *option, gboolean use_default); diff --git a/src/business/business-gnome/business-options-gnome.c b/src/business/business-gnome/business-options-gnome.c index a0adf6ef35..d05c3abdc8 100644 --- a/src/business/business-gnome/business-options-gnome.c +++ b/src/business/business-gnome/business-options-gnome.c @@ -149,7 +149,7 @@ owner_set_value (GNCOption *option, gboolean use_default, owner = &owner_def; } - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_owner_set_owner (widget, owner); return FALSE; } @@ -211,7 +211,7 @@ customer_set_value (GNCOption *option, gboolean use_default, customer = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0); gncOwnerInitCustomer (&owner, customer); - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_owner_set_owner (widget, &owner); return FALSE; } @@ -270,7 +270,7 @@ vendor_set_value (GNCOption *option, gboolean use_default, vendor = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncVendor"), 1, 0); gncOwnerInitVendor (&owner, vendor); - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_owner_set_owner (widget, &owner); return FALSE; } @@ -328,7 +328,7 @@ employee_set_value (GNCOption *option, gboolean use_default, employee = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncEmployee"), 1, 0); gncOwnerInitEmployee (&owner, employee); - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_owner_set_owner (widget, &owner); return FALSE; } @@ -401,7 +401,7 @@ invoice_set_value (GNCOption *option, gboolean use_default, invoice = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncInvoice"), 1, 0); - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice); return FALSE; } @@ -476,7 +476,7 @@ taxtable_set_value (GNCOption *option, gboolean use_default, taxtable = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncTaxTable"), 1, 0); - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_ui_optionmenu_set_value (widget, taxtable); return FALSE; } diff --git a/src/gnome-utils/dialog-options.c b/src/gnome-utils/dialog-options.c index e9ef676283..cffe2df067 100644 --- a/src/gnome-utils/dialog-options.c +++ b/src/gnome-utils/dialog-options.c @@ -117,6 +117,12 @@ void gnc_options_dialog_list_select_cb(GtkWidget * list, GtkWidget * item, gpointer data); +GtkWidget * +gnc_option_get_gtk_widget (GNCOption *option) +{ + return (GtkWidget *)gnc_option_get_widget(option); +} + static inline gint color_d_to_i16 (double d) { @@ -165,7 +171,7 @@ gnc_option_changed_option_cb(GtkWidget *dummy, GNCOption *option) { GtkWidget *widget; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); gnc_option_changed_widget_cb(widget, option); } @@ -177,7 +183,7 @@ gnc_date_option_set_select_method(GNCOption *option, gboolean use_absolute, GtkWidget *ab_button, *rel_button, *rel_widget, *ab_widget; GtkWidget *widget; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); widget_list = gtk_container_get_children(GTK_CONTAINER(widget)); ab_button = g_list_nth_data(widget_list, GNC_RD_WID_AB_BUTTON_POS); @@ -294,7 +300,7 @@ gnc_option_set_ui_value_internal (GNCOption *option, gboolean use_default) SCM value; GNCOptionDef_t *option_def; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); if (!widget) return; @@ -340,7 +346,7 @@ gnc_option_get_ui_value_internal (GNCOption *option) char *type; GNCOptionDef_t *option_def; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); if (!widget) return result; @@ -378,7 +384,7 @@ gnc_option_set_selectable_internal (GNCOption *option, gboolean selectable) { GtkWidget *widget; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); if (!widget) return; @@ -399,7 +405,7 @@ gnc_option_show_hidden_toggled_cb(GtkWidget *widget, GNCOption* option) AccountViewInfo avi; GncTreeViewAccount *tree_view; - tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_widget (option)); + tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_gtk_widget (option)); gnc_tree_view_account_get_view_info (tree_view, &avi); avi.show_hidden = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); gnc_tree_view_account_set_view_info (tree_view, &avi); @@ -424,7 +430,7 @@ gnc_option_multichoice_cb(GtkWidget *w, gint index, gpointer data) gint current; char *type; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); /* the option menu may be part of a date option widget, so we need to decomposit the enclosing hbox then */ @@ -471,7 +477,7 @@ gnc_option_radiobutton_cb(GtkWidget *w, gpointer data) gpointer _current, _new_value; gint current, new_value; - widget = gnc_option_get_widget (option); + widget = gnc_option_get_gtk_widget (option); _current = g_object_get_data(G_OBJECT(widget), "gnc_radiobutton_index"); current = GPOINTER_TO_INT (_current); @@ -809,7 +815,7 @@ gnc_option_account_select_all_cb(GtkWidget *widget, gpointer data) GncTreeViewAccount *tree_view; GtkTreeSelection *selection; - tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_widget (option)); + tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_gtk_widget (option)); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); gtk_tree_selection_select_all(selection); gnc_option_changed_widget_cb(widget, option); @@ -822,7 +828,7 @@ gnc_option_account_clear_all_cb(GtkWidget *widget, gpointer data) GncTreeViewAccount *tree_view; GtkTreeSelection *selection; - tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_widget (option)); + tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_gtk_widget (option)); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); gtk_tree_selection_unselect_all(selection); gnc_option_changed_widget_cb(widget, option); @@ -835,7 +841,7 @@ gnc_option_account_select_children_cb(GtkWidget *widget, gpointer data) GncTreeViewAccount *tree_view; Account *account; - tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_widget (option)); + tree_view = GNC_TREE_VIEW_ACCOUNT(gnc_option_get_gtk_widget (option)); account = gnc_tree_view_account_get_cursor_account(tree_view); if (!account) return; @@ -988,7 +994,7 @@ gnc_option_list_select_all_cb(GtkWidget *widget, gpointer data) GtkTreeView *view; GtkTreeSelection *selection; - view = GTK_TREE_VIEW(gnc_option_get_widget (option)); + view = GTK_TREE_VIEW(gnc_option_get_gtk_widget (option)); selection = gtk_tree_view_get_selection(view); gtk_tree_selection_select_all(selection); gnc_option_changed_widget_cb(GTK_WIDGET(view), option); @@ -1001,7 +1007,7 @@ gnc_option_list_clear_all_cb(GtkWidget *widget, gpointer data) GtkTreeView *view; GtkTreeSelection *selection; - view = GTK_TREE_VIEW(gnc_option_get_widget (option)); + view = GTK_TREE_VIEW(gnc_option_get_gtk_widget (option)); selection = gtk_tree_view_get_selection(view); gtk_tree_selection_unselect_all(selection); gnc_option_changed_widget_cb(GTK_WIDGET(view), option); @@ -1864,7 +1870,7 @@ gnc_option_set_ui_widget_account_list (GNCOption *option, GtkBox *page_box, GtkTreeSelection *selection; *enclosing = gnc_option_create_account_widget(option, name, tooltips); - value = gnc_option_get_widget (option); + value = gnc_option_get_gtk_widget (option); gtk_tooltips_set_tip(tooltips, *enclosing, documentation, NULL); @@ -1932,7 +1938,7 @@ gnc_option_set_ui_widget_list (GNCOption *option, GtkBox *page_box, GtkWidget *eventbox; *enclosing = gnc_option_create_list_widget(option, name, tooltips); - value = gnc_option_get_widget (option); + value = gnc_option_get_gtk_widget (option); /* Pack option widget into an extra eventbox because otherwise the "documentation" tooltip is not displayed. */ diff --git a/src/gnome-utils/dialog-options.h b/src/gnome-utils/dialog-options.h index 994aab88f0..952ade391f 100644 --- a/src/gnome-utils/dialog-options.h +++ b/src/gnome-utils/dialog-options.h @@ -24,8 +24,12 @@ #define OPTIONS_DIALOG_H #include - #include "option-util.h" +#include + +/** A simple wrapper that casts the gpointer result of + * gnc_option_get_widget() already into a GtkWidget*. */ +GtkWidget *gnc_option_get_gtk_widget (GNCOption *option); typedef struct gnc_option_win GNCOptionWin;