From 155ef5f0b7a71564f3f4cb049afc05fbc38715f4 Mon Sep 17 00:00:00 2001 From: ntakahas Date: Tue, 24 Apr 2007 12:55:07 +0000 Subject: [PATCH] *** empty log message *** --- src/command.c | 71 ++++++++++++++----- src/mim-config.c | 12 ++-- src/variable.c | 209 ++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 199 insertions(+), 93 deletions(-) diff --git a/src/command.c b/src/command.c index c53a5eb..535722c 100644 --- a/src/command.c +++ b/src/command.c @@ -39,7 +39,10 @@ struct BindingWidgets GtkWidget *clear; GtkWidget *add; GtkWidget *view; + GtkWidget *default_; + GtkWidget *revert; GtkWidget *delete; + GtkWidget *status; }; enum KeyMaskBit { @@ -106,7 +109,7 @@ update_binding_store (GtkWidget *view) } } -gboolean +static gboolean key_pressed_cb (GtkEntry *entry, GdkEventKey *event, gpointer data) { guint c; @@ -169,7 +172,7 @@ key_pressed_cb (GtkEntry *entry, GdkEventKey *event, gpointer data) return TRUE; } -gboolean +static gboolean key_released_cb (GtkEntry *entry, GdkEventKey *event, gpointer data) { guint c; @@ -193,6 +196,31 @@ key_released_cb (GtkEntry *entry, GdkEventKey *event, gpointer data) } static void +update_widgets (struct BindingWidgets *bw) +{ + MSymbol status = CURRENT_STATUS; + + if (status == Mconfigured) + { + gtk_widget_set_sensitive (bw->default_, TRUE); + gtk_widget_set_sensitive (bw->revert, TRUE); + gtk_label_set_text (GTK_LABEL (bw->status), _("Status : modified")); + } + else if (status == Mcustomized) + { + gtk_widget_set_sensitive (bw->default_, TRUE); + gtk_widget_set_sensitive (bw->revert, FALSE); + gtk_label_set_text (GTK_LABEL (bw->status), _("Status : customized")); + } + else + { + gtk_widget_set_sensitive (bw->default_, FALSE); + gtk_widget_set_sensitive (bw->revert, FALSE); + gtk_label_set_text (GTK_LABEL (bw->status), _("Status : default")); + } +} + +static void clear_cb (GtkButton *button, gpointer data) { struct BindingWidgets *bw = data; @@ -243,8 +271,7 @@ add_cb (GtkButton *button, gpointer data) gtk_list_store_set (store, &iter, 0, mplist_value (last), -1); update_binding_store (bw->view); clear_cb (NULL, bw); - gtk_widget_set_sensitive (bw->clear, FALSE); - gtk_widget_set_sensitive (bw->add, FALSE); + update_widgets (bw); } static GtkWidget * @@ -346,6 +373,7 @@ default_cb (GtkButton *button, gpointer data) CONFIG_COMMAND (empty); m17n_object_unref (empty); update_binding_store (bw->view); + update_widgets (bw); } static void * @@ -355,6 +383,7 @@ revert_cb (GtkButton *button, gpointer data) CONFIG_COMMAND (NULL); update_binding_store (bw->view); + update_widgets (bw); } static void @@ -380,14 +409,14 @@ delete_cb (GtkButton *button, gpointer data) m17n_object_unref (new); gtk_list_store_remove (GTK_LIST_STORE (model), &iter); update_binding_store (bw->view); - gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE); + update_widgets (bw); } static GtkWidget * create_deleting_section (struct BindingWidgets *bw) { GtkListStore *store; - GtkWidget *scrolled, *default_, *revert, *delete, *hbox, *vbox; + GtkWidget *scrolled, *hbox, *vbox; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkTreeIter iter; @@ -418,12 +447,12 @@ create_deleting_section (struct BindingWidgets *bw) gtk_tree_view_column_set_cell_data_func (column, renderer, keyseq_render_function, NULL, NULL); - default_ = gtk_button_new_from_stock (_("_Default")); - g_signal_connect (G_OBJECT (default_), "clicked", + bw->default_ = gtk_button_new_from_stock (_("_Default")); + g_signal_connect (G_OBJECT (bw->default_), "clicked", G_CALLBACK (default_cb), bw); - revert = gtk_button_new_from_stock (GTK_STOCK_REVERT_TO_SAVED); - g_signal_connect (G_OBJECT (revert), "clicked", + bw->revert = gtk_button_new_from_stock (GTK_STOCK_REVERT_TO_SAVED); + g_signal_connect (G_OBJECT (bw->revert), "clicked", G_CALLBACK (revert_cb), bw); bw->delete = gtk_button_new_from_stock (GTK_STOCK_DELETE); @@ -439,8 +468,8 @@ create_deleting_section (struct BindingWidgets *bw) hbox = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END); gtk_box_set_spacing (GTK_BOX (hbox), 6); - gtk_container_add (GTK_CONTAINER (hbox), default_); - gtk_container_add (GTK_CONTAINER (hbox), revert); + gtk_container_add (GTK_CONTAINER (hbox), bw->default_); + gtk_container_add (GTK_CONTAINER (hbox), bw->revert); gtk_container_add (GTK_CONTAINER (hbox), bw->delete); gtk_container_add (GTK_CONTAINER (vbox), hbox); @@ -454,12 +483,12 @@ set_status (GtkListStore *store, GtkTreeIter *iter) gchar *status_str; status = CURRENT_STATUS; - if (status == Mnil || status == Minherited) - status_str = _("default"); + if (status == Mconfigured) + status_str = _("modified"); else if (status == Mcustomized) status_str = _("customized"); else - status_str = _("modified"); + status_str = _("default"); gtk_list_store_set (store, iter, 1, status_str, -1); } @@ -469,7 +498,7 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, { GtkTreeModel *model; GtkTreeIter iter; - GtkWidget *dialog; + GtkWidget *dialog, *vbox; struct BindingWidgets bw; gchar *command; @@ -485,11 +514,19 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL)); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), create_adding_section (&bw)); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), create_deleting_section (&bw)); + bw.status = gtk_label_new (NULL); + vbox = gtk_vbox_new (FALSE, 12); + gtk_container_add (GTK_CONTAINER (vbox), bw.status); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox); + + update_widgets (&bw); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_tree_model_get_iter (model, &iter, path); @@ -499,7 +536,7 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, } GtkWidget * -create_command_entries (GtkTooltips *tip, MSymbol lang, MSymbol name) +create_command_list (GtkTooltips *tip, MSymbol lang, MSymbol name) { GtkListStore *store; GtkWidget *view; diff --git a/src/mim-config.c b/src/mim-config.c index 001b37a..775194c 100644 --- a/src/mim-config.c +++ b/src/mim-config.c @@ -162,10 +162,10 @@ tree_expanded_cb (GtkTreeView *tree, GtkTreeIter *parent, } } -extern GtkWidget *create_variable_entries (GtkTooltips *tip, MSymbol lang, - MSymbol name); -extern GtkWidget *create_command_entries (GtkTooltips *tip, MSymbol lang, - MSymbol name); +extern GtkWidget *create_variable_list (GtkTooltips *tip, MSymbol lang, + MSymbol name); +extern GtkWidget *create_command_list (GtkTooltips *tip, MSymbol lang, + MSymbol name); static void edit_im (GtkTreeView *tree, MSymbol lang, MSymbol name) @@ -196,7 +196,7 @@ edit_im (GtkTreeView *tree, MSymbol lang, MSymbol name) gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), vbox); gtk_box_pack_start (GTK_BOX (vbox), - create_variable_entries (tip, lang, name), + create_variable_list (tip, lang, name), FALSE, FALSE, 0); /* Commands' pages */ @@ -209,7 +209,7 @@ edit_im (GtkTreeView *tree, MSymbol lang, MSymbol name) gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled), vbox); gtk_box_pack_start (GTK_BOX (vbox), - create_command_entries (tip, lang, name), + create_command_list (tip, lang, name), FALSE, FALSE, 0); gtk_widget_show_all (dialog); diff --git a/src/variable.c b/src/variable.c index 49ff0ec..ad189a5 100644 --- a/src/variable.c +++ b/src/variable.c @@ -16,11 +16,12 @@ (current_lang, current_name, current_variable)))))) #define CURRENT_STATUS \ - (mplist_next \ + (mplist_value \ (mplist_next \ - (mplist_value \ - (minput_get_variable \ - (current_lang, current_name, current_variable))))) + (mplist_next \ + (mplist_value \ + (minput_get_variable \ + (current_lang, current_name, current_variable)))))) #define CONFIG_VARIABLE(plist) \ minput_config_variable (current_lang, current_name, current_variable, \ @@ -43,11 +44,91 @@ struct ControllerInfo /* type of widget */ enum WidgetType wtype; + + /* default button */ + GtkWidget *default_; + + /* revert button */ + GtkWidget *revert; + + /* apply button */ + GtkWidget *apply; + + /* status label */ + GtkWidget *status; }; static MSymbol current_lang, current_name, current_variable; static void +update_controller (struct ControllerInfo *ci) +{ + MPlist *plist; + MSymbol key, status; + void *value; + + status = CURRENT_STATUS; + if (status == Mconfigured) + { + gtk_widget_set_sensitive (ci->default_, TRUE); + gtk_widget_set_sensitive (ci->revert, TRUE); + gtk_widget_set_sensitive (ci->apply, FALSE); + gtk_label_set_text (GTK_LABEL (ci->status), _("Status : modified")); + } + else if (status == Mcustomized) + { + gtk_widget_set_sensitive (ci->default_, TRUE); + gtk_widget_set_sensitive (ci->revert, FALSE); + gtk_widget_set_sensitive (ci->apply, FALSE); + gtk_label_set_text (GTK_LABEL (ci->status), _("Status : customized")); + } + else + { + gtk_widget_set_sensitive (ci->default_, FALSE); + gtk_widget_set_sensitive (ci->revert, FALSE); + gtk_widget_set_sensitive (ci->apply, FALSE); + gtk_label_set_text (GTK_LABEL (ci->status), _("Status : default")); + } + + plist = CURRENT_VALUE; + /* plist == (value [valid-value ...]) */ + key = mplist_key (plist); + value = mplist_value (plist); + + if (ci->wtype == ENTRY_WIDGET) + { + if (key == Msymbol) + gtk_entry_set_text (GTK_ENTRY (ci->widget), + msymbol_name ((MSymbol) value)); + else if (key == Mtext) + /* Fixme : Assuming the return value is in UTF-8 */ + gtk_entry_set_text (GTK_ENTRY (ci->widget), + mtext_data ((MText *) value, + NULL, NULL, NULL, NULL)); + else + { + gchar buf[32]; + g_snprintf (buf, sizeof (buf), "%d", (gint) value); + gtk_entry_set_text (GTK_ENTRY (ci->widget), buf); + } + } + else if (ci->wtype == COMBO_BOX_WIDGET) + { + gint i; + + for (i = 0, plist = mplist_next (plist); + plist && mplist_key (plist) == key; + i++, plist = mplist_next (plist)) + if (mplist_value (plist) == value) + break; + gtk_combo_box_set_active (GTK_COMBO_BOX (ci->widget), i); + } + else + gtk_spin_button_set_value (GTK_SPIN_BUTTON (ci->widget), + (gdouble) (int) value); +} + +static void entry_cb (GtkEntry *entry, gpointer data) { const gchar *text = gtk_entry_get_text (entry); @@ -99,6 +180,7 @@ entry_cb (GtkEntry *entry, gpointer data) gtk_editable_set_position (GTK_EDITABLE (entry), -1); } m17n_object_unref (plist); + update_controller (ci); } static void @@ -132,6 +214,7 @@ combo_cb (GtkComboBox *combo, gpointer data) CONFIG_VARIABLE (plist); } m17n_object_unref (plist); + update_controller (ci); } static void @@ -144,6 +227,7 @@ spin_cb (GtkSpinButton *spin, gpointer data) (void *) gtk_spin_button_get_value_as_int (spin)); CONFIG_VARIABLE (plist); m17n_object_unref (plist); + update_controller (ci); } enum @@ -161,17 +245,15 @@ set_value_status (GtkListStore *store, GtkTreeIter *iter) MSymbol status; gchar *value_str, *status_str, buf[32]; - plist = CURRENT_STATUS; - /* plist == (status value [valid-value ...]) */ - status = mplist_value (plist); - if (status == Mnil || status == Minherited) - status_str = _("default"); + status = CURRENT_STATUS; + if (status == Mconfigured) + status_str = _("modified"); else if (status == Mcustomized) status_str = _("customized"); else - status_str = _("modified"); + status_str = _("default"); - plist = mplist_next (plist); + plist = CURRENT_VALUE; /* plist == (value [valid-value ...]) */ if (mplist_key (plist) == Msymbol) value_str = msymbol_name ((MSymbol) mplist_value (plist)); @@ -191,6 +273,17 @@ set_value_status (GtkListStore *store, GtkTreeIter *iter) -1); } +static gboolean +key_pressed_cb (GtkEntry *entry, GdkEventKey *event, gpointer data) +{ + struct ControllerInfo *ci = data; + + gtk_widget_set_sensitive (ci->default_, TRUE); + gtk_widget_set_sensitive (ci->revert, TRUE); + gtk_widget_set_sensitive (ci->apply, TRUE); + return FALSE; +} + static GtkWidget * create_widget (struct ControllerInfo *ci) { @@ -233,6 +326,8 @@ create_widget (struct ControllerInfo *ci) gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE); g_signal_connect (G_OBJECT (ci->widget), "activate", G_CALLBACK (entry_cb), ci); + g_signal_connect (G_OBJECT (ci->widget), "key-press-event", + G_CALLBACK (key_pressed_cb), ci); } } else if (ci->vtype == Mtext) @@ -270,6 +365,8 @@ create_widget (struct ControllerInfo *ci) gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE); g_signal_connect (G_OBJECT (ci->widget), "activate", G_CALLBACK (entry_cb), ci); + g_signal_connect (G_OBJECT (ci->widget), "key-press-event", + G_CALLBACK (key_pressed_cb), ci); } } else if (ci->vtype == Minteger) @@ -311,8 +408,12 @@ create_widget (struct ControllerInfo *ci) gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (ci->widget), TRUE); gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (ci->widget), GTK_UPDATE_IF_VALID); + g_signal_connect (G_OBJECT (ci->widget), "activate", + G_CALLBACK (entry_cb), ci); g_signal_connect (G_OBJECT (ci->widget), "value_changed", G_CALLBACK (spin_cb), ci); + g_signal_connect (G_OBJECT (ci->widget), "key-press-event", + G_CALLBACK (key_pressed_cb), ci); } else { @@ -325,9 +426,11 @@ create_widget (struct ControllerInfo *ci) gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE); g_signal_connect (G_OBJECT (ci->widget), "activate", G_CALLBACK (entry_cb), ci); + g_signal_connect (G_OBJECT (ci->widget), "key-press-event", + G_CALLBACK (key_pressed_cb), ci); } } - else + else /* should never come here */ { ci->widget = gtk_entry_new (); ci->wtype = ENTRY_WIDGET; @@ -335,70 +438,30 @@ create_widget (struct ControllerInfo *ci) gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE); g_signal_connect (G_OBJECT (ci->widget), "activate", G_CALLBACK (entry_cb), ci); + g_signal_connect (G_OBJECT (ci->widget), "key-press-event", + G_CALLBACK (key_pressed_cb), ci); } return ci->widget; } -static void -update_controller (struct ControllerInfo *ci) -{ - MPlist *plist; - MSymbol key; - void *value; - - plist = CURRENT_VALUE; - /* plist == (value [valid-value ...]) */ - key = mplist_key (plist); - value = mplist_value (plist); - - if (ci->wtype == ENTRY_WIDGET) - { - if (key == Msymbol) - gtk_entry_set_text (GTK_ENTRY (ci->widget), - msymbol_name ((MSymbol) value)); - else if (key == Mtext) - /* Fixme : Assuming the return value is in UTF-8 */ - gtk_entry_set_text (GTK_ENTRY (ci->widget), - mtext_data ((MText *) value, - NULL, NULL, NULL, NULL)); - else - { - gchar buf[32]; - g_snprintf (buf, sizeof (buf), "%d", (gint) value); - gtk_entry_set_text (GTK_ENTRY (ci->widget), buf); - } - } - else if (ci->wtype == COMBO_BOX_WIDGET) - { - gint i; - - for (i = 0, plist = mplist_next (plist); - plist && mplist_key (plist) == key; - i++, plist = mplist_next (plist)) - if (mplist_value (plist) == value) - break; - gtk_combo_box_set_active (GTK_COMBO_BOX (ci->widget), i); - } - else - gtk_spin_button_set_value (GTK_SPIN_BUTTON (ci->widget), - (gdouble) (int) value); -} - static void * default_cb (GtkButton *button, gpointer data) { MPlist *empty = mplist (); + struct ControllerInfo *ci = data; CONFIG_VARIABLE (empty); m17n_object_unref (empty); - update_controller ((struct ControllerInfo *) data); + update_controller (ci); } static void * revert_cb (GtkButton *button, gpointer data) { + struct ControllerInfo *ci = data; + CONFIG_VARIABLE (NULL); - update_controller ((struct ControllerInfo *) data); + update_controller (ci); } static void * @@ -408,6 +471,7 @@ apply_cb (GtkButton *button, gpointer data) if (ci->wtype == ENTRY_WIDGET) entry_cb (GTK_ENTRY (ci->widget), ci); + update_controller (ci); } static void @@ -416,7 +480,7 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, { GtkTreeModel *model; GtkTreeIter iter; - GtkWidget *dialog, *default_, *revert, *apply, *hbox, *vbox; + GtkWidget *dialog, *hbox, *vbox; struct ControllerInfo ci; gchar *variable; @@ -433,18 +497,20 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL)); - default_ = gtk_button_new_from_stock (_("_Default")); - g_signal_connect (G_OBJECT (default_), "clicked", + ci.default_ = gtk_button_new_from_stock (_("_Default")); + g_signal_connect (G_OBJECT (ci.default_), "clicked", G_CALLBACK (default_cb), &ci); - revert = gtk_button_new_from_stock (GTK_STOCK_REVERT_TO_SAVED); - g_signal_connect (G_OBJECT (revert), "clicked", + ci.revert = gtk_button_new_from_stock (GTK_STOCK_REVERT_TO_SAVED); + g_signal_connect (G_OBJECT (ci.revert), "clicked", G_CALLBACK (revert_cb), &ci); - apply = gtk_button_new_from_stock (GTK_STOCK_APPLY); - g_signal_connect (G_OBJECT (apply), "clicked", + ci.apply = gtk_button_new_from_stock (GTK_STOCK_APPLY); + g_signal_connect (G_OBJECT (ci.apply), "clicked", G_CALLBACK (apply_cb), &ci); + ci.status = gtk_label_new (NULL); + vbox = gtk_vbox_new (FALSE, 6); gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox); @@ -454,11 +520,14 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, hbox = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END); gtk_box_set_spacing (GTK_BOX (hbox), 6); - gtk_container_add (GTK_CONTAINER (hbox), default_); - gtk_container_add (GTK_CONTAINER (hbox), revert); - gtk_container_add (GTK_CONTAINER (hbox), apply); + gtk_container_add (GTK_CONTAINER (hbox), ci.default_); + gtk_container_add (GTK_CONTAINER (hbox), ci.revert); + gtk_container_add (GTK_CONTAINER (hbox), ci.apply); gtk_container_add (GTK_CONTAINER (vbox), hbox); + + gtk_container_add (GTK_CONTAINER (vbox), ci.status); + update_controller (&ci); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_tree_model_get_iter (model, &iter, path); @@ -467,7 +536,7 @@ activated_cb (GtkTreeView *parent, GtkTreePath *path, } GtkWidget * -create_variable_entries (GtkTooltips *tip, MSymbol lang, MSymbol name) +create_variable_list (GtkTooltips *tip, MSymbol lang, MSymbol name) { GtkListStore *store; GtkWidget *view; -- 1.7.10.4