diff --git a/honoka/src/Makefile.am b/honoka/src/Makefile.am index 8a938aa..6a30895 100644 --- a/honoka/src/Makefile.am +++ b/honoka/src/Makefile.am @@ -26,8 +26,8 @@ -DHONOKA_ICON_FILE=\"@SCIM_ICONDIR@/honoka.png\" \ -DHONOKA_PLUGINDIR=\"@SCIM_MODULEDIR@/honoka\" -noinst_HEADERS = honoka_imengine.h \ - multiconvertor.h honoka_def.h +noinst_HEADERS = honoka_imengine.h multiconvertor.h honoka_def.h \ + honokasetupgtk.h moduledir = @SCIM_MODULEDIR@/IMEngine module_LTLIBRARIES = honoka.la @@ -49,7 +49,7 @@ setupmoduledir = @SCIM_MODULEDIR@/SetupUI setupmodule_LTLIBRARIES = $(SETUP_MODULE) -honoka_imengine_setup_la_SOURCES = honoka_imengine_setup.cpp +honoka_imengine_setup_la_SOURCES = honoka_imengine_setup.cpp honokasetupgtk.cpp honoka_imengine_setup_la_CFLAGS = @SCIM_GTKUTILS_CFLAGS@ @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ diff --git a/honoka/src/honoka_imengine_setup.cpp b/honoka/src/honoka_imengine_setup.cpp index 6c3e8ae..a5b3de3 100644 --- a/honoka/src/honoka_imengine_setup.cpp +++ b/honoka/src/honoka_imengine_setup.cpp @@ -63,12 +63,15 @@ #define scim_setup_module_query_changed honoka_imengine_setup_LTX_scim_setup_module_query_changed +#include static GtkWidget * create_setup_window (); static void load_config (const ConfigPointer &config); static void save_config (const ConfigPointer &config); static bool query_changed (); +static HonokaSetupGtk * setup; + // Module Interface. extern "C" { @@ -119,1017 +122,240 @@ } // extern "C" -// Internal data structure -struct KeyboardConfigData +static GtkWidget * create_setup_window () { - const char *key; - String data; - const char *label; - const char *title; - const char *tooltip; - GtkWidget *entry; - GtkWidget *button; -}; - -struct KeyboardConfigPage -{ - const char *label; - KeyboardConfigData *data; -}; - -struct ListData -{ - GtkWidget *widget; - String name; - gchar *label; -}; - -// Internal data declaration. -//static bool __config_use_kana = false; -static String __config_server = HONOKA_DEFAULT_JSERVER; -static String __config_wnn_rc = HONOKA_DEFAULT_WNNENVRC; -static String __config_servertype = HONOKA_DEFAULT_JSERVERTYPE; -static String __config_preeditor = HONOKA_DEFAULT_DEFAULT_PREEDITOR; -static bool __config_yosoku = HONOKA_DEFAULT_WNNYOSOKU; -static bool __config_numkeyselect = HONOKA_DEFAULT_NUMKEY_SELECT; -static bool __config_autoconversion = HONOKA_DEFAULT_AUTO_CONVERSION; -static int __config_alp = HONOKA_DEFAULT_ALP; -static String __config_romkan_table = HONOKA_DEFAULT_ROMKAN_TABLE_FILE; - -static bool __have_changed = true; - -//static GtkWidget * __widget_use_kana = 0; -static GtkWidget * __widget_server = 0; -static GtkWidget * __widget_servertype = 0; -static GtkWidget * __widget_preeditor = 0; -static GtkWidget * __widget_wnn_rc = 0; -static GtkWidget * __widget_yosoku = 0; -static GtkWidget * __widget_alp = 0; -static GtkWidget * __widget_numkeyselect = 0; -static GtkWidget * __widget_autoconversion = 0; -static GtkWidget * __widget_romkan_table = 0; -static GtkTooltips * __widget_tooltips = 0; - -static ListData __list_data [] = -{ - { - NULL, - String("Wnn4"), - N_("Wnn4 or FreeWnn"), - }, - { - NULL, - String("Wnn6"), - N_("Wnn6"), - }, - { - NULL, - String("Wnn7"), - N_("Wnn7"), - }, - { - NULL, - String("Wnn8"), - N_("Wnn8"), - }, - { - NULL, - String("Romkan"), - N_("Roma-Kana input"), - }, - { - NULL, - String("KanaInput"), - N_("Kana input"), - }, - { - NULL, - String(), - NULL, - }, -}; - -static KeyboardConfigData __config_keyboards_common [] = -{ - { + setup = new HonokaSetupGtk("setup","",""); + HonokaSetupGtkPage *page; + vector l; + HonokaSetupGtk * keys = new HonokaSetupGtk(_("key setting"),"",""); + page = new HonokaSetupGtkPage(_("general setting"),"",""); + page->append(new HonokaSetupGtkIntItem( + _("_Auto candidates popup: "), + HONOKA_CONFIG_ALP, + _("set the count of conversion until displaying the list of lookup result automatically."), + HONOKA_DEFAULT_ALP, + -1,10 + )); + setup->append(page); + + page = new HonokaSetupGtkPage(_("Common keys"),"",""); + page->append(new HonokaSetupGtkKeyItem( + _("Commit keys:"), HONOKA_CONFIG_KEY_COMMIT, - HONOKA_DEFAULT_KEY_COMMIT, - N_("Commit keys:"), - N_("Select commit keys"), - N_("The key events to commit the preedit string. "), - NULL, - NULL, - }, - { + _("The key events to commit the preedit string. "), + HONOKA_DEFAULT_KEY_COMMIT + )); + page->append(new HonokaSetupGtkKeyItem( + _("Convert keys:"), HONOKA_CONFIG_KEY_CONVERSION_START, - HONOKA_DEFAULT_KEY_CONVERSION_START, - N_("Convert keys:"), - N_("Select convert keys"), - N_("The key events to convert the preedit string to kanji. "), - NULL, - NULL, - }, - { + _("The key events to convert the preedit string to kanji. "), + HONOKA_DEFAULT_KEY_CONVERSION_START + )); + page->append(new HonokaSetupGtkKeyItem( + _("Cancel keys:"), HONOKA_CONFIG_KEY_CANCEL, - HONOKA_DEFAULT_KEY_CANCEL, - N_("Cancel keys:"), - N_("Select cancel keys"), - N_("The key events to cancel preediting or converting. "), - NULL, - NULL, - }, - { + _("The key events to cancel preediting or converting. "), + HONOKA_DEFAULT_KEY_CANCEL + )); + page->append(new HonokaSetupGtkKeyItem( + _("Backspace keys:"), HONOKA_CONFIG_KEY_BACKSPACE, - HONOKA_DEFAULT_KEY_BACKSPACE, - N_("Backspace keys:"), - N_("Select backspace keys"), - N_("The key events to delete a character before caret. "), - NULL, - NULL, - }, - { + _("The key events to delete a character before caret. "), + HONOKA_DEFAULT_KEY_BACKSPACE + )); + page->append(new HonokaSetupGtkKeyItem( + _("Delete keys:"), HONOKA_CONFIG_KEY_DELETE, - HONOKA_DEFAULT_KEY_DELETE, - N_("Delete keys:"), - N_("Select delete keys"), - N_("The key events to delete a character after caret. "), - NULL, - NULL, - }, - { - NULL, - "", - NULL, - NULL, - NULL, - NULL, - NULL, - }, -}; + _("The key events to delete a character after caret. "), + HONOKA_DEFAULT_KEY_DELETE + )); + keys->append(page); -static KeyboardConfigData __config_keyboards_caret [] = -{ - { + page = new HonokaSetupGtkPage(_("Preedit keys"),"",""); + page->append(new HonokaSetupGtkKeyItem( + _("Move forward keys:"), HONOKA_CONFIG_KEY_FORWARD, - HONOKA_DEFAULT_KEY_FORWARD, - N_("Move forward keys:"), - N_("Select move caret forward keys"), - N_("The key events to move the caret to forward. "), - NULL, - NULL, - }, - { + _("The key events to move the caret to forward. "), + HONOKA_DEFAULT_KEY_FORWARD + )); + page->append(new HonokaSetupGtkKeyItem( + _("Move backward keys:"), HONOKA_CONFIG_KEY_BACKWARD, - HONOKA_DEFAULT_KEY_BACKWARD, - N_("Move backward keys:"), - N_("Select move caret backward keys"), - N_("The key events to move the caret to backward. "), - NULL, - NULL, - }, - { - NULL, - "", - NULL, - NULL, - NULL, - NULL, - NULL, - }, -}; + _("The key events to move the caret to backward. "), + HONOKA_DEFAULT_KEY_BACKWARD + )); + keys->append(page); -static KeyboardConfigData __config_keyboards_segment [] = -{ - { + page = new HonokaSetupGtkPage(_("Candidates keys"),"",""); + page->append(new HonokaSetupGtkKeyItem( + _("Next segment keys:"), HONOKA_CONFIG_KEY_CONVERSION_FORWARD, - HONOKA_DEFAULT_KEY_CONVERSION_FORWARD, - N_("Next segment keys:"), - N_("Select next segment keys"), - N_("The key events to select next segment. "), - NULL, - NULL, - }, - { + _("The key events to select next segment. "), + HONOKA_DEFAULT_KEY_CONVERSION_FORWARD + )); + page->append(new HonokaSetupGtkKeyItem( + _("Previous segment keys:"), HONOKA_CONFIG_KEY_CONVERSION_BACKWARD, - HONOKA_DEFAULT_KEY_CONVERSION_BACKWARD, - N_("Previous segment keys:"), - N_("Select previous segment keys"), - N_("The key events to select previous segment. "), - NULL, - NULL, - }, - { + _("The key events to select previous segment. "), + HONOKA_DEFAULT_KEY_CONVERSION_BACKWARD + )); + page->append(new HonokaSetupGtkKeyItem( + _("Shrink segment keys:"), HONOKA_CONFIG_KEY_CONVERSION_SHRINK, - HONOKA_DEFAULT_KEY_CONVERSION_SHRINK, - N_("Shrink segment keys:"), - N_("Select shrink segment keys"), - N_("The key events to shrink the selected segment. "), - NULL, - NULL, - }, - { + _("The key events to shrink the selected segment. "), + HONOKA_DEFAULT_KEY_CONVERSION_SHRINK + )); + page->append(new HonokaSetupGtkKeyItem( + _("Expand segment keys:"), HONOKA_CONFIG_KEY_CONVERSION_EXPAND, - HONOKA_DEFAULT_KEY_CONVERSION_EXPAND, - N_("Expand segment keys:"), - N_("Select expand segment keys"), - N_("The key events to expand the selected segment. "), - NULL, - NULL, - }, - { - NULL, - "", - NULL, - NULL, - NULL, - NULL, - NULL, - }, -}; + _("The key events to expand the selected segment. "), + HONOKA_DEFAULT_KEY_CONVERSION_EXPAND + )); + keys->append(page); -static KeyboardConfigData __config_keyboards_candidates [] = -{ - { + page = new HonokaSetupGtkPage(_("Candidates keys"),"",""); + page->append(new HonokaSetupGtkKeyItem( + _("Next keys:"), HONOKA_CONFIG_KEY_CONVERSION_NEXT, - HONOKA_DEFAULT_KEY_CONVERSION_NEXT, - N_("Next keys:"), - N_("Select next candidate keys"), - N_("The key events to select next candidate. "), - NULL, - NULL, - }, - { + _("The key events to select next candidate. "), + HONOKA_DEFAULT_KEY_CONVERSION_NEXT + )); + page->append(new HonokaSetupGtkKeyItem( + _("Previous keys:"), HONOKA_CONFIG_KEY_CONVERSION_PREV, - HONOKA_DEFAULT_KEY_CONVERSION_PREV, - N_("Previous keys:"), - N_("Select previous candidate keys"), - N_("The key events to select previous candidate. "), - NULL, - NULL, - }, - { + _("The key events to select previous candidate. "), + HONOKA_DEFAULT_KEY_CONVERSION_PREV + )); + page->append(new HonokaSetupGtkKeyItem( + _("candidates list keys:"), HONOKA_CONFIG_KEY_LOOKUPPOPUP, - HONOKA_DEFAULT_KEY_LOOKUPPOPUP, - N_("candidates list keys:"), - N_("Select candidates list keys"), - N_("The key events to popup candidates list. "), - NULL, - NULL, - }, - { + _("The key events to popup candidates list. "), + HONOKA_DEFAULT_KEY_LOOKUPPOPUP + )); + page->append(new HonokaSetupGtkKeyItem( + _("Page up keys:"), HONOKA_CONFIG_KEY_LOOKUPPAGEUP, - HONOKA_DEFAULT_KEY_LOOKUPPAGEUP, - N_("Page up keys:"), - N_("Select page up candidates keys"), - N_("The key events to select page up candidates. "), - NULL, - NULL, - }, - { + _("The key events to select page up candidates. "), + HONOKA_DEFAULT_KEY_LOOKUPPAGEUP + )); + page->append(new HonokaSetupGtkKeyItem( + _("Page down keys:"), HONOKA_CONFIG_KEY_LOOKUPPAGEDOWN, - HONOKA_DEFAULT_KEY_LOOKUPPAGEDOWN, - N_("Page down keys:"), - N_("Select page down candidates keys"), - N_("The key events to select page down candidates. "), - NULL, - NULL, - }, - { - NULL, - "", - NULL, - NULL, - NULL, - NULL, - NULL, - }, + _("The key events to select page down candidates. "), + HONOKA_DEFAULT_KEY_LOOKUPPAGEDOWN + )); + keys->append(page); + + setup->append(keys); + + page = new HonokaSetupGtkPage(_("Wnn-plugin"),"",""); + + page->append(new HonokaSetupGtkBoolItem( + _("_Use this plugin: "), + String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-wnn"), + _("if you use this plugin, check this."), + true + )); + + page->append(new HonokaSetupGtkEntryItem( + _("_Server: "), + HONOKA_CONFIG_JSERVER, + _("input the server name to connect."), + HONOKA_DEFAULT_JSERVER + )); + // file + page->append(new HonokaSetupGtkFileItem( + _("_wnnenvrc: "), + HONOKA_CONFIG_WNNENVRC, + _("input the path of wnnenvrc."), + HONOKA_DEFAULT_WNNENVRC + )); + l.clear(); + l.push_back(String("Wnn4")); + l.push_back(String("Wnn6")); + l.push_back(String("Wnn7")); + l.push_back(String("Wnn8")); + page->append(new HonokaSetupGtkSelectItem( + _("Server_type: "), + HONOKA_CONFIG_JSERVERTYPE, + _("select the server type from Wnn4 / Wnn6 / Wnn7."), + HONOKA_DEFAULT_JSERVERTYPE, + l + )); + setup->append(page); + + + page = new HonokaSetupGtkPage(_("Anthy-plugin"),"",""); + + page->append(new HonokaSetupGtkBoolItem( + _("_Use this plugin: "), + String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/plugin-anthy"), + _("if you use this plugin, check this."), + true + )); + setup->append(page); + + page = new HonokaSetupGtkPage(_("Canna-plugin"),"",""); + + page->append(new HonokaSetupGtkBoolItem( + _("_Use this plugin: "), + String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/canna-anthy"), + _("if you use this plugin, check this."), + true + )); + // file + page->append(new HonokaSetupGtkFileItem( + _("_DicHomeDir: "), + HONOKA_CONFIG_CANNA_DICHOMEDIRPATH, + _("set your DicHomeDir in this entry."), + HONOKA_DEFAULT_CANNA_DICHOMEDIRPATH + )); + setup->append(page); + + + page = new HonokaSetupGtkPage(_("SKKDic-plugin"),"",""); + + page->append(new HonokaSetupGtkBoolItem( + _("_Use this plugin: "), + String(HONOKA_CONFIG_PLUGINLOADER_PREFIX) + String("/skkdic-anthy"), + _("if you use this plugin, check this."), + true + )); + // file + page->append(new HonokaSetupGtkFileItem( + _("_SKKDic file: "), + HONOKA_CONFIG_SKKDIC_DICFILE, + _("set SKKDic file in this entry."), + HONOKA_DEFAULT_SKKDIC_DICFILE + )); + setup->append(page); + + + return setup->getValueWidget(); }; -static KeyboardConfigData __config_keyboards_other [] = -{ - { - HONOKA_CONFIG_KEY_AUTO_CONVERSION, - HONOKA_DEFAULT_KEY_AUTO_CONVERSION, - N_("auto conversion mode keys:"), - N_("Select auto conversion mode keys"), - N_("The key events to change auto conversion mode. "), - NULL, - NULL, - }, - { - HONOKA_CONFIG_KEY_SELECT_PREDICTION, - HONOKA_DEFAULT_KEY_SELECT_PREDICTION, - N_("Yosoku keys:"), - N_("Select yosoku keys"), - N_("The key events to select from completion list. "), - NULL, - NULL, - }, - { - HONOKA_CONFIG_KEY_CONVERSION_IKEIJI, - HONOKA_DEFAULT_KEY_CONVERSION_IKEIJI, - N_("Convert to ikeiji keys:"), - N_("Select ikeiji keys"), - N_("The key events to convert the selected candidate to ikei-kanji. "), - NULL, - NULL, - }, - { - HONOKA_CONFIG_KEY_CONVERSION_RENSOU, - HONOKA_DEFAULT_KEY_CONVERSION_RENSOU, - N_("Convert to rensou keys:"), - N_("Select rensou keys"), - N_("The key events to convert the selected candidate to the associated acceptation string. "), - NULL, - NULL, - }, - { - HONOKA_CONFIG_KEY_CONVERT_HIRAGANA, - HONOKA_DEFAULT_KEY_CONVERT_HIRAGANA, - N_("Convert to HIRAGANA keys:"), - N_("Select convert to HIRAGANA keys"), - N_("The key events to convert the selected candidate or the preedit string to HIRAGANA. "), - NULL, - NULL, - }, - { - HONOKA_CONFIG_KEY_CONVERT_KATAKANA, - HONOKA_DEFAULT_KEY_CONVERT_KATAKANA, - N_("Convert to KATAKANA keys:"), - N_("Select convert to KATAGANA keys"), - N_("The key events to convert the selected candidate or the preedit string to KATAKANA. "), - NULL, - NULL, - }, - { - NULL, - "", - NULL, - NULL, - NULL, - NULL, - NULL, - }, -}; - -static struct KeyboardConfigPage __key_conf_pages[] = -{ - {N_("Common keys"), __config_keyboards_common}, - {N_("Preedit keys"), __config_keyboards_caret}, - {N_("Candidates keys"), __config_keyboards_candidates}, - {N_("Other function keys"), __config_keyboards_other}, -}; -static unsigned int __key_conf_pages_num = sizeof (__key_conf_pages) / sizeof (KeyboardConfigPage); - -static void on_default_editable_changed (GtkEditable *editable, - gpointer user_data); -static void on_default_number_changed (GtkEditable *editable, - gpointer user_data); -static void on_default_toggle_button_toggled (GtkToggleButton *togglebutton, - gpointer user_data); -static void on_default_key_selection_clicked (GtkButton *button, - gpointer user_data); -static void on_default_file_selection_button (GtkButton *button, - gpointer user_data); -static void on_default_list_changed (GtkList *list, - GtkWidget *widget, - gpointer user_data); -static void setup_widget_value (void); - - -static GtkWidget * -create_options_page () -{ - GtkWidget *vbox, *table, *label, *button, *button2; - unsigned int i; - GList *list = NULL; - - vbox = gtk_vbox_new (FALSE, 0); - gtk_widget_show (vbox); - - for(i = 0;__list_data[i].label;i ++) { - __list_data[i].widget = gtk_list_item_new_with_label(_(__list_data[i].label)); - gtk_widget_show (__list_data[i].widget); - } - - //__widget_use_kana = gtk_check_button_new_with_mnemonic (_("Use _Kana Table")); - //gtk_widget_show (__widget_use_kana); - //gtk_box_pack_start (GTK_BOX (vbox), __widget_use_kana, FALSE, FALSE, 4); - //gtk_container_set_border_width (GTK_CONTAINER (__widget_use_kana), 4); - - // Connect all signals. - //g_signal_connect ((gpointer) __widget_use_kana, "toggled", - // G_CALLBACK (on_default_toggle_button_toggled), - // &__config_use_kana); - - table = gtk_table_new (3, 6, FALSE); - gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); - gtk_widget_show (table); - - /* server */ - label = gtk_label_new_with_mnemonic (_("_Server: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - __widget_server = gtk_entry_new (); - gtk_widget_show (__widget_server); - gtk_table_attach (GTK_TABLE (table), __widget_server, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_server); - if (!__widget_tooltips) - __widget_tooltips = gtk_tooltips_new(); - gtk_tooltips_set_tip (__widget_tooltips, __widget_server, - _("input the server name to connect."), NULL); - - - /* wnnenvrc */ - label = gtk_label_new_with_mnemonic (_("_wnnenvrc: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - __widget_wnn_rc = gtk_entry_new (); - gtk_widget_show (__widget_wnn_rc); - gtk_table_attach (GTK_TABLE (table), __widget_wnn_rc, 1, 2, 1, 2, - (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_wnn_rc); - - button = gtk_button_new_with_label (_("...")); - gtk_widget_show (button); - gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - //gtk_label_set_mnemonic_widget (GTK_LABEL (label), button); - gtk_tooltips_set_tip (__widget_tooltips, __widget_wnn_rc, - _("input the path of wnnenvrc."), NULL); - - /* servertype */ - label = gtk_label_new_with_mnemonic (_("Server_type: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - list = g_list_append(list,__list_data[0].widget); - list = g_list_append(list,__list_data[1].widget); - list = g_list_append(list,__list_data[2].widget); - list = g_list_append(list,__list_data[3].widget); - __widget_servertype = gtk_list_new (); - gtk_list_append_items(GTK_LIST(__widget_servertype),list); - gtk_widget_show (__widget_servertype); - gtk_table_attach (GTK_TABLE (table), __widget_servertype, 1, 2, 2, 3, - (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __list_data[0].widget); - gtk_tooltips_set_tip (__widget_tooltips, __widget_servertype, - _("select the server type from Wnn4 / Wnn6 / Wnn7."), NULL); - - /* default preeditor */ - label = gtk_label_new_with_mnemonic (_("Default_PreEditor: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - list = NULL; - list = g_list_append(list,__list_data[4].widget); - list = g_list_append(list,__list_data[5].widget); - __widget_preeditor = gtk_list_new (); - gtk_list_append_items(GTK_LIST(__widget_preeditor),list); - gtk_widget_show (__widget_preeditor); - gtk_table_attach (GTK_TABLE (table), __widget_preeditor, 1, 2, 3, 4, - (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __list_data[3].widget); - gtk_tooltips_set_tip (__widget_tooltips, __widget_preeditor, - _("select the default preeditor."), NULL); - - - /* ALP */ - label = gtk_label_new_with_mnemonic (_("_Auto candidates popup: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - GtkAdjustment* aj; - aj = (GtkAdjustment *) gtk_adjustment_new(0,-1,10,1,1,1); - __widget_alp = gtk_spin_button_new(aj,1,0); - gtk_widget_show (__widget_alp); - gtk_table_attach (GTK_TABLE (table), __widget_alp, 1, 2, 4, 5, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_alp); - gtk_tooltips_set_tip (__widget_tooltips, __widget_alp, - _("set the count of conversion until displaying the list of lookup result automatically."), NULL); - - /* numkeyselection */ - label = gtk_label_new_with_mnemonic (_("_NumKey selection: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 5, 6, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - __widget_numkeyselect = gtk_check_button_new(); - gtk_widget_show (__widget_numkeyselect); - gtk_table_attach (GTK_TABLE (table), __widget_numkeyselect, 1, 2, 5, 6, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_numkeyselect); - gtk_tooltips_set_tip (__widget_tooltips, __widget_numkeyselect, - _("If you use the candidate selection by numkey, check this."), NULL); - - /* auto conversion */ - label = gtk_label_new_with_mnemonic (_("Auto _conversion: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 6, 7, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - __widget_autoconversion = gtk_check_button_new(); - gtk_widget_show (__widget_autoconversion); - gtk_table_attach (GTK_TABLE (table), __widget_autoconversion, 1, 2, 6, 7, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_autoconversion); - gtk_tooltips_set_tip (__widget_tooltips, __widget_autoconversion, - _("If you set default to the auto conversion mode use, check this."), NULL); - - - /* completion */ - label = gtk_label_new_with_mnemonic (_("_YOSOKU-input: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 7, 8, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - __widget_yosoku = gtk_check_button_new(); - gtk_widget_show (__widget_yosoku); - gtk_table_attach (GTK_TABLE (table), __widget_yosoku, 1, 2, 7, 8, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_yosoku); - gtk_tooltips_set_tip (__widget_tooltips, __widget_yosoku, - _("if you use YOSOKU-input , check this."), NULL); - - - // romkan_table - label = gtk_label_new_with_mnemonic (_("_Roma-Kana table: ")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 8, 9, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - __widget_romkan_table = gtk_entry_new (); - gtk_widget_show (__widget_romkan_table); - gtk_table_attach (GTK_TABLE (table), __widget_romkan_table, 1, 2, 8, 9, - (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_romkan_table); - - button2 = gtk_button_new_with_label (_("...")); - gtk_widget_show (button2); - gtk_table_attach (GTK_TABLE (table), button2, 2, 3, 8, 9, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_tooltips_set_tip (__widget_tooltips, __widget_romkan_table, - _("input the path of Roma-Kana convert table file."), NULL); - - - - /* connect all signals */ - g_signal_connect ((gpointer) __widget_server, "changed", - G_CALLBACK (on_default_editable_changed), - &__config_server); - g_signal_connect ((gpointer) __widget_wnn_rc, "changed", - G_CALLBACK (on_default_editable_changed), - &__config_wnn_rc); - g_signal_connect ((gpointer) button, "clicked", - G_CALLBACK (on_default_file_selection_button), - __widget_wnn_rc); - g_signal_connect ((gpointer) __widget_servertype, "select-child", - G_CALLBACK (on_default_list_changed), - &__config_servertype); - g_signal_connect ((gpointer) __widget_preeditor, "select-child", - G_CALLBACK (on_default_list_changed), - &__config_preeditor); - g_signal_connect ((gpointer) __widget_alp, "changed", - G_CALLBACK (on_default_number_changed), - &__config_alp); - g_signal_connect ((gpointer) __widget_numkeyselect, "toggled", - G_CALLBACK (on_default_toggle_button_toggled), - &__config_numkeyselect); - g_signal_connect ((gpointer) __widget_autoconversion, "toggled", - G_CALLBACK (on_default_toggle_button_toggled), - &__config_autoconversion); - g_signal_connect ((gpointer) __widget_yosoku, "toggled", - G_CALLBACK (on_default_toggle_button_toggled), - &__config_yosoku); - g_signal_connect ((gpointer) __widget_romkan_table, "changed", - G_CALLBACK (on_default_editable_changed), - &__config_romkan_table); - g_signal_connect ((gpointer) button2, "clicked", - G_CALLBACK (on_default_file_selection_button), - __widget_romkan_table); - - return vbox; -} - -static GtkWidget * -create_keyboard_page (unsigned int page) -{ - GtkWidget *table; - GtkWidget *label; - - if (page >= __key_conf_pages_num) - return NULL; - - KeyboardConfigData *data = __key_conf_pages[page].data; - - table = gtk_table_new (3, 3, FALSE); - gtk_widget_show (table); - - // Create keyboard setting. - for (unsigned int i = 0; data[i].key; ++ i) { - label = gtk_label_new (NULL); - gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _(data[i].label)); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_misc_set_padding (GTK_MISC (label), 4, 0); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, i, i+1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - - data[i].entry = gtk_entry_new (); - gtk_widget_show (data[i].entry); - gtk_table_attach (GTK_TABLE (table), data[i].entry, 1, 2, i, i+1, - (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_entry_set_editable (GTK_ENTRY (data[i].entry), FALSE); - - data[i].button = gtk_button_new_with_label (_("...")); - gtk_widget_show (data[i].button); - gtk_table_attach (GTK_TABLE (table), data[i].button, 2, 3, i, i+1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), data[i].button); - } - - for (unsigned int i = 0; data[i].key; ++ i) { - g_signal_connect ((gpointer) data[i].button, "clicked", - G_CALLBACK (on_default_key_selection_clicked), - &(data[i])); - g_signal_connect ((gpointer) data[i].entry, "changed", - G_CALLBACK (on_default_editable_changed), - &(data[i].data)); - } - - if (!__widget_tooltips) - __widget_tooltips = gtk_tooltips_new(); - for (unsigned int i = 0; data[i].key; ++ i) { - gtk_tooltips_set_tip (__widget_tooltips, data[i].entry, - _(data[i].tooltip), NULL); - } - - return table; -} - -static GtkWidget * -create_setup_window () -{ - static GtkWidget *window = NULL; - - if (!window) { - GtkWidget *notebook = gtk_notebook_new(); - gtk_widget_show (notebook); - window = notebook; - gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); - - // Create the first page. - GtkWidget *page = create_options_page (); - GtkWidget *label = gtk_label_new (_("Options")); - gtk_widget_show (label); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label); - - setup_widget_value (); - - // Create the second page. - for (unsigned int i = 0; i < __key_conf_pages_num; i++) { - page = create_keyboard_page (i); - label = gtk_label_new (_(__key_conf_pages[i].label)); - gtk_widget_show (label); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label); - } - - setup_widget_value (); - } - - return window; -} - -static void -setup_widget_value (void) -{ -// if (__widget_use_kana) { -// gtk_toggle_button_set_active ( -// GTK_TOGGLE_BUTTON (__widget_use_kana), -// __config_use_kana); -// } - if (__widget_server) { - gtk_entry_set_text ( - GTK_ENTRY (__widget_server), - __config_server.c_str ()); - } - - if (__widget_wnn_rc) { - gtk_entry_set_text ( - GTK_ENTRY (__widget_wnn_rc), - __config_wnn_rc.c_str ()); - } - - if (__widget_servertype) { - for(unsigned int i = 0;__list_data[i].widget;i ++) { - if (__list_data[i].name == __config_servertype) { - gtk_list_select_child(GTK_LIST(__widget_servertype),__list_data[i].widget); - break; - } - } - } - - if (__widget_preeditor) { - for(unsigned int i = 0;__list_data[i].widget;i ++) { - if (__list_data[i].name == __config_preeditor) { - gtk_list_select_child(GTK_LIST(__widget_preeditor),__list_data[i].widget); - break; - } - } - } - - if (__widget_alp) { - gtk_spin_button_set_value ( - GTK_SPIN_BUTTON (__widget_alp), - __config_alp); - } - - if (__widget_numkeyselect) { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (__widget_numkeyselect), - __config_numkeyselect); - } - - if (__widget_autoconversion) { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (__widget_autoconversion), - __config_autoconversion); - } - - if (__widget_yosoku) { - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (__widget_yosoku), - __config_yosoku); - } - - if (__widget_romkan_table) { - gtk_entry_set_text ( - GTK_ENTRY (__widget_romkan_table), - __config_romkan_table.c_str ()); - } - - for (unsigned int j = 0; j < __key_conf_pages_num; ++ j) { - for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) { - if (__key_conf_pages[j].data[i].entry) { - gtk_entry_set_text ( - GTK_ENTRY (__key_conf_pages[j].data[i].entry), - __key_conf_pages[j].data[i].data.c_str ()); - } - } - } -} - static void load_config (const ConfigPointer &config) { - if (!config.null ()) { - // __config_use_kana = - // config->read (String (SCIM_CONFIG_IMENGINE_ANTHY_USE_KANA), - // __config_use_kana); - __config_server = - config->read (String (HONOKA_CONFIG_JSERVER), - __config_server); - __config_wnn_rc = - config->read (String (HONOKA_CONFIG_WNNENVRC), - __config_wnn_rc); - __config_servertype = - config->read (String (HONOKA_CONFIG_JSERVERTYPE), - __config_servertype); - __config_preeditor = - config->read (String (HONOKA_CONFIG_DEFAULT_PREEDITOR), - __config_preeditor); - __config_alp = - config->read (String (HONOKA_CONFIG_ALP), - __config_alp); - __config_numkeyselect = - config->read (String (HONOKA_CONFIG_NUMKEY_SELECT), - __config_numkeyselect); - __config_autoconversion = - config->read (String (HONOKA_CONFIG_AUTO_CONVERSION), - __config_autoconversion); - __config_yosoku = - config->read (String (HONOKA_CONFIG_WNNYOSOKU), - __config_yosoku); - __config_romkan_table = - config->read (String (HONOKA_CONFIG_ROMKAN_TABLE_FILE), - __config_romkan_table); - - for (unsigned int j = 0; j < __key_conf_pages_num; j++) { - for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) { - __key_conf_pages[j].data[i].data = - config->read (String (__key_conf_pages[j].data[i].key), - __key_conf_pages[j].data[i].data); - } - } - - setup_widget_value (); - - __have_changed = false; + if (!config.null()) { + setup->readConfig(config); + HonokaSetupGtk::changed = false; } } static void save_config (const ConfigPointer &config) { - if (!config.null ()) { - // config->write (String (SCIM_CONFIG_IMENGINE_ANTHY_USE_KANA), - // __config_use_kana); - config->write (String (HONOKA_CONFIG_JSERVER), - __config_server); - config->write (String (HONOKA_CONFIG_WNNENVRC), - __config_wnn_rc); - config->write (String (HONOKA_CONFIG_JSERVERTYPE), - __config_servertype); - config->write (String (HONOKA_CONFIG_DEFAULT_PREEDITOR), - __config_preeditor); - config->write (String (HONOKA_CONFIG_ALP), - __config_alp); - config->write (String (HONOKA_CONFIG_NUMKEY_SELECT), - __config_numkeyselect); - config->write (String (HONOKA_CONFIG_AUTO_CONVERSION), - __config_autoconversion); - config->write (String (HONOKA_CONFIG_WNNYOSOKU), - __config_yosoku); - config->write (String (HONOKA_CONFIG_ROMKAN_TABLE_FILE), - __config_romkan_table); - - for (unsigned j = 0; j < __key_conf_pages_num; j++) { - for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) { - config->write (String (__key_conf_pages[j].data[i].key), - __key_conf_pages[j].data[i].data); - } - } - - __have_changed = false; + if (!config.null()) { + setup->saveConfig(config); + HonokaSetupGtk::changed = false; } } static bool query_changed () { - return __have_changed; + return HonokaSetupGtk::changed; } -static void -on_default_toggle_button_toggled (GtkToggleButton *togglebutton, - gpointer user_data) -{ - bool *toggle = static_cast (user_data); - - if (toggle) { - *toggle = gtk_toggle_button_get_active (togglebutton); - __have_changed = true; - } -} - -static void -on_default_editable_changed (GtkEditable *editable, - gpointer user_data) -{ - String *str = static_cast (user_data); - - if (str) { - *str = String (gtk_entry_get_text (GTK_ENTRY (editable))); - __have_changed = true; - } -} - -static void -on_default_number_changed (GtkEditable *editable, - gpointer user_data) -{ - int *num = static_cast (user_data); - - if (num) { - *num = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (editable)); - __have_changed = true; - } -} - -static void -on_default_list_changed (GtkList *list, - GtkWidget *widget, - gpointer user_data) -{ - String *str = static_cast (user_data); - - if (str) { - for(unsigned int i = 0;__list_data[i].widget;i ++) { - if (__list_data[i].widget == widget) - *str = __list_data[i].name; - } - __have_changed = true; - } -} - -static void -on_default_key_selection_clicked (GtkButton *button, - gpointer user_data) -{ - KeyboardConfigData *data = static_cast (user_data); - - if (data) { - GtkWidget *dialog = scim_key_selection_dialog_new (_(data->title)); - gint result; - - scim_key_selection_dialog_set_keys ( - SCIM_KEY_SELECTION_DIALOG (dialog), - gtk_entry_get_text (GTK_ENTRY (data->entry))); - - result = gtk_dialog_run (GTK_DIALOG (dialog)); - - if (result == GTK_RESPONSE_OK) { - const gchar *keys = scim_key_selection_dialog_get_keys ( - SCIM_KEY_SELECTION_DIALOG (dialog)); - - if (!keys) keys = ""; - - if (strcmp (keys, gtk_entry_get_text (GTK_ENTRY (data->entry))) != 0) - gtk_entry_set_text (GTK_ENTRY (data->entry), keys); - } - - gtk_widget_destroy (dialog); - } -} - -static void -on_ok_clicked (GtkButton *button, gpointer user_data) -{ - bool *ok = static_cast(user_data); - if (ok) - *ok = true; -} - -static void -on_default_file_selection_button (GtkButton *button, gpointer user_data) -{ - GtkEntry *entry = GTK_ENTRY (user_data); - const char *path = gtk_entry_get_text (entry); - bool ok = false; - - GtkFileSelection *sel = GTK_FILE_SELECTION (gtk_file_selection_new ("Select a file")); - gtk_file_selection_set_filename (sel, path); - g_signal_connect (G_OBJECT (sel->ok_button), "clicked", - G_CALLBACK (on_ok_clicked), - (gpointer) &ok); - gtk_window_set_transient_for ( - GTK_WINDOW (sel), - GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET (entry)))); - gtk_dialog_run (GTK_DIALOG (sel)); - - if (ok) - gtk_entry_set_text (entry, gtk_file_selection_get_filename (sel)); - - gtk_widget_destroy (GTK_WIDGET (sel)); -} diff --git a/honoka/src/honokasetupgtk.cpp b/honoka/src/honokasetupgtk.cpp new file mode 100644 index 0000000..703b419 --- /dev/null +++ b/honoka/src/honokasetupgtk.cpp @@ -0,0 +1,568 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "honokasetupgtk.h" + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include +#include "honoka_def.h" +#include "../plugins/honoka_plugin_def.h" + +#ifdef HAVE_GETTEXT + #include + #define _(String) dgettext(GETTEXT_PACKAGE,String) + #define N_(String) (String) +#else + #define _(String) (String) + #define N_(String) (String) + #define bindtextdomain(Package,Directory) + #define textdomain(domain) + #define bind_textdomain_codeset(domain,codeset) +#endif + +GtkTooltips * HonokaSetupGtkItem::tipWidget = 0; +bool HonokaSetupGtkItem::changed = false; + +HonokaSetupGtkItem::HonokaSetupGtkItem(String _label,String _name,String _tip) +{ + label = _label; + name = _name; + tip = _tip; + + valueWidget = 0; + labelWidget = 0; + if (!tipWidget) tipWidget = gtk_tooltips_new(); +}; + +HonokaSetupGtkItem::~HonokaSetupGtkItem() +{ +}; + +GtkWidget *HonokaSetupGtkItem::getValueWidget() +{ + if (!valueWidget) { + createValueWidget(); + createTipWidget(); + } + return valueWidget; +}; + +GtkWidget *HonokaSetupGtkItem::getLabelWidget() +{ + if (!labelWidget) createLabelWidget(); + return labelWidget; +}; + +void HonokaSetupGtkItem::createLabelWidget() +{ + labelWidget = gtk_label_new_with_mnemonic(label.c_str()); + gtk_misc_set_alignment(GTK_MISC(labelWidget),1.0,0.5); + gtk_misc_set_padding(GTK_MISC(labelWidget),4,0); + gtk_widget_show(labelWidget); +} + +void HonokaSetupGtkItem::createValueWidget() +{ + valueWidget = gtk_label_new_with_mnemonic("."); + gtk_misc_set_alignment(GTK_MISC(valueWidget),1.0,0.5); + gtk_misc_set_padding(GTK_MISC(valueWidget),4,0); + gtk_widget_show(valueWidget); +}; + +void HonokaSetupGtkItem::createTipWidget() +{ + if (!valueWidget) createValueWidget(); + gtk_tooltips_set_tip(tipWidget,valueWidget,tip.c_str(),NULL); +}; + +void HonokaSetupGtkItem::readConfig(ConfigPointer cfg) +{ + return; +} + +void HonokaSetupGtkItem::saveConfig(ConfigPointer cfg) +{ + return; +} + + +// +// EntryItem +// + +HonokaSetupGtkEntryItem::HonokaSetupGtkEntryItem(String _label,String _name,String _tip,String _default) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + stringData = _default; +}; + +HonokaSetupGtkEntryItem::~HonokaSetupGtkEntryItem() +{ +}; + +void HonokaSetupGtkEntryItem::createValueWidget() +{ + valueWidget = gtk_entry_new(); + gtk_label_set_mnemonic_widget(GTK_LABEL(getLabelWidget()),valueWidget); + g_signal_connect((gpointer)valueWidget,"changed",G_CALLBACK(onEditableChanged),this); + gtk_widget_show(valueWidget); +}; + +void HonokaSetupGtkEntryItem::readConfig(ConfigPointer cfg) +{ + stringData = cfg->read(name,stringData); + gtk_entry_set_text(GTK_ENTRY(getValueWidget()),stringData.c_str()); + return; +} + +void HonokaSetupGtkEntryItem::saveConfig(ConfigPointer cfg) +{ + cfg->write(name,stringData); + return; +} + +void HonokaSetupGtkEntryItem::onEditableChanged(GtkEditable *widget,gpointer self) +{ + HonokaSetupGtkEntryItem *s = static_cast(self); + String str = String(gtk_entry_get_text(GTK_ENTRY(widget))); + if (s->stringData != str) { + s->stringData = str; + changed = true; + } +}; + +// +// KeyItem +// + +HonokaSetupGtkKeyItem::HonokaSetupGtkKeyItem(String _label,String _name,String _tip,String _default) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + stringData = _default; +}; + +HonokaSetupGtkKeyItem::~HonokaSetupGtkKeyItem() +{ +}; + +void HonokaSetupGtkKeyItem::createValueWidget() +{ + valueWidget = gtk_hbox_new(false,5); + entry = gtk_entry_new(); + gtk_entry_set_editable(GTK_ENTRY(entry),FALSE); + button = gtk_button_new_with_label("..."); + gtk_box_pack_start(GTK_BOX(valueWidget),entry,true,true,0); + gtk_box_pack_end(GTK_BOX(valueWidget),button,false,false,0); + gtk_label_set_mnemonic_widget(GTK_LABEL(getLabelWidget()),entry); + g_signal_connect((gpointer)entry,"changed",G_CALLBACK(onEditableChanged),this); + g_signal_connect((gpointer)button,"clicked",G_CALLBACK(onSelectButtonClicked),this); + gtk_widget_show(entry); + gtk_widget_show(button); + gtk_widget_show(valueWidget); +}; + +void HonokaSetupGtkKeyItem::createTipWidget() +{ + if (!valueWidget) createValueWidget(); + gtk_tooltips_set_tip(tipWidget,entry,tip.c_str(),NULL); + gtk_tooltips_set_tip(tipWidget,button,tip.c_str(),NULL); +}; + +void HonokaSetupGtkKeyItem::readConfig(ConfigPointer cfg) +{ + stringData = cfg->read(name,stringData); + gtk_entry_set_text(GTK_ENTRY(entry),stringData.c_str()); + return; +} + +void HonokaSetupGtkKeyItem::saveConfig(ConfigPointer cfg) +{ + cfg->write(name,stringData); + return; +} + +void HonokaSetupGtkKeyItem::onEditableChanged(GtkEditable *widget,gpointer self) +{ + HonokaSetupGtkKeyItem *s = static_cast(self); + String str = String(gtk_entry_get_text(GTK_ENTRY(widget))); + if (s->stringData != str) { + s->stringData = str; + changed = true; + } +}; + +void HonokaSetupGtkKeyItem::onSelectButtonClicked(GtkEditable *widget,gpointer self) +{ + HonokaSetupGtkKeyItem *s = static_cast(self); + if (s) { + GtkWidget *dialog = scim_key_selection_dialog_new(s->label.c_str()); + scim_key_selection_dialog_set_keys(SCIM_KEY_SELECTION_DIALOG(dialog),gtk_entry_get_text(GTK_ENTRY(s->entry))); + gint result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_OK) { + const gchar *keys = scim_key_selection_dialog_get_keys(SCIM_KEY_SELECTION_DIALOG(dialog)); + if (!keys) keys = ""; + if (strcmp(keys,gtk_entry_get_text(GTK_ENTRY(s->entry))) != 0) + gtk_entry_set_text(GTK_ENTRY(s->entry),keys); + } + gtk_widget_destroy (dialog); + changed = true; + } +}; + +// +// file +// +HonokaSetupGtkFileItem::HonokaSetupGtkFileItem(String _label,String _name,String _tip,String _default) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + stringData = _default; +}; + +HonokaSetupGtkFileItem::~HonokaSetupGtkFileItem() +{ +}; + +void HonokaSetupGtkFileItem::createValueWidget() +{ + valueWidget = gtk_hbox_new(false,5); + entry = gtk_entry_new(); + button = gtk_button_new_with_label("..."); + gtk_box_pack_start(GTK_BOX(valueWidget),entry,true,true,0); + gtk_box_pack_end(GTK_BOX(valueWidget),button,false,false,0); + gtk_label_set_mnemonic_widget(GTK_LABEL(getLabelWidget()),entry); + g_signal_connect((gpointer)entry,"changed",G_CALLBACK(onEditableChanged),this); + g_signal_connect((gpointer)button,"clicked",G_CALLBACK(onSelectButtonClicked),this); + gtk_widget_show(entry); + gtk_widget_show(button); + gtk_widget_show(valueWidget); +}; + +void HonokaSetupGtkFileItem::createTipWidget() +{ + if (!valueWidget) createValueWidget(); + gtk_tooltips_set_tip(tipWidget,entry,tip.c_str(),NULL); + gtk_tooltips_set_tip(tipWidget,button,tip.c_str(),NULL); +}; + +void HonokaSetupGtkFileItem::readConfig(ConfigPointer cfg) +{ + stringData = cfg->read(name,stringData); + gtk_entry_set_text(GTK_ENTRY(entry),stringData.c_str()); + return; +} + +void HonokaSetupGtkFileItem::saveConfig(ConfigPointer cfg) +{ + cfg->write(name,stringData); + return; +} + +void HonokaSetupGtkFileItem::onOkButtonClicked(GtkButton *widget,gpointer ok) +{ + bool *_ok = static_cast(ok); + if (_ok) *_ok = true; +}; + +void HonokaSetupGtkFileItem::onEditableChanged(GtkEditable *widget,gpointer self) +{ + HonokaSetupGtkFileItem *s = static_cast(self); + String str = String(gtk_entry_get_text(GTK_ENTRY(widget))); + if (s->stringData != str) { + s->stringData = str; + changed = true; + } +}; + +void HonokaSetupGtkFileItem::onSelectButtonClicked(GtkEditable *widget,gpointer self) +{ + HonokaSetupGtkFileItem *s = static_cast(self); + bool ok = false; + const char *path = gtk_entry_get_text(GTK_ENTRY(s->entry)); + if (s) { + GtkFileSelection *dialog = GTK_FILE_SELECTION(gtk_file_selection_new("Select a file")); + gtk_file_selection_set_filename(dialog,path); + g_signal_connect (G_OBJECT(dialog->ok_button),"clicked",G_CALLBACK(onOkButtonClicked),(gpointer)&ok); + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(s->entry)))); + gtk_dialog_run(GTK_DIALOG (dialog)); + if (ok) { + gtk_entry_set_text(GTK_ENTRY(s->entry),gtk_file_selection_get_filename(dialog)); + changed = true; + } + gtk_widget_destroy (GTK_WIDGET (dialog)); + } +}; + + +// +// bool +// + +HonokaSetupGtkBoolItem::HonokaSetupGtkBoolItem(String _label,String _name,String _tip,bool _default) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + boolData = _default; +}; + +HonokaSetupGtkBoolItem::~HonokaSetupGtkBoolItem() +{ +}; + +void HonokaSetupGtkBoolItem::createValueWidget() +{ + valueWidget = gtk_check_button_new(); + gtk_label_set_mnemonic_widget(GTK_LABEL(getLabelWidget()),valueWidget); + g_signal_connect((gpointer)valueWidget,"toggled",G_CALLBACK(onToggleButtonToggled),this); + gtk_widget_show(valueWidget); +}; + +void HonokaSetupGtkBoolItem::readConfig(ConfigPointer cfg) +{ + boolData = cfg->read(name,boolData); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(getValueWidget()),boolData); + return; +} + +void HonokaSetupGtkBoolItem::saveConfig(ConfigPointer cfg) +{ + cfg->write(name,boolData); + return; +} + +void HonokaSetupGtkBoolItem::onToggleButtonToggled(GtkEditable *widget,gpointer self) +{ + HonokaSetupGtkBoolItem *s = static_cast(self); + if (s) { + s->boolData = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s->valueWidget)); + changed = true; + } +}; + +// +// Int +// + +HonokaSetupGtkIntItem::HonokaSetupGtkIntItem(String _label,String _name,String _tip,int _default,int lower,int upper) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + intData = _default; + aj = (GtkAdjustment *) gtk_adjustment_new(_default,lower,upper,1,1,1); +}; + +HonokaSetupGtkIntItem::~HonokaSetupGtkIntItem() +{ +}; + +void HonokaSetupGtkIntItem::createValueWidget() +{ + valueWidget = gtk_spin_button_new(aj,1,0); + gtk_label_set_mnemonic_widget(GTK_LABEL(getLabelWidget()),valueWidget); + g_signal_connect((gpointer)valueWidget,"changed",G_CALLBACK(onValueChanged),this); + gtk_widget_show(valueWidget); +}; + +void HonokaSetupGtkIntItem::readConfig(ConfigPointer cfg) +{ + intData = cfg->read(name,intData); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(getValueWidget()),intData); + return; +} + +void HonokaSetupGtkIntItem::saveConfig(ConfigPointer cfg) +{ + cfg->write(name,intData); + return; +} + +void HonokaSetupGtkIntItem::onValueChanged(GtkSpinButton *widget,gpointer self) +{ + HonokaSetupGtkIntItem *s = static_cast(self); + if (s) { + s->intData = gtk_spin_button_get_value_as_int(widget); + changed = true; + } +}; + + +// +// Select +// + +HonokaSetupGtkSelectItem::HonokaSetupGtkSelectItem(String _label,String _name,String _tip,String _default,vector _list) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + stringData = _default; + stringListData = _list; +}; + + +HonokaSetupGtkSelectItem::~HonokaSetupGtkSelectItem() +{ +}; + +void HonokaSetupGtkSelectItem::createValueWidget() +{ + valueWidget = gtk_option_menu_new(); + menu = gtk_menu_new(); + gtk_option_menu_set_menu(GTK_OPTION_MENU(valueWidget),menu); + for(unsigned int i = 0;i < stringListData.size();i ++) { + GtkWidget *menuitem = gtk_menu_item_new_with_label(stringListData[i].c_str()); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),menuitem); + gtk_widget_show(menuitem); + } + gtk_label_set_mnemonic_widget(GTK_LABEL(getLabelWidget()),valueWidget); + gtk_option_menu_set_history(GTK_OPTION_MENU(valueWidget),0); + g_signal_connect((gpointer)valueWidget,"changed",G_CALLBACK(onSelected),this); + gtk_widget_show(valueWidget); + gtk_widget_show(menu); +}; + +void HonokaSetupGtkSelectItem::readConfig(ConfigPointer cfg) +{ + stringData = cfg->read(name,stringData); + for(unsigned int i = 0;i < stringListData.size();i ++) { + if (stringData == stringListData[i]) { + gtk_option_menu_set_history(GTK_OPTION_MENU(valueWidget),i); + break; + } + } + return; +} + +void HonokaSetupGtkSelectItem::saveConfig(ConfigPointer cfg) +{ + cfg->write(name,stringData); + return; +} + +void HonokaSetupGtkSelectItem::onSelected(GtkOptionMenu *widget,gpointer self) +{ + HonokaSetupGtkSelectItem *s = static_cast(self); + if (s) { + String c = s->stringListData[gtk_option_menu_get_history(widget)]; + if (s->stringData != c) { + s->stringData = c; + changed = true; + } + } +}; + + + +// +// Page +// + +HonokaSetupGtkPage::HonokaSetupGtkPage(String _label,String _name,String _tip) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + valueWidget = gtk_vbox_new(FALSE, 0); + gtk_widget_show(valueWidget); + + table = gtk_table_new(3,1,FALSE); + gtk_box_pack_start(GTK_BOX(valueWidget),table,FALSE,FALSE,0); + gtk_widget_show(table); +}; + +void HonokaSetupGtkPage::append(HonokaSetupGtkItem *item) +{ + items.push_back(item); + gtk_misc_set_alignment(GTK_MISC(item->getLabelWidget()),1.0,0.5); + gtk_misc_set_padding(GTK_MISC(item->getLabelWidget()),4,0); + if (dynamic_cast(item) != 0) { + gtk_table_attach(GTK_TABLE(table),item->getValueWidget(),0,2,items.size() - 1,items.size(), + (GtkAttachOptions)(GTK_FILL|GTK_EXPAND),(GtkAttachOptions)(GTK_FILL),4,4); + } else { + gtk_table_attach(GTK_TABLE(table),item->getLabelWidget(),0,1,items.size() - 1,items.size(), + (GtkAttachOptions)(GTK_FILL),(GtkAttachOptions)(GTK_FILL),4,4); + gtk_table_attach(GTK_TABLE(table),item->getValueWidget(),1,2,items.size() - 1,items.size(), + (GtkAttachOptions)(GTK_FILL|GTK_EXPAND),(GtkAttachOptions)(GTK_FILL),4,4); + } +}; + +void HonokaSetupGtkPage::readConfig(ConfigPointer cfg) +{ + for(unsigned int i = 0;i < items.size();i ++) { + items[i]->readConfig(cfg); + } + return; +} + +void HonokaSetupGtkPage::saveConfig(ConfigPointer cfg) +{ + for(unsigned int i = 0;i < items.size();i ++) { + items[i]->saveConfig(cfg); + } + return; +} + + +// + + +HonokaSetupGtk::HonokaSetupGtk(String _label,String _name,String _tip) +: HonokaSetupGtkItem(_label,_name,_tip) +{ + valueWidget = gtk_notebook_new(); + gtk_widget_show(valueWidget); + gtk_notebook_set_scrollable(GTK_NOTEBOOK(valueWidget),TRUE); + +} + + +HonokaSetupGtk::~HonokaSetupGtk() +{ +} + +void HonokaSetupGtk::append(HonokaSetupGtkItem *page) +{ + pages.push_back(page); + + gtk_widget_show(page->getLabelWidget()); + gtk_notebook_append_page(GTK_NOTEBOOK(valueWidget),page->getValueWidget(),page->getLabelWidget()); + if (dynamic_cast(page) != 0) gtk_notebook_set_tab_pos(GTK_NOTEBOOK(page->getValueWidget()),GTK_POS_LEFT); +}; + +void HonokaSetupGtk::readConfig(ConfigPointer cfg) +{ + for(unsigned int i = 0;i < pages.size();i ++) { + pages[i]->readConfig(cfg); + } + return; +} + +void HonokaSetupGtk::saveConfig(ConfigPointer cfg) +{ + for(unsigned int i = 0;i < pages.size();i ++) { + pages[i]->saveConfig(cfg); + } + return; +} + +HonokaSetupGtkItem * HonokaSetupGtk::getLastItem() { + if (!pages.size()) return 0; + return pages[pages.size() - 1]; +}; + + + diff --git a/honoka/src/honokasetupgtk.h b/honoka/src/honokasetupgtk.h new file mode 100644 index 0000000..b9bce16 --- /dev/null +++ b/honoka/src/honokasetupgtk.h @@ -0,0 +1,174 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef HONOKASETUPGTK_H +#define HONOKASETUPGTK_H + +#define Uses_SCIM_CONFIG_BASE + +#include +#include +#include +#include +#include +#include + + +using namespace scim; +using namespace std; + + +/** +@author TAM (Teppei Tamra) +*/ +class HonokaSetupGtkItem { +public: + GtkWidget *getValueWidget(); + GtkWidget *getLabelWidget(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); + static bool changed; +protected: + virtual void createLabelWidget(); + virtual void createValueWidget(); + virtual void createTipWidget(); + HonokaSetupGtkItem(String _label,String _name,String _tip); + ~HonokaSetupGtkItem(); + void createWidgets(); + String label; + String name; + String tip; + GtkWidget *valueWidget; + GtkWidget *labelWidget; + static GtkTooltips *tipWidget; +}; + +class HonokaSetupGtkEntryItem : public HonokaSetupGtkItem { +public: + HonokaSetupGtkEntryItem(String _label,String _name,String _tip,String _default); + ~HonokaSetupGtkEntryItem(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + virtual void createValueWidget(); + static void onEditableChanged(GtkEditable *widget,gpointer self); + String stringData; +}; + +class HonokaSetupGtkKeyItem : public HonokaSetupGtkItem { +public: + HonokaSetupGtkKeyItem(String _label,String _name,String _tip,String _default); + ~HonokaSetupGtkKeyItem(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + virtual void createValueWidget(); + virtual void createTipWidget(); + static void onEditableChanged(GtkEditable *widget,gpointer self); + static void onSelectButtonClicked(GtkEditable *widget,gpointer self); + String stringData; + GtkWidget *entry; + GtkWidget *button; +}; + +class HonokaSetupGtkFileItem : public HonokaSetupGtkItem { +public: + HonokaSetupGtkFileItem(String _label,String _name,String _tip,String _default); + ~HonokaSetupGtkFileItem(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + virtual void createValueWidget(); + virtual void createTipWidget(); + static void onEditableChanged(GtkEditable *widget,gpointer self); + static void onSelectButtonClicked(GtkEditable *widget,gpointer self); + static void onOkButtonClicked(GtkButton *widget,gpointer ok); + String stringData; + GtkWidget *entry; + GtkWidget *button; +}; + +class HonokaSetupGtkBoolItem : public HonokaSetupGtkItem { +public: + HonokaSetupGtkBoolItem(String _label,String _name,String _tip,bool _default); + ~HonokaSetupGtkBoolItem(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + virtual void createValueWidget(); + static void onToggleButtonToggled(GtkEditable *widget,gpointer self); + bool boolData; +}; + +class HonokaSetupGtkIntItem : public HonokaSetupGtkItem { +public: + HonokaSetupGtkIntItem(String _label,String _name,String _tip,int _default,int lower,int upper); + ~HonokaSetupGtkIntItem(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + virtual void createValueWidget(); + static void onValueChanged(GtkSpinButton *widget,gpointer self); + int intData; + GtkAdjustment* aj; +}; + +class HonokaSetupGtkSelectItem : public HonokaSetupGtkItem { +public: + HonokaSetupGtkSelectItem(String _label,String _name,String _tip,String _default,vector _list); + ~HonokaSetupGtkSelectItem(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + virtual void createValueWidget(); + static void onSelected(GtkOptionMenu *widget,gpointer self); + GtkWidget *menu; + vector stringListData; + String stringData; +}; + + +class HonokaSetupGtkPage: public HonokaSetupGtkItem { +public: + HonokaSetupGtkPage(String _label,String _name,String _tip); + ~HonokaSetupGtkPage(); + void append(HonokaSetupGtkItem *item); + String getLabel(); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); +protected: + vector items; + GtkWidget *table; +}; + + +class HonokaSetupGtk: public HonokaSetupGtkItem { +public: + HonokaSetupGtk(String _label,String _name,String _tip); + ~HonokaSetupGtk(); + void append(HonokaSetupGtkItem *page); + virtual void readConfig(ConfigPointer cfg); + virtual void saveConfig(ConfigPointer cfg); + HonokaSetupGtkItem * getLastItem(); +protected: + vector pages; +}; + +#endif