]>
cvs.zerfleddert.de Git - micropolis/blob - src/tk/tkatom.c
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 *--------------------------------------------------------------
54 Tk_Window tkwin
, /* Window token; map name to atom
55 * for this window's display. */
56 char *name
/* Name to turn into atom. */
59 register TkDisplay
*dispPtr
;
60 register Tcl_HashEntry
*hPtr
;
63 dispPtr
= ((TkWindow
*) tkwin
)->dispPtr
;
64 if (!dispPtr
->atomInit
) {
68 hPtr
= Tcl_CreateHashEntry(&dispPtr
->nameTable
, name
, &new);
73 atom
= XInternAtom(dispPtr
->display
, name
, False
);
74 Tcl_SetHashValue(hPtr
, atom
);
75 hPtr2
= Tcl_CreateHashEntry(&dispPtr
->atomTable
, (char *) atom
,
77 Tcl_SetHashValue(hPtr2
, Tcl_GetHashKey(&dispPtr
->nameTable
, hPtr
));
79 return (Atom
) Tcl_GetHashValue(hPtr
);
83 *--------------------------------------------------------------
87 * This procedure is equivalent to XGetAtomName except that
88 * it uses the local atom cache to avoid contacting the
92 * The return value is a character string corresponding to
93 * the atom given by "atom". This string's storage space
94 * is static: it need not be freed by the caller, and should
95 * not be modified by the caller. If "atom" doesn't exist
96 * on tkwin's display, then the string "?bad atom?" is returned.
101 *--------------------------------------------------------------
106 Tk_Window tkwin
, /* Window token; map atom to name
107 * relative to this window's
109 Atom atom
/* Atom whose name is wanted. */
112 register TkDisplay
*dispPtr
;
113 register Tcl_HashEntry
*hPtr
;
115 dispPtr
= ((TkWindow
*) tkwin
)->dispPtr
;
116 if (!dispPtr
->atomInit
) {
120 hPtr
= Tcl_FindHashEntry(&dispPtr
->atomTable
, (char *) atom
);
123 Tk_ErrorHandler handler
;
126 handler
= Tk_CreateErrorHandler(dispPtr
->display
, BadAtom
,
127 -1, -1, (int (*)(int *, XErrorEvent
*)) NULL
, (ClientData
) NULL
);
128 name
= XGetAtomName(dispPtr
->display
, atom
);
132 Tk_DeleteErrorHandler(handler
);
133 hPtr
= Tcl_CreateHashEntry(&dispPtr
->nameTable
, (char *) name
,
135 Tcl_SetHashValue(hPtr
, atom
);
136 name
= Tcl_GetHashKey(&dispPtr
->nameTable
, hPtr
);
137 hPtr
= Tcl_CreateHashEntry(&dispPtr
->atomTable
, (char *) atom
,
139 Tcl_SetHashValue(hPtr
, name
);
141 return (char *) Tcl_GetHashValue(hPtr
);
145 *--------------------------------------------------------------
149 * Initialize atom-related information for a display.
155 * Tables get initialized, etc. etc..
157 *--------------------------------------------------------------
162 register TkDisplay
*dispPtr
/* Display to initialize. */
165 dispPtr
->atomInit
= 1;
166 Tcl_InitHashTable(&dispPtr
->nameTable
, TCL_STRING_KEYS
);
167 Tcl_InitHashTable(&dispPtr
->atomTable
, TCL_ONE_WORD_KEYS
);