summaryrefslogtreecommitdiffstats
path: root/generic/tkScrollbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkScrollbar.c')
-rw-r--r--generic/tkScrollbar.c120
1 files changed, 62 insertions, 58 deletions
diff --git a/generic/tkScrollbar.c b/generic/tkScrollbar.c
index 49ddca0..fb06093 100644
--- a/generic/tkScrollbar.c
+++ b/generic/tkScrollbar.c
@@ -12,6 +12,10 @@
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+/*
+ * TODO: Convert scrollbars to the Tcl_Obj API.
+ */
+
#include "tkInt.h"
#include "tkScrollbar.h"
#include "default.h"
@@ -132,8 +136,10 @@ Tk_ScrollbarCmd(
Tk_Window newWin;
if (argc < 2) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " pathName ?-option value ...?\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s pathName ?-option value ...?\"",
+ argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
return TCL_ERROR;
}
@@ -230,8 +236,9 @@ ScrollbarWidgetCmd(
int c;
if (argc < 2) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " option ?arg ...?\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s option ?arg ...?\"", argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
return TCL_ERROR;
}
Tcl_Preserve(scrollPtr);
@@ -239,23 +246,23 @@ ScrollbarWidgetCmd(
length = strlen(argv[1]);
if ((c == 'a') && (strncmp(argv[1], "activate", length) == 0)) {
int oldActiveField;
+
if (argc == 2) {
+ const char *zone = "";
+
switch (scrollPtr->activeField) {
- case TOP_ARROW:
- Tcl_SetResult(interp, "arrow1", TCL_STATIC);
- break;
- case SLIDER:
- Tcl_SetResult(interp, "slider", TCL_STATIC);
- break;
- case BOTTOM_ARROW:
- Tcl_SetResult(interp, "arrow2", TCL_STATIC);
- break;
+ case TOP_ARROW: zone = "arrow1"; break;
+ case SLIDER: zone = "slider"; break;
+ case BOTTOM_ARROW: zone = "arrow2"; break;
}
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, -1));
goto done;
}
if (argc != 3) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " activate element\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s activate element\"",
+ argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
c = argv[2][0];
@@ -276,9 +283,9 @@ ScrollbarWidgetCmd(
} else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
&& (length >= 2)) {
if (argc != 3) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " cget option\"",
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s cget option\"", argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
result = Tk_ConfigureValue(interp, scrollPtr->tkwin,
@@ -300,8 +307,10 @@ ScrollbarWidgetCmd(
double fraction;
if (argc != 4) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " delta xDelta yDelta\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s delta xDelta yDelta\"",
+ argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
if ((Tcl_GetInt(interp, argv[2], &xDelta) != TCL_OK)
@@ -328,8 +337,9 @@ ScrollbarWidgetCmd(
double fraction;
if (argc != 4) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " fraction x y\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s fraction x y\"", argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)
@@ -357,20 +367,19 @@ ScrollbarWidgetCmd(
}
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fraction));
} else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) {
+ Tcl_Obj *resObjs[4];
+
if (argc != 2) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " get\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s get\"", argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
if (scrollPtr->flags & NEW_STYLE_COMMANDS) {
- Tcl_Obj *resObjs[2];
-
resObjs[0] = Tcl_NewDoubleObj(scrollPtr->firstFraction);
resObjs[1] = Tcl_NewDoubleObj(scrollPtr->lastFraction);
Tcl_SetObjResult(interp, Tcl_NewListObj(2, resObjs));
} else {
- Tcl_Obj *resObjs[4];
-
resObjs[0] = Tcl_NewIntObj(scrollPtr->totalUnits);
resObjs[1] = Tcl_NewIntObj(scrollPtr->windowUnits);
resObjs[2] = Tcl_NewIntObj(scrollPtr->firstUnit);
@@ -378,35 +387,27 @@ ScrollbarWidgetCmd(
Tcl_SetObjResult(interp, Tcl_NewListObj(4, resObjs));
}
} else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) {
- int x, y, thing;
+ int x, y;
+ const char *zone = "";
if (argc != 4) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " identify x y\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be \"%s identify x y\"", argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK)
|| (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) {
goto error;
}
- thing = TkpScrollbarPosition(scrollPtr, x,y);
- switch (thing) {
- case TOP_ARROW:
- Tcl_SetResult(interp, "arrow1", TCL_STATIC);
- break;
- case TOP_GAP:
- Tcl_SetResult(interp, "trough1", TCL_STATIC);
- break;
- case SLIDER:
- Tcl_SetResult(interp, "slider", TCL_STATIC);
- break;
- case BOTTOM_GAP:
- Tcl_SetResult(interp, "trough2", TCL_STATIC);
- break;
- case BOTTOM_ARROW:
- Tcl_SetResult(interp, "arrow2", TCL_STATIC);
- break;
+ switch (TkpScrollbarPosition(scrollPtr, x, y)) {
+ case TOP_ARROW: zone = "arrow1"; break;
+ case TOP_GAP: zone = "trough1"; break;
+ case SLIDER: zone = "slider"; break;
+ case BOTTOM_GAP: zone = "trough2"; break;
+ case BOTTOM_ARROW: zone = "arrow2"; break;
}
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(zone, -1));
} else if ((c == 's') && (strncmp(argv[1], "set", length) == 0)) {
int totalUnits, windowUnits, firstUnit, lastUnit;
@@ -473,18 +474,22 @@ ScrollbarWidgetCmd(
}
scrollPtr->flags &= ~NEW_STYLE_COMMANDS;
} else {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " set firstFraction lastFraction\" or \"",
- argv[0],
- " set totalUnits windowUnits firstUnit lastUnit\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # args: should be "
+ "\"%s set firstFraction lastFraction\" or "
+ "\"%s set totalUnits windowUnits firstUnit lastUnit\"",
+ argv[0], argv[0]));
+ Tcl_SetErrorCode(interp, "TCL", "WRONGARGS", NULL);
goto error;
}
TkpComputeScrollbarGeometry(scrollPtr);
TkScrollbarEventuallyRedraw(scrollPtr);
} else {
- Tcl_AppendResult(interp, "bad option \"", argv[1],
- "\": must be activate, cget, configure, delta, fraction, ",
- "get, identify, or set", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad option \"%s\": must be activate, cget, configure,"
+ " delta, fraction, get, identify, or set", argv[1]));
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option",
+ argv[1], NULL);
goto error;
}
@@ -538,7 +543,7 @@ ConfigureScrollbar(
*/
if (scrollPtr->command != NULL) {
- scrollPtr->commandSize = (int)strlen(scrollPtr->command);
+ scrollPtr->commandSize = (int) strlen(scrollPtr->command);
} else {
scrollPtr->commandSize = 0;
}
@@ -602,8 +607,7 @@ TkScrollbarEventProc(
* Tk_FreeOptions handle all the standard option-related stuff.
*/
- Tk_FreeOptions(configSpecs, (char *) scrollPtr,
- scrollPtr->display, 0);
+ Tk_FreeOptions(configSpecs, (char*) scrollPtr, scrollPtr->display, 0);
Tcl_EventuallyFree(scrollPtr, TCL_DYNAMIC);
} else if (eventPtr->type == ConfigureNotify) {
TkpComputeScrollbarGeometry(scrollPtr);