]>
git.zerfleddert.de Git - micropolis/blob - src/tk/tkatom.c
d62fedd1fcb68470356e5a2c4bbc8fdd790cee13
4 * This file manages a cache of X Atoms in order to avoid
5 * interactions with the X server. It's much like the Xmu
6 * routines, except it has a cleaner interface (caller
7 * doesn't have to provide permanent storage for atom names,
10 * Copyright 1990 Regents of the University of California.
11 * Permission to use, copy, modify, and distribute this
12 * software and its documentation for any purpose and without
13 * fee is hereby granted, provided that the above copyright
14 * notice appear in all copies. The University of California
15 * makes no representations about the suitability of this
16 * software for any purpose. It is provided "as is" without
17 * express or implied warranty.
21 static char rcsid
[] = "$Header: /user6/ouster/wish/RCS/tkAtom.c,v 1.6 92/05/07 09:51:06 ouster Exp $ SPRITE (Berkeley)";
28 * Forward references to procedures defined in this file:
31 static void AtomInit
_ANSI_ARGS_((TkDisplay
*dispPtr
));
34 *--------------------------------------------------------------
38 * Given a string, produce the equivalent X atom. This
39 * procedure is equivalent to XInternAtom, except that it
40 * keeps a local cache of atoms. Once a name is known,
41 * the server need not be contacted again for that name.
44 * The return value is the Atom corresponding to name.
47 * A new entry may be added to the local atom cache.
49 *--------------------------------------------------------------
53 Tk_InternAtom(tkwin
, name
)
54 Tk_Window tkwin
; /* Window token; map name to atom
55 * for this window's display. */
56 char *name
; /* Name to turn into atom. */
58 register TkDisplay
*dispPtr
;
59 register Tcl_HashEntry
*hPtr
;
62 dispPtr
= ((TkWindow
*) tkwin
)->dispPtr
;
63 if (!dispPtr
->atomInit
) {
67 hPtr
= Tcl_CreateHashEntry(&dispPtr
->nameTable
, name
, &new);
72 atom
= XInternAtom(dispPtr
->display
, name
, False
);
73 Tcl_SetHashValue(hPtr
, atom
);
74 hPtr2
= Tcl_CreateHashEntry(&dispPtr
->atomTable
, (char *) atom
,
76 Tcl_SetHashValue(hPtr2
, Tcl_GetHashKey(&dispPtr
->nameTable
, hPtr
));
78 return (Atom
) Tcl_GetHashValue(hPtr
);
82 *--------------------------------------------------------------
86 * This procedure is equivalent to XGetAtomName except that
87 * it uses the local atom cache to avoid contacting the
91 * The return value is a character string corresponding to
92 * the atom given by "atom". This string's storage space
93 * is static: it need not be freed by the caller, and should
94 * not be modified by the caller. If "atom" doesn't exist
95 * on tkwin's display, then the string "?bad atom?" is returned.
100 *--------------------------------------------------------------
104 Tk_GetAtomName(tkwin
, atom
)
105 Tk_Window tkwin
; /* Window token; map atom to name
106 * relative to this window's
108 Atom atom
; /* Atom whose name is wanted. */
110 register TkDisplay
*dispPtr
;
111 register Tcl_HashEntry
*hPtr
;
113 dispPtr
= ((TkWindow
*) tkwin
)->dispPtr
;
114 if (!dispPtr
->atomInit
) {
118 hPtr
= Tcl_FindHashEntry(&dispPtr
->atomTable
, (char *) atom
);
121 Tk_ErrorHandler handler
;
124 handler
= Tk_CreateErrorHandler(dispPtr
->display
, BadAtom
,
125 -1, -1, (int (*)()) NULL
, (ClientData
) NULL
);
126 name
= XGetAtomName(dispPtr
->display
, atom
);
130 Tk_DeleteErrorHandler(handler
);
131 hPtr
= Tcl_CreateHashEntry(&dispPtr
->nameTable
, (char *) name
,
133 Tcl_SetHashValue(hPtr
, atom
);
134 name
= Tcl_GetHashKey(&dispPtr
->nameTable
, hPtr
);
135 hPtr
= Tcl_CreateHashEntry(&dispPtr
->atomTable
, (char *) atom
,
137 Tcl_SetHashValue(hPtr
, name
);
139 return (char *) Tcl_GetHashValue(hPtr
);
143 *--------------------------------------------------------------
147 * Initialize atom-related information for a display.
153 * Tables get initialized, etc. etc..
155 *--------------------------------------------------------------
160 register TkDisplay
*dispPtr
; /* Display to initialize. */
162 dispPtr
->atomInit
= 1;
163 Tcl_InitHashTable(&dispPtr
->nameTable
, TCL_STRING_KEYS
);
164 Tcl_InitHashTable(&dispPtr
->atomTable
, TCL_ONE_WORD_KEYS
);