summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tkBitmap.c6
-rw-r--r--generic/tkGC.c8
-rw-r--r--generic/tkListbox.c32
-rw-r--r--generic/tkScrollbar.c7
-rw-r--r--generic/tkUtil.c164
5 files changed, 125 insertions, 92 deletions
diff --git a/generic/tkBitmap.c b/generic/tkBitmap.c
index 8fa32c1..33979d8 100644
--- a/generic/tkBitmap.c
+++ b/generic/tkBitmap.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkBitmap.c,v 1.19 2007/09/07 00:34:51 dgp Exp $
+ * RCS: @(#) $Id: tkBitmap.c,v 1.20 2007/09/08 16:01:20 dkf Exp $
*/
#include "tkInt.h"
@@ -25,7 +25,7 @@
* that warning message.
*/
-#if defined(__WIN32__) || defined(_WIN32)
+#if (defined(__WIN32__) || defined(_WIN32)) && !defined(__GNUC__)
#pragma warning (disable : 4305)
#endif
@@ -40,7 +40,7 @@
#include "question.xbm"
#include "warning.xbm"
-#if defined(__WIN32__) || defined(_WIN32)
+#if (defined(__WIN32__) || defined(_WIN32)) && !defined(__GNUC__)
#pragma warning (default : 4305)
#endif
diff --git a/generic/tkGC.c b/generic/tkGC.c
index 0916995..8f928d1 100644
--- a/generic/tkGC.c
+++ b/generic/tkGC.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkGC.c,v 1.8 2007/09/07 00:34:52 dgp Exp $
+ * RCS: @(#) $Id: tkGC.c,v 1.9 2007/09/08 16:01:20 dkf Exp $
*/
#include "tkInt.h"
@@ -92,7 +92,7 @@ Tk_GetGC(
* structure on some systems.
*/
- memset((void *) &valueKey, 0, sizeof(valueKey));
+ memset(&valueKey, 0, sizeof(valueKey));
/*
* First, check to see if there's already a GC that will work for this
@@ -218,7 +218,7 @@ Tk_GetGC(
valueKey.screenNum = Tk_ScreenNumber(tkwin);
valueKey.depth = Tk_Depth(tkwin);
valueHashPtr = Tcl_CreateHashEntry(&dispPtr->gcValueTable,
- (char *) &valueKey, &isNew);
+ (char *) &valueKey, &isNew);
if (!isNew) {
gcPtr = (TkGC *) Tcl_GetHashValue(valueHashPtr);
gcPtr->refCount++;
@@ -256,7 +256,7 @@ Tk_GetGC(
gcPtr->refCount = 1;
gcPtr->valueHashPtr = valueHashPtr;
idHashPtr = Tcl_CreateHashEntry(&dispPtr->gcIdTable,
- (char *) gcPtr->gc, &isNew);
+ (char *) gcPtr->gc, &isNew);
if (!isNew) {
Tcl_Panic("GC already registered in Tk_GetGC");
}
diff --git a/generic/tkListbox.c b/generic/tkListbox.c
index 614ea7f..a466d51 100644
--- a/generic/tkListbox.c
+++ b/generic/tkListbox.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkListbox.c,v 1.41 2007/09/07 00:34:53 dgp Exp $
+ * RCS: @(#) $Id: tkListbox.c,v 1.42 2007/09/08 16:01:20 dkf Exp $
*/
#include "default.h"
@@ -39,7 +39,7 @@ typedef struct {
Tk_Window tkwin; /* Window that embodies the listbox. NULL
* means that the window has been destroyed
* but the data structures haven't yet been
- * cleaned up.*/
+ * cleaned up. */
Display *display; /* Display containing widget. Used, among
* other things, so that resources can be
* freed even after tkwin has gone away. */
@@ -205,7 +205,8 @@ typedef struct {
/*
* The following enum is used to define a type for the -state option of the
- * Entry widget. These values are used as indices into the string table below.
+ * Listbox widget. These values are used as indices into the string table
+ * below.
*/
enum state {
@@ -609,6 +610,7 @@ ListboxWidgetObjCmd(
* Parse the command by looking up the second argument in the list of
* valid subcommand names
*/
+
result = Tcl_GetIndexFromObj(interp, objv[1], commandNames,
"option", 0, &cmdIndex);
if (result != TCL_OK) {
@@ -717,7 +719,7 @@ ListboxWidgetObjCmd(
* search functions (Tcl_FirstHashEntry, Tcl_NextHashEntry), but then
* the result wouldn't be in sorted order. So instead we loop through
* the indices in order, adding them to the result if they are
- * selected
+ * selected.
*/
for (i = 0; i < listPtr->nElements; i++) {
@@ -815,6 +817,7 @@ ListboxWidgetObjCmd(
/*
* One element request - we return a string
*/
+
Tcl_SetObjResult(interp, elemPtrs[first]);
} else {
Tcl_SetListObj(Tcl_GetObjResult(interp), (last - first + 1),
@@ -1420,7 +1423,7 @@ ListboxGetItemAttributes(
static void
DestroyListbox(
- char *memPtr) /* Info about listbox widget. */
+ char *memPtr) /* Info about listbox widget. */
{
register Listbox *listPtr = (Listbox *) memPtr;
Tcl_HashEntry *entry;
@@ -1631,6 +1634,7 @@ ConfigureListbox(
/*
* Make sure the object is a good list object.
*/
+
if (Tcl_ListObjLength(listPtr->interp, listVarObj, &dummy)
!= TCL_OK) {
Tcl_AppendResult(listPtr->interp,
@@ -1710,10 +1714,12 @@ ConfigureListboxItem(
return TCL_ERROR;
}
Tk_FreeSavedOptions(&savedOptions);
+
/*
- * Redraw this index - ListboxWorldChanged would need to be called
- * if item attributes were checked in the "world".
+ * Redraw this index - ListboxWorldChanged would need to be called if item
+ * attributes were checked in the "world".
*/
+
EventuallyRedrawRange(listPtr, index, index);
return TCL_OK;
}
@@ -2566,8 +2572,8 @@ ListboxDeleteSubCmd(
* None.
*
* Side effects:
- * When the window gets deleted, internal structures get cleaned up.
- * When it gets exposed, it is redisplayed.
+ * When the window gets deleted, internal structures get cleaned up. When
+ * it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
@@ -2980,10 +2986,10 @@ NearestListboxElement(
*
* Side effects:
* All of the elements in the range between first and last are marked as
- * either selected or deselected, depending on the "select" argument.
- * Any items whose state changes are redisplayed. The selection is
- * claimed from X when the number of selected elements changes from zero
- * to non-zero.
+ * either selected or deselected, depending on the "select" argument. Any
+ * items whose state changes are redisplayed. The selection is claimed
+ * from X when the number of selected elements changes from zero to
+ * non-zero.
*
*----------------------------------------------------------------------
*/
diff --git a/generic/tkScrollbar.c b/generic/tkScrollbar.c
index 3ac932f..932b6dd 100644
--- a/generic/tkScrollbar.c
+++ b/generic/tkScrollbar.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkScrollbar.c,v 1.9 2007/09/07 00:34:53 dgp Exp $
+ * RCS: @(#) $Id: tkScrollbar.c,v 1.10 2007/09/08 16:01:20 dkf Exp $
*/
#include "tkInt.h"
@@ -288,8 +288,7 @@ ScrollbarWidgetCmd(
&& (length >= 2)) {
if (argc == 2) {
result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
- tkpScrollbarConfigSpecs, (char *) scrollPtr,
- NULL, 0);
+ tkpScrollbarConfigSpecs, (char *) scrollPtr, NULL, 0);
} else if (argc == 3) {
result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);
@@ -597,7 +596,7 @@ TkScrollbarEventProc(
if (scrollPtr->tkwin != NULL) {
scrollPtr->tkwin = NULL;
Tcl_DeleteCommandFromToken(scrollPtr->interp,
- scrollPtr->widgetCmd);
+ scrollPtr->widgetCmd);
}
if (scrollPtr->flags & REDRAW_PENDING) {
Tcl_CancelIdleCall(TkpDisplayScrollbar, (ClientData) scrollPtr);
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index 37dc093..b41f4c3 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUtil.c,v 1.18 2007/09/07 00:34:54 dgp Exp $
+ * RCS: @(#) $Id: tkUtil.c,v 1.19 2007/09/08 16:01:20 dkf Exp $
*/
#include "tkInt.h"
@@ -135,15 +135,16 @@ TkStatePrintProc(
{
register Tk_State *statePtr = (Tk_State *) (widgRec + offset);
- if (*statePtr==TK_STATE_NORMAL) {
+ switch (*statePtr) {
+ case TK_STATE_NORMAL:
return "normal";
- } else if (*statePtr==TK_STATE_DISABLED) {
+ case TK_STATE_DISABLED:
return "disabled";
- } else if (*statePtr==TK_STATE_HIDDEN) {
+ case TK_STATE_HIDDEN:
return "hidden";
- } else if (*statePtr==TK_STATE_ACTIVE) {
+ case TK_STATE_ACTIVE:
return "active";
- } else {
+ default:
return "";
}
}
@@ -262,7 +263,7 @@ TkOffsetParseProc(
char *widgRec, /* Widget structure record */
int offset) /* Offset of tile in record */
{
- Tk_TSOffset *offsetPtr = (Tk_TSOffset *)(widgRec + offset);
+ Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
Tk_TSOffset tsoffset;
const char *q, *p;
int result;
@@ -403,48 +404,48 @@ TkOffsetPrintProc(
int offset, /* Offset of tile in record */
Tcl_FreeProc **freeProcPtr) /* not used */
{
- Tk_TSOffset *offsetPtr = (Tk_TSOffset *)(widgRec + offset);
+ Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
char *p, *q;
- if ((offsetPtr->flags) & TK_OFFSET_INDEX) {
- if ((offsetPtr->flags) >= INT_MAX) {
+ if (offsetPtr->flags & TK_OFFSET_INDEX) {
+ if (offsetPtr->flags >= INT_MAX) {
return "end";
}
p = (char *) ckalloc(32);
- sprintf(p, "%d",(offsetPtr->flags & (~TK_OFFSET_INDEX)));
+ sprintf(p, "%d", offsetPtr->flags & ~TK_OFFSET_INDEX);
*freeProcPtr = TCL_DYNAMIC;
return p;
}
- if ((offsetPtr->flags) & TK_OFFSET_TOP) {
- if ((offsetPtr->flags) & TK_OFFSET_LEFT) {
+ if (offsetPtr->flags & TK_OFFSET_TOP) {
+ if (offsetPtr->flags & TK_OFFSET_LEFT) {
return "nw";
- } else if ((offsetPtr->flags) & TK_OFFSET_CENTER) {
+ } else if (offsetPtr->flags & TK_OFFSET_CENTER) {
return "n";
- } else if ((offsetPtr->flags) & TK_OFFSET_RIGHT) {
+ } else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
return "ne";
}
- } else if ((offsetPtr->flags) & TK_OFFSET_MIDDLE) {
- if ((offsetPtr->flags) & TK_OFFSET_LEFT) {
+ } else if (offsetPtr->flags & TK_OFFSET_MIDDLE) {
+ if (offsetPtr->flags & TK_OFFSET_LEFT) {
return "w";
- } else if ((offsetPtr->flags) & TK_OFFSET_CENTER) {
+ } else if (offsetPtr->flags & TK_OFFSET_CENTER) {
return "center";
- } else if ((offsetPtr->flags) & TK_OFFSET_RIGHT) {
+ } else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
return "e";
}
- } else if ((offsetPtr->flags) & TK_OFFSET_BOTTOM) {
- if ((offsetPtr->flags) & TK_OFFSET_LEFT) {
+ } else if (offsetPtr->flags & TK_OFFSET_BOTTOM) {
+ if (offsetPtr->flags & TK_OFFSET_LEFT) {
return "sw";
- } else if ((offsetPtr->flags) & TK_OFFSET_CENTER) {
+ } else if (offsetPtr->flags & TK_OFFSET_CENTER) {
return "s";
- } else if ((offsetPtr->flags) & TK_OFFSET_RIGHT) {
+ } else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
return "se";
}
}
q = p = (char *) ckalloc(32);
- if ((offsetPtr->flags) & TK_OFFSET_RELATIVE) {
+ if (offsetPtr->flags & TK_OFFSET_RELATIVE) {
*q++ = '#';
}
- sprintf(q, "%d,%d",offsetPtr->xoffset, offsetPtr->yoffset);
+ sprintf(q, "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset);
*freeProcPtr = TCL_DYNAMIC;
return p;
}
@@ -469,7 +470,7 @@ TkPixelParseProc(
char *widgRec, /* Widget structure record */
int offset) /* Offset of tile in record */
{
- double *doublePtr = (double *)(widgRec + offset);
+ double *doublePtr = (double *) (widgRec + offset);
int result;
result = TkGetDoublePixels(interp, tkwin, value, doublePtr);
@@ -502,10 +503,9 @@ TkPixelPrintProc(
int offset, /* Offset of tile in record */
Tcl_FreeProc **freeProcPtr) /* not used */
{
- double *doublePtr = (double *)(widgRec + offset);
- char *p;
+ double *doublePtr = (double *) (widgRec + offset);
+ char *p = (char *) ckalloc(24);
- p = (char *) ckalloc(24);
Tcl_PrintDouble(NULL, *doublePtr, p);
*freeProcPtr = TCL_DYNAMIC;
return p;
@@ -571,11 +571,11 @@ TkDrawInsetFocusHighlight(
* This function draws a rectangular ring around the outside of a widget
* to indicate that it has received the input focus.
*
- * This function is now deprecated. Use TkpDrawHighlightBorder instead,
- * since this function does not handle drawing the Focus ring properly on
- * the Macintosh - you need to know the background GC as well as the
- * foreground since the Mac focus ring separated from the widget by a 1
- * pixel border.
+ * This function is now deprecated. Use TkpDrawHighlightBorder instead,
+ * since this function does not handle drawing the Focus ring properly on
+ * the Macintosh - you need to know the background GC as well as the
+ * foreground since the Mac focus ring separated from the widget by a 1
+ * pixel border.
*
* Results:
* None.
@@ -634,11 +634,9 @@ Tk_GetScrollInfo(
int *intPtr) /* Filled in with number of pages or lines to
* scroll, if any. */
{
- int c;
- size_t length;
+ int c = argv[2][0];
+ size_t length = strlen(argv[2]);
- length = strlen(argv[2]);
- c = argv[2][0];
if ((c == 'm') && (strncmp(argv[2], "moveto", length) == 0)) {
if (argc != 4) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
@@ -665,11 +663,11 @@ Tk_GetScrollInfo(
return TK_SCROLL_PAGES;
} else if ((c == 'u') && (strncmp(argv[4], "units", length) == 0)) {
return TK_SCROLL_UNITS;
- } else {
- Tcl_AppendResult(interp, "bad argument \"", argv[4],
- "\": must be units or pages", NULL);
- return TK_SCROLL_ERROR;
}
+
+ Tcl_AppendResult(interp, "bad argument \"", argv[4],
+ "\": must be units or pages", NULL);
+ return TK_SCROLL_ERROR;
}
Tcl_AppendResult(interp, "unknown option \"", argv[2],
"\": must be moveto or scroll", NULL);
@@ -710,14 +708,14 @@ Tk_GetScrollInfoObj(
int *intPtr) /* Filled in with number of pages or lines to
* scroll, if any. */
{
- int c;
- size_t length;
- char *arg2, *arg4;
+ int length;
+ const char *arg;
+
+ arg = Tcl_GetStringFromObj(objv[2], &length);
+
+#define ArgPfxEq(str) ((arg[0]==str[0])&&!strncmp(arg,str,(unsigned)length))
- arg2 = Tcl_GetString(objv[2]);
- length = strlen(arg2);
- c = arg2[0];
- if ((c == 'm') && (strncmp(arg2, "moveto", length) == 0)) {
+ if (ArgPfxEq("moveto")) {
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "moveto fraction");
return TK_SCROLL_ERROR;
@@ -726,8 +724,7 @@ Tk_GetScrollInfoObj(
return TK_SCROLL_ERROR;
}
return TK_SCROLL_MOVETO;
- } else if ((c == 's')
- && (strncmp(arg2, "scroll", length) == 0)) {
+ } else if (ArgPfxEq("scroll")) {
if (objc != 5) {
Tcl_WrongNumArgs(interp, 2, objv, "scroll number units|pages");
return TK_SCROLL_ERROR;
@@ -735,20 +732,19 @@ Tk_GetScrollInfoObj(
if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
return TK_SCROLL_ERROR;
}
- arg4 = Tcl_GetString(objv[4]);
- length = (strlen(arg4));
- c = arg4[0];
- if ((c == 'p') && (strncmp(arg4, "pages", length) == 0)) {
+
+ arg = Tcl_GetStringFromObj(objv[4], &length);
+ if (ArgPfxEq("pages")) {
return TK_SCROLL_PAGES;
- } else if ((c == 'u') && (strncmp(arg4, "units", length) == 0)) {
+ } else if (ArgPfxEq("units")) {
return TK_SCROLL_UNITS;
- } else {
- Tcl_AppendResult(interp, "bad argument \"", arg4,
- "\": must be units or pages", NULL);
- return TK_SCROLL_ERROR;
}
+
+ Tcl_AppendResult(interp, "bad argument \"", arg,
+ "\": must be units or pages", NULL);
+ return TK_SCROLL_ERROR;
}
- Tcl_AppendResult(interp, "unknown option \"", arg2,
+ Tcl_AppendResult(interp, "unknown option \"", arg,
"\": must be moveto or scroll", NULL);
return TK_SCROLL_ERROR;
}
@@ -785,6 +781,10 @@ TkComputeAnchor(
int *xPtr, int *yPtr) /* Returns upper-left corner of anchored
* rectangle. */
{
+ /*
+ * Handle the horizontal parts.
+ */
+
switch (anchor) {
case TK_ANCHOR_NW:
case TK_ANCHOR_W:
@@ -801,11 +801,15 @@ TkComputeAnchor(
break;
default:
- *xPtr = Tk_Width(tkwin) - (Tk_InternalBorderRight(tkwin) + padX)
+ *xPtr = Tk_Width(tkwin) - Tk_InternalBorderRight(tkwin) - padX
- innerWidth;
break;
}
+ /*
+ * Handle the vertical parts.
+ */
+
switch (anchor) {
case TK_ANCHOR_NW:
case TK_ANCHOR_N:
@@ -851,9 +855,9 @@ TkFindStateString(
const TkStateMap *mapPtr, /* The state table. */
int numKey) /* The key to try to find in the table. */
{
- for ( ; mapPtr->strKey != NULL; mapPtr++) {
+ for (; mapPtr->strKey!=NULL ; mapPtr++) {
if (numKey == mapPtr->numKey) {
- return (char*)(mapPtr->strKey);
+ return (char *) mapPtr->strKey;
}
}
return NULL;
@@ -862,7 +866,7 @@ TkFindStateString(
/*
*---------------------------------------------------------------------------
*
- * TkFindStateNum --
+ * TkFindStateNum, TkFindStateNumObj --
*
* Given a lookup table, map a string to a number in the table.
*
@@ -889,11 +893,21 @@ TkFindStateNum(
{
const TkStateMap *mPtr;
+ /*
+ * See if the value is in the state map.
+ */
+
for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) {
if (strcmp(strKey, mPtr->strKey) == 0) {
return mPtr->numKey;
}
}
+
+ /*
+ * Not there. Generate an error message (if we can) and return the
+ * default.
+ */
+
if (interp != NULL) {
mPtr = mapPtr;
Tcl_AppendResult(interp, "bad ", option, " value \"", strKey,
@@ -918,11 +932,19 @@ TkFindStateNumObj(
const char *key;
const Tcl_ObjType *typePtr;
+ /*
+ * See if the value is in the object cache.
+ */
+
if ((keyPtr->typePtr == &tkStateKeyObjType)
- && (keyPtr->internalRep.twoPtrValue.ptr1 == (VOID *) mapPtr)) {
+ && (keyPtr->internalRep.twoPtrValue.ptr1 == mapPtr)) {
return (int) keyPtr->internalRep.twoPtrValue.ptr2;
}
+ /*
+ * Not there. Look in the state map.
+ */
+
key = Tcl_GetStringFromObj(keyPtr, NULL);
for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) {
if (strcmp(key, mPtr->strKey) == 0) {
@@ -930,12 +952,18 @@ TkFindStateNumObj(
if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
(*typePtr->freeIntRepProc)(keyPtr);
}
- keyPtr->internalRep.twoPtrValue.ptr1 = (VOID *) mapPtr;
- keyPtr->internalRep.twoPtrValue.ptr2 = (VOID *) mPtr->numKey;
+ keyPtr->internalRep.twoPtrValue.ptr1 = (void *) mapPtr;
+ keyPtr->internalRep.twoPtrValue.ptr2 = (void *) mPtr->numKey;
keyPtr->typePtr = &tkStateKeyObjType;
return mPtr->numKey;
}
}
+
+ /*
+ * Not there either. Generate an error message (if we can) and return the
+ * default.
+ */
+
if (interp != NULL) {
mPtr = mapPtr;
Tcl_AppendResult(interp, "bad ", Tcl_GetString(optionPtr),