/*
* tkImgBmap.c --
*
* This procedure implements images of type "bitmap" for Tk.
*
* 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: @(#) tkImgBmap.c 1.28 96/07/31 16:45:26
*/
#include "tkInt.h"
/*
* The following data structure represents the master for a bitmap
* image:
*/
typedef struct BitmapMaster {
* the image is being deleted. */
* using image. */
* it when the image goes away). NULL means
* the image command has already been
* deleted. */
* input to XCreateBitmapFromData). May
* be NULL if no data. Malloc'ed. */
* input to XCreateBitmapFromData).
* Malloc'ed. */
/* First in list of all instances associated
* with this master. */
} BitmapMaster;
/*
* The following data structure represents all of the instances of an
* image that lie within a particular window:
*/
typedef struct BitmapInstance {
* data structure. */
* displayed. */
* there are 1's here. */
* None means there was an error while
* setting up the instance, so it cannot
* be displayed. */
/* Next in list of all instance structures
* associated with masterPtr (NULL means
* end of list). */
/*
* The type record for bitmap images:
*/
"bitmap", /* name */
ImgBmapCreate, /* createProc */
ImgBmapGet, /* getProc */
ImgBmapDisplay, /* displayProc */
ImgBmapFree, /* freeProc */
ImgBmapDelete, /* deleteProc */
};
/*
* Information used for parsing configuration specs:
*/
(char *) NULL, 0, 0}
};
/*
* The following data structure is used to describe the state of
* parsing a bitmap file or string. It is used for communication
* between TkGetBitmapData and NextBitmapWord.
*/
typedef struct ParseInfo {
* or NULL if bitmap is being read from
* file. */
FILE *f; /* File containing bitmap data, or NULL
* if no file. */
/* Current word of bitmap data, NULL
* terminated. */
} ParseInfo;
/*
* Prototypes for procedures used only locally in this file:
*/
static void ImgBmapCmdDeletedProc _ANSI_ARGS_((
static void ImgBmapConfigureInstance _ANSI_ARGS_((
static int ImgBmapConfigureMaster _ANSI_ARGS_((
int flags));
/*
*----------------------------------------------------------------------
*
* ImgBmapCreate --
*
* This procedure is called by the Tk image code to create "test"
* images.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* The data structure for a new image is allocated.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
static int
* image. */
char *name; /* Name to use for image. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings for options (doesn't
* include image name or type). */
* later callbacks. */
* it will be returned in later callbacks. */
{
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* ImgBmapConfigureMaster --
*
* This procedure is called when a bitmap image is created or
* reconfigured. It process configuration options and resets
* any instances of the image.
*
* Results:
* A standard Tcl return value. If TCL_ERROR is returned then
* an error message is left in masterPtr->interp->result.
*
* Side effects:
* Existing instances of the image will be redisplayed to match
* the new configuration options.
*
*----------------------------------------------------------------------
*/
static int
* overall bitmap image to (reconfigure). */
int argc; /* Number of entries in argv. */
char **argv; /* Pairs of configuration options for image. */
int flags; /* Flags to pass to Tk_ConfigureWidget,
* such as TK_CONFIG_ARGV_ONLY. */
{
!= TCL_OK) {
return TCL_ERROR;
}
/*
* the bitmap and mask have the same dimensions.
*/
}
return TCL_ERROR;
}
}
}
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_ERROR;
}
}
/*
* Cycle through all of the instances of this image, regenerating
* the information for each instance. Then force the image to be
* redisplayed everywhere that it is used.
*/
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* ImgBmapConfigureInstance --
*
* This procedure is called to create displaying information for
* a bitmap image instance based on the configuration information
* in the master. It is invoked both when new instances are
* created and when the master is reconfigured.
*
* Results:
* None.
*
* Side effects:
* Generates errors via Tcl_BackgroundError if there are problems
* in setting up the instance.
*
*----------------------------------------------------------------------
*/
static void
{
unsigned int mask;
/*
* For each of the options in masterPtr, translate the string
* form into an internal form appropriate for instancePtr.
*/
goto error;
}
} else {
}
}
goto error;
}
}
}
}
}
}
mask |= GCBackground;
mask |= GCClipMask;
}
} else {
mask |= GCClipMask;
}
} else {
}
}
return;
/*
* An error occurred: clear the graphics context in the instance to
* make it clear that this instance cannot be displayed. Then report
* the error.
*/
}
}
/*
*----------------------------------------------------------------------
*
* TkGetBitmapData --
*
* Given a file name or ASCII string, this procedure parses the
* file or string contents to produce binary data for a bitmap.
*
* Results:
* If the bitmap description was parsed successfully then the
* return value is a malloc-ed array containing the bitmap data.
* The dimensions of the data are stored in *widthPtr and
* *heightPtr. *hotXPtr and *hotYPtr are set to the bitmap
* hotspot if one is defined, otherwise they are set to -1, -1.
* If an error occurred, NULL is returned and an error message is
* left in interp->result.
*
* Side effects:
* A bitmap is created.
*
*----------------------------------------------------------------------
*/
char *
char *string; /* String describing bitmap. May
* be NULL. */
char *fileName; /* Name of file containing bitmap
* description. Used only if string
* is NULL. Must not be NULL if
* string is NULL. */
* here. */
{
if (expandedFileName == NULL) {
return NULL;
}
return NULL;
}
} else {
}
/*
* Parse the lines that define the dimensions of the bitmap,
* plus the first line that defines the bitmap data (it declares
* the name of a data variable but doesn't include any actual
* data). These lines look something like the following:
*
* #define foo_width 16
* #define foo_height 16
* #define foo_x_hot 3
* #define foo_y_hot 3
* static char foo_bits[] = {
*
* The x_hot and y_hot lines may or may not be present. It's
* important to check for "char" in the last line, in order to
* reject old X10-style bitmaps that used shorts.
*/
width = 0;
height = 0;
hotX = -1;
hotY = -1;
while (1) {
goto error;
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
goto error;
}
while (1) {
goto error;
}
goto getData;
}
}
"looks like it's an obsolete X10 bitmap file",
(char *) NULL);
goto errorCleanup;
}
}
/*
* Now we've read everything but the data. Allocate an array
* and read in the data.
*/
goto error;
}
goto error;
}
goto error;
}
}
/*
* All done. Clean up and return.
*/
}
return data;
}
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
* NextBitmapWord --
*
* This procedure retrieves the next word of information (stuff
* between commas or white space) from a bitmap description.
*
* Results:
* Returns TCL_OK if all went well. In this case the next word,
* and its length, will be availble in *parseInfoPtr. If the end
* of the bitmap description was reached then TCL_ERROR is returned.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
* and where we are in it. */
{
int c;
parseInfoPtr->wordLength = 0;
src++) {
if (*src == 0) {
return TCL_ERROR;
}
}
dst++;
return TCL_ERROR;
}
}
} else {
c = getc(parseInfoPtr->f)) {
if (c == EOF) {
return TCL_ERROR;
}
}
c = getc(parseInfoPtr->f)) {
*dst = c;
dst++;
return TCL_ERROR;
}
}
}
if (parseInfoPtr->wordLength == 0) {
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ImgBmapCmd --
*
* This procedure is invoked to process the Tcl command
* that corresponds to an image 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. */
{
int c, code;
if (argc < 2) {
"wrong # args: should be \"%.50s option ?arg arg ...?\"",
argv[0]);
return TCL_ERROR;
}
c = argv[1][0];
&& (length >= 2)) {
if (argc != 3) {
argv[0], " cget option\"",
(char *) NULL);
return TCL_ERROR;
}
&& (length >= 2)) {
if (argc == 2) {
} else if (argc == 3) {
} else {
}
return code;
} else {
"\": must be cget or configure", (char *) NULL);
return TCL_ERROR;
}
}
/*
*----------------------------------------------------------------------
*
* ImgBmapGet --
*
* This procedure is called for each use of a bitmap image in a
* widget.
*
* Results:
* The return value is a token for the instance, which is passed
* back to us in calls to ImgBmapDisplay and ImgBmapFree.
*
* Side effects:
* A data structure is set up for the instance (or, an existing
* instance is re-used for the new one).
*
*----------------------------------------------------------------------
*/
static ClientData
* used. */
* image. */
{
/*
* See if there is already an instance for this window. If so
* then just re-use it.
*/
instancePtr->refCount++;
return (ClientData) instancePtr;
}
}
/*
* The image isn't already in use in this window. Make a new
* instance of the image.
*/
/*
* If this is the first instance, must set the size of the image.
*/
}
return (ClientData) instancePtr;
}
/*
*----------------------------------------------------------------------
*
* ImgBmapDisplay --
*
* This procedure is invoked to draw a bitmap image.
*
* Results:
* None.
*
* Side effects:
* A portion of the image gets rendered in a pixmap or window.
*
*----------------------------------------------------------------------
*/
static void
* for instance to be displayed. */
* to draw. */
* correspond to imageX and imageY. */
{
int masking;
/*
* If there's no graphics context, it means that an error occurred
* while creating the image instance so it can't be displayed.
*/
return;
}
/*
* If masking is in effect, must modify the mask origin within
* the graphics context to line up with the image's origin.
* Then draw the image and reset the clip origin, if there's
* a mask.
*/
if (masking) {
}
if (masking) {
}
}
/*
*----------------------------------------------------------------------
*
* ImgBmapFree --
*
* This procedure is called when a widget ceases to use a
* particular instance of an image.
*
* Results:
* None.
*
* Side effects:
* Internal data structures get cleaned up.
*
*----------------------------------------------------------------------
*/
static void
* for instance to be displayed. */
{
instancePtr->refCount--;
if (instancePtr->refCount > 0) {
return;
}
/*
* There are no more uses of the image within this widget. Free
* the instance structure.
*/
}
}
}
}
}
} else {
/* Empty loop body */
}
}
ckfree((char *) instancePtr);
}
/*
*----------------------------------------------------------------------
*
* ImgBmapDelete --
*
* This procedure is called by the image code to delete the
* master structure for an image.
*
* Results:
* None.
*
* Side effects:
* Resources associated with the image get freed.
*
*----------------------------------------------------------------------
*/
static void
* image. Must not have any more instances. */
{
panic("tried to delete bitmap image when instances still exist");
}
}
}
}
}
/*
*----------------------------------------------------------------------
*
* ImgBmapCmdDeletedProc --
*
* This procedure is invoked when the image command for an image
* is deleted. It deletes the image.
*
* Results:
* None.
*
* Side effects:
* The image is deleted.
*
*----------------------------------------------------------------------
*/
static void
* image. */
{
}
}