Get rid of gtk dependency in <app-util/option-util.h> 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
This commit is contained in:
Christian Stimming 2011-01-30 10:21:48 +00:00
parent 5cb52dbdb5
commit 47032f3687
5 changed files with 44 additions and 53 deletions

View File

@ -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;

View File

@ -32,32 +32,6 @@
#include "qof.h"
#include "GNCId.h"
#if defined(GNOME)
# include <gtk/gtk.h>
#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);

View File

@ -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;
}

View File

@ -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. */

View File

@ -24,8 +24,12 @@
#define OPTIONS_DIALOG_H
#include <libguile.h>
#include "option-util.h"
#include <gtk/gtk.h>
/** 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;