From 0d9ef3fdc010c95fed12724c9790daf0c2d67dfe Mon Sep 17 00:00:00 2001 From: handa Date: Mon, 26 Mar 2007 11:28:09 +0000 Subject: [PATCH] *** empty log message *** --- bootstrap.sh | 4 +-- src/m17n-im-config.h | 21 +++---------- src/main.c | 81 +++++++++++++++++++++++--------------------------- src/mim-config.c | 68 ++++++++++++++++++++++++++---------------- 4 files changed, 87 insertions(+), 87 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index caff9f9..c01e9cf 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -8,13 +8,13 @@ echo "Cleaning up old files..." rm -rf aclocal.m4 autom4te.cache config.guess. ltmain.sh echo "Running aclocal..." -aclocal-1.9 -I m4 +aclocal -I m4 echo "Running autoheader..." autoheader echo "Running libtoolize..." libtoolize --automake echo "Running automake..." -automake-1.9 -a -c +automake -a -c echo "Running autoconf..." autoconf echo "The remaining steps to install this package are:" diff --git a/src/m17n-im-config.h b/src/m17n-im-config.h index f3dc539..8e04981 100644 --- a/src/m17n-im-config.h +++ b/src/m17n-im-config.h @@ -24,28 +24,15 @@ #ifndef _M17N_IM_CONFIG_H_ #define _M17N_IM_CONFIG_H_ -#ifdef __cplusplus -extern "C" -{ -#endif +#include +G_BEGIN_DECLS -extern int mim_config_init (void); -extern int mim_config_fini (void); - -typedef struct _MimConfigCallback -{ - void (*func) (gboolean modified, gpointer arg); - gpointer arg; -} MimConfigCallback; - -extern GtkWidget *mim_config_widget (MimConfigCallback *callback); +extern GtkWidget *mim_config_new (GCallback func, gpointer data); extern gboolean mim_config_modified (GtkWidget *config); extern gboolean mim_config_revert (GtkWidget *config); extern gboolean mim_config_save (GtkWidget *config); -#ifdef __cplusplus -} -#endif +G_END_DECLS #endif /* _M17N_IM_CONFIG_H_ */ diff --git a/src/main.c b/src/main.c index c4df32f..047c259 100644 --- a/src/main.c +++ b/src/main.c @@ -28,11 +28,11 @@ #include #include -/* Argument to callback functions. */ +/* Common argument to all callback functions. */ -struct ConfigSaveRevert +struct CallbackArgument { - /* IM configuration widget created by mim_config_widget (). */ + /* IM configuration widget created by mim_config_new (). */ GtkWidget *config; /* Button widget "revert" */ GtkWidget *revert; @@ -41,55 +41,58 @@ struct ConfigSaveRevert }; -/* Called when the status of configuration (modified or not) is - changed. */ +/* Called when the status of configuration is changed. */ void -status_changed_cb (gboolean modified, gpointer data) +status_changed_cb (GtkWidget *config, gpointer data) { - struct ConfigSaveRevert *config_save_revert = data; + struct CallbackArgument *arg = data; + gboolean modified = mim_config_modified (arg->config); - if (GTK_WIDGET_SENSITIVE (config_save_revert->save)) + if (GTK_WIDGET_SENSITIVE (arg->save)) { if (! modified) { - gtk_widget_set_sensitive (config_save_revert->revert, FALSE); - gtk_widget_set_sensitive (config_save_revert->save, FALSE); + gtk_widget_set_sensitive (arg->revert, FALSE); + gtk_widget_set_sensitive (arg->save, FALSE); } } else { if (modified) { - gtk_widget_set_sensitive (config_save_revert->revert, TRUE); - gtk_widget_set_sensitive (config_save_revert->save, TRUE); + gtk_widget_set_sensitive (arg->revert, TRUE); + gtk_widget_set_sensitive (arg->save, TRUE); } } } +/* Called when "revert" button is clicked. */ static void revert_clicked_cb (GtkButton *button, gpointer data) { - struct ConfigSaveRevert *config_save_revert = data; + struct CallbackArgument *arg = data; - mim_config_revert (config_save_revert->config); + mim_config_revert (arg->config); status_changed_cb (FALSE, data); } +/* Called when "save" button is clicked. */ static void save_clicked_cb (GtkButton *button, gpointer data) { - struct ConfigSaveRevert *config_save_revert = data; + struct CallbackArgument *arg = data; - mim_config_save (config_save_revert->config); + mim_config_save (arg->config); status_changed_cb (FALSE, data); } +/* Called when "quit" button is clicked. */ static void quit_clicked_cb (GtkButton *button, gpointer data) { - struct ConfigSaveRevert *config_save_revert = data; + struct CallbackArgument *arg = data; - if (mim_config_modified (config_save_revert->config)) + if (mim_config_modified (arg->config)) { GtkWidget *dialog, *label; gint response; @@ -110,40 +113,36 @@ quit_clicked_cb (GtkButton *button, gpointer data) if (response == GTK_RESPONSE_CANCEL) return; if (response == GTK_RESPONSE_YES) - mim_config_save (config_save_revert->config); + mim_config_save (arg->config); } + gtk_widget_destroy (arg->config); gtk_main_quit (); } - +/* Called when "ok" button is clicked. */ static void ok_clicked_cb (GtkButton *button, gpointer data) { - struct ConfigSaveRevert *config_save_revert = data; + struct CallbackArgument *arg = data; - if (mim_config_modified (config_save_revert->config)) - mim_config_save (config_save_revert->config); + if (mim_config_modified (arg->config)) + mim_config_save (arg->config); + gtk_widget_destroy (arg->config); gtk_main_quit (); } int main (int argc, char **argv) { - GtkWidget *window, *vbox, *config, *hbox; + GtkWidget *window, *vbox, *hbox; GtkWidget *revert, *save, *ok, *quit; - struct ConfigSaveRevert config_save_revert; - MimConfigCallback callback; + struct CallbackArgument arg; #if ENABLE_NLS bindtextdomain ("m17n-im-config", GETTEXTDIR); bind_textdomain_codeset ("m17n-im-config", "UTF-8"); #endif gtk_init (&argc, &argv); - if (mim_config_init () < 0) - { - g_print ("m17n-im-config initialization error\n"); - exit (1); - } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request (window, 500, 300); @@ -178,22 +177,19 @@ main (int argc, char **argv) quit = gtk_button_new_from_stock (GTK_STOCK_QUIT); ok = gtk_button_new_from_stock (GTK_STOCK_OK); - config_save_revert.revert = revert; - config_save_revert.save = save; - callback.func = status_changed_cb; - callback.arg = &config_save_revert; - config = mim_config_widget (&callback); - config_save_revert.config = config; - gtk_box_pack_start (GTK_BOX (vbox), config, TRUE, TRUE, 0); + arg.revert = revert; + arg.save = save; + arg.config = mim_config_new (G_CALLBACK (status_changed_cb), &arg); + gtk_box_pack_start (GTK_BOX (vbox), arg.config, TRUE, TRUE, 0); g_signal_connect (G_OBJECT (revert), "clicked", - G_CALLBACK (revert_clicked_cb), &config_save_revert); + G_CALLBACK (revert_clicked_cb), &arg); g_signal_connect (G_OBJECT (save), "clicked", - G_CALLBACK (save_clicked_cb), &config_save_revert); + G_CALLBACK (save_clicked_cb), &arg); g_signal_connect (G_OBJECT (quit), "clicked", - G_CALLBACK (quit_clicked_cb), &config_save_revert); + G_CALLBACK (quit_clicked_cb), &arg); g_signal_connect (G_OBJECT (ok), "clicked", - G_CALLBACK (ok_clicked_cb), &config_save_revert); + G_CALLBACK (ok_clicked_cb), &arg); hbox = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END); @@ -206,7 +202,6 @@ main (int argc, char **argv) gtk_widget_show_all (window); gtk_main (); - mim_config_fini (); return 0; } diff --git a/src/mim-config.c b/src/mim-config.c index 3d41031..6923125 100644 --- a/src/mim-config.c +++ b/src/mim-config.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "m17n-im-config.h" @@ -35,6 +36,15 @@ #define CONFIG_STATUS_DATA " config-status-data" #define CONFIG_TREE_VIEW " config-tree-view" +typedef void (*MimConfigCallbackFunc) (GtkWidget *widget, gpointer data); + +typedef struct _MimConfigCallback +{ + GtkWidget *widget; + MimConfigCallbackFunc func; + gpointer data; +} MimConfigCallback; + typedef struct _MimConfigStatus { /* Number of available input methods. */ @@ -246,8 +256,7 @@ update_child_row (GtkTreeModel *model, GtkTreeIter *iter, callback = g_object_get_data (G_OBJECT (tree), CONFIG_CALLBACK_DATA); if (callback) - callback->func (config_status->num_modified == 0 ? FALSE : TRUE, - callback->arg); + callback->func (callback->widget, callback->data); } } @@ -460,13 +469,30 @@ set_as_saved (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, return FALSE; } +static int initialized = 0; + +static void +destroy_cb (GtkWidget *widget, gpointer data) +{ + M17N_FINI (); +} + /* Public API */ -int -mim_config_init () +GtkWidget * +mim_config_new (GCallback func, gpointer data) { + GtkWidget *tree, *config; + GtkTreeStore *store; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + if (initialized) + return NULL; M17N_INIT (); + if (merror_code < 0) + return NULL; #if ENABLE_NLS bindtextdomain ("m17n-im-config", GETTEXTDIR); @@ -478,30 +504,9 @@ mim_config_init () mim_status_str[MIM_STATUS_MODIFIED] = _("modified"); mim_status_str[MIM_STATUS_NO] = _("uncustomizable"); - return 0; -} - -int -mim_config_fini () -{ - M17N_FINI (); - - return 0; -} - -GtkWidget * -mim_config_widget (MimConfigCallback *callback) -{ - GtkWidget *tree, *config; - GtkTreeStore *store; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - store = make_store_for_input_methods (); tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); g_object_unref (G_OBJECT (store)); - if (callback) - g_object_set_data (G_OBJECT (tree), CONFIG_CALLBACK_DATA, callback); renderer = gtk_cell_renderer_text_new (); column = (gtk_tree_view_column_new_with_attributes @@ -522,8 +527,21 @@ mim_config_widget (MimConfigCallback *callback) gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (config), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (config), tree); + g_signal_connect (G_OBJECT (config), "destroy", + G_CALLBACK (destroy_cb), NULL); g_object_set_data (G_OBJECT (config), CONFIG_TREE_VIEW, tree); + if (func) + { + MimConfigCallback *callback; + + callback = g_new (MimConfigCallback, 1); + callback->widget = config; + callback->func = (MimConfigCallbackFunc) func; + callback->data = data; + g_object_set_data_full (G_OBJECT (tree), CONFIG_CALLBACK_DATA, + callback, g_free); + } return config; } -- 1.7.10.4