Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libtk/generic/tkAtom.c
1810 views
1
/*
2
* tkAtom.c --
3
*
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,
8
* for example).
9
*
10
* Copyright (c) 1990-1994 The Regents of the University of California.
11
* Copyright (c) 1994 Sun Microsystems, Inc.
12
*
13
* See the file "license.terms" for information on usage and redistribution
14
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
*
16
* SCCS: @(#) tkAtom.c 1.13 96/02/15 18:51:34
17
*/
18
19
#include "tkInt.h"
20
21
/*
22
* The following are a list of the predefined atom strings.
23
* They should match those found in xatom.h
24
*/
25
26
static char * atomNameArray[] = {
27
"PRIMARY", "SECONDARY", "ARC",
28
"ATOM", "BITMAP", "CARDINAL",
29
"COLORMAP", "CURSOR", "CUT_BUFFER0",
30
"CUT_BUFFER1", "CUT_BUFFER2", "CUT_BUFFER3",
31
"CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6",
32
"CUT_BUFFER7", "DRAWABLE", "FONT",
33
"INTEGER", "PIXMAP", "POINT",
34
"RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP",
35
"RGB_BEST_MAP", "RGB_BLUE_MAP", "RGB_DEFAULT_MAP",
36
"RGB_GRAY_MAP", "RGB_GREEN_MAP", "RGB_RED_MAP",
37
"STRING", "VISUALID", "WINDOW",
38
"WM_COMMAND", "WM_HINTS", "WM_CLIENT_MACHINE",
39
"WM_ICON_NAME", "WM_ICON_SIZE", "WM_NAME",
40
"WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS",
41
"MIN_SPACE", "NORM_SPACE", "MAX_SPACE",
42
"END_SPACE", "SUPERSCRIPT_X", "SUPERSCRIPT_Y",
43
"SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION",
44
"UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT",
45
"ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH",
46
"WEIGHT", "POINT_SIZE", "RESOLUTION",
47
"COPYRIGHT", "NOTICE", "FONT_NAME",
48
"FAMILY_NAME", "FULL_NAME", "CAP_HEIGHT",
49
"WM_CLASS", "WM_TRANSIENT_FOR",
50
(char *) NULL
51
};
52
53
/*
54
* Forward references to procedures defined in this file:
55
*/
56
57
static void AtomInit _ANSI_ARGS_((TkDisplay *dispPtr));
58
59
/*
60
*--------------------------------------------------------------
61
*
62
* Tk_InternAtom --
63
*
64
* Given a string, produce the equivalent X atom. This
65
* procedure is equivalent to XInternAtom, except that it
66
* keeps a local cache of atoms. Once a name is known,
67
* the server need not be contacted again for that name.
68
*
69
* Results:
70
* The return value is the Atom corresponding to name.
71
*
72
* Side effects:
73
* A new entry may be added to the local atom cache.
74
*
75
*--------------------------------------------------------------
76
*/
77
78
Atom
79
Tk_InternAtom(tkwin, name)
80
Tk_Window tkwin; /* Window token; map name to atom
81
* for this window's display. */
82
char *name; /* Name to turn into atom. */
83
{
84
register TkDisplay *dispPtr;
85
register Tcl_HashEntry *hPtr;
86
int new;
87
88
dispPtr = ((TkWindow *) tkwin)->dispPtr;
89
if (!dispPtr->atomInit) {
90
AtomInit(dispPtr);
91
}
92
93
hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &new);
94
if (new) {
95
Tcl_HashEntry *hPtr2;
96
Atom atom;
97
98
atom = XInternAtom(dispPtr->display, name, False);
99
Tcl_SetHashValue(hPtr, atom);
100
hPtr2 = Tcl_CreateHashEntry(&dispPtr->atomTable, (char *) atom,
101
&new);
102
Tcl_SetHashValue(hPtr2, Tcl_GetHashKey(&dispPtr->nameTable, hPtr));
103
}
104
return (Atom) Tcl_GetHashValue(hPtr);
105
}
106
107
/*
108
*--------------------------------------------------------------
109
*
110
* Tk_GetAtomName --
111
*
112
* This procedure is equivalent to XGetAtomName except that
113
* it uses the local atom cache to avoid contacting the
114
* server.
115
*
116
* Results:
117
* The return value is a character string corresponding to
118
* the atom given by "atom". This string's storage space
119
* is static: it need not be freed by the caller, and should
120
* not be modified by the caller. If "atom" doesn't exist
121
* on tkwin's display, then the string "?bad atom?" is returned.
122
*
123
* Side effects:
124
* None.
125
*
126
*--------------------------------------------------------------
127
*/
128
129
char *
130
Tk_GetAtomName(tkwin, atom)
131
Tk_Window tkwin; /* Window token; map atom to name
132
* relative to this window's
133
* display. */
134
Atom atom; /* Atom whose name is wanted. */
135
{
136
register TkDisplay *dispPtr;
137
register Tcl_HashEntry *hPtr;
138
139
dispPtr = ((TkWindow *) tkwin)->dispPtr;
140
if (!dispPtr->atomInit) {
141
AtomInit(dispPtr);
142
}
143
144
hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, (char *) atom);
145
if (hPtr == NULL) {
146
char *name;
147
Tk_ErrorHandler handler;
148
int new, mustFree;
149
150
handler= Tk_CreateErrorHandler(dispPtr->display, BadAtom,
151
-1, -1, (Tk_ErrorProc *) NULL, (ClientData) NULL);
152
name = XGetAtomName(dispPtr->display, atom);
153
mustFree = 1;
154
if (name == NULL) {
155
name = "?bad atom?";
156
mustFree = 0;
157
}
158
Tk_DeleteErrorHandler(handler);
159
hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, (char *) name,
160
&new);
161
Tcl_SetHashValue(hPtr, atom);
162
if (mustFree) {
163
XFree(name);
164
}
165
name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
166
hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, (char *) atom,
167
&new);
168
Tcl_SetHashValue(hPtr, name);
169
}
170
return (char *) Tcl_GetHashValue(hPtr);
171
}
172
173
/*
174
*--------------------------------------------------------------
175
*
176
* AtomInit --
177
*
178
* Initialize atom-related information for a display.
179
*
180
* Results:
181
* None.
182
*
183
* Side effects:
184
* Tables get initialized, etc. etc..
185
*
186
*--------------------------------------------------------------
187
*/
188
189
static void
190
AtomInit(dispPtr)
191
register TkDisplay *dispPtr; /* Display to initialize. */
192
{
193
Tcl_HashEntry *hPtr;
194
Atom atom;
195
196
dispPtr->atomInit = 1;
197
Tcl_InitHashTable(&dispPtr->nameTable, TCL_STRING_KEYS);
198
Tcl_InitHashTable(&dispPtr->atomTable, TCL_ONE_WORD_KEYS);
199
200
for (atom = 1; atom <= XA_LAST_PREDEFINED; atom++) {
201
hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, (char *) atom);
202
if (hPtr == NULL) {
203
char *name;
204
int new;
205
206
name = atomNameArray[atom - 1];
207
hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, (char *) name,
208
&new);
209
Tcl_SetHashValue(hPtr, atom);
210
name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
211
hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, (char *) atom,
212
&new);
213
Tcl_SetHashValue(hPtr, name);
214
}
215
}
216
}
217
218