1 #include "gcin.h"
2 #include "pho.h"
3 #include "win-sym.h"
4 #include "gst.h"
5 #include "tsin.h"
6
7
8 static GtkWidget *phrase_save_win;
9
destroy_phrase_save_menu()10 void destroy_phrase_save_menu()
11 {
12 if (!phrase_save_win)
13 return;
14 gtk_widget_destroy(phrase_save_win);
15 phrase_save_win = NULL;
16 }
17
18 void save_phrase(int save_frm, int len);
cb_clicked(GtkWidget * widget,gpointer data)19 static void cb_clicked(GtkWidget *widget, gpointer data)
20 {
21 destroy_phrase_save_menu();
22
23 int v = GPOINTER_TO_INT(data);
24 int len = v & 0xff;
25 int idx = v >> 8;
26
27 if (!len)
28 return;
29
30 save_phrase(idx, len);
31 }
32
33 void chpho_extract(CHPHO *chph, int len, phokey_t *pho, char *ch);
34
add_button(GtkWidget * vbox,char * s,int idx,int len)35 static void add_button(GtkWidget *vbox, char *s, int idx, int len)
36 {
37 int data = (int)((idx << 8) | len);
38
39 GtkWidget *but = gtk_button_new_with_label(s);
40 gtk_box_pack_start (GTK_BOX (vbox), but, FALSE, FALSE, 0);
41 g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (cb_clicked), GINT_TO_POINTER(data));
42 }
43
create_phrase_save_menu(GdkEventButton * event)44 void create_phrase_save_menu(GdkEventButton * event)
45 {
46 destroy_phrase_save_menu();
47
48 int len = tss.c_len - tss.c_idx;
49 if ((len < 2 || len > MAX_PHRASE_LEN) && tss.c_idx < 2)
50 return;
51
52 phrase_save_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
53 gtk_window_set_has_resize_grip(GTK_WINDOW(phrase_save_win), FALSE);
54 #if WIN32
55 set_no_focus(phrase_save_win);
56 #endif
57 gtk_widget_realize (phrase_save_win);
58
59 #if UNIX
60 set_no_focus(phrase_save_win);
61 #else
62 win32_init_win(phrase_save_win);
63 #endif
64 GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
65 gtk_container_add(GTK_CONTAINER(phrase_save_win), vbox);
66 char tt[512];
67
68 add_button(vbox, _(_L("關閉")), 0, 0);
69
70 GtkWidget *label = gtk_label_new(_(_L("--- 加到詞庫 ---")));
71 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
72
73
74 if (len > 1 && len < MAX_PHRASE_LEN) {
75 phokey_t phs[MAX_PHRASE_LEN];
76 char str[MAX_PHRASE_STR_LEN];
77 chpho_extract(&tss.chpho[tss.c_idx], len, phs, str);
78 sprintf(tt, _(_L("%s shift-Enter")), str);
79 add_button(vbox, tt, tss.c_idx, len);
80 }
81
82 if (tss.c_idx > 1) {
83 for(len=2; len <= tss.c_idx && len <= 5; len++) {
84 phokey_t phs[MAX_PHRASE_LEN];
85 char str[MAX_PHRASE_STR_LEN];
86 chpho_extract(&tss.chpho[tss.c_idx - len], len, phs, str);
87 sprintf(tt, _(_L("%s Ctrl-%d")), str, len);
88 add_button(vbox, tt, tss.c_idx, len);
89 }
90 }
91
92 gtk_widget_show_all(phrase_save_win);
93 int x, y, w_xl, w_yl;
94
95 get_win_size(phrase_save_win, &w_xl, &w_yl);
96 x = win_x;
97 if (x + w_xl > dpy_xl)
98 x = dpy_xl - w_xl;
99
100 y = win_y + win_yl;
101 if (y + w_yl > dpy_yl)
102 y = win_y - w_yl;
103
104 gtk_window_move(GTK_WINDOW(phrase_save_win), x, y);
105 }
106