/*
* tkImage.c --
*
* This module implements the image protocol, which allows lots
* of different kinds of images to be used in lots of different
* widgets.
*
* Copyright (c) 1994 The Regents of the University of California.
* Copyright (c) 1994-1996 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: @(#) tkImage.c 1.11 96/03/01 17:19:28
*/
#include "tkInt.h"
/*
* Each call to Tk_GetImage returns a pointer to one of the following
* structures, which is used as a token by clients (widgets) that
* display images.
*/
typedef struct Image {
* "re-get" the image later if the manager
* changes). */
* the image is eventually freed tkwin may
* not exist anymore. */
/* Master for this image (identifiers image
* manager, for example). */
/* One word argument to pass to image manager
* when dealing with this image instance. */
/* Code in widget to call when image changes
* in a way that affects redisplay. */
/* Argument to pass to changeProc. */
* associated with the same name. */
} Image;
/*
* For each image master there is one of the following structures,
* which represents a name in the image table and all of the images
* instantiated from it. Entries in mainPtr->imageTable point to
* these structures.
*/
typedef struct ImageMaster {
* that no image manager owns this image: the
* image was deleted. */
* when dealing with the master, as opposed
* to instances. */
* (the imageTable field in some TkMainInfo
* structure). */
* this structure (used to delete the hash
* entry). */
* derived from this name. */
} ImageMaster;
/*
* The following variable points to the first in a list of all known
* image types.
*/
/*
* Prototypes for local procedures:
*/
/*
*----------------------------------------------------------------------
*
* Tk_CreateImageType --
*
* This procedure is invoked by an image manager to tell Tk about
* a new kind of image and the procedures that manage the new type.
* The procedure is typically invoked during Tcl_AppInit.
*
* Results:
* None.
*
* Side effects:
* The new image type is entered into a table used in the "image
* create" command.
*
*----------------------------------------------------------------------
*/
void
* the fields except "nextPtr" must be filled
* in by caller. Must not have been passed
* to Tk_CreateImageType previously. */
{
}
/*
*----------------------------------------------------------------------
*
* Tk_ImageCmd --
*
* This procedure is invoked to process the "image" Tcl command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
static int id = 0;
if (argc < 2) {
" option ?args?\"", (char *) NULL);
return TCL_ERROR;
}
c = argv[1][0];
if (argc < 3) {
" create type ?name? ?options?\"", (char *) NULL);
return TCL_ERROR;
}
c = argv[2][0];
/*
* Look up the image type.
*/
break;
}
}
"\" doesn't exist", (char *) NULL);
return TCL_ERROR;
}
/*
* Figure out a name to use for the new image.
*/
id++;
firstOption = 3;
} else {
firstOption = 4;
}
/*
* Create the data structure for the new image.
*/
if (new) {
} else {
/*
* An image already exists by this name. Disconnect the
* instances from the master.
*/
}
}
}
/*
* Call the image type manager so that it can perform its own
* initialization, then re-"get" for any existing instances of
* the image.
*/
return TCL_ERROR;
}
}
for (i = 2; i < argc; i++) {
"\" doesn't exist", (char *) NULL);
return TCL_ERROR;
}
}
if (argc != 3) {
" height name\"", (char *) NULL);
return TCL_ERROR;
}
"\" doesn't exist", (char *) NULL);
return TCL_ERROR;
}
if (argc != 2) {
" names\"", (char *) NULL);
return TCL_ERROR;
}
}
if (argc != 3) {
" type name\"", (char *) NULL);
return TCL_ERROR;
}
"\" doesn't exist", (char *) NULL);
return TCL_ERROR;
}
}
if (argc != 2) {
" types\"", (char *) NULL);
return TCL_ERROR;
}
}
if (argc != 3) {
" width name\"", (char *) NULL);
return TCL_ERROR;
}
"\" doesn't exist", (char *) NULL);
return TCL_ERROR;
}
} else {
"\": must be create, delete, height, names, type, types,",
" or width", (char *) NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Tk_ImageChanged --
*
* This procedure is called by an image manager whenever something
* has happened that requires the image to be redrawn (some of its
* pixels have changed, or its size has changed).
*
* Results:
* None.
*
* Side effects:
* Any widgets that display the image are notified so that they
* can redisplay themselves as appropriate.
*
*----------------------------------------------------------------------
*/
void
int x, y; /* Coordinates of upper-left pixel of
* region of image that needs to be
* redrawn. */
* image to redraw. If either dimension
* is zero then the image doesn't need to
* be redrawn (perhaps all that happened is
* that its size changed). */
{
}
}
/*
*----------------------------------------------------------------------
*
* Tk_NameOfImage --
*
* Given a token for an image master, this procedure returns
* the name of the image.
*
* Results:
* The return value is the string name for imageMaster.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
char *
{
}
/*
*----------------------------------------------------------------------
*
* Tk_GetImage --
*
* This procedure is invoked by a widget when it wants to use
* a particular image in a particular window.
*
* Results:
* The return value is a token for the image. If there is no image
* by the given name, then NULL is returned and an error message is
* left in interp->result.
*
* Side effects:
* Tk records the fact that the widget is using the image, and
* it will invoke changeProc later if the widget needs redisplay
* (i.e. its size changes or some of its pixels change). The
* caller must eventually invoke Tk_FreeImage when it no longer
* needs the image.
*
*----------------------------------------------------------------------
*/
* can't be found. */
* be used. */
char *name; /* Name of desired image. */
/* Procedure to invoke when redisplay is
* needed because image's pixels or size
* changed. */
{
goto noSuchImage;
}
goto noSuchImage;
}
(char *) NULL);
return NULL;
}
/*
*----------------------------------------------------------------------
*
* Tk_FreeImage --
*
* This procedure is invoked by a widget when it no longer needs
* an image acquired by a previous call to Tk_GetImage. For each
* call to Tk_GetImage there must be exactly one call to Tk_FreeImage.
*
* Results:
* None.
*
* Side effects:
* The association between the image and the widget is removed.
*
*----------------------------------------------------------------------
*/
void
* needed by a widget. */
{
/*
* Clean up the particular instance.
*/
}
} else {
}
}
/*
* If there are no more instances left for the master, and if the
* master image has been deleted, then delete the master too.
*/
}
}
/*
*----------------------------------------------------------------------
*
* Tk_RedrawImage --
*
* This procedure is called by widgets that contain images in order
* to redisplay an image on the screen or an off-screen pixmap.
*
* Results:
* None.
*
* Side effects:
* The image's manager is notified, and it redraws the desired
* portion of the image before returning.
*
*----------------------------------------------------------------------
*/
void
* needs to be redisplayed. */
* (window or pixmap). If this is a pixmap,
* it must have the same depth as the window
* used in the Tk_GetImage call for the
* image. */
* to imageX and imageY. */
{
/*
* No master for image, so nothing to display.
*/
return;
}
/*
* Clip the redraw area to the area of the image.
*/
if (imageX < 0) {
imageX = 0;
}
if (imageY < 0) {
imageY = 0;
}
}
}
}
/*
*----------------------------------------------------------------------
*
* Tk_SizeOfImage --
*
* This procedure returns the current dimensions of an image.
*
* Results:
* The width and height of the image are returned in *widthPtr
* and *heightPtr.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
int *widthPtr; /* Return width of image here. */
int *heightPtr; /* Return height of image here. */
{
}
/*
*----------------------------------------------------------------------
*
* Tk_DeleteImage --
*
* Given the name of an image, this procedure destroys the
* image.
*
* Results:
* None.
*
* Side effects:
* The image is destroyed; existing instances will display as
* blank areas. If no such image exists then the procedure does
* nothing.
*
*----------------------------------------------------------------------
*/
void
* created. */
char *name; /* Name of image. */
{
return;
}
return;
}
}
/*
*----------------------------------------------------------------------
*
* DeleteImage --
*
* This procedure is responsible for deleting an image.
*
* Results:
* None.
*
* Side effects:
* The connection is dropped between instances of this image and
* an image master. Image instances will redisplay themselves
* as empty areas, but existing instances will not be deleted.
*
*----------------------------------------------------------------------
*/
static void
{
}
}
}
}
/*
*----------------------------------------------------------------------
*
* TkDeleteAllImages --
*
* This procedure is called when an application is deleted. It
* calls back all of the managers for all images so that they
* can cleanup, then it deletes all of Tk's internal information
* about images.
*
* Results:
* None.
*
* Side effects:
* All information for all images gets deleted.
*
*----------------------------------------------------------------------
*/
void
* going away. */
{
}
}