summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixKey.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tkUnixKey.c')
-rw-r--r--unix/tkUnixKey.c94
1 files changed, 46 insertions, 48 deletions
diff --git a/unix/tkUnixKey.c b/unix/tkUnixKey.c
index 030e472..7461d75 100644
--- a/unix/tkUnixKey.c
+++ b/unix/tkUnixKey.c
@@ -22,7 +22,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.
*
*----------------------------------------------------------------------
@@ -38,11 +38,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;
}
@@ -51,22 +50,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, (void *) NULL);
- XSetICValues(winPtr->inputContext,
- XNPreeditAttributes, preedit_attr,
+ XSetICValues(winPtr->inputContext, XNPreeditAttributes, preedit_attr,
(void *) NULL);
XFree(preedit_attr);
}
@@ -91,7 +89,7 @@ Tk_SetCaretPos(
*----------------------------------------------------------------------
*/
-char *
+const char *
TkpGetString(
TkWindow *winPtr, /* Window where event occurred */
XEvent *eventPtr, /* X keyboard event. */
@@ -115,8 +113,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
@@ -125,10 +122,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)) {
@@ -142,7 +143,6 @@ TkpGetString(
Tcl_DStringInit(&buf);
Tcl_DStringSetLength(&buf, TCL_DSTRING_STATIC_SIZE-1);
-
len = XmbLookupString(winPtr->inputContext, &eventPtr->xkey,
Tcl_DStringValue(&buf), Tcl_DStringLength(&buf),
&kePtr->keysym, &status);
@@ -159,7 +159,6 @@ TkpGetString(
if ((status != XLookupChars) && (status != XLookupBoth)) {
len = 0;
}
-
Tcl_DStringSetLength(&buf, len);
Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&buf), len, dsPtr);
Tcl_DStringFree(&buf);
@@ -203,7 +202,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);
@@ -221,30 +220,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 (state & 2) {
- TkDisplay *dispPtr;
-
- dispPtr = ((TkWindow *) tkwin)->dispPtr;
- eventPtr->xkey.state |= dispPtr->modeModMask;
+ 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;
}
- break;
}
}
}
@@ -420,7 +416,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;
@@ -442,12 +438,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;
@@ -459,23 +454,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++;