1 /*
2 * Copyright (C) 2020 The HIME team, Taiwan
3 * Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
4 * Copyright (C) 2012 tytsim <https://github.com/tytsim>
5 * Copyright (C) 2012 Favonia <favonia@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation version 2.1
10 * of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "hime.h"
23
24 #include "gst.h"
25 #include "hime-module-cb.h"
26 #include "hime-module.h"
27 #include "im-client/hime-im-client-attr.h"
28 #include "pho.h"
29 #include "tsin.h"
30
31 /* XXX UI states hold uncommited preference.
32 * That's why we need these global variables. */
33 static GtkWidget *check_button_root_style_use,
34 *check_button_hime_pop_up_win,
35 *check_button_hime_inner_frame,
36 *check_button_hime_show_win_kbm,
37 #if TRAY_ENABLED
38 *check_button_hime_status_tray,
39 *check_button_hime_tray_hf_win_kbm,
40 #endif
41 *check_button_hime_win_color_use,
42 *check_button_hime_on_the_spot_key;
43
44 static GtkWidget *appearance_widget;
45 static GtkWidget *opt_hime_icon_dir_display;
46 static GtkWidget *opt_hime_edit_display;
47 static GdkColor hime_win_gcolor_fg, hime_win_gcolor_bg, hime_sel_key_gcolor, tsin_cursor_gcolor;
48 gboolean button_order;
49 #if TRAY_ENABLED
50 static GtkWidget *opt_hime_tray_display;
51 #endif
52
53 typedef struct {
54 GdkColor *color;
55 char **color_str;
56 GtkWidget *color_selector;
57 unich_t *title;
58 } COLORSEL;
59
60 typedef struct {
61 unich_t *name;
62 char *path;
63 } ICON_DIR_SEL;
64
65 ICON_DIR_SEL icon_dir_sel[] =
66 {{N_ ("Default"), "DEFAULT"},
67 {N_ ("Pink"), "pink"},
68 {N_ ("Grey"), "gray"},
69 {N_ ("Dark"), "dark"},
70 {N_ ("Black"), "black"}};
71
72 COLORSEL colorsel[4] =
73 {{&hime_win_gcolor_fg, &hime_win_color_fg, NULL, N_ ("Foreground color")},
74 {&hime_win_gcolor_bg, &hime_win_color_bg, NULL, N_ ("Background color")},
75 {&hime_sel_key_gcolor, &hime_sel_key_color, NULL, N_ ("Color of selection key")},
76 {&tsin_cursor_gcolor, &tsin_cursor_color, NULL, N_ ("Cursor color")}};
77
78 struct {
79 unich_t *keystr;
80 int keynum;
81 } edit_disp[] = {
82 {N_ ("Input window"), HIME_EDIT_DISPLAY_OVER_THE_SPOT},
83 {N_ ("on application window"), HIME_EDIT_DISPLAY_ON_THE_SPOT},
84 {N_ ("on both windows"), HIME_EDIT_DISPLAY_BOTH},
85 {NULL, 0},
86 };
87
88 #if TRAY_ENABLED
89 struct {
90 unich_t *keystr;
91 int keynum;
92 } tray_disp[] = {
93 {N_ ("Single icon"), HIME_TRAY_DISPLAY_SINGLE},
94 {N_ ("Dual icons"), HIME_TRAY_DISPLAY_DOUBLE},
95 #if TRAY_UNITY
96 {N_ ("AppIndicator"), HIME_TRAY_DISPLAY_APPINDICATOR},
97 #endif
98 {NULL, 0},
99 };
100 #endif
101
102 static GtkWidget *spinner_hime_font_size_tsin_presel,
103 *spinner_hime_font_size_symbol, *spinner_hime_font_size_pho_near,
104 *spinner_hime_font_size_win_kbm,
105 *spinner_hime_font_size_win_kbm_en,
106 *spinner_hime_font_size_tsin_pho_in, *spinner_hime_font_size_gtab_in, *spinner_root_style_x,
107 *spinner_root_style_y, *font_sel;
108
109 static GtkWidget *label_win_color_test, *event_box_win_color_test;
110
save_appearance_conf()111 void save_appearance_conf () {
112 if (appearance_widget == NULL) {
113 fprintf (stderr, "save_appearance_conf: appearance_widget is NULL!\n");
114 return;
115 }
116
117 char fname[128];
118 strcpy (fname, gtk_font_button_get_font_name (GTK_FONT_BUTTON (font_sel)));
119 int len = strlen (fname) - 1;
120
121 while (len > 0 && isdigit (fname[len])) {
122 len--;
123 }
124 save_hime_conf_int (HIME_FONT_SIZE, atoi (&(fname[len + 1])));
125
126 while (len > 0 && fname[len] == ' ') {
127 fname[len--] = 0;
128 }
129 save_hime_conf_str (HIME_FONT_NAME, fname);
130
131 int font_size_tsin_presel = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_tsin_presel));
132 save_hime_conf_int (HIME_FONT_SIZE_TSIN_PRESEL, font_size_tsin_presel);
133
134 int font_size_symbol = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_symbol));
135 save_hime_conf_int (HIME_FONT_SIZE_SYMBOL, font_size_symbol);
136
137 int font_size_tsin_pho_in = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_tsin_pho_in));
138 save_hime_conf_int (HIME_FONT_SIZE_TSIN_PHO_IN, font_size_tsin_pho_in);
139
140 int font_size_pho_near = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_pho_near));
141 save_hime_conf_int (HIME_FONT_SIZE_PHO_NEAR, font_size_pho_near);
142
143 int font_size_gtab_in = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_gtab_in));
144 save_hime_conf_int (HIME_FONT_SIZE_GTAB_IN, font_size_gtab_in);
145
146 int font_size_win_kbm = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_win_kbm));
147 save_hime_conf_int (HIME_FONT_SIZE_WIN_KBM, font_size_win_kbm);
148 int font_size_win_kbm_en = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_hime_font_size_win_kbm_en));
149 save_hime_conf_int (HIME_FONT_SIZE_WIN_KBM_EN, font_size_win_kbm_en);
150
151 int hime_pop_up_win = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_pop_up_win));
152 save_hime_conf_int (HIME_POP_UP_WIN, hime_pop_up_win);
153
154 int hime_root_x = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_root_style_x));
155 save_hime_conf_int (HIME_ROOT_X, hime_root_x);
156
157 int hime_root_y = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinner_root_style_y));
158 save_hime_conf_int (HIME_ROOT_Y, hime_root_y);
159
160 int style = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_root_style_use)) ? InputStyleRoot : InputStyleOverSpot;
161 save_hime_conf_int (HIME_INPUT_STYLE, style);
162
163 save_hime_conf_int (HIME_INNER_FRAME, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_inner_frame)));
164 #if TRAY_ENABLED
165 save_hime_conf_int (HIME_STATUS_TRAY, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_status_tray)));
166 #endif
167
168 save_hime_conf_int (HIME_WIN_COLOR_USE, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_win_color_use)));
169 save_hime_conf_str (HIME_WIN_COLOR_FG, hime_win_color_fg);
170 save_hime_conf_str (HIME_WIN_COLOR_BG, hime_win_color_bg);
171 save_hime_conf_str (HIME_SEL_KEY_COLOR, hime_sel_key_color);
172 int idx = gtk_combo_box_get_active (GTK_COMBO_BOX (opt_hime_icon_dir_display));
173 save_hime_conf_str (HIME_ICON_DIR, icon_dir_sel[idx].path);
174 save_hime_conf_str (TSIN_CURSOR_COLOR, tsin_cursor_color);
175
176 save_hime_conf_int (HIME_ON_THE_SPOT_KEY, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_on_the_spot_key)));
177 save_hime_conf_int (KBM_TOGGLE, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_show_win_kbm)));
178 #if TRAY_ENABLED
179 save_hime_conf_int (HIME_TRAY_HF_WIN_KBM, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_tray_hf_win_kbm)));
180 #endif
181
182 idx = gtk_combo_box_get_active (GTK_COMBO_BOX (opt_hime_edit_display));
183 save_hime_conf_int (HIME_EDIT_DISPLAY, edit_disp[idx].keynum);
184
185 #if TRAY_ENABLED
186 idx = gtk_combo_box_get_active (GTK_COMBO_BOX (opt_hime_tray_display));
187 save_hime_conf_int (HIME_TRAY_DISPLAY, tray_disp[idx].keynum);
188 #endif
189
190 #if 0
191 save_hime_conf_int(HIME_SETUP_WINDOW_TYPE_UTILITY, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button_hime_setup_window_type_utility)));
192 #endif
193
194 save_omni_config ();
195 send_hime_message (GDK_DISPLAY (), CHANGE_FONT_SIZE);
196 #if TRAY_ENABLED
197 send_hime_message (GDK_DISPLAY (), UPDATE_TRAY);
198 #endif
199 }
200
destroy_appearance_widget()201 void destroy_appearance_widget () {
202 gtk_widget_destroy (appearance_widget);
203 appearance_widget = NULL;
204 }
205
206 void disp_win_sample ();
cb_save_hime_win_color(GtkWidget * widget,gpointer user_data)207 static void cb_save_hime_win_color (GtkWidget *widget, gpointer user_data) {
208 COLORSEL *sel = (COLORSEL *) user_data;
209 GtkWidget *color_selector = sel->color_selector;
210 gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (color_selector))), sel->color);
211 *sel->color_str = gtk_color_selection_palette_to_string (sel->color, 1);
212 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_win_color_use), TRUE);
213 disp_win_sample ();
214 }
215
cb_hime_win_color(GtkWidget * widget,gpointer data)216 static gboolean cb_hime_win_color (GtkWidget *widget,
217 gpointer data) {
218 COLORSEL *sel = (COLORSEL *) data;
219 GtkWidget *color_selector = gtk_color_selection_dialog_new (_ (sel->title));
220
221 gdk_color_parse (*sel->color_str, sel->color);
222
223 gtk_color_selection_set_current_color (
224 GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (color_selector))),
225 sel->color);
226
227 sel->color_selector = color_selector;
228
229 gtk_widget_show ((GtkWidget *) color_selector);
230
231 if (gtk_dialog_run (GTK_DIALOG (color_selector)) == GTK_RESPONSE_OK)
232 cb_save_hime_win_color ((GtkWidget *) color_selector, (gpointer) sel);
233 gtk_widget_destroy (color_selector);
234
235 return TRUE;
236 }
237
disp_win_sample()238 void disp_win_sample () {
239 dbg ("disp_win_sample\n");
240 unich_t tt[512];
241 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button_hime_win_color_use))) {
242 #if !GTK_CHECK_VERSION(2, 91, 6)
243 gtk_widget_modify_bg (event_box_win_color_test, GTK_STATE_NORMAL, &hime_win_gcolor_bg);
244 #else
245 GdkRGBA rgbbg;
246 gdk_rgba_parse (&rgbbg, gdk_color_to_string (&hime_win_gcolor_bg));
247 gtk_widget_override_background_color (event_box_win_color_test, GTK_STATE_FLAG_NORMAL, &rgbbg);
248 #endif
249
250 #if PANGO_VERSION_CHECK(1, 22, 0)
251 snprintf (tt, sizeof (tt), _ ("<span foreground=\"%s\" font=\"%d\">7</span><span foreground=\"%s\" font=\"%d\">測</span><span font=\"%d\" foreground=\"white\" background=\"%s\">試</span>"), hime_sel_key_color,
252 hime_font_size_tsin_presel, hime_win_color_fg, hime_font_size_tsin_presel, hime_font_size_tsin_presel, tsin_cursor_color);
253 #else
254 snprintf (tt, sizeof (tt), _ ("<span foreground=\"%s\" font_desc=\"%d\">7</span><span foreground=\"%s\" font_desc=\"%d\">測</span><span font_desc=\"%d\" foreground=\"white\" background=\"%s\">試</span>"), hime_sel_key_color,
255 hime_font_size_tsin_presel, hime_win_color_fg, hime_font_size_tsin_presel, hime_font_size_tsin_presel, tsin_cursor_color);
256 #endif
257 } else {
258 #if !GTK_CHECK_VERSION(2, 91, 6)
259 gtk_widget_modify_bg (event_box_win_color_test, GTK_STATE_NORMAL, NULL);
260 #else
261 gtk_widget_override_background_color (event_box_win_color_test, GTK_STATE_FLAG_NORMAL, NULL);
262 #endif
263
264 #if PANGO_VERSION_CHECK(1, 22, 0)
265 snprintf (tt, sizeof (tt), _ ("<span foreground=\"blue\" font=\"%d\">7</span><span font=\"%d\">測</span><span font=\"%d\" foreground=\"white\" background=\"blue\">試</span>"), hime_font_size_tsin_presel, hime_font_size_tsin_presel, hime_font_size_tsin_presel);
266 #else
267 snprintf (tt, sizeof (tt), _ ("<span foreground=\"blue\" font_desc=\"%d\">7</span><span font_desc=\"%d\">測</span><span font_desc=\"%d\" foreground=\"white\" background=\"blue\">試</span>"), hime_font_size_tsin_presel, hime_font_size_tsin_presel, hime_font_size_tsin_presel);
268 #endif
269 }
270
271 gtk_label_set_markup (GTK_LABEL (label_win_color_test), _ (tt));
272 }
273
cb_button_hime_on_the_spot_key(GtkToggleButton * togglebutton,gpointer user_data)274 void cb_button_hime_on_the_spot_key (GtkToggleButton *togglebutton, gpointer user_data) {
275 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)))
276 return;
277 int i;
278 for (i = 0; edit_disp[i].keystr; i++)
279 if (edit_disp[i].keynum == HIME_EDIT_DISPLAY_ON_THE_SPOT)
280 gtk_combo_box_set_active (GTK_COMBO_BOX (opt_hime_edit_display), i);
281 }
282
combo_selected(GtkWidget * widget,gpointer window)283 void combo_selected (GtkWidget *widget, gpointer window) {
284 int idx = gtk_combo_box_get_active (GTK_COMBO_BOX (opt_hime_edit_display));
285 if (edit_disp[idx].keynum != HIME_EDIT_DISPLAY_ON_THE_SPOT) {
286 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_on_the_spot_key), FALSE);
287 }
288 }
289
create_hime_icon_dir_display()290 static GtkWidget *create_hime_icon_dir_display () {
291 GtkWidget *hbox_hime_icon_dir = gtk_hbox_new (FALSE, 10);
292
293 gtk_orientable_set_orientation (GTK_ORIENTABLE (hbox_hime_icon_dir), GTK_ORIENTATION_HORIZONTAL);
294
295 GtkWidget *label = gtk_label_new (_ ("Icon style"));
296 gtk_box_pack_start (GTK_BOX (hbox_hime_icon_dir), label, FALSE, FALSE, 0);
297 opt_hime_icon_dir_display = gtk_combo_box_text_new ();
298 gtk_box_pack_start (GTK_BOX (hbox_hime_icon_dir), opt_hime_icon_dir_display, FALSE, FALSE, 0);
299 int i, current_idx = 0;
300 for (i = 0; i < sizeof (icon_dir_sel) / sizeof (icon_dir_sel[0]); i++) {
301 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (opt_hime_icon_dir_display), icon_dir_sel[i].name);
302 if (!strcmp (hime_icon_dir, icon_dir_sel[i].path)) {
303 current_idx = i;
304 }
305 }
306 gtk_combo_box_set_active (GTK_COMBO_BOX (opt_hime_icon_dir_display), current_idx);
307 return hbox_hime_icon_dir;
308 }
309
create_hime_edit_display()310 static GtkWidget *create_hime_edit_display () {
311
312 GtkWidget *box = gtk_vbox_new (FALSE, 1);
313 gtk_orientable_set_orientation (GTK_ORIENTABLE (box), GTK_ORIENTATION_VERTICAL);
314
315 GtkWidget *hbox = gtk_hbox_new (FALSE, 1);
316 gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
317 GtkWidget *label = gtk_label_new (_ ("Editing area"));
318 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
319
320 opt_hime_edit_display = gtk_combo_box_text_new ();
321 gtk_box_pack_start (GTK_BOX (hbox), opt_hime_edit_display, FALSE, FALSE, 0);
322
323 int i, current_idx = 0;
324
325 for (i = 0; edit_disp[i].keystr; i++) {
326 if (edit_disp[i].keynum == hime_edit_display)
327 current_idx = i;
328 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (opt_hime_edit_display), _ (edit_disp[i].keystr));
329 }
330
331 gtk_combo_box_set_active (GTK_COMBO_BOX (opt_hime_edit_display), current_idx);
332
333 check_button_hime_on_the_spot_key = gtk_check_button_new_with_label (_ ("Show keycodes on application window (OnTheSpot)"));
334 g_signal_connect (G_OBJECT (check_button_hime_on_the_spot_key), "toggled",
335 G_CALLBACK (cb_button_hime_on_the_spot_key), NULL);
336 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_on_the_spot_key),
337 hime_on_the_spot_key);
338 gtk_box_pack_start (GTK_BOX (box), check_button_hime_on_the_spot_key, FALSE, FALSE, 0);
339
340 g_signal_connect (G_OBJECT (opt_hime_edit_display), "changed",
341 G_CALLBACK (combo_selected), (gpointer) NULL);
342
343 return box;
344 }
345
346 #if TRAY_ENABLED
create_hime_tray_display()347 static GtkWidget *create_hime_tray_display () {
348
349 GtkWidget *hbox = gtk_hbox_new (FALSE, 1);
350
351 check_button_hime_status_tray = gtk_check_button_new_with_label (_ ("Enable system tray icon"));
352 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_status_tray),
353 hime_status_tray);
354 gtk_box_pack_start (GTK_BOX (hbox), check_button_hime_status_tray, FALSE, FALSE, 0);
355
356 // GtkWidget *label = gtk_label_new(_("System tray displays as"));
357 // gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
358
359 opt_hime_tray_display = gtk_combo_box_text_new ();
360
361 gtk_box_pack_start (GTK_BOX (hbox), opt_hime_tray_display, FALSE, FALSE, 0);
362
363 int i, current_idx = 0;
364
365 for (i = 0; tray_disp[i].keystr; i++) {
366 if (tray_disp[i].keynum == hime_tray_display)
367 current_idx = i;
368 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (opt_hime_tray_display), _ (tray_disp[i].keystr));
369 }
370
371 gtk_combo_box_set_active (GTK_COMBO_BOX (opt_hime_tray_display), current_idx);
372
373 // g_signal_connect(G_OBJECT(opt_hime_tray_display), "changed",
374 // G_CALLBACK(combo_selected), (gpointer) NULL);
375
376 return hbox;
377 }
378 #endif
379
cb_hime_win_color_use(GtkToggleButton * togglebutton,gpointer user_data)380 static gboolean cb_hime_win_color_use (GtkToggleButton *togglebutton, gpointer user_data) {
381 dbg ("cb_hime_win_color_use\n");
382 disp_win_sample ();
383 return TRUE;
384 }
385
create_appearance_widget()386 GtkWidget *create_appearance_widget () {
387 if (appearance_widget != NULL)
388 fprintf (stderr, "create_appearance_widget: appearance_widget was not NULL!\n");
389
390 load_settings ();
391
392 GtkWidget *vbox_top = gtk_vbox_new (FALSE, 0);
393 gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox_top), GTK_ORIENTATION_VERTICAL);
394 gtk_container_set_border_width (GTK_CONTAINER (vbox_top), 10);
395 appearance_widget = vbox_top;
396
397 GtkWidget *hbox_hime_font_size = gtk_hbox_new (FALSE, 10);
398 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size, FALSE, FALSE, 0);
399
400 GtkWidget *label_hime_font_size = gtk_label_new (_ ("Main font"));
401 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size), label_hime_font_size, FALSE, FALSE, 0);
402 char tt[128];
403 snprintf (tt, sizeof (tt), "%s %d", hime_font_name, hime_font_size);
404 font_sel = gtk_font_button_new_with_font (tt);
405 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size), font_sel, FALSE, FALSE, 0);
406
407 GtkWidget *hbox_hime_font_size_symbol = gtk_hbox_new (FALSE, 10);
408 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size_symbol, FALSE, FALSE, 0);
409 GtkWidget *label_hime_font_size_symbol = gtk_label_new (_ ("Font size of symbols window"));
410 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_symbol), label_hime_font_size_symbol, FALSE, FALSE, 0);
411 GtkAdjustment *adj_hime_font_size_symbol =
412 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_symbol, 8.0, 32.0, 1.0, 1.0, 0.0);
413 spinner_hime_font_size_symbol = gtk_spin_button_new (adj_hime_font_size_symbol, 0, 0);
414 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_symbol), spinner_hime_font_size_symbol, FALSE, FALSE, 0);
415
416 GtkWidget *hbox_hime_font_size_tsin_presel = gtk_hbox_new (FALSE, 10);
417 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size_tsin_presel, FALSE, FALSE, 0);
418 GtkWidget *label_hime_font_size_tsin_presel = gtk_label_new (_ ("Font size of Tsin's and gtab's preselection window"));
419 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_tsin_presel), label_hime_font_size_tsin_presel, FALSE, FALSE, 0);
420 GtkAdjustment *adj_hime_font_size_tsin_presel =
421 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_tsin_presel, 8.0, 32.0, 1.0, 1.0, 0.0);
422 spinner_hime_font_size_tsin_presel = gtk_spin_button_new (adj_hime_font_size_tsin_presel, 0, 0);
423 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_tsin_presel), spinner_hime_font_size_tsin_presel, FALSE, FALSE, 0);
424
425 GtkWidget *hbox_hime_font_size_tsin_pho_in = gtk_hbox_new (FALSE, 10);
426 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size_tsin_pho_in, FALSE, FALSE, 0);
427 GtkWidget *label_hime_font_size_tsin_pho_in = gtk_label_new (_ ("Font size of keycodes for Bopomofo and Tsin"));
428 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_tsin_pho_in), label_hime_font_size_tsin_pho_in, FALSE, FALSE, 0);
429 GtkAdjustment *adj_hime_font_size_tsin_pho_in =
430 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_tsin_pho_in, 8.0, 32.0, 1.0, 1.0, 0.0);
431 spinner_hime_font_size_tsin_pho_in = gtk_spin_button_new (adj_hime_font_size_tsin_pho_in, 0, 0);
432 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_tsin_pho_in), spinner_hime_font_size_tsin_pho_in, FALSE, FALSE, 0);
433
434 GtkWidget *hbox_hime_font_size_pho_near = gtk_hbox_new (FALSE, 10);
435 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size_pho_near, FALSE, FALSE, 0);
436 GtkWidget *label_hime_font_size_pho_near = gtk_label_new (_ ("Font size of similar phonetic choices"));
437 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_pho_near), label_hime_font_size_pho_near, FALSE, FALSE, 0);
438 GtkAdjustment *adj_hime_font_size_pho_near =
439 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_pho_near, 8.0, 32.0, 1.0, 1.0, 0.0);
440 spinner_hime_font_size_pho_near = gtk_spin_button_new (adj_hime_font_size_pho_near, 0, 0);
441 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_pho_near), spinner_hime_font_size_pho_near, FALSE, FALSE, 0);
442
443 GtkWidget *hbox_hime_font_size_gtab_in = gtk_hbox_new (FALSE, 10);
444 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size_gtab_in, FALSE, FALSE, 0);
445 GtkWidget *label_hime_font_size_gtab_in = gtk_label_new (_ ("Font size of keycodes for gtab"));
446 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_gtab_in), label_hime_font_size_gtab_in, FALSE, FALSE, 0);
447 GtkAdjustment *adj_hime_font_size_gtab_in =
448 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_gtab_in, 8.0, 32.0, 1.0, 1.0, 0.0);
449 spinner_hime_font_size_gtab_in = gtk_spin_button_new (adj_hime_font_size_gtab_in, 0, 0);
450 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_gtab_in), spinner_hime_font_size_gtab_in, FALSE, FALSE, 0);
451
452 GtkWidget *hbox_hime_font_size_win_kbm = gtk_hbox_new (FALSE, 10);
453 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_font_size_win_kbm, FALSE, FALSE, 0);
454 GtkWidget *label_hime_font_size_win_kbm = gtk_label_new (_ ("Font size of virtual keyboard"));
455 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_win_kbm), label_hime_font_size_win_kbm, FALSE, FALSE, 0);
456 GtkAdjustment *adj_hime_font_size_win_kbm =
457 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_win_kbm, 8.0, 32.0, 1.0, 1.0, 0.0);
458 spinner_hime_font_size_win_kbm = gtk_spin_button_new (adj_hime_font_size_win_kbm, 0, 0);
459 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_win_kbm), spinner_hime_font_size_win_kbm, FALSE, FALSE, 0);
460 GtkWidget *label_hime_font_size_win_kbm_en = gtk_label_new (_ ("Alphabet-numeric"));
461 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_win_kbm), label_hime_font_size_win_kbm_en, FALSE, FALSE, 0);
462 GtkAdjustment *adj_hime_font_size_win_kbm_en =
463 (GtkAdjustment *) gtk_adjustment_new (hime_font_size_win_kbm_en, 8.0, 32.0, 1.0, 1.0, 0.0);
464 spinner_hime_font_size_win_kbm_en = gtk_spin_button_new (adj_hime_font_size_win_kbm_en, 0, 0);
465 gtk_box_pack_start (GTK_BOX (hbox_hime_font_size_win_kbm), spinner_hime_font_size_win_kbm_en, FALSE, FALSE, 0);
466
467 GtkWidget *hbox_hime_pop_up_win = gtk_hbox_new (FALSE, 10);
468 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_pop_up_win, FALSE, FALSE, 0);
469 check_button_hime_pop_up_win = gtk_check_button_new_with_label (_ ("Popup input window when typing"));
470 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_pop_up_win),
471 hime_pop_up_win);
472 gtk_box_pack_start (GTK_BOX (hbox_hime_pop_up_win), check_button_hime_pop_up_win, FALSE, FALSE, 0);
473
474 #if TRAY_ENABLED
475 gtk_box_pack_start (GTK_BOX (vbox_top), create_hime_tray_display (), FALSE, FALSE, 0);
476 check_button_hime_tray_hf_win_kbm = gtk_check_button_new_with_label (_ ("Toggle virtual keyboard by clicking shape tray"));
477 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_tray_hf_win_kbm),
478 hime_tray_hf_win_kbm);
479 gtk_box_pack_start (GTK_BOX (vbox_top), check_button_hime_tray_hf_win_kbm, FALSE, FALSE, 0);
480 #endif
481 check_button_hime_show_win_kbm = gtk_check_button_new_with_label (_ ("Show virtual keyboard on initial"));
482 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_show_win_kbm), hime_show_win_kbm);
483 gtk_box_pack_start (GTK_BOX (vbox_top), check_button_hime_show_win_kbm, FALSE, FALSE, 0);
484
485 GtkWidget *frame_root_style = gtk_frame_new (_ ("Fixed input window"));
486 gtk_box_pack_start (GTK_BOX (vbox_top), frame_root_style, FALSE, FALSE, 0);
487 gtk_container_set_border_width (GTK_CONTAINER (frame_root_style), 3);
488 GtkWidget *vbox_root_style = gtk_vbox_new (FALSE, 10);
489 gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox_root_style), GTK_ORIENTATION_VERTICAL);
490 gtk_container_add (GTK_CONTAINER (frame_root_style), vbox_root_style);
491
492 GtkWidget *hbox_root_style_use = gtk_hbox_new (FALSE, 10);
493 gtk_box_pack_start (GTK_BOX (vbox_root_style), hbox_root_style_use, FALSE, FALSE, 0);
494 check_button_root_style_use = gtk_check_button_new_with_label (_ ("Enable"));
495 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_root_style_use),
496 hime_input_style == InputStyleRoot);
497 gtk_box_pack_start (GTK_BOX (hbox_root_style_use), check_button_root_style_use, FALSE, FALSE, 0);
498
499 GtkWidget *label_fix_location = gtk_label_new (_ ("Fixed position:"));
500 gtk_box_pack_start (GTK_BOX (hbox_root_style_use), label_fix_location, FALSE, FALSE, 0);
501
502 GtkAdjustment *adj_root_style_x =
503 (GtkAdjustment *) gtk_adjustment_new (hime_root_x, 0.0, 5120.0, 1.0, 1.0, 0.0);
504 spinner_root_style_x = gtk_spin_button_new (adj_root_style_x, 0, 0);
505 gtk_widget_set_hexpand (spinner_root_style_x, TRUE);
506 gtk_box_pack_start (GTK_BOX (hbox_root_style_use), spinner_root_style_x, FALSE, FALSE, 0);
507
508 GtkAdjustment *adj_root_style_y =
509 (GtkAdjustment *) gtk_adjustment_new (hime_root_y, 0.0, 2880.0, 1.0, 1.0, 0.0);
510 spinner_root_style_y = gtk_spin_button_new (adj_root_style_y, 0, 0);
511 gtk_widget_set_hexpand (spinner_root_style_y, TRUE);
512 gtk_box_pack_start (GTK_BOX (hbox_root_style_use), spinner_root_style_y, FALSE, FALSE, 0);
513
514 gtk_box_pack_start (GTK_BOX (vbox_top), create_hime_edit_display (), FALSE, FALSE, 0);
515
516 GtkWidget *hbox_hime_inner_frame = gtk_hbox_new (FALSE, 10);
517 gtk_box_pack_start (GTK_BOX (vbox_top), hbox_hime_inner_frame, FALSE, FALSE, 0);
518 check_button_hime_inner_frame = gtk_check_button_new_with_label (_ ("Show frame of input window"));
519 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_inner_frame),
520 hime_inner_frame);
521 gtk_box_pack_start (GTK_BOX (hbox_hime_inner_frame), check_button_hime_inner_frame, FALSE, FALSE, 0);
522
523 #if 0
524 check_button_hime_setup_window_type_utility = gtk_check_button_new_with_label (_("Set setup windows as UTILITY"));
525 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button_hime_setup_window_type_utility),
526 hime_setup_window_type_utility);
527 gtk_box_pack_start (GTK_BOX(vbox_top), check_button_hime_setup_window_type_utility, FALSE, FALSE, 0);
528 #endif
529
530 gtk_box_pack_start (GTK_BOX (vbox_top), create_hime_icon_dir_display (), FALSE, FALSE, 0);
531
532 GtkWidget *frame_win_color = gtk_frame_new (_ ("Color selection"));
533 gtk_box_pack_start (GTK_BOX (vbox_top), frame_win_color, FALSE, FALSE, 0);
534 gtk_container_set_border_width (GTK_CONTAINER (frame_win_color), 1);
535 GtkWidget *vbox_win_color = gtk_vbox_new (FALSE, 0);
536 gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox_win_color), GTK_ORIENTATION_VERTICAL);
537 gtk_container_add (GTK_CONTAINER (frame_win_color), vbox_win_color);
538
539 GtkWidget *hbox_win_color_use = gtk_hbox_new (FALSE, 10);
540 gtk_box_pack_start (GTK_BOX (vbox_win_color), hbox_win_color_use, FALSE, FALSE, 0);
541 check_button_hime_win_color_use = gtk_check_button_new_with_label (_ ("Custom theme color"));
542 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button_hime_win_color_use),
543 hime_win_color_use);
544
545 g_signal_connect (G_OBJECT (check_button_hime_win_color_use), "clicked",
546 G_CALLBACK (cb_hime_win_color_use), NULL);
547
548 gtk_box_pack_start (GTK_BOX (hbox_win_color_use), check_button_hime_win_color_use, FALSE, FALSE, 0);
549 event_box_win_color_test = gtk_event_box_new ();
550 // this will make the color test failed
551 // gtk_event_box_set_visible_window (GTK_EVENT_BOX(event_box_win_color_test), FALSE);
552 gtk_box_pack_start (GTK_BOX (vbox_win_color), event_box_win_color_test, FALSE, FALSE, 0);
553 label_win_color_test = gtk_label_new (NULL);
554 gtk_container_add (GTK_CONTAINER (event_box_win_color_test), label_win_color_test);
555 GtkWidget *hbox_win_color_fbg = gtk_hbox_new (FALSE, 10);
556 gtk_box_pack_start (GTK_BOX (vbox_win_color), hbox_win_color_fbg, FALSE, FALSE, 0);
557 GtkWidget *button_fg = gtk_button_new_with_label (_ ("Foreground color"));
558 gtk_widget_set_hexpand (button_fg, TRUE);
559 gtk_widget_set_halign (button_fg, GTK_ALIGN_FILL);
560 gtk_box_pack_start (GTK_BOX (hbox_win_color_fbg), button_fg, TRUE, TRUE, 0);
561 g_signal_connect (G_OBJECT (button_fg), "clicked",
562 G_CALLBACK (cb_hime_win_color), &colorsel[0]);
563 gdk_color_parse (hime_win_color_fg, &hime_win_gcolor_fg);
564 // gtk_widget_modify_fg(label_win_color_test, GTK_STATE_NORMAL, &hime_win_gcolor_fg);
565 gdk_color_parse (hime_win_color_bg, &hime_win_gcolor_bg);
566 // gtk_widget_modify_bg(event_box_win_color_test, GTK_STATE_NORMAL, &hime_win_gcolor_bg);
567
568 GtkWidget *button_bg = gtk_button_new_with_label (_ ("Background color"));
569 gtk_widget_set_hexpand (button_bg, TRUE);
570 gtk_widget_set_halign (button_bg, GTK_ALIGN_FILL);
571 gtk_box_pack_start (GTK_BOX (hbox_win_color_fbg), button_bg, TRUE, TRUE, 0);
572 g_signal_connect (G_OBJECT (button_bg), "clicked",
573 G_CALLBACK (cb_hime_win_color), &colorsel[1]);
574
575 GtkWidget *button_hime_sel_key_color = gtk_button_new_with_label (_ ("Color of selection key"));
576 gtk_widget_set_hexpand (button_hime_sel_key_color, TRUE);
577 gtk_widget_set_halign (button_hime_sel_key_color, GTK_ALIGN_FILL);
578 g_signal_connect (G_OBJECT (button_hime_sel_key_color), "clicked",
579 G_CALLBACK (cb_hime_win_color), &colorsel[2]);
580 gdk_color_parse (hime_sel_key_color, &hime_sel_key_gcolor);
581 gtk_box_pack_start (GTK_BOX (hbox_win_color_fbg), button_hime_sel_key_color, TRUE, TRUE, 0);
582
583 GtkWidget *button_tsin_cursor_color = gtk_button_new_with_label (_ ("Cursor color"));
584 gtk_widget_set_hexpand (button_tsin_cursor_color, TRUE);
585 gtk_widget_set_halign (button_tsin_cursor_color, GTK_ALIGN_FILL);
586 g_signal_connect (G_OBJECT (button_tsin_cursor_color), "clicked",
587 G_CALLBACK (cb_hime_win_color), &colorsel[3]);
588 gdk_color_parse (tsin_cursor_color, &tsin_cursor_gcolor);
589 gtk_box_pack_start (GTK_BOX (hbox_win_color_fbg), button_tsin_cursor_color, TRUE, TRUE, 0);
590
591 disp_win_sample ();
592
593 return appearance_widget;
594 }
595