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
|
/*
Copyright (C) 1994-2008 Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/
#define InAreaX (0)
#include "gcin.h"
#include "intcode.h"
#include "pho.h"
#include "gst.h"
#include "im-client/gcin-im-client-attr.h"
#include "win1.h"
#include "gcin-module.h"
#include "gcin-module-cb.h"
extern GtkWidget *gwin_int;
GCIN_module_main_functions gmf;
int current_intcode = INTCODE_UTF32;
static char inch[MAX_INTCODE];
int intcode_cin;
void create_win_intcode();
void module_show_win();
int module_init_win(GCIN_module_main_functions *funcs)
{
intcode_cin=0;
gmf = *funcs;
create_win_intcode();
return TRUE;
}
static int h2i(int x)
{
return (x<='9'?x-'0':x-'A'+10);
}
static void utf32to8(char *t, char *s)
{
gsize rn,wn=0;
GError *err = NULL;
char *utf8 = g_convert(s, 4, "UTF-8", "UTF-32", &rn, &wn, &err);
if (utf8) {
memcpy(t, utf8, wn);
g_free(utf8);
}
t[wn]=0;
}
void big5_utf8_n(char *s, int len, char out[])
{
out[0]=0;
GError *err = NULL;
gsize rn, wn;
char *utf8 = g_convert(s, len, "UTF-8", "Big5", &rn, &wn, &err);
if (err) {
dbg("big5_utf8 convert error\n");
out[0]=0;
// abort();
return;
}
strcpy(out, utf8);
g_free(utf8);
}
void big5_utf8(char *s, char out[])
{
big5_utf8_n(s, strlen(s), out);
}
static char *dstr[]={
"0", "1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"
};
void disp_int(int index, char *intcode);
void clear_int_code_all();
gboolean module_feedkey(int key, int kvstate)
{
int i;
#if 0
if (key <= XK_KP_9 && key >= XK_KP_0)
key -= XK_KP_0 - '0';
#endif
key=toupper(key);
if (key==XK_BackSpace||key==XK_Delete) {
#if WIN32
if (*gmf.mf_test_mode)
return intcode_cin>0;
#endif
if (intcode_cin)
intcode_cin--;
else
return 0;
goto dispIn;
}
else
if ((key<'0'||key>'F'||(key>'9' && key<'A')) && (key!=' ')){
return 0;
}
if (current_intcode==INTCODE_BIG5) {
if (intcode_cin==0 && key<'8')
return 1;
if (intcode_cin==1 && inch[0]=='F' && key=='F')
return 1;
if (intcode_cin==2 && (key<'4' || (key>'7' && key<'A')))
return 1;
if (intcode_cin==3 && (inch[2]=='7'||inch[2]=='F') && key=='F')
return 1;
}
if (!intcode_cin && key==' ')
return 0;
#if WIN32
if (*gmf.mf_test_mode)
return 1;
#endif
if ((intcode_cin<MAX_INTCODE-1 || (current_intcode!=INTCODE_BIG5 && intcode_cin < MAX_INTCODE)) && key!=' ')
inch[intcode_cin++]=key;
dispIn:
clear_int_code_all();
#if 1
if (intcode_cin)
module_show_win();
#endif
for(i=0;i<intcode_cin;i++) {
disp_int(i, dstr[h2i(inch[i])]);
}
if ((current_intcode==INTCODE_BIG5 && intcode_cin==4 ||
current_intcode==INTCODE_UTF32 && intcode_cin==6) || key==' ') {
u_char utf8[CH_SZ+1];
if (current_intcode==INTCODE_BIG5) {
u_char ttt[3];
ttt[2]=ttt[3]=0;
ttt[0]=(h2i(inch[0])<<4)+h2i(inch[1]);
ttt[1]=(h2i(inch[2])<<4)+h2i(inch[3]);
big5_utf8((char *)ttt, (char *)utf8);
} else {
int i;
u_int v = 0;
for(i=0; i < intcode_cin; i++) {
v <<= 4;
v |= h2i(inch[i]);
}
utf32to8((char *)utf8, (char *)&v);
}
gmf.mf_send_utf8_ch((char *)utf8);
intcode_cin=0;
clear_int_code_all();
}
return 1;
}
extern GtkWidget *gwin_int;
int module_get_preedit(char *str, GCIN_PREEDIT_ATTR attr[], int *cursor, int *comp_flag)
{
#if WIN32 || 1
*comp_flag = intcode_cin>0;
#if 1
if (gwin_int && GTK_WIDGET_VISIBLE(gwin_int))
*comp_flag|=2;
#endif
// dbg("comp_len %x\n", *sub_comp_len);
#endif
str[0]=0;
*cursor=0;
return 0;
}
int module_feedkey_release(KeySym xkey, int kbstate)
{
return 0;
}
int module_flush_input()
{
return FALSE;
}
int module_reset()
{
return TRUE;
}
|