summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2008-11-26 15:56:37 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2008-11-26 15:56:37 (GMT)
commita3f4e672b7776ad620f5bc519ed88a5366d0a927 (patch)
tree32207129bc4af526d0f74885fdececc8a860f965 /unix
parent1c05251e57f9a18ea76fe0cbdaa590c601191506 (diff)
downloadtk-a3f4e672b7776ad620f5bc519ed88a5366d0a927.zip
tk-a3f4e672b7776ad620f5bc519ed88a5366d0a927.tar.gz
tk-a3f4e672b7776ad620f5bc519ed88a5366d0a927.tar.bz2
Making code neater...
Diffstat (limited to 'unix')
-rw-r--r--unix/tkUnixKey.c146
-rw-r--r--unix/tkUnixMenu.c35
2 files changed, 81 insertions, 100 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++;
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index ec77732..6d3b7be 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixMenu.c,v 1.20 2008/04/27 22:39:13 dkf Exp $
+ * RCS: @(#) $Id: tkUnixMenu.c,v 1.21 2008/11/26 15:56:37 dkf Exp $
*/
#include "default.h"
@@ -330,6 +330,8 @@ GetMenuIndicatorGeometry(
int *widthPtr, /* The resulting width */
int *heightPtr) /* The resulting height */
{
+ int borderWidth;
+
if ((mePtr->type == CHECK_BUTTON_ENTRY)
|| (mePtr->type == RADIO_BUTTON_ENTRY)) {
if (!mePtr->hideMargin && mePtr->indicatorOn) {
@@ -354,23 +356,18 @@ GetMenuIndicatorGeometry(
}
}
} else {
- int borderWidth;
-
- Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
- menuPtr->borderWidthPtr, &borderWidth);
+ Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
+ &borderWidth);
*heightPtr = 0;
*widthPtr = borderWidth;
}
} else {
- int borderWidth;
-
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin, menuPtr->borderWidthPtr,
&borderWidth);
*heightPtr = 0;
*widthPtr = borderWidth;
}
}
-
/*
*----------------------------------------------------------------------
@@ -400,9 +397,8 @@ GetMenuAccelGeometry(
*heightPtr = fmPtr->linespace;
if (mePtr->type == CASCADE_ENTRY) {
*widthPtr = 2 * CASCADE_ARROW_WIDTH;
- } else if ((menuPtr->menuType != MENUBAR)
- && (mePtr->accelPtr != NULL)) {
- char *accel = Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
+ } else if ((menuPtr->menuType != MENUBAR) && (mePtr->accelPtr != NULL)) {
+ char *accel = Tcl_GetString(mePtr->accelPtr);
*widthPtr = Tk_TextWidth(tkfont, accel, mePtr->accelLength);
} else {
@@ -521,7 +517,7 @@ DrawMenuEntryAccelerator(
(menuPtr->postedCascade == mePtr)
? TK_RELIEF_SUNKEN : TK_RELIEF_RAISED);
} else if (mePtr->accelPtr != NULL) {
- char *accel = Tcl_GetStringFromObj(mePtr->accelPtr, NULL);
+ char *accel = Tcl_GetString(mePtr->accelPtr);
int left = x + mePtr->labelWidth + activeBorderWidth
+ mePtr->indicatorSpace;
@@ -703,12 +699,14 @@ DrawMenuEntryLabel(
haveImage = 1;
} else if (mePtr->bitmapPtr != NULL) {
Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
+
Tk_SizeOfBitmap(menuPtr->display, bitmap, &imageWidth, &imageHeight);
haveImage = 1;
}
if (!haveImage || (mePtr->compound != COMPOUND_NONE)) {
if (mePtr->labelLength > 0) {
- char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+ char *label = Tcl_GetString(mePtr->labelPtr);
+
textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength);
textHeight = fmPtr->linespace;
haveText = 1;
@@ -721,6 +719,7 @@ DrawMenuEntryLabel(
if (haveImage && haveText) {
int fullWidth = (imageWidth > textWidth ? imageWidth : textWidth);
+
switch ((enum compound) mePtr->compound) {
case COMPOUND_TOP:
textXOffset = (fullWidth - textWidth)/2;
@@ -803,7 +802,7 @@ DrawMenuEntryLabel(
int baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;
if (mePtr->labelLength > 0) {
- char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+ char *label = Tcl_GetString(mePtr->labelPtr);
Tk_DrawChars(menuPtr->display, d, gc, tkfont, label,
mePtr->labelLength, leftEdge + textXOffset,
@@ -867,7 +866,7 @@ DrawMenuUnderline(
int activeBorderWidth, leftEdge;
const char *label, *start, *end;
- label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
+ label = Tcl_GetString(mePtr->labelPtr);
start = Tcl_UtfAtIndex(label, mePtr->underline);
end = Tcl_UtfNext(start);
@@ -1076,7 +1075,6 @@ TkpComputeMenubarGeometry(
if (mePtr->entryFlags & ENTRY_HELP_MENU) {
helpMenuIndex = i;
} else if (x + mePtr->width + borderWidth > maxWindowWidth) {
-
if (i == lastRowBreak) {
mePtr->y = y;
mePtr->x = x;
@@ -1473,6 +1471,7 @@ GetMenuLabelGeometry(
haveImage = 1;
} else if (mePtr->bitmapPtr != NULL) {
Pixmap bitmap = Tk_GetBitmapFromObj(menuPtr->tkwin, mePtr->bitmapPtr);
+
Tk_SizeOfBitmap(menuPtr->display, bitmap, widthPtr, heightPtr);
haveImage = 1;
} else {
@@ -1491,9 +1490,9 @@ GetMenuLabelGeometry(
if (mePtr->labelPtr != NULL) {
int textWidth;
- char *label = Tcl_GetStringFromObj(mePtr->labelPtr, NULL);
- textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength);
+ char *label = Tcl_GetString(mePtr->labelPtr);
+ textWidth = Tk_TextWidth(tkfont, label, mePtr->labelLength);
if ((mePtr->compound != COMPOUND_NONE) && haveImage) {
switch ((enum compound) mePtr->compound) {
case COMPOUND_TOP: