summaryrefslogtreecommitdiffstats
path: root/generic/tkEntry.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkEntry.c')
-rw-r--r--generic/tkEntry.c540
1 files changed, 275 insertions, 265 deletions
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index 26311a3..eb94cbd 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -64,11 +64,11 @@ enum validateType {
static const Tk_OptionSpec entryOptSpec[] = {
{TK_OPTION_BORDER, "-background", "background", "Background",
DEF_ENTRY_BG_COLOR, -1, Tk_Offset(Entry, normalBorder),
- 0, (ClientData) DEF_ENTRY_BG_MONO, 0},
+ 0, DEF_ENTRY_BG_MONO, 0},
{TK_OPTION_SYNONYM, "-bd", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-borderwidth", 0},
+ NULL, 0, -1, 0, "-borderwidth", 0},
{TK_OPTION_SYNONYM, "-bg", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-background", 0},
+ NULL, 0, -1, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
DEF_ENTRY_BORDER_WIDTH, -1, Tk_Offset(Entry, borderWidth), 0, 0, 0},
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
@@ -85,7 +85,7 @@ static const Tk_OptionSpec entryOptSpec[] = {
"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, -1,
Tk_Offset(Entry, exportSelection), 0, 0, 0},
{TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
- NULL, 0, -1, 0, (ClientData) "-foreground", 0},
+ NULL, 0, -1, 0, "-foreground", 0},
{TK_OPTION_FONT, "-font", "font", "Font",
DEF_ENTRY_FONT, -1, Tk_Offset(Entry, tkfont), 0, 0, 0},
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
@@ -115,7 +115,7 @@ static const Tk_OptionSpec entryOptSpec[] = {
DEF_ENTRY_INVALIDCMD, -1, Tk_Offset(Entry, invalidCmd),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-invcmd", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-invalidcommand", 0},
+ NULL, 0, -1, 0, "-invalidcommand", 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
DEF_ENTRY_JUSTIFY, -1, Tk_Offset(Entry, justify), 0, 0, 0},
{TK_OPTION_BORDER, "-readonlybackground", "readonlyBackground",
@@ -126,20 +126,20 @@ static const Tk_OptionSpec entryOptSpec[] = {
DEF_ENTRY_RELIEF, -1, Tk_Offset(Entry, relief), 0, 0, 0},
{TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
DEF_ENTRY_SELECT_COLOR, -1, Tk_Offset(Entry, selBorder),
- 0, (ClientData) DEF_ENTRY_SELECT_MONO, 0},
+ 0, DEF_ENTRY_SELECT_MONO, 0},
{TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, -1,
Tk_Offset(Entry, selBorderWidth),
- 0, (ClientData) DEF_ENTRY_SELECT_BD_MONO, 0},
+ 0, DEF_ENTRY_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_ENTRY_SELECT_FG_COLOR, -1, Tk_Offset(Entry, selFgColorPtr),
- TK_CONFIG_NULL_OK, (ClientData) DEF_ENTRY_SELECT_FG_MONO, 0},
+ TK_CONFIG_NULL_OK, DEF_ENTRY_SELECT_FG_MONO, 0},
{TK_OPTION_STRING, "-show", "show", "Show",
DEF_ENTRY_SHOW, -1, Tk_Offset(Entry, showChar),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING_TABLE, "-state", "state", "State",
DEF_ENTRY_STATE, -1, Tk_Offset(Entry, state),
- 0, (ClientData) stateStrings, 0},
+ 0, stateStrings, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_ENTRY_TAKE_FOCUS, -1, Tk_Offset(Entry, takeFocus),
TK_OPTION_NULL_OK, 0, 0},
@@ -148,11 +148,11 @@ static const Tk_OptionSpec entryOptSpec[] = {
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate",
DEF_ENTRY_VALIDATE, -1, Tk_Offset(Entry, validate),
- 0, (ClientData) validateStrings, 0},
+ 0, validateStrings, 0},
{TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand",
NULL, -1, Tk_Offset(Entry, validateCmd), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-vcmd", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-validatecommand", 0},
+ NULL, 0, -1, 0, "-validatecommand", 0},
{TK_OPTION_INT, "-width", "width", "Width",
DEF_ENTRY_WIDTH, -1, Tk_Offset(Entry, prefWidth), 0, 0, 0},
{TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
@@ -181,19 +181,19 @@ static const Tk_OptionSpec entryOptSpec[] = {
static const Tk_OptionSpec sbOptSpec[] = {
{TK_OPTION_BORDER, "-activebackground", "activeBackground", "Background",
DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(Spinbox, activeBorder),
- 0, (ClientData) DEF_BUTTON_ACTIVE_BG_MONO, 0},
+ 0, DEF_BUTTON_ACTIVE_BG_MONO, 0},
{TK_OPTION_BORDER, "-background", "background", "Background",
DEF_ENTRY_BG_COLOR, -1, Tk_Offset(Entry, normalBorder),
- 0, (ClientData) DEF_ENTRY_BG_MONO, 0},
+ 0, DEF_ENTRY_BG_MONO, 0},
{TK_OPTION_SYNONYM, "-bd", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-borderwidth", 0},
+ NULL, 0, -1, 0, "-borderwidth", 0},
{TK_OPTION_SYNONYM, "-bg", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-background", 0},
+ NULL, 0, -1, 0, "-background", 0},
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
DEF_ENTRY_BORDER_WIDTH, -1, Tk_Offset(Entry, borderWidth), 0, 0, 0},
{TK_OPTION_BORDER, "-buttonbackground", "Button.background", "Background",
DEF_BUTTON_BG_COLOR, -1, Tk_Offset(Spinbox, buttonBorder),
- 0, (ClientData) DEF_BUTTON_BG_MONO, 0},
+ 0, DEF_BUTTON_BG_MONO, 0},
{TK_OPTION_CURSOR, "-buttoncursor", "Button.cursor", "Cursor",
DEF_BUTTON_CURSOR, -1, Tk_Offset(Spinbox, bCursor),
TK_OPTION_NULL_OK, 0, 0},
@@ -218,7 +218,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, -1,
Tk_Offset(Entry, exportSelection), 0, 0, 0},
{TK_OPTION_SYNONYM, "-fg", "foreground", NULL,
- NULL, 0, -1, 0, (ClientData) "-foreground", 0},
+ NULL, 0, -1, 0, "-foreground", 0},
{TK_OPTION_FONT, "-font", "font", "Font",
DEF_ENTRY_FONT, -1, Tk_Offset(Entry, tkfont), 0, 0, 0},
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
@@ -255,7 +255,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
DEF_ENTRY_INVALIDCMD, -1, Tk_Offset(Entry, invalidCmd),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-invcmd", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-invalidcommand", 0},
+ NULL, 0, -1, 0, "-invalidcommand", 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
DEF_ENTRY_JUSTIFY, -1, Tk_Offset(Entry, justify), 0, 0, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
@@ -272,17 +272,17 @@ static const Tk_OptionSpec sbOptSpec[] = {
0, 0, 0},
{TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
DEF_ENTRY_SELECT_COLOR, -1, Tk_Offset(Entry, selBorder),
- 0, (ClientData) DEF_ENTRY_SELECT_MONO, 0},
+ 0, DEF_ENTRY_SELECT_MONO, 0},
{TK_OPTION_PIXELS, "-selectborderwidth", "selectBorderWidth",
"BorderWidth", DEF_ENTRY_SELECT_BD_COLOR, -1,
Tk_Offset(Entry, selBorderWidth),
- 0, (ClientData) DEF_ENTRY_SELECT_BD_MONO, 0},
+ 0, DEF_ENTRY_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_ENTRY_SELECT_FG_COLOR, -1, Tk_Offset(Entry, selFgColorPtr),
- TK_CONFIG_NULL_OK, (ClientData) DEF_ENTRY_SELECT_FG_MONO, 0},
+ TK_CONFIG_NULL_OK, DEF_ENTRY_SELECT_FG_MONO, 0},
{TK_OPTION_STRING_TABLE, "-state", "state", "State",
DEF_ENTRY_STATE, -1, Tk_Offset(Entry, state),
- 0, (ClientData) stateStrings, 0},
+ 0, stateStrings, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_ENTRY_TAKE_FOCUS, -1, Tk_Offset(Entry, takeFocus),
TK_CONFIG_NULL_OK, 0, 0},
@@ -293,14 +293,14 @@ static const Tk_OptionSpec sbOptSpec[] = {
DEF_SPINBOX_TO, -1, Tk_Offset(Spinbox, toValue), 0, 0, 0},
{TK_OPTION_STRING_TABLE, "-validate", "validate", "Validate",
DEF_ENTRY_VALIDATE, -1, Tk_Offset(Entry, validate),
- 0, (ClientData) validateStrings, 0},
+ 0, validateStrings, 0},
{TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand",
NULL, -1, Tk_Offset(Entry, validateCmd), TK_CONFIG_NULL_OK, 0, 0},
{TK_OPTION_STRING, "-values", "values", "Values",
DEF_SPINBOX_VALUES, -1, Tk_Offset(Spinbox, valueStr),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_SYNONYM, "-vcmd", NULL, NULL,
- NULL, 0, -1, 0, (ClientData) "-validatecommand", 0},
+ NULL, 0, -1, 0, "-validatecommand", 0},
{TK_OPTION_INT, "-width", "width", "Width",
DEF_ENTRY_WIDTH, -1, Tk_Offset(Entry, prefWidth), 0, 0, 0},
{TK_OPTION_BOOLEAN, "-wrap", "wrap", "Wrap",
@@ -317,7 +317,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
* dispatch the entry widget command.
*/
-static const char *entryCmdNames[] = {
+static const char *const entryCmdNames[] = {
"bbox", "cget", "configure", "delete", "get", "icursor", "index",
"insert", "scan", "selection", "validate", "xview", NULL
};
@@ -328,7 +328,7 @@ enum entryCmd {
COMMAND_SCAN, COMMAND_SELECTION, COMMAND_VALIDATE, COMMAND_XVIEW
};
-static const char *selCmdNames[] = {
+static const char *const selCmdNames[] = {
"adjust", "clear", "from", "present", "range", "to", NULL
};
@@ -343,7 +343,7 @@ enum selCmd {
* dispatch the spinbox widget command.
*/
-static const char *sbCmdNames[] = {
+static const char *const sbCmdNames[] = {
"bbox", "cget", "configure", "delete", "get", "icursor", "identify",
"index", "insert", "invoke", "scan", "selection", "set",
"validate", "xview", NULL
@@ -356,7 +356,7 @@ enum sbCmd {
SB_CMD_SET, SB_CMD_VALIDATE, SB_CMD_XVIEW
};
-static const char *sbSelCmdNames[] = {
+static const char *const sbSelCmdNames[] = {
"adjust", "clear", "element", "from", "present", "range", "to", NULL
};
@@ -374,7 +374,7 @@ enum sbselCmd {
* modify them, you must modify the strings here.
*/
-static const char *selElementNames[] = {
+static const char *const selElementNames[] = {
"none", "buttondown", "buttonup", NULL, "entry"
};
@@ -392,7 +392,7 @@ static const char *selElementNames[] = {
static int ConfigureEntry(Tcl_Interp *interp, Entry *entryPtr,
int objc, Tcl_Obj *const objv[], int flags);
static void DeleteChars(Entry *entryPtr, int index, int count);
-static void DestroyEntry(char *memPtr);
+static void DestroyEntry(void *memPtr);
static void DisplayEntry(ClientData clientData);
static void EntryBlinkProc(ClientData clientData);
static void EntryCmdDeletedProc(ClientData clientData);
@@ -412,8 +412,8 @@ static char * EntryTextVarProc(ClientData clientData,
const char *name2, int flags);
static void EntryUpdateScrollbar(Entry *entryPtr);
static int EntryValidate(Entry *entryPtr, char *cmd);
-static int EntryValidateChange(Entry *entryPtr, char *change,
- const char *newStr, int index, int type);
+static int EntryValidateChange(Entry *entryPtr, const char *change,
+ const char *newStr, int index, int type);
static void ExpandPercents(Entry *entryPtr, const char *before,
const char *change, const char *newStr, int index,
int type, Tcl_DString *dsPtr);
@@ -426,8 +426,8 @@ static int EntryWidgetObjCmd(ClientData clientData,
Tcl_Obj *const objv[]);
static void EntryWorldChanged(ClientData instanceData);
static int GetEntryIndex(Tcl_Interp *interp, Entry *entryPtr,
- char *string, int *indexPtr);
-static void InsertChars(Entry *entryPtr, int index, char *string);
+ const char *string, int *indexPtr);
+static void InsertChars(Entry *entryPtr, int index, const char *string);
/*
* These forward declarations are the spinbox specific ones:
@@ -446,11 +446,12 @@ static int ComputeFormat(Spinbox *sbPtr);
* that can be invoked from generic window code.
*/
-static Tk_ClassProcs entryClass = {
+static const Tk_ClassProcs entryClass = {
sizeof(Tk_ClassProcs), /* size */
EntryWorldChanged, /* worldChangedProc */
+ NULL, /* createProc */
+ NULL /* modalProc */
};
-
/*
*--------------------------------------------------------------
@@ -482,7 +483,7 @@ Tk_EntryObjCmd(
char *tmp;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
+ Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
return TCL_ERROR;
}
@@ -506,18 +507,18 @@ Tk_EntryObjCmd(
* initialized as memset covers the rest.
*/
- entryPtr = (Entry *) ckalloc(sizeof(Entry));
+ entryPtr = ckalloc(sizeof(Entry));
memset(entryPtr, 0, sizeof(Entry));
entryPtr->tkwin = tkwin;
entryPtr->display = Tk_Display(tkwin);
entryPtr->interp = interp;
entryPtr->widgetCmd = Tcl_CreateObjCommand(interp,
- Tk_PathName(entryPtr->tkwin), EntryWidgetObjCmd,
- (ClientData) entryPtr, EntryCmdDeletedProc);
+ Tk_PathName(entryPtr->tkwin), EntryWidgetObjCmd, entryPtr,
+ EntryCmdDeletedProc);
entryPtr->optionTable = optionTable;
entryPtr->type = TK_ENTRY;
- tmp = (char *) ckalloc(1);
+ tmp = ckalloc(1);
tmp[0] = '\0';
entryPtr->string = tmp;
entryPtr->selectFirst = -1;
@@ -541,15 +542,15 @@ Tk_EntryObjCmd(
* otherwise Tk might free it while we still need it.
*/
- Tcl_Preserve((ClientData) entryPtr->tkwin);
+ Tcl_Preserve(entryPtr->tkwin);
Tk_SetClass(entryPtr->tkwin, "Entry");
- Tk_SetClassProcs(entryPtr->tkwin, &entryClass, (ClientData) entryPtr);
+ Tk_SetClassProcs(entryPtr->tkwin, &entryClass, entryPtr);
Tk_CreateEventHandler(entryPtr->tkwin,
ExposureMask|StructureNotifyMask|FocusChangeMask,
- EntryEventProc, (ClientData) entryPtr);
+ EntryEventProc, entryPtr);
Tk_CreateSelHandler(entryPtr->tkwin, XA_PRIMARY, XA_STRING,
- EntryFetchSelection, (ClientData) entryPtr, XA_STRING);
+ EntryFetchSelection, entryPtr, XA_STRING);
if ((Tk_InitOptions(interp, (char *) entryPtr, optionTable, tkwin)
!= TCL_OK) ||
@@ -558,7 +559,7 @@ Tk_EntryObjCmd(
return TCL_ERROR;
}
- Tcl_SetResult(interp, Tk_PathName(entryPtr->tkwin), TCL_STATIC);
+ Tcl_SetObjResult(interp, TkNewWindowObj(entryPtr->tkwin));
return TCL_OK;
}
@@ -587,12 +588,12 @@ EntryWidgetObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
int cmdIndex, selIndex, result;
Tcl_Obj *objPtr;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
+ Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
return TCL_ERROR;
}
@@ -601,17 +602,17 @@ EntryWidgetObjCmd(
* valid command names.
*/
- result = Tcl_GetIndexFromObj(interp, objv[1], entryCmdNames,
- "option", 0, &cmdIndex);
+ result = Tcl_GetIndexFromObj(interp, objv[1], entryCmdNames, "option", 0,
+ &cmdIndex);
if (result != TCL_OK) {
return result;
}
- Tcl_Preserve((ClientData) entryPtr);
+ Tcl_Preserve(entryPtr);
switch ((enum entryCmd) cmdIndex) {
case COMMAND_BBOX: {
int index, x, y, width, height;
- char buf[TCL_INTEGER_SPACE * 4];
+ Tcl_Obj *bbox[4];
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "index");
@@ -625,9 +626,11 @@ EntryWidgetObjCmd(
index--;
}
Tk_CharBbox(entryPtr->textLayout, index, &x, &y, &width, &height);
- sprintf(buf, "%d %d %d %d", x + entryPtr->layoutX,
- y + entryPtr->layoutY, width, height);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ bbox[0] = Tcl_NewIntObj(x + entryPtr->layoutX);
+ bbox[1] = Tcl_NewIntObj(y + entryPtr->layoutY);
+ bbox[2] = Tcl_NewIntObj(width);
+ bbox[3] = Tcl_NewIntObj(height);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(4, bbox));
break;
}
@@ -641,9 +644,8 @@ EntryWidgetObjCmd(
entryPtr->optionTable, objv[2], entryPtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
break;
case COMMAND_CONFIGURE:
@@ -654,9 +656,8 @@ EntryWidgetObjCmd(
entryPtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
} else {
result = ConfigureEntry(interp, entryPtr, objc-2, objv+2, 0);
}
@@ -690,7 +691,7 @@ EntryWidgetObjCmd(
Tcl_WrongNumArgs(interp, 2, objv, NULL);
goto error;
}
- Tcl_SetStringObj(Tcl_GetObjResult(interp), entryPtr->string, -1);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, -1));
break;
case COMMAND_ICURSOR:
@@ -739,7 +740,7 @@ EntryWidgetObjCmd(
case COMMAND_SCAN: {
int x;
- char *minorCmd;
+ const char *minorCmd;
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "mark|dragto x");
@@ -758,9 +759,11 @@ EntryWidgetObjCmd(
&& (strncmp(minorCmd, "dragto", strlen(minorCmd)) == 0)) {
EntryScanTo(entryPtr, x);
} else {
- Tcl_AppendResult(interp, "bad scan option \"",
- Tcl_GetString(objv[2]), "\": must be mark or dragto",
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad scan option \"%s\": must be mark or dragto",
+ minorCmd));
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "scan option",
+ minorCmd, NULL);
goto error;
}
break;
@@ -854,7 +857,7 @@ EntryWidgetObjCmd(
goto error;
}
Tcl_SetObjResult(interp,
- Tcl_NewBooleanObj((entryPtr->selectFirst >= 0)));
+ Tcl_NewBooleanObj(entryPtr->selectFirst >= 0));
goto done;
case SELECTION_RANGE:
@@ -880,7 +883,7 @@ EntryWidgetObjCmd(
if (!(entryPtr->flags & GOT_SELECTION)
&& (entryPtr->exportSelection)) {
Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY,
- EntryLostSelection, (ClientData) entryPtr);
+ EntryLostSelection, entryPtr);
entryPtr->flags |= GOT_SELECTION;
}
EventuallyRedraw(entryPtr);
@@ -915,7 +918,7 @@ EntryWidgetObjCmd(
if (entryPtr->validate != VALIDATE_NONE) {
entryPtr->validate = selIndex;
}
- Tcl_SetObjResult(interp, Tcl_NewBooleanObj((code == TCL_OK)));
+ Tcl_SetObjResult(interp, Tcl_NewBooleanObj(code == TCL_OK));
break;
}
@@ -924,13 +927,12 @@ EntryWidgetObjCmd(
if (objc == 2) {
double first, last;
- char buf[TCL_DOUBLE_SPACE];
+ Tcl_Obj *span[2];
EntryVisibleRange(entryPtr, &first, &last);
- Tcl_PrintDouble(NULL, first, buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- Tcl_PrintDouble(NULL, last, buf);
- Tcl_AppendResult(interp, " ", buf, NULL);
+ span[0] = Tcl_NewDoubleObj(first);
+ span[1] = Tcl_NewDoubleObj(last);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(2, span));
goto done;
} else if (objc == 3) {
if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
@@ -980,11 +982,11 @@ EntryWidgetObjCmd(
}
done:
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
return result;
error:
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
return TCL_ERROR;
}
@@ -1008,9 +1010,9 @@ EntryWidgetObjCmd(
static void
DestroyEntry(
- char *memPtr) /* Info about entry widget. */
+ void *memPtr) /* Info about entry widget. */
{
- Entry *entryPtr = (Entry *) memPtr;
+ Entry *entryPtr = memPtr;
/*
* Free up all the stuff that requires special handling, then let
@@ -1019,9 +1021,9 @@ DestroyEntry(
ckfree((char *)entryPtr->string);
if (entryPtr->textVarName != NULL) {
- Tcl_UntraceVar(entryPtr->interp, entryPtr->textVarName,
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- EntryTextVarProc, (ClientData) entryPtr);
+ Tcl_UntraceVar2(entryPtr->interp, entryPtr->textVarName,
+ NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ EntryTextVarProc, entryPtr);
entryPtr->flags &= ~ENTRY_VAR_TRACED;
}
if (entryPtr->textGC != None) {
@@ -1048,10 +1050,10 @@ DestroyEntry(
Tk_FreeTextLayout(entryPtr->textLayout);
Tk_FreeConfigOptions((char *) entryPtr, entryPtr->optionTable,
entryPtr->tkwin);
- Tcl_Release((ClientData) entryPtr->tkwin);
+ Tcl_Release(entryPtr->tkwin);
entryPtr->tkwin = NULL;
- ckfree((char *) entryPtr);
+ ckfree(entryPtr);
}
/*
@@ -1103,9 +1105,9 @@ ConfigureEntry(
if ((entryPtr->textVarName != NULL)
&& (entryPtr->flags & ENTRY_VAR_TRACED)) {
- Tcl_UntraceVar(interp, entryPtr->textVarName,
+ Tcl_UntraceVar2(interp, entryPtr->textVarName, NULL,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- EntryTextVarProc, (ClientData) entryPtr);
+ EntryTextVarProc, entryPtr);
entryPtr->flags &= ~ENTRY_VAR_TRACED;
}
@@ -1114,12 +1116,12 @@ ConfigureEntry(
* value.
*/
- oldExport = entryPtr->exportSelection;
+ oldExport = entryPtr->exportSelection;
if (entryPtr->type == TK_SPINBOX) {
- oldValues = sbPtr->valueStr;
- oldFormat = sbPtr->reqFormat;
- oldFrom = sbPtr->fromValue;
- oldTo = sbPtr->toValue;
+ oldValues = sbPtr->valueStr;
+ oldFormat = sbPtr->reqFormat;
+ oldFrom = sbPtr->fromValue;
+ oldTo = sbPtr->toValue;
}
for (error = 0; error <= 1; error++) {
@@ -1168,9 +1170,11 @@ ConfigureEntry(
if (entryPtr->type == TK_SPINBOX) {
if (sbPtr->fromValue > sbPtr->toValue) {
- Tcl_SetResult(interp,
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
"-to value must be greater than -from value",
- TCL_VOLATILE);
+ -1));
+ Tcl_SetErrorCode(interp, "TK", "SPINBOX", "RANGE_SANITY",
+ NULL);
continue;
}
@@ -1187,9 +1191,12 @@ ConfigureEntry(
formatLen = strlen(fmt);
if ((fmt[0] != '%') || (fmt[formatLen-1] != 'f')) {
- badFormatOpt:
- Tcl_AppendResult(interp, "bad spinbox format specifier \"",
- sbPtr->reqFormat, "\"", NULL);
+ badFormatOpt:
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad spinbox format specifier \"%s\"",
+ sbPtr->reqFormat));
+ Tcl_SetErrorCode(interp, "TK", "SPINBOX", "FORMAT_SANITY",
+ NULL);
continue;
}
if ((sscanf(fmt, "%%%d.%d%[f]", &min, &max, fbuf) == 3)
@@ -1266,7 +1273,7 @@ ConfigureEntry(
&& (entryPtr->selectFirst != -1)
&& !(entryPtr->flags & GOT_SELECTION)) {
Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection,
- (ClientData) entryPtr);
+ entryPtr);
entryPtr->flags |= GOT_SELECTION;
}
@@ -1296,7 +1303,7 @@ ConfigureEntry(
if (entryPtr->textVarName != NULL) {
const char *value;
- value = Tcl_GetVar(interp, entryPtr->textVarName, TCL_GLOBAL_ONLY);
+ value = Tcl_GetVar2(interp, entryPtr->textVarName, NULL, TCL_GLOBAL_ONLY);
if (value == NULL) {
EntryValueChanged(entryPtr, NULL);
} else {
@@ -1333,12 +1340,10 @@ ConfigureEntry(
if (sscanf(entryPtr->string, "%lf", &dvalue) == 0) {
/* Scan failure */
dvalue = sbPtr->fromValue;
- } else {
- if (dvalue > sbPtr->toValue) {
- dvalue = sbPtr->toValue;
- } else if (dvalue < sbPtr->fromValue) {
- dvalue = sbPtr->fromValue;
- }
+ } else if (dvalue > sbPtr->toValue) {
+ dvalue = sbPtr->toValue;
+ } else if (dvalue < sbPtr->fromValue) {
+ dvalue = sbPtr->fromValue;
}
sprintf(sbPtr->formatBuf, sbPtr->valueFormat, dvalue);
EntryValueChanged(entryPtr, sbPtr->formatBuf);
@@ -1352,13 +1357,13 @@ ConfigureEntry(
if ((entryPtr->textVarName != NULL)
&& !(entryPtr->flags & ENTRY_VAR_TRACED)) {
- Tcl_TraceVar(interp, entryPtr->textVarName,
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- EntryTextVarProc, (ClientData) entryPtr);
+ Tcl_TraceVar2(interp, entryPtr->textVarName,
+ NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ EntryTextVarProc, entryPtr);
entryPtr->flags |= ENTRY_VAR_TRACED;
}
- EntryWorldChanged((ClientData) entryPtr);
+ EntryWorldChanged(entryPtr);
if (error) {
Tcl_SetObjResult(interp, errorResult);
Tcl_DecrRefCount(errorResult);
@@ -1395,7 +1400,7 @@ EntryWorldChanged(
unsigned long mask;
Tk_3DBorder border;
XColor *colorPtr;
- Entry *entryPtr = (Entry *) instanceData;
+ Entry *entryPtr = instanceData;
entryPtr->avgWidth = Tk_TextWidth(entryPtr->tkfont, "0", 1);
if (entryPtr->avgWidth == 0) {
@@ -1419,8 +1424,8 @@ EntryWorldChanged(
* the background may be overridden.
*/
- border = entryPtr->normalBorder;
- colorPtr = entryPtr->fgColorPtr;
+ border = entryPtr->normalBorder;
+ colorPtr = entryPtr->fgColorPtr;
switch (entryPtr->state) {
case STATE_DISABLED:
if (entryPtr->disabledBorder != NULL) {
@@ -1547,7 +1552,7 @@ static void
DisplayEntry(
ClientData clientData) /* Information about window. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
Tk_Window tkwin = entryPtr->tkwin;
int baseY, selStartX, selEndX, cursorX;
int showSelection, xBound;
@@ -1574,14 +1579,14 @@ DisplayEntry(
* side-effect of destroying or unmapping the entry widget.
*/
- Tcl_Preserve((ClientData) entryPtr);
+ Tcl_Preserve(entryPtr);
EntryUpdateScrollbar(entryPtr);
if ((entryPtr->flags & ENTRY_DELETED) || !Tk_IsMapped(tkwin)) {
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
return;
}
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
}
#ifndef TK_NO_DOUBLE_BUFFERING
@@ -1652,7 +1657,7 @@ DisplayEntry(
baseY - fm.ascent - entryPtr->selBorderWidth,
(selEndX - selStartX) + 2*entryPtr->selBorderWidth,
(fm.ascent + fm.descent) + 2*entryPtr->selBorderWidth,
- entryPtr->selBorderWidth,
+ entryPtr->selBorderWidth,
#ifndef MAC_OSX_TK
TK_RELIEF_RAISED
#else
@@ -1902,7 +1907,7 @@ EntryComputeGeometry(
size = Tcl_UniCharToUtf(ch, buf);
entryPtr->numDisplayBytes = entryPtr->numChars * size;
- p = (char *) ckalloc((unsigned) (entryPtr->numDisplayBytes + 1));
+ p = ckalloc(entryPtr->numDisplayBytes + 1);
entryPtr->displayString = p;
for (i = entryPtr->numChars; --i >= 0; ) {
@@ -1966,12 +1971,10 @@ EntryComputeGeometry(
height = fm.linespace + 2*entryPtr->inset + 2*(YPAD-XPAD);
if (entryPtr->prefWidth > 0) {
width = entryPtr->prefWidth*entryPtr->avgWidth + 2*entryPtr->inset;
+ } else if (totalLength == 0) {
+ width = entryPtr->avgWidth + 2*entryPtr->inset;
} else {
- if (totalLength == 0) {
- width = entryPtr->avgWidth + 2*entryPtr->inset;
- } else {
- width = totalLength + 2*entryPtr->inset;
- }
+ width = totalLength + 2*entryPtr->inset;
}
/*
@@ -2004,7 +2007,7 @@ InsertChars(
Entry *entryPtr, /* Entry that is to get the new elements. */
int index, /* Add the new elements before this character
* index. */
- char *value) /* New characters to add (NULL-terminated
+ const char *value) /* New characters to add (NULL-terminated
* string). */
{
ptrdiff_t byteIndex;
@@ -2021,7 +2024,7 @@ InsertChars(
}
newByteCount = entryPtr->numBytes + byteCount + 1;
- newStr = (char *) ckalloc((unsigned) newByteCount);
+ newStr = ckalloc(newByteCount);
memcpy(newStr, string, byteIndex);
strcpy(newStr + byteIndex, value);
strcpy(newStr + byteIndex + byteCount, string + byteIndex);
@@ -2121,11 +2124,11 @@ DeleteChars(
byteCount = Tcl_UtfAtIndex(string + byteIndex, count) - (string+byteIndex);
newByteCount = entryPtr->numBytes + 1 - byteCount;
- newStr = (char *) ckalloc((unsigned) newByteCount);
+ newStr = ckalloc(newByteCount);
memcpy(newStr, string, (size_t) byteIndex);
strcpy(newStr + byteIndex, string + byteIndex + byteCount);
- toDelete = (char *) ckalloc((unsigned) (byteCount + 1));
+ toDelete = ckalloc(byteCount + 1);
memcpy(toDelete, string + byteIndex, (size_t) byteCount);
toDelete[byteCount] = '\0';
@@ -2228,8 +2231,8 @@ EntryValueChanged(
if (entryPtr->textVarName == NULL) {
newValue = NULL;
} else {
- newValue = Tcl_SetVar(entryPtr->interp, entryPtr->textVarName,
- entryPtr->string, TCL_GLOBAL_ONLY);
+ newValue = Tcl_SetVar2(entryPtr->interp, entryPtr->textVarName,
+ NULL, entryPtr->string, TCL_GLOBAL_ONLY);
}
if ((newValue != NULL) && (strcmp(newValue, entryPtr->string) != 0)) {
@@ -2297,7 +2300,7 @@ EntrySetValue(
* during validation
*/
- char *tmp = (char *) ckalloc((unsigned) (valueLen + 1));
+ char *tmp = ckalloc(valueLen + 1);
strcpy(tmp, value);
value = tmp;
@@ -2326,7 +2329,7 @@ EntrySetValue(
if (malloced) {
entryPtr->string = value;
} else {
- char *tmp = (char *) ckalloc((unsigned) (valueLen + 1));
+ char *tmp = ckalloc(valueLen + 1);
strcpy(tmp, value);
entryPtr->string = tmp;
@@ -2386,10 +2389,10 @@ EntryEventProc(
ClientData clientData, /* Information about window. */
XEvent *eventPtr) /* Information about event. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
if ((entryPtr->type == TK_SPINBOX) && (eventPtr->type == MotionNotify)) {
- Spinbox *sbPtr = (Spinbox *) clientData;
+ Spinbox *sbPtr = clientData;
int elem;
elem = GetSpinboxElement(sbPtr, eventPtr->xmotion.x,
@@ -2426,15 +2429,15 @@ EntryEventProc(
if (entryPtr->flags & REDRAW_PENDING) {
Tcl_CancelIdleCall(DisplayEntry, clientData);
}
- Tcl_EventuallyFree(clientData, DestroyEntry);
+ Tcl_EventuallyFree(clientData, (Tcl_FreeProc *) DestroyEntry);
}
break;
case ConfigureNotify:
- Tcl_Preserve((ClientData) entryPtr);
+ Tcl_Preserve(entryPtr);
entryPtr->flags |= UPDATE_SCROLLBAR;
EntryComputeGeometry(entryPtr);
EventuallyRedraw(entryPtr);
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
break;
case FocusIn:
case FocusOut:
@@ -2467,7 +2470,7 @@ static void
EntryCmdDeletedProc(
ClientData clientData) /* Pointer to widget record for widget. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
/*
* This function could be invoked either because the window was destroyed
@@ -2506,47 +2509,41 @@ GetEntryIndex(
Tcl_Interp *interp, /* For error messages. */
Entry *entryPtr, /* Entry for which the index is being
* specified. */
- char *string, /* Specifies character in entryPtr. */
+ const char *string, /* Specifies character in entryPtr. */
int *indexPtr) /* Where to store converted character index */
{
size_t length;
length = strlen(string);
- if (string[0] == 'a') {
- if (strncmp(string, "anchor", length) == 0) {
- *indexPtr = entryPtr->selectAnchor;
- } else {
- badIndex:
-
- /*
- * Some of the paths here leave messages in the interp's result,
- * so we have to clear it out before storing our own message.
- */
-
- Tcl_SetResult(interp, NULL, TCL_STATIC);
- Tcl_AppendResult(interp, "bad ",
- (entryPtr->type == TK_ENTRY) ? "entry" : "spinbox",
- " index \"", string, "\"", NULL);
- return TCL_ERROR;
+ switch (string[0]) {
+ case 'a':
+ if (strncmp(string, "anchor", length) != 0) {
+ goto badIndex;
}
- } else if (string[0] == 'e') {
- if (strncmp(string, "end", length) == 0) {
- *indexPtr = entryPtr->numChars;
- } else {
+ *indexPtr = entryPtr->selectAnchor;
+ break;
+ case 'e':
+ if (strncmp(string, "end", length) != 0) {
goto badIndex;
}
- } else if (string[0] == 'i') {
- if (strncmp(string, "insert", length) == 0) {
- *indexPtr = entryPtr->insertPos;
- } else {
+ *indexPtr = entryPtr->numChars;
+ break;
+ case 'i':
+ if (strncmp(string, "insert", length) != 0) {
goto badIndex;
}
- } else if (string[0] == 's') {
+ *indexPtr = entryPtr->insertPos;
+ break;
+ case 's':
if (entryPtr->selectFirst < 0) {
- Tcl_SetResult(interp, NULL, TCL_STATIC);
- Tcl_AppendResult(interp, "selection isn't in widget ",
- Tk_PathName(entryPtr->tkwin), NULL);
+ Tcl_ResetResult(interp);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "selection isn't in widget %s",
+ Tk_PathName(entryPtr->tkwin)));
+ Tcl_SetErrorCode(interp, "TK",
+ (entryPtr->type == TK_ENTRY) ? "ENTRY" : "SPINBOX",
+ "NO_SELECTION", NULL);
return TCL_ERROR;
}
if (length < 5) {
@@ -2559,7 +2556,8 @@ GetEntryIndex(
} else {
goto badIndex;
}
- } else if (string[0] == '@') {
+ break;
+ case '@': {
int x, roundUp, maxWidth;
if (Tcl_GetInt(interp, string + 1, &x) != TCL_OK) {
@@ -2570,7 +2568,7 @@ GetEntryIndex(
}
roundUp = 0;
maxWidth = Tk_Width(entryPtr->tkwin) - entryPtr->inset
- - entryPtr->xWidth - 1;
+ - entryPtr->xWidth - 1;
if (x > maxWidth) {
x = maxWidth;
roundUp = 1;
@@ -2588,7 +2586,9 @@ GetEntryIndex(
if (roundUp && (*indexPtr < entryPtr->numChars)) {
*indexPtr += 1;
}
- } else {
+ break;
+ }
+ default:
if (Tcl_GetInt(interp, string, indexPtr) != TCL_OK) {
goto badIndex;
}
@@ -2599,6 +2599,14 @@ GetEntryIndex(
}
}
return TCL_OK;
+
+ badIndex:
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad %s index \"%s\"",
+ (entryPtr->type == TK_ENTRY) ? "entry" : "spinbox", string));
+ Tcl_SetErrorCode(interp, "TK",
+ (entryPtr->type == TK_ENTRY) ? "ENTRY" : "SPINBOX",
+ "BAD_INDEX", NULL);
+ return TCL_ERROR;
}
/*
@@ -2690,7 +2698,7 @@ EntrySelectTo(
if (!(entryPtr->flags & GOT_SELECTION) && (entryPtr->exportSelection)) {
Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection,
- (ClientData) entryPtr);
+ entryPtr);
entryPtr->flags |= GOT_SELECTION;
}
@@ -2750,7 +2758,7 @@ EntryFetchSelection(
int maxBytes) /* Maximum number of bytes to place at buffer,
* not including terminating NUL character. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
int byteCount;
const char *string;
const char *selStart, *selEnd;
@@ -2773,7 +2781,7 @@ EntryFetchSelection(
buffer[byteCount] = '\0';
return byteCount;
}
-
+
/*
*----------------------------------------------------------------------
*
@@ -2796,7 +2804,7 @@ static void
EntryLostSelection(
ClientData clientData) /* Information about entry widget. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
entryPtr->flags &= ~GOT_SELECTION;
@@ -2850,7 +2858,7 @@ EventuallyRedraw(
if (!(entryPtr->flags & REDRAW_PENDING)) {
entryPtr->flags |= REDRAW_PENDING;
- Tcl_DoWhenIdle(DisplayEntry, (ClientData) entryPtr);
+ Tcl_DoWhenIdle(DisplayEntry, entryPtr);
}
}
@@ -2937,21 +2945,20 @@ EntryUpdateScrollbar(
}
interp = entryPtr->interp;
- Tcl_Preserve((ClientData) interp);
+ Tcl_Preserve(interp);
EntryVisibleRange(entryPtr, &first, &last);
Tcl_PrintDouble(NULL, first, firstStr);
Tcl_PrintDouble(NULL, last, lastStr);
code = Tcl_VarEval(interp, entryPtr->scrollCmd, " ", firstStr, " ",
lastStr, NULL);
if (code != TCL_OK) {
- Tcl_AddErrorInfo(interp,
- "\n (horizontal scrolling command executed by ");
- Tcl_AddErrorInfo(interp, Tk_PathName(entryPtr->tkwin));
- Tcl_AddErrorInfo(interp, ")");
- Tcl_BackgroundError(interp);
+ Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
+ "\n (horizontal scrolling command executed by %s)",
+ Tk_PathName(entryPtr->tkwin)));
+ Tcl_BackgroundException(interp, code);
}
- Tcl_SetResult(interp, NULL, TCL_STATIC);
- Tcl_Release((ClientData) interp);
+ Tcl_ResetResult(interp);
+ Tcl_Release(interp);
}
/*
@@ -2976,7 +2983,7 @@ static void
EntryBlinkProc(
ClientData clientData) /* Pointer to record describing entry. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
if ((entryPtr->state == STATE_DISABLED) ||
(entryPtr->state == STATE_READONLY) ||
@@ -2986,11 +2993,11 @@ EntryBlinkProc(
if (entryPtr->flags & CURSOR_ON) {
entryPtr->flags &= ~CURSOR_ON;
entryPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
- entryPtr->insertOffTime, EntryBlinkProc, (ClientData) entryPtr);
+ entryPtr->insertOffTime, EntryBlinkProc, entryPtr);
} else {
entryPtr->flags |= CURSOR_ON;
entryPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
- entryPtr->insertOnTime, EntryBlinkProc, (ClientData) entryPtr);
+ entryPtr->insertOnTime, EntryBlinkProc, entryPtr);
}
EventuallyRedraw(entryPtr);
}
@@ -3024,23 +3031,22 @@ EntryFocusProc(
entryPtr->flags |= GOT_FOCUS | CURSOR_ON;
if (entryPtr->insertOffTime != 0) {
entryPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
- entryPtr->insertOnTime, EntryBlinkProc,
- (ClientData) entryPtr);
+ entryPtr->insertOnTime, EntryBlinkProc, entryPtr);
}
if (entryPtr->validate == VALIDATE_ALL ||
- entryPtr->validate == VALIDATE_FOCUS ||
- entryPtr->validate == VALIDATE_FOCUSIN) {
- EntryValidateChange(entryPtr, NULL,
- entryPtr->string, -1, VALIDATE_FOCUSIN);
+ entryPtr->validate == VALIDATE_FOCUS ||
+ entryPtr->validate == VALIDATE_FOCUSIN) {
+ EntryValidateChange(entryPtr, NULL, entryPtr->string, -1,
+ VALIDATE_FOCUSIN);
}
} else {
entryPtr->flags &= ~(GOT_FOCUS | CURSOR_ON);
- entryPtr->insertBlinkHandler = (Tcl_TimerToken) NULL;
+ entryPtr->insertBlinkHandler = NULL;
if (entryPtr->validate == VALIDATE_ALL ||
- entryPtr->validate == VALIDATE_FOCUS ||
- entryPtr->validate == VALIDATE_FOCUSOUT) {
- EntryValidateChange(entryPtr, NULL,
- entryPtr->string, -1, VALIDATE_FOCUSOUT);
+ entryPtr->validate == VALIDATE_FOCUS ||
+ entryPtr->validate == VALIDATE_FOCUSOUT) {
+ EntryValidateChange(entryPtr, NULL, entryPtr->string, -1,
+ VALIDATE_FOCUSOUT);
}
}
EventuallyRedraw(entryPtr);
@@ -3072,7 +3078,7 @@ EntryTextVarProc(
const char *name2, /* Not used. */
int flags) /* Information about what happened. */
{
- Entry *entryPtr = (Entry *) clientData;
+ Entry *entryPtr = clientData;
const char *value;
if (entryPtr->flags & ENTRY_DELETED) {
@@ -3089,9 +3095,9 @@ EntryTextVarProc(
if (flags & TCL_TRACE_UNSETS) {
if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
- Tcl_SetVar(interp, entryPtr->textVarName, entryPtr->string,
- TCL_GLOBAL_ONLY);
- Tcl_TraceVar(interp, entryPtr->textVarName,
+ Tcl_SetVar2(interp, entryPtr->textVarName, NULL,
+ entryPtr->string, TCL_GLOBAL_ONLY);
+ Tcl_TraceVar2(interp, entryPtr->textVarName, NULL,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
EntryTextVarProc, clientData);
entryPtr->flags |= ENTRY_VAR_TRACED;
@@ -3105,7 +3111,7 @@ EntryTextVarProc(
* value because we changed it because someone typed in the entry).
*/
- value = Tcl_GetVar(interp, entryPtr->textVarName, TCL_GLOBAL_ONLY);
+ value = Tcl_GetVar2(interp, entryPtr->textVarName, NULL, TCL_GLOBAL_ONLY);
if (value == NULL) {
value = "";
}
@@ -3150,10 +3156,10 @@ EntryValidate(
*/
if (code != TCL_OK && code != TCL_RETURN) {
- Tcl_AddErrorInfo(interp, "\n\t(in validation command executed by ");
- Tcl_AddErrorInfo(interp, Tk_PathName(entryPtr->tkwin));
- Tcl_AddErrorInfo(interp, ")");
- Tcl_BackgroundError(interp);
+ Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
+ "\n (in validation command executed by %s)",
+ Tk_PathName(entryPtr->tkwin)));
+ Tcl_BackgroundException(interp, code);
return TCL_ERROR;
}
@@ -3164,13 +3170,13 @@ EntryValidate(
if (Tcl_GetBooleanFromObj(interp, Tcl_GetObjResult(interp),
&bool) != TCL_OK) {
Tcl_AddErrorInfo(interp,
- "\nvalid boolean not returned by validation command");
- Tcl_BackgroundError(interp);
- Tcl_SetResult(interp, NULL, 0);
+ "\n (invalid boolean result from validation command)");
+ Tcl_BackgroundException(interp, TCL_ERROR);
+ Tcl_ResetResult(interp);
return TCL_ERROR;
}
- Tcl_SetResult(interp, NULL, 0);
+ Tcl_ResetResult(interp);
return (bool ? TCL_OK : TCL_BREAK);
}
@@ -3196,7 +3202,7 @@ EntryValidate(
static int
EntryValidateChange(
register Entry *entryPtr, /* Entry that needs validation. */
- char *change, /* Characters to be added/deleted
+ const char *change, /* Characters to be added/deleted
* (NUL-terminated string). */
const char *newValue, /* Potential new value of entry string */
int index, /* index of insert/delete, -1 otherwise */
@@ -3279,16 +3285,19 @@ EntryValidateChange(
if (varValidate) {
entryPtr->validate = VALIDATE_NONE;
} else if (entryPtr->invalidCmd != NULL) {
+ int result;
+
Tcl_DStringInit(&script);
ExpandPercents(entryPtr, entryPtr->invalidCmd,
change, newValue, index, type, &script);
Tcl_DStringAppend(&script, "", 1);
p = Tcl_DStringValue(&script);
- if (Tcl_EvalEx(entryPtr->interp, p, -1,
- TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT) != TCL_OK) {
+ result = Tcl_EvalEx(entryPtr->interp, p, -1,
+ TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
+ if (result != TCL_OK) {
Tcl_AddErrorInfo(entryPtr->interp,
- "\n\t(in invalidcommand executed by entry)");
- Tcl_BackgroundError(entryPtr->interp);
+ "\n (in invalidcommand executed by entry)");
+ Tcl_BackgroundException(entryPtr->interp, result);
code = TCL_ERROR;
entryPtr->validate = VALIDATE_NONE;
}
@@ -3508,7 +3517,7 @@ Tk_SpinboxObjCmd(
char *tmp;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
+ Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
return TCL_ERROR;
}
@@ -3532,7 +3541,7 @@ Tk_SpinboxObjCmd(
* initialized as memset covers the rest.
*/
- sbPtr = (Spinbox *) ckalloc(sizeof(Spinbox));
+ sbPtr = ckalloc(sizeof(Spinbox));
entryPtr = (Entry *) sbPtr;
memset(sbPtr, 0, sizeof(Spinbox));
@@ -3540,11 +3549,11 @@ Tk_SpinboxObjCmd(
entryPtr->display = Tk_Display(tkwin);
entryPtr->interp = interp;
entryPtr->widgetCmd = Tcl_CreateObjCommand(interp,
- Tk_PathName(entryPtr->tkwin), SpinboxWidgetObjCmd,
- (ClientData) sbPtr, EntryCmdDeletedProc);
+ Tk_PathName(entryPtr->tkwin), SpinboxWidgetObjCmd, sbPtr,
+ EntryCmdDeletedProc);
entryPtr->optionTable = optionTable;
entryPtr->type = TK_SPINBOX;
- tmp = (char *) ckalloc(1);
+ tmp = ckalloc(1);
tmp[0] = '\0';
entryPtr->string = tmp;
entryPtr->selectFirst = -1;
@@ -3571,7 +3580,7 @@ Tk_SpinboxObjCmd(
sbPtr->fromValue = 0.0;
sbPtr->toValue = 100.0;
sbPtr->increment = 1.0;
- sbPtr->formatBuf = (char *) ckalloc(TCL_DOUBLE_SPACE);
+ sbPtr->formatBuf = ckalloc(TCL_DOUBLE_SPACE);
sbPtr->bdRelief = TK_RELIEF_FLAT;
sbPtr->buRelief = TK_RELIEF_FLAT;
@@ -3580,15 +3589,15 @@ Tk_SpinboxObjCmd(
* otherwise Tk might free it while we still need it.
*/
- Tcl_Preserve((ClientData) entryPtr->tkwin);
+ Tcl_Preserve(entryPtr->tkwin);
Tk_SetClass(entryPtr->tkwin, "Spinbox");
- Tk_SetClassProcs(entryPtr->tkwin, &entryClass, (ClientData) entryPtr);
+ Tk_SetClassProcs(entryPtr->tkwin, &entryClass, entryPtr);
Tk_CreateEventHandler(entryPtr->tkwin,
PointerMotionMask|ExposureMask|StructureNotifyMask|FocusChangeMask,
- EntryEventProc, (ClientData) entryPtr);
+ EntryEventProc, entryPtr);
Tk_CreateSelHandler(entryPtr->tkwin, XA_PRIMARY, XA_STRING,
- EntryFetchSelection, (ClientData) entryPtr, XA_STRING);
+ EntryFetchSelection, entryPtr, XA_STRING);
if (Tk_InitOptions(interp, (char *) sbPtr, optionTable, tkwin)
!= TCL_OK) {
@@ -3599,10 +3608,10 @@ Tk_SpinboxObjCmd(
goto error;
}
- Tcl_SetResult(interp, Tk_PathName(entryPtr->tkwin), TCL_STATIC);
+ Tcl_SetObjResult(interp, TkNewWindowObj(entryPtr->tkwin));
return TCL_OK;
- error:
+ error:
Tk_DestroyWindow(entryPtr->tkwin);
return TCL_ERROR;
}
@@ -3632,13 +3641,13 @@ SpinboxWidgetObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
- Entry *entryPtr = (Entry *) clientData;
- Spinbox *sbPtr = (Spinbox *) clientData;
+ Entry *entryPtr = clientData;
+ Spinbox *sbPtr = clientData;
int cmdIndex, selIndex, result;
Tcl_Obj *objPtr;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
+ Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
return TCL_ERROR;
}
@@ -3653,11 +3662,11 @@ SpinboxWidgetObjCmd(
return result;
}
- Tcl_Preserve((ClientData) entryPtr);
+ Tcl_Preserve(entryPtr);
switch ((enum sbCmd) cmdIndex) {
case SB_CMD_BBOX: {
int index, x, y, width, height;
- char buf[TCL_INTEGER_SPACE * 4];
+ Tcl_Obj *bbox[4];
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "index");
@@ -3670,11 +3679,12 @@ SpinboxWidgetObjCmd(
if ((index == entryPtr->numChars) && (index > 0)) {
index--;
}
- Tk_CharBbox(entryPtr->textLayout, index, &x, &y,
- &width, &height);
- sprintf(buf, "%d %d %d %d", x + entryPtr->layoutX,
- y + entryPtr->layoutY, width, height);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tk_CharBbox(entryPtr->textLayout, index, &x, &y, &width, &height);
+ bbox[0] = Tcl_NewIntObj(x + entryPtr->layoutX);
+ bbox[1] = Tcl_NewIntObj(y + entryPtr->layoutY);
+ bbox[2] = Tcl_NewIntObj(width);
+ bbox[3] = Tcl_NewIntObj(height);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(4, bbox));
break;
}
@@ -3688,22 +3698,19 @@ SpinboxWidgetObjCmd(
entryPtr->optionTable, objv[2], entryPtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
break;
case SB_CMD_CONFIGURE:
if (objc <= 3) {
objPtr = Tk_GetOptionInfo(interp, (char *) entryPtr,
- entryPtr->optionTable,
- (objc == 3) ? objv[2] : NULL,
+ entryPtr->optionTable, (objc == 3) ? objv[2] : NULL,
entryPtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
} else {
result = ConfigureEntry(interp, entryPtr, objc-2, objv+2, 0);
}
@@ -3739,7 +3746,7 @@ SpinboxWidgetObjCmd(
Tcl_WrongNumArgs(interp, 2, objv, NULL);
goto error;
}
- Tcl_SetStringObj(Tcl_GetObjResult(interp), entryPtr->string, -1);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, -1));
break;
case SB_CMD_ICURSOR:
@@ -3767,8 +3774,8 @@ SpinboxWidgetObjCmd(
}
elem = GetSpinboxElement(sbPtr, x, y);
if (elem != SEL_NONE) {
- Tcl_SetStringObj(Tcl_GetObjResult(interp),
- selElementNames[elem], -1);
+ Tcl_SetObjResult(interp,
+ Tcl_NewStringObj(selElementNames[elem], -1));
}
break;
}
@@ -3824,7 +3831,7 @@ SpinboxWidgetObjCmd(
case SB_CMD_SCAN: {
int x;
- char *minorCmd;
+ const char *minorCmd;
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "mark|dragto x");
@@ -3843,9 +3850,11 @@ SpinboxWidgetObjCmd(
&& (strncmp(minorCmd, "dragto", strlen(minorCmd)) == 0)) {
EntryScanTo(entryPtr, x);
} else {
- Tcl_AppendResult(interp, "bad scan option \"",
- Tcl_GetString(objv[2]), "\": must be mark or dragto",
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad scan option \"%s\": must be mark or dragto",
+ minorCmd));
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "scan option",
+ minorCmd, NULL);
goto error;
}
break;
@@ -3938,8 +3947,8 @@ SpinboxWidgetObjCmd(
Tcl_WrongNumArgs(interp, 3, objv, NULL);
goto error;
}
- Tcl_SetObjResult(interp,
- Tcl_NewBooleanObj((entryPtr->selectFirst >= 0)));
+ Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
+ entryPtr->selectFirst >= 0));
goto done;
case SB_SEL_RANGE:
@@ -3963,9 +3972,9 @@ SpinboxWidgetObjCmd(
entryPtr->selectLast = index2;
}
if (!(entryPtr->flags & GOT_SELECTION)
- && (entryPtr->exportSelection)) {
+ && entryPtr->exportSelection) {
Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY,
- EntryLostSelection, (ClientData) entryPtr);
+ EntryLostSelection, entryPtr);
entryPtr->flags |= GOT_SELECTION;
}
EventuallyRedraw(entryPtr);
@@ -3989,8 +3998,8 @@ SpinboxWidgetObjCmd(
goto error;
}
if (objc == 3) {
- Tcl_SetStringObj(Tcl_GetObjResult(interp),
- selElementNames[sbPtr->selElement], -1);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ selElementNames[sbPtr->selElement], -1));
} else {
int lastElement = sbPtr->selElement;
@@ -4016,7 +4025,7 @@ SpinboxWidgetObjCmd(
if (objc == 3) {
EntryValueChanged(entryPtr, Tcl_GetString(objv[2]));
}
- Tcl_SetStringObj(Tcl_GetObjResult(interp), entryPtr->string, -1);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(entryPtr->string, -1));
break;
case SB_CMD_VALIDATE: {
@@ -4033,7 +4042,8 @@ SpinboxWidgetObjCmd(
if (entryPtr->validate != VALIDATE_NONE) {
entryPtr->validate = selIndex;
}
- Tcl_SetObjResult(interp, Tcl_NewBooleanObj((code == TCL_OK)));
+
+ Tcl_SetObjResult(interp, Tcl_NewBooleanObj(code == TCL_OK));
break;
}
@@ -4042,13 +4052,12 @@ SpinboxWidgetObjCmd(
if (objc == 2) {
double first, last;
- char buf[TCL_DOUBLE_SPACE];
+ Tcl_Obj *span[2];
EntryVisibleRange(entryPtr, &first, &last);
- Tcl_PrintDouble(NULL, first, buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
- Tcl_PrintDouble(NULL, last, buf);
- Tcl_AppendResult(interp, " ", buf, NULL);
+ span[0] = Tcl_NewDoubleObj(first);
+ span[1] = Tcl_NewDoubleObj(last);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(2, span));
goto done;
} else if (objc == 3) {
if (GetEntryIndex(interp, entryPtr, Tcl_GetString(objv[2]),
@@ -4099,11 +4108,11 @@ SpinboxWidgetObjCmd(
}
done:
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
return result;
error:
- Tcl_Release((ClientData) entryPtr);
+ Tcl_Release(entryPtr);
return TCL_ERROR;
}
@@ -4172,7 +4181,7 @@ SpinboxInvoke(
* "down" button. */
{
Entry *entryPtr = (Entry *) sbPtr;
- char *type;
+ const char *type;
int code, up;
Tcl_DString script;
@@ -4202,7 +4211,7 @@ SpinboxInvoke(
*/
int i, listc, elemLen, length = entryPtr->numChars;
- char *bytes;
+ const char *bytes;
Tcl_Obj **listv;
Tcl_ListObjGetElements(interp, sbPtr->listObj, &listc, &listv);
@@ -4296,8 +4305,9 @@ SpinboxInvoke(
Tcl_DStringFree(&script);
if (code != TCL_OK) {
- Tcl_AddErrorInfo(interp, "\n\t(in command executed by spinbox)");
- Tcl_BackgroundError(interp);
+ Tcl_AddErrorInfo(interp,
+ "\n (in command executed by spinbox)");
+ Tcl_BackgroundException(interp, code);
/*
* Yes, it's an error, but a bg one, so we return OK
@@ -4306,7 +4316,7 @@ SpinboxInvoke(
return TCL_OK;
}
- Tcl_SetResult(interp, NULL, 0);
+ Tcl_ResetResult(interp);
}
return TCL_OK;