0
|
1 /* X-specific Lisp objects.
|
|
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995 Tinker Systems
|
|
5 Copyright (C) 1995, 1996 Ben Wing
|
|
6 Copyright (C) 1995 Sun Microsystems
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify it
|
|
11 under the terms of the GNU General Public License as published by the
|
|
12 Free Software Foundation; either version 2, or (at your option) any
|
|
13 later version.
|
|
14
|
|
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
18 for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with XEmacs; see the file COPYING. If not, write to
|
|
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 Boston, MA 02111-1307, USA. */
|
|
24
|
|
25 /* Synched up with: Not in FSF. */
|
|
26
|
|
27 /* Original author: Jamie Zawinski for 19.8
|
|
28 font-truename stuff added by Jamie Zawinski for 19.10
|
|
29 subwindow support added by Chuck Thompson
|
|
30 additional XPM support added by Chuck Thompson
|
|
31 initial X-Face support added by Stig
|
185
|
32 rewritten/restructured by Ben Wing for 19.12/19.13
|
0
|
33 GIF/JPEG support added by Ben Wing for 19.14
|
|
34 PNG support added by Bill Perry for 19.14
|
|
35 Improved GIF/JPEG support added by Bill Perry for 19.14
|
|
36 Cleanup/simplification of error handling by Ben Wing for 19.14
|
|
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
|
276
|
38 GIF support changed to external GIFlib 3.1 by Jareth Hein for 21.0
|
|
39 Many changes for color work and optimizations by Jareth Hein for 21.0
|
|
40 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0
|
|
41 TIFF code by Jareth Hein for 21.0
|
308
|
42 GIF/JPEG/PNG/TIFF code moved to new glyph-eimage.c for 21.0
|
0
|
43
|
|
44 TODO:
|
357
|
45 Support the GrayScale, StaticColor and StaticGray visual classes.
|
0
|
46 Convert images.el to C and stick it in here?
|
|
47 */
|
|
48
|
|
49 #include <config.h>
|
|
50 #include "lisp.h"
|
251
|
51 #include "lstream.h"
|
0
|
52 #include "console-x.h"
|
|
53 #include "glyphs-x.h"
|
|
54 #include "objects-x.h"
|
|
55 #include "xmu.h"
|
|
56
|
|
57 #include "buffer.h"
|
|
58 #include "frame.h"
|
|
59 #include "insdel.h"
|
|
60 #include "opaque.h"
|
|
61
|
265
|
62 #include "imgproc.h"
|
|
63
|
0
|
64 #include "sysfile.h"
|
|
65
|
251
|
66 #include <setjmp.h>
|
290
|
67
|
259
|
68 #ifdef FILE_CODING
|
|
69 #include "file-coding.h"
|
138
|
70 #endif
|
0
|
71
|
265
|
72 #if INTBITS == 32
|
|
73 # define FOUR_BYTE_TYPE unsigned int
|
|
74 #elif LONGBITS == 32
|
|
75 # define FOUR_BYTE_TYPE unsigned long
|
|
76 #elif SHORTBITS == 32
|
|
77 # define FOUR_BYTE_TYPE unsigned short
|
|
78 #else
|
|
79 #error What kind of strange-ass system are we running on?
|
|
80 #endif
|
|
81
|
|
82 #define LISP_DEVICE_TO_X_SCREEN(dev) XDefaultScreenOfDisplay (DEVICE_X_DISPLAY (XDEVICE (dev)))
|
0
|
83
|
|
84 #ifdef HAVE_XFACE
|
|
85 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xface);
|
|
86 Lisp_Object Qxface;
|
|
87 #endif
|
|
88
|
|
89 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor_font);
|
|
90 Lisp_Object Qcursor_font;
|
|
91
|
|
92 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font);
|
|
93
|
122
|
94 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect);
|
0
|
95
|
|
96 static void cursor_font_instantiate (Lisp_Object image_instance,
|
|
97 Lisp_Object instantiator,
|
|
98 Lisp_Object pointer_fg,
|
|
99 Lisp_Object pointer_bg,
|
124
|
100 int dest_mask,
|
|
101 Lisp_Object domain);
|
0
|
102
|
|
103 #include "bitmaps.h"
|
|
104
|
|
105
|
|
106 /************************************************************************/
|
|
107 /* image instance methods */
|
|
108 /************************************************************************/
|
|
109
|
265
|
110 /************************************************************************/
|
|
111 /* convert from a series of RGB triples to an XImage formated for the */
|
|
112 /* proper display */
|
|
113 /************************************************************************/
|
272
|
114 static XImage *
|
|
115 convert_EImage_to_XImage (Lisp_Object device, int width, int height,
|
|
116 unsigned char *pic, unsigned long **pixtbl,
|
280
|
117 int *npixels)
|
265
|
118 {
|
|
119 Display *dpy;
|
|
120 Colormap cmap;
|
|
121 Visual *vis;
|
|
122 XImage *outimg;
|
|
123 int depth, bitmap_pad, byte_cnt, i, j;
|
|
124 int rd,gr,bl,q;
|
|
125 unsigned char *data, *ip, *dp;
|
|
126 quant_table *qtable;
|
|
127 union {
|
|
128 FOUR_BYTE_TYPE val;
|
|
129 char cp[4];
|
|
130 } conv;
|
|
131
|
|
132 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
133 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
134 vis = DEVICE_X_VISUAL (XDEVICE(device));
|
|
135 depth = DEVICE_X_DEPTH(XDEVICE(device));
|
|
136
|
357
|
137 if (vis->class == GrayScale || vis->class == StaticColor ||
|
|
138 vis->class == StaticGray)
|
|
139 {
|
|
140 /* #### Implement me!!! */
|
|
141 return NULL;
|
|
142 }
|
|
143
|
269
|
144 if (vis->class == PseudoColor)
|
|
145 {
|
|
146 /* Quantize the image and get a histogram while we're at it.
|
|
147 Do this first to save memory */
|
|
148 qtable = build_EImage_quantable(pic, width, height, 256);
|
|
149 if (qtable == NULL) return NULL;
|
|
150 }
|
265
|
151
|
|
152 bitmap_pad = ((depth > 16) ? 32 :
|
|
153 (depth > 8) ? 16 :
|
|
154 8);
|
|
155
|
|
156 outimg = XCreateImage (dpy, vis,
|
|
157 depth, ZPixmap, 0, 0, width, height,
|
|
158 bitmap_pad, 0);
|
|
159 if (!outimg) return NULL;
|
|
160
|
333
|
161 byte_cnt = outimg->bits_per_pixel >> 3;
|
|
162
|
265
|
163 data = (unsigned char *) xmalloc (outimg->bytes_per_line * height);
|
269
|
164 if (!data)
|
|
165 {
|
272
|
166 XDestroyImage (outimg);
|
269
|
167 return NULL;
|
|
168 }
|
272
|
169 outimg->data = (char *) data;
|
265
|
170
|
269
|
171 if (vis->class == PseudoColor)
|
|
172 {
|
|
173 unsigned long pixarray[256];
|
280
|
174 int pixcount, n;
|
269
|
175 /* use our quantize table to allocate the colors */
|
280
|
176 pixcount = 32;
|
|
177 *pixtbl = xnew_array (unsigned long, pixcount);
|
269
|
178 *npixels = 0;
|
|
179
|
|
180 /* ### should implement a sort by popularity to assure proper allocation */
|
|
181 n = *npixels;
|
|
182 for (i = 0; i < qtable->num_active_colors; i++)
|
|
183 {
|
|
184 XColor color;
|
|
185 int res;
|
265
|
186
|
269
|
187 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0;
|
|
188 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0;
|
|
189 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0;
|
|
190 color.flags = DoRed | DoGreen | DoBlue;
|
|
191 res = allocate_nearest_color (dpy, cmap, vis, &color);
|
|
192 if (res > 0 && res < 3)
|
|
193 {
|
280
|
194 DO_REALLOC(*pixtbl, pixcount, n+1, unsigned long);
|
269
|
195 (*pixtbl)[n] = color.pixel;
|
|
196 n++;
|
|
197 }
|
|
198 pixarray[i] = color.pixel;
|
|
199 }
|
|
200 *npixels = n;
|
|
201 ip = pic;
|
|
202 for (i = 0; i < height; i++)
|
|
203 {
|
|
204 dp = data + (i * outimg->bytes_per_line);
|
|
205 for (j = 0; j < width; j++)
|
|
206 {
|
|
207 rd = *ip++;
|
|
208 gr = *ip++;
|
|
209 bl = *ip++;
|
|
210 conv.val = pixarray[QUANT_GET_COLOR(qtable,rd,gr,bl)];
|
304
|
211 #if WORDS_BIGENDIAN
|
298
|
212 if (outimg->byte_order == MSBFirst)
|
|
213 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q];
|
|
214 else
|
304
|
215 for (q = 3; q >= 4-byte_cnt; q--) *dp++ = conv.cp[q];
|
|
216 #else
|
|
217 if (outimg->byte_order == MSBFirst)
|
|
218 for (q = byte_cnt-1; q >= 0; q--) *dp++ = conv.cp[q];
|
|
219 else
|
298
|
220 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
|
304
|
221 #endif
|
269
|
222 }
|
|
223 }
|
|
224 xfree(qtable);
|
|
225 } else {
|
|
226 unsigned long rshift,gshift,bshift,rbits,gbits,bbits,junk;
|
|
227 junk = vis->red_mask;
|
|
228 rshift = 0;
|
|
229 while ((junk & 0x1) == 0)
|
|
230 {
|
|
231 junk = junk >> 1;
|
|
232 rshift ++;
|
|
233 }
|
|
234 rbits = 0;
|
|
235 while (junk != 0)
|
|
236 {
|
|
237 junk = junk >> 1;
|
|
238 rbits++;
|
|
239 }
|
|
240 junk = vis->green_mask;
|
|
241 gshift = 0;
|
|
242 while ((junk & 0x1) == 0)
|
|
243 {
|
|
244 junk = junk >> 1;
|
|
245 gshift ++;
|
|
246 }
|
|
247 gbits = 0;
|
|
248 while (junk != 0)
|
|
249 {
|
|
250 junk = junk >> 1;
|
|
251 gbits++;
|
|
252 }
|
|
253 junk = vis->blue_mask;
|
|
254 bshift = 0;
|
|
255 while ((junk & 0x1) == 0)
|
|
256 {
|
|
257 junk = junk >> 1;
|
|
258 bshift ++;
|
|
259 }
|
|
260 bbits = 0;
|
|
261 while (junk != 0)
|
|
262 {
|
|
263 junk = junk >> 1;
|
|
264 bbits++;
|
|
265 }
|
|
266 ip = pic;
|
|
267 for (i = 0; i < height; i++)
|
|
268 {
|
|
269 dp = data + (i * outimg->bytes_per_line);
|
|
270 for (j = 0; j < width; j++)
|
|
271 {
|
|
272 if (rbits > 8)
|
|
273 rd = *ip++ << (rbits - 8);
|
|
274 else
|
|
275 rd = *ip++ >> (8 - rbits);
|
|
276 if (gbits > 8)
|
|
277 gr = *ip++ << (gbits - 8);
|
|
278 else
|
|
279 gr = *ip++ >> (8 - gbits);
|
|
280 if (bbits > 8)
|
|
281 bl = *ip++ << (bbits - 8);
|
|
282 else
|
|
283 bl = *ip++ >> (8 - bbits);
|
|
284
|
|
285 conv.val = (rd << rshift) | (gr << gshift) | (bl << bshift);
|
304
|
286 #if WORDS_BIGENDIAN
|
298
|
287 if (outimg->byte_order == MSBFirst)
|
|
288 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q];
|
|
289 else
|
304
|
290 for (q = 3; q >= 4-byte_cnt; q--) *dp++ = conv.cp[q];
|
|
291 #else
|
|
292 if (outimg->byte_order == MSBFirst)
|
|
293 for (q = byte_cnt-1; q >= 0; q--) *dp++ = conv.cp[q];
|
|
294 else
|
298
|
295 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
|
304
|
296 #endif
|
269
|
297 }
|
|
298 }
|
|
299 }
|
265
|
300 return outimg;
|
|
301 }
|
|
302
|
|
303
|
|
304
|
0
|
305 static void
|
|
306 x_print_image_instance (struct Lisp_Image_Instance *p,
|
|
307 Lisp_Object printcharfun,
|
|
308 int escapeflag)
|
|
309 {
|
|
310 char buf[100];
|
|
311
|
|
312 switch (IMAGE_INSTANCE_TYPE (p))
|
|
313 {
|
|
314 case IMAGE_MONO_PIXMAP:
|
|
315 case IMAGE_COLOR_PIXMAP:
|
|
316 case IMAGE_POINTER:
|
|
317 sprintf (buf, " (0x%lx", (unsigned long) IMAGE_INSTANCE_X_PIXMAP (p));
|
|
318 write_c_string (buf, printcharfun);
|
|
319 if (IMAGE_INSTANCE_X_MASK (p))
|
|
320 {
|
|
321 sprintf (buf, "/0x%lx", (unsigned long) IMAGE_INSTANCE_X_MASK (p));
|
|
322 write_c_string (buf, printcharfun);
|
|
323 }
|
|
324 write_c_string (")", printcharfun);
|
|
325 break;
|
114
|
326 #if HAVE_SUBWINDOWS
|
0
|
327 case IMAGE_SUBWINDOW:
|
|
328 /* #### implement me */
|
114
|
329 #endif
|
0
|
330 default:
|
|
331 break;
|
|
332 }
|
|
333 }
|
|
334
|
|
335 static void
|
|
336 x_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
337 {
|
|
338 if (!p->data)
|
|
339 return;
|
|
340
|
|
341 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
342 {
|
219
|
343 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (p->device));
|
0
|
344
|
|
345 if (IMAGE_INSTANCE_X_PIXMAP (p))
|
219
|
346 XFreePixmap (dpy, IMAGE_INSTANCE_X_PIXMAP (p));
|
0
|
347 if (IMAGE_INSTANCE_X_MASK (p) &&
|
|
348 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p))
|
219
|
349 XFreePixmap (dpy, IMAGE_INSTANCE_X_MASK (p));
|
0
|
350 IMAGE_INSTANCE_X_PIXMAP (p) = 0;
|
|
351 IMAGE_INSTANCE_X_MASK (p) = 0;
|
|
352
|
|
353 if (IMAGE_INSTANCE_X_CURSOR (p))
|
|
354 {
|
219
|
355 XFreeCursor (dpy, IMAGE_INSTANCE_X_CURSOR (p));
|
0
|
356 IMAGE_INSTANCE_X_CURSOR (p) = 0;
|
|
357 }
|
|
358
|
|
359 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0)
|
|
360 {
|
219
|
361 XFreeColors (dpy,
|
269
|
362 IMAGE_INSTANCE_X_COLORMAP (p),
|
0
|
363 IMAGE_INSTANCE_X_PIXELS (p),
|
|
364 IMAGE_INSTANCE_X_NPIXELS (p), 0);
|
|
365 IMAGE_INSTANCE_X_NPIXELS (p) = 0;
|
|
366 }
|
|
367 }
|
|
368 if (IMAGE_INSTANCE_X_PIXELS (p))
|
|
369 {
|
|
370 xfree (IMAGE_INSTANCE_X_PIXELS (p));
|
|
371 IMAGE_INSTANCE_X_PIXELS (p) = 0;
|
|
372 }
|
|
373
|
|
374 xfree (p->data);
|
|
375 p->data = 0;
|
|
376 }
|
|
377
|
|
378 static int
|
|
379 x_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
380 struct Lisp_Image_Instance *p2, int depth)
|
|
381 {
|
|
382 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
383 {
|
|
384 case IMAGE_MONO_PIXMAP:
|
|
385 case IMAGE_COLOR_PIXMAP:
|
|
386 case IMAGE_POINTER:
|
269
|
387 if (IMAGE_INSTANCE_X_COLORMAP (p1) != IMAGE_INSTANCE_X_COLORMAP (p2) ||
|
|
388 IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2))
|
0
|
389 return 0;
|
114
|
390 #if HAVE_SUBWINDOWS
|
0
|
391 case IMAGE_SUBWINDOW:
|
|
392 /* #### implement me */
|
114
|
393 #endif
|
56
|
394 break;
|
0
|
395 default:
|
|
396 break;
|
|
397 }
|
|
398
|
|
399 return 1;
|
|
400 }
|
|
401
|
|
402 static unsigned long
|
|
403 x_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
404 {
|
|
405 switch (IMAGE_INSTANCE_TYPE (p))
|
|
406 {
|
|
407 case IMAGE_MONO_PIXMAP:
|
|
408 case IMAGE_COLOR_PIXMAP:
|
|
409 case IMAGE_POINTER:
|
|
410 return IMAGE_INSTANCE_X_NPIXELS (p);
|
114
|
411 #if HAVE_SUBWINDOWS
|
0
|
412 case IMAGE_SUBWINDOW:
|
|
413 /* #### implement me */
|
149
|
414 return 0;
|
114
|
415 #endif
|
0
|
416 default:
|
|
417 return 0;
|
|
418 }
|
|
419 }
|
|
420
|
|
421 /* Set all the slots in an image instance structure to reasonable
|
|
422 default values. This is used somewhere within an instantiate
|
|
423 method. It is assumed that the device slot within the image
|
|
424 instance is already set -- this is the case when instantiate
|
|
425 methods are called. */
|
|
426
|
|
427 static void
|
|
428 x_initialize_pixmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
429 enum image_instance_type type)
|
|
430 {
|
185
|
431 ii->data = xnew_and_zero (struct x_image_instance_data);
|
0
|
432 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
433 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
434 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
435 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
436 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
437 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
438 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
439 }
|
|
440
|
|
441
|
|
442 /************************************************************************/
|
|
443 /* pixmap file functions */
|
|
444 /************************************************************************/
|
|
445
|
|
446 /* Where bitmaps are; initialized from resource database */
|
|
447 Lisp_Object Vx_bitmap_file_path;
|
|
448
|
|
449 #ifndef BITMAPDIR
|
|
450 #define BITMAPDIR "/usr/include/X11/bitmaps"
|
|
451 #endif
|
|
452
|
|
453 #define USE_XBMLANGPATH
|
|
454
|
|
455 /* Given a pixmap filename, look through all of the "standard" places
|
|
456 where the file might be located. Return a full pathname if found;
|
|
457 otherwise, return Qnil. */
|
|
458
|
280
|
459 static Lisp_Object
|
278
|
460 x_locate_pixmap_file (Lisp_Object name)
|
0
|
461 {
|
|
462 /* This function can GC if IN_REDISPLAY is false */
|
|
463 Display *display;
|
|
464
|
|
465 /* Check non-absolute pathnames with a directory component relative to
|
|
466 the search path; that's the way Xt does it. */
|
|
467 /* #### Unix-specific */
|
80
|
468 if (XSTRING_BYTE (name, 0) == '/' ||
|
|
469 (XSTRING_BYTE (name, 0) == '.' &&
|
|
470 (XSTRING_BYTE (name, 1) == '/' ||
|
|
471 (XSTRING_BYTE (name, 1) == '.' &&
|
|
472 (XSTRING_BYTE (name, 2) == '/')))))
|
0
|
473 {
|
|
474 if (!NILP (Ffile_readable_p (name)))
|
|
475 return name;
|
|
476 else
|
|
477 return Qnil;
|
|
478 }
|
|
479
|
|
480 if (NILP (Vdefault_x_device))
|
|
481 /* This may occur during intialization. */
|
|
482 return Qnil;
|
|
483 else
|
|
484 /* We only check the bitmapFilePath resource on the original X device. */
|
|
485 display = DEVICE_X_DISPLAY (XDEVICE (Vdefault_x_device));
|
|
486
|
|
487 #ifdef USE_XBMLANGPATH
|
|
488 {
|
|
489 char *path = egetenv ("XBMLANGPATH");
|
|
490 SubstitutionRec subs[1];
|
|
491 subs[0].match = 'B';
|
14
|
492 subs[0].substitution = (char *) XSTRING_DATA (name);
|
0
|
493 /* #### Motif uses a big hairy default if $XBMLANGPATH isn't set.
|
|
494 We don't. If you want it used, set it. */
|
|
495 if (path &&
|
|
496 (path = XtResolvePathname (display, "bitmaps", 0, 0, path,
|
|
497 subs, XtNumber (subs), 0)))
|
|
498 {
|
|
499 name = build_string (path);
|
|
500 XtFree (path);
|
|
501 return (name);
|
|
502 }
|
|
503 }
|
|
504 #endif
|
|
505
|
|
506 if (NILP (Vx_bitmap_file_path))
|
|
507 {
|
|
508 char *type = 0;
|
|
509 XrmValue value;
|
|
510 if (XrmGetResource (XtDatabase (display),
|
|
511 "bitmapFilePath", "BitmapFilePath", &type, &value)
|
|
512 && !strcmp (type, "String"))
|
|
513 Vx_bitmap_file_path = decode_env_path (0, (char *) value.addr);
|
|
514 Vx_bitmap_file_path = nconc2 (Vx_bitmap_file_path,
|
265
|
515 (decode_path (BITMAPDIR)));
|
0
|
516 }
|
|
517
|
|
518 {
|
|
519 Lisp_Object found;
|
|
520 if (locate_file (Vx_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
521 {
|
|
522 Lisp_Object temp = list1 (Vdata_directory);
|
|
523 struct gcpro gcpro1;
|
|
524
|
|
525 GCPRO1 (temp);
|
|
526 locate_file (temp, name, "", &found, R_OK);
|
|
527 UNGCPRO;
|
|
528 }
|
|
529
|
|
530 return found;
|
|
531 }
|
|
532 }
|
|
533
|
278
|
534 static Lisp_Object
|
|
535 locate_pixmap_file (Lisp_Object name)
|
|
536 {
|
|
537 return x_locate_pixmap_file (name);
|
|
538 }
|
|
539
|
|
540 #if 0
|
0
|
541 static void
|
|
542 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out)
|
|
543 {
|
251
|
544 Lisp_Object instream, outstream;
|
|
545 Lstream *istr, *ostr;
|
|
546 char tempbuf[1024]; /* some random amount */
|
|
547 int fubar = 0;
|
|
548 FILE *tmpfil;
|
265
|
549 static Extbyte_dynarr *conversion_out_dynarr;
|
251
|
550 Bytecount bstart, bend;
|
|
551 struct gcpro gcpro1, gcpro2;
|
259
|
552 #ifdef FILE_CODING
|
251
|
553 Lisp_Object conv_out_stream;
|
|
554 Lstream *costr;
|
|
555 struct gcpro gcpro3;
|
|
556 #endif
|
|
557
|
|
558 /* This function can GC */
|
|
559 if (!conversion_out_dynarr)
|
|
560 conversion_out_dynarr = Dynarr_new (Extbyte);
|
|
561 else
|
|
562 Dynarr_reset (conversion_out_dynarr);
|
|
563
|
|
564 /* Create the temporary file ... */
|
0
|
565 sprintf (filename_out, "/tmp/emacs%d.XXXXXX", (int) getpid ());
|
|
566 mktemp (filename_out);
|
251
|
567 tmpfil = fopen (filename_out, "w");
|
|
568 if (!tmpfil)
|
0
|
569 {
|
251
|
570 if (tmpfil)
|
0
|
571 {
|
|
572 int old_errno = errno;
|
251
|
573 fclose (tmpfil);
|
0
|
574 unlink (filename_out);
|
|
575 errno = old_errno;
|
|
576 }
|
|
577 report_file_error ("Creating temp file",
|
|
578 list1 (build_string (filename_out)));
|
|
579 }
|
|
580
|
251
|
581 CHECK_STRING (string);
|
|
582 get_string_range_byte (string, Qnil, Qnil, &bstart, &bend,
|
|
583 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
584 instream = make_lisp_string_input_stream (string, bstart, bend);
|
|
585 istr = XLSTREAM (instream);
|
|
586 /* setup the out stream */
|
|
587 outstream = make_dynarr_output_stream((unsigned_char_dynarr *)conversion_out_dynarr);
|
|
588 ostr = XLSTREAM (outstream);
|
259
|
589 #ifdef FILE_CODING
|
251
|
590 /* setup the conversion stream */
|
|
591 conv_out_stream = make_encoding_output_stream (ostr, Fget_coding_system(Qbinary));
|
|
592 costr = XLSTREAM (conv_out_stream);
|
|
593 GCPRO3 (instream, outstream, conv_out_stream);
|
|
594 #else
|
|
595 GCPRO2 (instream, outstream);
|
|
596 #endif
|
|
597
|
|
598 /* Get the data while doing the conversion */
|
269
|
599 while (1)
|
|
600 {
|
|
601 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
|
|
602 if (!size_in_bytes)
|
|
603 break;
|
|
604 /* It does seem the flushes are necessary... */
|
259
|
605 #ifdef FILE_CODING
|
269
|
606 Lstream_write (costr, tempbuf, size_in_bytes);
|
|
607 Lstream_flush (costr);
|
251
|
608 #else
|
269
|
609 Lstream_write (ostr, tempbuf, size_in_bytes);
|
251
|
610 #endif
|
269
|
611 Lstream_flush (ostr);
|
|
612 if (fwrite ((unsigned char *)Dynarr_atp(conversion_out_dynarr, 0),
|
|
613 Dynarr_length(conversion_out_dynarr), 1, tmpfil) != 1)
|
|
614 {
|
|
615 fubar = 1;
|
|
616 break;
|
|
617 }
|
|
618 /* reset the dynarr */
|
|
619 Lstream_rewind(ostr);
|
|
620 }
|
251
|
621
|
|
622 if (fclose (tmpfil) != 0)
|
|
623 fubar = 1;
|
|
624 Lstream_close (istr);
|
259
|
625 #ifdef FILE_CODING
|
251
|
626 Lstream_close (costr);
|
|
627 #endif
|
|
628 Lstream_close (ostr);
|
272
|
629
|
251
|
630 UNGCPRO;
|
|
631 Lstream_delete (istr);
|
|
632 Lstream_delete (ostr);
|
259
|
633 #ifdef FILE_CODING
|
251
|
634 Lstream_delete (costr);
|
|
635 #endif
|
259
|
636
|
251
|
637 if (fubar)
|
|
638 report_file_error ("Writing temp file",
|
|
639 list1 (build_string (filename_out)));
|
0
|
640 }
|
272
|
641 #endif /* 0 */
|
0
|
642
|
|
643
|
|
644 /************************************************************************/
|
|
645 /* cursor functions */
|
|
646 /************************************************************************/
|
|
647
|
|
648 /* Check that this server supports cursors of size WIDTH * HEIGHT. If
|
|
649 not, signal an error. INSTANTIATOR is only used in the error
|
|
650 message. */
|
|
651
|
|
652 static void
|
|
653 check_pointer_sizes (Screen *xs, unsigned int width, unsigned int height,
|
|
654 Lisp_Object instantiator)
|
|
655 {
|
|
656 unsigned int best_width, best_height;
|
|
657 if (! XQueryBestCursor (DisplayOfScreen (xs), RootWindowOfScreen (xs),
|
|
658 width, height, &best_width, &best_height))
|
|
659 /* this means that an X error of some sort occurred (we trap
|
|
660 these so they're not fatal). */
|
|
661 signal_simple_error ("XQueryBestCursor() failed?", instantiator);
|
|
662
|
|
663 if (width > best_width || height > best_height)
|
|
664 error_with_frob (instantiator,
|
|
665 "pointer too large (%dx%d): "
|
|
666 "server requires %dx%d or smaller",
|
|
667 width, height, best_width, best_height);
|
|
668 }
|
|
669
|
|
670
|
|
671 static void
|
|
672 generate_cursor_fg_bg (Lisp_Object device, Lisp_Object *foreground,
|
|
673 Lisp_Object *background, XColor *xfg, XColor *xbg)
|
|
674 {
|
|
675 if (!NILP (*foreground) && !COLOR_INSTANCEP (*foreground))
|
|
676 *foreground =
|
|
677 Fmake_color_instance (*foreground, device,
|
|
678 encode_error_behavior_flag (ERROR_ME));
|
|
679 if (COLOR_INSTANCEP (*foreground))
|
|
680 *xfg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*foreground));
|
|
681 else
|
|
682 {
|
|
683 xfg->pixel = 0;
|
|
684 xfg->red = xfg->green = xfg->blue = 0;
|
|
685 }
|
185
|
686
|
0
|
687 if (!NILP (*background) && !COLOR_INSTANCEP (*background))
|
|
688 *background =
|
|
689 Fmake_color_instance (*background, device,
|
|
690 encode_error_behavior_flag (ERROR_ME));
|
|
691 if (COLOR_INSTANCEP (*background))
|
|
692 *xbg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*background));
|
|
693 else
|
|
694 {
|
|
695 xbg->pixel = 0;
|
|
696 xbg->red = xbg->green = xbg->blue = ~0;
|
|
697 }
|
|
698 }
|
|
699
|
|
700 static void
|
|
701 maybe_recolor_cursor (Lisp_Object image_instance, Lisp_Object foreground,
|
|
702 Lisp_Object background)
|
|
703 {
|
|
704 Lisp_Object device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
705 XColor xfg, xbg;
|
|
706
|
|
707 generate_cursor_fg_bg (device, &foreground, &background, &xfg, &xbg);
|
|
708 if (!NILP (foreground) || !NILP (background))
|
|
709 {
|
|
710 XRecolorCursor (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
711 XIMAGE_INSTANCE_X_CURSOR (image_instance),
|
|
712 &xfg, &xbg);
|
|
713 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
714 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
715 }
|
|
716 }
|
|
717
|
|
718
|
|
719 /************************************************************************/
|
|
720 /* color pixmap functions */
|
|
721 /************************************************************************/
|
|
722
|
|
723 /* Initialize an image instance from an XImage.
|
|
724
|
|
725 DEST_MASK specifies the mask of allowed image types.
|
|
726
|
|
727 PIXELS and NPIXELS specify an array of pixels that are used in
|
|
728 the image. These need to be kept around for the duration of the
|
|
729 image. When the image instance is freed, XFreeColors() will
|
|
730 automatically be called on all the pixels specified here; thus,
|
|
731 you should have allocated the pixels yourself using XAllocColor()
|
|
732 or the like. The array passed in is used directly without
|
|
733 being copied, so it should be heap data created with xmalloc().
|
|
734 It will be freed using xfree() when the image instance is
|
|
735 destroyed.
|
|
736
|
|
737 If this fails, signal an error. INSTANTIATOR is only used
|
|
738 in the error message.
|
|
739
|
|
740 #### This should be able to handle conversion into `pointer'.
|
|
741 Use the same code as for `xpm'. */
|
|
742
|
|
743 static void
|
|
744 init_image_instance_from_x_image (struct Lisp_Image_Instance *ii,
|
|
745 XImage *ximage,
|
|
746 int dest_mask,
|
269
|
747 Colormap cmap,
|
0
|
748 unsigned long *pixels,
|
|
749 int npixels,
|
|
750 Lisp_Object instantiator)
|
|
751 {
|
|
752 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
753 Display *dpy;
|
|
754 GC gc;
|
|
755 Drawable d;
|
|
756 Pixmap pixmap;
|
|
757
|
|
758 if (!DEVICE_X_P (XDEVICE (device)))
|
|
759 signal_simple_error ("Not an X device", device);
|
|
760
|
|
761 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
219
|
762 d = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
|
0
|
763
|
|
764 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
765 incompatible_image_types (instantiator, dest_mask,
|
|
766 IMAGE_COLOR_PIXMAP_MASK);
|
185
|
767
|
0
|
768 pixmap = XCreatePixmap (dpy, d, ximage->width,
|
|
769 ximage->height, ximage->depth);
|
|
770 if (!pixmap)
|
|
771 signal_simple_error ("Unable to create pixmap", instantiator);
|
|
772
|
|
773 gc = XCreateGC (dpy, pixmap, 0, NULL);
|
|
774 if (!gc)
|
|
775 {
|
|
776 XFreePixmap (dpy, pixmap);
|
|
777 signal_simple_error ("Unable to create GC", instantiator);
|
|
778 }
|
185
|
779
|
0
|
780 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
|
|
781 ximage->width, ximage->height);
|
185
|
782
|
0
|
783 XFreeGC (dpy, gc);
|
|
784
|
|
785 x_initialize_pixmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
786
|
|
787 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
788 find_keyword_in_vector (instantiator, Q_file);
|
185
|
789
|
0
|
790 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
791 IMAGE_INSTANCE_X_MASK (ii) = 0;
|
|
792 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width;
|
|
793 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height;
|
|
794 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth;
|
269
|
795 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap;
|
0
|
796 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
797 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
798 }
|
|
799
|
278
|
800 static void
|
|
801 x_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
|
|
802 int width, int height,
|
|
803 unsigned char *eimage,
|
|
804 int dest_mask,
|
|
805 Lisp_Object instantiator,
|
|
806 Lisp_Object domain)
|
|
807 {
|
|
808 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
809 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
280
|
810 unsigned long *pixtbl = NULL;
|
|
811 int npixels = 0;
|
278
|
812 XImage* ximage;
|
|
813
|
|
814 ximage = convert_EImage_to_XImage (device, width, height, eimage,
|
280
|
815 &pixtbl, &npixels);
|
278
|
816 if (!ximage)
|
280
|
817 {
|
|
818 if (pixtbl) xfree (pixtbl);
|
|
819 signal_image_error("EImage to XImage conversion failed", instantiator);
|
|
820 }
|
|
821
|
278
|
822 /* Now create the pixmap and set up the image instance */
|
|
823 init_image_instance_from_x_image (ii, ximage, dest_mask,
|
|
824 cmap, pixtbl, npixels,
|
|
825 instantiator);
|
|
826
|
|
827 if (ximage)
|
|
828 {
|
|
829 if (ximage->data)
|
|
830 {
|
|
831 xfree (ximage->data);
|
|
832 ximage->data = 0;
|
|
833 }
|
|
834 XDestroyImage (ximage);
|
|
835 }
|
|
836 }
|
|
837
|
288
|
838 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width,
|
|
839 unsigned int *height, unsigned char **datap,
|
|
840 int *x_hot, int *y_hot)
|
0
|
841 {
|
288
|
842 return XmuReadBitmapDataFromFile (filename, width, height,
|
|
843 datap, x_hot, y_hot);
|
0
|
844 }
|
|
845
|
|
846 /* Given inline data for a mono pixmap, create and return the
|
|
847 corresponding X object. */
|
|
848
|
|
849 static Pixmap
|
|
850 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
|
|
851 /* Note that data is in ext-format! */
|
|
852 CONST Extbyte *bits)
|
|
853 {
|
219
|
854 return XCreatePixmapFromBitmapData (DEVICE_X_DISPLAY (XDEVICE(device)),
|
|
855 XtWindow (DEVICE_XT_APP_SHELL (XDEVICE (device))),
|
0
|
856 (char *) bits, width, height,
|
|
857 1, 0, 1);
|
|
858 }
|
|
859
|
|
860 /* Given inline data for a mono pixmap, initialize the given
|
|
861 image instance accordingly. */
|
|
862
|
|
863 static void
|
|
864 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
|
|
865 int width, int height,
|
|
866 /* Note that data is in ext-format! */
|
|
867 CONST char *bits,
|
|
868 Lisp_Object instantiator,
|
|
869 Lisp_Object pointer_fg,
|
|
870 Lisp_Object pointer_bg,
|
|
871 int dest_mask,
|
|
872 Pixmap mask,
|
|
873 Lisp_Object mask_filename)
|
|
874 {
|
|
875 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
876 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
877 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
878 Display *dpy;
|
|
879 Screen *scr;
|
219
|
880 Drawable draw;
|
0
|
881 enum image_instance_type type;
|
|
882
|
|
883 if (!DEVICE_X_P (XDEVICE (device)))
|
|
884 signal_simple_error ("Not an X device", device);
|
|
885
|
|
886 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
219
|
887 draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
|
0
|
888 scr = DefaultScreenOfDisplay (dpy);
|
|
889
|
|
890 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
891 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
892 {
|
|
893 if (!NILP (foreground) || !NILP (background))
|
|
894 type = IMAGE_COLOR_PIXMAP;
|
|
895 else
|
|
896 type = IMAGE_MONO_PIXMAP;
|
|
897 }
|
|
898 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
899 type = IMAGE_MONO_PIXMAP;
|
|
900 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
901 type = IMAGE_COLOR_PIXMAP;
|
|
902 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
903 type = IMAGE_POINTER;
|
|
904 else
|
|
905 incompatible_image_types (instantiator, dest_mask,
|
|
906 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
907 | IMAGE_POINTER_MASK);
|
|
908
|
|
909 x_initialize_pixmap_image_instance (ii, type);
|
|
910 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
911 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
912 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
913 find_keyword_in_vector (instantiator, Q_file);
|
|
914
|
|
915 switch (type)
|
|
916 {
|
|
917 case IMAGE_MONO_PIXMAP:
|
|
918 {
|
|
919 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
|
920 pixmap_from_xbm_inline (device, width, height, (Extbyte *) bits);
|
|
921 }
|
|
922 break;
|
|
923
|
|
924 case IMAGE_COLOR_PIXMAP:
|
|
925 {
|
219
|
926 Dimension d = DEVICE_X_DEPTH (XDEVICE(device));
|
0
|
927 unsigned long fg = BlackPixelOfScreen (scr);
|
|
928 unsigned long bg = WhitePixelOfScreen (scr);
|
|
929
|
|
930 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
931 foreground =
|
|
932 Fmake_color_instance (foreground, device,
|
|
933 encode_error_behavior_flag (ERROR_ME));
|
|
934
|
|
935 if (COLOR_INSTANCEP (foreground))
|
|
936 fg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground)).pixel;
|
|
937
|
|
938 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
939 background =
|
|
940 Fmake_color_instance (background, device,
|
|
941 encode_error_behavior_flag (ERROR_ME));
|
|
942
|
|
943 if (COLOR_INSTANCEP (background))
|
|
944 bg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background)).pixel;
|
|
945
|
|
946 /* We used to duplicate the pixels using XAllocColor(), to protect
|
|
947 against their getting freed. Just as easy to just store the
|
|
948 color instances here and GC-protect them, so this doesn't
|
|
949 happen. */
|
|
950 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
951 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
952 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
219
|
953 XCreatePixmapFromBitmapData (dpy, draw,
|
0
|
954 (char *) bits, width, height,
|
|
955 fg, bg, d);
|
|
956 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
957 }
|
|
958 break;
|
|
959
|
|
960 case IMAGE_POINTER:
|
207
|
961 {
|
0
|
962 XColor fg_color, bg_color;
|
|
963 Pixmap source;
|
|
964
|
|
965 check_pointer_sizes (scr, width, height, instantiator);
|
|
966
|
|
967 source =
|
219
|
968 XCreatePixmapFromBitmapData (dpy, draw,
|
0
|
969 (char *) bits, width, height,
|
|
970 1, 0, 1);
|
|
971
|
|
972 if (NILP (foreground))
|
|
973 foreground = pointer_fg;
|
|
974 if (NILP (background))
|
|
975 background = pointer_bg;
|
|
976 generate_cursor_fg_bg (device, &foreground, &background,
|
|
977 &fg_color, &bg_color);
|
|
978
|
|
979 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
980 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
981 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
|
|
982 find_keyword_in_vector (instantiator, Q_hotspot_x);
|
|
983 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
|
|
984 find_keyword_in_vector (instantiator, Q_hotspot_y);
|
|
985 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
986 XCreatePixmapCursor
|
|
987 (dpy, source, mask, &fg_color, &bg_color,
|
|
988 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ?
|
|
989 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) : 0,
|
|
990 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) ?
|
|
991 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) : 0);
|
|
992 }
|
|
993 break;
|
|
994
|
|
995 default:
|
|
996 abort ();
|
|
997 }
|
|
998 }
|
|
999
|
|
1000 static void
|
|
1001 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1002 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1003 int dest_mask, int width, int height,
|
|
1004 /* Note that data is in ext-format! */
|
|
1005 CONST char *bits)
|
|
1006 {
|
|
1007 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1008 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
|
1009 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1010 Pixmap mask = 0;
|
|
1011 CONST char *gcc_may_you_rot_in_hell;
|
|
1012
|
|
1013 if (!NILP (mask_data))
|
269
|
1014 {
|
0
|
1015 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))),
|
|
1016 gcc_may_you_rot_in_hell);
|
|
1017 mask =
|
|
1018 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
|
|
1019 XINT (XCAR (mask_data)),
|
|
1020 XINT (XCAR (XCDR (mask_data))),
|
|
1021 (CONST unsigned char *)
|
|
1022 gcc_may_you_rot_in_hell);
|
288
|
1023 }
|
0
|
1024
|
|
1025 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1026 instantiator, pointer_fg, pointer_bg,
|
|
1027 dest_mask, mask, mask_file);
|
|
1028 }
|
|
1029
|
|
1030 /* Instantiate method for XBM's. */
|
|
1031
|
|
1032 static void
|
288
|
1033 x_xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1034 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1035 int dest_mask, Lisp_Object domain)
|
0
|
1036 {
|
|
1037 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1038 CONST char *gcc_go_home;
|
|
1039
|
|
1040 assert (!NILP (data));
|
|
1041
|
|
1042 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))),
|
|
1043 gcc_go_home);
|
|
1044
|
|
1045 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1046 pointer_bg, dest_mask, XINT (XCAR (data)),
|
|
1047 XINT (XCAR (XCDR (data))), gcc_go_home);
|
|
1048 }
|
|
1049
|
|
1050
|
|
1051 #ifdef HAVE_XPM
|
|
1052
|
|
1053 /**********************************************************************
|
|
1054 * XPM *
|
|
1055 **********************************************************************/
|
|
1056 /* xpm 3.2g and better has XpmCreatePixmapFromBuffer()...
|
|
1057 There was no version number in xpm.h before 3.3, but this should do.
|
|
1058 */
|
|
1059 #if (XpmVersion >= 3) || defined(XpmExactColors)
|
|
1060 # define XPM_DOES_BUFFERS
|
|
1061 #endif
|
|
1062
|
|
1063 #ifndef XPM_DOES_BUFFERS
|
|
1064 Your version of XPM is too old. You cannot compile with it.
|
|
1065 Upgrade to version 3.2g or better or compile with --with-xpm=no.
|
|
1066 #endif /* !XPM_DOES_BUFFERS */
|
|
1067
|
|
1068 static XpmColorSymbol *
|
|
1069 extract_xpm_color_names (XpmAttributes *xpmattrs, Lisp_Object device,
|
124
|
1070 Lisp_Object domain,
|
0
|
1071 Lisp_Object color_symbol_alist)
|
|
1072 {
|
|
1073 /* This function can GC */
|
219
|
1074 Display *dpy = DEVICE_X_DISPLAY (XDEVICE(device));
|
|
1075 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
0
|
1076 XColor color;
|
|
1077 Lisp_Object rest;
|
|
1078 Lisp_Object results = Qnil;
|
|
1079 int i;
|
|
1080 XpmColorSymbol *symbols;
|
|
1081 struct gcpro gcpro1, gcpro2;
|
|
1082
|
|
1083 GCPRO2 (results, device);
|
|
1084
|
|
1085 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
1086 error happens we don't lose any malloc()ed data, or more importantly,
|
|
1087 leave any pixels allocated in the server. */
|
|
1088 i = 0;
|
|
1089 LIST_LOOP (rest, color_symbol_alist)
|
|
1090 {
|
|
1091 Lisp_Object cons = XCAR (rest);
|
|
1092 Lisp_Object name = XCAR (cons);
|
|
1093 Lisp_Object value = XCDR (cons);
|
|
1094 if (NILP (value))
|
|
1095 continue;
|
|
1096 if (STRINGP (value))
|
|
1097 value =
|
|
1098 Fmake_color_instance
|
|
1099 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
|
|
1100 else
|
|
1101 {
|
|
1102 assert (COLOR_SPECIFIERP (value));
|
124
|
1103 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
0
|
1104 }
|
|
1105 if (NILP (value))
|
|
1106 continue;
|
|
1107 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
1108 i++;
|
|
1109 }
|
|
1110 UNGCPRO; /* no more evaluation */
|
|
1111
|
|
1112 if (i == 0) return 0;
|
|
1113
|
185
|
1114 symbols = xnew_array (XpmColorSymbol, i);
|
0
|
1115 xpmattrs->valuemask |= XpmColorSymbols;
|
|
1116 xpmattrs->colorsymbols = symbols;
|
|
1117 xpmattrs->numsymbols = i;
|
|
1118
|
|
1119 while (--i >= 0)
|
|
1120 {
|
|
1121 Lisp_Object cons = XCAR (results);
|
|
1122 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
1123 /* Duplicate the pixel value so that we still have a lock on it if
|
|
1124 the pixel we were passed is later freed. */
|
|
1125 if (! XAllocColor (dpy, cmap, &color))
|
|
1126 abort (); /* it must be allocable since we're just duplicating it */
|
|
1127
|
14
|
1128 symbols [i].name = (char *) XSTRING_DATA (XCAR (cons));
|
0
|
1129 symbols [i].pixel = color.pixel;
|
|
1130 symbols [i].value = 0;
|
|
1131 free_cons (XCONS (cons));
|
|
1132 cons = results;
|
|
1133 results = XCDR (results);
|
|
1134 free_cons (XCONS (cons));
|
|
1135 }
|
|
1136 return symbols;
|
|
1137 }
|
|
1138
|
|
1139 static void
|
|
1140 xpm_free (XpmAttributes *xpmattrs)
|
|
1141 {
|
|
1142 /* Could conceivably lose if XpmXXX returned an error without first
|
|
1143 initializing this structure, if we didn't know that initializing it
|
|
1144 to all zeros was ok (and also that it's ok to call XpmFreeAttributes()
|
|
1145 multiple times, since it zeros slots as it frees them...) */
|
|
1146 XpmFreeAttributes (xpmattrs);
|
|
1147 }
|
|
1148
|
280
|
1149 static void
|
276
|
1150 x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1151 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1152 int dest_mask, Lisp_Object domain)
|
0
|
1153 {
|
|
1154 /* This function can GC */
|
|
1155 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
276
|
1156 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
0
|
1157 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1158 Display *dpy;
|
|
1159 Screen *xs;
|
219
|
1160 Colormap cmap;
|
|
1161 int depth;
|
280
|
1162 Visual *visual;
|
0
|
1163 Pixmap pixmap;
|
|
1164 Pixmap mask = 0;
|
|
1165 XpmAttributes xpmattrs;
|
|
1166 int result;
|
|
1167 XpmColorSymbol *color_symbols;
|
|
1168 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
1169 Q_color_symbols);
|
|
1170 enum image_instance_type type;
|
|
1171 int force_mono;
|
|
1172 unsigned int w, h;
|
|
1173
|
|
1174 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1175 signal_simple_error ("Not an X device", device);
|
|
1176
|
|
1177 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1178 xs = DefaultScreenOfDisplay (dpy);
|
|
1179
|
|
1180 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1181 type = IMAGE_COLOR_PIXMAP;
|
|
1182 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
1183 type = IMAGE_MONO_PIXMAP;
|
|
1184 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
1185 type = IMAGE_POINTER;
|
|
1186 else
|
|
1187 incompatible_image_types (instantiator, dest_mask,
|
|
1188 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
1189 | IMAGE_POINTER_MASK);
|
|
1190 force_mono = (type != IMAGE_COLOR_PIXMAP);
|
|
1191
|
269
|
1192 #if 1
|
251
|
1193 /* Although I haven't found it documented yet, it appears that pointers are
|
280
|
1194 always colored via the default window colormap... Sigh. */
|
251
|
1195 if (type == IMAGE_POINTER)
|
|
1196 {
|
|
1197 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
|
|
1198 depth = DefaultDepthOfScreen (xs);
|
280
|
1199 visual = DefaultVisualOfScreen (xs);
|
251
|
1200 }
|
|
1201 else
|
|
1202 {
|
|
1203 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
1204 depth = DEVICE_X_DEPTH (XDEVICE(device));
|
280
|
1205 visual = DEVICE_X_VISUAL (XDEVICE(device));
|
251
|
1206 }
|
|
1207 #else
|
|
1208 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
1209 depth = DEVICE_X_DEPTH (XDEVICE(device));
|
280
|
1210 visual = DEVICE_X_VISUAL (XDEVICE(device));
|
251
|
1211 #endif
|
|
1212
|
0
|
1213 x_initialize_pixmap_image_instance (ii, type);
|
|
1214
|
|
1215 assert (!NILP (data));
|
|
1216
|
|
1217 retry:
|
|
1218
|
272
|
1219 xzero (xpmattrs); /* want XpmInitAttributes() */
|
0
|
1220 xpmattrs.valuemask = XpmReturnPixels;
|
|
1221 if (force_mono)
|
|
1222 {
|
|
1223 /* Without this, we get a 1-bit version of the color image, which
|
|
1224 isn't quite right. With this, we get the mono image, which might
|
|
1225 be very different looking. */
|
|
1226 xpmattrs.valuemask |= XpmColorKey;
|
|
1227 xpmattrs.color_key = XPM_MONO;
|
|
1228 xpmattrs.depth = 1;
|
|
1229 xpmattrs.valuemask |= XpmDepth;
|
|
1230 }
|
|
1231 else
|
|
1232 {
|
|
1233 xpmattrs.closeness = 65535;
|
|
1234 xpmattrs.valuemask |= XpmCloseness;
|
219
|
1235 xpmattrs.depth = depth;
|
|
1236 xpmattrs.valuemask |= XpmDepth;
|
280
|
1237 xpmattrs.visual = visual;
|
219
|
1238 xpmattrs.valuemask |= XpmVisual;
|
|
1239 xpmattrs.colormap = cmap;
|
|
1240 xpmattrs.valuemask |= XpmColormap;
|
0
|
1241 }
|
185
|
1242
|
124
|
1243 color_symbols = extract_xpm_color_names (&xpmattrs, device, domain,
|
0
|
1244 color_symbol_alist);
|
|
1245
|
|
1246 result = XpmCreatePixmapFromBuffer (dpy,
|
219
|
1247 XtWindow(DEVICE_XT_APP_SHELL (XDEVICE(device))),
|
14
|
1248 (char *) XSTRING_DATA (data),
|
0
|
1249 &pixmap, &mask, &xpmattrs);
|
|
1250
|
|
1251 if (color_symbols)
|
|
1252 {
|
|
1253 xfree (color_symbols);
|
|
1254 xpmattrs.colorsymbols = 0; /* in case XpmFreeAttr is too smart... */
|
|
1255 xpmattrs.numsymbols = 0;
|
|
1256 }
|
|
1257
|
|
1258 switch (result)
|
|
1259 {
|
|
1260 case XpmSuccess:
|
|
1261 break;
|
|
1262 case XpmFileInvalid:
|
|
1263 {
|
|
1264 xpm_free (&xpmattrs);
|
269
|
1265 signal_image_error ("invalid XPM data", data);
|
0
|
1266 }
|
|
1267 case XpmColorFailed:
|
|
1268 case XpmColorError:
|
|
1269 {
|
|
1270 xpm_free (&xpmattrs);
|
|
1271 if (force_mono)
|
|
1272 {
|
|
1273 /* second time; blow out. */
|
|
1274 signal_double_file_error ("Reading pixmap data",
|
|
1275 "color allocation failed",
|
|
1276 data);
|
|
1277 }
|
|
1278 else
|
|
1279 {
|
|
1280 if (! (dest_mask & IMAGE_MONO_PIXMAP_MASK))
|
|
1281 {
|
|
1282 /* second time; blow out. */
|
|
1283 signal_double_file_error ("Reading pixmap data",
|
|
1284 "color allocation failed",
|
|
1285 data);
|
|
1286 }
|
|
1287 force_mono = 1;
|
|
1288 IMAGE_INSTANCE_TYPE (ii) = IMAGE_MONO_PIXMAP;
|
|
1289 goto retry;
|
|
1290 }
|
|
1291 }
|
|
1292 case XpmNoMemory:
|
|
1293 {
|
|
1294 xpm_free (&xpmattrs);
|
|
1295 signal_double_file_error ("Parsing pixmap data",
|
|
1296 "out of memory", data);
|
|
1297 }
|
|
1298 default:
|
|
1299 {
|
|
1300 xpm_free (&xpmattrs);
|
|
1301 signal_double_file_error_2 ("Parsing pixmap data",
|
|
1302 "unknown error code",
|
|
1303 make_int (result), data);
|
|
1304 }
|
|
1305 }
|
|
1306
|
|
1307 w = xpmattrs.width;
|
|
1308 h = xpmattrs.height;
|
|
1309
|
|
1310 {
|
|
1311 int npixels = xpmattrs.npixels;
|
185
|
1312 Pixel *pixels;
|
0
|
1313
|
|
1314 if (npixels != 0)
|
|
1315 {
|
185
|
1316 pixels = xnew_array (Pixel, npixels);
|
0
|
1317 memcpy (pixels, xpmattrs.pixels, npixels * sizeof (Pixel));
|
|
1318 }
|
|
1319 else
|
185
|
1320 pixels = NULL;
|
0
|
1321
|
|
1322 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
1323 IMAGE_INSTANCE_X_MASK (ii) = mask;
|
269
|
1324 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap;
|
0
|
1325 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
1326 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
1327 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
|
|
1328 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
|
|
1329 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
1330 find_keyword_in_vector (instantiator, Q_file);
|
|
1331 }
|
|
1332
|
|
1333 switch (type)
|
|
1334 {
|
|
1335 case IMAGE_MONO_PIXMAP:
|
|
1336 break;
|
|
1337
|
|
1338 case IMAGE_COLOR_PIXMAP:
|
|
1339 {
|
219
|
1340 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
|
0
|
1341 }
|
|
1342 break;
|
|
1343
|
|
1344 case IMAGE_POINTER:
|
|
1345 {
|
|
1346 int npixels = xpmattrs.npixels;
|
|
1347 Pixel *pixels = xpmattrs.pixels;
|
|
1348 XColor fg, bg;
|
|
1349 int i;
|
|
1350 int xhot = 0, yhot = 0;
|
|
1351
|
|
1352 if (xpmattrs.valuemask & XpmHotspot)
|
|
1353 {
|
|
1354 xhot = xpmattrs.x_hotspot;
|
|
1355 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), xpmattrs.x_hotspot);
|
|
1356 }
|
|
1357 if (xpmattrs.valuemask & XpmHotspot)
|
|
1358 {
|
|
1359 yhot = xpmattrs.y_hotspot;
|
|
1360 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), xpmattrs.y_hotspot);
|
|
1361 }
|
|
1362 check_pointer_sizes (xs, w, h, instantiator);
|
|
1363
|
|
1364 /* If the loaded pixmap has colors allocated (meaning it came from an
|
|
1365 XPM file), then use those as the default colors for the cursor we
|
|
1366 create. Otherwise, default to pointer_fg and pointer_bg.
|
|
1367 */
|
|
1368 if (npixels >= 2)
|
|
1369 {
|
|
1370 /* With an XBM file, it's obvious which bit is foreground
|
|
1371 and which is background, or rather, it's implicit: in
|
|
1372 an XBM file, a 1 bit is foreground, and a 0 bit is
|
|
1373 background.
|
185
|
1374
|
0
|
1375 XCreatePixmapCursor() assumes this property of the
|
|
1376 pixmap it is called with as well; the `foreground'
|
|
1377 color argument is used for the 1 bits.
|
|
1378
|
|
1379 With an XPM file, it's tricker, since the elements of
|
|
1380 the pixmap don't represent FG and BG, but are actual
|
|
1381 pixel values. So we need to figure out which of those
|
|
1382 pixels is the foreground color and which is the
|
|
1383 background. We do it by comparing RGB and assuming
|
|
1384 that the darker color is the foreground. This works
|
|
1385 with the result of xbmtopbm|ppmtoxpm, at least.
|
185
|
1386
|
0
|
1387 It might be nice if there was some way to tag the
|
|
1388 colors in the XPM file with whether they are the
|
|
1389 foreground - perhaps with logical color names somehow?
|
185
|
1390
|
0
|
1391 Once we have decided which color is the foreground, we
|
|
1392 need to ensure that that color corresponds to a `1' bit
|
|
1393 in the Pixmap. The XPM library wrote into the (1-bit)
|
|
1394 pixmap with XPutPixel, which will ignore all but the
|
|
1395 least significant bit.
|
185
|
1396
|
0
|
1397 This means that a 1 bit in the image corresponds to
|
|
1398 `fg' only if `fg.pixel' is odd.
|
185
|
1399
|
0
|
1400 (This also means that the image will be all the same
|
|
1401 color if both `fg' and `bg' are odd or even, but we can
|
|
1402 safely assume that that won't happen if the XPM file is
|
|
1403 sensible I think.)
|
185
|
1404
|
0
|
1405 The desired result is that the image use `1' to
|
|
1406 represent the foreground color, and `0' to represent
|
|
1407 the background color. So, we may need to invert the
|
|
1408 image to accomplish this; we invert if fg is
|
|
1409 odd. (Remember that WhitePixel and BlackPixel are not
|
|
1410 necessarily 1 and 0 respectively, though I think it
|
|
1411 might be safe to assume that one of them is always 1
|
|
1412 and the other is always 0. We also pretty much need to
|
|
1413 assume that one is even and the other is odd.)
|
|
1414 */
|
|
1415
|
|
1416 fg.pixel = pixels[0]; /* pick a pixel at random. */
|
|
1417 bg.pixel = fg.pixel;
|
|
1418 for (i = 1; i < npixels; i++) /* Look for an "other" pixel value.*/
|
|
1419 {
|
|
1420 bg.pixel = pixels[i];
|
|
1421 if (fg.pixel != bg.pixel)
|
|
1422 break;
|
|
1423 }
|
|
1424
|
|
1425 /* If (fg.pixel == bg.pixel) then probably something has
|
|
1426 gone wrong, but I don't think signalling an error would
|
|
1427 be appropriate. */
|
|
1428
|
219
|
1429 XQueryColor (dpy, cmap, &fg);
|
|
1430 XQueryColor (dpy, cmap, &bg);
|
0
|
1431
|
|
1432 /* If the foreground is lighter than the background, swap them.
|
|
1433 (This occurs semi-randomly, depending on the ordering of the
|
|
1434 color list in the XPM file.)
|
|
1435 */
|
|
1436 {
|
|
1437 unsigned short fg_total = ((fg.red / 3) + (fg.green / 3)
|
|
1438 + (fg.blue / 3));
|
|
1439 unsigned short bg_total = ((bg.red / 3) + (bg.green / 3)
|
|
1440 + (bg.blue / 3));
|
|
1441 if (fg_total > bg_total)
|
|
1442 {
|
|
1443 XColor swap;
|
|
1444 swap = fg;
|
|
1445 fg = bg;
|
|
1446 bg = swap;
|
|
1447 }
|
|
1448 }
|
185
|
1449
|
0
|
1450 /* If the fg pixel corresponds to a `0' in the bitmap, invert it.
|
|
1451 (This occurs (only?) on servers with Black=0, White=1.)
|
|
1452 */
|
|
1453 if ((fg.pixel & 1) == 0)
|
|
1454 {
|
|
1455 XGCValues gcv;
|
|
1456 GC gc;
|
|
1457 gcv.function = GXxor;
|
|
1458 gcv.foreground = 1;
|
|
1459 gc = XCreateGC (dpy, pixmap, (GCFunction | GCForeground),
|
|
1460 &gcv);
|
|
1461 XFillRectangle (dpy, pixmap, gc, 0, 0, w, h);
|
|
1462 XFreeGC (dpy, gc);
|
|
1463 }
|
|
1464 }
|
|
1465 else
|
|
1466 {
|
|
1467 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg,
|
|
1468 &fg, &bg);
|
|
1469 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg;
|
|
1470 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg;
|
|
1471 }
|
|
1472
|
|
1473 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1474 XCreatePixmapCursor
|
|
1475 (dpy, pixmap, mask, &fg, &bg, xhot, yhot);
|
|
1476 }
|
|
1477
|
|
1478 break;
|
|
1479
|
|
1480 default:
|
|
1481 abort ();
|
|
1482 }
|
185
|
1483
|
0
|
1484 xpm_free (&xpmattrs); /* after we've read pixels and hotspot */
|
|
1485 }
|
|
1486
|
|
1487 #endif /* HAVE_XPM */
|
|
1488
|
|
1489
|
|
1490 #ifdef HAVE_XFACE
|
|
1491
|
|
1492 /**********************************************************************
|
|
1493 * X-Face *
|
|
1494 **********************************************************************/
|
|
1495
|
|
1496 static void
|
|
1497 xface_validate (Lisp_Object instantiator)
|
|
1498 {
|
|
1499 file_or_data_must_be_present (instantiator);
|
|
1500 }
|
|
1501
|
|
1502 static Lisp_Object
|
|
1503 xface_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1504 {
|
116
|
1505 /* This funcation can call lisp */
|
0
|
1506 Lisp_Object file = Qnil, mask_file = Qnil;
|
|
1507 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1508 Lisp_Object alist = Qnil;
|
185
|
1509
|
0
|
1510 GCPRO3 (file, mask_file, alist);
|
|
1511
|
|
1512 /* Now, convert any file data into inline data for both the regular
|
|
1513 data and the mask data. At the end of this, `data' will contain
|
|
1514 the inline data (if any) or Qnil, and `file' will contain
|
|
1515 the name this data was derived from (if known) or Qnil.
|
|
1516 Likewise for `mask_file' and `mask_data'.
|
|
1517
|
|
1518 Note that if we cannot generate any regular inline data, we
|
|
1519 skip out. */
|
|
1520
|
278
|
1521 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data,
|
|
1522 console_type);
|
0
|
1523 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
|
278
|
1524 Q_mask_data, console_type);
|
0
|
1525
|
|
1526 if (CONSP (file)) /* failure locating filename */
|
|
1527 signal_double_file_error ("Opening bitmap file",
|
|
1528 "no such file or directory",
|
|
1529 Fcar (file));
|
|
1530
|
|
1531 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
|
|
1532 RETURN_UNGCPRO (inst);
|
|
1533
|
|
1534 alist = tagged_vector_to_alist (inst);
|
|
1535
|
|
1536 {
|
|
1537 Lisp_Object data = make_string_from_file (file);
|
|
1538 alist = remassq_no_quit (Q_file, alist);
|
|
1539 /* there can't be a :data at this point. */
|
|
1540 alist = Fcons (Fcons (Q_file, file),
|
|
1541 Fcons (Fcons (Q_data, data), alist));
|
|
1542 }
|
|
1543
|
288
|
1544 alist = xbm_mask_file_munging (alist, file, mask_file, console_type);
|
0
|
1545
|
|
1546 {
|
|
1547 Lisp_Object result = alist_to_tagged_vector (Qxface, alist);
|
|
1548 free_alist (alist);
|
|
1549 RETURN_UNGCPRO (result);
|
|
1550 }
|
|
1551 }
|
|
1552
|
|
1553 static int
|
74
|
1554 xface_possible_dest_types (void)
|
0
|
1555 {
|
74
|
1556 return
|
|
1557 IMAGE_MONO_PIXMAP_MASK |
|
|
1558 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
1559 IMAGE_POINTER_MASK;
|
|
1560 }
|
|
1561
|
|
1562 #if defined(EXTERN)
|
|
1563 /* This is about to get redefined! */
|
|
1564 #undef EXTERN
|
|
1565 #endif
|
|
1566 /* We have to define SYSV32 so that compface.h includes string.h
|
|
1567 instead of strings.h. */
|
|
1568 #define SYSV32
|
185
|
1569 #ifdef __cplusplus
|
|
1570 extern "C" {
|
|
1571 #endif
|
0
|
1572 #include <compface.h>
|
185
|
1573 #ifdef __cplusplus
|
|
1574 }
|
|
1575 #endif
|
0
|
1576 /* JMP_BUF cannot be used here because if it doesn't get defined
|
|
1577 to jmp_buf we end up with a conflicting type error with the
|
|
1578 definition in compface.h */
|
|
1579 extern jmp_buf comp_env;
|
|
1580 #undef SYSV32
|
|
1581
|
|
1582 static void
|
|
1583 xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1584 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1585 int dest_mask, Lisp_Object domain)
|
0
|
1586 {
|
|
1587 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1588 int i, stattis;
|
|
1589 char *p, *bits, *bp;
|
16
|
1590 CONST char * volatile emsg = 0;
|
|
1591 CONST char * volatile dstring;
|
0
|
1592
|
|
1593 assert (!NILP (data));
|
|
1594
|
|
1595 GET_C_STRING_BINARY_DATA_ALLOCA (data, dstring);
|
|
1596
|
|
1597 if ((p = strchr (dstring, ':')))
|
|
1598 {
|
|
1599 dstring = p + 1;
|
|
1600 }
|
|
1601
|
|
1602 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
1603 if (!(stattis = setjmp (comp_env)))
|
|
1604 {
|
|
1605 UnCompAll ((char *) dstring);
|
|
1606 UnGenFace ();
|
|
1607 }
|
|
1608
|
|
1609 switch (stattis)
|
|
1610 {
|
|
1611 case -2:
|
|
1612 emsg = "uncompface: internal error";
|
|
1613 break;
|
|
1614 case -1:
|
|
1615 emsg = "uncompface: insufficient or invalid data";
|
|
1616 break;
|
|
1617 case 1:
|
|
1618 emsg = "uncompface: excess data ignored";
|
|
1619 break;
|
|
1620 }
|
|
1621
|
|
1622 if (emsg)
|
|
1623 signal_simple_error_2 (emsg, data, Qimage);
|
|
1624
|
|
1625 bp = bits = (char *) alloca (PIXELS / 8);
|
|
1626
|
|
1627 /* the compface library exports char F[], which uses a single byte per
|
|
1628 pixel to represent a 48x48 bitmap. Yuck. */
|
|
1629 for (i = 0, p = F; i < (PIXELS / 8); ++i)
|
|
1630 {
|
|
1631 int n, b;
|
|
1632 /* reverse the bit order of each byte... */
|
|
1633 for (b = n = 0; b < 8; ++b)
|
|
1634 {
|
|
1635 n |= ((*p++) << b);
|
|
1636 }
|
|
1637 *bp++ = (char) n;
|
|
1638 }
|
|
1639
|
|
1640 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1641 pointer_bg, dest_mask, 48, 48, bits);
|
|
1642 }
|
|
1643
|
|
1644 #endif /* HAVE_XFACE */
|
|
1645
|
|
1646
|
|
1647 /**********************************************************************
|
122
|
1648 * Autodetect *
|
0
|
1649 **********************************************************************/
|
|
1650
|
|
1651 static void
|
122
|
1652 autodetect_validate (Lisp_Object instantiator)
|
0
|
1653 {
|
|
1654 data_must_be_present (instantiator);
|
|
1655 }
|
|
1656
|
|
1657 static Lisp_Object
|
122
|
1658 autodetect_normalize (Lisp_Object instantiator,
|
120
|
1659 Lisp_Object console_type)
|
0
|
1660 {
|
|
1661 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
1662 Lisp_Object filename = Qnil;
|
|
1663 Lisp_Object data = Qnil;
|
|
1664 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1665 Lisp_Object alist = Qnil;
|
|
1666
|
|
1667 GCPRO3 (filename, data, alist);
|
|
1668
|
|
1669 if (NILP (file)) /* no conversion necessary */
|
|
1670 RETURN_UNGCPRO (instantiator);
|
|
1671
|
|
1672 alist = tagged_vector_to_alist (instantiator);
|
|
1673
|
|
1674 filename = locate_pixmap_file (file);
|
|
1675 if (!NILP (filename))
|
|
1676 {
|
|
1677 int xhot, yhot;
|
|
1678 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
1679 called by pixmap_to_lisp_data, don't return an error value
|
|
1680 if the given file is not a valid XPM file. Instead, they
|
|
1681 just seg fault. It is definitely caused by passing a
|
|
1682 bitmap. To try and avoid this we check for bitmaps first. */
|
185
|
1683
|
0
|
1684 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
1685
|
|
1686 if (!EQ (data, Qt))
|
|
1687 {
|
|
1688 alist = remassq_no_quit (Q_data, alist);
|
|
1689 alist = Fcons (Fcons (Q_file, filename),
|
|
1690 Fcons (Fcons (Q_data, data), alist));
|
|
1691 if (xhot != -1)
|
|
1692 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
1693 alist);
|
|
1694 if (yhot != -1)
|
|
1695 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
1696 alist);
|
|
1697
|
288
|
1698 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type);
|
0
|
1699
|
|
1700 {
|
|
1701 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
1702 free_alist (alist);
|
|
1703 RETURN_UNGCPRO (result);
|
|
1704 }
|
|
1705 }
|
|
1706
|
|
1707 #ifdef HAVE_XPM
|
|
1708 data = pixmap_to_lisp_data (filename, 1);
|
|
1709
|
|
1710 if (!EQ (data, Qt))
|
|
1711 {
|
|
1712 alist = remassq_no_quit (Q_data, alist);
|
|
1713 alist = Fcons (Fcons (Q_file, filename),
|
|
1714 Fcons (Fcons (Q_data, data), alist));
|
|
1715 alist = Fcons (Fcons (Q_color_symbols,
|
|
1716 evaluate_xpm_color_symbols ()),
|
|
1717 alist);
|
|
1718 {
|
|
1719 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1720 free_alist (alist);
|
|
1721 RETURN_UNGCPRO (result);
|
|
1722 }
|
|
1723 }
|
|
1724 #endif
|
|
1725 }
|
|
1726
|
|
1727 /* If we couldn't convert it, just put it back as it is.
|
|
1728 We might try to further frob it later as a cursor-font
|
|
1729 specification. (We can't do that now because we don't know
|
|
1730 what dest-types it's going to be instantiated into.) */
|
|
1731 {
|
122
|
1732 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
0
|
1733 free_alist (alist);
|
|
1734 RETURN_UNGCPRO (result);
|
|
1735 }
|
|
1736 }
|
|
1737
|
|
1738 static int
|
122
|
1739 autodetect_possible_dest_types (void)
|
0
|
1740 {
|
74
|
1741 return
|
|
1742 IMAGE_MONO_PIXMAP_MASK |
|
|
1743 IMAGE_COLOR_PIXMAP_MASK |
|
|
1744 IMAGE_POINTER_MASK |
|
|
1745 IMAGE_TEXT_MASK;
|
0
|
1746 }
|
|
1747
|
|
1748 static void
|
122
|
1749 autodetect_instantiate (Lisp_Object image_instance,
|
120
|
1750 Lisp_Object instantiator,
|
|
1751 Lisp_Object pointer_fg,
|
|
1752 Lisp_Object pointer_bg,
|
124
|
1753 int dest_mask, Lisp_Object domain)
|
0
|
1754 {
|
|
1755 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1756 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1757 Lisp_Object alist = Qnil;
|
|
1758 Lisp_Object result = Qnil;
|
|
1759 int is_cursor_font = 0;
|
|
1760
|
|
1761 GCPRO3 (data, alist, result);
|
|
1762
|
|
1763 alist = tagged_vector_to_alist (instantiator);
|
|
1764 if (dest_mask & IMAGE_POINTER_MASK)
|
|
1765 {
|
|
1766 CONST char *name_ext;
|
|
1767 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext);
|
|
1768 if (XmuCursorNameToIndex (name_ext) != -1)
|
|
1769 {
|
|
1770 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
1771 is_cursor_font = 1;
|
|
1772 }
|
|
1773 }
|
|
1774
|
|
1775 if (!is_cursor_font)
|
|
1776 result = alist_to_tagged_vector (Qstring, alist);
|
|
1777 free_alist (alist);
|
|
1778
|
|
1779 if (is_cursor_font)
|
|
1780 cursor_font_instantiate (image_instance, result, pointer_fg,
|
124
|
1781 pointer_bg, dest_mask, domain);
|
0
|
1782 else
|
|
1783 string_instantiate (image_instance, result, pointer_fg,
|
124
|
1784 pointer_bg, dest_mask, domain);
|
0
|
1785
|
|
1786 UNGCPRO;
|
|
1787 }
|
|
1788
|
|
1789
|
|
1790 /**********************************************************************
|
|
1791 * Font *
|
|
1792 **********************************************************************/
|
|
1793
|
|
1794 static void
|
|
1795 font_validate (Lisp_Object instantiator)
|
|
1796 {
|
|
1797 data_must_be_present (instantiator);
|
|
1798 }
|
|
1799
|
|
1800 /* XmuCvtStringToCursor is bogus in the following ways:
|
|
1801
|
|
1802 - When it can't convert the given string to a real cursor, it will
|
|
1803 sometimes return a "success" value, after triggering a BadPixmap
|
|
1804 error. It then gives you a cursor that will itself generate BadCursor
|
|
1805 errors. So we install this error handler to catch/notice the X error
|
|
1806 and take that as meaning "couldn't convert."
|
|
1807
|
|
1808 - When you tell it to find a cursor file that doesn't exist, it prints
|
|
1809 an error message on stderr. You can't make it not do that.
|
|
1810
|
|
1811 - Also, using Xmu means we can't properly hack Lisp_Image_Instance
|
|
1812 objects, or XPM files, or $XBMLANGPATH.
|
|
1813 */
|
|
1814
|
|
1815 /* Duplicate the behavior of XmuCvtStringToCursor() to bypass its bogusness. */
|
|
1816
|
|
1817 static int XLoadFont_got_error;
|
|
1818
|
|
1819 static int
|
|
1820 XLoadFont_error_handler (Display *dpy, XErrorEvent *xerror)
|
|
1821 {
|
|
1822 XLoadFont_got_error = 1;
|
|
1823 return 0;
|
|
1824 }
|
|
1825
|
|
1826 static Font
|
|
1827 safe_XLoadFont (Display *dpy, char *name)
|
|
1828 {
|
|
1829 Font font;
|
|
1830 int (*old_handler) (Display *, XErrorEvent *);
|
|
1831 XLoadFont_got_error = 0;
|
|
1832 XSync (dpy, 0);
|
|
1833 old_handler = XSetErrorHandler (XLoadFont_error_handler);
|
|
1834 font = XLoadFont (dpy, name);
|
|
1835 XSync (dpy, 0);
|
|
1836 XSetErrorHandler (old_handler);
|
|
1837 if (XLoadFont_got_error) return 0;
|
|
1838 return font;
|
|
1839 }
|
|
1840
|
|
1841 static int
|
74
|
1842 font_possible_dest_types (void)
|
0
|
1843 {
|
|
1844 return IMAGE_POINTER_MASK;
|
|
1845 }
|
|
1846
|
|
1847 static void
|
|
1848 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1849 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1850 int dest_mask, Lisp_Object domain)
|
0
|
1851 {
|
|
1852 /* This function can GC */
|
|
1853 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1854 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1855 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1856 Display *dpy;
|
|
1857 XColor fg, bg;
|
|
1858 Font source, mask;
|
|
1859 char source_name[MAXPATHLEN], mask_name[MAXPATHLEN], dummy;
|
|
1860 int source_char, mask_char;
|
|
1861 int count;
|
|
1862 Lisp_Object foreground, background;
|
|
1863
|
|
1864 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1865 signal_simple_error ("Not an X device", device);
|
|
1866
|
|
1867 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1868
|
|
1869 if (!STRINGP (data) ||
|
14
|
1870 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
0
|
1871 signal_simple_error ("Invalid font-glyph instantiator",
|
|
1872 instantiator);
|
|
1873
|
|
1874 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1875 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1876
|
|
1877 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1878 if (NILP (foreground))
|
|
1879 foreground = pointer_fg;
|
|
1880 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1881 if (NILP (background))
|
|
1882 background = pointer_bg;
|
|
1883
|
|
1884 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
1885
|
14
|
1886 count = sscanf ((char *) XSTRING_DATA (data),
|
0
|
1887 "FONT %s %d %s %d %c",
|
|
1888 source_name, &source_char,
|
|
1889 mask_name, &mask_char, &dummy);
|
|
1890 /* Allow "%s %d %d" as well... */
|
|
1891 if (count == 3 && (1 == sscanf (mask_name, "%d %c", &mask_char, &dummy)))
|
|
1892 count = 4, mask_name[0] = 0;
|
|
1893
|
|
1894 if (count != 2 && count != 4)
|
|
1895 signal_simple_error ("invalid cursor specification", data);
|
|
1896 source = safe_XLoadFont (dpy, source_name);
|
|
1897 if (! source)
|
|
1898 signal_simple_error_2 ("couldn't load font",
|
|
1899 build_string (source_name),
|
|
1900 data);
|
|
1901 if (count == 2)
|
|
1902 mask = 0;
|
|
1903 else if (!mask_name[0])
|
|
1904 mask = source;
|
|
1905 else
|
|
1906 {
|
|
1907 mask = safe_XLoadFont (dpy, mask_name);
|
|
1908 if (!mask)
|
|
1909 /* continuable */
|
|
1910 Fsignal (Qerror, list3 (build_string ("couldn't load font"),
|
|
1911 build_string (mask_name), data));
|
|
1912 }
|
|
1913 if (!mask)
|
|
1914 mask_char = 0;
|
|
1915
|
|
1916 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
1917
|
|
1918 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER);
|
|
1919 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1920 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
1921 &fg, &bg);
|
|
1922 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
1923 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
1924 XUnloadFont (dpy, source);
|
|
1925 if (mask && mask != source) XUnloadFont (dpy, mask);
|
|
1926 }
|
|
1927
|
|
1928
|
|
1929 /**********************************************************************
|
|
1930 * Cursor-Font *
|
|
1931 **********************************************************************/
|
|
1932
|
|
1933 static void
|
|
1934 cursor_font_validate (Lisp_Object instantiator)
|
|
1935 {
|
|
1936 data_must_be_present (instantiator);
|
|
1937 }
|
|
1938
|
|
1939 static int
|
74
|
1940 cursor_font_possible_dest_types (void)
|
0
|
1941 {
|
|
1942 return IMAGE_POINTER_MASK;
|
|
1943 }
|
|
1944
|
|
1945 static void
|
|
1946 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1947 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1948 int dest_mask, Lisp_Object domain)
|
0
|
1949 {
|
|
1950 /* This function can GC */
|
|
1951 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1952 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1953 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1954 Display *dpy;
|
|
1955 int i;
|
|
1956 CONST char *name_ext;
|
|
1957 Lisp_Object foreground, background;
|
|
1958
|
|
1959 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1960 signal_simple_error ("Not an X device", device);
|
|
1961
|
|
1962 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1963
|
|
1964 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1965 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1966
|
|
1967 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext);
|
|
1968 if ((i = XmuCursorNameToIndex (name_ext)) == -1)
|
|
1969 signal_simple_error ("Unrecognized cursor-font name", data);
|
|
1970
|
|
1971 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER);
|
|
1972 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i);
|
|
1973 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1974 if (NILP (foreground))
|
|
1975 foreground = pointer_fg;
|
|
1976 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1977 if (NILP (background))
|
|
1978 background = pointer_bg;
|
|
1979 maybe_recolor_cursor (image_instance, foreground, background);
|
|
1980 }
|
|
1981
|
|
1982 static int
|
|
1983 x_colorize_image_instance (Lisp_Object image_instance,
|
|
1984 Lisp_Object foreground, Lisp_Object background)
|
|
1985 {
|
|
1986 struct Lisp_Image_Instance *p;
|
|
1987
|
|
1988 p = XIMAGE_INSTANCE (image_instance);
|
|
1989
|
|
1990 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1991 {
|
|
1992 case IMAGE_MONO_PIXMAP:
|
|
1993 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
1994 /* Make sure there aren't two pointers to the same mask, causing
|
|
1995 it to get freed twice. */
|
|
1996 IMAGE_INSTANCE_X_MASK (p) = 0;
|
|
1997 break;
|
|
1998
|
|
1999 default:
|
|
2000 return 0;
|
|
2001 }
|
|
2002
|
|
2003 {
|
|
2004 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
219
|
2005 Drawable draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
2006 Dimension d = DEVICE_X_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
2007 Pixmap new = XCreatePixmap (dpy, draw,
|
0
|
2008 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2009 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d);
|
|
2010 XColor color;
|
|
2011 XGCValues gcv;
|
|
2012 GC gc;
|
|
2013 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground));
|
|
2014 gcv.foreground = color.pixel;
|
|
2015 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background));
|
|
2016 gcv.background = color.pixel;
|
|
2017 gc = XCreateGC (dpy, new, GCBackground|GCForeground, &gcv);
|
|
2018 XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP (p), new, gc, 0, 0,
|
|
2019 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2020 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2021 0, 0, 1);
|
|
2022 XFreeGC (dpy, gc);
|
|
2023 IMAGE_INSTANCE_X_PIXMAP (p) = new;
|
|
2024 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = d;
|
|
2025 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
2026 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
2027 return 1;
|
|
2028 }
|
|
2029 }
|
|
2030
|
|
2031
|
114
|
2032 #if HAVE_SUBWINDOWS
|
0
|
2033 /************************************************************************/
|
|
2034 /* subwindows */
|
|
2035 /************************************************************************/
|
|
2036
|
|
2037 Lisp_Object Qsubwindowp;
|
|
2038
|
|
2039 static Lisp_Object
|
|
2040 mark_subwindow (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2041 {
|
|
2042 struct Lisp_Subwindow *sw = XSUBWINDOW (obj);
|
|
2043 return sw->frame;
|
|
2044 }
|
|
2045
|
|
2046 static void
|
|
2047 print_subwindow (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
2048 {
|
|
2049 char buf[100];
|
|
2050 struct Lisp_Subwindow *sw = XSUBWINDOW (obj);
|
|
2051 struct frame *frm = XFRAME (sw->frame);
|
|
2052
|
|
2053 if (print_readably)
|
|
2054 error ("printing unreadable object #<subwindow 0x%x>",
|
|
2055 sw->header.uid);
|
|
2056
|
|
2057 write_c_string ("#<subwindow", printcharfun);
|
|
2058 sprintf (buf, " %dx%d", sw->width, sw->height);
|
|
2059 write_c_string (buf, printcharfun);
|
|
2060
|
|
2061 /* This is stolen from frame.c. Subwindows are strange in that they
|
|
2062 are specific to a particular frame so we want to print in their
|
|
2063 description what that frame is. */
|
185
|
2064
|
0
|
2065 write_c_string (" on #<", printcharfun);
|
|
2066 if (!FRAME_LIVE_P (frm))
|
|
2067 write_c_string ("dead", printcharfun);
|
|
2068 else if (FRAME_TTY_P (frm))
|
|
2069 write_c_string ("tty", printcharfun);
|
|
2070 else if (FRAME_X_P (frm))
|
|
2071 write_c_string ("x", printcharfun);
|
|
2072 else
|
|
2073 write_c_string ("UNKNOWN", printcharfun);
|
|
2074 write_c_string ("-frame ", printcharfun);
|
|
2075 print_internal (frm->name, printcharfun, 1);
|
|
2076 sprintf (buf, " 0x%x>", frm->header.uid);
|
|
2077 write_c_string (buf, printcharfun);
|
|
2078
|
|
2079 sprintf (buf, ") 0x%x>", sw->header.uid);
|
|
2080 write_c_string (buf, printcharfun);
|
|
2081 }
|
|
2082
|
|
2083 static void
|
|
2084 finalize_subwindow (void *header, int for_disksave)
|
|
2085 {
|
|
2086 struct Lisp_Subwindow *sw = (struct Lisp_Subwindow *) header;
|
|
2087 if (for_disksave) finalose (sw);
|
|
2088 if (sw->subwindow)
|
|
2089 {
|
|
2090 XDestroyWindow (DisplayOfScreen (sw->xscreen), sw->subwindow);
|
|
2091 sw->subwindow = 0;
|
|
2092 }
|
|
2093 }
|
|
2094
|
|
2095 /* subwindows are equal iff they have the same window XID */
|
|
2096 static int
|
|
2097 subwindow_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2098 {
|
|
2099 return (XSUBWINDOW (o1)->subwindow == XSUBWINDOW (o2)->subwindow);
|
|
2100 }
|
|
2101
|
|
2102 static unsigned long
|
|
2103 subwindow_hash (Lisp_Object obj, int depth)
|
|
2104 {
|
|
2105 return XSUBWINDOW (obj)->subwindow;
|
|
2106 }
|
|
2107
|
272
|
2108 DEFINE_LRECORD_IMPLEMENTATION ("subwindow", subwindow,
|
|
2109 mark_subwindow, print_subwindow,
|
|
2110 finalize_subwindow, subwindow_equal,
|
|
2111 subwindow_hash, struct Lisp_Subwindow);
|
|
2112
|
0
|
2113 /* #### PROBLEM: The display routines assume that the glyph is only
|
|
2114 being displayed in one buffer. If it is in two different buffers
|
|
2115 which are both being displayed simultaneously you will lose big time.
|
|
2116 This can be dealt with in the new redisplay. */
|
|
2117
|
70
|
2118 /* #### These are completely un-re-implemented in 19.14. Get it done
|
|
2119 for 19.15. */
|
0
|
2120
|
20
|
2121 DEFUN ("make-subwindow", Fmake_subwindow, 0, 3, 0, /*
|
0
|
2122 Creates a new `subwindow' object of size WIDTH x HEIGHT.
|
|
2123 The default is a window of size 1x1, which is also the minimum allowed
|
|
2124 window size. Subwindows are per-frame. A buffer being shown in two
|
|
2125 different frames will only display a subwindow glyph in the frame in
|
|
2126 which it was actually created. If two windows on the same frame are
|
|
2127 displaying the buffer then the most recently used window will actually
|
|
2128 display the window. If the frame is not specified, the selected frame
|
|
2129 is used.
|
|
2130
|
|
2131 Subwindows are not currently implemented.
|
20
|
2132 */
|
|
2133 (width, height, frame))
|
0
|
2134 {
|
|
2135 Display *dpy;
|
|
2136 Screen *xs;
|
|
2137 Window pw;
|
|
2138 struct frame *f;
|
|
2139 unsigned int iw, ih;
|
|
2140 XSetWindowAttributes xswa;
|
|
2141 Mask valueMask = 0;
|
|
2142
|
140
|
2143 error ("subwindows are not functional in 20.2; they may be again someday");
|
0
|
2144
|
|
2145 f = decode_x_frame (frame);
|
|
2146
|
|
2147 xs = LISP_DEVICE_TO_X_SCREEN (FRAME_DEVICE (f));
|
|
2148 dpy = DisplayOfScreen (xs);
|
|
2149 pw = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2150
|
|
2151 if (NILP (width))
|
|
2152 iw = 1;
|
|
2153 else
|
|
2154 {
|
|
2155 CHECK_INT (width);
|
|
2156 iw = XINT (width);
|
|
2157 if (iw < 1) iw = 1;
|
|
2158 }
|
|
2159 if (NILP (height))
|
|
2160 ih = 1;
|
|
2161 else
|
|
2162 {
|
|
2163 CHECK_INT (height);
|
|
2164 ih = XINT (height);
|
|
2165 if (ih < 1) ih = 1;
|
|
2166 }
|
|
2167
|
|
2168 {
|
185
|
2169 struct Lisp_Subwindow *sw =
|
|
2170 alloc_lcrecord_type (struct Lisp_Subwindow, lrecord_subwindow);
|
0
|
2171 Lisp_Object val;
|
|
2172 sw->frame = frame;
|
|
2173 sw->xscreen = xs;
|
|
2174 sw->parent_window = pw;
|
|
2175 sw->height = ih;
|
|
2176 sw->width = iw;
|
|
2177
|
|
2178 xswa.backing_store = Always;
|
|
2179 valueMask |= CWBackingStore;
|
|
2180
|
|
2181 xswa.colormap = DefaultColormapOfScreen (xs);
|
|
2182 valueMask |= CWColormap;
|
|
2183
|
|
2184 sw->subwindow = XCreateWindow (dpy, pw, 0, 0, iw, ih, 0, CopyFromParent,
|
|
2185 InputOutput, CopyFromParent, valueMask,
|
|
2186 &xswa);
|
|
2187
|
|
2188 XSETSUBWINDOW (val, sw);
|
|
2189 return val;
|
|
2190 }
|
|
2191 }
|
|
2192
|
|
2193 /* #### Should this function exist? */
|
20
|
2194 DEFUN ("change-subwindow-property", Fchange_subwindow_property, 3, 3, 0, /*
|
0
|
2195 For the given SUBWINDOW, set PROPERTY to DATA, which is a string.
|
|
2196 Subwindows are not currently implemented.
|
20
|
2197 */
|
|
2198 (subwindow, property, data))
|
0
|
2199 {
|
|
2200 Atom property_atom;
|
|
2201 struct Lisp_Subwindow *sw;
|
|
2202 Display *dpy;
|
|
2203
|
|
2204 CHECK_SUBWINDOW (subwindow);
|
|
2205 CHECK_STRING (property);
|
|
2206 CHECK_STRING (data);
|
|
2207
|
|
2208 sw = XSUBWINDOW (subwindow);
|
|
2209 dpy = DisplayOfScreen (LISP_DEVICE_TO_X_SCREEN
|
|
2210 (FRAME_DEVICE (XFRAME (sw->frame))));
|
|
2211
|
16
|
2212 property_atom = XInternAtom (dpy, (char *) XSTRING_DATA (property), False);
|
0
|
2213 XChangeProperty (dpy, sw->subwindow, property_atom, XA_STRING, 8,
|
16
|
2214 PropModeReplace,
|
|
2215 XSTRING_DATA (data),
|
14
|
2216 XSTRING_LENGTH (data));
|
0
|
2217
|
272
|
2218 return property;
|
0
|
2219 }
|
|
2220
|
20
|
2221 DEFUN ("subwindowp", Fsubwindowp, 1, 1, 0, /*
|
0
|
2222 Return non-nil if OBJECT is a subwindow.
|
|
2223 Subwindows are not currently implemented.
|
20
|
2224 */
|
|
2225 (object))
|
0
|
2226 {
|
272
|
2227 return SUBWINDOWP (object) ? Qt : Qnil;
|
0
|
2228 }
|
|
2229
|
20
|
2230 DEFUN ("subwindow-width", Fsubwindow_width, 1, 1, 0, /*
|
0
|
2231 Width of SUBWINDOW.
|
|
2232 Subwindows are not currently implemented.
|
20
|
2233 */
|
|
2234 (subwindow))
|
0
|
2235 {
|
|
2236 CHECK_SUBWINDOW (subwindow);
|
272
|
2237 return make_int (XSUBWINDOW (subwindow)->width);
|
0
|
2238 }
|
|
2239
|
20
|
2240 DEFUN ("subwindow-height", Fsubwindow_height, 1, 1, 0, /*
|
0
|
2241 Height of SUBWINDOW.
|
|
2242 Subwindows are not currently implemented.
|
20
|
2243 */
|
|
2244 (subwindow))
|
0
|
2245 {
|
|
2246 CHECK_SUBWINDOW (subwindow);
|
272
|
2247 return make_int (XSUBWINDOW (subwindow)->height);
|
0
|
2248 }
|
|
2249
|
20
|
2250 DEFUN ("subwindow-xid", Fsubwindow_xid, 1, 1, 0, /*
|
0
|
2251 Return the xid of SUBWINDOW as a number.
|
|
2252 Subwindows are not currently implemented.
|
20
|
2253 */
|
|
2254 (subwindow))
|
0
|
2255 {
|
|
2256 CHECK_SUBWINDOW (subwindow);
|
272
|
2257 return make_int (XSUBWINDOW (subwindow)->subwindow);
|
0
|
2258 }
|
|
2259
|
20
|
2260 DEFUN ("resize-subwindow", Fresize_subwindow, 1, 3, 0, /*
|
0
|
2261 Resize SUBWINDOW to WIDTH x HEIGHT.
|
|
2262 If a value is nil that parameter is not changed.
|
|
2263 Subwindows are not currently implemented.
|
20
|
2264 */
|
|
2265 (subwindow, width, height))
|
0
|
2266 {
|
|
2267 int neww, newh;
|
|
2268 struct Lisp_Subwindow *sw;
|
|
2269
|
|
2270 CHECK_SUBWINDOW (subwindow);
|
|
2271 sw = XSUBWINDOW (subwindow);
|
|
2272
|
|
2273 if (NILP (width))
|
|
2274 neww = sw->width;
|
|
2275 else
|
|
2276 neww = XINT (width);
|
|
2277
|
|
2278 if (NILP (height))
|
|
2279 newh = sw->height;
|
|
2280 else
|
|
2281 newh = XINT (height);
|
|
2282
|
|
2283 XResizeWindow (DisplayOfScreen (sw->xscreen), sw->subwindow, neww, newh);
|
|
2284
|
|
2285 sw->height = newh;
|
|
2286 sw->width = neww;
|
|
2287
|
|
2288 return subwindow;
|
|
2289 }
|
|
2290
|
20
|
2291 DEFUN ("force-subwindow-map", Fforce_subwindow_map, 1, 1, 0, /*
|
0
|
2292 Generate a Map event for SUBWINDOW.
|
|
2293 Subwindows are not currently implemented.
|
20
|
2294 */
|
|
2295 (subwindow))
|
0
|
2296 {
|
|
2297 CHECK_SUBWINDOW (subwindow);
|
|
2298
|
|
2299 XMapWindow (DisplayOfScreen (XSUBWINDOW (subwindow)->xscreen),
|
|
2300 XSUBWINDOW (subwindow)->subwindow);
|
|
2301
|
|
2302 return subwindow;
|
|
2303 }
|
114
|
2304 #endif
|
0
|
2305
|
|
2306 /************************************************************************/
|
|
2307 /* initialization */
|
|
2308 /************************************************************************/
|
|
2309
|
|
2310 void
|
|
2311 syms_of_glyphs_x (void)
|
|
2312 {
|
114
|
2313 #if HAVE_SUBWINDOWS
|
0
|
2314 defsymbol (&Qsubwindowp, "subwindowp");
|
|
2315
|
20
|
2316 DEFSUBR (Fmake_subwindow);
|
|
2317 DEFSUBR (Fchange_subwindow_property);
|
|
2318 DEFSUBR (Fsubwindowp);
|
|
2319 DEFSUBR (Fsubwindow_width);
|
|
2320 DEFSUBR (Fsubwindow_height);
|
|
2321 DEFSUBR (Fsubwindow_xid);
|
|
2322 DEFSUBR (Fresize_subwindow);
|
|
2323 DEFSUBR (Fforce_subwindow_map);
|
114
|
2324 #endif
|
0
|
2325 }
|
|
2326
|
|
2327 void
|
|
2328 console_type_create_glyphs_x (void)
|
|
2329 {
|
|
2330 /* image methods */
|
|
2331
|
|
2332 CONSOLE_HAS_METHOD (x, print_image_instance);
|
|
2333 CONSOLE_HAS_METHOD (x, finalize_image_instance);
|
|
2334 CONSOLE_HAS_METHOD (x, image_instance_equal);
|
|
2335 CONSOLE_HAS_METHOD (x, image_instance_hash);
|
|
2336 CONSOLE_HAS_METHOD (x, colorize_image_instance);
|
278
|
2337 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage);
|
|
2338 CONSOLE_HAS_METHOD (x, locate_pixmap_file);
|
280
|
2339 #ifdef HAVE_XPM
|
|
2340 CONSOLE_HAS_METHOD (x, xpm_instantiate);
|
|
2341 #endif
|
288
|
2342 CONSOLE_HAS_METHOD (x, xbm_instantiate);
|
0
|
2343 }
|
|
2344
|
|
2345 void
|
|
2346 image_instantiator_format_create_glyphs_x (void)
|
|
2347 {
|
|
2348
|
|
2349 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
2350
|
|
2351 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
2352 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
2353 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
2354
|
|
2355 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
2356 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
2357 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
2358
|
|
2359 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
2360
|
|
2361 IIFORMAT_HAS_METHOD (font, validate);
|
|
2362 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
2363 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
2364
|
|
2365 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
2366 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
2367 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
2368
|
|
2369 #ifdef HAVE_XFACE
|
|
2370 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xface, "xface");
|
|
2371
|
|
2372 IIFORMAT_HAS_METHOD (xface, validate);
|
|
2373 IIFORMAT_HAS_METHOD (xface, normalize);
|
|
2374 IIFORMAT_HAS_METHOD (xface, possible_dest_types);
|
|
2375 IIFORMAT_HAS_METHOD (xface, instantiate);
|
|
2376
|
|
2377 IIFORMAT_VALID_KEYWORD (xface, Q_data, check_valid_string);
|
|
2378 IIFORMAT_VALID_KEYWORD (xface, Q_file, check_valid_string);
|
|
2379 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_x, check_valid_int);
|
|
2380 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_y, check_valid_int);
|
|
2381 IIFORMAT_VALID_KEYWORD (xface, Q_foreground, check_valid_string);
|
|
2382 IIFORMAT_VALID_KEYWORD (xface, Q_background, check_valid_string);
|
185
|
2383 #endif
|
0
|
2384
|
122
|
2385 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect,
|
|
2386 "autodetect");
|
|
2387
|
|
2388 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
2389 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
2390 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
|
2391 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
2392
|
|
2393 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
0
|
2394 }
|
|
2395
|
|
2396 void
|
|
2397 vars_of_glyphs_x (void)
|
|
2398 {
|
|
2399 #ifdef HAVE_XFACE
|
|
2400 Fprovide (Qxface);
|
185
|
2401 #endif
|
0
|
2402
|
|
2403 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path /*
|
|
2404 A list of the directories in which X bitmap files may be found.
|
185
|
2405 If nil, this is initialized from the "*bitmapFilePath" resource.
|
0
|
2406 This is used by the `make-image-instance' function (however, note that if
|
|
2407 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
2408 */ );
|
|
2409 Vx_bitmap_file_path = Qnil;
|
|
2410 }
|
|
2411
|
|
2412 void
|
|
2413 complex_vars_of_glyphs_x (void)
|
|
2414 {
|
|
2415 #define BUILD_GLYPH_INST(variable, name) \
|
|
2416 Fadd_spec_to_specifier \
|
|
2417 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
2418 vector3 (Qxbm, Q_data, \
|
|
2419 list3 (make_int (name##_width), \
|
|
2420 make_int (name##_height), \
|
|
2421 make_ext_string (name##_bits, \
|
|
2422 sizeof (name##_bits), \
|
|
2423 FORMAT_BINARY))), \
|
|
2424 Qglobal, Qx, Qnil)
|
|
2425
|
|
2426 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
2427 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
2428 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
74
|
2429 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
0
|
2430
|
|
2431 #undef BUILD_GLYPH_INST
|
|
2432 }
|