1/*
2 * tkColor.h --
3 *
4 *	Declarations of data types and functions used by the Tk color module.
5 *
6 * Copyright (c) 1996-1997 by Sun Microsystems, Inc.
7 *
8 * See the file "license.terms" for information on usage and redistribution of
9 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 *
11 * RCS: @(#) $Id$
12 */
13
14#ifndef _TKCOLOR
15#define _TKCOLOR
16
17#include <tkInt.h>
18
19#ifdef BUILD_tk
20#undef TCL_STORAGE_CLASS
21#define TCL_STORAGE_CLASS DLLEXPORT
22#endif
23
24/*
25 * One of the following data structures is used to keep track of each color
26 * that is being used by the application; typically there is a colormap entry
27 * allocated for each of these colors.
28 */
29
30#define TK_COLOR_BY_NAME	1
31#define TK_COLOR_BY_VALUE	2
32
33#define COLOR_MAGIC ((unsigned int) 0x46140277)
34
35typedef struct TkColor {
36    XColor color;		/* Information about this color. */
37    unsigned int magic;		/* Used for quick integrity check on this
38				 * structure. Must always have the value
39				 * COLOR_MAGIC. */
40    GC gc;			/* Simple gc with this color as foreground
41				 * color and all other fields defaulted. May
42				 * be None. */
43    Screen *screen;		/* Screen where this color is valid. Used to
44				 * delete it, and to find its display. */
45    Colormap colormap;		/* Colormap from which this entry was
46				 * allocated. */
47    Visual *visual;		/* Visual associated with colormap. */
48    int resourceRefCount;	/* Number of active uses of this color (each
49				 * active use corresponds to a call to
50				 * Tk_AllocColorFromObj or Tk_GetColor). If
51				 * this count is 0, then this TkColor
52				 * structure is no longer valid and it isn't
53				 * present in a hash table: it is being kept
54				 * around only because there are objects
55				 * referring to it. The structure is freed
56				 * when resourceRefCount and objRefCount are
57				 * both 0. */
58    int objRefCount;		/* The number of Tcl objects that reference
59				 * this structure. */
60    int type;			/* TK_COLOR_BY_NAME or TK_COLOR_BY_VALUE. */
61    Tcl_HashEntry *hashPtr;	/* Pointer to hash table entry for this
62				 * structure. (for use in deleting entry). */
63    struct TkColor *nextPtr;	/* Points to the next TkColor structure with
64				 * the same color name. Colors with the same
65				 * name but different screens or colormaps are
66				 * chained together off a single entry in
67				 * nameTable. For colors in valueTable (those
68				 * allocated by Tk_GetColorByValue) this field
69				 * is always NULL. */
70} TkColor;
71
72/*
73 * Common APIs exported from all platform-specific implementations.
74 */
75
76#ifndef TkpFreeColor
77MODULE_SCOPE void	TkpFreeColor(TkColor *tkColPtr);
78#endif
79MODULE_SCOPE TkColor *	TkpGetColor(Tk_Window tkwin, Tk_Uid name);
80MODULE_SCOPE TkColor *	TkpGetColorByValue(Tk_Window tkwin, XColor *colorPtr);
81
82#undef TCL_STORAGE_CLASS
83#define TCL_STORAGE_CLASS DLLIMPORT
84
85#endif /* _TKCOLOR */
86