2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
6 * The contents of this file are subject to the terms of either the GNU Lesser
7 * General Public License Version 2.1 only ("LGPL") or the Common Development and
8 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
9 * file except in compliance with the License. You can obtain a copy of the CDDL at
10 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
11 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
12 * specific language governing permissions and limitations under the License. When
13 * distributing the software, include this License Header Notice in each file and
14 * include the full text of the License in the License file as well as the
17 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
19 * For Covered Software in this distribution, this License shall be governed by the
20 * laws of the State of California (excluding conflict-of-law provisions).
21 * Any litigation relating to this License shall be subject to the jurisdiction of
22 * the Federal Courts of the Northern District of California and the state courts
23 * of the State of California, with venue lying in Santa Clara County, California.
27 * If you wish your version of this file to be governed by only the CDDL or only
28 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
29 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
30 * license." If you don't indicate a single choice of license, a recipient has the
31 * option to distribute your version of this file under either the CDDL or the LGPL
32 * Version 2.1, or to extend the choice of license to its licensees as provided
33 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
34 * Version 2 license, then the option applies only if the new code is made subject
35 * to such option by the copyright holder.
37 #define Uses_SCIM_CONFIG_BASE
42 #include <gtk/scimkeyselection.h>
44 #include "sunpinyin_private.h"
45 #include "sunpinyin_imengine_config_keys.h"
49 #if !GTK_CHECK_VERSION(2, 12, 0)
50 #define SUNPINYIN_USE_GTK_TOOLTIPS
53 #if GTK_CHECK_VERSION(2, 24, 0)
54 #define SUNPINYIN_USE_GTK_COMBO_BOX_TEXT
57 #if GTK_CHECK_VERSION(3, 0, 0)
58 #define SUNPINYIN_USE_GTK_BOX
61 #define scim_module_init sunpinyin_imengine_setup_LTX_scim_module_init
62 #define scim_module_exit sunpinyin_imengine_setup_LTX_scim_module_exit
64 #define scim_setup_module_create_ui sunpinyin_imengine_setup_LTX_scim_setup_module_create_ui
65 #define scim_setup_module_get_category sunpinyin_imengine_setup_LTX_scim_setup_module_get_category
66 #define scim_setup_module_get_name sunpinyin_imengine_setup_LTX_scim_setup_module_get_name
67 #define scim_setup_module_get_description sunpinyin_imengine_setup_LTX_scim_setup_module_get_description
68 #define scim_setup_module_load_config sunpinyin_imengine_setup_LTX_scim_setup_module_load_config
69 #define scim_setup_module_save_config sunpinyin_imengine_setup_LTX_scim_setup_module_save_config
70 #define scim_setup_module_query_changed sunpinyin_imengine_setup_LTX_scim_setup_module_query_changed
72 static GtkWidget * input_style_combo = NULL;
73 static GtkWidget * charset_combo = NULL;
74 static GtkWidget * minus_pageup_button = NULL;
75 static GtkWidget * bracket_pageup_button = NULL;
76 static GtkWidget * comma_pageup_button = NULL;
77 static GtkWidget * memory_power_button = NULL;
79 static GtkWidget * create_setup_window ();
80 static void load_config (const ConfigPointer &config);
81 static void save_config (const ConfigPointer &config);
82 static bool query_changed ();
86 EXPORTED void scim_module_init (void)
88 bindtextdomain (GETTEXT_PACKAGE, SCIM_SUNPINYIN_LOCALEDIR);
89 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
92 EXPORTED void scim_module_exit (void)
96 EXPORTED GtkWidget * scim_setup_module_create_ui (void)
98 static GtkWidget *setup_ui = NULL;
100 setup_ui = create_setup_window ();
104 EXPORTED String scim_setup_module_get_category (void)
106 return String ("IMEngine");
109 EXPORTED String scim_setup_module_get_name (void)
111 return String (_("SunPinyin"));
114 EXPORTED String scim_setup_module_get_description (void)
116 return String (_("A Statistical Language Model Based Intelligent IMEngine Module for Simplified Chinese."));
119 EXPORTED void scim_setup_module_load_config (const ConfigPointer &config)
121 load_config (config);
124 EXPORTED void scim_setup_module_save_config (const ConfigPointer &config)
126 save_config (config);
129 EXPORTED bool scim_setup_module_query_changed ()
131 return query_changed ();
135 static bool __have_changed = false;
138 on_value_changed(GtkWidget * widget,
141 __have_changed = true;
145 #ifdef SUNPINYIN_USE_GTK_TOOLTIPS
146 create_options_page(GtkTooltips *tooltips)
148 create_options_page()
155 #ifdef SUNPINYIN_USE_GTK_BOX
156 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
158 vbox = gtk_vbox_new (FALSE, 12);
161 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
163 GtkWidget *table = gtk_table_new (2, 2, FALSE);
164 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, TRUE, 0);
166 label = gtk_label_new (_("Input Style:"));
167 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
168 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
169 (GtkAttachOptions) (GTK_FILL),
170 (GtkAttachOptions) (GTK_FILL), 4, 4);
173 #ifdef SUNPINYIN_USE_GTK_COMBO_BOX_TEXT
174 GtkWidget *combo_box = gtk_combo_box_text_new();
176 GtkWidget *combo_box = gtk_combo_box_new_text();
179 gtk_table_attach (GTK_TABLE (table), combo_box, 1, 2, 0, 1,
180 (GtkAttachOptions) (GTK_FILL),
181 (GtkAttachOptions) (GTK_FILL), 4, 4);
183 #ifdef SUNPINYIN_USE_GTK_COMBO_BOX_TEXT
184 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("Classic Style"));
185 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("Instant Style"));
187 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("Classic Style"));
188 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("Instant Style"));
191 const gchar *input_style_tooltip = _("You may feel more comfortable in classic style, "
192 "if you are used to input methods like scim-pinyin."
193 " In instant style, the most possible candidate "
194 "word will show up in the preedit area right after "
195 "its pinyin is input.");
196 #ifdef SUNPINYIN_USE_GTK_TOOLTIPS
197 gtk_tooltips_set_tip(tooltips, combo_box, input_style_tooltip, NULL);
199 gtk_widget_set_tooltip_text(combo_box, input_style_tooltip);
202 g_signal_connect(G_OBJECT(combo_box), "changed",
203 G_CALLBACK(on_value_changed), NULL);
204 input_style_combo = combo_box;
206 label = gtk_label_new (_("Character Set:"));
207 gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
208 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
209 (GtkAttachOptions) (GTK_FILL),
210 (GtkAttachOptions) (GTK_FILL), 4, 4);
212 #ifdef SUNPINYIN_USE_GTK_COMBO_BOX_TEXT
213 combo_box = gtk_combo_box_text_new();
215 combo_box = gtk_combo_box_new_text();
218 gtk_table_attach (GTK_TABLE (table), combo_box, 1, 2, 1, 2,
219 (GtkAttachOptions) (GTK_FILL),
220 (GtkAttachOptions) (GTK_FILL), 4, 4);
222 #ifdef SUNPINYIN_USE_GTK_COMBO_BOX_TEXT
223 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("GB2312"));
224 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), _("GBK"));
226 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("GB2312"));
227 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), _("GBK"));
230 const gchar *charset_tooltip = _("Choosing GBK over GB2312 will trade some speed "
231 "with a larger charset in which I search candidate "
232 "words/characters for you.");
233 #ifdef SUNPINYIN_USE_GTK_TOOLTIPS
234 gtk_tooltips_set_tip(tooltips, combo_box, charset_tooltip, NULL);
236 gtk_widget_set_tooltip_text(combo_box, charset_tooltip);
239 g_signal_connect(G_OBJECT(combo_box), "changed",
240 G_CALLBACK(on_value_changed), NULL);
241 charset_combo = combo_box;
243 button = gtk_check_button_new_with_mnemonic (_("Use -/= for paging down/up"));
244 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
245 g_signal_connect(G_OBJECT(button), "toggled",
246 G_CALLBACK(on_value_changed), NULL);
247 minus_pageup_button = button;
249 button = gtk_check_button_new_with_mnemonic (_("Use [/] for paging down/up"));
250 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
251 g_signal_connect(G_OBJECT(button), "toggled",
252 G_CALLBACK(on_value_changed), NULL);
253 bracket_pageup_button = button;
255 button = gtk_check_button_new_with_mnemonic (_("Use ,/. for paging down/up"));
256 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
257 g_signal_connect(G_OBJECT(button), "toggled",
258 G_CALLBACK(on_value_changed), NULL);
259 comma_pageup_button = button;
264 #ifdef SUNPINYIN_USE_GTK_BOX
265 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
267 hbox = gtk_hbox_new (FALSE, 0);
270 gtk_widget_show (hbox);
271 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
273 label = gtk_label_new (NULL);
274 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("M_emory power:"));
275 gtk_widget_show (label);
276 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
277 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
278 gtk_misc_set_padding (GTK_MISC (label), 2, 0);
280 button = gtk_spin_button_new_with_range (0, 10, 1);
282 const gchar *memory_power_tooltip = _("The larger this number is, the faster I "
283 "memorize/forget new words.");
284 #ifdef SUNPINYIN_USE_GTK_TOOLTIPS
285 gtk_tooltips_set_tip(tooltips, button, memory_power_tooltip, NULL);
287 gtk_widget_set_tooltip_text(button, memory_power_tooltip);
290 g_signal_connect (G_OBJECT(button), "value_changed",
291 G_CALLBACK(on_value_changed), NULL);
292 gtk_widget_show (button);
293 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
294 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (button), TRUE);
295 gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (button), TRUE);
296 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (button), 0);
297 gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
298 memory_power_button = button;
304 create_setup_window ()
309 #ifdef SUNPINYIN_USE_GTK_TOOLTIPS
310 GtkTooltips *tooltips;
312 // Create the shared tooltips.
313 tooltips = gtk_tooltips_new ();
316 notebook = gtk_notebook_new ();
318 // Create the option page.
319 #ifdef SUNPINYIN_USE_GTK_TOOLTIPS
320 page = create_options_page(tooltips);
322 page = create_options_page();
324 label = gtk_label_new (_("Options"));
325 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
327 gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), 0);
329 gtk_widget_show_all(notebook);
334 load_config (const ConfigPointer &config)
339 int viewtype = config->read (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_VIEW_TYPE), 0);
340 gtk_combo_box_set_active (GTK_COMBO_BOX(input_style_combo), viewtype);
342 int charset = config->read (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_CHARHSET), 1);
343 gtk_combo_box_set_active (GTK_COMBO_BOX(charset_combo), charset);
346 stat = config->read (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_PAGE_MINUS), true);
347 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(minus_pageup_button), stat);
349 stat = config->read (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_PAGE_BRACKET), true);
350 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bracket_pageup_button), stat);
352 stat = config->read (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_PAGE_COMMA), false);
353 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(comma_pageup_button), stat);
356 value = config->read (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_MEMORY_POWER), 5);
357 gtk_spin_button_set_value(GTK_SPIN_BUTTON(memory_power_button), value);
359 __have_changed = false;
363 save_config (const ConfigPointer &config)
368 int no = gtk_combo_box_get_active(GTK_COMBO_BOX(input_style_combo));
369 config->write (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_VIEW_TYPE), no);
371 no = gtk_combo_box_get_active(GTK_COMBO_BOX(charset_combo));
372 config->write (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_CHARHSET), no);
375 stat = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(minus_pageup_button));
376 config->write (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_PAGE_MINUS), (bool)stat);
378 stat = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bracket_pageup_button));
379 config->write (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_PAGE_BRACKET), (bool)stat);
381 stat = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(comma_pageup_button));
382 config->write (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_PAGE_COMMA), (bool)stat);
385 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(memory_power_button));
386 config->write (String (SCIM_CONFIG_IMENGINE_SUNPINYIN_USER_MEMORY_POWER), value);
387 __have_changed = false;
393 return __have_changed;