/*
* 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
* 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-1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkSquare.c 1.17 96/07/23 16:54:29
*/
#include "tkInt.h"
/*
* A data structure of the following type is kept for each square
* widget managed by this file:
*/
typedef struct {
* means window has been deleted but
* widget record hasn't been cleaned up yet. */
int x, y; /* Position of square's upper-left corner
* within widget. */
/*
* Information used when displaying widget:
*/
* raised, sunken, or flat. */
* off-screen pixmap onto screen. */
* with pixmap; zero means draw straight
* onto the display. */
* has already been scheduled. */
} Square;
/*
* Information used for argv parsing.
*/
(char *) NULL, 0, 0},
(char *) NULL, 0, 0},
(char *) NULL, 0, 0},
(char *) NULL, 0, 0}
};
/*
* Forward declarations for procedures defined later in this file:
*/
static void SquareCmdDeletedProc _ANSI_ARGS_((
int flags));
/*
*--------------------------------------------------------------
*
* SquareCmd --
*
* This procedure is invoked to process the "square" Tcl
* command. It creates a new "square" widget.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* A new widget is created and configured.
*
*--------------------------------------------------------------
*/
int
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
if (argc < 2) {
return TCL_ERROR;
}
return TCL_ERROR;
}
/*
* Allocate and initialize the widget record.
*/
squarePtr->x = 0;
squarePtr->y = 0;
squarePtr->borderWidth = 0;
squarePtr->updatePending = 0;
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* SquareWidgetCmd --
*
* 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.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
static int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
char c;
if (argc < 2) {
return TCL_ERROR;
}
c = argv[1][0];
&& (length >= 2)) {
if (argc != 3) {
argv[0], " cget option\"",
(char *) NULL);
goto error;
}
&& (length >= 2)) {
if (argc == 2) {
} else if (argc == 3) {
} else {
}
goto error;
}
if (argc == 4) {
goto error;
}
}
goto error;
}
if (argc == 3) {
int i;
goto error;
}
if ((i <= 0) || (i > 100)) {
"\"", (char *) NULL);
goto error;
}
}
} else {
"\": must be cget, configure, position, or size",
(char *) NULL);
goto error;
}
if (!squarePtr->updatePending) {
}
return result;
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* SquareConfigure --
*
* 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 interp->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.
*
*----------------------------------------------------------------------
*/
static int
int argc; /* Number of valid entries in argv. */
char **argv; /* Arguments. */
int flags; /* Flags to pass to
* Tk_ConfigureWidget. */
{
return TCL_ERROR;
}
/*
* Set the background for the window and create a graphics context
* for use during redisplay.
*/
}
/*
* Register the desired geometry for the window. Then arrange for
* the window to be redisplayed.
*/
if (!squarePtr->updatePending) {
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* SquareEventProc --
*
* 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.
*
*--------------------------------------------------------------
*/
static void
{
if (!squarePtr->updatePending) {
}
if (!squarePtr->updatePending) {
}
}
if (squarePtr->updatePending) {
}
}
}
/*
*----------------------------------------------------------------------
*
* SquareCmdDeletedProc --
*
* 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.
*
* Side effects:
* The widget is destroyed.
*
*----------------------------------------------------------------------
*/
static void
{
/*
* 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.
*/
}
}
/*
*--------------------------------------------------------------
*
* 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.
*
* Results:
* None.
*
* Side effects:
* Information appears on the screen.
*
*--------------------------------------------------------------
*/
static void
{
Drawable d;
squarePtr->updatePending = 0;
if (!Tk_IsMapped(tkwin)) {
return;
}
/*
* Create a pixmap for double-buffering, if necessary.
*/
if (squarePtr->doubleBuffer) {
d = pm;
} else {
d = Tk_WindowId(tkwin);
}
/*
* Redraw the widget's background and border.
*/
/*
* Display the square.
*/
/*
* If double-buffered, copy to the screen and release the pixmap.
*/
if (squarePtr->doubleBuffer) {
0, 0);
}
}
/*
*----------------------------------------------------------------------
*
* 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).
*
* Results:
* None.
*
* Side effects:
* Everything associated with the square is freed up.
*
*----------------------------------------------------------------------
*/
static void
char *memPtr; /* Info about square widget. */
{
}
}
/*
*----------------------------------------------------------------------
*
* KeepInWindow --
*
* 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.
*
*----------------------------------------------------------------------
*/
static void
{
int i, bd;
bd = 0;
}
if (i < 0) {
squarePtr->x += i;
}
if (i < 0) {
squarePtr->y += i;
}
}
}
}