/*
* tkCanvWind.c --
*
* This file implements window items for canvas widgets.
*
* Copyright (c) 1992-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: @(#) tkCanvWind.c 1.26 96/09/06 08:41:52
*/
#include "tkInt.h"
#include "tkCanvas.h"
/*
* The structure below defines the record for each window item.
*/
typedef struct WindowItem {
* types. MUST BE FIRST IN STRUCTURE. */
double x, y; /* Coordinates of positioning point for
* window. */
* window has been destroyed. */
* window's requested width). */
* window's requested width). */
* (x,y). */
} WindowItem;
/*
* Information used for parsing configuration specs:
*/
};
(char *) NULL, 0, 0}
};
/*
* Prototypes for procedures defined in this file:
*/
WindowItem *winItemPtr));
char **argv));
static void WinItemLostSlaveProc _ANSI_ARGS_((
static void WinItemStructureProc _ANSI_ARGS_((
/*
* The structure below defines the window item type by means of procedures
* that can be invoked by generic item code.
*/
"window", /* name */
sizeof(WindowItem), /* itemSize */
CreateWinItem, /* createProc */
configSpecs, /* configSpecs */
ConfigureWinItem, /* configureProc */
WinItemCoords, /* coordProc */
DeleteWinItem, /* deleteProc */
DisplayWinItem, /* displayProc */
1, /* alwaysRedraw */
WinItemToPoint, /* pointProc */
WinItemToArea, /* areaProc */
ScaleWinItem, /* scaleProc */
TranslateWinItem, /* translateProc */
};
/*
* The structure below defines the official type record for the
* placer:
*/
"canvas", /* name */
WinItemRequestProc, /* requestProc */
WinItemLostSlaveProc, /* lostSlaveProc */
};
/*
*--------------------------------------------------------------
*
* CreateWinItem --
*
* This procedure is invoked to create a new window
* item in a canvas.
*
* Results:
* A standard Tcl return value. If an error occurred in
* creating the item, then an error message is left in
* interp->result; in this case itemPtr is
* left uninitialized, so it can be safely freed by the
* caller.
*
* Side effects:
* A new window item is created.
*
*--------------------------------------------------------------
*/
static int
* has been initialized by caller. */
int argc; /* Number of arguments in argv. */
char **argv; /* Arguments describing rectangle. */
{
if (argc < 2) {
(char *) NULL);
return TCL_ERROR;
}
/*
* Initialize item's record.
*/
winItemPtr->width = 0;
winItemPtr->height = 0;
/*
* Process the arguments to fill in the item record.
*/
&winItemPtr->y) != TCL_OK)) {
return TCL_ERROR;
}
!= TCL_OK) {
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* WinItemCoords --
*
* This procedure is invoked to process the "coords" widget
* command on window items. See the user documentation for
* details on what it does.
*
* Results:
* Returns TCL_OK or TCL_ERROR, and sets interp->result.
*
* Side effects:
* The coordinates for the given item may be changed.
*
*--------------------------------------------------------------
*/
static int
* read or modified. */
int argc; /* Number of coordinates supplied in
* argv. */
char **argv; /* Array of coordinates: x1, y1,
* x2, y2, ... */
{
char x[TCL_DOUBLE_SPACE], y[TCL_DOUBLE_SPACE];
if (argc == 0) {
} else if (argc == 2) {
&winItemPtr->y) != TCL_OK)) {
return TCL_ERROR;
}
} else {
"wrong # coordinates: expected 0 or 2, got %d", argc);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ConfigureWinItem --
*
* This procedure is invoked to configure various aspects
* of a window item, such as its anchor position.
*
* Results:
* A standard Tcl result code. If an error occurs, then
* an error message is left in interp->result.
*
* Side effects:
* Configuration information may be set for itemPtr.
*
*--------------------------------------------------------------
*/
static int
int argc; /* Number of elements in argv. */
char **argv; /* Arguments describing things to configure. */
int flags; /* Flags to pass to Tk_ConfigureWidget. */
{
return TCL_ERROR;
}
/*
* A few of the options require additional processing.
*/
(ClientData) NULL);
}
/*
* Make sure that the canvas is either the parent of the
* window associated with the item or a descendant of that
* parent. Also, don't allow a top-level window to be
* managed inside a canvas.
*/
for (ancestor = canvasTkwin; ;
break;
}
" in a window item of this canvas", (char *) NULL);
return TCL_ERROR;
}
}
goto badWindow;
}
goto badWindow;
}
(ClientData) winItemPtr);
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DeleteWinItem --
*
* This procedure is called to clean up the data structure
* associated with a window item.
*
* Results:
* None.
*
* Side effects:
* Resources associated with itemPtr are released.
*
*--------------------------------------------------------------
*/
static void
* canvas. */
{
(ClientData) NULL);
}
}
}
/*
*--------------------------------------------------------------
*
* ComputeWindowBbox --
*
* This procedure is invoked to compute the bounding box of
* all the pixels that may be drawn as part of a window item.
* This procedure is where the child window's placement is
* computed.
*
* Results:
* None.
*
* Side effects:
* The fields x1, y1, x2, and y2 are updated in the header
* for itemPtr.
*
*--------------------------------------------------------------
*/
static void
* recomputed. */
{
return;
}
/*
* Compute dimensions of window.
*/
if (width <= 0) {
if (width <= 0) {
width = 1;
}
}
if (height <= 0) {
if (height <= 0) {
height = 1;
}
}
/*
* Compute location of window, using anchor information.
*/
switch (winItemPtr->anchor) {
case TK_ANCHOR_N:
x -= width/2;
break;
case TK_ANCHOR_NE:
x -= width;
break;
case TK_ANCHOR_E:
x -= width;
y -= height/2;
break;
case TK_ANCHOR_SE:
x -= width;
y -= height;
break;
case TK_ANCHOR_S:
x -= width/2;
y -= height;
break;
case TK_ANCHOR_SW:
y -= height;
break;
case TK_ANCHOR_W:
y -= height/2;
break;
case TK_ANCHOR_NW:
break;
case TK_ANCHOR_CENTER:
x -= width/2;
y -= height/2;
break;
}
/*
* Store the information in the item header.
*/
}
/*
*--------------------------------------------------------------
*
* DisplayWinItem --
*
* This procedure is invoked to "draw" a window item in a given
* drawable. Since the window draws itself, we needn't do any
* actual redisplay here. However, this procedure takes care
* of actually repositioning the child window so that it occupies
* the correct screen position.
*
* Results:
* None.
*
* Side effects:
* The child window's position may get changed. Note: this
* procedure gets called both when a window needs to be displayed
* and when it ceases to be visible on the screen (e.g. it was
* scrolled or moved off-screen or the enclosing canvas is
* unmapped).
*
*--------------------------------------------------------------
*/
static void
* item. */
/* Describes region of canvas that
* must be redisplayed (not used). */
{
short x, y;
return;
}
/*
* Reposition and map the window (but in different ways depending
* on whether the canvas is the window's parent).
*/
}
} else {
}
}
/*
*--------------------------------------------------------------
*
* WinItemToPoint --
*
* Computes the distance from a given point to a given
* rectangle, in canvas units.
*
* Results:
* The return value is 0 if the point whose x and y coordinates
* are coordPtr[0] and coordPtr[1] is inside the window. If the
* point isn't inside the window then the return value is the
* distance from the point to the window.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static double
double *pointPtr; /* Pointer to x and y coordinates. */
{
/*
* Point is outside rectangle.
*/
} else {
xDiff = 0;
}
} else {
yDiff = 0;
}
}
/*
*--------------------------------------------------------------
*
* WinItemToArea --
*
* This procedure is called to determine whether an item
* lies entirely inside, entirely outside, or overlapping
* a given rectangle.
*
* Results:
* -1 is returned if the item is entirely outside the area
* given by rectPtr, 0 if it overlaps, and 1 if it is entirely
* inside the given area.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static int
double *rectPtr; /* Pointer to array of four coordinates
* (x1, y1, x2, y2) describing rectangular
* area. */
{
return -1;
}
return 1;
}
return 0;
}
/*
*--------------------------------------------------------------
*
* ScaleWinItem --
*
* This procedure is invoked to rescale a rectangle or oval
* item.
*
* Results:
* None.
*
* Side effects:
* The rectangle or oval referred to by itemPtr is rescaled
* so that the following transformation is applied to all
* point coordinates:
* x' = originX + scaleX*(x-originX)
* y' = originY + scaleY*(y-originY)
*
*--------------------------------------------------------------
*/
static void
double scaleX; /* Amount to scale in X direction. */
double scaleY; /* Amount to scale in Y direction. */
{
if (winItemPtr->width > 0) {
}
if (winItemPtr->height > 0) {
}
}
/*
*--------------------------------------------------------------
*
* TranslateWinItem --
*
* This procedure is called to move a rectangle or oval by a
* given amount.
*
* Results:
* None.
*
* Side effects:
* The position of the rectangle or oval is offset by
* (xDelta, yDelta), and the bounding box is updated in the
* generic part of the item structure.
*
*--------------------------------------------------------------
*/
static void
* moved. */
{
winItemPtr->x += deltaX;
winItemPtr->y += deltaY;
}
/*
*--------------------------------------------------------------
*
* WinItemStructureProc --
*
* This procedure is invoked whenever StructureNotify events
* occur for a window that's managed as part of a canvas window
* item. This procudure's only purpose is to clean up when
* windows are deleted.
*
* Results:
* None.
*
* Side effects:
* The window is disassociated from the window item when it is
* deleted.
*
*--------------------------------------------------------------
*/
static void
{
}
}
/*
*--------------------------------------------------------------
*
* WinItemRequestProc --
*
* This procedure is invoked whenever a window that's associated
* with a window canvas item changes its requested dimensions.
*
* Results:
* None.
*
* Side effects:
* The size and location on the screen of the window may change,
* depending on the options specified for the window item.
*
*--------------------------------------------------------------
*/
static void
* size. */
{
}
/*
*--------------------------------------------------------------
*
* WinItemLostSlaveProc --
*
* This procedure is invoked by Tk whenever some other geometry
* claims control over a slave that used to be managed by us.
*
* Results:
* None.
*
* Side effects:
* Forgets all canvas-related information about the slave.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static void
* was stolen away. */
{
}
}