diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | generic/tk.h | 7 | ||||
-rw-r--r-- | generic/tkScale.c | 812 | ||||
-rw-r--r-- | generic/tkScale.h | 61 | ||||
-rw-r--r-- | generic/tkWindow.c | 4 | ||||
-rw-r--r-- | mac/tkMacDefault.h | 5 | ||||
-rw-r--r-- | unix/tkUnixDefault.h | 7 | ||||
-rw-r--r-- | unix/tkUnixScale.c | 42 | ||||
-rw-r--r-- | win/tkWinDefault.h | 5 | ||||
-rw-r--r-- | win/tkWinX.c | 75 |
10 files changed, 576 insertions, 457 deletions
@@ -1,3 +1,18 @@ +1999-02-12 <lfb@scriptics.com> + + * generic/tk.h: + * generic/tkScale.h: + * generic/tkScale.c: + * generic/tkWindow.c: + * unix/tkUnixScale.c: + * unix/tkUnixDefault.h: + * unix/tkWinDefault.h: + * mac/tkMacDefault.h: Objectified scale widget. + + * win/tkWinX.c: Removed Thread-specific data from process + initialization code that was stopping the Tk Dll from + loading. + 1999-02-11 <stanton@GASPODE> * README: diff --git a/generic/tk.h b/generic/tk.h index 0b3f14b..7907c49 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tk.h,v 1.1.4.8 1999/02/12 01:09:02 stanton Exp $ + * RCS: @(#) $Id: tk.h,v 1.1.4.9 1999/02/13 05:09:35 lfb Exp $ */ #ifndef _TK @@ -1765,8 +1765,9 @@ EXTERN int Tk_RadiobuttonObjCmd _ANSI_ARGS_((ClientData clientData, Tcl_Obj *CONST objv[])); EXTERN int Tk_RaiseCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, char **argv)); -EXTERN int Tk_ScaleCmd _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, char **argv)); +EXTERN int Tk_ScaleObjCmd _ANSI_ARGS_((ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[])); EXTERN int Tk_ScrollbarCmd _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, int argc, char **argv)); EXTERN int Tk_SelectionCmd _ANSI_ARGS_((ClientData clientData, diff --git a/generic/tkScale.c b/generic/tkScale.c index 57d1fd3..6588fb8 100644 --- a/generic/tkScale.c +++ b/generic/tkScale.c @@ -17,7 +17,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkScale.c,v 1.1.4.3 1999/01/07 02:42:51 lfb Exp $ + * RCS: @(#) $Id: tkScale.c,v 1.1.4.4 1999/02/13 05:09:35 lfb Exp $ */ #include "tkPort.h" @@ -26,96 +26,131 @@ #include "tclMath.h" #include "tkScale.h" -static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground", - DEF_SCALE_ACTIVE_BG_COLOR, Tk_Offset(TkScale, activeBorder), - TK_CONFIG_COLOR_ONLY}, - {TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Foreground", - DEF_SCALE_ACTIVE_BG_MONO, Tk_Offset(TkScale, activeBorder), - TK_CONFIG_MONO_ONLY}, - {TK_CONFIG_BORDER, "-background", "background", "Background", - DEF_SCALE_BG_COLOR, Tk_Offset(TkScale, bgBorder), - TK_CONFIG_COLOR_ONLY}, - {TK_CONFIG_BORDER, "-background", "background", "Background", - DEF_SCALE_BG_MONO, Tk_Offset(TkScale, bgBorder), - TK_CONFIG_MONO_ONLY}, - {TK_CONFIG_DOUBLE, "-bigincrement", "bigIncrement", "BigIncrement", - DEF_SCALE_BIG_INCREMENT, Tk_Offset(TkScale, bigIncrement), 0}, - {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL, - (char *) NULL, 0, 0}, - {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL, - (char *) NULL, 0, 0}, - {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", - DEF_SCALE_BORDER_WIDTH, Tk_Offset(TkScale, borderWidth), 0}, - {TK_CONFIG_STRING, "-command", "command", "Command", - DEF_SCALE_COMMAND, Tk_Offset(TkScale, command), TK_CONFIG_NULL_OK}, - {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", - DEF_SCALE_CURSOR, Tk_Offset(TkScale, cursor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_INT, "-digits", "digits", "Digits", - DEF_SCALE_DIGITS, Tk_Offset(TkScale, digits), 0}, - {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL, - (char *) NULL, 0, 0}, - {TK_CONFIG_FONT, "-font", "font", "Font", - DEF_SCALE_FONT, Tk_Offset(TkScale, tkfont), - 0}, - {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", - DEF_SCALE_FG_COLOR, Tk_Offset(TkScale, textColorPtr), - TK_CONFIG_COLOR_ONLY}, - {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", - DEF_SCALE_FG_MONO, Tk_Offset(TkScale, textColorPtr), - TK_CONFIG_MONO_ONLY}, - {TK_CONFIG_DOUBLE, "-from", "from", "From", - DEF_SCALE_FROM, Tk_Offset(TkScale, fromValue), 0}, - {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground", - "HighlightBackground", DEF_SCALE_HIGHLIGHT_BG, - Tk_Offset(TkScale, highlightBgColorPtr), 0}, - {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", - DEF_SCALE_HIGHLIGHT, Tk_Offset(TkScale, highlightColorPtr), 0}, - {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness", - "HighlightThickness", - DEF_SCALE_HIGHLIGHT_WIDTH, Tk_Offset(TkScale, highlightWidth), 0}, - {TK_CONFIG_STRING, "-label", "label", "Label", - DEF_SCALE_LABEL, Tk_Offset(TkScale, label), TK_CONFIG_NULL_OK}, - {TK_CONFIG_PIXELS, "-length", "length", "Length", - DEF_SCALE_LENGTH, Tk_Offset(TkScale, length), 0}, - {TK_CONFIG_UID, "-orient", "orient", "Orient", - DEF_SCALE_ORIENT, Tk_Offset(TkScale, orientUid), 0}, - {TK_CONFIG_RELIEF, "-relief", "relief", "Relief", - DEF_SCALE_RELIEF, Tk_Offset(TkScale, relief), 0}, - {TK_CONFIG_INT, "-repeatdelay", "repeatDelay", "RepeatDelay", - DEF_SCALE_REPEAT_DELAY, Tk_Offset(TkScale, repeatDelay), 0}, - {TK_CONFIG_INT, "-repeatinterval", "repeatInterval", "RepeatInterval", - DEF_SCALE_REPEAT_INTERVAL, Tk_Offset(TkScale, repeatInterval), 0}, - {TK_CONFIG_DOUBLE, "-resolution", "resolution", "Resolution", - DEF_SCALE_RESOLUTION, Tk_Offset(TkScale, resolution), 0}, - {TK_CONFIG_BOOLEAN, "-showvalue", "showValue", "ShowValue", - DEF_SCALE_SHOW_VALUE, Tk_Offset(TkScale, showValue), 0}, - {TK_CONFIG_PIXELS, "-sliderlength", "sliderLength", "SliderLength", - DEF_SCALE_SLIDER_LENGTH, Tk_Offset(TkScale, sliderLength), 0}, - {TK_CONFIG_RELIEF, "-sliderrelief", "sliderRelief", "SliderRelief", - DEF_SCALE_SLIDER_RELIEF, Tk_Offset(TkScale, sliderRelief), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_STATE, "-state", "state", "State", - DEF_SCALE_STATE, Tk_Offset(TkScale, state), 0}, - {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", - DEF_SCALE_TAKE_FOCUS, Tk_Offset(TkScale, takeFocus), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_DOUBLE, "-tickinterval", "tickInterval", "TickInterval", - DEF_SCALE_TICK_INTERVAL, Tk_Offset(TkScale, tickInterval), 0}, - {TK_CONFIG_DOUBLE, "-to", "to", "To", - DEF_SCALE_TO, Tk_Offset(TkScale, toValue), 0}, - {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background", - DEF_SCALE_TROUGH_COLOR, Tk_Offset(TkScale, troughColorPtr), - TK_CONFIG_COLOR_ONLY}, - {TK_CONFIG_COLOR, "-troughcolor", "troughColor", "Background", - DEF_SCALE_TROUGH_MONO, Tk_Offset(TkScale, troughColorPtr), - TK_CONFIG_MONO_ONLY}, - {TK_CONFIG_STRING, "-variable", "variable", "Variable", - DEF_SCALE_VARIABLE, Tk_Offset(TkScale, varName), TK_CONFIG_NULL_OK}, - {TK_CONFIG_PIXELS, "-width", "width", "Width", - DEF_SCALE_WIDTH, Tk_Offset(TkScale, width), 0}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} +/* + * The following table defines the legal values for the -orient option. + * It is used together with the "enum orient" declaration in tkScale.h. + */ + +static char *orientStrings[] = { + "horizontal", "vertical", (char *) NULL +}; + +/* + * The following table defines the legal values for the -state option. + * It is used together with the "enum state" declaration in tkScale.h. + */ + +static char *stateStrings[] = { + "active", "disabled", "normal", (char *) NULL +}; + +static Tk_OptionSpec optionSpecs[] = { + {TK_OPTION_BORDER, "-activebackground", "activeBackground", "Foreground", + DEF_BUTTON_ACTIVE_BG_COLOR, -1, Tk_Offset(TkScale, activeBorder), + 0, (ClientData) 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}, + {TK_OPTION_DOUBLE, "-bigincrement", "bigIncrement", "BigIncrement", + DEF_SCALE_BIG_INCREMENT, -1, Tk_Offset(TkScale, bigIncrement), + 0, 0, 0}, + {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL, + (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth", 0}, + {TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL, + (char *) NULL, 0, -1, 0, (ClientData) "-background", 0}, + {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", + DEF_SCALE_BORDER_WIDTH, -1, Tk_Offset(TkScale, borderWidth), + 0, 0, 0}, + {TK_OPTION_STRING, "-command", "command", "Command", + DEF_SCALE_COMMAND, Tk_Offset(TkScale, commandPtr), -1, + TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", + DEF_SCALE_CURSOR, -1, Tk_Offset(TkScale, cursor), + TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_INT, "-digits", "digits", "Digits", + DEF_SCALE_DIGITS, -1, Tk_Offset(TkScale, digits), + 0, 0, 0}, + {TK_OPTION_SYNONYM, "-fg", "foreground", (char *) NULL, + (char *) NULL, 0, -1, 0, (ClientData) "-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", + DEF_BUTTON_FG, -1, Tk_Offset(TkScale, textColorPtr), 0, 0, 0}, + {TK_OPTION_DOUBLE, "-from", "from", "From", DEF_SCALE_FROM, -1, + Tk_Offset(TkScale, fromValue), 0, 0, 0}, + {TK_OPTION_BORDER, "-highlightbackground", "highlightBackground", + "HighlightBackground", DEF_SCALE_HIGHLIGHT_BG_COLOR, + -1, Tk_Offset(TkScale, highlightBorder), + 0, (ClientData) DEF_SCALE_HIGHLIGHT_BG_MONO, 0}, + {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", + DEF_SCALE_HIGHLIGHT, -1, Tk_Offset(TkScale, highlightColorPtr), + 0, 0, 0}, + {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", + "HighlightThickness", DEF_SCALE_HIGHLIGHT_WIDTH, -1, + Tk_Offset(TkScale, highlightWidth), 0, 0, 0}, + {TK_OPTION_STRING, "-label", "label", "Label", + DEF_SCALE_LABEL, Tk_Offset(TkScale, labelPtr), -1, 0, 0, 0}, + {TK_OPTION_PIXELS, "-length", "length", "Length", + 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}, + {TK_OPTION_RELIEF, "-relief", "relief", "Relief", + DEF_SCALE_RELIEF, -1, Tk_Offset(TkScale, relief), 0, 0, 0}, + {TK_OPTION_INT, "-repeatdelay", "repeatDelay", "RepeatDelay", + DEF_SCALE_REPEAT_DELAY, -1, Tk_Offset(TkScale, repeatDelay), + 0, 0, 0}, + {TK_OPTION_INT, "-repeatinterval", "repeatInterval", "RepeatInterval", + DEF_SCALE_REPEAT_INTERVAL, -1, Tk_Offset(TkScale, repeatInterval), + 0, 0, 0}, + {TK_OPTION_DOUBLE, "-resolution", "resolution", "Resolution", + DEF_SCALE_RESOLUTION, -1, Tk_Offset(TkScale, resolution), + 0, 0, 0}, + {TK_OPTION_BOOLEAN, "-showvalue", "showValue", "ShowValue", + DEF_SCALE_SHOW_VALUE, -1, Tk_Offset(TkScale, showValue), + 0, 0, 0}, + {TK_OPTION_PIXELS, "-sliderlength", "sliderLength", "SliderLength", + DEF_SCALE_SLIDER_LENGTH, -1, Tk_Offset(TkScale, sliderLength), + 0, 0, 0}, + {TK_OPTION_RELIEF, "-sliderrelief", "sliderRelief", "SliderRelief", + DEF_SCALE_SLIDER_RELIEF, -1, Tk_Offset(TkScale, sliderRelief), + 0, 0, 0}, + {TK_OPTION_STRING_TABLE, "-state", "state", "State", + DEF_SCALE_STATE, -1, Tk_Offset(TkScale, state), + 0, (ClientData) stateStrings, 0}, + {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", + DEF_SCALE_TAKE_FOCUS, Tk_Offset(TkScale, takeFocusPtr), -1, + TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_DOUBLE, "-tickinterval", "tickInterval", "TickInterval", + DEF_SCALE_TICK_INTERVAL, -1, Tk_Offset(TkScale, tickInterval), + 0, 0, 0}, + {TK_OPTION_DOUBLE, "-to", "to", "To", + 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}, + {TK_OPTION_STRING, "-variable", "variable", "Variable", + DEF_SCALE_VARIABLE, Tk_Offset(TkScale, varNamePtr), -1, + TK_OPTION_NULL_OK, 0, 0}, + {TK_OPTION_PIXELS, "-width", "width", "Width", + DEF_SCALE_WIDTH, -1, Tk_Offset(TkScale, width), 0, 0, 0}, + {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL, + (char *) NULL, 0, -1, 0, 0, 0} +}; + +/* + * The following tables define the scale widget commands and map the + * indexes into the string tables into a single enumerated type used + * to dispatch the scale widget command. + */ + +static char *commandNames[] = { + "cget", "configure", "coords", "get", "identify", "set", (char *) NULL +}; + +enum command { + COMMAND_CGET, COMMAND_CONFIGURE, COMMAND_COORDS, COMMAND_GET, + COMMAND_IDENTIFY, COMMAND_SET }; /* @@ -125,8 +160,8 @@ static Tk_ConfigSpec configSpecs[] = { static void ComputeFormat _ANSI_ARGS_((TkScale *scalePtr)); static void ComputeScaleGeometry _ANSI_ARGS_((TkScale *scalePtr)); static int ConfigureScale _ANSI_ARGS_((Tcl_Interp *interp, - TkScale *scalePtr, int argc, char **argv, - int flags)); + TkScale *scalePtr, int objc, + Tcl_Obj *CONST objv[], int flags)); static void DestroyScale _ANSI_ARGS_((char *memPtr)); static void ScaleCmdDeletedProc _ANSI_ARGS_(( ClientData clientData)); @@ -135,8 +170,9 @@ static void ScaleEventProc _ANSI_ARGS_((ClientData clientData, static char * ScaleVarProc _ANSI_ARGS_((ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags)); -static int ScaleWidgetCmd _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int argc, char **argv)); +static int ScaleWidgetObjCmd _ANSI_ARGS_((ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[])); static void ScaleWorldChanged _ANSI_ARGS_(( ClientData instanceData)); @@ -155,7 +191,7 @@ static TkClassProcs scaleClass = { /* *-------------------------------------------------------------- * - * Tk_ScaleCmd -- + * Tk_ScaleObjCmd -- * * This procedure is invoked to process the "scale" Tcl * command. See the user documentation for details on what @@ -171,28 +207,46 @@ static TkClassProcs scaleClass = { */ int -Tk_ScaleCmd(clientData, interp, argc, argv) - ClientData clientData; /* Main window associated with - * interpreter. */ +Tk_ScaleObjCmd(clientData, interp, objc, objv) + ClientData clientData; /* Either NULL or pointer to option table. */ Tcl_Interp *interp; /* Current interpreter. */ - int argc; /* Number of arguments. */ - char **argv; /* Argument strings. */ + int objc; /* Number of arguments. */ + Tcl_Obj *CONST objv[]; /* Argument values. */ { - Tk_Window tkwin = (Tk_Window) clientData; register TkScale *scalePtr; - Tk_Window new; + Tk_OptionTable optionTable; + Tk_Window tkwin; + + optionTable = (Tk_OptionTable) clientData; + if (optionTable == NULL) { + Tcl_CmdInfo info; + char *name; + + /* + * We haven't created the option table for this widget class + * yet. Do it now and save the table as the clientData for + * the command, so we'll have access to it in future + * invocations of the command. + */ + + optionTable = Tk_CreateOptionTable(interp, optionSpecs); + name = Tcl_GetString(objv[0]); + Tcl_GetCommandInfo(interp, name, &info); + info.objClientData = (ClientData) optionTable; + Tcl_SetCommandInfo(interp, name, &info); + } - if (argc < 2) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " pathName ?options?\"", (char *) NULL); + if (objc < 2) { + Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?"); return TCL_ERROR; } - new = Tk_CreateWindowFromPath(interp, tkwin, argv[1], (char *) NULL); - if (new == NULL) { + tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), + Tcl_GetString(objv[1]), (char *) NULL); + if (tkwin == NULL) { return TCL_ERROR; } - scalePtr = TkpCreateScale(new); + scalePtr = TkpCreateScale(tkwin); /* * Initialize fields that won't be initialized by ConfigureScale, @@ -200,29 +254,30 @@ Tk_ScaleCmd(clientData, interp, argc, argv) * (e.g. resource pointers). */ - scalePtr->tkwin = new; - scalePtr->display = Tk_Display(new); + scalePtr->tkwin = tkwin; + scalePtr->display = Tk_Display(tkwin); scalePtr->interp = interp; - scalePtr->widgetCmd = Tcl_CreateCommand(interp, - Tk_PathName(scalePtr->tkwin), ScaleWidgetCmd, + scalePtr->widgetCmd = Tcl_CreateObjCommand(interp, + Tk_PathName(scalePtr->tkwin), ScaleWidgetObjCmd, (ClientData) scalePtr, ScaleCmdDeletedProc); - scalePtr->orientUid = NULL; - scalePtr->vertical = 0; + scalePtr->optionTable = optionTable; + scalePtr->orient = ORIENT_VERTICAL; scalePtr->width = 0; scalePtr->length = 0; - scalePtr->value = 0; - scalePtr->varName = NULL; - scalePtr->fromValue = 0; - scalePtr->toValue = 0; - scalePtr->tickInterval = 0; + scalePtr->value = 0.0; + scalePtr->varNamePtr = NULL; + scalePtr->fromValue = 0.0; + scalePtr->toValue = 0.0; + scalePtr->tickInterval = 0.0; scalePtr->resolution = 1; + scalePtr->digits = 0; scalePtr->bigIncrement = 0.0; - scalePtr->command = NULL; + scalePtr->commandPtr = NULL; scalePtr->repeatDelay = 0; scalePtr->repeatInterval = 0; - scalePtr->label = NULL; + scalePtr->labelPtr = NULL; scalePtr->labelLength = 0; - scalePtr->state = TK_STATE_NORMAL; + scalePtr->state = STATE_NORMAL; scalePtr->borderWidth = 0; scalePtr->bgBorder = NULL; scalePtr->activeBorder = NULL; @@ -235,7 +290,7 @@ Tk_ScaleCmd(clientData, interp, argc, argv) scalePtr->textGC = None; scalePtr->relief = TK_RELIEF_FLAT; scalePtr->highlightWidth = 0; - scalePtr->highlightBgColorPtr = NULL; + scalePtr->highlightBorder = NULL; scalePtr->highlightColorPtr = NULL; scalePtr->inset = 0; scalePtr->sliderLength = 0; @@ -249,7 +304,7 @@ Tk_ScaleCmd(clientData, interp, argc, argv) scalePtr->vertTroughX = 0; scalePtr->vertLabelX = 0; scalePtr->cursor = None; - scalePtr->takeFocus = NULL; + scalePtr->takeFocusPtr = NULL; scalePtr->flags = NEVER_SET; Tk_SetClass(scalePtr->tkwin, "Scale"); @@ -257,22 +312,25 @@ Tk_ScaleCmd(clientData, interp, argc, argv) Tk_CreateEventHandler(scalePtr->tkwin, ExposureMask|StructureNotifyMask|FocusChangeMask, ScaleEventProc, (ClientData) scalePtr); - if (ConfigureScale(interp, scalePtr, argc-2, argv+2, 0) != TCL_OK) { - goto error; - } - Tcl_SetResult(interp, Tk_PathName(scalePtr->tkwin), TCL_STATIC); + if (Tk_InitOptions(interp, (char *) scalePtr, optionTable, tkwin) + != TCL_OK) { + Tk_DestroyWindow(scalePtr->tkwin); + return TCL_ERROR; + } + if (ConfigureScale(interp, scalePtr, objc - 2, objv + 2, 0) != TCL_OK) { + Tk_DestroyWindow(scalePtr->tkwin); + return TCL_ERROR; + } + Tcl_SetStringObj(Tcl_GetObjResult(interp), Tk_PathName(scalePtr->tkwin), + -1); return TCL_OK; - - error: - Tk_DestroyWindow(scalePtr->tkwin); - return TCL_ERROR; } /* *-------------------------------------------------------------- * - * ScaleWidgetCmd -- + * ScaleWidgetObjCmd -- * * This procedure is invoked to process the Tcl command * that corresponds to a widget managed by this module. @@ -288,141 +346,151 @@ Tk_ScaleCmd(clientData, interp, argc, argv) */ static int -ScaleWidgetCmd(clientData, interp, argc, argv) +ScaleWidgetObjCmd(clientData, interp, objc, objv) ClientData clientData; /* Information about scale * widget. */ Tcl_Interp *interp; /* Current interpreter. */ - int argc; /* Number of arguments. */ - char **argv; /* Argument strings. */ + int objc; /* Number of arguments. */ + Tcl_Obj *CONST objv[]; /* Argument strings. */ { - register TkScale *scalePtr = (TkScale *) clientData; - int result = TCL_OK; - size_t length; - int c; + TkScale *scalePtr = (TkScale *) clientData; + Tcl_Obj *objPtr; + int index; + int result; - if (argc < 2) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " option ?arg arg ...?\"", (char *) NULL); + if (objc < 2) { + Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); return TCL_ERROR; } + result = Tcl_GetIndexFromObj(interp, objv[1], commandNames, + "option", 0, &index); Tcl_Preserve((ClientData) scalePtr); - c = argv[1][0]; - length = strlen(argv[1]); - 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\"", - (char *) NULL); - goto error; - } - result = Tk_ConfigureValue(interp, scalePtr->tkwin, configSpecs, - (char *) scalePtr, argv[2], 0); - } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0) - && (length >= 3)) { - if (argc == 2) { - result = Tk_ConfigureInfo(interp, scalePtr->tkwin, configSpecs, - (char *) scalePtr, (char *) NULL, 0); - } else if (argc == 3) { - result = Tk_ConfigureInfo(interp, scalePtr->tkwin, configSpecs, - (char *) scalePtr, argv[2], 0); - } else { - result = ConfigureScale(interp, scalePtr, argc-2, argv+2, - TK_CONFIG_ARGV_ONLY); - } - } else if ((c == 'c') && (strncmp(argv[1], "coords", length) == 0) - && (length >= 3)) { - int x, y ; - double value; - char buf[TCL_INTEGER_SPACE * 2]; - - if ((argc != 2) && (argc != 3)) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " coords ?value?\"", (char *) NULL); - goto error; - } - if (argc == 3) { - if (Tcl_GetDouble(interp, argv[2], &value) != TCL_OK) { + + switch (index) { + case COMMAND_CGET: { + if (objc !=3) { + Tcl_WrongNumArgs(interp, 1, objv, "cget option"); goto error; } - } else { - value = scalePtr->value; - } - if (scalePtr->vertical) { - x = scalePtr->vertTroughX + scalePtr->width/2 - + scalePtr->borderWidth; - y = TkpValueToPixel(scalePtr, value); - } else { - x = TkpValueToPixel(scalePtr, value); - y = scalePtr->horizTroughY + scalePtr->width/2 - + scalePtr->borderWidth; + objPtr = Tk_GetOptionValue(interp, (char *) scalePtr, + scalePtr->optionTable, objv[2], scalePtr->tkwin); + if (objPtr == NULL) { + goto error; + } else { + Tcl_SetObjResult(interp, objPtr); + } + break; } - sprintf(buf, "%d %d", x, y); - Tcl_SetResult(interp, buf, TCL_VOLATILE); - } else if ((c == 'g') && (strncmp(argv[1], "get", length) == 0)) { - double value; - int x, y; - char buf[TCL_DOUBLE_SPACE]; - - if ((argc != 2) && (argc != 4)) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " get ?x y?\"", (char *) NULL); - goto error; + case COMMAND_CONFIGURE: { + if (objc <= 3) { + objPtr = Tk_GetOptionInfo(interp, (char *) scalePtr, + scalePtr->optionTable, + (objc == 3) ? objv[2] : (Tcl_Obj *) NULL, + scalePtr->tkwin); + if (objPtr == NULL) { + goto error; + } else { + Tcl_SetObjResult(interp, objPtr); + } + } else { + result = ConfigureScale(interp, scalePtr, objc-2, objv+2, + TK_CONFIG_ARGV_ONLY); + } + break; } - if (argc == 2) { - value = scalePtr->value; - } else { - if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) - || (Tcl_GetInt(interp, argv[3], &y) != TCL_OK)) { + case COMMAND_COORDS: { + int x, y ; + double value; + char buf[TCL_INTEGER_SPACE * 2]; + + if ((objc != 2) && (objc != 3)) { + Tcl_WrongNumArgs(interp, 1, objv, "coords ?value?"); goto error; } - value = TkpPixelToValue(scalePtr, x, y); - } - sprintf(buf, scalePtr->format, value); - Tcl_SetResult(interp, buf, TCL_VOLATILE); - } else if ((c == 'i') && (strncmp(argv[1], "identify", length) == 0)) { - int x, y, thing; - - if (argc != 4) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " identify x y\"", (char *) NULL); - goto error; - } - if ((Tcl_GetInt(interp, argv[2], &x) != TCL_OK) - || (Tcl_GetInt(interp, argv[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; - } - } else if ((c == 's') && (strncmp(argv[1], "set", length) == 0)) { - double value; + if (objc == 3) { + if (Tcl_GetDoubleFromObj(interp, objv[2], &value) + != TCL_OK) { + goto error; + } + } else { + value = scalePtr->value; + } + if (scalePtr->orient == ORIENT_VERTICAL) { + x = scalePtr->vertTroughX + scalePtr->width/2 + + scalePtr->borderWidth; + y = TkpValueToPixel(scalePtr, value); + } else { + x = TkpValueToPixel(scalePtr, value); + y = scalePtr->horizTroughY + scalePtr->width/2 + + scalePtr->borderWidth; + } + sprintf(buf, "%d %d", x, y); + Tcl_SetResult(interp, buf, TCL_VOLATILE); + 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?"); + goto error; + } + if (objc == 2) { + value = scalePtr->value; + } else { + if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK) + || (Tcl_GetIntFromObj(interp, objv[3], &y) + != TCL_OK)) { + goto error; + } + value = TkpPixelToValue(scalePtr, x, y); + } + sprintf(buf, scalePtr->format, value); + Tcl_SetResult(interp, buf, TCL_VOLATILE); + break; + } + case COMMAND_IDENTIFY: { + int x, y, thing; + + if (objc != 4) { + Tcl_WrongNumArgs(interp, 1, objv, "identify x y"); + goto error; + } + if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK) + || (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; + } + break; + } + case COMMAND_SET: { + double value; - if (argc != 3) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " set value\"", (char *) NULL); - goto error; - } - if (Tcl_GetDouble(interp, argv[2], &value) != TCL_OK) { - goto error; - } - if (scalePtr->state != TK_STATE_DISABLED) { - TkpSetScaleValue(scalePtr, value, 1, 1); - } - } else { - Tcl_AppendResult(interp, "bad option \"", argv[1], - "\": must be cget, configure, coords, get, identify, or set", - (char *) NULL); - goto error; + if (objc != 3) { + Tcl_WrongNumArgs(interp, 1, objv, "set value"); + goto error; + } + if (Tcl_GetDoubleFromObj(interp, objv[2], &value) != TCL_OK) { + goto error; + } + if ((scalePtr->state != STATE_DISABLED)) { + TkpSetScaleValue(scalePtr, value, 1, 1); + } + break; + } } Tcl_Release((ClientData) scalePtr); return result; @@ -462,8 +530,8 @@ DestroyScale(memPtr) * stuff. */ - if (scalePtr->varName != NULL) { - Tcl_UntraceVar(scalePtr->interp, scalePtr->varName, + if (scalePtr->varNamePtr != NULL) { + Tcl_UntraceVar(scalePtr->interp, Tcl_GetString(scalePtr->varNamePtr), TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, ScaleVarProc, (ClientData) scalePtr); } @@ -476,7 +544,8 @@ DestroyScale(memPtr) if (scalePtr->textGC != None) { Tk_FreeGC(scalePtr->display, scalePtr->textGC); } - Tk_FreeOptions(configSpecs, (char *) scalePtr, scalePtr->display, 0); + Tk_FreeConfigOptions((char *) scalePtr, scalePtr->optionTable, + scalePtr->tkwin); TkpDestroyScale(scalePtr); } @@ -502,118 +571,136 @@ DestroyScale(memPtr) */ static int -ConfigureScale(interp, scalePtr, argc, argv, flags) +ConfigureScale(interp, scalePtr, objc, objv, flags) Tcl_Interp *interp; /* Used for error reporting. */ register TkScale *scalePtr; /* Information about widget; may or may * not already have values for some fields. */ - int argc; /* Number of valid entries in argv. */ - char **argv; /* Arguments. */ + int objc; /* Number of valid entries in objv. */ + Tcl_Obj *CONST objv[]; /* Argument values. */ int flags; /* Flags to pass to Tk_ConfigureWidget. */ { - size_t length; + Tk_SavedOptions savedOptions; + Tcl_Obj *errorResult; + int error; + char *label; /* * Eliminate any existing trace on a variable monitored by the scale. */ - if (scalePtr->varName != NULL) { - Tcl_UntraceVar(interp, scalePtr->varName, + if (scalePtr->varNamePtr != NULL) { + Tcl_UntraceVar(interp, Tcl_GetString(scalePtr->varNamePtr), TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, ScaleVarProc, (ClientData) scalePtr); } - if (Tk_ConfigureWidget(interp, scalePtr->tkwin, configSpecs, - argc, argv, (char *) scalePtr, flags) != TCL_OK) { - return TCL_ERROR; - } + for (error = 0; error <= 1; error++) { + if (!error) { + /* + * First pass: set options to new values. + */ - /* - * If the scale is tied to the value of a variable, then set up - * a trace on the variable's value and set the scale's value from - * the value of the variable, if it exists. - */ + if (Tk_SetOptions(interp, (char *) scalePtr, + scalePtr->optionTable, objc, objv, + scalePtr->tkwin, &savedOptions, (int *) NULL) != TCL_OK) { + continue; + } + } else { + /* + * Second pass: restore options to old values. + */ - if (scalePtr->varName != NULL) { - char *stringValue, *end; - double value; + errorResult = Tcl_GetObjResult(interp); + Tcl_IncrRefCount(errorResult); + Tk_RestoreSavedOptions(&savedOptions); + } - stringValue = Tcl_GetVar(interp, scalePtr->varName, TCL_GLOBAL_ONLY); - if (stringValue != NULL) { - value = strtod(stringValue, &end); - if ((end != stringValue) && (*end == 0)) { - scalePtr->value = TkRoundToResolution(scalePtr, value); + /* + * If the scale is tied to the value of a variable, then set + * the scale's value from the value of the variable, if it exists. + */ + + if (scalePtr->varNamePtr != NULL) { + char *name; + double value; + Tcl_Obj *valuePtr; + + name = Tcl_GetString(scalePtr->varNamePtr); + valuePtr = Tcl_GetVar2Ex(interp, name, NULL, TCL_GLOBAL_ONLY); + if (valuePtr != NULL) { + Tcl_GetDoubleFromObj(interp, valuePtr, &value); } + scalePtr->value = TkRoundToResolution(scalePtr, value); } - Tcl_TraceVar(interp, scalePtr->varName, - TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, - ScaleVarProc, (ClientData) scalePtr); - } - /* - * Several options need special processing, such as parsing the - * orientation and creating GCs. - */ + /* + * Several options need special processing, such as parsing the + * orientation and creating GCs. + */ - length = strlen(scalePtr->orientUid); - if (strncmp(scalePtr->orientUid, "vertical", length) == 0) { - scalePtr->vertical = 1; - } else if (strncmp(scalePtr->orientUid, "horizontal", length) == 0) { - scalePtr->vertical = 0; - } else { - Tcl_AppendResult(interp, "bad orientation \"", scalePtr->orientUid, - "\": must be vertical or horizontal", (char *) NULL); - return TCL_ERROR; - } + scalePtr->fromValue = TkRoundToResolution(scalePtr, + scalePtr->fromValue); + scalePtr->toValue = TkRoundToResolution(scalePtr, scalePtr->toValue); + scalePtr->tickInterval = TkRoundToResolution(scalePtr, + scalePtr->tickInterval); + + /* + * Make sure that the tick interval has the right sign so that + * addition moves from fromValue to toValue. + */ - scalePtr->fromValue = TkRoundToResolution(scalePtr, scalePtr->fromValue); - scalePtr->toValue = TkRoundToResolution(scalePtr, scalePtr->toValue); - scalePtr->tickInterval = TkRoundToResolution(scalePtr, - scalePtr->tickInterval); + if ((scalePtr->tickInterval < 0) + ^ ((scalePtr->toValue - scalePtr->fromValue) < 0)) { + scalePtr->tickInterval = -scalePtr->tickInterval; + } - /* - * Make sure that the tick interval has the right sign so that - * addition moves from fromValue to toValue. - */ + /* + * Set the scale value to itself; all this does is to make sure + * that the scale's value is within the new acceptable range for + * the scale and reflect the value in the associated variable, + * if any. + */ - if ((scalePtr->tickInterval < 0) - ^ ((scalePtr->toValue - scalePtr->fromValue) < 0)) { - scalePtr->tickInterval = -scalePtr->tickInterval; - } + ComputeFormat(scalePtr); + TkpSetScaleValue(scalePtr, scalePtr->value, 1, 1); - /* - * Set the scale value to itself; all this does is to make sure - * that the scale's value is within the new acceptable range for - * the scale and reflect the value in the associated variable, - * if any. - */ + if (scalePtr->labelPtr != NULL) { + label = Tcl_GetString(scalePtr->labelPtr); + scalePtr->labelLength = strlen(label); + } else { + scalePtr->labelLength = 0; + } - ComputeFormat(scalePtr); - TkpSetScaleValue(scalePtr, scalePtr->value, 1, 1); + Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder); - if (scalePtr->label != NULL) { - scalePtr->labelLength = strlen(scalePtr->label); - } else { - scalePtr->labelLength = 0; + if (scalePtr->highlightWidth < 0) { + scalePtr->highlightWidth = 0; + } + scalePtr->inset = scalePtr->highlightWidth + scalePtr->borderWidth; + break; } - - if ((scalePtr->state != TK_STATE_NORMAL) - && (scalePtr->state != TK_STATE_DISABLED) - && (scalePtr->state != TK_STATE_ACTIVE)) { - Tcl_AppendResult(interp, "bad state value \"", scalePtr->state, - "\": must be normal, active, or disabled", (char *) NULL); - scalePtr->state = TK_STATE_NORMAL; - return TCL_ERROR; + if (!error) { + Tk_FreeSavedOptions(&savedOptions); } - Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder); + /* + * Reestablish the variable trace, if it is needed. + */ - if (scalePtr->highlightWidth < 0) { - scalePtr->highlightWidth = 0; + if (scalePtr->varNamePtr != NULL) { + Tcl_TraceVar(interp, Tcl_GetString(scalePtr->varNamePtr), + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + ScaleVarProc, (ClientData) scalePtr); } - scalePtr->inset = scalePtr->highlightWidth + scalePtr->borderWidth; ScaleWorldChanged((ClientData) scalePtr); - return TCL_OK; + if (error) { + Tcl_SetObjResult(interp, errorResult); + Tcl_DecrRefCount(errorResult); + return TCL_ERROR; + } else { + return TCL_OK; + } } /* @@ -811,6 +898,7 @@ ComputeScaleGeometry(scalePtr) char valueString[PRINT_CHARS]; int tmp, valuePixels, x, y, extraSpace; Tk_FontMetrics fm; + char *label; /* * Horizontal scales are simpler than vertical ones because @@ -819,7 +907,7 @@ ComputeScaleGeometry(scalePtr) */ Tk_GetFontMetrics(scalePtr->tkfont, &fm); - if (!scalePtr->vertical) { + if (!scalePtr->orient == ORIENT_VERTICAL) { y = scalePtr->inset; extraSpace = 0; if (scalePtr->labelLength != 0) { @@ -891,8 +979,9 @@ ComputeScaleGeometry(scalePtr) scalePtr->vertLabelX = 0; } else { scalePtr->vertLabelX = x + fm.ascent/2; + label = Tcl_GetString(scalePtr->labelPtr); x = scalePtr->vertLabelX + fm.ascent/2 - + Tk_TextWidth(scalePtr->tkfont, scalePtr->label, + + Tk_TextWidth(scalePtr->tkfont, label, scalePtr->labelLength); } Tk_GeometryRequest(scalePtr->tkwin, x + scalePtr->inset, @@ -1099,8 +1188,12 @@ ScaleVarProc(clientData, interp, name1, name2, flags) int flags; /* Information about what happened. */ { register TkScale *scalePtr = (TkScale *) clientData; - char *stringValue, *end, *result; + char *resultStr, *name; double value; + Tcl_Obj *valuePtr; + int result; + + name = Tcl_GetString(scalePtr->varNamePtr); /* * If the variable is unset, then immediately recreate it unless @@ -1109,7 +1202,7 @@ ScaleVarProc(clientData, interp, name1, name2, flags) if (flags & TCL_TRACE_UNSETS) { if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { - Tcl_TraceVar(interp, scalePtr->varName, + Tcl_TraceVar(interp, name, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, ScaleVarProc, clientData); scalePtr->flags |= NEVER_SET; @@ -1127,27 +1220,26 @@ ScaleVarProc(clientData, interp, name1, name2, flags) if (scalePtr->flags & SETTING_VAR) { return (char *) NULL; } - result = NULL; - stringValue = Tcl_GetVar(interp, scalePtr->varName, TCL_GLOBAL_ONLY); - if (stringValue != NULL) { - value = strtod(stringValue, &end); - if ((end == stringValue) || (*end != 0)) { - result = "can't assign non-numeric value to scale variable"; - } else { - scalePtr->value = TkRoundToResolution(scalePtr, value); - } - - /* - * This code is a bit tricky because it sets the scale's value before - * calling TkpSetScaleValue. This way, TkpSetScaleValue won't bother - * to set the variable again or to invoke the -command. However, it - * also won't redisplay the scale, so we have to ask for that - * explicitly. - */ - - TkpSetScaleValue(scalePtr, scalePtr->value, 1, 0); - TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER); + resultStr = NULL; + valuePtr = Tcl_GetVar2Ex(interp, name, NULL, + TCL_GLOBAL_ONLY); + result = Tcl_GetDoubleFromObj(interp, valuePtr, &value); + if (result != TCL_OK) { + resultStr = "can't assign non-numeric value to scale variable"; + } else { + scalePtr->value = TkRoundToResolution(scalePtr, value); + + /* + * This code is a bit tricky because it sets the scale's value before + * calling TkpSetScaleValue. This way, TkpSetScaleValue won't bother + * to set the variable again or to invoke the -command. However, it + * also won't redisplay the scale, so we have to ask for that + * explicitly. + */ + + TkpSetScaleValue(scalePtr, scalePtr->value, 1, 0); + TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER); } - return result; + return resultStr; } diff --git a/generic/tkScale.h b/generic/tkScale.h index 8144b4d..cba3d40 100644 --- a/generic/tkScale.h +++ b/generic/tkScale.h @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkScale.h,v 1.1.4.2 1999/01/07 02:42:51 lfb Exp $ + * RCS: @(#) $Id: tkScale.h,v 1.1.4.3 1999/02/13 05:09:35 lfb Exp $ */ #ifndef _TKSCALE @@ -25,6 +25,22 @@ #endif /* + * Legal values for the "orient" field of TkScale records. + */ + +enum orient { + ORIENT_HORIZONTAL, ORIENT_VERTICAL +}; + +/* + * Legal values for the "state" field of TkScale records. + */ + +enum state { + STATE_ACTIVE, STATE_DISABLED, STATE_NORMAL +}; + +/* * A data structure of the following type is kept for each scale * widget managed by this file: */ @@ -39,16 +55,16 @@ typedef struct TkScale { * freed even after tkwin has gone away. */ Tcl_Interp *interp; /* Interpreter associated with scale. */ Tcl_Command widgetCmd; /* Token for scale's widget command. */ - Tk_Uid orientUid; /* Orientation for window ("vertical" or - * "horizontal"). */ - int vertical; /* Non-zero means vertical orientation, - * zero means horizontal. */ + Tk_OptionTable optionTable; /* Table that defines configuration options + * available for this widget. */ + enum orient orient; /* Orientation for window (vertical or + * horizontal). */ int width; /* Desired narrow dimension of scale, * in pixels. */ int length; /* Desired long dimension of scale, * in pixels. */ - double value; /* Current value of scale. */ - char *varName; /* Name of variable (malloc'ed) or NULL. + double value; /* Current value of scale. */ + Tcl_Obj *varNamePtr; /* Name of variable or NULL. * If non-NULL, scale's value tracks * the contents of this variable and * vice versa. */ @@ -68,20 +84,19 @@ typedef struct TkScale { * digits and other information. */ double bigIncrement; /* Amount to use for large increments to * scale value. (0 means we pick a value). */ - char *command; /* Command prefix to use when invoking Tcl + Tcl_Obj *commandPtr; /* Command prefix to use when invoking Tcl * commands because the scale value changed. - * NULL means don't invoke commands. - * Malloc'ed. */ + * NULL means don't invoke commands. */ int repeatDelay; /* How long to wait before auto-repeating * on scrolling actions (in ms). */ int repeatInterval; /* Interval between autorepeats (in ms). */ - char *label; /* Label to display above or to right of + Tcl_Obj *labelPtr; /* Label to display above or to right of * scale; NULL means don't display a - * label. Malloc'ed. */ + * label. */ int labelLength; /* Number of non-NULL chars. in label. */ - int state; /* TK_STATE_ACTIVE, TK_STATE_NORMAL - * or TK_STATE_DISABLED. Value of scale - * cannot be changed when disabled. */ + enum state state; /* Values are active, normal, or disabled. + * Value of scale cannot be changed when + * disabled. */ /* * Information used when displaying widget: @@ -91,7 +106,8 @@ typedef struct TkScale { Tk_3DBorder bgBorder; /* Used for drawing slider and other * background areas. */ Tk_3DBorder activeBorder; /* For drawing the slider when active. */ - int sliderRelief; /* Is slider to be drawn raised, sunken, etc. */ + int sliderRelief; /* Is slider to be drawn raised, sunken, + * etc. */ XColor *troughColorPtr; /* Color for drawing trough. */ GC troughGC; /* For drawing trough. */ GC copyGC; /* Used for copying from pixmap onto screen. */ @@ -103,9 +119,10 @@ typedef struct TkScale { int highlightWidth; /* Width in pixels of highlight to draw * around widget when it has the focus. * <= 0 means don't draw a highlight. */ - XColor *highlightBgColorPtr; - /* Color for drawing traversal highlight - * area when highlight is off. */ + Tk_3DBorder highlightBorder;/* Value of -highlightbackground option: + * specifies background with which to draw 3-D + * default ring and focus highlight area when + * highlight is off. */ XColor *highlightColorPtr; /* Color for drawing traversal highlight. */ int inset; /* Total width of all borders, including * traversal highlight and 3-D border. @@ -142,9 +159,9 @@ typedef struct TkScale { */ Tk_Cursor cursor; /* Current cursor for window, or None. */ - char *takeFocus; /* Value of -takefocus option; not used in + Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in * the C code, but used by keyboard traversal - * scripts. Malloc'ed, but may be NULL. */ + * scripts. May be NULL. */ int flags; /* Various flags; see below for * definitions. */ } TkScale; @@ -208,7 +225,7 @@ typedef struct TkScale { #define PRINT_CHARS 150 /* - * Declaration of procedures used in the implementation of the scrollbar + * Declaration of procedures used in the implementation of the scale * widget. */ diff --git a/generic/tkWindow.c b/generic/tkWindow.c index 4f9578c..f571819 100644 --- a/generic/tkWindow.c +++ b/generic/tkWindow.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWindow.c,v 1.1.4.5 1999/01/07 02:42:53 lfb Exp $ + * RCS: @(#) $Id: tkWindow.c,v 1.1.4.6 1999/02/13 05:09:35 lfb Exp $ */ #include "tkPort.h" @@ -138,7 +138,7 @@ static TkCmd commands[] = { {"menubutton", Tk_MenubuttonCmd, NULL, 1, 1}, {"message", Tk_MessageCmd, NULL, 1, 1}, {"radiobutton", NULL, Tk_RadiobuttonObjCmd, 1, 0}, - {"scale", Tk_ScaleCmd, NULL, 1, 1}, + {"scale", NULL, Tk_ScaleObjCmd, 1, 0}, {"scrollbar", Tk_ScrollbarCmd, NULL, 1, 1}, {"text", Tk_TextCmd, NULL, 1, 1}, {"toplevel", Tk_ToplevelCmd, NULL, 0, 1}, diff --git a/mac/tkMacDefault.h b/mac/tkMacDefault.h index 29fc14c..d26014f 100644 --- a/mac/tkMacDefault.h +++ b/mac/tkMacDefault.h @@ -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: tkMacDefault.h,v 1.1.4.2 1998/09/30 02:18:05 stanton Exp $ + * RCS: @(#) $Id: tkMacDefault.h,v 1.1.4.3 1999/02/13 05:09:36 lfb Exp $ */ #ifndef _TKMACDEFAULT @@ -349,7 +349,8 @@ #define DEF_SCALE_FG_COLOR BLACK #define DEF_SCALE_FG_MONO BLACK #define DEF_SCALE_FROM "0" -#define DEF_SCALE_HIGHLIGHT_BG NORMAL_BG +#define DEF_SCALE_HIGHLIGHT_BG_COLOR DEF_SCALE_BG_COLOR +#define DEF_SCALE_HIGHLIGHT_BG_MONO DEF_SCALE_BG_MONO #define DEF_SCALE_HIGHLIGHT BLACK #define DEF_SCALE_HIGHLIGHT_WIDTH "0" #define DEF_SCALE_LABEL "" diff --git a/unix/tkUnixDefault.h b/unix/tkUnixDefault.h index c3dae54..89e757a 100644 --- a/unix/tkUnixDefault.h +++ b/unix/tkUnixDefault.h @@ -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: tkUnixDefault.h,v 1.1.4.2 1998/09/30 02:19:15 stanton Exp $ + * RCS: @(#) $Id: tkUnixDefault.h,v 1.1.4.3 1999/02/13 05:09:36 lfb Exp $ */ #ifndef _TKUNIXDEFAULT @@ -342,14 +342,15 @@ #define DEF_SCALE_FG_COLOR BLACK #define DEF_SCALE_FG_MONO BLACK #define DEF_SCALE_FROM "0" -#define DEF_SCALE_HIGHLIGHT_BG NORMAL_BG +#define DEF_SCALE_HIGHLIGHT_BG_COLOR DEF_SCALE_BG_COLOR +#define DEF_SCALE_HIGHLIGHT_BG_MONO DEF_SCALE_BG_MONO #define DEF_SCALE_HIGHLIGHT BLACK #define DEF_SCALE_HIGHLIGHT_WIDTH "1" #define DEF_SCALE_LABEL "" #define DEF_SCALE_LENGTH "100" #define DEF_SCALE_ORIENT "vertical" #define DEF_SCALE_RELIEF "flat" -#define DEF_SCALE_REPEAT_DELAY "300" +#define DEF_SCALE_REPEAT_DELAY "300" #define DEF_SCALE_REPEAT_INTERVAL "100" #define DEF_SCALE_RESOLUTION "1" #define DEF_SCALE_TROUGH_COLOR TROUGH diff --git a/unix/tkUnixScale.c b/unix/tkUnixScale.c index 431cf9c..8f517fb 100644 --- a/unix/tkUnixScale.c +++ b/unix/tkUnixScale.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkUnixScale.c,v 1.1.4.2 1999/01/07 02:42:57 lfb Exp $ + * RCS: @(#) $Id: tkUnixScale.c,v 1.1.4.3 1999/02/13 05:09:37 lfb Exp $ */ #include "tkScale.h" @@ -177,7 +177,7 @@ DisplayVerticalScale(scalePtr, drawable, drawnAreaPtr) (unsigned) scalePtr->width, (unsigned) (Tk_Height(tkwin) - 2*scalePtr->inset - 2*scalePtr->borderWidth)); - if (scalePtr->state == TK_STATE_ACTIVE) { + if (scalePtr->state == STATE_ACTIVE) { sliderBorder = scalePtr->activeBorder; } else { sliderBorder = scalePtr->bgBorder; @@ -210,8 +210,9 @@ DisplayVerticalScale(scalePtr, drawable, drawnAreaPtr) Tk_GetFontMetrics(scalePtr->tkfont, &fm); Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC, - scalePtr->tkfont, scalePtr->label, scalePtr->labelLength, - scalePtr->vertLabelX, scalePtr->inset + (3*fm.ascent)/2); + scalePtr->tkfont, Tcl_GetString(scalePtr->labelPtr), + scalePtr->labelLength, scalePtr->vertLabelX, + scalePtr->inset + (3*fm.ascent)/2); } } @@ -376,7 +377,7 @@ DisplayHorizontalScale(scalePtr, drawable, drawnAreaPtr) (unsigned) (Tk_Width(tkwin) - 2*scalePtr->inset - 2*scalePtr->borderWidth), (unsigned) scalePtr->width); - if (scalePtr->state == TK_STATE_ACTIVE) { + if (scalePtr->state == STATE_ACTIVE) { sliderBorder = scalePtr->activeBorder; } else { sliderBorder = scalePtr->bgBorder; @@ -409,8 +410,9 @@ DisplayHorizontalScale(scalePtr, drawable, drawnAreaPtr) Tk_GetFontMetrics(scalePtr->tkfont, &fm); Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC, - scalePtr->tkfont, scalePtr->label, scalePtr->labelLength, - scalePtr->inset + fm.ascent/2, scalePtr->horizLabelY + fm.ascent); + scalePtr->tkfont, Tcl_GetString(scalePtr->labelPtr), + scalePtr->labelLength, scalePtr->inset + fm.ascent/2, + scalePtr->horizLabelY + fm.ascent); } } @@ -512,10 +514,12 @@ TkpDisplayScale(clientData) Tcl_Preserve((ClientData) scalePtr); Tcl_Preserve((ClientData) interp); - if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { + if ((scalePtr->flags & INVOKE_COMMAND) + && (scalePtr->commandPtr != NULL)) { sprintf(string, scalePtr->format, scalePtr->value); - result = Tcl_VarEval(interp, scalePtr->command, " ", string, - (char *) NULL); + + result = Tcl_VarEval(interp, Tcl_GetString(scalePtr->commandPtr), + " ", string, (char *) NULL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (command executed by scale)"); Tcl_BackgroundError(interp); @@ -549,7 +553,7 @@ TkpDisplayScale(clientData) * different. */ - if (scalePtr->vertical) { + if (scalePtr->orient == ORIENT_VERTICAL) { DisplayVerticalScale(scalePtr, pixmap, &drawnArea); } else { DisplayHorizontalScale(scalePtr, pixmap, &drawnArea); @@ -575,7 +579,8 @@ TkpDisplayScale(clientData) if (scalePtr->flags & GOT_FOCUS) { gc = Tk_GCForColor(scalePtr->highlightColorPtr, pixmap); } else { - gc = Tk_GCForColor(scalePtr->highlightBgColorPtr, pixmap); + gc = Tk_GCForColor( + Tk_3DBorderColor(scalePtr->highlightBorder), pixmap); } Tk_DrawFocusHighlight(tkwin, gc, scalePtr->highlightWidth, pixmap); } @@ -621,7 +626,7 @@ TkpScaleElement(scalePtr, x, y) { int sliderFirst; - if (scalePtr->vertical) { + if (scalePtr->orient == ORIENT_VERTICAL) { if ((x < scalePtr->vertTroughX) || (x >= (scalePtr->vertTroughX + 2*scalePtr->borderWidth + scalePtr->width))) { @@ -712,11 +717,11 @@ TkpSetScaleValue(scalePtr, value, setVar, invokeCommand) } TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER); - if (setVar && (scalePtr->varName != NULL)) { + if (setVar && (scalePtr->varNamePtr != NULL)) { sprintf(string, scalePtr->format, scalePtr->value); scalePtr->flags |= SETTING_VAR; - Tcl_SetVar(scalePtr->interp, scalePtr->varName, string, - TCL_GLOBAL_ONLY); + Tcl_SetVar(scalePtr->interp, Tcl_GetString(scalePtr->varNamePtr), + string, TCL_GLOBAL_ONLY); scalePtr->flags &= ~SETTING_VAR; } } @@ -748,7 +753,7 @@ TkpPixelToValue(scalePtr, x, y) { double value, pixelRange; - if (scalePtr->vertical) { + if (scalePtr->orient == ORIENT_VERTICAL) { pixelRange = Tk_Height(scalePtr->tkwin) - scalePtr->sliderLength - 2*scalePtr->inset - 2*scalePtr->borderWidth; value = y; @@ -809,7 +814,8 @@ TkpValueToPixel(scalePtr, value) double valueRange; valueRange = scalePtr->toValue - scalePtr->fromValue; - pixelRange = (scalePtr->vertical ? Tk_Height(scalePtr->tkwin) + pixelRange = (scalePtr->orient == ORIENT_VERTICAL + ? Tk_Height(scalePtr->tkwin) : Tk_Width(scalePtr->tkwin)) - scalePtr->sliderLength - 2*scalePtr->inset - 2*scalePtr->borderWidth; if (valueRange == 0) { diff --git a/win/tkWinDefault.h b/win/tkWinDefault.h index 9a6264b..d395aec 100644 --- a/win/tkWinDefault.h +++ b/win/tkWinDefault.h @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinDefault.h,v 1.1.4.2 1998/09/30 02:19:30 stanton Exp $ + * RCS: @(#) $Id: tkWinDefault.h,v 1.1.4.3 1999/02/13 05:09:37 lfb Exp $ */ #ifndef _TKWINDEFAULT @@ -348,7 +348,8 @@ #define DEF_SCALE_FG_COLOR NORMAL_FG #define DEF_SCALE_FG_MONO BLACK #define DEF_SCALE_FROM "0" -#define DEF_SCALE_HIGHLIGHT_BG NORMAL_BG +#define DEF_SCALE_HIGHLIGHT_BG_COLOR DEF_SCALE_BG_COLOR +#define DEF_SCALE_HIGHLIGHT_BG_MONO DEF_SCALE_BG_MONO #define DEF_SCALE_HIGHLIGHT HIGHLIGHT #define DEF_SCALE_HIGHLIGHT_WIDTH "2" #define DEF_SCALE_LABEL "" diff --git a/win/tkWinX.c b/win/tkWinX.c index 67aede0..120d7aa 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -10,18 +10,15 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinX.c,v 1.1.4.6 1998/12/13 08:16:21 lfb Exp $ + * RCS: @(#) $Id: tkWinX.c,v 1.1.4.7 1999/02/13 05:09:37 lfb Exp $ */ #include "tkWinInt.h" -typedef struct ThreadSpecificData { - TkDisplay *winDisplay; /* Display that represents Windows screen. */ - HINSTANCE tkInstance; /* Application instance handle. */ - int childClassInitialized; /* Registered child class? */ - WNDCLASS childClass; /* Window class for child windows. */ -} ThreadSpecificData; -static Tcl_ThreadDataKey dataKey; +static TkDisplay *winDisplay; /* Display that represents Windows screen. */ +static HINSTANCE tkInstance; /* Application instance handle. */ +static int childClassInitialized; /* Registered child class? */ +static WNDCLASS childClass; /* Window class for child windows. */ /* * The zmouse.h file includes the definition for WM_MOUSEWHEEL. @@ -111,10 +108,7 @@ TkGetServerInfo(interp, tkwin) HINSTANCE Tk_GetHINSTANCE() { - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - - return tsdPtr->tkInstance; + return tkInstance; } /* @@ -138,37 +132,35 @@ TkWinXInit(hInstance) HINSTANCE hInstance; { OSVERSIONINFO info; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&info); tkpIsWin32s = (info.dwPlatformId == VER_PLATFORM_WIN32s); - if (tsdPtr->childClassInitialized != 0) { + if (childClassInitialized != 0) { return; } - tsdPtr->childClassInitialized = 1; + childClassInitialized = 1; - tsdPtr->tkInstance = hInstance; + tkInstance = hInstance; - tsdPtr->childClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC; - tsdPtr->childClass.cbClsExtra = 0; - tsdPtr->childClass.cbWndExtra = 0; - tsdPtr->childClass.hInstance = hInstance; - tsdPtr->childClass.hbrBackground = NULL; - tsdPtr->childClass.lpszMenuName = NULL; + childClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC; + childClass.cbClsExtra = 0; + childClass.cbWndExtra = 0; + childClass.hInstance = hInstance; + childClass.hbrBackground = NULL; + childClass.lpszMenuName = NULL; /* * Register the Child window class. */ - tsdPtr->childClass.lpszClassName = TK_WIN_CHILD_CLASS_NAME; - tsdPtr->childClass.lpfnWndProc = TkWinChildProc; - tsdPtr->childClass.hIcon = NULL; - tsdPtr->childClass.hCursor = NULL; + childClass.lpszClassName = TK_WIN_CHILD_CLASS_NAME; + childClass.lpfnWndProc = TkWinChildProc; + childClass.hIcon = NULL; + childClass.hCursor = NULL; - if (!RegisterClass(&tsdPtr->childClass)) { + if (!RegisterClass(&childClass)) { panic("Unable to register TkChild class"); } } @@ -193,15 +185,12 @@ void TkWinXCleanup(hInstance) HINSTANCE hInstance; { - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - /* * Clean up our own class. */ - if (tsdPtr->childClassInitialized) { - tsdPtr->childClassInitialized = 0; + if (childClassInitialized) { + childClassInitialized = 0; UnregisterClass(TK_WIN_CHILD_CLASS_NAME, hInstance); } @@ -265,13 +254,11 @@ TkpOpenDisplay(display_name) HDC dc; TkWinDrawable *twdPtr; Display *display; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - if (tsdPtr->winDisplay != NULL) { - if (strcmp(tsdPtr->winDisplay->display->display_name, display_name) + if (winDisplay != NULL) { + if (strcmp(winDisplay->display->display_name, display_name) == 0) { - return tsdPtr->winDisplay; + return winDisplay; } else { return NULL; } @@ -373,9 +360,9 @@ TkpOpenDisplay(display_name) display->default_screen = 0; screen->cmap = XCreateColormap(display, None, screen->root_visual, AllocNone); - tsdPtr->winDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay)); - tsdPtr->winDisplay->display = display; - return tsdPtr->winDisplay; + winDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay)); + winDisplay->display = display; + return winDisplay; } /* @@ -401,10 +388,8 @@ TkpCloseDisplay(dispPtr) { Display *display = dispPtr->display; HWND hwnd; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - if (dispPtr != tsdPtr->winDisplay) { + if (dispPtr != winDisplay) { panic("TkpCloseDisplay: tried to call TkpCloseDisplay on another display"); return; } @@ -423,7 +408,7 @@ TkpCloseDisplay(dispPtr) } } - tsdPtr->winDisplay = NULL; + winDisplay = NULL; if (display->display_name != (char *) NULL) { ckfree(display->display_name); |