428
|
1 /* This file contains compatibility routines for systems without Xmu.
|
|
2 * You would be better served by installing Xmu on your machine or
|
|
3 * yelling at your vendor to ship it.
|
|
4 */
|
|
5
|
|
6 /* XEmacs changes: rindex -> strrchr */
|
|
7
|
|
8 /* Synched up with: Not in FSF. */
|
|
9
|
|
10 #include <config.h>
|
|
11
|
|
12 #ifndef HAVE_XMU
|
|
13 /*
|
|
14 * Copyright 1989 Massachusetts Institute of Technology
|
|
15 *
|
|
16 * Permission to use, copy, modify, and distribute this software and its
|
|
17 * documentation for any purpose and without fee is hereby granted, provided
|
|
18 * that the above copyright notice appear in all copies and that both that
|
|
19 * copyright notice and this permission notice appear in supporting
|
|
20 * documentation, and that the name of M.I.T. not be used in advertising
|
|
21 * or publicity pertaining to distribution of the software without specific,
|
|
22 * written prior permission. M.I.T. makes no representations about the
|
|
23 * suitability of this software for any purpose. It is provided "as is"
|
|
24 * without express or implied warranty.
|
|
25 *
|
|
26 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
|
|
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
|
|
28 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
30 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
31 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
32 */
|
|
33 #include <X11/cursorfont.h>
|
|
34 #include <X11/Xlib.h>
|
|
35 #include <X11/Xutil.h>
|
|
36 #include <X11/Intrinsic.h>
|
|
37
|
|
38 /* for XmuCopyISOLatin1Lowered */
|
|
39 #define XK_LATIN1
|
|
40 #include <X11/keysymdef.h>
|
|
41 #undef XK_LATIN1
|
|
42
|
|
43 #if (XtSpecificationRelease >= 5)
|
|
44 /*
|
|
45 * Don't know why, but this works with X11R5, not X11R4.
|
|
46 * Anyway, _XExtension is defined in Xlib.h in X11R4, so we do not need
|
|
47 * Xlibint in that case...
|
|
48 */
|
|
49 #include <X11/Xlibint.h>
|
|
50 #endif
|
|
51 #include <X11/Xproto.h>
|
|
52 #include <stdio.h>
|
|
53 #include <ctype.h>
|
|
54
|
|
55
|
442
|
56 int XmuCursorNameToIndex (const char *name)
|
428
|
57 {
|
442
|
58 static const struct _CursorName {
|
|
59 const char *name;
|
428
|
60 unsigned int shape;
|
|
61 } cursor_names[] = {
|
|
62 {"x_cursor", XC_X_cursor},
|
|
63 {"arrow", XC_arrow},
|
|
64 {"based_arrow_down", XC_based_arrow_down},
|
|
65 {"based_arrow_up", XC_based_arrow_up},
|
|
66 {"boat", XC_boat},
|
|
67 {"bogosity", XC_bogosity},
|
|
68 {"bottom_left_corner", XC_bottom_left_corner},
|
|
69 {"bottom_right_corner", XC_bottom_right_corner},
|
|
70 {"bottom_side", XC_bottom_side},
|
|
71 {"bottom_tee", XC_bottom_tee},
|
|
72 {"box_spiral", XC_box_spiral},
|
|
73 {"center_ptr", XC_center_ptr},
|
|
74 {"circle", XC_circle},
|
|
75 {"clock", XC_clock},
|
|
76 {"coffee_mug", XC_coffee_mug},
|
|
77 {"cross", XC_cross},
|
|
78 {"cross_reverse", XC_cross_reverse},
|
|
79 {"crosshair", XC_crosshair},
|
|
80 {"diamond_cross", XC_diamond_cross},
|
|
81 {"dot", XC_dot},
|
|
82 {"dotbox", XC_dotbox},
|
|
83 {"double_arrow", XC_double_arrow},
|
|
84 {"draft_large", XC_draft_large},
|
|
85 {"draft_small", XC_draft_small},
|
|
86 {"draped_box", XC_draped_box},
|
|
87 {"exchange", XC_exchange},
|
|
88 {"fleur", XC_fleur},
|
|
89 {"gobbler", XC_gobbler},
|
|
90 {"gumby", XC_gumby},
|
|
91 {"hand1", XC_hand1},
|
|
92 {"hand2", XC_hand2},
|
|
93 {"heart", XC_heart},
|
|
94 {"icon", XC_icon},
|
|
95 {"iron_cross", XC_iron_cross},
|
|
96 {"left_ptr", XC_left_ptr},
|
|
97 {"left_side", XC_left_side},
|
|
98 {"left_tee", XC_left_tee},
|
|
99 {"leftbutton", XC_leftbutton},
|
|
100 {"ll_angle", XC_ll_angle},
|
|
101 {"lr_angle", XC_lr_angle},
|
|
102 {"man", XC_man},
|
|
103 {"middlebutton", XC_middlebutton},
|
|
104 {"mouse", XC_mouse},
|
|
105 {"pencil", XC_pencil},
|
|
106 {"pirate", XC_pirate},
|
|
107 {"plus", XC_plus},
|
|
108 {"question_arrow", XC_question_arrow},
|
|
109 {"right_ptr", XC_right_ptr},
|
|
110 {"right_side", XC_right_side},
|
|
111 {"right_tee", XC_right_tee},
|
|
112 {"rightbutton", XC_rightbutton},
|
|
113 {"rtl_logo", XC_rtl_logo},
|
|
114 {"sailboat", XC_sailboat},
|
|
115 {"sb_down_arrow", XC_sb_down_arrow},
|
|
116 {"sb_h_double_arrow", XC_sb_h_double_arrow},
|
|
117 {"sb_left_arrow", XC_sb_left_arrow},
|
|
118 {"sb_right_arrow", XC_sb_right_arrow},
|
|
119 {"sb_up_arrow", XC_sb_up_arrow},
|
|
120 {"sb_v_double_arrow", XC_sb_v_double_arrow},
|
|
121 {"shuttle", XC_shuttle},
|
|
122 {"sizing", XC_sizing},
|
|
123 {"spider", XC_spider},
|
|
124 {"spraycan", XC_spraycan},
|
|
125 {"star", XC_star},
|
|
126 {"target", XC_target},
|
|
127 {"tcross", XC_tcross},
|
|
128 {"top_left_arrow", XC_top_left_arrow},
|
|
129 {"top_left_corner", XC_top_left_corner},
|
|
130 {"top_right_corner", XC_top_right_corner},
|
|
131 {"top_side", XC_top_side},
|
|
132 {"top_tee", XC_top_tee},
|
|
133 {"trek", XC_trek},
|
|
134 {"ul_angle", XC_ul_angle},
|
|
135 {"umbrella", XC_umbrella},
|
|
136 {"ur_angle", XC_ur_angle},
|
|
137 {"watch", XC_watch},
|
|
138 {"xterm", XC_xterm},
|
|
139 };
|
442
|
140 const struct _CursorName *table;
|
428
|
141 int i;
|
|
142 char tmp[40];
|
|
143
|
647
|
144 if (strlen (name) >= sizeof (tmp)) return -1;
|
428
|
145 for (i=0; i<strlen(name); i++)
|
|
146 if (isupper((unsigned char) name[i]))
|
|
147 tmp[i] = tolower((unsigned char) name[i]);
|
|
148 else
|
|
149 tmp[i] = name[i];
|
|
150 tmp[i] = 0;
|
|
151
|
|
152 for (i=0, table=cursor_names; i < XtNumber(cursor_names); i++, table++ ) {
|
|
153 if (strcmp(tmp, table->name) == 0) return table->shape;
|
|
154 }
|
|
155
|
|
156 return -1;
|
|
157 }
|
|
158
|
608
|
159 /* Definition of XmuReadBitmapDataFromFile replaced with the code in
|
|
160 * glyphs-shared.c
|
|
161 *
|
|
162 * wmperry Jun 1, 2001
|
428
|
163 */
|
|
164
|
|
165 /*
|
|
166 * XmuPrintDefaultErrorMessage - print a nice error that looks like the usual
|
|
167 * message. Return 1 if the caller should consider exiting, else 0.
|
|
168 */
|
|
169 int XmuPrintDefaultErrorMessage (Display *dpy, XErrorEvent *event, FILE *fp)
|
|
170 {
|
|
171 char buffer[BUFSIZ];
|
|
172 char mesg[BUFSIZ];
|
|
173 char number[32];
|
|
174 char *mtype = "XlibMessage";
|
|
175 _XExtension *ext = (_XExtension *)NULL;
|
|
176 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
|
|
177 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
|
|
178 fprintf(fp, "%s: %s\n ", mesg, buffer);
|
|
179 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
|
|
180 mesg, BUFSIZ);
|
|
181 fprintf(fp, mesg, event->request_code);
|
|
182 if (event->request_code < 128) {
|
|
183 sprintf(number, "%d", event->request_code);
|
|
184 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
|
|
185 } else {
|
|
186 /* XXX this is non-portable */
|
|
187 for (ext = dpy->ext_procs;
|
|
188 ext && (ext->codes.major_opcode != event->request_code);
|
|
189 ext = ext->next)
|
|
190 ;
|
|
191 if (ext)
|
|
192 strcpy(buffer, ext->name);
|
|
193 else
|
|
194 buffer[0] = '\0';
|
|
195 }
|
|
196 fprintf(fp, " (%s)", buffer);
|
|
197 fputs("\n ", fp);
|
|
198 #if (XtSpecificationRelease >= 5)
|
|
199 if (event->request_code >= 128) {
|
|
200 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
|
|
201 mesg, BUFSIZ);
|
|
202 fprintf(fp, mesg, event->minor_code);
|
|
203 if (ext) {
|
|
204 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
|
|
205 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
|
|
206 fprintf(fp, " (%s)", buffer);
|
|
207 }
|
|
208 fputs("\n ", fp);
|
|
209 }
|
|
210 if (event->error_code >= 128) {
|
|
211 /* let extensions try to print the values */
|
|
212 /* XXX this is non-portable code */
|
|
213 for (ext = dpy->ext_procs; ext; ext = ext->next) {
|
|
214 if (ext->error_values)
|
|
215 (*ext->error_values)(dpy, event, fp);
|
|
216 }
|
|
217 /* the rest is a fallback, providing a simple default */
|
|
218 /* kludge, try to find the extension that caused it */
|
|
219 buffer[0] = '\0';
|
|
220 for (ext = dpy->ext_procs; ext; ext = ext->next) {
|
|
221 if (ext->error_string)
|
|
222 (*ext->error_string)(dpy, event->error_code, &ext->codes,
|
|
223 buffer, BUFSIZ);
|
|
224 if (buffer[0])
|
|
225 break;
|
|
226 }
|
|
227 if (buffer[0])
|
|
228 sprintf(buffer, "%s.%d", ext->name,
|
|
229 event->error_code - ext->codes.first_error);
|
|
230 else
|
|
231 strcpy(buffer, "Value");
|
|
232 XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
|
|
233 if (*mesg) {
|
|
234 fprintf(fp, mesg, event->resourceid);
|
|
235 fputs("\n ", fp);
|
|
236 }
|
|
237 } else if ((event->error_code == BadWindow) ||
|
|
238 (event->error_code == BadPixmap) ||
|
|
239 (event->error_code == BadCursor) ||
|
|
240 (event->error_code == BadFont) ||
|
|
241 (event->error_code == BadDrawable) ||
|
|
242 (event->error_code == BadColor) ||
|
|
243 (event->error_code == BadGC) ||
|
|
244 (event->error_code == BadIDChoice) ||
|
|
245 (event->error_code == BadValue) ||
|
|
246 (event->error_code == BadAtom)) {
|
|
247 if (event->error_code == BadValue)
|
|
248 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
|
|
249 mesg, BUFSIZ);
|
|
250 else if (event->error_code == BadAtom)
|
|
251 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
|
|
252 mesg, BUFSIZ);
|
|
253 else
|
|
254 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
|
|
255 mesg, BUFSIZ);
|
|
256 fprintf(fp, mesg, event->resourceid);
|
|
257 fputs("\n ", fp);
|
|
258 }
|
|
259 #elif (XtSpecificationRelease == 4)
|
|
260 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
|
|
261 mesg, BUFSIZ);
|
|
262 fprintf(fp, mesg, event->minor_code);
|
|
263 fputs("\n ", fp);
|
|
264 if (ext) {
|
|
265 sprintf(mesg, "%s.%d", ext->name, event->minor_code);
|
|
266 XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
|
|
267 fprintf(fp, " (%s)", buffer);
|
|
268 }
|
|
269 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
|
|
270 mesg, BUFSIZ);
|
|
271 fprintf(fp, mesg, event->resourceid);
|
|
272 fputs("\n ", fp);
|
|
273 #else
|
|
274 ERROR! Unsupported release of X11
|
|
275 #endif
|
|
276 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
|
|
277 mesg, BUFSIZ);
|
|
278 fprintf(fp, mesg, event->serial);
|
|
279 fputs("\n ", fp);
|
|
280 XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
|
|
281 mesg, BUFSIZ);
|
|
282 fprintf(fp, mesg, NextRequest(dpy)-1);
|
|
283 fputs("\n", fp);
|
|
284 if (event->error_code == BadImplementation) return 0;
|
|
285 return 1;
|
|
286 }
|
|
287
|
|
288
|
|
289 /*
|
|
290 * XmuSimpleErrorHandler - ignore errors for XQueryTree, XGetWindowAttributes,
|
|
291 * and XGetGeometry; print a message for everything else. In all case, do
|
|
292 * not exit.
|
|
293 */
|
|
294 int XmuSimpleErrorHandler (Display *dpy, XErrorEvent *errorp)
|
|
295 {
|
|
296 switch (errorp->request_code) {
|
|
297 case X_QueryTree:
|
|
298 case X_GetWindowAttributes:
|
|
299 if (errorp->error_code == BadWindow) return 0;
|
|
300 break;
|
|
301 case X_GetGeometry:
|
|
302 if (errorp->error_code == BadDrawable) return 0;
|
|
303 break;
|
|
304 }
|
|
305 /* got a "real" X error */
|
|
306 return XmuPrintDefaultErrorMessage (dpy, errorp, stderr);
|
|
307 }
|
|
308
|
442
|
309 void XmuCopyISOLatin1Lowered(char *dst, const char *src)
|
428
|
310 {
|
|
311 unsigned char *dest = (unsigned char *) dst;
|
|
312 unsigned char *source = (unsigned char *) src;
|
|
313
|
|
314 for ( ; *source; source++, dest++)
|
|
315 {
|
|
316 if ((*source >= XK_A) && (*source <= XK_Z))
|
|
317 *dest = *source + (XK_a - XK_A);
|
|
318 else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
|
|
319 *dest = *source + (XK_agrave - XK_Agrave);
|
|
320 else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
|
|
321 *dest = *source + (XK_oslash - XK_Ooblique);
|
|
322 else
|
|
323 *dest = *source;
|
|
324 }
|
|
325 *dest = '\0';
|
|
326 }
|
|
327 #endif /* !HAVE_XMU */
|