+++ /dev/null
-#include <stdlib.h>
-#include <string.h>
-#include <libintl.h>
-#include <m17n.h>
-#include <gtk/gtk.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkkeysyms.h>
-#include <config.h>
-
-#define _(String) dgettext (PACKAGE, String)
-
-#define CURRENT_BINDINGS \
- (mplist_next \
- (mplist_next \
- (mplist_next \
- (mplist_value \
- (minput_get_command \
- (current_lang, current_name, current_command))))))
-
-#define CURRENT_STATUS \
- (mplist_value \
- (mplist_next \
- (mplist_next \
- (mplist_value \
- (minput_get_command \
- (current_lang, current_name, current_command))))))
-
-#define CURRENT_DESCRIPTION \
- (mtext_data \
- (mplist_value \
- (mplist_next \
- (mplist_value \
- (minput_get_command \
- (current_lang, current_name, current_command)))), \
- NULL, NULL, NULL, NULL))
-
-#define CONFIG_COMMAND(plist) \
- minput_config_command (current_lang, current_name, current_command, \
- (plist))
-
-static void
-mtext__cat_str (MText *mt, char *str)
-{
- while (*str)
- {
- mtext_cat_char (mt, (int) *str);
- str++;
- }
-}
-
-static unsigned modifier_state = 0;
-static MPlist *entry_keyseq;
-static MSymbol current_lang, current_name, current_command;
-
-struct BindingWidgets
-{
- GtkWidget *view;
- GtkWidget *default_;
- GtkWidget *revert;
- GtkWidget *delete;
- GtkWidget *entry;
- GtkWidget *clear;
- GtkWidget *add;
- GtkWidget *status;
-};
-
-enum KeyMaskBit {
- META_MASK_BIT = 1,
- ALT_MASK_BIT = META_MASK_BIT << 1,
- SUPER_MASK_BIT = ALT_MASK_BIT << 1,
- HYPER_MASK_BIT = SUPER_MASK_BIT << 1
-};
-
-static int
-keyseq_equal (MPlist *pl1, MPlist *pl2)
-{
- if (mplist_length (pl1) != mplist_length (pl2))
- return 0;
- while (pl1 && mplist_key (pl1) == Msymbol)
- {
- if (mplist_value (pl1) != mplist_value (pl2))
- return 0;
- pl1 = mplist_next (pl1);
- pl2 = mplist_next (pl2);
- }
- return 1;
-}
-
-static void
-update_entry (GtkEntry *entry)
-{
- if (mplist_key (entry_keyseq) == Mnil)
- gtk_entry_set_text (entry, "");
- else
- {
- MPlist *p;
- gchar *name;
-
- name = msymbol_name ((MSymbol) mplist_value (entry_keyseq));
- gtk_entry_set_text (entry, name);
- for (p = mplist_next (entry_keyseq); mplist_key (p) != Mnil;
- p = mplist_next (p))
- {
- name = msymbol_name ((MSymbol) mplist_value (p));
- gtk_entry_append_text (entry, " ");
- gtk_entry_append_text (entry, name);
- }
- gtk_editable_set_position (GTK_EDITABLE (entry), -1);
- }
-}
-
-static void
-update_binding_store (GtkWidget *view)
-{
- GtkListStore *store;
- GtkTreeIter iter;
- MPlist *pl;
-
- store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
- gtk_list_store_clear (store);
-
- for (pl = CURRENT_BINDINGS;
- pl && mplist_key (pl) == Mplist;
- pl = mplist_next (pl))
- {
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, mplist_value (pl), -1);
- }
-}
-
-static gboolean
-key_pressed_cb (GtkEntry *entry, GdkEventKey *event, gpointer data)
-{
- guint c;
- MText *mt;
- char buf[32];
- char *name;
- int nbytes, i;
- struct BindingWidgets *bw = data;
-
- c = gdk_keyval_to_unicode (event->keyval);
- if (c == 0)
- {
- switch (event->keyval)
- {
- case GDK_Meta_L: case GDK_Meta_R:
- modifier_state |= META_MASK_BIT; return TRUE;
- case GDK_Alt_L: case GDK_Alt_R:
- modifier_state |= ALT_MASK_BIT; return TRUE;
- case GDK_Super_L: case GDK_Super_R:
- modifier_state |= SUPER_MASK_BIT; return TRUE;
- case GDK_Hyper_L: case GDK_Hyper_R:
- modifier_state |= HYPER_MASK_BIT; return TRUE;
- default:
- if (event->keyval >= GDK_Shift_L && event->keyval <= GDK_Shift_Lock)
- return TRUE;
- }
- name = gdk_keyval_name (event->keyval);
- if (! name)
- return TRUE;
- nbytes = strlen (name);
- }
- else
- {
- name = alloca (8);
- mt = mtext ();
- mtext_cat_char (mt, c);
- nbytes = mconv_encode_buffer (msymbol ("utf-8"), mt,
- (unsigned char *) name, 32);
- m17n_object_unref (mt);
- }
- i = 0;
- if (c == 0 && event->state & GDK_SHIFT_MASK)
- buf[i++] = 'S', buf[i++] = '-';
- if (event->state & GDK_CONTROL_MASK)
- buf[i++] = 'C', buf[i++] = '-';
- if (modifier_state & META_MASK_BIT)
- buf[i++] = 'M', buf[i++] = '-';
- if (modifier_state & ALT_MASK_BIT)
- buf[i++] = 'A', buf[i++] = '-';
- if (modifier_state & SUPER_MASK_BIT)
- buf[i++] = 's', buf[i++] = '-';
- if (modifier_state & HYPER_MASK_BIT)
- buf[i++] = 'H', buf[i++] = '-';
- strncpy (buf + i, name, nbytes);
- buf[i + nbytes] = 0;
- mplist_add (entry_keyseq, Msymbol, msymbol (buf));
- update_entry (entry);
- gtk_widget_set_sensitive (bw->clear, TRUE);
- gtk_widget_set_sensitive (bw->add, TRUE);
- return TRUE;
-}
-
-static gboolean
-key_released_cb (GtkEntry *entry, GdkEventKey *event, gpointer data)
-{
- guint c;
-
- c = gdk_keyval_to_unicode (event->keyval);
- if (c == 0)
- {
- switch (event->keyval)
- {
- case GDK_Meta_L: case GDK_Meta_R:
- modifier_state &= ~META_MASK_BIT; break;
- case GDK_Alt_L: case GDK_Alt_R:
- modifier_state &= ~ALT_MASK_BIT; break;
- case GDK_Super_L: case GDK_Super_R:
- modifier_state &= ~SUPER_MASK_BIT; break;
- case GDK_Hyper_L: case GDK_Hyper_R:
- modifier_state &= ~HYPER_MASK_BIT; break;
- }
- }
- return FALSE;
-}
-
-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);
- }
- else if (status == Mcustomized)
- {
- gtk_widget_set_sensitive (bw->default_, TRUE);
- gtk_widget_set_sensitive (bw->revert, FALSE);
- }
- else
- {
- gtk_widget_set_sensitive (bw->default_, FALSE);
- gtk_widget_set_sensitive (bw->revert, FALSE);
- }
-}
-
-static void
-clear_cb (GtkButton *button, gpointer data)
-{
- struct BindingWidgets *bw = data;
-
- mplist_set (entry_keyseq, Mnil, NULL);
- gtk_widget_grab_focus (bw->entry);
- update_entry (GTK_ENTRY (bw->entry));
- gtk_widget_set_sensitive (bw->clear, FALSE);
- gtk_widget_set_sensitive (bw->add, FALSE);
-}
-
-static void
-add_cb (GtkButton *button, gpointer data)
-{
- MPlist *new, *pl, *last;
- GtkListStore *store;
- GtkTreeIter iter;
- struct BindingWidgets *bw = data;
-
- if (mplist_length (entry_keyseq) == 0)
- return;
- new = mplist ();
- for (pl = CURRENT_BINDINGS;
- pl && mplist_key (pl) == Mplist;
- pl = mplist_next (pl))
- {
- if (! keyseq_equal (mplist_value (pl), entry_keyseq))
- mplist_add (new, Mplist, mplist_value (pl));
- else
- {
- /* entry_keyseq is already registered. */
- m17n_object_unref (new);
- return;
- }
- }
- mplist_add (new, Mplist, entry_keyseq);
- CONFIG_COMMAND (new);
- m17n_object_unref (new);
-
- /* We cannot use ENTRY_KEYSEQ for gtk_list_store_set (). We must
- use a pointer to the internally copied one. */
- new = CURRENT_BINDINGS;
- for (pl = new;
- pl && mplist_key (pl) == Mplist;
- last = pl, pl = mplist_next (pl));
- store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (bw->view)));
- gtk_list_store_append (store, &iter);
- 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->default_, TRUE);
- gtk_widget_set_sensitive (bw->revert, TRUE);
- gtk_label_set_text (GTK_LABEL (bw->status), _("modified"));
-}
-
-static GtkWidget *
-create_adding_section (struct BindingWidgets *bw)
-{
- GtkWidget *label, *hbox, *vbox;
-
- label = gtk_label_new (_("New key binding:"));
-
- entry_keyseq = mplist ();
- bw->entry = gtk_entry_new ();
- g_signal_connect (G_OBJECT (bw->entry), "key-press-event",
- G_CALLBACK (key_pressed_cb), bw);
- g_signal_connect (G_OBJECT (bw->entry), "key-release-event",
- G_CALLBACK (key_released_cb), bw);
-
- bw->clear = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
- gtk_widget_set_sensitive (bw->clear, FALSE);
- g_signal_connect (G_OBJECT (bw->clear), "clicked",
- G_CALLBACK (clear_cb), bw);
-
- bw->add = gtk_button_new_from_stock (GTK_STOCK_ADD);
- gtk_widget_set_sensitive (bw->add, FALSE);
- g_signal_connect (G_OBJECT (bw->add), "clicked",
- G_CALLBACK (add_cb), bw);
-
- vbox = gtk_vbox_new (FALSE, 12);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- gtk_container_add (GTK_CONTAINER (vbox), bw->entry);
-
- 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), bw->clear);
- gtk_container_add (GTK_CONTAINER (hbox), bw->add);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- return vbox;
-}
-
-static void
-selection_cb (GtkTreeSelection *selection, gpointer data)
-{
- struct BindingWidgets *bw = data;
-
- gtk_widget_set_sensitive
- (bw->delete,
- gtk_tree_selection_count_selected_rows (selection) ? TRUE : FALSE);
-}
-
-static void
-keyseq_render_function (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- MPlist *keyseq, *pl;
- gint n;
- MText *mt = mtext ();
-
- gtk_tree_model_get (model, iter, 0, &keyseq, -1);
- for (pl = keyseq;
- pl && mplist_key (pl) == Msymbol;
- pl = mplist_next (pl))
- {
- mtext__cat_str (mt, msymbol_name ((MSymbol) mplist_value (pl)));
- mtext_cat_char (mt, ' ');
- }
- g_object_set (renderer, "text", mtext_data (mt, NULL, NULL, NULL, NULL),
- NULL);
- m17n_object_unref (mt);
-}
-
-static void *
-default_cb (GtkButton *button, gpointer data)
-{
- MPlist *empty = mplist ();
- struct BindingWidgets *bw = data;
-
- CONFIG_COMMAND (empty);
- m17n_object_unref (empty);
- update_binding_store (bw->view);
- gtk_widget_set_sensitive (bw->default_, FALSE);
- if (CURRENT_STATUS == Mconfigured)
- {
- gtk_widget_set_sensitive (bw->revert, TRUE);
- gtk_label_set_text (GTK_LABEL (bw->status), _("modified"));
- }
- else
- {
- gtk_widget_set_sensitive (bw->revert, FALSE);
- gtk_label_set_text (GTK_LABEL (bw->status), _("default"));
- }
-}
-
-static void *
-revert_cb (GtkButton *button, gpointer data)
-{
- struct BindingWidgets *bw = data;
-
- CONFIG_COMMAND (NULL);
- update_binding_store (bw->view);
- gtk_widget_set_sensitive (bw->revert, FALSE);
- if (CURRENT_STATUS == Mnil)
- {
- gtk_widget_set_sensitive (bw->default_, FALSE);
- gtk_label_set_text (GTK_LABEL (bw->status), _("default"));
- }
- else
- {
- gtk_widget_set_sensitive (bw->default_, TRUE);
- gtk_label_set_text (GTK_LABEL (bw->status), _("customized"));
- }
-}
-
-static void
-delete_cb (GtkButton *button, gpointer data)
-{
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- MPlist *keyseq, *new, *pl;
- struct BindingWidgets *bw = data;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (bw->view));
- if (! gtk_tree_selection_get_selected (selection, &model, &iter))
- return;
- gtk_tree_model_get (model, &iter, 0, &keyseq, -1);
- new = mplist ();
- for (pl = CURRENT_BINDINGS;
- pl && mplist_key (pl) == Mplist;
- pl = mplist_next (pl))
- if (! keyseq_equal (mplist_value (pl), keyseq))
- mplist_add (new, Mplist, mplist_value (pl));
- CONFIG_COMMAND (new);
- m17n_object_unref (new);
- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
- update_binding_store (bw->view);
- update_widgets (bw);
- gtk_widget_set_sensitive (bw->default_, TRUE);
- gtk_widget_set_sensitive (bw->revert, TRUE);
- gtk_label_set_text (GTK_LABEL (bw->status), _("modified"));
-}
-
-static GtkWidget *
-create_deleting_section (struct BindingWidgets *bw)
-{
- GtkListStore *store;
- GtkWidget *label, *scrolled, *hbox, *vbox;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
- MPlist *pl;
-
- label = gtk_label_new (_("Current key bindings:"));
-
- store = gtk_list_store_new (1, G_TYPE_POINTER);
- bw->view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
- g_object_unref (G_OBJECT (store));
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (bw->view), FALSE);
- update_binding_store (bw->view);
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(bw->view));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
- g_signal_connect (G_OBJECT (selection), "changed",
- G_CALLBACK (selection_cb), bw);
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled),
- bw->view);
-
- column = gtk_tree_view_column_new ();
- gtk_tree_view_append_column (GTK_TREE_VIEW (bw->view), column);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (column, renderer, TRUE);
- gtk_tree_view_column_set_cell_data_func
- (column, renderer, keyseq_render_function, NULL, NULL);
-
- bw->default_ = gtk_button_new_from_stock (_("_Default"));
- g_signal_connect (G_OBJECT (bw->default_), "clicked",
- G_CALLBACK (default_cb), bw);
-
- 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);
- gtk_widget_set_sensitive (bw->delete, FALSE);
- g_signal_connect (G_OBJECT (bw->delete), "clicked",
- G_CALLBACK (delete_cb), bw);
-
- vbox = gtk_vbox_new (FALSE, 12);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
-
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- gtk_container_add (GTK_CONTAINER (vbox), scrolled);
-
- 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), 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);
-
- return vbox;
-}
-
-static void *
-help_cb (GtkButton *button, gpointer data)
-{
- struct BindingWidgets *bw = data;
- GtkWidget *msg;
-
- msg = gtk_message_dialog_new (GTK_WINDOW
- (gtk_widget_get_toplevel (bw->view)),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_CLOSE,
- CURRENT_DESCRIPTION);
- gtk_dialog_run (GTK_DIALOG (msg));
- gtk_widget_destroy (msg);
-}
-
-static void
-set_status (GtkListStore *store, GtkTreeIter *iter)
-{
- MSymbol status;
- gchar *status_str;
-
- status = CURRENT_STATUS;
- if (status == Mconfigured)
- status_str = _("modified");
- else if (status == Mcustomized)
- status_str = _("customized");
- else
- status_str = _("default");
- gtk_list_store_set (store, iter, 1, status_str, -1);
-}
-
-static void
-activated_cb (GtkTreeView *parent, GtkTreePath *path,
- GtkTreeViewColumn *col, gpointer data)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkWidget *dialog, *label, *help, *vbox, *hbox;
- MSymbol status;
- struct BindingWidgets bw;
- gchar *command;
-
- model = gtk_tree_view_get_model (parent);
- if (! gtk_tree_model_get_iter (model, &iter, path))
- return;
- gtk_tree_model_get (model, &iter, 0, &command, -1);
- current_command = msymbol (command);
-
- /*
- dialog = (gtk_dialog_new_with_buttons
- (command,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (parent))),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_OK, GTK_RESPONSE_OK,
- NULL));
- */
- dialog = gtk_dialog_new ();
- gtk_window_set_title (GTK_WINDOW (dialog), command);
- gtk_window_set_transient_for
- (GTK_WINDOW (dialog),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (parent))));
- gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
- gtk_button_box_set_layout (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area),
- GTK_BUTTONBOX_EDGE);
-
- help = gtk_button_new_from_stock (GTK_STOCK_HELP);
- g_signal_connect (G_OBJECT (help), "clicked",
- G_CALLBACK (help_cb), &bw);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
- help, FALSE, FALSE, 0);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_OK);
-
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
- create_deleting_section (&bw));
-
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
- create_adding_section (&bw));
-
- vbox = gtk_vbox_new (FALSE, 12);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
-
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- label = gtk_label_new (_("Status : "));
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
-
- bw.status = gtk_label_new (NULL);
- gtk_box_pack_start (GTK_BOX (hbox), bw.status, FALSE, FALSE, 0);
-
- 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), _("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), _("customized"));
- }
- else
- {
- gtk_widget_set_sensitive (bw.default_, FALSE);
- gtk_widget_set_sensitive (bw.revert, FALSE);
- gtk_label_set_text (GTK_LABEL (bw.status), _("default"));
- }
-
- gtk_widget_show_all (dialog);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_tree_model_get_iter (model, &iter, path);
- set_status (GTK_LIST_STORE (model), &iter);
- gtk_widget_destroy (dialog);
- m17n_object_unref (entry_keyseq);
-}
-
-GtkWidget *
-create_command_list (MSymbol lang, MSymbol name)
-{
- GtkListStore *store;
- GtkWidget *view;
- GtkCellRenderer *renderer;
- MPlist *plist;
-
- current_lang = lang;
- current_name = name;
-
- plist = minput_get_command (lang, name, Mnil);
- /*
- * plist == ((command description status keyseq keyseq ...)
- * (command description status keyseq keyseq ...)
- * ...)
- */
- if (! plist)
- return gtk_label_new (_("No customizable commands."));
-
- store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
- for (; plist && mplist_key (plist) == Mplist; plist = mplist_next (plist))
- {
- GtkTreeIter iter;
- MPlist *pl;
- MSymbol command, status;
- gchar *desc;
- gchar *status_str;
-
- pl = mplist_value (plist);
- /* pl == (command description status keyseq keyseq ...) */
- current_command = command = mplist_value (pl);
-
- pl = mplist_next (pl);
- /* pl == (description status keyseq keyseq ...) */
- if (mplist_key (pl) == Mtext)
- /* Fixme : Assuming the return value is in UTF-8 */
- desc = mtext_data (mplist_value (pl), NULL, NULL, NULL, NULL);
- else
- desc = NULL;
-
- pl = mplist_next (pl);
- /* pl == (status keyseq keyseq ...) */
- status = mplist_value (pl);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, msymbol_name (command),
- -1);
- set_status (store, &iter);
- }
- view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
- g_object_unref (G_OBJECT (store));
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1,
- _("Name"),
- renderer,
- "text", 0,
- NULL);
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1,
- _("Status"),
- renderer,
- "text", 1,
- NULL);
- g_signal_connect (G_OBJECT (view), "row-activated",
- G_CALLBACK (activated_cb), NULL);
- return view;
-}
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include <libintl.h>
-#include <gtk/gtk.h>
-#include <m17n.h>
-#include <config.h>
-
-#define _(String) dgettext (PACKAGE, String)
-
-#define CURRENT_VALUE \
- (mplist_next \
- (mplist_next \
- (mplist_next \
- (mplist_value \
- (minput_get_variable \
- (current_lang, current_name, current_variable))))))
-
-#define CURRENT_STATUS \
- (mplist_value \
- (mplist_next \
- (mplist_next \
- (mplist_value \
- (minput_get_variable \
- (current_lang, current_name, current_variable))))))
-
-#define CURRENT_DESCRIPTION \
- (mtext_data \
- (mplist_value \
- (mplist_next \
- (mplist_value \
- (minput_get_variable \
- (current_lang, current_name, current_variable)))), \
- NULL, NULL, NULL, NULL))
-
-#define CONFIG_VARIABLE(plist) \
- minput_config_variable (current_lang, current_name, current_variable, \
- (plist))
-
-enum WidgetType
- {
- ENTRY_WIDGET,
- COMBO_BOX_WIDGET,
- SPIN_BUTTON_WIDGET
- };
-
-struct ControllerInfo
-{
- /* type of current variable: Minteger, Msymbol, or Mtext */
- MSymbol vtype;
-
- /* widget showing and controlling current variable */
- GtkWidget *widget;
-
- /* type of widget */
- enum WidgetType wtype;
-
- /* whether minput_config_variable () should be called on ok button */
- gboolean need_config;
-
- /* default button */
- GtkWidget *default_;
-
- /* revert button */
- GtkWidget *revert;
-
- /* status label */
- GtkWidget *status;
-
- /* dialog itself */
- GtkWidget *dialog;
-};
-
-static MSymbol current_lang, current_name, current_variable;
-
-static void
-update_widget (struct ControllerInfo *ci)
-{
- MPlist *plist;
- MSymbol key, status;
- 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 /* key == Minteger */
- {
- 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 /* ci->wtype == SPIN_BUTTON_WIDGET */
- 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_widget (ci);
- gtk_widget_set_sensitive (ci->default_, FALSE);
- if (CURRENT_STATUS == Mconfigured)
- {
- gtk_widget_set_sensitive (ci->revert, TRUE);
- gtk_label_set_text (GTK_LABEL (ci->status), _("modified"));
- }
- else
- {
- gtk_widget_set_sensitive (ci->revert, FALSE);
- gtk_label_set_text (GTK_LABEL (ci->status), _("default"));
- }
- ci->need_config = FALSE;
-}
-
-static void *
-revert_cb (GtkButton *button, gpointer data)
-{
- struct ControllerInfo *ci = data;
-
- CONFIG_VARIABLE (NULL);
- update_widget (ci);
- gtk_widget_set_sensitive (ci->revert, FALSE);
- if (CURRENT_STATUS == Mnil)
- {
- gtk_widget_set_sensitive (ci->default_, FALSE);
- gtk_label_set_text (GTK_LABEL (ci->status), _("default"));
- }
- else
- {
- gtk_widget_set_sensitive (ci->default_, TRUE);
- gtk_label_set_text (GTK_LABEL (ci->status), _("customized"));
- }
- ci->need_config = FALSE;
-}
-
-static gboolean
-config_with_entry (struct ControllerInfo *ci)
-{
- const gchar *text = gtk_entry_get_text (GTK_ENTRY (ci->widget));
- MPlist *plist = mplist ();
- gboolean ret = TRUE;
-
- if (ci->vtype == Msymbol)
- {
- mplist_add (plist, Msymbol, msymbol (text));
- CONFIG_VARIABLE (plist);
- }
- else if (ci->vtype == Mtext)
- {
- MText *mt;
-
- mt = mconv_decode_buffer (Mcoding_utf_8, text, strlen (text));
- mplist_add (plist, Mtext, mt);
- CONFIG_VARIABLE (plist);
- m17n_object_unref (mt);
- }
- else /* ci->vtype == Minteger */
- {
- int i;
- gchar buf[32];
-
- if (sscanf (text, "%d", &i) == 1)
- {
- mplist_add (plist, Minteger, (void *) i);
- CONFIG_VARIABLE (plist);
- }
- else
- {
- GtkWidget *msg;
-
- msg = gtk_message_dialog_new (GTK_WINDOW
- (gtk_widget_get_toplevel (ci->dialog)),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("The value must be an integer."));
- gtk_dialog_run (GTK_DIALOG (msg));
- gtk_widget_destroy (msg);
- ret = FALSE;
- }
- }
-
- m17n_object_unref (plist);
- return ret;
-}
-
-static gboolean
-config_with_combo (struct ControllerInfo *ci)
-{
- gchar *text = gtk_combo_box_get_active_text (GTK_COMBO_BOX (ci->widget));
- MPlist *plist = mplist ();
-
- if (ci->vtype == Msymbol)
- {
- mplist_add (plist, Msymbol, msymbol (text));
- CONFIG_VARIABLE (plist);
- }
- else if (ci->vtype == Mtext)
- {
- MText *mt;
-
- mt = mconv_decode_buffer (Mcoding_utf_8, text, strlen (text));
- mplist_add (plist, Mtext, mt);
- CONFIG_VARIABLE (plist);
- m17n_object_unref (mt);
- }
- else /* ci->vtype == Minteger */
- {
- int i;
-
- sscanf (text, "%d", &i);
- mplist_add (plist, Minteger, (void *) i);
- CONFIG_VARIABLE (plist);
- }
- m17n_object_unref (plist);
- return TRUE;
-}
-
-static gboolean
-config_with_spin (struct ControllerInfo *ci)
-{
- gint i;
-
- i = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ci->widget));
- MPlist *plist = mplist ();
-
- mplist_add (plist, Minteger, (void *) i);
- CONFIG_VARIABLE (plist);
- m17n_object_unref (plist);
- return TRUE;
-}
-
-static void *
-ok_cb (GtkButton *button, gpointer data)
-{
- struct ControllerInfo *ci = data;
-
- if (ci->need_config)
- {
- if (ci->wtype == ENTRY_WIDGET)
- {
- if (config_with_entry (ci))
- gtk_dialog_response (GTK_DIALOG (ci->dialog), GTK_RESPONSE_OK);
- else
- revert_cb (NULL, ci);
- }
-
- else if (ci->wtype == COMBO_BOX_WIDGET)
- {
- config_with_combo (ci); /* always returns true */
- gtk_dialog_response (GTK_DIALOG (ci->dialog), GTK_RESPONSE_OK);
- }
-
- else /* ci->wtype == SPIN_BUTTON */
- {
- config_with_spin (ci); /* always returns true */
- gtk_dialog_response (GTK_DIALOG (ci->dialog), GTK_RESPONSE_OK);
- }
- }
- else
- gtk_dialog_response (GTK_DIALOG (ci->dialog), GTK_RESPONSE_OK);
-}
-
-static void
-changed_cb (GtkEntry *entry, gpointer data)
-{
- struct ControllerInfo *ci = data;
-
- gtk_widget_set_sensitive (ci->default_, TRUE);
- gtk_widget_set_sensitive (ci->revert, TRUE);
- gtk_label_set_text (GTK_LABEL (ci->status), _("modified"));
- ci->need_config = TRUE;
-}
-
-enum
- {
- VCOL_VARIABLE,
- VCOL_VALUE,
- VCOL_STATUS,
- NUM_VCOLS
- };
-
-static void
-set_value_status (GtkListStore *store, GtkTreeIter *iter)
-{
- MPlist *plist;
- MSymbol status;
- gchar *value_str, *status_str, buf[32];
-
- status = CURRENT_STATUS;
- if (status == Mconfigured)
- status_str = _("modified");
- else if (status == Mcustomized)
- status_str = _("customized");
- else
- status_str = _("default");
-
- plist = CURRENT_VALUE;
- /* plist == (value [valid-value ...]) */
- if (mplist_key (plist) == Msymbol)
- value_str = msymbol_name ((MSymbol) mplist_value (plist));
- else if (mplist_key (plist) == Mtext)
- /* Fixme : Assuming the return value is in UTF-8 */
- value_str = mtext_data ((MText *) mplist_value (plist),
- NULL, NULL, NULL, NULL);
- else
- {
- g_snprintf (buf, sizeof (buf), "%d", (gint) mplist_value (plist));
- value_str = buf;
- }
-
- gtk_list_store_set (store, iter,
- VCOL_VALUE, value_str,
- VCOL_STATUS, status_str,
- -1);
-}
-
-static GtkWidget *
-create_widget (struct ControllerInfo *ci)
-{
- MPlist *plist;
- void *value;
-
- plist = CURRENT_VALUE;
- /* plist == (value [valid-value ...]) */
- ci->vtype = mplist_key (plist);
- value = mplist_value (plist);
- plist = mplist_next (plist);
-
- if (ci->vtype == Msymbol)
- {
- if (plist && mplist_key (plist) == Msymbol)
- {
- gint i, nth;
-
- ci->widget = gtk_combo_box_new_text ();
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- ci->wtype = COMBO_BOX_WIDGET;
- for (i = 0; plist && mplist_key (plist) == Msymbol;
- plist = mplist_next (plist), i++)
- {
- if (mplist_value (plist) == value)
- nth = i;
- gtk_combo_box_append_text
- (GTK_COMBO_BOX (ci->widget),
- msymbol_name ((MSymbol) mplist_value (plist)));
- }
- gtk_combo_box_set_active (GTK_COMBO_BOX (ci->widget), nth);
- }
- else
- {
- ci->widget = gtk_entry_new ();
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- g_signal_connect (GTK_OBJECT (ci->widget), "activate",
- G_CALLBACK (ok_cb), ci);
- ci->wtype = ENTRY_WIDGET;
- gtk_entry_set_text (GTK_ENTRY (ci->widget), msymbol_name (value));
- gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE);
- }
- }
- else if (ci->vtype == Mtext)
- {
- if (plist && mplist_key (plist) == Mtext)
- {
- gint i, nth;
-
- ci->widget = gtk_combo_box_new_text ();
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- ci->wtype = COMBO_BOX_WIDGET;
- for (i = 0; plist && mplist_key (plist) == Mtext;
- plist = mplist_next (plist), i++)
- {
- if (! mtext_cmp ((MText *) mplist_value (plist),
- (MText *) value))
- nth = i;
- /* Fixme : Assuming the return value is in UTF-8 */
- gtk_combo_box_append_text
- (GTK_COMBO_BOX (ci->widget),
- mtext_data ((MText *) mplist_value (plist),
- NULL, NULL, NULL, NULL));
- }
- gtk_combo_box_set_active (GTK_COMBO_BOX (ci->widget), nth);
- }
- else
- {
- ci->widget = gtk_entry_new ();
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- g_signal_connect (GTK_OBJECT (ci->widget), "activate",
- G_CALLBACK (ok_cb), ci);
- ci->wtype = ENTRY_WIDGET;
- /* Fixme : Assuming the return value is in UTF-8 */
- gtk_entry_set_text (GTK_ENTRY (ci->widget),
- mtext_data (value, NULL, NULL, NULL, NULL));
- gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE);
- }
- }
- else /* ci->vtype == Minteger */
- {
- if (plist && mplist_key (plist) == Minteger)
- {
- gint i, nth;
-
- ci->widget = gtk_combo_box_new_text ();
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- ci->wtype = COMBO_BOX_WIDGET;
- for (i = 0; plist && mplist_key (plist) == Minteger;
- plist = mplist_next (plist), i++)
- {
- gchar buf[32];
-
- if (mplist_value (plist) == value)
- nth = i;
- g_snprintf (buf, sizeof (buf), "%d",
- (gint) mplist_value (plist));
- gtk_combo_box_append_text (GTK_COMBO_BOX (ci->widget), buf);
- }
- gtk_combo_box_set_active (GTK_COMBO_BOX (ci->widget), nth);
- }
- else if (plist && mplist_key (plist) == Mplist)
- {
- GtkObject *adj;
- gdouble lower, upper;
-
- plist = mplist_value (plist);
- lower = (gdouble) (int) mplist_value (plist);
- upper = (gdouble) (int) mplist_value (mplist_next (plist));
- adj = gtk_adjustment_new ((gdouble) (int) value, lower, upper,
- 1.0, 10.0, 0);
- ci->widget = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 0, 0);
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- ci->wtype = SPIN_BUTTON_WIDGET;
- gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (ci->widget), TRUE);
- gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (ci->widget),
- GTK_UPDATE_ALWAYS);
- }
- else
- {
- gchar buf[32];
-
- ci->widget = gtk_entry_new ();
- g_signal_connect (GTK_OBJECT (ci->widget), "changed",
- G_CALLBACK (changed_cb), ci);
- g_signal_connect (GTK_OBJECT (ci->widget), "activate",
- G_CALLBACK (ok_cb), ci);
- ci->wtype = ENTRY_WIDGET;
- g_snprintf (buf, sizeof (buf), "%d", (gint) value);
- gtk_entry_set_text (GTK_ENTRY (ci->widget), buf);
- gtk_editable_set_editable (GTK_EDITABLE (ci->widget), TRUE);
- }
- }
-
- return ci->widget;
-}
-
-static void *
-help_cb (GtkButton *button, gpointer data)
-{
- struct ControllerInfo *ci = data;
- GtkWidget *msg;
-
- msg = gtk_message_dialog_new (GTK_WINDOW
- (gtk_widget_get_toplevel (ci->dialog)),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_CLOSE,
- CURRENT_DESCRIPTION);
- gtk_dialog_run (GTK_DIALOG (msg));
- gtk_widget_destroy (msg);
-}
-
-static void
-row_activated_cb (GtkTreeView *parent, GtkTreePath *path,
- GtkTreeViewColumn *col, gpointer data)
-{
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkWidget *label, *ok, *help, *hbox, *vbox;
- MSymbol status;
- struct ControllerInfo ci;
- gchar *variable;
-
- model = gtk_tree_view_get_model (parent);
- if (! gtk_tree_model_get_iter (model, &iter, path))
- return;
- gtk_tree_model_get (model, &iter, VCOL_VARIABLE, &variable, -1);
- current_variable = msymbol (variable);
-
- ci.dialog = (gtk_dialog_new_with_buttons
- (variable,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (parent))),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- NULL));
-
- ci.default_ = gtk_button_new_from_stock (_("_Default"));
- g_signal_connect (G_OBJECT (ci.default_), "clicked",
- G_CALLBACK (default_cb), &ci);
-
- 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);
-
- label = gtk_label_new (_("Status : "));
- ci.status = gtk_label_new (NULL);
-
- ok = gtk_button_new_from_stock (GTK_STOCK_OK);
- g_signal_connect (G_OBJECT (ok), "clicked",
- G_CALLBACK (ok_cb), &ci);
-
- help = gtk_button_new_from_stock (GTK_STOCK_HELP);
- g_signal_connect (G_OBJECT (help), "clicked",
- G_CALLBACK (help_cb), &ci);
-
- vbox = gtk_vbox_new (FALSE, 12);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (ci.dialog)->vbox), vbox);
-
- gtk_container_add (GTK_CONTAINER (vbox), create_widget (&ci));
-
- hbox = gtk_hbutton_box_new ();
- gtk_box_set_spacing (GTK_BOX (hbox), 6);
- gtk_container_add (GTK_CONTAINER (hbox), ci.default_);
- gtk_container_add (GTK_CONTAINER (hbox), ci.revert);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- hbox = gtk_hbox_new (FALSE, 6);
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), ci.status, FALSE, FALSE, 0);
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- gtk_button_box_set_layout
- (GTK_BUTTON_BOX (GTK_DIALOG (ci.dialog)->action_area),
- GTK_BUTTONBOX_EDGE);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (ci.dialog)->action_area),
- help);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (ci.dialog)->action_area),
- ok);
-
- status = CURRENT_STATUS;
- if (status == Mconfigured)
- {
- gtk_widget_set_sensitive (ci.default_, TRUE);
- gtk_widget_set_sensitive (ci.revert, TRUE);
- gtk_label_set_text (GTK_LABEL (ci.status), _("modified"));
- }
- else if (status == Mcustomized)
- {
- gtk_widget_set_sensitive (ci.default_, TRUE);
- gtk_widget_set_sensitive (ci.revert, FALSE);
- gtk_label_set_text (GTK_LABEL (ci.status), _("customized"));
- }
- else
- {
- gtk_widget_set_sensitive (ci.default_, FALSE);
- gtk_widget_set_sensitive (ci.revert, FALSE);
- gtk_label_set_text (GTK_LABEL (ci.status), _("default"));
- }
-
- ci.need_config = FALSE;
-
- gtk_widget_show_all (ci.dialog);
- gtk_dialog_run (GTK_DIALOG (ci.dialog));
- gtk_tree_model_get_iter (model, &iter, path);
- set_value_status (GTK_LIST_STORE (model), &iter);
- gtk_widget_destroy (ci.dialog);
-}
-
-GtkWidget *
-create_variable_list (MSymbol lang, MSymbol name)
-{
- GtkListStore *store;
- GtkWidget *view;
- GtkCellRenderer *renderer;
- MPlist *plist;
-
- current_lang = lang;
- current_name = name;
-
- plist = minput_get_variable (lang, name, Mnil);
- if (! plist)
- return gtk_label_new (_("No customizable variables."));
-
- /*
- * plist == ((variable description status value [valid-value ...])
- * (variable description status value [valid-value ...])
- * ...)
- */
-
- store = gtk_list_store_new (NUM_VCOLS,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING);
- for (; plist && mplist_key (plist) == Mplist; plist = mplist_next (plist))
- {
- GtkTreeIter iter;
- MPlist *pl;
- MSymbol variable, value, status;
- gchar *desc;
- gchar *status_str;
-
- pl = mplist_value (plist);
- /* pl == (variable description status value [valid-value ...]) */
- current_variable = mplist_value (pl);
-
- pl = mplist_next (pl);
- /* pl == (description status value [valid-value ...]) */
- if (mplist_key (pl) == Mtext)
- /* Fixme : Assuming the return value is in UTF-8 */
- desc = mtext_data (mplist_value (pl), NULL, NULL, NULL, NULL);
- else
- desc = NULL;
-
- pl = mplist_next (pl);
- /* pl == (status value [valid-value ...]) */
- status = mplist_value (pl);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- VCOL_VARIABLE, msymbol_name (current_variable),
- -1);
- set_value_status (store, &iter);
- }
- view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
- g_object_unref (G_OBJECT (store));
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1,
- _("Name"),
- renderer,
- "text",
- VCOL_VARIABLE,
- NULL);
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1,
- _("Value"),
- renderer,
- "text",
- VCOL_VALUE,
- NULL);
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1,
- _("Status"),
- renderer,
- "text",
- VCOL_STATUS,
- NULL);
- g_signal_connect (G_OBJECT (view), "row-activated",
- G_CALLBACK (row_activated_cb), NULL);
- return view;
-}