summaryrefslogtreecommitdiffstats
path: root/generic/tkSquare.c
diff options
context:
space:
mode:
authorstanton <stanton>1999-04-16 01:51:06 (GMT)
committerstanton <stanton>1999-04-16 01:51:06 (GMT)
commit03656f44f81469f459031fa3a4a7b09c8bc77712 (patch)
tree31378e81bd58f8c726fc552d6b30cbf3ca07497b /generic/tkSquare.c
parent404fc236f34304df53b7e44bc7971d786b87d453 (diff)
downloadtk-03656f44f81469f459031fa3a4a7b09c8bc77712.zip
tk-03656f44f81469f459031fa3a4a7b09c8bc77712.tar.gz
tk-03656f44f81469f459031fa3a4a7b09c8bc77712.tar.bz2
* Merged 8.1 branch into the main trunk
Diffstat (limited to 'generic/tkSquare.c')
-rw-r--r--generic/tkSquare.c390
1 files changed, 220 insertions, 170 deletions
diff --git a/generic/tkSquare.c b/generic/tkSquare.c
index e7cc047..a835e31 100644
--- a/generic/tkSquare.c
+++ b/generic/tkSquare.c
@@ -1,23 +1,24 @@
/*
* tkSquare.c --
*
- * This module implements "square" widgets. A "square" is
- * a widget that displays a single square that can be moved
- * around and resized. This file is intended as an example
+ * This module implements "square" widgets that are object
+ * based. A "square" is a widget that displays a single square that can
+ * be moved around and resized. This file is intended as an example
* of how to build a widget; it isn't included in the
* normal wish, but it is included in "tktest".
*
- * Copyright (c) 1991-1994 The Regents of the University of California.
- * Copyright (c) 1994-1997 Sun Microsystems, Inc.
+ * Copyright (c) 1997 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkSquare.c,v 1.2 1998/09/14 18:23:17 stanton Exp $
+ * RCS: @(#) $Id: tkSquare.c,v 1.3 1999/04/16 01:51:22 stanton Exp $
*/
#include "tkPort.h"
+#define __NO_OLD_CONFIG
#include "tk.h"
+#include "tkInt.h"
/*
* A data structure of the following type is kept for each square
@@ -31,22 +32,24 @@ typedef struct {
Display *display; /* X's token for the window's display. */
Tcl_Interp *interp; /* Interpreter associated with widget. */
Tcl_Command widgetCmd; /* Token for square's widget command. */
- int x, y; /* Position of square's upper-left corner
+ Tk_OptionTable optionTable; /* Token representing the configuration
+ * specifications. */
+ Tcl_Obj *xPtr, *yPtr; /* Position of square's upper-left corner
* within widget. */
- int size; /* Width and height of square. */
+ int x, y;
+ Tcl_Obj *sizeObjPtr; /* Width and height of square. */
/*
* Information used when displaying widget:
*/
- int borderWidth; /* Width of 3-D border around whole widget. */
- Tk_3DBorder bgBorder; /* Used for drawing background. */
- Tk_3DBorder fgBorder; /* For drawing square. */
- int relief; /* Indicates whether window as a whole is
- * raised, sunken, or flat. */
+ Tcl_Obj *borderWidthPtr; /* Width of 3-D border around whole widget. */
+ Tcl_Obj *bgBorderPtr;
+ Tcl_Obj *fgBorderPtr;
+ Tcl_Obj *reliefPtr;
GC gc; /* Graphics context for copying from
* off-screen pixmap onto screen. */
- int doubleBuffer; /* Non-zero means double-buffer redisplay
+ Tcl_Obj *doubleBufferPtr; /* Non-zero means double-buffer redisplay
* with pixmap; zero means draw straight
* onto the display. */
int updatePending; /* Non-zero means a call to SquareDisplay
@@ -57,49 +60,52 @@ typedef struct {
* Information used for argv parsing.
*/
-static Tk_ConfigSpec configSpecs[] = {
- {TK_CONFIG_BORDER, "-background", "background", "Background",
- "#d9d9d9", Tk_Offset(Square, bgBorder), TK_CONFIG_COLOR_ONLY},
- {TK_CONFIG_BORDER, "-background", "background", "Background",
- "white", Tk_Offset(Square, bgBorder), TK_CONFIG_MONO_ONLY},
- {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",
- "2", Tk_Offset(Square, borderWidth), 0},
- {TK_CONFIG_INT, "-dbl", "doubleBuffer", "DoubleBuffer",
- "1", Tk_Offset(Square, doubleBuffer), 0},
- {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
- (char *) NULL, 0, 0},
- {TK_CONFIG_BORDER, "-foreground", "foreground", "Foreground",
- "#b03060", Tk_Offset(Square, fgBorder), TK_CONFIG_COLOR_ONLY},
- {TK_CONFIG_BORDER, "-foreground", "foreground", "Foreground",
- "black", Tk_Offset(Square, fgBorder), TK_CONFIG_MONO_ONLY},
- {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
- "raised", Tk_Offset(Square, relief), 0},
- {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
- (char *) NULL, 0, 0}
+static Tk_OptionSpec configSpecs[] = {
+ {TK_OPTION_BORDER, "-background", "background", "Background",
+ "#d9d9d9", Tk_Offset(Square, bgBorderPtr), -1, 0,
+ (ClientData) "white"},
+ {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
+ (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth"},
+ {TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL,
+ (char *) NULL, 0, -1, 0, (ClientData) "-background"},
+ {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
+ "2", Tk_Offset(Square, borderWidthPtr), -1},
+ {TK_OPTION_BOOLEAN, "-dbl", "doubleBuffer", "DoubleBuffer",
+ "1", Tk_Offset(Square, doubleBufferPtr), -1},
+ {TK_OPTION_SYNONYM, "-fg", (char *) NULL, (char *) NULL,
+ (char *) NULL, 0, -1, 0, (ClientData) "-foreground"},
+ {TK_OPTION_BORDER, "-foreground", "foreground", "Foreground",
+ "#b03060", Tk_Offset(Square, fgBorderPtr), -1, 0,
+ (ClientData) "black"},
+ {TK_OPTION_PIXELS, "-posx", "posx", "PosX", "0",
+ Tk_Offset(Square, xPtr), -1},
+ {TK_OPTION_PIXELS, "-posy", "posy", "PosY", "0",
+ Tk_Offset(Square, yPtr), -1},
+ {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
+ "raised", Tk_Offset(Square, reliefPtr), -1},
+ {TK_OPTION_PIXELS, "-size", "size", "Size", "20",
+ Tk_Offset(Square, sizeObjPtr), -1},
+ {TK_OPTION_END}
};
/*
* Forward declarations for procedures defined later in this file:
*/
-int SquareCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int argc, char **argv));
-static void SquareCmdDeletedProc _ANSI_ARGS_((
+int SquareObjCmd _ANSI_ARGS_((ClientData clientData,
+ Tcl_Interp *interp, int objc,
+ Tcl_Obj * CONST objv[]));
+static void SquareDeletedProc _ANSI_ARGS_((
ClientData clientData));
static int SquareConfigure _ANSI_ARGS_((Tcl_Interp *interp,
- Square *squarePtr, int argc, char **argv,
- int flags));
+ Square *squarePtr));
static void SquareDestroy _ANSI_ARGS_((char *memPtr));
static void SquareDisplay _ANSI_ARGS_((ClientData clientData));
static void KeepInWindow _ANSI_ARGS_((Square *squarePtr));
-static void SquareEventProc _ANSI_ARGS_((ClientData clientData,
+static void SquareObjEventProc _ANSI_ARGS_((ClientData clientData,
XEvent *eventPtr));
static int SquareWidgetCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *, int argc, char **argv));
+ Tcl_Interp *, int objc, Tcl_Obj * CONST objv[]));
/*
*--------------------------------------------------------------
@@ -119,24 +125,41 @@ static int SquareWidgetCmd _ANSI_ARGS_((ClientData clientData,
*/
int
-SquareCmd(clientData, interp, argc, argv)
+SquareObjCmd(clientData, interp, objc, objv)
ClientData clientData; /* Main window associated with
* interpreter. */
Tcl_Interp *interp; /* Current interpreter. */
- int argc; /* Number of arguments. */
- char **argv; /* Argument strings. */
+ int objc; /* Number of arguments. */
+ Tcl_Obj * CONST objv[]; /* Argument objects. */
{
- Tk_Window main = (Tk_Window) clientData;
Square *squarePtr;
Tk_Window tkwin;
+ Tk_OptionTable optionTable = (Tk_OptionTable) clientData;
+ Tcl_CmdInfo info;
+ char *commandName;
+
+ if (optionTable == NULL) {
+ /*
+ * The first time this procedure is invoked, optionTable will
+ * be NULL. We then create the option table from the template
+ * and store the table pointer as the command's clinical so
+ * we'll have easy access to it in the future.
+ */
+
+ optionTable = Tk_CreateOptionTable(interp, configSpecs);
+ commandName = Tcl_GetStringFromObj(objv[0], (int *) NULL);
+ Tcl_GetCommandInfo(interp, commandName, &info);
+ info.clientData = (ClientData) optionTable;
+ Tcl_SetCommandInfo(interp, commandName, &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;
}
- tkwin = Tk_CreateWindowFromPath(interp, main, argv[1], (char *) NULL);
+ tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
+ Tcl_GetStringFromObj(objv[1], NULL), (char *) NULL);
if (tkwin == NULL) {
return TCL_ERROR;
}
@@ -150,29 +173,47 @@ SquareCmd(clientData, interp, argc, argv)
squarePtr->tkwin = tkwin;
squarePtr->display = Tk_Display(tkwin);
squarePtr->interp = interp;
- squarePtr->widgetCmd = Tcl_CreateCommand(interp,
+ squarePtr->widgetCmd = Tcl_CreateObjCommand(interp,
Tk_PathName(squarePtr->tkwin), SquareWidgetCmd,
- (ClientData) squarePtr, SquareCmdDeletedProc);
+ (ClientData) squarePtr, SquareDeletedProc);
+ squarePtr->xPtr = NULL;
+ squarePtr->yPtr = NULL;
squarePtr->x = 0;
squarePtr->y = 0;
- squarePtr->size = 20;
- squarePtr->borderWidth = 0;
- squarePtr->bgBorder = NULL;
- squarePtr->fgBorder = NULL;
- squarePtr->relief = TK_RELIEF_FLAT;
+ squarePtr->sizeObjPtr = NULL;
+ squarePtr->borderWidthPtr = NULL;
+ squarePtr->bgBorderPtr = NULL;
+ squarePtr->fgBorderPtr = NULL;
+ squarePtr->reliefPtr = NULL;
squarePtr->gc = None;
- squarePtr->doubleBuffer = 1;
+ squarePtr->doubleBufferPtr = NULL;
squarePtr->updatePending = 0;
+ squarePtr->optionTable = optionTable;
- Tk_CreateEventHandler(squarePtr->tkwin, ExposureMask|StructureNotifyMask,
- SquareEventProc, (ClientData) squarePtr);
- if (SquareConfigure(interp, squarePtr, argc-2, argv+2, 0) != TCL_OK) {
+ if (Tk_InitOptions(interp, (char *) squarePtr, optionTable, tkwin)
+ != TCL_OK) {
Tk_DestroyWindow(squarePtr->tkwin);
+ ckfree((char *) squarePtr);
return TCL_ERROR;
}
- interp->result = Tk_PathName(squarePtr->tkwin);
+ Tk_CreateEventHandler(squarePtr->tkwin, ExposureMask|StructureNotifyMask,
+ SquareObjEventProc, (ClientData) squarePtr);
+ if (Tk_SetOptions(interp, (char *) squarePtr, optionTable, objc - 2,
+ objv + 2, tkwin, NULL, (int *) NULL) != TCL_OK) {
+ goto error;
+ }
+ if (SquareConfigure(interp, squarePtr) != TCL_OK) {
+ goto error;
+ }
+
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(squarePtr->tkwin),
+ -1));
return TCL_OK;
+
+error:
+ Tk_DestroyWindow(squarePtr->tkwin);
+ return TCL_ERROR;
}
/*
@@ -194,92 +235,79 @@ SquareCmd(clientData, interp, argc, argv)
*/
static int
-SquareWidgetCmd(clientData, interp, argc, argv)
+SquareWidgetCmd(clientData, interp, objc, objv)
ClientData clientData; /* Information about square 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 objects. */
{
Square *squarePtr = (Square *) clientData;
int result = TCL_OK;
- size_t length;
- char c;
+ static char *squareOptions[] = {"cget", "configure", (char *) NULL};
+ enum {
+ SQUARE_CGET, SQUARE_CONFIGURE
+ };
+ Tcl_Obj *resultObjPtr;
+ int index;
+
+ if (objc < 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg...?");
+ return TCL_ERROR;
+ }
- if (argc < 2) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " option ?arg arg ...?\"", (char *) NULL);
+ if (Tcl_GetIndexFromObj(interp, objv[1], squareOptions, "command",
+ 0, &index) != TCL_OK) {
return TCL_ERROR;
}
+
Tcl_Preserve((ClientData) squarePtr);
- 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, squarePtr->tkwin, configSpecs,
- (char *) squarePtr, argv[2], 0);
- } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
- && (length >= 2)) {
- if (argc == 2) {
- result = Tk_ConfigureInfo(interp, squarePtr->tkwin, configSpecs,
- (char *) squarePtr, (char *) NULL, 0);
- } else if (argc == 3) {
- result = Tk_ConfigureInfo(interp, squarePtr->tkwin, configSpecs,
- (char *) squarePtr, argv[2], 0);
- } else {
- result = SquareConfigure(interp, squarePtr, argc-2, argv+2,
- TK_CONFIG_ARGV_ONLY);
- }
- } else if ((c == 'p') && (strncmp(argv[1], "position", length) == 0)) {
- if ((argc != 2) && (argc != 4)) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " position ?x y?\"", (char *) NULL);
- goto error;
- }
- if (argc == 4) {
- if ((Tk_GetPixels(interp, squarePtr->tkwin, argv[2],
- &squarePtr->x) != TCL_OK) || (Tk_GetPixels(interp,
- squarePtr->tkwin, argv[3], &squarePtr->y) != TCL_OK)) {
+
+ switch (index) {
+ case SQUARE_CGET: {
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "option");
goto error;
}
- KeepInWindow(squarePtr);
- }
- sprintf(interp->result, "%d %d", squarePtr->x, squarePtr->y);
- } else if ((c == 's') && (strncmp(argv[1], "size", length) == 0)) {
- if ((argc != 2) && (argc != 3)) {
- Tcl_AppendResult(interp, "wrong # args: should be \"",
- argv[0], " size ?amount?\"", (char *) NULL);
- goto error;
+ resultObjPtr = Tk_GetOptionValue(interp, (char *) squarePtr,
+ squarePtr->optionTable, objv[2], squarePtr->tkwin);
+ if (resultObjPtr == NULL) {
+ result = TCL_ERROR;
+ } else {
+ Tcl_SetObjResult(interp, resultObjPtr);
+ }
+ break;
}
- if (argc == 3) {
- int i;
-
- if (Tk_GetPixels(interp, squarePtr->tkwin, argv[2], &i) != TCL_OK) {
- goto error;
+ case SQUARE_CONFIGURE: {
+ resultObjPtr = NULL;
+ if (objc == 2) {
+ resultObjPtr = Tk_GetOptionInfo(interp, (char *) squarePtr,
+ squarePtr->optionTable, (Tcl_Obj *) NULL,
+ squarePtr->tkwin);
+ if (resultObjPtr == NULL) {
+ result = TCL_ERROR;
+ }
+ } else if (objc == 3) {
+ resultObjPtr = Tk_GetOptionInfo(interp, (char *) squarePtr,
+ squarePtr->optionTable, objv[2], squarePtr->tkwin);
+ if (resultObjPtr == NULL) {
+ result = TCL_ERROR;
+ }
+ } else {
+ result = Tk_SetOptions(interp, (char *) squarePtr,
+ squarePtr->optionTable, objc - 2, objv + 2,
+ squarePtr->tkwin, NULL, (int *) NULL);
+ if (result == TCL_OK) {
+ result = SquareConfigure(interp, squarePtr);
+ }
+ if (!squarePtr->updatePending) {
+ Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);
+ squarePtr->updatePending = 1;
+ }
}
- if ((i <= 0) || (i > 100)) {
- Tcl_AppendResult(interp, "bad size \"", argv[2],
- "\"", (char *) NULL);
- goto error;
+ if (resultObjPtr != NULL) {
+ Tcl_SetObjResult(interp, resultObjPtr);
}
- squarePtr->size = i;
- KeepInWindow(squarePtr);
}
- sprintf(interp->result, "%d", squarePtr->size);
- } else {
- Tcl_AppendResult(interp, "bad option \"", argv[1],
- "\": must be cget, configure, position, or size",
- (char *) NULL);
- goto error;
- }
- if (!squarePtr->updatePending) {
- Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);
- squarePtr->updatePending = 1;
}
Tcl_Release((ClientData) squarePtr);
return result;
@@ -300,7 +328,7 @@ SquareWidgetCmd(clientData, interp, argc, argv)
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
- * returned, then interp->result contains an error message.
+ * returned, then the interp's result contains an error message.
*
* Side effects:
* Configuration information, such as colors, border width,
@@ -311,27 +339,25 @@ SquareWidgetCmd(clientData, interp, argc, argv)
*/
static int
-SquareConfigure(interp, squarePtr, argc, argv, flags)
+SquareConfigure(interp, squarePtr)
Tcl_Interp *interp; /* Used for error reporting. */
Square *squarePtr; /* Information about widget. */
- int argc; /* Number of valid entries in argv. */
- char **argv; /* Arguments. */
- int flags; /* Flags to pass to
- * Tk_ConfigureWidget. */
{
- if (Tk_ConfigureWidget(interp, squarePtr->tkwin, configSpecs,
- argc, argv, (char *) squarePtr, flags) != TCL_OK) {
- return TCL_ERROR;
- }
+ int borderWidth;
+ Tk_3DBorder bgBorder;
+ int doubleBuffer;
/*
* Set the background for the window and create a graphics context
* for use during redisplay.
*/
+ bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
+ squarePtr->bgBorderPtr);
Tk_SetWindowBackground(squarePtr->tkwin,
- Tk_3DBorderColor(squarePtr->bgBorder)->pixel);
- if ((squarePtr->gc == None) && (squarePtr->doubleBuffer)) {
+ Tk_3DBorderColor(bgBorder)->pixel);
+ Tcl_GetBooleanFromObj(NULL, squarePtr->doubleBufferPtr, &doubleBuffer);
+ if ((squarePtr->gc == None) && (doubleBuffer)) {
XGCValues gcValues;
gcValues.function = GXcopy;
gcValues.graphics_exposures = False;
@@ -345,18 +371,21 @@ SquareConfigure(interp, squarePtr, argc, argv, flags)
*/
Tk_GeometryRequest(squarePtr->tkwin, 200, 150);
- Tk_SetInternalBorder(squarePtr->tkwin, squarePtr->borderWidth);
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
+ &borderWidth);
+ Tk_SetInternalBorder(squarePtr->tkwin, borderWidth);
if (!squarePtr->updatePending) {
Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);
squarePtr->updatePending = 1;
}
+ KeepInWindow(squarePtr);
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
- * SquareEventProc --
+ * SquareObjEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on squares.
@@ -372,7 +401,7 @@ SquareConfigure(interp, squarePtr, argc, argv, flags)
*/
static void
-SquareEventProc(clientData, eventPtr)
+SquareObjEventProc(clientData, eventPtr)
ClientData clientData; /* Information about window. */
XEvent *eventPtr; /* Information about event. */
{
@@ -391,6 +420,11 @@ SquareEventProc(clientData, eventPtr)
}
} else if (eventPtr->type == DestroyNotify) {
if (squarePtr->tkwin != NULL) {
+ Tk_FreeConfigOptions((char *) squarePtr, squarePtr->optionTable,
+ squarePtr->tkwin);
+ if (squarePtr->gc != None) {
+ Tk_FreeGC(squarePtr->display, squarePtr->gc);
+ }
squarePtr->tkwin = NULL;
Tcl_DeleteCommandFromToken(squarePtr->interp,
squarePtr->widgetCmd);
@@ -405,7 +439,7 @@ SquareEventProc(clientData, eventPtr)
/*
*----------------------------------------------------------------------
*
- * SquareCmdDeletedProc --
+ * SquareDeletedProc --
*
* This procedure is invoked when a widget command is deleted. If
* the widget isn't already in the process of being destroyed,
@@ -421,7 +455,7 @@ SquareEventProc(clientData, eventPtr)
*/
static void
-SquareCmdDeletedProc(clientData)
+SquareDeletedProc(clientData)
ClientData clientData; /* Pointer to widget record for widget. */
{
Square *squarePtr = (Square *) clientData;
@@ -435,7 +469,6 @@ SquareCmdDeletedProc(clientData)
*/
if (tkwin != NULL) {
- squarePtr->tkwin = NULL;
Tk_DestroyWindow(tkwin);
}
}
@@ -466,6 +499,9 @@ SquareDisplay(clientData)
Tk_Window tkwin = squarePtr->tkwin;
Pixmap pm = None;
Drawable d;
+ int borderWidth, size, relief;
+ Tk_3DBorder bgBorder, fgBorder;
+ int doubleBuffer;
squarePtr->updatePending = 0;
if (!Tk_IsMapped(tkwin)) {
@@ -476,7 +512,8 @@ SquareDisplay(clientData)
* Create a pixmap for double-buffering, if necessary.
*/
- if (squarePtr->doubleBuffer) {
+ Tcl_GetBooleanFromObj(NULL, squarePtr->doubleBufferPtr, &doubleBuffer);
+ if (doubleBuffer) {
pm = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin),
Tk_Width(tkwin), Tk_Height(tkwin),
DefaultDepthOfScreen(Tk_Screen(tkwin)));
@@ -489,22 +526,29 @@ SquareDisplay(clientData)
* Redraw the widget's background and border.
*/
- Tk_Fill3DRectangle(tkwin, d, squarePtr->bgBorder, 0, 0, Tk_Width(tkwin),
- Tk_Height(tkwin), squarePtr->borderWidth, squarePtr->relief);
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
+ &borderWidth);
+ bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
+ squarePtr->bgBorderPtr);
+ Tk_GetReliefFromObj(NULL, squarePtr->reliefPtr, &relief);
+ Tk_Fill3DRectangle(tkwin, d, bgBorder, 0, 0, Tk_Width(tkwin),
+ Tk_Height(tkwin), borderWidth, relief);
/*
* Display the square.
*/
- Tk_Fill3DRectangle(tkwin, d, squarePtr->fgBorder, squarePtr->x,
- squarePtr->y, squarePtr->size, squarePtr->size,
- squarePtr->borderWidth, TK_RELIEF_RAISED);
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->sizeObjPtr, &size);
+ fgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
+ squarePtr->fgBorderPtr);
+ Tk_Fill3DRectangle(tkwin, d, fgBorder, squarePtr->x, squarePtr->y, size,
+ size, borderWidth, TK_RELIEF_RAISED);
/*
* If double-buffered, copy to the screen and release the pixmap.
*/
- if (squarePtr->doubleBuffer) {
+ if (doubleBuffer) {
XCopyArea(Tk_Display(tkwin), pm, Tk_WindowId(tkwin), squarePtr->gc,
0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
0, 0);
@@ -535,11 +579,7 @@ SquareDestroy(memPtr)
char *memPtr; /* Info about square widget. */
{
Square *squarePtr = (Square *) memPtr;
-
- Tk_FreeOptions(configSpecs, (char *) squarePtr, squarePtr->display, 0);
- if (squarePtr->gc != None) {
- Tk_FreeGC(squarePtr->display, squarePtr->gc);
- }
+
ckfree((char *) squarePtr);
}
@@ -565,16 +605,26 @@ static void
KeepInWindow(squarePtr)
register Square *squarePtr; /* Pointer to widget record. */
{
- int i, bd;
+ int i, bd, relief;
+ int borderWidth, size;
+
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
+ &borderWidth);
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->xPtr,
+ &squarePtr->x);
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->yPtr,
+ &squarePtr->y);
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->sizeObjPtr, &size);
+ Tk_GetReliefFromObj(NULL, squarePtr->reliefPtr, &relief);
bd = 0;
- if (squarePtr->relief != TK_RELIEF_FLAT) {
- bd = squarePtr->borderWidth;
+ if (relief != TK_RELIEF_FLAT) {
+ bd = borderWidth;
}
- i = (Tk_Width(squarePtr->tkwin) - bd) - (squarePtr->x + squarePtr->size);
+ i = (Tk_Width(squarePtr->tkwin) - bd) - (squarePtr->x + size);
if (i < 0) {
squarePtr->x += i;
}
- i = (Tk_Height(squarePtr->tkwin) - bd) - (squarePtr->y + squarePtr->size);
+ i = (Tk_Height(squarePtr->tkwin) - bd) - (squarePtr->y + size);
if (i < 0) {
squarePtr->y += i;
}