diff options
Diffstat (limited to 'unix/tkUnixKey.c')
-rw-r--r-- | unix/tkUnixKey.c | 98 |
1 files changed, 48 insertions, 50 deletions
diff --git a/unix/tkUnixKey.c b/unix/tkUnixKey.c index f422111..d07f13a 100644 --- a/unix/tkUnixKey.c +++ b/unix/tkUnixKey.c @@ -23,7 +23,7 @@ * Tk_SetCaretPos -- * * This enables correct placement of the XIM caret. This is called by - * widgets to indicate their cursor placement. This is currently only + * widgets to indicate their cursor placement. This is currently only * used for over-the-spot XIM. * *---------------------------------------------------------------------- @@ -39,11 +39,10 @@ Tk_SetCaretPos( TkWindow *winPtr = (TkWindow *) tkwin; TkDisplay *dispPtr = winPtr->dispPtr; - if ( dispPtr->caret.winPtr == winPtr - && dispPtr->caret.x == x - && dispPtr->caret.y == y - && dispPtr->caret.height == height) - { + if ((dispPtr->caret.winPtr == winPtr) + && (dispPtr->caret.x == x) + && (dispPtr->caret.y == y) + && (dispPtr->caret.height == height)) { return; } @@ -52,22 +51,21 @@ Tk_SetCaretPos( dispPtr->caret.y = y; dispPtr->caret.height = height; -#ifdef TK_USE_INPUT_METHODS /* * Adjust the XIM caret position. */ - if ( (dispPtr->flags & TK_DISPLAY_USE_IM) - && (dispPtr->inputStyle & XIMPreeditPosition) - && (winPtr->inputContext != NULL) ) - { + +#ifdef TK_USE_INPUT_METHODS + if ((dispPtr->flags & TK_DISPLAY_USE_IM) + && (dispPtr->inputStyle & XIMPreeditPosition) + && (winPtr->inputContext != NULL)) { XVaNestedList preedit_attr; XPoint spot; spot.x = dispPtr->caret.x; spot.y = dispPtr->caret.y + dispPtr->caret.height; preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); - XSetICValues(winPtr->inputContext, - XNPreeditAttributes, preedit_attr, + XSetICValues(winPtr->inputContext, XNPreeditAttributes, preedit_attr, NULL); XFree(preedit_attr); } @@ -92,7 +90,7 @@ Tk_SetCaretPos( *---------------------------------------------------------------------- */ -char * +const char * TkpGetString( TkWindow *winPtr, /* Window where event occurred */ XEvent *eventPtr, /* X keyboard event. */ @@ -116,8 +114,7 @@ TkpGetString( #ifdef TK_USE_INPUT_METHODS if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM) && (winPtr->inputContext != NULL) - && (eventPtr->type == KeyPress)) - { + && (eventPtr->type == KeyPress)) { Status status; #if X_HAVE_UTF8_STRING @@ -126,10 +123,14 @@ TkpGetString( Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), &kePtr->keysym, &status); - if (status == XBufferOverflow) { /* Expand buffer and try again */ + if (status == XBufferOverflow) { + /* + * Expand buffer and try again. + */ + Tcl_DStringSetLength(dsPtr, len); len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey, - Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), + Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), &kePtr->keysym, &status); } if ((status != XLookupChars) && (status != XLookupBoth)) { @@ -143,9 +144,8 @@ TkpGetString( Tcl_DStringInit(&buf); Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1); - len = XmbLookupString(winPtr->inputContext, &eventPtr->xkey, - Tcl_DStringValue(&buf), Tcl_DStringLength(&buf), + Tcl_DStringValue(&buf), Tcl_DStringLength(&buf), &kePtr->keysym, &status); /* @@ -160,7 +160,6 @@ TkpGetString( if ((status != XLookupChars) && (status != XLookupBoth)) { len = 0; } - Tcl_DStringSetLength(&buf, len); Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buf), len, dsPtr); Tcl_DStringFree(&buf); @@ -204,7 +203,7 @@ TkpGetString( * from having to reenter the XIM engine. [Bug 1373712] */ - kePtr->charValuePtr = ckalloc((unsigned) len + 1); + kePtr->charValuePtr = ckalloc(len + 1); kePtr->charValueLen = len; memcpy(kePtr->charValuePtr, Tcl_DStringValue(dsPtr), (unsigned) len + 1); return Tcl_DStringValue(dsPtr); @@ -222,30 +221,27 @@ TkpSetKeycodeAndState( KeySym keySym, XEvent *eventPtr) { - Display *display; + Display *display = Tk_Display(tkwin); int state; KeyCode keycode; - display = Tk_Display(tkwin); - if (keySym == NoSymbol) { keycode = 0; } else { keycode = XKeysymToKeycode(display, keySym); - } - if (keycode != 0) { - for (state = 0; state < 4; state++) { - if (XkbKeycodeToKeysym(display, keycode, 0, state) == keySym) { - if (state & 1) { - eventPtr->xkey.state |= ShiftMask; + if (keycode != 0) { + for (state = 0; state < 4; state++) { + if (XkbKeycodeToKeysym(display, keycode, 0, state) == keySym){ + if (state & 1) { + eventPtr->xkey.state |= ShiftMask; + } + if (state & 2) { + TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; + + eventPtr->xkey.state |= dispPtr->modeModMask; + } + break; } - if (state & 2) { - TkDisplay *dispPtr; - - dispPtr = ((TkWindow *) tkwin)->dispPtr; - eventPtr->xkey.state |= dispPtr->modeModMask; - } - break; } } } @@ -281,7 +277,7 @@ TkpGetKeySym( TkKeyEvent* kePtr = (TkKeyEvent*) eventPtr; #ifdef TK_USE_INPUT_METHODS - /* + /* * If input methods are active, we may already have determined a keysym. * Return it. */ @@ -422,7 +418,7 @@ TkpInitKeymapInfo( dispPtr->metaModMask = 0; dispPtr->altModMask = 0; codePtr = modMapPtr->modifiermap; - max = 8*modMapPtr->max_keypermod; + max = 8 * modMapPtr->max_keypermod; for (i = 0; i < max; i++, codePtr++) { if (*codePtr == 0) { continue; @@ -444,12 +440,11 @@ TkpInitKeymapInfo( */ if (dispPtr->modKeyCodes != NULL) { - ckfree((char *) dispPtr->modKeyCodes); + ckfree(dispPtr->modKeyCodes); } dispPtr->numModKeyCodes = 0; arraySize = KEYCODE_ARRAY_SIZE; - dispPtr->modKeyCodes = (KeyCode *) - ckalloc((unsigned) (KEYCODE_ARRAY_SIZE * sizeof(KeyCode))); + dispPtr->modKeyCodes = ckalloc(KEYCODE_ARRAY_SIZE * sizeof(KeyCode)); for (i = 0, codePtr = modMapPtr->modifiermap; i < max; i++, codePtr++) { if (*codePtr == 0) { continue; @@ -461,23 +456,26 @@ TkpInitKeymapInfo( for (j = 0; j < dispPtr->numModKeyCodes; j++) { if (dispPtr->modKeyCodes[j] == *codePtr) { + /* + * 'continue' the outer loop. + */ + goto nextModCode; } } if (dispPtr->numModKeyCodes >= arraySize) { - KeyCode *new; + KeyCode *newCodes; /* * Ran out of space in the array; grow it. */ arraySize *= 2; - new = (KeyCode *) - ckalloc((unsigned) (arraySize * sizeof(KeyCode))); - memcpy(new, dispPtr->modKeyCodes, - (dispPtr->numModKeyCodes * sizeof(KeyCode))); - ckfree((char *) dispPtr->modKeyCodes); - dispPtr->modKeyCodes = new; + newCodes = ckalloc(arraySize * sizeof(KeyCode)); + memcpy(newCodes, dispPtr->modKeyCodes, + dispPtr->numModKeyCodes * sizeof(KeyCode)); + ckfree(dispPtr->modKeyCodes); + dispPtr->modKeyCodes = newCodes; } dispPtr->modKeyCodes[dispPtr->numModKeyCodes] = *codePtr; dispPtr->numModKeyCodes++; |