/** @file scim_chewing_imengine_setup.cpp
* implementation of SetupUI Module of chewing imengine module.
*/
/*
* SCIM-chewing -
* Intelligent Chinese Phonetic IM Engine for SCIM.
*
* Copyright (c) 2005, 2006
* SCIM-chewing Developers. See ChangeLog for details.
*
* See the file "COPYING" for information on usage and redistribution
* of this file.
*/
#define Uses_SCIM_CONFIG_BASE
#include <gtk/gtk.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_GETTEXT
#include <libintl.h>
#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
#include <scim.h>
#include <gtk/scimkeyselection.h>
#include "scim_chewing_config_entry.h"
#include "scim_color_button.h"
using namespace scim;
#define scim_module_init chewing_imengine_setup_LTX_scim_module_init
#define scim_module_exit chewing_imengine_setup_LTX_scim_module_exit
#define scim_setup_module_create_ui chewing_imengine_setup_LTX_scim_setup_module_create_ui
#define scim_setup_module_get_category chewing_imengine_setup_LTX_scim_setup_module_get_category
#define scim_setup_module_get_name chewing_imengine_setup_LTX_scim_setup_module_get_name
#define scim_setup_module_get_description chewing_imengine_setup_LTX_scim_setup_module_get_description
#define scim_setup_module_load_config chewing_imengine_setup_LTX_scim_setup_module_load_config
#define scim_setup_module_save_config chewing_imengine_setup_LTX_scim_setup_module_save_config
#define scim_setup_module_query_changed chewing_imengine_setup_LTX_scim_setup_module_query_changed
static GtkWidget * create_setup_window();
static void load_config( const ConfigPointer &config );
static void save_config( const ConfigPointer &config );
static bool query_changed();
// Module Interface.
extern "C" {
void scim_module_init()
{
bindtextdomain( GETTEXT_PACKAGE, SCIM_CHEWING_LOCALEDIR );
bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
}
void scim_module_exit()
{
}
GtkWidget * scim_setup_module_create_ui()
{
return create_setup_window();
}
String scim_setup_module_get_category()
{
return String( "IMEngine" );
}
String scim_setup_module_get_name()
{
return String( _( "Chewing" ) );
}
String scim_setup_module_get_description()
{
return String( _( "A Intelligent Chinese Phonetic IMEngine Module." ) );
}
void scim_setup_module_load_config( const ConfigPointer &config )
{
load_config( config );
}
void scim_setup_module_save_config( const ConfigPointer &config )
{
save_config( config );
}
bool scim_setup_module_query_changed()
{
return query_changed();
}
} // extern "C"
// Internal data structure
struct KeyboardConfigData {
const char *key;
const char *label;
const char *title;
const char *tooltip;
GtkWidget *entry;
GtkWidget *button;
String data;
};
struct ColorConfigData {
const char *fg_key;
String fg_value;
String fg_default_value;
const char *bg_key;
String bg_value;
String bg_default_valuel;
const char *label;
const char *title;
void *widget;
bool changed;
};
// Internal data declaration.
// static bool __config_use_capslock = true;
static bool __config_add_phrase_forward = false;
static bool __config_esc_clean_all_buffer = false;
static bool __config_space_as_selection = true;
// static bool __config_show_candidate_comment= true;
static String __config_kb_type_data;
static String __config_kb_type_data_translated;
static String __config_selKey_type_data;
static String __config_selKey_num_data;
static bool __have_changed = false;
// static GtkWidget * __widget_use_capslock = 0;
static GtkWidget * __widget_add_phrase_forward = 0;
static GtkWidget * __widget_esc_clean_all_buffer = 0;
static GtkWidget * __widget_space_as_selection = 0;
static GtkWidget * __widget_kb_type = 0;
static GList *kb_type_list = 0;
static GtkWidget * __widget_selKey_type = 0;
static GtkWidget * __widget_selKey_num = 0;
static GList *selKey_type_list = 0;
static GList *selKey_num_list = 0;
// static GtkWidget * __widget_show_candidate_comment= 0;
static GtkTooltips * __widget_tooltips = 0;
static KeyboardConfigData __config_keyboards[] =
{
{
// key
SCIM_CONFIG_IMENGINE_CHEWING_TRIGGER_KEY,
// label
_( "Trigger keys:" ),
// title
_( "Select trigger keys" ),
// tooltip
_( "The key events to switch Chewing input mode. "
"Click on the button on the right to edit it." ),
// entry
NULL,
// button
NULL,
// data
"Ctrl+space"
},
{
// key
SCIM_CONFIG_IMENGINE_CHEWING_CHI_ENG_KEY,
// label
_("Chewing CHI/ENG keys:"),
// title
_("Select CHI/ENG keys"),
// tooltip
_("The key events to switch English and Chinese mode. "
"Click on the button on the right to edit it."),
// entry
NULL,
// button
NULL,
// data
"Shift+Shift_L+KeyRelease"
},
{
// key
NULL,
// label
NULL,
// title
NULL,
// tooltip
NULL,
// entry
NULL,
// button
NULL,
// data
""
},
};
/* XXX: It should be a pair of fg/bg colors */
#define FG_COLOR_DEFAULT "#000000"
#define FG_COLOR ""
static ColorConfigData config_color_common[] = {
{
FG_COLOR,
FG_COLOR_DEFAULT,
FG_COLOR_DEFAULT,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_ "_1",
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_1,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_1,
N_("Color #1"),
N_("The color of preediting text"),
NULL,
false
},
{
FG_COLOR,
FG_COLOR_DEFAULT,
FG_COLOR_DEFAULT,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_ "_2",
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_2,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_2,
N_("Color #2"),
N_("The color of preediting text"),
NULL,
false
},
{
FG_COLOR,
FG_COLOR_DEFAULT,
FG_COLOR_DEFAULT,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_ "_3",
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_3,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_3,
N_("Color #3"),
N_("The color of preediting text"),
NULL,
false
},
{
FG_COLOR,
FG_COLOR_DEFAULT,
FG_COLOR_DEFAULT,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_ "_4",
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_4,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_4,
N_("Color #4"),
N_("The color of preediting text"),
NULL,
false
},
{
FG_COLOR,
FG_COLOR_DEFAULT,
FG_COLOR_DEFAULT,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_ "_5",
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_5,
SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_5,
N_("Color #5"),
N_("The color of preediting text"),
NULL,
false
}
};
// Declaration of internal functions.
static void on_default_editable_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 GtkWidget *create_color_button (const char *config_key);
static void on_color_button_changed(
ScimColorButton *button,
gpointer user_data);
static void setup_widget_value();
static GtkWidg