summaryrefslogtreecommitdiffstats
path: root/generic/tkSquare.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkSquare.c')
-rw-r--r--generic/tkSquare.c333
1 files changed, 167 insertions, 166 deletions
diff --git a/generic/tkSquare.c b/generic/tkSquare.c
index d3b6f04..0b984dd 100644
--- a/generic/tkSquare.c
+++ b/generic/tkSquare.c
@@ -1,18 +1,18 @@
-/*
+/*
* tkSquare.c --
*
- * 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".
+ * 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) 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.
+ * 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.5 2002/01/17 23:33:53 dgp Exp $
+ * RCS: @(#) $Id: tkSquare.c,v 1.6 2005/11/15 15:18:22 dkf Exp $
*/
#include "tkPort.h"
@@ -21,14 +21,14 @@
#include "tkInt.h"
/*
- * A data structure of the following type is kept for each square
- * widget managed by this file:
+ * A data structure of the following type is kept for each square widget
+ * managed by this file:
*/
typedef struct {
- Tk_Window tkwin; /* Window that embodies the square. NULL
- * means window has been deleted but
- * widget record hasn't been cleaned up yet. */
+ Tk_Window tkwin; /* Window that embodies the square. NULL means
+ * window has been deleted but widget record
+ * hasn't been cleaned up yet. */
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. */
@@ -49,11 +49,11 @@ typedef struct {
Tcl_Obj *reliefPtr;
GC gc; /* Graphics context for copying from
* off-screen pixmap onto screen. */
- 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
- * has already been scheduled. */
+ 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 has
+ * already been scheduled. */
} Square;
/*
@@ -64,16 +64,16 @@ static Tk_OptionSpec optionSpecs[] = {
{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_SYNONYM, "-bd", NULL, NULL, NULL, 0, -1, 0,
+ (ClientData) "-borderwidth"},
+ {TK_OPTION_SYNONYM, "-bg", NULL, NULL, 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_SYNONYM, "-fg", NULL, NULL, NULL, 0, -1, 0,
+ (ClientData) "-foreground"},
{TK_OPTION_BORDER, "-foreground", "foreground", "Foreground",
"#b03060", Tk_Offset(Square, fgBorderPtr), -1, 0,
(ClientData) "black"},
@@ -92,28 +92,26 @@ static Tk_OptionSpec optionSpecs[] = {
* Forward declarations for procedures defined later in this file:
*/
-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));
-static void SquareDestroy _ANSI_ARGS_((char *memPtr));
-static void SquareDisplay _ANSI_ARGS_((ClientData clientData));
-static void KeepInWindow _ANSI_ARGS_((Square *squarePtr));
-static void SquareObjEventProc _ANSI_ARGS_((ClientData clientData,
- XEvent *eventPtr));
-static int SquareWidgetObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *, int objc, Tcl_Obj * CONST objv[]));
+int SquareObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc,
+ Tcl_Obj * CONST objv[]);
+static void SquareDeletedProc(ClientData clientData);
+static int SquareConfigure(Tcl_Interp *interp, Square *squarePtr);
+static void SquareDestroy(char *memPtr);
+static void SquareDisplay(ClientData clientData);
+static void KeepInWindow(Square *squarePtr);
+static void SquareObjEventProc(ClientData clientData,
+ XEvent *eventPtr);
+static int SquareWidgetObjCmd(ClientData clientData,
+ Tcl_Interp *, int objc, Tcl_Obj * CONST objv[]);
/*
*--------------------------------------------------------------
*
* SquareCmd --
*
- * This procedure is invoked to process the "square" Tcl
- * command. It creates a new "square" widget.
+ * This procedure is invoked to process the "square" Tcl command. It
+ * creates a new "square" widget.
*
* Results:
* A standard Tcl result.
@@ -125,11 +123,11 @@ static int SquareWidgetObjCmd _ANSI_ARGS_((ClientData clientData,
*/
int
-SquareObjCmd(clientData, interp, objc, objv)
- ClientData clientData; /* NULL. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+SquareObjCmd(
+ ClientData clientData, /* NULL. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
Square *squarePtr;
Tk_Window tkwin;
@@ -140,39 +138,38 @@ SquareObjCmd(clientData, interp, objc, objv)
return TCL_ERROR;
}
- tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
- Tcl_GetStringFromObj(objv[1], NULL), (char *) NULL);
+ tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
+ Tcl_GetString(objv[1]), NULL);
if (tkwin == NULL) {
return TCL_ERROR;
}
Tk_SetClass(tkwin, "Square");
/*
- * Create the option table for this widget class. If it has
- * already been created, the refcount will get bumped and just
- * the pointer will be returned. The refcount getting bumped
- * does not concern us, because Tk will ensure the table is
- * deleted when the interpreter is destroyed.
+ * Create the option table for this widget class. If it has already been
+ * created, the refcount will get bumped and just the pointer will be
+ * returned. The refcount getting bumped does not concern us, because Tk
+ * will ensure the table is deleted when the interpreter is destroyed.
*/
optionTable = Tk_CreateOptionTable(interp, optionSpecs);
/*
- * Allocate and initialize the widget record. The memset allows
- * us to set just the non-NULL/0 items.
+ * Allocate and initialize the widget record. The memset allows us to set
+ * just the non-NULL/0 items.
*/
- squarePtr = (Square *) ckalloc(sizeof(Square));
+ squarePtr = (Square *) ckalloc(sizeof(Square));
memset((void *) squarePtr, 0, (sizeof(Square)));
- squarePtr->tkwin = tkwin;
- squarePtr->display = Tk_Display(tkwin);
- squarePtr->interp = interp;
- squarePtr->widgetCmd = Tcl_CreateObjCommand(interp,
+ squarePtr->tkwin = tkwin;
+ squarePtr->display = Tk_Display(tkwin);
+ squarePtr->interp = interp;
+ squarePtr->widgetCmd = Tcl_CreateObjCommand(interp,
Tk_PathName(squarePtr->tkwin), SquareWidgetObjCmd,
(ClientData) squarePtr, SquareDeletedProc);
- squarePtr->gc = None;
- squarePtr->optionTable = optionTable;
+ squarePtr->gc = None;
+ squarePtr->optionTable = optionTable;
if (Tk_InitOptions(interp, (char *) squarePtr, optionTable, tkwin)
!= TCL_OK) {
@@ -184,7 +181,7 @@ SquareObjCmd(clientData, interp, objc, objv)
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) {
+ objv + 2, tkwin, NULL, NULL) != TCL_OK) {
goto error;
}
if (SquareConfigure(interp, squarePtr) != TCL_OK) {
@@ -195,7 +192,7 @@ SquareObjCmd(clientData, interp, objc, objv)
Tcl_NewStringObj(Tk_PathName(squarePtr->tkwin), -1));
return TCL_OK;
-error:
+ error:
Tk_DestroyWindow(squarePtr->tkwin);
return TCL_ERROR;
}
@@ -205,9 +202,9 @@ error:
*
* SquareWidgetObjCmd --
*
- * This procedure is invoked to process the Tcl command
- * that corresponds to a widget managed by this module.
- * See the user documentation for details on what it does.
+ * This procedure is invoked to process the Tcl command that corresponds
+ * to a widget managed by this module. See the user documentation for
+ * details on what it does.
*
* Results:
* A standard Tcl result.
@@ -219,15 +216,15 @@ error:
*/
static int
-SquareWidgetObjCmd(clientData, interp, objc, objv)
- ClientData clientData; /* Information about square widget. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+SquareWidgetObjCmd(
+ ClientData clientData, /* Information about square widget. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj * CONST objv[]) /* Argument objects. */
{
Square *squarePtr = (Square *) clientData;
int result = TCL_OK;
- static CONST char *squareOptions[] = {"cget", "configure", (char *) NULL};
+ static CONST char *squareOptions[] = {"cget", "configure", NULL};
enum {
SQUARE_CGET, SQUARE_CONFIGURE
};
@@ -245,58 +242,55 @@ SquareWidgetObjCmd(clientData, interp, objc, objv)
}
Tcl_Preserve((ClientData) squarePtr);
-
+
switch (index) {
- case SQUARE_CGET: {
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "option");
- goto error;
+ case SQUARE_CGET:
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "option");
+ 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;
+ case SQUARE_CONFIGURE:
+ resultObjPtr = NULL;
+ if (objc == 2) {
+ resultObjPtr = Tk_GetOptionInfo(interp, (char *) squarePtr,
+ squarePtr->optionTable, NULL, squarePtr->tkwin);
+ if (resultObjPtr == NULL) {
+ result = TCL_ERROR;
}
- resultObjPtr = Tk_GetOptionValue(interp, (char *) squarePtr,
+ } else if (objc == 3) {
+ resultObjPtr = Tk_GetOptionInfo(interp, (char *) squarePtr,
squarePtr->optionTable, objv[2], squarePtr->tkwin);
if (resultObjPtr == NULL) {
result = TCL_ERROR;
- } else {
- Tcl_SetObjResult(interp, resultObjPtr);
}
- break;
- }
- 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;
- }
+ } else {
+ result = Tk_SetOptions(interp, (char *) squarePtr,
+ squarePtr->optionTable, objc - 2, objv + 2,
+ squarePtr->tkwin, NULL, NULL);
+ if (result == TCL_OK) {
+ result = SquareConfigure(interp, squarePtr);
}
- if (resultObjPtr != NULL) {
- Tcl_SetObjResult(interp, resultObjPtr);
+ if (!squarePtr->updatePending) {
+ Tcl_DoWhenIdle(SquareDisplay, (ClientData) squarePtr);
+ squarePtr->updatePending = 1;
}
}
+ if (resultObjPtr != NULL) {
+ Tcl_SetObjResult(interp, resultObjPtr);
+ }
}
Tcl_Release((ClientData) squarePtr);
return result;
- error:
+ error:
Tcl_Release((ClientData) squarePtr);
return TCL_ERROR;
}
@@ -306,37 +300,36 @@ SquareWidgetObjCmd(clientData, interp, objc, objv)
*
* SquareConfigure --
*
- * This procedure is called to process an argv/argc list in
- * conjunction with the Tk option database to configure (or
- * reconfigure) a square widget.
+ * This procedure is called to process an argv/argc list in conjunction
+ * with the Tk option database to configure (or reconfigure) a square
+ * widget.
*
* Results:
- * The return value is a standard Tcl result. If TCL_ERROR is
- * returned, then the interp's result contains an error message.
+ * The return value is a standard Tcl result. If TCL_ERROR is returned,
+ * then the interp's result contains an error message.
*
* Side effects:
- * Configuration information, such as colors, border width,
- * etc. get set for squarePtr; old resources get freed,
- * if there were any.
+ * Configuration information, such as colors, border width, etc. get set
+ * for squarePtr; old resources get freed, if there were any.
*
*----------------------------------------------------------------------
*/
static int
-SquareConfigure(interp, squarePtr)
- Tcl_Interp *interp; /* Used for error reporting. */
- Square *squarePtr; /* Information about widget. */
+SquareConfigure(
+ Tcl_Interp *interp, /* Used for error reporting. */
+ Square *squarePtr) /* Information about widget. */
{
int borderWidth;
Tk_3DBorder bgBorder;
int doubleBuffer;
/*
- * Set the background for the window and create a graphics context
- * for use during redisplay.
+ * Set the background for the window and create a graphics context for use
+ * during redisplay.
*/
- bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
+ bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
squarePtr->bgBorderPtr);
Tk_SetWindowBackground(squarePtr->tkwin,
Tk_3DBorderColor(bgBorder)->pixel);
@@ -350,8 +343,8 @@ SquareConfigure(interp, squarePtr)
}
/*
- * Register the desired geometry for the window. Then arrange for
- * the window to be redisplayed.
+ * Register the desired geometry for the window. Then arrange for the
+ * window to be redisplayed.
*/
Tk_GeometryRequest(squarePtr->tkwin, 200, 150);
@@ -371,23 +364,23 @@ SquareConfigure(interp, squarePtr)
*
* SquareObjEventProc --
*
- * This procedure is invoked by the Tk dispatcher for various
- * events on squares.
+ * This procedure is invoked by the Tk dispatcher for various events on
+ * squares.
*
* Results:
* None.
*
* Side effects:
- * When the window gets deleted, internal structures get
- * cleaned up. When it gets exposed, it is redisplayed.
+ * When the window gets deleted, internal structures get cleaned up. When
+ * it gets exposed, it is redisplayed.
*
*--------------------------------------------------------------
*/
static void
-SquareObjEventProc(clientData, eventPtr)
- ClientData clientData; /* Information about window. */
- XEvent *eventPtr; /* Information about event. */
+SquareObjEventProc(
+ ClientData clientData, /* Information about window. */
+ XEvent *eventPtr) /* Information about event. */
{
Square *squarePtr = (Square *) clientData;
@@ -425,9 +418,9 @@ SquareObjEventProc(clientData, eventPtr)
*
* SquareDeletedProc --
*
- * This procedure is invoked when a widget command is deleted. If
- * the widget isn't already in the process of being destroyed,
- * this command destroys it.
+ * This procedure is invoked when a widget command is deleted. If the
+ * widget isn't already in the process of being destroyed, this command
+ * destroys it.
*
* Results:
* None.
@@ -439,17 +432,17 @@ SquareObjEventProc(clientData, eventPtr)
*/
static void
-SquareDeletedProc(clientData)
- ClientData clientData; /* Pointer to widget record for widget. */
+SquareDeletedProc(
+ ClientData clientData) /* Pointer to widget record for widget. */
{
Square *squarePtr = (Square *) clientData;
Tk_Window tkwin = squarePtr->tkwin;
/*
- * This procedure could be invoked either because the window was
- * destroyed and the command was then deleted (in which case tkwin
- * is NULL) or because the command was deleted, and then this procedure
- * destroys the widget.
+ * This procedure could be invoked either because the window was destroyed
+ * and the command was then deleted (in which case tkwin is NULL) or
+ * because the command was deleted, and then this procedure destroys the
+ * widget.
*/
if (tkwin != NULL) {
@@ -462,9 +455,9 @@ SquareDeletedProc(clientData)
*
* SquareDisplay --
*
- * This procedure redraws the contents of a square window.
- * It is invoked as a do-when-idle handler, so it only runs
- * when there's nothing else for the application to do.
+ * This procedure redraws the contents of a square window. It is invoked
+ * as a do-when-idle handler, so it only runs when there's nothing else
+ * for the application to do.
*
* Results:
* None.
@@ -476,8 +469,8 @@ SquareDeletedProc(clientData)
*/
static void
-SquareDisplay(clientData)
- ClientData clientData; /* Information about window. */
+SquareDisplay(
+ ClientData clientData) /* Information about window. */
{
Square *squarePtr = (Square *) clientData;
Tk_Window tkwin = squarePtr->tkwin;
@@ -512,7 +505,7 @@ SquareDisplay(clientData)
Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
&borderWidth);
- bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
+ bgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
squarePtr->bgBorderPtr);
Tk_GetReliefFromObj(NULL, squarePtr->reliefPtr, &relief);
Tk_Fill3DRectangle(tkwin, d, bgBorder, 0, 0, Tk_Width(tkwin),
@@ -523,9 +516,9 @@ SquareDisplay(clientData)
*/
Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->sizeObjPtr, &size);
- fgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
+ fgBorder = Tk_Get3DBorderFromObj(squarePtr->tkwin,
squarePtr->fgBorderPtr);
- Tk_Fill3DRectangle(tkwin, d, fgBorder, squarePtr->x, squarePtr->y, size,
+ Tk_Fill3DRectangle(tkwin, d, fgBorder, squarePtr->x, squarePtr->y, size,
size, borderWidth, TK_RELIEF_RAISED);
/*
@@ -545,9 +538,9 @@ SquareDisplay(clientData)
*
* SquareDestroy --
*
- * This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
- * to clean up the internal structure of a square at a safe time
- * (when no-one is using it anymore).
+ * This procedure is invoked by Tcl_EventuallyFree or Tcl_Release to
+ * clean up the internal structure of a square at a safe time (when
+ * no-one is using it anymore).
*
* Results:
* None.
@@ -559,11 +552,11 @@ SquareDisplay(clientData)
*/
static void
-SquareDestroy(memPtr)
- char *memPtr; /* Info about square widget. */
+SquareDestroy(
+ char *memPtr) /* Info about square widget. */
{
Square *squarePtr = (Square *) memPtr;
-
+
ckfree((char *) squarePtr);
}
@@ -572,31 +565,31 @@ SquareDestroy(memPtr)
*
* KeepInWindow --
*
- * Adjust the position of the square if necessary to keep it in
- * the widget's window.
+ * Adjust the position of the square if necessary to keep it in the
+ * widget's window.
*
* Results:
* None.
*
* Side effects:
- * The x and y position of the square are adjusted if necessary
- * to keep the square in the window.
+ * The x and y position of the square are adjusted if necessary to keep
+ * the square in the window.
*
*----------------------------------------------------------------------
*/
static void
-KeepInWindow(squarePtr)
- register Square *squarePtr; /* Pointer to widget record. */
+KeepInWindow(
+ register Square *squarePtr) /* Pointer to widget record. */
{
int i, bd, relief;
int borderWidth, size;
Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->borderWidthPtr,
&borderWidth);
- Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->xPtr,
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->xPtr,
&squarePtr->x);
- Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->yPtr,
+ Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->yPtr,
&squarePtr->y);
Tk_GetPixelsFromObj(NULL, squarePtr->tkwin, squarePtr->sizeObjPtr, &size);
Tk_GetReliefFromObj(NULL, squarePtr->reliefPtr, &relief);
@@ -619,3 +612,11 @@ KeepInWindow(squarePtr)
squarePtr->y = bd;
}
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */