| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tkInt.h" |
| 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 |
void |
| 42 |
Tk_SetCaretPos(tkwin, x, y, height) |
| 43 |
Tk_Window tkwin; |
| 44 |
int x; |
| 45 |
int y; |
| 46 |
int height; |
| 47 |
{ |
| 48 |
TkCaret *caretPtr = &(((TkWindow *) tkwin)->dispPtr->caret); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
caretPtr->winPtr = ((TkWindow *) tkwin); |
| 55 |
caretPtr->x = x; |
| 56 |
caretPtr->y = y; |
| 57 |
caretPtr->height = height; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
char * |
| 79 |
TkpGetString(winPtr, eventPtr, dsPtr) |
| 80 |
TkWindow *winPtr; |
| 81 |
|
| 82 |
XEvent *eventPtr; |
| 83 |
Tcl_DString *dsPtr; |
| 84 |
|
| 85 |
{ |
| 86 |
int len; |
| 87 |
Tcl_DString buf; |
| 88 |
Status status; |
| 89 |
#ifdef TK_USE_INPUT_METHODS |
| 90 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 91 |
#endif |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
#ifdef TK_USE_INPUT_METHODS |
| 98 |
if ((dispPtr->flags & TK_DISPLAY_USE_IM) |
| 99 |
&& (winPtr->inputContext != NULL) |
| 100 |
&& (eventPtr->type == KeyPress)) { |
| 101 |
#if TK_XIM_SPOT |
| 102 |
XVaNestedList preedit_attr; |
| 103 |
XPoint spot; |
| 104 |
#endif |
| 105 |
|
| 106 |
#ifdef X_HAVE_UTF8_STRING |
| 107 |
Tcl_DStringInit(dsPtr); |
| 108 |
Tcl_DStringSetLength(dsPtr, TCL_DSTRING_STATIC_SIZE-1); |
| 109 |
len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey, |
| 110 |
Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), |
| 111 |
(KeySym *) NULL, &status); |
| 112 |
#else |
| 113 |
Tcl_DStringInit(&buf); |
| 114 |
Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1); |
| 115 |
len = XmbLookupString(winPtr->inputContext, &eventPtr->xkey, |
| 116 |
Tcl_DStringValue(&buf), Tcl_DStringLength(&buf), |
| 117 |
(KeySym *) NULL, &status); |
| 118 |
#endif |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
if (status == XBufferOverflow) { |
| 124 |
#ifdef X_HAVE_UTF8_STRING |
| 125 |
Tcl_DStringSetLength(dsPtr, len); |
| 126 |
len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey, |
| 127 |
Tcl_DStringValue(dsPtr), len, (KeySym *) NULL, &status); |
| 128 |
#else |
| 129 |
Tcl_DStringSetLength(&buf, len); |
| 130 |
len = XmbLookupString(winPtr->inputContext, &eventPtr->xkey, |
| 131 |
Tcl_DStringValue(&buf), len, (KeySym *) NULL, &status); |
| 132 |
#endif |
| 133 |
} |
| 134 |
if ((status != XLookupChars) && (status != XLookupBoth)) { |
| 135 |
len = 0; |
| 136 |
} |
| 137 |
|
| 138 |
#if TK_XIM_SPOT |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
if (dispPtr->flags & TK_DISPLAY_XIM_SPOT) { |
| 144 |
spot.x = dispPtr->caret.x; |
| 145 |
spot.y = dispPtr->caret.y + dispPtr->caret.height; |
| 146 |
preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); |
| 147 |
XSetICValues(winPtr->inputContext, |
| 148 |
XNPreeditAttributes, preedit_attr, NULL); |
| 149 |
XFree(preedit_attr); |
| 150 |
} |
| 151 |
#endif |
| 152 |
#ifdef X_HAVE_UTF8_STRING |
| 153 |
Tcl_DStringSetLength(dsPtr, len); |
| 154 |
return Tcl_DStringValue(dsPtr); |
| 155 |
#endif |
| 156 |
} else { |
| 157 |
Tcl_DStringInit(&buf); |
| 158 |
Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1); |
| 159 |
len = XLookupString(&eventPtr->xkey, Tcl_DStringValue(&buf), |
| 160 |
Tcl_DStringLength(&buf), (KeySym *) NULL, |
| 161 |
(XComposeStatus *) NULL); |
| 162 |
} |
| 163 |
#else |
| 164 |
Tcl_DStringInit(&buf); |
| 165 |
Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1); |
| 166 |
len = XLookupString(&eventPtr->xkey, Tcl_DStringValue(&buf), |
| 167 |
Tcl_DStringLength(&buf), (KeySym *) NULL, |
| 168 |
(XComposeStatus *) NULL); |
| 169 |
#endif |
| 170 |
Tcl_DStringSetLength(&buf, len); |
| 171 |
|
| 172 |
Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buf), len, dsPtr); |
| 173 |
Tcl_DStringFree(&buf); |
| 174 |
|
| 175 |
return Tcl_DStringValue(dsPtr); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
void |
| 187 |
TkpSetKeycodeAndState(tkwin, keySym, eventPtr) |
| 188 |
Tk_Window tkwin; |
| 189 |
KeySym keySym; |
| 190 |
XEvent *eventPtr; |
| 191 |
{ |
| 192 |
Display *display; |
| 193 |
int state; |
| 194 |
KeyCode keycode; |
| 195 |
|
| 196 |
display = Tk_Display(tkwin); |
| 197 |
|
| 198 |
if (keySym == NoSymbol) { |
| 199 |
keycode = 0; |
| 200 |
} else { |
| 201 |
keycode = XKeysymToKeycode(display, keySym); |
| 202 |
} |
| 203 |
if (keycode != 0) { |
| 204 |
for (state = 0; state < 4; state++) { |
| 205 |
if (XKeycodeToKeysym(display, keycode, state) == keySym) { |
| 206 |
if (state & 1) { |
| 207 |
eventPtr->xkey.state |= ShiftMask; |
| 208 |
} |
| 209 |
if (state & 2) { |
| 210 |
TkDisplay *dispPtr; |
| 211 |
|
| 212 |
dispPtr = ((TkWindow *) tkwin)->dispPtr; |
| 213 |
eventPtr->xkey.state |= dispPtr->modeModMask; |
| 214 |
} |
| 215 |
break; |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
eventPtr->xkey.keycode = keycode; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
KeySym |
| 243 |
TkpGetKeySym(dispPtr, eventPtr) |
| 244 |
TkDisplay *dispPtr; |
| 245 |
|
| 246 |
XEvent *eventPtr; |
| 247 |
{ |
| 248 |
KeySym sym; |
| 249 |
int index; |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
if (dispPtr->bindInfoStale) { |
| 256 |
TkpInitKeymapInfo(dispPtr); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
index = 0; |
| 266 |
if (eventPtr->xkey.state & dispPtr->modeModMask) { |
| 267 |
index = 2; |
| 268 |
} |
| 269 |
if ((eventPtr->xkey.state & ShiftMask) |
| 270 |
|| ((dispPtr->lockUsage != LU_IGNORE) |
| 271 |
&& (eventPtr->xkey.state & LockMask))) { |
| 272 |
index += 1; |
| 273 |
} |
| 274 |
sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, index); |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
if ((index & 1) && !(eventPtr->xkey.state & ShiftMask) |
| 284 |
&& (dispPtr->lockUsage == LU_CAPS)) { |
| 285 |
if (!(((sym >= XK_A) && (sym <= XK_Z)) |
| 286 |
|| ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis)) |
| 287 |
|| ((sym >= XK_Ooblique) && (sym <= XK_Thorn)))) { |
| 288 |
index &= ~1; |
| 289 |
sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, |
| 290 |
index); |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
if ((index & 1) && (sym == NoSymbol)) { |
| 300 |
sym = XKeycodeToKeysym(dispPtr->display, eventPtr->xkey.keycode, |
| 301 |
index & ~1); |
| 302 |
} |
| 303 |
return sym; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
void |
| 326 |
TkpInitKeymapInfo(dispPtr) |
| 327 |
TkDisplay *dispPtr; |
| 328 |
|
| 329 |
{ |
| 330 |
XModifierKeymap *modMapPtr; |
| 331 |
KeyCode *codePtr; |
| 332 |
KeySym keysym; |
| 333 |
int count, i, j, max, arraySize; |
| 334 |
#define KEYCODE_ARRAY_SIZE 20 |
| 335 |
|
| 336 |
dispPtr->bindInfoStale = 0; |
| 337 |
modMapPtr = XGetModifierMapping(dispPtr->display); |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
dispPtr->lockUsage = LU_IGNORE; |
| 346 |
codePtr = modMapPtr->modifiermap + modMapPtr->max_keypermod*LockMapIndex; |
| 347 |
for (count = modMapPtr->max_keypermod; count > 0; count--, codePtr++) { |
| 348 |
if (*codePtr == 0) { |
| 349 |
continue; |
| 350 |
} |
| 351 |
keysym = XKeycodeToKeysym(dispPtr->display, *codePtr, 0); |
| 352 |
if (keysym == XK_Shift_Lock) { |
| 353 |
dispPtr->lockUsage = LU_SHIFT; |
| 354 |
break; |
| 355 |
} |
| 356 |
if (keysym == XK_Caps_Lock) { |
| 357 |
dispPtr->lockUsage = LU_CAPS; |
| 358 |
break; |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
dispPtr->modeModMask = 0; |
| 369 |
dispPtr->metaModMask = 0; |
| 370 |
dispPtr->altModMask = 0; |
| 371 |
codePtr = modMapPtr->modifiermap; |
| 372 |
max = 8*modMapPtr->max_keypermod; |
| 373 |
for (i = 0; i < max; i++, codePtr++) { |
| 374 |
if (*codePtr == 0) { |
| 375 |
continue; |
| 376 |
} |
| 377 |
keysym = XKeycodeToKeysym(dispPtr->display, *codePtr, 0); |
| 378 |
if (keysym == XK_Mode_switch) { |
| 379 |
dispPtr->modeModMask |= ShiftMask << (i/modMapPtr->max_keypermod); |
| 380 |
} |
| 381 |
if ((keysym == XK_Meta_L) || (keysym == XK_Meta_R)) { |
| 382 |
dispPtr->metaModMask |= ShiftMask << (i/modMapPtr->max_keypermod); |
| 383 |
} |
| 384 |
if ((keysym == XK_Alt_L) || (keysym == XK_Alt_R)) { |
| 385 |
dispPtr->altModMask |= ShiftMask << (i/modMapPtr->max_keypermod); |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
if (dispPtr->modKeyCodes != NULL) { |
| 394 |
ckfree((char *) dispPtr->modKeyCodes); |
| 395 |
} |
| 396 |
dispPtr->numModKeyCodes = 0; |
| 397 |
arraySize = KEYCODE_ARRAY_SIZE; |
| 398 |
dispPtr->modKeyCodes = (KeyCode *) ckalloc((unsigned) |
| 399 |
(KEYCODE_ARRAY_SIZE * sizeof(KeyCode))); |
| 400 |
for (i = 0, codePtr = modMapPtr->modifiermap; i < max; i++, codePtr++) { |
| 401 |
if (*codePtr == 0) { |
| 402 |
continue; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
for (j = 0; j < dispPtr->numModKeyCodes; j++) { |
| 410 |
if (dispPtr->modKeyCodes[j] == *codePtr) { |
| 411 |
goto nextModCode; |
| 412 |
} |
| 413 |
} |
| 414 |
if (dispPtr->numModKeyCodes >= arraySize) { |
| 415 |
KeyCode *new; |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
arraySize *= 2; |
| 422 |
new = (KeyCode *) ckalloc((unsigned) |
| 423 |
(arraySize * sizeof(KeyCode))); |
| 424 |
memcpy((VOID *) new, (VOID *) dispPtr->modKeyCodes, |
| 425 |
(dispPtr->numModKeyCodes * sizeof(KeyCode))); |
| 426 |
ckfree((char *) dispPtr->modKeyCodes); |
| 427 |
dispPtr->modKeyCodes = new; |
| 428 |
} |
| 429 |
dispPtr->modKeyCodes[dispPtr->numModKeyCodes] = *codePtr; |
| 430 |
dispPtr->numModKeyCodes++; |
| 431 |
nextModCode: continue; |
| 432 |
} |
| 433 |
XFreeModifiermap(modMapPtr); |
| 434 |
} |