summaryrefslogtreecommitdiffstats
path: root/generic/tkScrollbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkScrollbar.c')
-rw-r--r--generic/tkScrollbar.c134
1 files changed, 66 insertions, 68 deletions
diff --git a/generic/tkScrollbar.c b/generic/tkScrollbar.c
index f19671c..49ddca0 100644
--- a/generic/tkScrollbar.c
+++ b/generic/tkScrollbar.c
@@ -20,75 +20,76 @@
* Custom option for handling "-orient"
*/
-static Tk_CustomOption orientOption = {
- (Tk_OptionParseProc *) TkOrientParseProc,
- TkOrientPrintProc,
- (ClientData) NULL
+static const Tk_CustomOption orientOption = {
+ TkOrientParseProc, TkOrientPrintProc, NULL
};
+/* non-const space for "-width" default value for scrollbars */
+char tkDefScrollbarWidth[TCL_INTEGER_SPACE] = DEF_SCROLLBAR_WIDTH;
+
/*
* Information used for argv parsing.
*/
-Tk_ConfigSpec tkpScrollbarConfigSpecs[] = {
+static const Tk_ConfigSpec configSpecs[] = {
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",
DEF_SCROLLBAR_ACTIVE_BG_COLOR, Tk_Offset(TkScrollbar, activeBorder),
- TK_CONFIG_COLOR_ONLY},
+ TK_CONFIG_COLOR_ONLY, NULL},
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground",
DEF_SCROLLBAR_ACTIVE_BG_MONO, Tk_Offset(TkScrollbar, activeBorder),
- TK_CONFIG_MONO_ONLY},
+ TK_CONFIG_MONO_ONLY, NULL},
{TK_CONFIG_RELIEF, "-activerelief", "activeRelief", "Relief",
- DEF_SCROLLBAR_ACTIVE_RELIEF, Tk_Offset(TkScrollbar, activeRelief), 0},
+ DEF_SCROLLBAR_ACTIVE_RELIEF, Tk_Offset(TkScrollbar, activeRelief), 0, NULL},
{TK_CONFIG_BORDER, "-background", "background", "Background",
DEF_SCROLLBAR_BG_COLOR, Tk_Offset(TkScrollbar, bgBorder),
- TK_CONFIG_COLOR_ONLY},
+ TK_CONFIG_COLOR_ONLY, NULL},
{TK_CONFIG_BORDER, "-background", "background", "Background",
DEF_SCROLLBAR_BG_MONO, Tk_Offset(TkScrollbar, bgBorder),
- TK_CONFIG_MONO_ONLY},
- {TK_CONFIG_SYNONYM, "-bd", "borderWidth", NULL, NULL, 0, 0},
- {TK_CONFIG_SYNONYM, "-bg", "background", NULL, NULL, 0, 0},
+ TK_CONFIG_MONO_ONLY, NULL},
+ {TK_CONFIG_SYNONYM, "-bd", "borderWidth", NULL, NULL, 0, 0, NULL},
+ {TK_CONFIG_SYNONYM, "-bg", "background", NULL, NULL, 0, 0, NULL},
{TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
- DEF_SCROLLBAR_BORDER_WIDTH, Tk_Offset(TkScrollbar, borderWidth), 0},
+ DEF_SCROLLBAR_BORDER_WIDTH, Tk_Offset(TkScrollbar, borderWidth), 0, NULL},
{TK_CONFIG_STRING, "-command", "command", "Command",
DEF_SCROLLBAR_COMMAND, Tk_Offset(TkScrollbar, command),
- TK_CONFIG_NULL_OK},
+ TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
- DEF_SCROLLBAR_CURSOR, Tk_Offset(TkScrollbar, cursor), TK_CONFIG_NULL_OK},
+ DEF_SCROLLBAR_CURSOR, Tk_Offset(TkScrollbar, cursor), TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_PIXELS, "-elementborderwidth", "elementBorderWidth",
"BorderWidth", DEF_SCROLLBAR_EL_BORDER_WIDTH,
- Tk_Offset(TkScrollbar, elementBorderWidth), 0},
+ Tk_Offset(TkScrollbar, elementBorderWidth), 0, NULL},
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
"HighlightBackground", DEF_SCROLLBAR_HIGHLIGHT_BG,
- Tk_Offset(TkScrollbar, highlightBgColorPtr), 0},
+ Tk_Offset(TkScrollbar, highlightBgColorPtr), 0, NULL},
{TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
DEF_SCROLLBAR_HIGHLIGHT,
- Tk_Offset(TkScrollbar, highlightColorPtr), 0},
+ Tk_Offset(TkScrollbar, highlightColorPtr), 0, NULL},
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness",
- DEF_SCROLLBAR_HIGHLIGHT_WIDTH, Tk_Offset(TkScrollbar, highlightWidth), 0},
+ DEF_SCROLLBAR_HIGHLIGHT_WIDTH, Tk_Offset(TkScrollbar, highlightWidth), 0, NULL},
{TK_CONFIG_BOOLEAN, "-jump", "jump", "Jump",
- DEF_SCROLLBAR_JUMP, Tk_Offset(TkScrollbar, jump), 0},
+ DEF_SCROLLBAR_JUMP, Tk_Offset(TkScrollbar, jump), 0, NULL},
{TK_CONFIG_CUSTOM, "-orient", "orient", "Orient",
DEF_SCROLLBAR_ORIENT, Tk_Offset(TkScrollbar, vertical), 0,
&orientOption},
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
- DEF_SCROLLBAR_RELIEF, Tk_Offset(TkScrollbar, relief), 0},
+ DEF_SCROLLBAR_RELIEF, Tk_Offset(TkScrollbar, relief), 0, NULL},
{TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay",
- DEF_SCROLLBAR_REPEAT_DELAY, Tk_Offset(TkScrollbar, repeatDelay), 0},
+ DEF_SCROLLBAR_REPEAT_DELAY, Tk_Offset(TkScrollbar, repeatDelay), 0, NULL},
{TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval",
- DEF_SCROLLBAR_REPEAT_INTERVAL, Tk_Offset(TkScrollbar, repeatInterval), 0},
+ DEF_SCROLLBAR_REPEAT_INTERVAL, Tk_Offset(TkScrollbar, repeatInterval), 0, NULL},
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_SCROLLBAR_TAKE_FOCUS, Tk_Offset(TkScrollbar, takeFocus),
- TK_CONFIG_NULL_OK},
+ TK_CONFIG_NULL_OK, NULL},
{TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
DEF_SCROLLBAR_TROUGH_COLOR, Tk_Offset(TkScrollbar, troughColorPtr),
- TK_CONFIG_COLOR_ONLY},
+ TK_CONFIG_COLOR_ONLY, NULL},
{TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background",
DEF_SCROLLBAR_TROUGH_MONO, Tk_Offset(TkScrollbar, troughColorPtr),
- TK_CONFIG_MONO_ONLY},
+ TK_CONFIG_MONO_ONLY, NULL},
{TK_CONFIG_PIXELS, "-width", "width", "Width",
- DEF_SCROLLBAR_WIDTH, Tk_Offset(TkScrollbar, width), 0},
- {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
+ tkDefScrollbarWidth, Tk_Offset(TkScrollbar, width), 0, NULL},
+ {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL}
};
/*
@@ -97,10 +98,10 @@ Tk_ConfigSpec tkpScrollbarConfigSpecs[] = {
static int ConfigureScrollbar(Tcl_Interp *interp,
TkScrollbar *scrollPtr, int argc,
- CONST char **argv, int flags);
+ const char **argv, int flags);
static void ScrollbarCmdDeletedProc(ClientData clientData);
static int ScrollbarWidgetCmd(ClientData clientData,
- Tcl_Interp *, int argc, CONST char **argv);
+ Tcl_Interp *, int argc, const char **argv);
/*
*--------------------------------------------------------------
@@ -124,15 +125,15 @@ Tk_ScrollbarCmd(
ClientData clientData, /* Main window associated with interpreter. */
Tcl_Interp *interp, /* Current interpreter. */
int argc, /* Number of arguments. */
- CONST char **argv) /* Argument strings. */
+ const char **argv) /* Argument strings. */
{
- Tk_Window tkwin = (Tk_Window) clientData;
+ Tk_Window tkwin = clientData;
register TkScrollbar *scrollPtr;
Tk_Window newWin;
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " pathName ?options?\"", NULL);
+ argv[0], " pathName ?-option value ...?\"", NULL);
return TCL_ERROR;
}
@@ -144,7 +145,7 @@ Tk_ScrollbarCmd(
Tk_SetClass(newWin, "Scrollbar");
scrollPtr = TkpCreateScrollbar(newWin);
- Tk_SetClassProcs(newWin, &tkpScrollbarProcs, (ClientData) scrollPtr);
+ Tk_SetClassProcs(newWin, &tkpScrollbarProcs, scrollPtr);
/*
* Initialize fields that won't be initialized by ConfigureScrollbar, or
@@ -157,7 +158,7 @@ Tk_ScrollbarCmd(
scrollPtr->interp = interp;
scrollPtr->widgetCmd = Tcl_CreateCommand(interp,
Tk_PathName(scrollPtr->tkwin), ScrollbarWidgetCmd,
- (ClientData) scrollPtr, ScrollbarCmdDeletedProc);
+ scrollPtr, ScrollbarCmdDeletedProc);
scrollPtr->vertical = 0;
scrollPtr->width = 0;
scrollPtr->command = NULL;
@@ -194,7 +195,7 @@ Tk_ScrollbarCmd(
return TCL_ERROR;
}
- Tcl_SetResult(interp, Tk_PathName(scrollPtr->tkwin), TCL_STATIC);
+ Tcl_SetObjResult(interp, TkNewWindowObj(scrollPtr->tkwin));
return TCL_OK;
}
@@ -221,19 +222,19 @@ ScrollbarWidgetCmd(
ClientData clientData, /* Information about scrollbar widget. */
Tcl_Interp *interp, /* Current interpreter. */
int argc, /* Number of arguments. */
- CONST char **argv) /* Argument strings. */
+ const char **argv) /* Argument strings. */
{
- register TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
+ register TkScrollbar *scrollPtr = clientData;
int result = TCL_OK;
size_t length;
int c;
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " option ?arg arg ...?\"", NULL);
+ argv[0], " option ?arg ...?\"", NULL);
return TCL_ERROR;
}
- Tcl_Preserve((ClientData) scrollPtr);
+ Tcl_Preserve(scrollPtr);
c = argv[1][0];
length = strlen(argv[1]);
if ((c == 'a') && (strncmp(argv[1], "activate", length) == 0)) {
@@ -281,15 +282,15 @@ ScrollbarWidgetCmd(
goto error;
}
result = Tk_ConfigureValue(interp, scrollPtr->tkwin,
- tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);
+ configSpecs, (char *) scrollPtr, argv[2], 0);
} else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
&& (length >= 2)) {
if (argc == 2) {
result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
- tkpScrollbarConfigSpecs, (char *) scrollPtr, NULL, 0);
+ configSpecs, (char *) scrollPtr, NULL, 0);
} else if (argc == 3) {
result = Tk_ConfigureInfo(interp, scrollPtr->tkwin,
- tkpScrollbarConfigSpecs, (char *) scrollPtr, argv[2], 0);
+ configSpecs, (char *) scrollPtr, argv[2], 0);
} else {
result = ConfigureScrollbar(interp, scrollPtr, argc-2, argv+2,
TK_CONFIG_ARGV_ONLY);
@@ -297,7 +298,6 @@ ScrollbarWidgetCmd(
} else if ((c == 'd') && (strncmp(argv[1], "delta", length) == 0)) {
int xDelta, yDelta, pixels, length;
double fraction;
- char buf[TCL_DOUBLE_SPACE];
if (argc != 4) {
Tcl_AppendResult(interp, "wrong # args: should be \"",
@@ -322,12 +322,10 @@ ScrollbarWidgetCmd(
} else {
fraction = ((double) pixels / (double) length);
}
- Tcl_PrintDouble(NULL, fraction, buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fraction));
} else if ((c == 'f') && (strncmp(argv[1], "fraction", length) == 0)) {
int x, y, pos, length;
double fraction;
- char buf[TCL_DOUBLE_SPACE];
if (argc != 4) {
Tcl_AppendResult(interp, "wrong # args: should be \"",
@@ -357,8 +355,7 @@ ScrollbarWidgetCmd(
} else if (fraction > 1.0) {
fraction = 1.0;
}
- Tcl_PrintDouble(NULL, fraction, buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fraction));
} else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) {
if (argc != 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"",
@@ -366,18 +363,19 @@ ScrollbarWidgetCmd(
goto error;
}
if (scrollPtr->flags & NEW_STYLE_COMMANDS) {
- char first[TCL_DOUBLE_SPACE], last[TCL_DOUBLE_SPACE];
+ Tcl_Obj *resObjs[2];
- Tcl_PrintDouble(interp, scrollPtr->firstFraction, first);
- Tcl_PrintDouble(interp, scrollPtr->lastFraction, last);
- Tcl_AppendResult(interp, first, " ", last, NULL);
+ resObjs[0] = Tcl_NewDoubleObj(scrollPtr->firstFraction);
+ resObjs[1] = Tcl_NewDoubleObj(scrollPtr->lastFraction);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(2, resObjs));
} else {
- char buf[TCL_INTEGER_SPACE * 4];
+ Tcl_Obj *resObjs[4];
- sprintf(buf, "%d %d %d %d", scrollPtr->totalUnits,
- scrollPtr->windowUnits, scrollPtr->firstUnit,
- scrollPtr->lastUnit);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ resObjs[0] = Tcl_NewIntObj(scrollPtr->totalUnits);
+ resObjs[1] = Tcl_NewIntObj(scrollPtr->windowUnits);
+ resObjs[2] = Tcl_NewIntObj(scrollPtr->firstUnit);
+ resObjs[3] = Tcl_NewIntObj(scrollPtr->lastUnit);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(4, resObjs));
}
} else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) {
int x, y, thing;
@@ -491,11 +489,11 @@ ScrollbarWidgetCmd(
}
done:
- Tcl_Release((ClientData) scrollPtr);
+ Tcl_Release(scrollPtr);
return result;
error:
- Tcl_Release((ClientData) scrollPtr);
+ Tcl_Release(scrollPtr);
return TCL_ERROR;
}
@@ -526,10 +524,10 @@ ConfigureScrollbar(
/* Information about widget; may or may not
* already have values for some fields. */
int argc, /* Number of valid entries in argv. */
- CONST char **argv, /* Arguments. */
+ const char **argv, /* Arguments. */
int flags) /* Flags to pass to Tk_ConfigureWidget. */
{
- if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, tkpScrollbarConfigSpecs,
+ if (Tk_ConfigureWidget(interp, scrollPtr->tkwin, configSpecs,
argc, argv, (char *) scrollPtr, flags) != TCL_OK) {
return TCL_ERROR;
}
@@ -585,7 +583,7 @@ TkScrollbarEventProc(
ClientData clientData, /* Information about window. */
XEvent *eventPtr) /* Information about event. */
{
- TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
+ TkScrollbar *scrollPtr = clientData;
if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
TkScrollbarEventuallyRedraw(scrollPtr);
@@ -597,16 +595,16 @@ TkScrollbarEventProc(
scrollPtr->widgetCmd);
}
if (scrollPtr->flags & REDRAW_PENDING) {
- Tcl_CancelIdleCall(TkpDisplayScrollbar, (ClientData) scrollPtr);
+ Tcl_CancelIdleCall(TkpDisplayScrollbar, scrollPtr);
}
/*
* Free up all the stuff that requires special handling, then let
* Tk_FreeOptions handle all the standard option-related stuff.
*/
- Tk_FreeOptions(tkpScrollbarConfigSpecs, (char *) scrollPtr,
+ Tk_FreeOptions(configSpecs, (char *) scrollPtr,
scrollPtr->display, 0);
- Tcl_EventuallyFree((ClientData) scrollPtr, TCL_DYNAMIC);
+ Tcl_EventuallyFree(scrollPtr, TCL_DYNAMIC);
} else if (eventPtr->type == ConfigureNotify) {
TkpComputeScrollbarGeometry(scrollPtr);
TkScrollbarEventuallyRedraw(scrollPtr);
@@ -649,7 +647,7 @@ static void
ScrollbarCmdDeletedProc(
ClientData clientData) /* Pointer to widget record for widget. */
{
- TkScrollbar *scrollPtr = (TkScrollbar *) clientData;
+ TkScrollbar *scrollPtr = clientData;
Tk_Window tkwin = scrollPtr->tkwin;
/*
@@ -689,7 +687,7 @@ TkScrollbarEventuallyRedraw(
return;
}
if ((scrollPtr->flags & REDRAW_PENDING) == 0) {
- Tcl_DoWhenIdle(TkpDisplayScrollbar, (ClientData) scrollPtr);
+ Tcl_DoWhenIdle(TkpDisplayScrollbar, scrollPtr);
scrollPtr->flags |= REDRAW_PENDING;
}
}