forked from hime-ime/hime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhime-common.cpp
199 lines (173 loc) · 4.24 KB
/
hime-common.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
/* Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "hime.h"
#include "pho.h"
#if USE_TSIN
void flush_tsin_buffer();
#endif
PIN_JUYIN *pin_juyin;
int text_pho_N=3;
gboolean b_use_full_space = TRUE;
static char text_pho[6][CH_SZ];
void bell()
{
if (hime_bell_off)
return;
#if UNIX
XBell(dpy, hime_bell_volume);
#else
gdk_beep();
#endif
// abort();
}
void case_inverse(KeySym *xkey, int shift_m)
{
if (*xkey > 0x7e)
return;
if (shift_m) {
if (islower(*xkey))
*xkey-=0x20;
} else
if (isupper(*xkey))
*xkey+=0x20;
}
gint64 current_time()
{
#if WIN32
gint64 v = (gint64)GetTickCount()*1000;
// dbg("v %lld\n", v);
return v;
#else
struct timeval tval;
gettimeofday(&tval, NULL);
return (gint64)tval.tv_sec * 1000000 + tval.tv_usec;
#endif
}
void disp_pho_sub(GtkWidget *label, int index, char *pho)
{
if (!label)
return;
if (index>=text_pho_N)
return;
if (pho[0]==' ' && !pin_juyin) {
u8cpy(text_pho[index], _(_L(" ")));
}
else {
u8cpy(text_pho[index], pho);
}
#if UNIX
char s[text_pho_N * CH_SZ+1];
#else
char *s = new char[text_pho_N * CH_SZ+1];
#endif
int tn = 0;
int i;
for(i=0; i < text_pho_N; i++) {
int n = utf8cpy(s + tn, text_pho[i]);
tn += n;
}
// gtk_widget_show(label);
gtk_label_set_text(GTK_LABEL(label), s);
#if WIN32
delete s;
#endif
}
void exec_hime_setup()
{
dbg("exec hime\n");
#if UNIX
if (geteuid() < 100 || getegid() < 100)
return;
#else
if (getenv("WIN_LOGON"))
return;
#endif
#if 0
char pidstr[32];
sprintf(pidstr, "HIME_PID=%d",
#if UNIX
getpid()
#else
GetCurrentProcessId()
#endif
);
putenv(pidstr);
#endif
#if UNIX
system(HIME_BIN_DIR"/hime-setup &");
#else
win32exec("hime-setup.exe");
#endif
}
void set_label_font_size(GtkWidget *label, int size)
{
if (!label)
return;
PangoContext *pango_context = gtk_widget_get_pango_context (label);
PangoFontDescription* font=pango_context_get_font_description (pango_context);
#if 0
pango_font_description_set_family(font, hime_font_name);
pango_font_description_set_size(font, PANGO_SCALE * size);
#else
char tt[256];
sprintf(tt, "%s %d", hime_font_name, size);
PangoFontDescription* nfont = pango_font_description_from_string(tt);
pango_font_description_merge(font, nfont, TRUE);
pango_font_description_free(nfont);
#endif
gtk_widget_override_font(label, font);
}
// the width of ascii space in firefly song
void set_label_space(GtkWidget *label)
{
gtk_label_set_text(GTK_LABEL(label), "\xe3\x80\x80");
return;
}
void set_no_focus(GtkWidget *win)
{
#if UNIX
gdk_window_set_override_redirect(gtk_widget_get_window(win), TRUE);
#else
gtk_window_set_decorated(GTK_WINDOW(win), FALSE);
gtk_window_set_keep_above(GTK_WINDOW(win), TRUE);
gtk_window_set_accept_focus(GTK_WINDOW(win), FALSE);
gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_TOOLTIP);
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(win), TRUE);
#endif
gtk_window_set_accept_focus(GTK_WINDOW(win), FALSE);
gtk_window_set_focus_on_map (GTK_WINDOW(win), FALSE);
}
#if !USE_TSIN
void add_to_tsin_buf(){}
void add_to_tsin_buf_str(){}
void build_ts_gtab(){}
void change_tsin_color(){}
void change_tsin_font_size(){}
void change_win0_style(){}
void clear_ch_buf_sel_area(){}
void clear_tsin_buffer(){}
void destroy_win0(){}
void destroy_win1(){}
void free_tsin(){}
void load_ts_gtab(){}
void load_tsin_db(){}
void putbuf(){}
void tsin_remove_last(){}
void tsin_reset_in_pho(){}
void tsin_set_eng_ch(){}
void tsin_toggle_half_full(){}
#endif