/*
* tkBitmap.c --
*
* This file maintains a database of read-only bitmaps for the Tk
* toolkit. This allows bitmaps to be shared between widgets and
* also avoids interactions with the X server.
*
* Copyright (c) 1990-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: @(#) tkBitmap.c 1.37 96/07/23 16:54:40
*/
#include "tkInt.h"
/*
* The includes below are for pre-defined bitmaps.
*/
#include "error.bmp"
#include "gray12.bmp"
#include "gray25.bmp"
#include "gray50.bmp"
#include "hourglass.bmp"
#include "info.bmp"
#include "questhead.bmp"
#include "question.bmp"
#include "warning.bmp"
/*
* One of the following data structures exists for each bitmap that is
* currently in use. Each structure is indexed with both "idTable" and
* "nameTable".
*/
typedef struct {
* bitmap was created by Tk_DefineBitmap
* and it isn't currently in use. */
* (needed when deleting). */
} TkBitmap;
/*
* Hash table to map from a textual description of a bitmap to the
* TkBitmap record for the bitmap, and key structure used in that
* hash table:
*/
typedef struct {
} NameKey;
/*
* Hash table that maps from <display + bitmap id> to the TkBitmap structure
* for the bitmap. This table is used by Tk_FreeBitmap.
*/
typedef struct {
} IdKey;
/*
* For each call to Tk_DefineBitmap one of the following structures is
* created to hold information about the bitmap.
*/
typedef struct {
} PredefBitmap;
/*
* Hash table create by Tk_DefineBitmap to map from a name to a
* collection of in-core data about a bitmap. The table is
* indexed by the address of the data for the bitmap, and the entries
* contain pointers to PredefBitmap structures.
*/
/*
* Hash table used by Tk_GetBitmapFromData to map from a collection
* of in-core data about a bitmap to a Tk_Uid giving an automatically-
* generated name for the bitmap:
*/
typedef struct {
} DataKey;
* initialized yet. */
/*
* Forward declarations for procedures defined in this file:
*/
static void BitmapInit _ANSI_ARGS_((void));
/*
*----------------------------------------------------------------------
*
* Tk_GetBitmap --
*
* Given a string describing a bitmap, locate (or create if necessary)
* a bitmap that fits the description.
*
* Results:
* The return value is the X identifer for the desired bitmap
* (i.e. a Pixmap with a single plane), unless string couldn't be
* parsed correctly. In this case, None is returned and an error
* message is left in interp->result. The caller should never
* modify the bitmap that is returned, and should eventually call
* Tk_FreeBitmap when the bitmap is no longer needed.
*
* Side effects:
* The bitmap is added to an internal database with a reference count.
* For each call to this procedure, there should eventually be a call
* to Tk_FreeBitmap, so that the database can be cleaned up when bitmaps
* aren't needed anymore.
*
*----------------------------------------------------------------------
*/
* for details on legal syntax. */
{
int new;
int dummy2;
if (!initialized) {
BitmapInit();
}
if (!new) {
}
/*
* No suitable bitmap exists. Create a new bitmap from the
* information contained in the string. If the string starts
* with "@" then the rest of the string is a file name containing
* the bitmap. Otherwise the string must refer to a bitmap
* defined by a call to Tk_DefineBitmap.
*/
if (*string == '@') {
int result;
goto error;
}
if (result != BitmapSuccess) {
"\"", (char *) NULL);
goto error;
}
} else {
if (predefHashPtr == NULL) {
/*
* The check for a NULL interpreter is a special hack that
* allows this procedure to be called from GetShadows in
* tk3d.c, where it doesn't have an intepreter handle.
*/
"\" not defined", (char *) NULL);
}
goto error;
}
}
/*
* Add information about this bitmap to our database.
*/
&new);
if (!new) {
panic("bitmap already registered in Tk_GetBitmap");
}
return None;
}
/*
*----------------------------------------------------------------------
*
* Tk_DefineBitmap --
*
* This procedure associates a textual name with a binary bitmap
* description, so that the name may be used to refer to the
* bitmap in future calls to Tk_GetBitmap.
*
* Results:
* A standard Tcl result. If an error occurs then TCL_ERROR is
* returned and a message is left in interp->result.
*
* Side effects:
* "Name" is entered into the bitmap table and may be used from
* here on to refer to the given bitmap.
*
*----------------------------------------------------------------------
*/
int
* be defined as a bitmap. */
char *source; /* Address of bits for bitmap. */
int width; /* Width of bitmap. */
int height; /* Height of bitmap. */
{
int new;
if (!initialized) {
BitmapInit();
}
if (!new) {
"\" is already defined", (char *) NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* Tk_NameOfBitmap --
*
* Given a bitmap, return a textual string identifying the
* bitmap.
*
* Results:
* The return value is the string name associated with bitmap.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
* allocated. */
{
void *ptr;
if (!initialized) {
panic("Tk_NameOfBitmap received unknown bitmap argument");
}
goto unknown;
}
}
/*
*--------------------------------------------------------------
*
* Tk_SizeOfBitmap --
*
* Given a bitmap managed by this module, returns the width
* and height of the bitmap.
*
* Results:
* The words at *widthPtr and *heightPtr are filled in with
* the dimenstions of bitmap.
*
* Side effects:
* If bitmap isn't managed by this module then the procedure
* panics..
*
*--------------------------------------------------------------
*/
void
* allocated. */
int *widthPtr; /* Store bitmap width here. */
int *heightPtr; /* Store bitmap height here. */
{
if (!initialized) {
panic("Tk_SizeOfBitmap received unknown bitmap argument");
}
goto unknownBitmap;
}
}
/*
*----------------------------------------------------------------------
*
* Tk_FreeBitmap --
*
* This procedure is called to release a bitmap allocated by
* Tk_GetBitmap or TkGetBitmapFromData.
*
* Results:
* None.
*
* Side effects:
* The reference count associated with bitmap is decremented, and
* it is officially deallocated if no-one is using it anymore.
*
*----------------------------------------------------------------------
*/
void
* allocated. */
{
if (!initialized) {
panic("Tk_FreeBitmap called before Tk_GetBitmap");
}
panic("Tk_FreeBitmap received unknown bitmap argument");
}
}
}
/*
*----------------------------------------------------------------------
*
* Tk_GetBitmapFromData --
*
* Given a description of the bits for a bitmap, make a bitmap that
* has the given properties. *** NOTE: this procedure is obsolete
* and really shouldn't be used anymore. ***
*
* Results:
* The return value is the X identifer for the desired bitmap
* (a one-plane Pixmap), unless it couldn't be created properly.
* In this case, None is returned and an error message is left in
* interp->result. The caller should never modify the bitmap that
* is returned, and should eventually call Tk_FreeBitmap when the
* bitmap is no longer needed.
*
* Side effects:
* The bitmap is added to an internal database with a reference count.
* For each call to this procedure, there should eventually be a call
* to Tk_FreeBitmap, so that the database can be cleaned up when bitmaps
* aren't needed anymore.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
char *source; /* Bitmap data for bitmap shape. */
{
* compiler warning. */
int new;
static int autoNumber = 0;
if (!initialized) {
BitmapInit();
}
if (!new) {
} else {
autoNumber++;
return TCL_ERROR;
}
}
}
/*
*----------------------------------------------------------------------
*
* BitmapInit --
*
* Initialize the structures used for bitmap management.
*
* Results:
* None.
*
* Side effects:
* Read the code.
*
*----------------------------------------------------------------------
*/
static void
{
dummy = Tcl_CreateInterp();
initialized = 1;
/*
* The call below is tricky: can't use sizeof(IdKey) because it
* gets padded with extra unpredictable bytes on some 64-bit
* machines.
*/
/sizeof(int));
}