summaryrefslogtreecommitdiffstats
path: root/generic/tkScale.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkScale.c')
-rw-r--r--generic/tkScale.c134
1 files changed, 63 insertions, 71 deletions
diff --git a/generic/tkScale.c b/generic/tkScale.c
index 69a7d91..cc7c294 100644
--- a/generic/tkScale.c
+++ b/generic/tkScale.c
@@ -42,17 +42,17 @@ static const char *const stateStrings[] = {
static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground",
DEF_SCALE_ACTIVE_BG_COLOR, -1, Tk_Offset(TkScale, activeBorder),
- 0, (ClientData) DEF_SCALE_ACTIVE_BG_MONO, 0},
+ 0, DEF_SCALE_ACTIVE_BG_MONO, 0},
{TK_OPTION_BORDER, "-background", "background", "Background",
DEF_SCALE_BG_COLOR, -1, Tk_Offset(TkScale, bgBorder),
- 0, (ClientData) DEF_SCALE_BG_MONO, 0},
+ 0, DEF_SCALE_BG_MONO, 0},
{TK_OPTION_DOUBLE, "-bigincrement", "bigIncrement", "BigIncrement",
DEF_SCALE_BIG_INCREMENT, -1, Tk_Offset(TkScale, bigIncrement),
0, 0, 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_SCALE_BORDER_WIDTH, -1, Tk_Offset(TkScale, borderWidth),
0, 0, 0},
@@ -66,7 +66,7 @@ static const Tk_OptionSpec optionSpecs[] = {
DEF_SCALE_DIGITS, -1, Tk_Offset(TkScale, digits),
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_SCALE_FONT, -1, Tk_Offset(TkScale, tkfont), 0, 0, 0},
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
@@ -77,7 +77,7 @@ static const Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_BORDER, "-highlightbackground", "highlightBackground",
"HighlightBackground", DEF_SCALE_HIGHLIGHT_BG_COLOR,
-1, Tk_Offset(TkScale, highlightBorder),
- 0, (ClientData) DEF_SCALE_HIGHLIGHT_BG_MONO, 0},
+ 0, DEF_SCALE_HIGHLIGHT_BG_MONO, 0},
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
DEF_SCALE_HIGHLIGHT, -1, Tk_Offset(TkScale, highlightColorPtr),
0, 0, 0},
@@ -91,7 +91,7 @@ static const Tk_OptionSpec optionSpecs[] = {
DEF_SCALE_LENGTH, -1, Tk_Offset(TkScale, length), 0, 0, 0},
{TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
DEF_SCALE_ORIENT, -1, Tk_Offset(TkScale, orient),
- 0, (ClientData) orientStrings, 0},
+ 0, orientStrings, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
DEF_SCALE_RELIEF, -1, Tk_Offset(TkScale, relief), 0, 0, 0},
{TK_OPTION_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
@@ -114,7 +114,7 @@ static const Tk_OptionSpec optionSpecs[] = {
0, 0, 0},
{TK_OPTION_STRING_TABLE, "-state", "state", "State",
DEF_SCALE_STATE, -1, Tk_Offset(TkScale, state),
- 0, (ClientData) stateStrings, 0},
+ 0, stateStrings, 0},
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_SCALE_TAKE_FOCUS, Tk_Offset(TkScale, takeFocusPtr), -1,
TK_OPTION_NULL_OK, 0, 0},
@@ -125,7 +125,7 @@ static const Tk_OptionSpec optionSpecs[] = {
DEF_SCALE_TO, -1, Tk_Offset(TkScale, toValue), 0, 0, 0},
{TK_OPTION_COLOR, "-troughcolor", "troughColor", "Background",
DEF_SCALE_TROUGH_COLOR, -1, Tk_Offset(TkScale, troughColorPtr),
- 0, (ClientData) DEF_SCALE_TROUGH_MONO, 0},
+ 0, DEF_SCALE_TROUGH_MONO, 0},
{TK_OPTION_STRING, "-variable", "variable", "Variable",
DEF_SCALE_VARIABLE, Tk_Offset(TkScale, varNamePtr), -1,
TK_OPTION_NULL_OK, 0, 0},
@@ -140,7 +140,7 @@ static const Tk_OptionSpec optionSpecs[] = {
* scale widget command.
*/
-static const char *commandNames[] = {
+static const char *const commandNames[] = {
"cget", "configure", "coords", "get", "identify", "set", NULL
};
@@ -175,9 +175,11 @@ static void ScaleSetVariable(TkScale *scalePtr);
* that can be invoked from generic window code.
*/
-static Tk_ClassProcs scaleClass = {
+static const Tk_ClassProcs scaleClass = {
sizeof(Tk_ClassProcs), /* size */
ScaleWorldChanged, /* worldChangedProc */
+ NULL, /* createProc */
+ NULL /* modalProc */
};
/*
@@ -209,7 +211,7 @@ Tk_ScaleObjCmd(
Tk_Window tkwin;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
+ Tcl_WrongNumArgs(interp, 1, objv, "pathName ?-option value ...?");
return TCL_ERROR;
}
@@ -240,7 +242,7 @@ Tk_ScaleObjCmd(
scalePtr->interp = interp;
scalePtr->widgetCmd = Tcl_CreateObjCommand(interp,
Tk_PathName(scalePtr->tkwin), ScaleWidgetObjCmd,
- (ClientData) scalePtr, ScaleCmdDeletedProc);
+ scalePtr, ScaleCmdDeletedProc);
scalePtr->optionTable = optionTable;
scalePtr->orient = ORIENT_VERTICAL;
scalePtr->width = 0;
@@ -289,10 +291,10 @@ Tk_ScaleObjCmd(
scalePtr->takeFocusPtr = NULL;
scalePtr->flags = NEVER_SET;
- Tk_SetClassProcs(scalePtr->tkwin, &scaleClass, (ClientData) scalePtr);
+ Tk_SetClassProcs(scalePtr->tkwin, &scaleClass, scalePtr);
Tk_CreateEventHandler(scalePtr->tkwin,
ExposureMask|StructureNotifyMask|FocusChangeMask,
- ScaleEventProc, (ClientData) scalePtr);
+ ScaleEventProc, scalePtr);
if ((Tk_InitOptions(interp, (char *) scalePtr, optionTable, tkwin)
!= TCL_OK) ||
@@ -301,7 +303,7 @@ Tk_ScaleObjCmd(
return TCL_ERROR;
}
- Tcl_SetResult(interp, Tk_PathName(scalePtr->tkwin), TCL_STATIC);
+ Tcl_SetObjResult(interp, TkNewWindowObj(scalePtr->tkwin));
return TCL_OK;
}
@@ -330,20 +332,20 @@ ScaleWidgetObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument strings. */
{
- TkScale *scalePtr = (TkScale *) clientData;
+ TkScale *scalePtr = clientData;
Tcl_Obj *objPtr;
int index, result;
if (objc < 2) {
- Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
+ Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
return TCL_ERROR;
}
- result = Tcl_GetIndexFromObj(interp, objv[1], commandNames,
- "option", 0, &index);
+ result = Tcl_GetIndexFromObjStruct(interp, objv[1], commandNames,
+ sizeof(char *), "option", 0, &index);
if (result != TCL_OK) {
return result;
}
- Tcl_Preserve((ClientData) scalePtr);
+ Tcl_Preserve(scalePtr);
switch (index) {
case COMMAND_CGET:
@@ -355,9 +357,8 @@ ScaleWidgetObjCmd(
scalePtr->optionTable, objv[2], scalePtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
break;
case COMMAND_CONFIGURE:
if (objc <= 3) {
@@ -366,17 +367,16 @@ ScaleWidgetObjCmd(
(objc == 3) ? objv[2] : NULL, scalePtr->tkwin);
if (objPtr == NULL) {
goto error;
- } else {
- Tcl_SetObjResult(interp, objPtr);
}
+ Tcl_SetObjResult(interp, objPtr);
} else {
result = ConfigureScale(interp, scalePtr, objc-2, objv+2);
}
break;
case COMMAND_COORDS: {
- int x, y ;
+ int x, y;
double value;
- char buf[TCL_INTEGER_SPACE * 2];
+ Tcl_Obj *coords[2];
if ((objc != 2) && (objc != 3)) {
Tcl_WrongNumArgs(interp, 1, objv, "coords ?value?");
@@ -398,14 +398,14 @@ ScaleWidgetObjCmd(
y = scalePtr->horizTroughY + scalePtr->width/2
+ scalePtr->borderWidth;
}
- sprintf(buf, "%d %d", x, y);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ coords[0] = Tcl_NewIntObj(x);
+ coords[1] = Tcl_NewIntObj(y);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(2, coords));
break;
}
case COMMAND_GET: {
double value;
int x, y;
- char buf[TCL_DOUBLE_SPACE];
if ((objc != 2) && (objc != 4)) {
Tcl_WrongNumArgs(interp, 1, objv, "get ?x y?");
@@ -420,12 +420,12 @@ ScaleWidgetObjCmd(
}
value = TkScalePixelToValue(scalePtr, x, y);
}
- sprintf(buf, scalePtr->format, value);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(scalePtr->format, value));
break;
}
case COMMAND_IDENTIFY: {
- int x, y, thing;
+ int x, y;
+ const char *zone = "";
if (objc != 4) {
Tcl_WrongNumArgs(interp, 1, objv, "identify x y");
@@ -435,18 +435,12 @@ ScaleWidgetObjCmd(
|| (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
goto error;
}
- thing = TkpScaleElement(scalePtr, x,y);
- switch (thing) {
- case TROUGH1:
- Tcl_SetResult(interp, "trough1", TCL_STATIC);
- break;
- case SLIDER:
- Tcl_SetResult(interp, "slider", TCL_STATIC);
- break;
- case TROUGH2:
- Tcl_SetResult(interp, "trough2", TCL_STATIC);
- break;
+ switch (TkpScaleElement(scalePtr, x, y)) {
+ case TROUGH1: zone = "trough1"; break;
+ case SLIDER: zone = "slider"; break;
+ case TROUGH2: zone = "trough2"; break;
}
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, -1));
break;
}
case COMMAND_SET: {
@@ -465,11 +459,11 @@ ScaleWidgetObjCmd(
break;
}
}
- Tcl_Release((ClientData) scalePtr);
+ Tcl_Release(scalePtr);
return result;
error:
- Tcl_Release((ClientData) scalePtr);
+ Tcl_Release(scalePtr);
return TCL_ERROR;
}
@@ -501,7 +495,7 @@ DestroyScale(
Tcl_DeleteCommandFromToken(scalePtr->interp, scalePtr->widgetCmd);
if (scalePtr->flags & REDRAW_PENDING) {
- Tcl_CancelIdleCall(TkpDisplayScale, (ClientData) scalePtr);
+ Tcl_CancelIdleCall(TkpDisplayScale, scalePtr);
}
/*
@@ -510,9 +504,9 @@ DestroyScale(
*/
if (scalePtr->varNamePtr != NULL) {
- Tcl_UntraceVar(scalePtr->interp, Tcl_GetString(scalePtr->varNamePtr),
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- ScaleVarProc, (ClientData) scalePtr);
+ Tcl_UntraceVar2(scalePtr->interp, Tcl_GetString(scalePtr->varNamePtr),
+ NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ ScaleVarProc, scalePtr);
}
if (scalePtr->troughGC != None) {
Tk_FreeGC(scalePtr->display, scalePtr->troughGC);
@@ -567,9 +561,9 @@ ConfigureScale(
*/
if (scalePtr->varNamePtr != NULL) {
- Tcl_UntraceVar(interp, Tcl_GetString(scalePtr->varNamePtr),
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- ScaleVarProc, (ClientData) scalePtr);
+ Tcl_UntraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr),
+ NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ ScaleVarProc, scalePtr);
}
for (error = 0; error <= 1; error++) {
@@ -579,8 +573,8 @@ ConfigureScale(
*/
if (Tk_SetOptions(interp, (char *) scalePtr,
- scalePtr->optionTable, objc, objv,
- scalePtr->tkwin, &savedOptions, NULL) != TCL_OK) {
+ scalePtr->optionTable, objc, objv, scalePtr->tkwin,
+ &savedOptions, NULL) != TCL_OK) {
continue;
}
} else {
@@ -683,12 +677,12 @@ ConfigureScale(
ScaleSetVariable(scalePtr);
}
}
- Tcl_TraceVar(interp, Tcl_GetString(scalePtr->varNamePtr),
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
- ScaleVarProc, (ClientData) scalePtr);
+ Tcl_TraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr),
+ NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ ScaleVarProc, scalePtr);
}
- ScaleWorldChanged((ClientData) scalePtr);
+ ScaleWorldChanged(scalePtr);
if (error) {
Tcl_SetObjResult(interp, errorResult);
Tcl_DecrRefCount(errorResult);
@@ -721,9 +715,7 @@ ScaleWorldChanged(
{
XGCValues gcValues;
GC gc;
- TkScale *scalePtr;
-
- scalePtr = (TkScale *) instanceData;
+ TkScale *scalePtr = instanceData;
gcValues.foreground = scalePtr->troughColorPtr->pixel;
gc = Tk_GetGC(scalePtr->tkwin, GCForeground, &gcValues);
@@ -1008,12 +1000,12 @@ ScaleEventProc(
ClientData clientData, /* Information about window. */
XEvent *eventPtr) /* Information about event. */
{
- TkScale *scalePtr = (TkScale *) clientData;
+ TkScale *scalePtr = clientData;
if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
TkEventuallyRedrawScale(scalePtr, REDRAW_ALL);
} else if (eventPtr->type == DestroyNotify) {
- DestroyScale((char *) clientData);
+ DestroyScale(clientData);
} else if (eventPtr->type == ConfigureNotify) {
ComputeScaleGeometry(scalePtr);
TkEventuallyRedrawScale(scalePtr, REDRAW_ALL);
@@ -1056,7 +1048,7 @@ static void
ScaleCmdDeletedProc(
ClientData clientData) /* Pointer to widget record for widget. */
{
- TkScale *scalePtr = (TkScale *) clientData;
+ TkScale *scalePtr = clientData;
Tk_Window tkwin = scalePtr->tkwin;
/*
@@ -1103,7 +1095,7 @@ TkEventuallyRedrawScale(
}
if (!(scalePtr->flags & REDRAW_PENDING)) {
scalePtr->flags |= REDRAW_PENDING;
- Tcl_DoWhenIdle(TkpDisplayScale, (ClientData) scalePtr);
+ Tcl_DoWhenIdle(TkpDisplayScale, scalePtr);
}
scalePtr->flags |= what;
}
@@ -1178,8 +1170,8 @@ ScaleVarProc(
const char *name2, /* Second part of variable name. */
int flags) /* Information about what happened. */
{
- register TkScale *scalePtr = (TkScale *) clientData;
- char *resultStr;
+ register TkScale *scalePtr = clientData;
+ const char *resultStr;
double value;
Tcl_Obj *valuePtr;
int result;
@@ -1191,8 +1183,8 @@ ScaleVarProc(
if (flags & TCL_TRACE_UNSETS) {
if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
- Tcl_TraceVar(interp, Tcl_GetString(scalePtr->varNamePtr),
- TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
+ Tcl_TraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr),
+ NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
ScaleVarProc, clientData);
scalePtr->flags |= NEVER_SET;
TkScaleSetValue(scalePtr, scalePtr->value, 1, 0);
@@ -1230,7 +1222,7 @@ ScaleVarProc(
}
TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER);
- return resultStr;
+ return (char *) resultStr;
}
/*