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
|
/*
* $Id$
*/
#include "../x_xic.h"
#include <kiklib/kik_debug.h>
#include <kiklib/kik_str.h> /* kik_str_alloca_dup */
#include <kiklib/kik_mem.h> /* malloc */
#include <kiklib/kik_locale.h> /* kik_get_locale */
#ifdef UTF16_IME_CHAR
#include <mkf/mkf_utf16_parser.h>
#endif
#define HAS_XIM_LISTENER(win,function) \
((win)->xim_listener && (win)->xim_listener->function)
/* --- static functions --- */
static int
get_spot(
x_window_t * win ,
XPoint * spot
)
{
int x ;
int y ;
if( ! HAS_XIM_LISTENER(win,get_spot) ||
win->xim_listener->get_spot( win->xim_listener->self , &x , &y) == 0)
{
#ifdef DEBUG
kik_warn_printf( KIK_DEBUG_TAG " xim_listener->get_spot() failed.\n") ;
#endif
return 0 ;
}
spot->x = x + win->margin ;
spot->y = y /* + win->margin */ ;
return 1 ;
}
/* --- global functions --- */
int
x_xic_activate(
x_window_t * win ,
char * xim_name ,
char * xim_locale
)
{
if( win->xic)
{
/* already activated */
return 0 ;
}
if( ( win->xic = malloc( sizeof( x_xic_t))) == NULL)
{
return 0 ;
}
#ifndef UTF16_IME_CHAR
if( ( win->xic->parser = ml_parser_new(
ml_get_char_encoding( kik_get_codeset_win32()))) == NULL)
#else
/* UTF16LE => UTF16BE in x_xic_get_str. */
if( ( win->xic->parser = mkf_utf16_parser_new()) == NULL)
#endif
{
return 0 ;
}
win->xic->ic = ImmGetContext( win->my_window) ;
win->xic->prev_keydown_wparam = 0 ;
return 1 ;
}
int
x_xic_deactivate(
x_window_t * win
)
{
if( win->xic == NULL)
{
/* already deactivated */
return 0 ;
}
ImmReleaseContext( win->my_window, win->xic->ic) ;
(*win->xic->parser->delete)( win->xic->parser) ;
free( win->xic) ;
win->xic = NULL ;
return 1 ;
}
char *
x_xic_get_xim_name(
x_window_t * win
)
{
return "" ;
}
char *
x_xic_get_default_xim_name(void)
{
return "" ;
}
int
x_xic_fg_color_changed(
x_window_t * win
)
{
return 0 ;
}
int
x_xic_bg_color_changed(
x_window_t * win
)
{
return 0 ;
}
int
x_xic_font_set_changed(
x_window_t * win
)
{
return 0 ;
}
int
x_xic_resized(
x_window_t * win
)
{
return 0 ;
}
int
x_xic_set_spot(
x_window_t * win
)
{
XPoint spot ;
COMPOSITIONFORM cf ;
if( win->xic == NULL)
{
return 0 ;
}
if( get_spot( win, &spot) == 0)
{
return 0 ;
}
MapWindowPoints( win->my_window, x_get_root_window( win)->my_window, &spot, 1) ;
cf.ptCurrentPos = spot ;
cf.dwStyle = CFS_POINT ;
return ImmSetCompositionWindow( win->xic->ic, &cf) ;
}
size_t
x_xic_get_str(
x_window_t * win ,
u_char * seq ,
size_t seq_len ,
mkf_parser_t ** parser ,
KeySym * keysym ,
XKeyEvent * event
)
{
size_t len ;
if( seq_len == 0 || event->ch == 0)
{
goto zero_return ;
}
else if( event->state & ControlMask)
{
if( event->ch == '2' || event->ch == ' ')
{
event->ch = 0 ;
}
else if( '3' <= event->ch && event->ch <= '7')
{
/* '3' => 0x1b '4' => 0x1c '5' => 0x1d '6' => 0x1e '7' => 0x1f */
event->ch -= 0x18 ;
}
else if( event->ch == '8')
{
event->ch = 0x7f ;
}
else if( event->ch == '^')
{
event->ch = 0x1d ;
}
else if( event->ch == '_' || event->ch == '/')
{
event->ch = 0x1f ;
}
}
#ifndef UTF16_IME_CHAR
len = 1 ;
if( event->ch > 0xff)
{
*(seq++) = (char)((event->ch >> 8) & 0xff) ;
if( seq_len == 1)
{
goto zero_return ;
}
len ++ ;
}
*seq = (char)(event->ch & 0xff) ;
#else
if( seq_len == 1)
{
goto zero_return ;
}
*(seq++) = (char)((event->ch >> 8) & 0xff) ;
*seq = (char)(event->ch & 0xff) ;
len = 2 ;
#endif
*parser = win->xic->parser ;
*keysym = win->xic->prev_keydown_wparam ;
win->xic->prev_keydown_wparam = 0 ;
return len ;
zero_return:
*parser = NULL ;
*keysym = win->xic->prev_keydown_wparam ;
win->xic->prev_keydown_wparam = 0 ;
return 0 ;
}
size_t
x_xic_get_utf8_str(
x_window_t * win ,
u_char * seq ,
size_t seq_len ,
mkf_parser_t ** parser ,
KeySym * keysym ,
XKeyEvent * event
)
{
return 0 ;
}
int
x_xic_filter_event(
x_window_t * win, /* Should be root window. */
XEvent * event
)
{
u_int count ;
if( event->msg != WM_KEYDOWN)
{
return 0 ;
}
for( count = 0 ; count < win->num_of_children ; count++)
{
x_xic_filter_event( win->children[count], event) ;
}
if( ! win->xic)
{
return 0 ;
}
win->xic->prev_keydown_wparam = event->wparam ;
return 1 ;
}
int
x_xic_set_focus(
x_window_t * win
)
{
return 1 ;
}
int
x_xic_unset_focus(
x_window_t * win
)
{
return 1 ;
}
int
x_xic_is_active(
x_window_t * win
)
{
if( win->xic == NULL)
{
return 0 ;
}
return ImmGetOpenStatus( win->xic->ic) ;
}
int
x_xic_switch_mode(
x_window_t * win
)
{
if( win->xic == NULL)
{
return 0 ;
}
return ImmSetOpenStatus( win->xic->ic , (ImmGetOpenStatus( win->xic->ic) == FALSE)) ;
}
#if 0
/*
* x_xim.c <-> x_xic.c communication functions
* Not necessary in win32.
*/
int
x_xim_activated(
x_window_t * win
)
{
return 1 ;
}
int
x_xim_destroyed(
x_window_t * win
)
{
return 1 ;
}
#endif
|