diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2008-11-26 15:56:37 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2008-11-26 15:56:37 (GMT) |
commit | a3f4e672b7776ad620f5bc519ed88a5366d0a927 (patch) | |
tree | 32207129bc4af526d0f74885fdececc8a860f965 /unix/tkUnixKey.c | |
parent | 1c05251e57f9a18ea76fe0cbdaa590c601191506 (diff) | |
download | tk-a3f4e672b7776ad620f5bc519ed88a5366d0a927.zip tk-a3f4e672b7776ad620f5bc519ed88a5366d0a927.tar.gz tk-a3f4e672b7776ad620f5bc519ed88a5366d0a927.tar.bz2 |
Making code neater...
Diffstat (limited to 'unix/tkUnixKey.c')
-rw-r--r-- | unix/tkUnixKey.c | 146 |
1 files changed, 64 insertions, 82 deletions
diff --git a/unix/tkUnixKey.c b/unix/tkUnixKey.c index a800d73..77e782f 100644 --- a/unix/tkUnixKey.c +++ b/unix/tkUnixKey.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkUnixKey.c,v 1.14 2008/06/11 00:41:43 jenglish Exp $ + * RCS: @(#) $Id: tkUnixKey.c,v 1.15 2008/11/26 15:56:37 dkf Exp $ */ #include "tkInt.h" @@ -24,7 +24,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. * *---------------------------------------------------------------------- @@ -40,11 +40,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; } @@ -53,22 +52,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); } @@ -82,13 +80,13 @@ Tk_SetCaretPos( * * Convert a keyboard event to a UTF-8 string using XLookupString. * - * This is used as a fallback instead of Xutf8LookupString - * or XmbLookupString if input methods are turned off - * and for KeyRelease events. + * This is used as a fallback instead of Xutf8LookupString or + * XmbLookupString if input methods are turned off and for KeyRelease + * events. * * Notes: - * XLookupString() normally returns a single ISO Latin 1 - * or ASCII control character. + * XLookupString() normally returns a single ISO Latin 1 or ASCII control + * character. * *---------------------------------------------------------------------- */ @@ -104,13 +102,15 @@ TkpGetChar( buf[len] = '\0'; if (len == 1) { - len = Tcl_UniCharToUtf((unsigned char)buf[0], Tcl_DStringValue(dsPtr)); + len = Tcl_UniCharToUtf((unsigned char) buf[0], + Tcl_DStringValue(dsPtr)); Tcl_DStringSetLength(dsPtr, len); } else { /* * len > 1 should only happen if someone has called XRebindKeysym(). * Assume UTF-8. */ + Tcl_DStringSetLength(dsPtr, len); strncpy(Tcl_DStringValue(dsPtr), buf, len); } @@ -140,22 +140,25 @@ TkpGetString( TkWindow *winPtr, /* Window where event occurred */ XEvent *eventPtr, /* X keyboard event. */ Tcl_DString *dsPtr) /* Initialized, empty string to hold result. */ -#ifdef TK_USE_INPUT_METHODS -#if X_HAVE_UTF8_STRING { +#ifdef TK_USE_INPUT_METHODS if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM) && (winPtr->inputContext != NULL) - && (eventPtr->type == KeyPress)) - { + && (eventPtr->type == KeyPress)) { int len; Status status; +#if X_HAVE_UTF8_STRING Tcl_DStringSetLength(dsPtr, TCL_DSTRING_STATIC_SIZE-1); len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey, Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), NULL, &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), @@ -166,29 +169,15 @@ TkpGetString( len = 0; } Tcl_DStringSetLength(dsPtr, len); - - return Tcl_DStringValue(dsPtr); - } else { - return TkpGetChar(eventPtr, dsPtr); - } -} #else /* !X_HAVE_UTF8_STRING */ -{ - int len; - Tcl_DString buf; - Status status; - - /* - * Overallocate the dstring to the maximum stack amount. - */ - - Tcl_DStringInit(&buf); - Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1); + Tcl_DString buf; /* Holds string in system encoding. */ - if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM) - && (winPtr->inputContext != NULL) - && (eventPtr->type == KeyPress)) { + /* + * Overallocate the dstring to the maximum stack amount. + */ + Tcl_DStringInit(&buf); + Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1); len = XmbLookupString(winPtr->inputContext, &eventPtr->xkey, Tcl_DStringValue(&buf), Tcl_DStringLength(&buf), NULL, &status); @@ -205,24 +194,16 @@ TkpGetString( if ((status != XLookupChars) && (status != XLookupBoth)) { len = 0; } - } else { - return TkpGetChar(eventPtr, dsPtr); - } - - Tcl_DStringSetLength(&buf, len); - Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buf), len, dsPtr); - Tcl_DStringFree(&buf); - - return Tcl_DStringValue(dsPtr); -} - + Tcl_DStringSetLength(&buf, len); + Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buf), len, dsPtr); + Tcl_DStringFree(&buf); #endif /* X_HAVE_UTF8_STRING */ -#else /* !TK_USE_INPUT_METHODS */ -{ + + return Tcl_DStringValue(dsPtr); + } +#endif /* TK_USE_INPUT_METHODS */ return TkpGetChar(eventPtr, dsPtr); } -#endif - /* * When mapping from a keysym to a keycode, need information about the @@ -236,30 +217,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 (XKeycodeToKeysym(display, keycode, state) == keySym) { - if (state & 1) { - eventPtr->xkey.state |= ShiftMask; + if (keycode != 0) { + for (state = 0; state < 4; state++) { + if (XKeycodeToKeysym(display, keycode, 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; } } } @@ -412,7 +390,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; @@ -451,23 +429,27 @@ 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 *) + newCodes = (KeyCode *) ckalloc((unsigned) (arraySize * sizeof(KeyCode))); - memcpy(new, dispPtr->modKeyCodes, - (dispPtr->numModKeyCodes * sizeof(KeyCode))); + memcpy(newCodes, dispPtr->modKeyCodes, + dispPtr->numModKeyCodes * sizeof(KeyCode)); ckfree((char *) dispPtr->modKeyCodes); - dispPtr->modKeyCodes = new; + dispPtr->modKeyCodes = newCodes; } dispPtr->modKeyCodes[dispPtr->numModKeyCodes] = *codePtr; dispPtr->numModKeyCodes++; |