1 /** @file scim_hangul_imengine_setup.cpp
2 * implementation of Setup Module of hangul imengine module.
6 * Smart Common Input Method
8 * Copyright (C) 2004-2006 Choe Hwanjin
9 * Copyright (c) 2004-2006 James Su <suzhe@turbolinux.com.cn>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
25 * $Id: scim_hangul_imengine_setup.cpp,v 1.8 2006/10/23 12:42:47 hwanjin Exp $
29 #define Uses_SCIM_CONFIG_BASE
38 //#include <gtk/scimkeyselection.h>
43 #define _(String) dgettext(GETTEXT_PACKAGE,String)
44 #define N_(String) (String)
46 #define _(String) (String)
47 #define N_(String) (String)
48 #define bindtextdomain(Package,Directory)
49 #define textdomain(domain)
50 #define bind_textdomain_codeset(domain,codeset)
55 #define scim_module_init hangul_imengine_setup_LTX_scim_module_init
56 #define scim_module_exit hangul_imengine_setup_LTX_scim_module_exit
58 #define scim_setup_module_create_ui hangul_imengine_setup_LTX_scim_setup_module_create_ui
59 #define scim_setup_module_get_category hangul_imengine_setup_LTX_scim_setup_module_get_category
60 #define scim_setup_module_get_name hangul_imengine_setup_LTX_scim_setup_module_get_name
61 #define scim_setup_module_get_description hangul_imengine_setup_LTX_scim_setup_module_get_description
62 #define scim_setup_module_load_config hangul_imengine_setup_LTX_scim_setup_module_load_config
63 #define scim_setup_module_save_config hangul_imengine_setup_LTX_scim_setup_module_save_config
64 #define scim_setup_module_query_changed hangul_imengine_setup_LTX_scim_setup_module_query_changed
67 #define SCIM_CONFIG_IMENGINE_HANGUL_USE_DVORAK "/IMEngine/Hangul/UseDvorak"
68 #define SCIM_CONFIG_IMENGINE_HANGUL_SHOW_CANDIDATE_COMMENT "/IMEngine/Hangul/ShowCandidateComment"
69 #define SCIM_CONFIG_IMENGINE_HANGUL_HANGUL_HANJA_KEY "/IMEngine/Hangul/HangulHanjaKey"
71 #define SCIM_CONFIG_SHOW_CANDIDATE_COMMENT "/IMEngine/Hangul/ShowCandidateComment"
72 #define SCIM_CONFIG_LAYOUT "/IMEngine/Hangul/KeyboardLayout"
73 #define SCIM_CONFIG_HANGUL_KEY "/IMEngine/Hangul/HangulKey"
74 #define SCIM_CONFIG_HANJA_KEY "/IMEngine/Hangul/HanjaKey"
75 #define SCIM_CONFIG_HANJA_MODE_KEY "/IMEngine/Hangul/HanjaModeKey"
76 #define SCIM_CONFIG_USE_ASCII_MODE "/IMEngine/Hangul/UseAsciiMode"
77 #define SCIM_CONFIG_COMMIT_BY_WORD "/IMEngine/Hangul/CommitByWord"
80 static GtkWidget * create_setup_window ();
81 static void load_config (const ConfigPointer &config);
82 static void save_config (const ConfigPointer &config);
83 static bool query_changed ();
87 void scim_module_init (void)
89 bindtextdomain (GETTEXT_PACKAGE, SCIM_HANGUL_LOCALEDIR);
90 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
93 void scim_module_exit (void)
97 GtkWidget * scim_setup_module_create_ui (void)
99 static GtkWidget *setup_ui = NULL;
100 if (setup_ui == NULL)
101 setup_ui = create_setup_window ();
105 String scim_setup_module_get_category (void)
107 return String ("IMEngine");
110 String scim_setup_module_get_name (void)
112 return String (_("Hangul"));
115 String scim_setup_module_get_description (void)
117 return String (_("A Hangul IMEngine Module."));
120 void scim_setup_module_load_config (const ConfigPointer &config)
122 load_config (config);
125 void scim_setup_module_save_config (const ConfigPointer &config)
127 save_config (config);
130 bool scim_setup_module_query_changed ()
132 return query_changed ();
136 // Internal data structure
137 struct KeyBindingData
148 static GtkWidget *keyboard_layout_combo = NULL;
149 static GtkWidget *use_ascii_mode_button = NULL;
150 static GtkWidget *commit_by_word_button = NULL;
151 static GtkWidget *show_candidate_comment_button = NULL;
153 static bool __have_changed = false;
155 static KeyBindingData key_bindings[] =
159 SCIM_CONFIG_HANGUL_KEY,
163 N_("Select Hangul keys"),
165 N_("The key events to change input mode between hangul and ascii."
166 "Click on the button on the right to edit it."),
177 SCIM_CONFIG_HANJA_KEY,
179 N_("Hangul to Hanja keys:"),
181 N_("Select Hangul to Hanja keys"),
183 N_("The key events to convert Hangul to Hanja character. "
184 "Click on the button on the right to edit it."),
195 SCIM_CONFIG_HANJA_MODE_KEY,
197 N_("Hanja mode keys:"),
199 N_("Select a key to toggle hanja mode keys"),
201 N_("The key events to toggle Hanja mode. "
202 "Click on the button on the right to edit it."),
212 // Declaration of internal functions.
214 on_default_editable_changed (GtkEditable *editable,
218 on_default_toggle_button_toggled (GtkToggleButton *togglebutton,
222 on_default_key_selection_clicked (GtkButton *button,
226 on_default_combo_box_changed (GtkComboBox *combobox,
230 create_options_page(GtkTooltips *tooltip);
233 create_keyboard_page(GtkTooltips *tooltip);
235 // Function implementations.
237 create_options_page(GtkTooltips *tooltips)
242 vbox = gtk_vbox_new (FALSE, 12);
243 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
245 button = gtk_check_button_new_with_mnemonic (_("_Use ascii input mode"));
246 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
247 gtk_tooltips_set_tip(tooltips, button,
248 _("Whether to enable to change the input mode "
249 "between hangul and ascii mode."), NULL);
250 g_signal_connect(G_OBJECT(button), "toggled",
251 G_CALLBACK(on_default_toggle_button_toggled), NULL);
252 use_ascii_mode_button = button;
254 button = gtk_check_button_new_with_mnemonic (_("_Show candidate comment"));
255 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
256 gtk_tooltips_set_tip(tooltips, button,
257 _("Whether to show the comment of candidates or not."), NULL);
258 g_signal_connect(G_OBJECT(button), "toggled",
259 G_CALLBACK(on_default_toggle_button_toggled), NULL);
260 show_candidate_comment_button = button;
262 button = gtk_check_button_new_with_mnemonic (_("_Commit by word"));
263 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
264 gtk_tooltips_set_tip(tooltips, button,
265 _("Whether not to commit until any non-hangul character is inputed."), NULL);
266 g_signal_connect(G_OBJECT(button), "toggled",
267 G_CALLBACK(on_default_toggle_button_toggled), NULL);
268 commit_by_word_button = button;
274 create_keyboard_page(GtkTooltips *tooltips)
278 GtkWidget *vbox1 = gtk_vbox_new(FALSE, 12);
279 gtk_container_set_border_width(GTK_CONTAINER(vbox1), 12);
281 GtkWidget *label = gtk_label_new("");
282 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
283 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
284 gtk_label_set_markup(GTK_LABEL(label),
285 _("<span weight=\"bold\">Keyboard layout</span>"));
286 gtk_box_pack_start(GTK_BOX(vbox1), label, FALSE, TRUE, 0);
288 GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
289 gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, TRUE, 0);
291 label = gtk_label_new(" ");
292 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0);
294 GtkWidget *vbox2 = gtk_vbox_new(FALSE, 0);
295 gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, TRUE, 0);
297 GtkWidget *combo_box = gtk_combo_box_new_text();
298 gtk_box_pack_start(GTK_BOX(vbox2), combo_box, FALSE, TRUE, 0);
299 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("2bul"));
300 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("3bul 2bul-shifted"));
301 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("3bul Final"));
302 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("3bul 390"));
303 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("3bul No-Shift"));
304 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("3bul Yetgeul"));
305 g_signal_connect(G_OBJECT(combo_box), "changed",
306 G_CALLBACK (on_default_combo_box_changed), NULL);
307 keyboard_layout_combo = combo_box;
310 label = gtk_label_new("");
311 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
312 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
313 gtk_label_set_markup(GTK_LABEL(label),
314 _("<span weight=\"bold\">Key bindings</span>"));
315 gtk_box_pack_start(GTK_BOX(vbox1), label, FALSE, TRUE, 0);
317 hbox = gtk_hbox_new(FALSE, 0);
318 gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, TRUE, 0);
320 label = gtk_label_new(" ");
321 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0);
323 vbox2 = gtk_vbox_new(FALSE, 0);
324 gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, TRUE, 0);
326 GtkWidget *table = gtk_table_new (3, G_N_ELEMENTS(key_bindings), FALSE);
327 gtk_box_pack_start(GTK_BOX(vbox2), table, FALSE, TRUE, 0);
329 for (i = 0; i < G_N_ELEMENTS(key_bindings); ++ i) {
330 label = gtk_label_new (NULL);
331 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _(key_bindings[i].label));
332 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
333 gtk_misc_set_padding (GTK_MISC (label), 4, 0);
334 gtk_table_attach (GTK_TABLE (table), label, 0, 1, i, i+1,
335 (GtkAttachOptions) (GTK_FILL),
336 (GtkAttachOptions) (GTK_FILL), 4, 4);
338 key_bindings[i].entry = gtk_entry_new ();
339 gtk_table_attach (GTK_TABLE (table), key_bindings[i].entry, 1, 2, i, i+1,
340 (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
341 (GtkAttachOptions) (GTK_FILL), 4, 4);
342 gtk_entry_set_editable (GTK_ENTRY (key_bindings[i].entry), FALSE);
343 gtk_entry_set_text (GTK_ENTRY (key_bindings[i].entry),
344 key_bindings[i].data.c_str());
346 key_bindings[i].button = gtk_button_new_with_label ("...");
347 gtk_table_attach (GTK_TABLE (table), key_bindings[i].button, 2, 3, i, i+1,
348 (GtkAttachOptions) (GTK_FILL),
349 (GtkAttachOptions) (GTK_FILL), 4, 4);
350 gtk_label_set_mnemonic_widget (GTK_LABEL (label), key_bindings[i].button);
352 g_signal_connect(G_OBJECT(key_bindings[i].button), "clicked",
353 G_CALLBACK (on_default_key_selection_clicked),
355 g_signal_connect(G_OBJECT(key_bindings[i].entry), "changed",
356 G_CALLBACK (on_default_editable_changed), NULL);
358 gtk_tooltips_set_tip(tooltips, key_bindings[i].entry,
359 _(key_bindings[i].tooltip), NULL);
366 create_setup_window ()
371 GtkTooltips *tooltips;
373 tooltips = gtk_tooltips_new ();
375 // Create the Notebook.
376 notebook = gtk_notebook_new ();
378 // Create the first page.
379 page = create_keyboard_page(tooltips);
380 label = gtk_label_new (_("Keyboard"));
381 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
383 // Create the second page.
384 page = create_options_page(tooltips);
385 label = gtk_label_new (_("Options"));
386 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
388 gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 0);
390 gtk_widget_show_all(notebook);
396 load_config (const ConfigPointer &config)
401 // keyboard layout option
402 String layout = config->read(String(SCIM_CONFIG_LAYOUT), String("2"));
406 } else if (layout == "32") {
408 } else if (layout == "3f") {
410 } else if (layout == "39") {
412 } else if (layout == "3s") {
414 } else if (layout == "3y") {
417 gtk_combo_box_set_active(GTK_COMBO_BOX(keyboard_layout_combo), no);
420 for (unsigned int i = 0; i < G_N_ELEMENTS(key_bindings); ++ i) {
422 config->read (String (key_bindings[i].key), key_bindings[i].data);
423 gtk_entry_set_text(GTK_ENTRY(key_bindings[i].entry), text.c_str());
428 // use ascii input mode
429 stat = config->read(String(SCIM_CONFIG_USE_ASCII_MODE), false);
430 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(use_ascii_mode_button), stat);
432 // show candidate comment option
433 stat = config->read(String(SCIM_CONFIG_SHOW_CANDIDATE_COMMENT), true);
434 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_candidate_comment_button), stat);
436 // commit by word or not
437 stat = config->read(String(SCIM_CONFIG_COMMIT_BY_WORD), false);
438 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(commit_by_word_button), stat);
440 __have_changed = false;
444 save_config (const ConfigPointer &config)
449 int no = gtk_combo_box_get_active(GTK_COMBO_BOX(keyboard_layout_combo));
453 } else if (no == 1) {
455 } else if (no == 2) {
457 } else if (no == 3) {
459 } else if (no == 4) {
461 } else if (no == 5) {
464 config->write(String(SCIM_CONFIG_LAYOUT), layout);
466 for (unsigned int i = 0; i < G_N_ELEMENTS(key_bindings); ++ i) {
467 String text = gtk_entry_get_text(GTK_ENTRY(key_bindings[i].entry));
468 config->write(String (key_bindings[i].key), text);
473 // use ascii input mode
474 stat = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(use_ascii_mode_button));
475 config->write(String(SCIM_CONFIG_USE_ASCII_MODE), (bool)stat);
477 // show candidate comment
478 stat = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(show_candidate_comment_button));
479 config->write(String(SCIM_CONFIG_SHOW_CANDIDATE_COMMENT), (bool)stat);
481 // commit by word or not
482 stat = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(commit_by_word_button));
483 config->write(String(SCIM_CONFIG_COMMIT_BY_WORD), (bool)stat);
485 __have_changed = false;
491 return __have_changed;
495 on_default_editable_changed (GtkEditable *editable,
498 __have_changed = true;
502 on_default_toggle_button_toggled (GtkToggleButton *togglebutton,
505 __have_changed = true;
509 on_default_combo_box_changed(GtkComboBox *combobox,
512 __have_changed = true;
516 on_default_key_selection_clicked (GtkButton *button,
519 KeyBindingData *data = static_cast<KeyBindingData *> (user_data);
522 GtkWidget *dialog = NULL;// = scim_key_selection_dialog_new (_(data->title));
525 scim_key_selection_dialog_set_keys (
526 SCIM_KEY_SELECTION_DIALOG (dialog),
527 gtk_entry_get_text (GTK_ENTRY (data->entry)));
529 result = gtk_dialog_run (GTK_DIALOG (dialog));
531 if (result == GTK_RESPONSE_OK) {
532 const gchar *keys = "";//scim_key_selection_dialog_get_keys (
533 //SCIM_KEY_SELECTION_DIALOG (dialog));
535 if (!keys) keys = "";
537 if (strcmp (keys, gtk_entry_get_text (GTK_ENTRY (data->entry))) != 0)
538 gtk_entry_set_text (GTK_ENTRY (data->entry), keys);
541 gtk_widget_destroy (dialog);
546 vi:ts=4:nowrap:expandtab