/*
* tkCursor.c --
*
* This file maintains a database of read-only cursors for the Tk
* toolkit. This allows cursors to be shared between widgets and
* also avoids round-trips to 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: @(#) tkCursor.c 1.27 96/02/15 18:52:40
*/
#include "tkInt.h"
/*
* A TkCursor structure exists for each cursor that is currently
* active. Each structure is indexed with two hash tables defined
* below. One of the tables is idTable, and the other is either
* nameTable or dataTable, also defined below.
*/
/*
* Hash table to map from a textual description of a cursor to the
* TkCursor record for the cursor, and key structure used in that
* hash table:
*/
typedef struct {
} NameKey;
/*
* Hash table to map from a collection of in-core data about a
* cursor (bitmap contents, etc.) to a TkCursor structure:
*/
typedef struct {
* and mask). */
} DataKey;
/*
* Hash table that maps from <display + cursor id> to the TkCursor structure
* for the cursor. This table is used by Tk_FreeCursor.
*/
typedef struct {
} IdKey;
* initialized yet. */
/*
* Forward declarations for procedures defined in this file:
*/
static void CursorInit _ANSI_ARGS_((void));
/*
*----------------------------------------------------------------------
*
* Tk_GetCursor --
*
* Given a string describing a cursor, locate (or create if necessary)
* a cursor that fits the description.
*
* Results:
* The return value is the X identifer for the desired cursor,
* 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 cursor that is returned, and
* should eventually call Tk_FreeCursor when the cursor is no longer
* needed.
*
* Side effects:
* The cursor is added to an internal database with a reference count.
* For each call to this procedure, there should eventually be a call
* to Tk_FreeCursor, so that the database can be cleaned up when cursors
* aren't needed anymore.
*
*----------------------------------------------------------------------
*/
* for details on legal syntax. */
{
int new;
if (!initialized) {
CursorInit();
}
if (!new) {
}
return None;
}
/*
* Add information about this cursor to our database.
*/
if (!new) {
panic("cursor already registered in Tk_GetCursor");
}
}
/*
*----------------------------------------------------------------------
*
* Tk_GetCursorFromData --
*
* Given a description of the bits and colors for a cursor,
* make a cursor that has the given properties.
*
* Results:
* The return value is the X identifer for the desired cursor,
* 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 cursor that is returned, and
* should eventually call Tk_FreeCursor when the cursor is no
* longer needed.
*
* Side effects:
* The cursor is added to an internal database with a reference count.
* For each call to this procedure, there should eventually be a call
* to Tk_FreeCursor, so that the database can be cleaned up when cursors
* aren't needed anymore.
*
*----------------------------------------------------------------------
*/
char *source; /* Bitmap data for cursor shape. */
char *mask; /* Bitmap data for cursor mask. */
{
int new;
if (!initialized) {
CursorInit();
}
if (!new) {
}
/*
* No suitable cursor exists yet. Make one using the data
* available and add it to the database.
*/
(char *) NULL);
goto error;
}
(char *) NULL);
goto error;
}
goto error;
}
if (!new) {
panic("cursor already registered in Tk_GetCursorFromData");
}
return None;
}
/*
*--------------------------------------------------------------
*
* Tk_NameOfCursor --
*
* Given a cursor, return a textual string identifying it.
*
* Results:
* If cursor was created by Tk_GetCursor, then the return
* value is the "string" that was used to create it.
* Otherwise the return value is a string giving the X
* identifier for the cursor. The storage for the returned
* string is only guaranteed to persist up until the next
* call to this procedure.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
char *
* wanted. */
{
void *ptr;
if (!initialized) {
return string;
}
goto printid;
}
goto printid;
}
}
/*
*----------------------------------------------------------------------
*
* Tk_FreeCursor --
*
* This procedure is called to release a cursor allocated by
* Tk_GetCursor or TkGetCursorFromData.
*
* Results:
* None.
*
* Side effects:
* The reference count associated with cursor is decremented, and
* it is officially deallocated if no-one is using it anymore.
*
*----------------------------------------------------------------------
*/
void
{
if (!initialized) {
panic("Tk_FreeCursor called before Tk_GetCursor");
}
panic("Tk_FreeCursor received unknown cursor argument");
}
}
}
/*
*----------------------------------------------------------------------
*
* CursorInit --
*
* Initialize the structures used for cursor management.
*
* Results:
* None.
*
* Side effects:
* Read the code.
*
*----------------------------------------------------------------------
*/
static void
{
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));
}