forked from medicalwei/gcin-debian
/
win-pho.cpp
379 lines (285 loc) · 8.01 KB
/
win-pho.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include "gcin.h"
#include "win-sym.h"
#include "gtab.h"
static int current_gcin_inner_frame;
static int current_pho_in_row1;
GtkWidget *gwin_pho;
static GtkWidget *top_bin, *hbox_row2;
static GtkWidget *label_pho_sele;
static GtkWidget *label_pho;
static GtkWidget *label_full;
static GtkWidget *label_key_codes;
void change_pho_font_size(), toggle_win_sym();
void disp_pho_sub(GtkWidget *label, int index, char *pho);
void disp_pho(int index, char *phochar)
{
// dbg("%d '", index); utf8_putchar(phochar); dbg("'\n");
disp_pho_sub(label_pho, index, phochar);
}
#if WIN32
static int timeout_handle_pho;
gboolean timeout_minimize_win_pho(gpointer data)
{
if (!gwin_pho)
return FALSE;
gtk_window_resize(GTK_WINDOW(gwin_pho), 1, 1);
// gtk_window_present(GTK_WINDOW(gwin0));
timeout_handle_pho = 0;
return FALSE;
}
#endif
void minimize_win_pho()
{
gtk_window_resize(GTK_WINDOW(gwin_pho), 1, 1);
#if WIN32
if (!timeout_handle_pho)
timeout_handle_pho = g_timeout_add(50, timeout_minimize_win_pho, NULL);
#endif
}
void move_win_pho(int x, int y);
void get_win_size(GtkWidget *win, int *width, int *height)
{
GtkRequisition sz;
sz.width = sz.height = 0;
gtk_widget_get_preferred_size(GTK_WIDGET(win), NULL, &sz);
*width = sz.width;
*height = sz.height;
}
gboolean win_size_exceed(GtkWidget *win)
{
int width, height;
get_win_size(win, &width, &height);
return (width + current_in_win_x > dpy_xl || height + current_in_win_y > dpy_yl);
}
void disp_pho_sel(char *s)
{
gtk_label_set_markup(GTK_LABEL(label_pho_sele), s);
minimize_win_pho();
if (win_size_exceed(gwin_pho)) {
move_win_pho(current_in_win_x, current_in_win_y);
}
}
void set_key_codes_label_pho(char *s)
{
if (!label_key_codes)
return;
if (!s || !*s) {
gtk_widget_hide(label_key_codes);
return;
}
gtk_label_set_text(GTK_LABEL(label_key_codes), s);
gtk_widget_show(label_key_codes);
}
void show_win_sym();
void move_win_pho(int x, int y)
{
int twin_xl, twin_yl;
win_x = x; win_y = y;
if (!gwin_pho)
return;
get_win_size(gwin_pho, &twin_xl, &twin_yl);
if (x + twin_xl > dpy_xl)
x = dpy_xl - twin_xl;
if (x < 0)
x = 0;
if (y + twin_yl > dpy_yl)
y = dpy_yl - twin_yl;
if (y < 0)
y = 0;
gtk_window_move(GTK_WINDOW(gwin_pho), x, y);
move_win_sym();
}
void create_win_pho()
{
if (gwin_pho)
return;
gwin_pho = create_no_focus_win();
change_win_bg(gwin_pho);
}
void create_win_sym(), exec_gcin_setup();
static void mouse_button_callback( GtkWidget *widget,GdkEventButton *event, gpointer data)
{
// dbg("mouse_button_callback %d\n", event->button);
switch (event->button) {
case 1:
toggle_win_sym();
break;
case 2:
inmd_switch_popup_handler(widget, (GdkEvent *)event);
break;
case 3:
exec_gcin_setup();
break;
}
}
void create_win_pho_gui_simple()
{
// dbg("create_win_pho .....\n");
if (top_bin)
return;
GtkWidget *vbox_top = gtk_vbox_new (FALSE, 0);
GtkWidget *event_box_pho;
if (gtab_in_area_button)
event_box_pho = gtk_button_new();
else {
event_box_pho = gtk_event_box_new();
gtk_event_box_set_visible_window (GTK_EVENT_BOX(event_box_pho), FALSE);
}
gtk_container_set_border_width (GTK_CONTAINER (event_box_pho), 0);
if (gcin_inner_frame) {
GtkWidget *frame = top_bin = gtk_frame_new(NULL);
gtk_container_set_border_width (GTK_CONTAINER (frame), 0);
gtk_container_add (GTK_CONTAINER(gwin_pho), frame);
gtk_container_add (GTK_CONTAINER (frame), vbox_top);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
} else {
gtk_container_add (GTK_CONTAINER(gwin_pho), vbox_top);
top_bin = vbox_top;
}
GtkWidget *align = gtk_alignment_new (0, 0, 0, 0);
label_pho_sele = gtk_label_new(NULL);
if (!pho_in_row1) {
gtk_box_pack_start (GTK_BOX (vbox_top), align, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (align), label_pho_sele);
} else {
GtkWidget *hbox_row1 = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox_top), hbox_row1, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox_row1), event_box_pho, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox_row1), align, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (align), label_pho_sele);
}
hbox_row2 = gtk_hbox_new (FALSE, 0);
/* This packs the button into the gwin_pho (a gtk container). */
gtk_container_add (GTK_CONTAINER (vbox_top), hbox_row2);
label_full = gtk_label_new(_(_L("全")));
gtk_container_add (GTK_CONTAINER (hbox_row2), label_full);
if (!pho_in_row1)
gtk_box_pack_start (GTK_BOX (hbox_row2), event_box_pho, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(event_box_pho),"button-press-event",
G_CALLBACK(mouse_button_callback), NULL);
label_pho = gtk_label_new(NULL);
GtkWidget *frame_pho;
if (gtab_in_area_button) {
gtk_container_add (GTK_CONTAINER (event_box_pho), label_pho);
}
else {
frame_pho = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame_pho), GTK_SHADOW_OUT);
gtk_container_add (GTK_CONTAINER (event_box_pho), frame_pho);
gtk_container_set_border_width (GTK_CONTAINER (frame_pho), 0);
gtk_container_add (GTK_CONTAINER (frame_pho), label_pho);
}
if (left_right_button_tips) {
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text (event_box_pho, _(_L("左鍵符號,右鍵設定")));
#else
GtkTooltips *button_gtab_tips = gtk_tooltips_new ();
gtk_tooltips_set_tip (GTK_TOOLTIPS (button_gtab_tips), event_box_pho, _(_L("左鍵符號,右鍵設定")),NULL);
#endif
}
label_key_codes = gtk_label_new(NULL);
gtk_label_set_selectable(GTK_LABEL(label_key_codes), TRUE);
gtk_box_pack_start (GTK_BOX (hbox_row2), label_key_codes, FALSE, FALSE, 2);
change_pho_font_size();
gtk_widget_show_all (gwin_pho);
gtk_widget_hide(label_key_codes);
gtk_widget_hide(label_full);
}
void create_win_pho_gui()
{
create_win_pho_gui_simple();
if (pho_hide_row2) {
gtk_widget_hide(hbox_row2);
gtk_window_resize(GTK_WINDOW(gwin_pho), 1, 1);
}
current_gcin_inner_frame = gcin_inner_frame;
current_pho_in_row1 = pho_in_row1;
}
gboolean pho_has_input();
void show_win_pho()
{
// dbg("show_win_pho\n");
create_win_pho();
create_win_pho_gui();
if (gcin_pop_up_win && !pho_has_input() &&
inmd[default_input_method].method_type==method_type_PHO)
return;
#if UNIX
if (!GTK_WIDGET_VISIBLE(gwin_pho))
#endif
{
gtk_widget_show(gwin_pho);
move_win_pho(win_x, win_y);
}
gtk_widget_show(gwin_pho);
#if UNIX
if (current_CS->b_raise_window)
#endif
gtk_window_present(GTK_WINDOW(gwin_pho));
show_win_sym();
if (pho_hide_row2)
gtk_widget_hide(hbox_row2);
else
gtk_widget_show(hbox_row2);
}
void hide_win_sym();
void hide_win_pho()
{
// dbg("hide_win_pho\n");
if (!gwin_pho)
return;
#if WIN32
if (timeout_handle_pho) {
g_source_remove(timeout_handle_pho);
timeout_handle_pho = 0;
}
#endif
gtk_widget_hide(gwin_pho);
hide_win_sym();
}
void init_tab_pho();
void get_win_gtab_geom();
void init_gtab_pho_query_win()
{
init_tab_pho();
get_win_gtab_geom();
move_win_pho(win_x, win_y + win_yl);
}
char *get_full_str();
void win_pho_disp_half_full()
{
if (gcin_win_color_use)
gtk_label_set_markup(GTK_LABEL(label_pho), get_full_str());
else
gtk_label_set_text(GTK_LABEL(label_pho), get_full_str());
if (current_CS->im_state == GCIN_STATE_CHINESE && (!current_CS->b_half_full_char))
gtk_widget_hide(label_full);
else
gtk_widget_show(label_full);
minimize_win_pho();
}
void get_win_pho_geom()
{
if (!gwin_pho)
return;
gtk_window_get_position(GTK_WINDOW(gwin_pho), &win_x, &win_y);
get_win_size(gwin_pho, &win_xl, &win_yl);
}
void change_pho_font_size()
{
if (!top_bin)
return;
set_label_font_size(label_pho, gcin_font_size_tsin_pho_in);
set_label_font_size(label_pho_sele, gcin_font_size);
change_win_fg_bg(gwin_pho, label_pho_sele);
}
#if 0
void recreate_win_pho()
{
gtk_widget_destroy(gwin_pho);
top_bin = NULL;
gwin_pho = NULL;
create_win_pho();
create_win_pho_gui_simple();
}
#endif