428
|
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
|
771
|
5 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing
|
428
|
6 Copyright (C) 1995 Sun Microsystems
|
438
|
7 Copyright (C) 1999, 2000 Andy Piper
|
428
|
8
|
|
9 This file is part of XEmacs.
|
|
10
|
|
11 XEmacs is free software; you can redistribute it and/or modify it
|
|
12 under the terms of the GNU General Public License as published by the
|
|
13 Free Software Foundation; either version 2, or (at your option) any
|
|
14 later version.
|
|
15
|
|
16 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
19 for more details.
|
|
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
|
442
|
27 /* 7-8-00 This file is more or less Mule-ized in my Mule workspace. */
|
|
28
|
428
|
29 /* Original author: Jamie Zawinski for 19.8
|
|
30 font-truename stuff added by Jamie Zawinski for 19.10
|
|
31 subwindow support added by Chuck Thompson
|
|
32 additional XPM support added by Chuck Thompson
|
|
33 initial X-Face support added by Stig
|
|
34 rewritten/restructured by Ben Wing for 19.12/19.13
|
|
35 GIF/JPEG support added by Ben Wing for 19.14
|
|
36 PNG support added by Bill Perry for 19.14
|
|
37 Improved GIF/JPEG support added by Bill Perry for 19.14
|
|
38 Cleanup/simplification of error handling by Ben Wing for 19.14
|
|
39 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
|
|
40 GIF support changed to external GIFlib 3.1 by Jareth Hein for 21.0
|
|
41 Many changes for color work and optimizations by Jareth Hein for 21.0
|
|
42 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0
|
|
43 TIFF code by Jareth Hein for 21.0
|
|
44 GIF/JPEG/PNG/TIFF code moved to new glyph-eimage.c by Andy Piper for 21.0
|
|
45 Subwindow and Widget support by Andy Piper for 21.2
|
|
46
|
|
47 TODO:
|
430
|
48 Support the GrayScale, StaticColor and StaticGray visual classes.
|
428
|
49 Convert images.el to C and stick it in here?
|
|
50 */
|
|
51
|
771
|
52 /* Mule-ized last 6-22-00 */
|
|
53
|
428
|
54 #include <config.h>
|
|
55 #include "lisp.h"
|
800
|
56
|
|
57 #include "buffer.h"
|
|
58 #include "device.h"
|
|
59 #include "faces.h"
|
|
60 #include "file-coding.h"
|
|
61 #include "frame.h"
|
|
62 #include "gui.h"
|
|
63 #include "imgproc.h"
|
|
64 #include "insdel.h"
|
428
|
65 #include "lstream.h"
|
800
|
66 #include "opaque.h"
|
|
67 #include "window.h"
|
|
68
|
428
|
69 #include "console-x.h"
|
|
70 #include "glyphs-x.h"
|
|
71 #include "objects-x.h"
|
771
|
72 #ifdef HAVE_X_WIDGETS
|
428
|
73 #include "gui-x.h"
|
|
74 #endif
|
|
75 #include "xmu.h"
|
|
76
|
|
77 #include "sysfile.h"
|
771
|
78 #include "sysproc.h" /* for qxe_getpid() */
|
428
|
79
|
|
80 #include <setjmp.h>
|
|
81
|
|
82 #ifdef LWLIB_WIDGETS_MOTIF
|
|
83 #include <Xm/Xm.h>
|
639
|
84 #include <Xm/Scale.h>
|
428
|
85 #endif
|
|
86 #include <X11/IntrinsicP.h>
|
|
87
|
|
88 #define LISP_DEVICE_TO_X_SCREEN(dev) XDefaultScreenOfDisplay (DEVICE_X_DISPLAY (XDEVICE (dev)))
|
|
89
|
|
90 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing);
|
|
91 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string);
|
|
92 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
|
|
93 DECLARE_IMAGE_INSTANTIATOR_FORMAT (inherit);
|
|
94 #ifdef HAVE_JPEG
|
|
95 DECLARE_IMAGE_INSTANTIATOR_FORMAT (jpeg);
|
|
96 #endif
|
|
97 #ifdef HAVE_TIFF
|
|
98 DECLARE_IMAGE_INSTANTIATOR_FORMAT (tiff);
|
438
|
99 #endif
|
428
|
100 #ifdef HAVE_PNG
|
|
101 DECLARE_IMAGE_INSTANTIATOR_FORMAT (png);
|
438
|
102 #endif
|
428
|
103 #ifdef HAVE_GIF
|
|
104 DECLARE_IMAGE_INSTANTIATOR_FORMAT (gif);
|
438
|
105 #endif
|
428
|
106 #ifdef HAVE_XPM
|
|
107 DEFINE_DEVICE_IIFORMAT (x, xpm);
|
|
108 #endif
|
|
109 DEFINE_DEVICE_IIFORMAT (x, xbm);
|
|
110 DEFINE_DEVICE_IIFORMAT (x, subwindow);
|
|
111 #ifdef HAVE_XFACE
|
|
112 DEFINE_DEVICE_IIFORMAT (x, xface);
|
|
113 #endif
|
|
114
|
|
115 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor_font);
|
|
116 Lisp_Object Qcursor_font;
|
|
117
|
|
118 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font);
|
|
119
|
|
120 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect);
|
|
121
|
771
|
122 #ifdef HAVE_X_WIDGETS
|
442
|
123 DECLARE_IMAGE_INSTANTIATOR_FORMAT (layout);
|
428
|
124 DEFINE_DEVICE_IIFORMAT (x, widget);
|
442
|
125 DEFINE_DEVICE_IIFORMAT (x, native_layout);
|
428
|
126 DEFINE_DEVICE_IIFORMAT (x, button);
|
|
127 DEFINE_DEVICE_IIFORMAT (x, progress_gauge);
|
|
128 DEFINE_DEVICE_IIFORMAT (x, edit_field);
|
|
129 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
|
130 DEFINE_DEVICE_IIFORMAT (x, combo_box);
|
|
131 #endif
|
|
132 DEFINE_DEVICE_IIFORMAT (x, tab_control);
|
|
133 DEFINE_DEVICE_IIFORMAT (x, label);
|
|
134 #endif
|
|
135
|
|
136 static void cursor_font_instantiate (Lisp_Object image_instance,
|
|
137 Lisp_Object instantiator,
|
|
138 Lisp_Object pointer_fg,
|
|
139 Lisp_Object pointer_bg,
|
|
140 int dest_mask,
|
|
141 Lisp_Object domain);
|
|
142
|
771
|
143 #ifdef HAVE_X_WIDGETS
|
428
|
144 static void
|
434
|
145 update_widget_face (widget_value* wv,
|
440
|
146 Lisp_Image_Instance* ii, Lisp_Object domain);
|
434
|
147 static void
|
|
148 update_tab_widget_face (widget_value* wv,
|
440
|
149 Lisp_Image_Instance* ii, Lisp_Object domain);
|
428
|
150 #endif
|
450
|
151 void
|
|
152 emacs_Xt_handle_widget_losing_focus (struct frame* f, Widget losing_widget);
|
428
|
153
|
|
154 #include "bitmaps.h"
|
|
155
|
|
156
|
|
157 /************************************************************************/
|
|
158 /* image instance methods */
|
|
159 /************************************************************************/
|
|
160
|
|
161 /************************************************************************/
|
|
162 /* convert from a series of RGB triples to an XImage formated for the */
|
|
163 /* proper display */
|
|
164 /************************************************************************/
|
|
165 static XImage *
|
|
166 convert_EImage_to_XImage (Lisp_Object device, int width, int height,
|
771
|
167 UChar_Binary *pic, unsigned long **pixtbl,
|
428
|
168 int *npixels)
|
|
169 {
|
|
170 Display *dpy;
|
|
171 Colormap cmap;
|
|
172 Visual *vis;
|
|
173 XImage *outimg;
|
|
174 int depth, bitmap_pad, bits_per_pixel, byte_cnt, i, j;
|
|
175 int rd,gr,bl,q;
|
771
|
176 UChar_Binary *data, *ip, *dp;
|
428
|
177 quant_table *qtable = 0;
|
|
178 union {
|
826
|
179 UINT_32_BIT val;
|
428
|
180 char cp[4];
|
|
181 } conv;
|
|
182
|
|
183 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
184 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
185 vis = DEVICE_X_VISUAL (XDEVICE(device));
|
|
186 depth = DEVICE_X_DEPTH(XDEVICE(device));
|
|
187
|
430
|
188 if (vis->class == GrayScale || vis->class == StaticColor ||
|
|
189 vis->class == StaticGray)
|
|
190 {
|
|
191 /* #### Implement me!!! */
|
|
192 return NULL;
|
|
193 }
|
|
194
|
428
|
195 if (vis->class == PseudoColor)
|
|
196 {
|
|
197 /* Quantize the image and get a histogram while we're at it.
|
|
198 Do this first to save memory */
|
|
199 qtable = build_EImage_quantable(pic, width, height, 256);
|
|
200 if (qtable == NULL) return NULL;
|
|
201 }
|
|
202
|
|
203 bitmap_pad = ((depth > 16) ? 32 :
|
|
204 (depth > 8) ? 16 :
|
|
205 8);
|
|
206
|
|
207 outimg = XCreateImage (dpy, vis,
|
|
208 depth, ZPixmap, 0, 0, width, height,
|
|
209 bitmap_pad, 0);
|
|
210 if (!outimg) return NULL;
|
|
211
|
|
212 bits_per_pixel = outimg->bits_per_pixel;
|
|
213 byte_cnt = bits_per_pixel >> 3;
|
|
214
|
771
|
215 data = (UChar_Binary *) xmalloc (outimg->bytes_per_line * height);
|
428
|
216 if (!data)
|
|
217 {
|
|
218 XDestroyImage (outimg);
|
|
219 return NULL;
|
|
220 }
|
|
221 outimg->data = (char *) data;
|
|
222
|
|
223 if (vis->class == PseudoColor)
|
|
224 {
|
|
225 unsigned long pixarray[256];
|
|
226 int pixcount, n;
|
|
227 /* use our quantize table to allocate the colors */
|
|
228 pixcount = 32;
|
|
229 *pixtbl = xnew_array (unsigned long, pixcount);
|
|
230 *npixels = 0;
|
|
231
|
440
|
232 /* #### should implement a sort by popularity to assure proper allocation */
|
428
|
233 n = *npixels;
|
|
234 for (i = 0; i < qtable->num_active_colors; i++)
|
|
235 {
|
|
236 XColor color;
|
|
237 int res;
|
|
238
|
|
239 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0;
|
|
240 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0;
|
|
241 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0;
|
|
242 color.flags = DoRed | DoGreen | DoBlue;
|
|
243 res = allocate_nearest_color (dpy, cmap, vis, &color);
|
|
244 if (res > 0 && res < 3)
|
|
245 {
|
|
246 DO_REALLOC(*pixtbl, pixcount, n+1, unsigned long);
|
|
247 (*pixtbl)[n] = color.pixel;
|
|
248 n++;
|
|
249 }
|
|
250 pixarray[i] = color.pixel;
|
|
251 }
|
|
252 *npixels = n;
|
|
253 ip = pic;
|
|
254 for (i = 0; i < height; i++)
|
|
255 {
|
|
256 dp = data + (i * outimg->bytes_per_line);
|
|
257 for (j = 0; j < width; j++)
|
|
258 {
|
|
259 rd = *ip++;
|
|
260 gr = *ip++;
|
|
261 bl = *ip++;
|
|
262 conv.val = pixarray[QUANT_GET_COLOR(qtable,rd,gr,bl)];
|
442
|
263 #ifdef WORDS_BIGENDIAN
|
428
|
264 if (outimg->byte_order == MSBFirst)
|
|
265 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q];
|
|
266 else
|
|
267 for (q = 3; q >= 4-byte_cnt; q--) *dp++ = conv.cp[q];
|
|
268 #else
|
|
269 if (outimg->byte_order == MSBFirst)
|
|
270 for (q = byte_cnt-1; q >= 0; q--) *dp++ = conv.cp[q];
|
|
271 else
|
|
272 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
|
|
273 #endif
|
|
274 }
|
|
275 }
|
|
276 xfree(qtable);
|
|
277 } else {
|
|
278 unsigned long rshift,gshift,bshift,rbits,gbits,bbits,junk;
|
|
279 junk = vis->red_mask;
|
|
280 rshift = 0;
|
|
281 while ((junk & 0x1) == 0)
|
|
282 {
|
|
283 junk = junk >> 1;
|
|
284 rshift ++;
|
|
285 }
|
|
286 rbits = 0;
|
|
287 while (junk != 0)
|
|
288 {
|
|
289 junk = junk >> 1;
|
|
290 rbits++;
|
|
291 }
|
|
292 junk = vis->green_mask;
|
|
293 gshift = 0;
|
|
294 while ((junk & 0x1) == 0)
|
|
295 {
|
|
296 junk = junk >> 1;
|
|
297 gshift ++;
|
|
298 }
|
|
299 gbits = 0;
|
|
300 while (junk != 0)
|
|
301 {
|
|
302 junk = junk >> 1;
|
|
303 gbits++;
|
|
304 }
|
|
305 junk = vis->blue_mask;
|
|
306 bshift = 0;
|
|
307 while ((junk & 0x1) == 0)
|
|
308 {
|
|
309 junk = junk >> 1;
|
|
310 bshift ++;
|
|
311 }
|
|
312 bbits = 0;
|
|
313 while (junk != 0)
|
|
314 {
|
|
315 junk = junk >> 1;
|
|
316 bbits++;
|
|
317 }
|
|
318 ip = pic;
|
|
319 for (i = 0; i < height; i++)
|
|
320 {
|
|
321 dp = data + (i * outimg->bytes_per_line);
|
|
322 for (j = 0; j < width; j++)
|
|
323 {
|
|
324 if (rbits > 8)
|
|
325 rd = *ip++ << (rbits - 8);
|
|
326 else
|
|
327 rd = *ip++ >> (8 - rbits);
|
|
328 if (gbits > 8)
|
|
329 gr = *ip++ << (gbits - 8);
|
|
330 else
|
|
331 gr = *ip++ >> (8 - gbits);
|
|
332 if (bbits > 8)
|
|
333 bl = *ip++ << (bbits - 8);
|
|
334 else
|
|
335 bl = *ip++ >> (8 - bbits);
|
|
336
|
|
337 conv.val = (rd << rshift) | (gr << gshift) | (bl << bshift);
|
442
|
338 #ifdef WORDS_BIGENDIAN
|
428
|
339 if (outimg->byte_order == MSBFirst)
|
|
340 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q];
|
|
341 else
|
|
342 for (q = 3; q >= 4-byte_cnt; q--) *dp++ = conv.cp[q];
|
|
343 #else
|
|
344 if (outimg->byte_order == MSBFirst)
|
|
345 for (q = byte_cnt-1; q >= 0; q--) *dp++ = conv.cp[q];
|
|
346 else
|
|
347 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
|
|
348 #endif
|
|
349 }
|
|
350 }
|
|
351 }
|
|
352 return outimg;
|
|
353 }
|
|
354
|
|
355
|
|
356
|
|
357 static void
|
440
|
358 x_print_image_instance (Lisp_Image_Instance *p,
|
428
|
359 Lisp_Object printcharfun,
|
|
360 int escapeflag)
|
|
361 {
|
|
362 switch (IMAGE_INSTANCE_TYPE (p))
|
|
363 {
|
|
364 case IMAGE_MONO_PIXMAP:
|
|
365 case IMAGE_COLOR_PIXMAP:
|
|
366 case IMAGE_POINTER:
|
800
|
367 write_fmt_string (printcharfun, " (0x%lx",
|
|
368 (unsigned long) IMAGE_INSTANCE_X_PIXMAP (p));
|
428
|
369 if (IMAGE_INSTANCE_X_MASK (p))
|
|
370 {
|
800
|
371 write_fmt_string (printcharfun, "/0x%lx",
|
|
372 (unsigned long) IMAGE_INSTANCE_X_MASK (p));
|
428
|
373 }
|
826
|
374 write_c_string (printcharfun, ")");
|
428
|
375 break;
|
|
376 default:
|
|
377 break;
|
|
378 }
|
|
379 }
|
|
380
|
|
381 #ifdef DEBUG_WIDGETS
|
|
382 extern int debug_widget_instances;
|
|
383 #endif
|
|
384
|
|
385 static void
|
440
|
386 x_finalize_image_instance (Lisp_Image_Instance *p)
|
428
|
387 {
|
|
388 if (!p->data)
|
|
389 return;
|
|
390
|
442
|
391 if (DEVICE_LIVE_P (XDEVICE (IMAGE_INSTANCE_DEVICE (p))))
|
428
|
392 {
|
442
|
393 Display *dpy = DEVICE_X_DISPLAY
|
|
394 (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
395 if (0)
|
|
396 ;
|
771
|
397 #ifdef HAVE_X_WIDGETS
|
442
|
398 else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET)
|
428
|
399 {
|
|
400 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
|
|
401 {
|
|
402 #ifdef DEBUG_WIDGETS
|
|
403 debug_widget_instances--;
|
|
404 stderr_out ("widget destroyed, %d left\n", debug_widget_instances);
|
|
405 #endif
|
|
406 lw_destroy_widget (IMAGE_INSTANCE_X_WIDGET_ID (p));
|
|
407 lw_destroy_widget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
|
442
|
408
|
|
409 /* We can release the callbacks again. */
|
|
410 ungcpro_popup_callbacks (IMAGE_INSTANCE_X_WIDGET_LWID (p));
|
|
411
|
|
412 IMAGE_INSTANCE_X_WIDGET_ID (p) = 0;
|
|
413 IMAGE_INSTANCE_X_CLIPWIDGET (p) = 0;
|
428
|
414 }
|
|
415 }
|
442
|
416 #endif
|
428
|
417 else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
418 {
|
|
419 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
|
|
420 XDestroyWindow (dpy, IMAGE_INSTANCE_X_SUBWINDOW_ID (p));
|
|
421 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0;
|
|
422 }
|
|
423 else
|
|
424 {
|
|
425 int i;
|
|
426 if (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p))
|
|
427 disable_glyph_animated_timeout (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p));
|
|
428
|
|
429 if (IMAGE_INSTANCE_X_MASK (p) &&
|
|
430 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p))
|
|
431 XFreePixmap (dpy, IMAGE_INSTANCE_X_MASK (p));
|
|
432 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
|
438
|
433
|
428
|
434 if (IMAGE_INSTANCE_X_PIXMAP_SLICES (p))
|
|
435 {
|
|
436 for (i = 0; i < IMAGE_INSTANCE_PIXMAP_MAXSLICE (p); i++)
|
|
437 if (IMAGE_INSTANCE_X_PIXMAP_SLICE (p,i))
|
|
438 {
|
|
439 XFreePixmap (dpy, IMAGE_INSTANCE_X_PIXMAP_SLICE (p,i));
|
|
440 IMAGE_INSTANCE_X_PIXMAP_SLICE (p, i) = 0;
|
|
441 }
|
|
442 xfree (IMAGE_INSTANCE_X_PIXMAP_SLICES (p));
|
|
443 IMAGE_INSTANCE_X_PIXMAP_SLICES (p) = 0;
|
|
444 }
|
|
445
|
|
446 if (IMAGE_INSTANCE_X_CURSOR (p))
|
|
447 {
|
|
448 XFreeCursor (dpy, IMAGE_INSTANCE_X_CURSOR (p));
|
|
449 IMAGE_INSTANCE_X_CURSOR (p) = 0;
|
|
450 }
|
438
|
451
|
428
|
452 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0)
|
|
453 {
|
|
454 XFreeColors (dpy,
|
|
455 IMAGE_INSTANCE_X_COLORMAP (p),
|
|
456 IMAGE_INSTANCE_X_PIXELS (p),
|
|
457 IMAGE_INSTANCE_X_NPIXELS (p), 0);
|
|
458 IMAGE_INSTANCE_X_NPIXELS (p) = 0;
|
|
459 }
|
|
460 }
|
|
461 }
|
|
462 /* You can sometimes have pixels without a live device. I forget
|
|
463 why, but that's why we free them here if we have a pixmap type
|
|
464 image instance. It probably means that we might also get a memory
|
|
465 leak with widgets. */
|
|
466 if (IMAGE_INSTANCE_TYPE (p) != IMAGE_WIDGET
|
|
467 && IMAGE_INSTANCE_TYPE (p) != IMAGE_SUBWINDOW
|
|
468 && IMAGE_INSTANCE_X_PIXELS (p))
|
|
469 {
|
|
470 xfree (IMAGE_INSTANCE_X_PIXELS (p));
|
|
471 IMAGE_INSTANCE_X_PIXELS (p) = 0;
|
|
472 }
|
|
473
|
|
474 xfree (p->data);
|
|
475 p->data = 0;
|
|
476 }
|
|
477
|
|
478 static int
|
440
|
479 x_image_instance_equal (Lisp_Image_Instance *p1,
|
|
480 Lisp_Image_Instance *p2, int depth)
|
428
|
481 {
|
|
482 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
483 {
|
|
484 case IMAGE_MONO_PIXMAP:
|
|
485 case IMAGE_COLOR_PIXMAP:
|
|
486 case IMAGE_POINTER:
|
|
487 if (IMAGE_INSTANCE_X_COLORMAP (p1) != IMAGE_INSTANCE_X_COLORMAP (p2) ||
|
|
488 IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2))
|
|
489 return 0;
|
|
490 break;
|
|
491 default:
|
|
492 break;
|
|
493 }
|
|
494
|
|
495 return 1;
|
|
496 }
|
|
497
|
665
|
498 static Hashcode
|
440
|
499 x_image_instance_hash (Lisp_Image_Instance *p, int depth)
|
428
|
500 {
|
|
501 switch (IMAGE_INSTANCE_TYPE (p))
|
|
502 {
|
|
503 case IMAGE_MONO_PIXMAP:
|
|
504 case IMAGE_COLOR_PIXMAP:
|
|
505 case IMAGE_POINTER:
|
|
506 return IMAGE_INSTANCE_X_NPIXELS (p);
|
|
507 default:
|
|
508 return 0;
|
|
509 }
|
|
510 }
|
|
511
|
|
512 /* Set all the slots in an image instance structure to reasonable
|
|
513 default values. This is used somewhere within an instantiate
|
|
514 method. It is assumed that the device slot within the image
|
|
515 instance is already set -- this is the case when instantiate
|
|
516 methods are called. */
|
|
517
|
|
518 static void
|
440
|
519 x_initialize_pixmap_image_instance (Lisp_Image_Instance *ii,
|
428
|
520 int slices,
|
|
521 enum image_instance_type type)
|
|
522 {
|
|
523 ii->data = xnew_and_zero (struct x_image_instance_data);
|
|
524 IMAGE_INSTANCE_PIXMAP_MAXSLICE (ii) = slices;
|
438
|
525 IMAGE_INSTANCE_X_PIXMAP_SLICES (ii) =
|
428
|
526 xnew_array_and_zero (Pixmap, slices);
|
|
527 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
528 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
529 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
530 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
531 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
532 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
533 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
534 }
|
|
535
|
|
536
|
|
537 /************************************************************************/
|
|
538 /* pixmap file functions */
|
|
539 /************************************************************************/
|
|
540
|
|
541 /* Where bitmaps are; initialized from resource database */
|
|
542 Lisp_Object Vx_bitmap_file_path;
|
|
543
|
|
544 #ifndef BITMAPDIR
|
|
545 #define BITMAPDIR "/usr/include/X11/bitmaps"
|
|
546 #endif
|
|
547
|
|
548 #define USE_XBMLANGPATH
|
|
549
|
|
550 /* Given a pixmap filename, look through all of the "standard" places
|
|
551 where the file might be located. Return a full pathname if found;
|
|
552 otherwise, return Qnil. */
|
|
553
|
|
554 static Lisp_Object
|
|
555 x_locate_pixmap_file (Lisp_Object name)
|
|
556 {
|
|
557 /* This function can GC if IN_REDISPLAY is false */
|
|
558 Display *display;
|
|
559
|
|
560 /* Check non-absolute pathnames with a directory component relative to
|
|
561 the search path; that's the way Xt does it. */
|
|
562 /* #### Unix-specific */
|
826
|
563 if (string_byte (name, 0) == '/' ||
|
|
564 (string_byte (name, 0) == '.' &&
|
|
565 (string_byte (name, 1) == '/' ||
|
|
566 (string_byte (name, 1) == '.' &&
|
|
567 (string_byte (name, 2) == '/')))))
|
428
|
568 {
|
|
569 if (!NILP (Ffile_readable_p (name)))
|
440
|
570 return Fexpand_file_name (name, Qnil);
|
428
|
571 else
|
|
572 return Qnil;
|
|
573 }
|
|
574
|
|
575 if (NILP (Vdefault_x_device))
|
|
576 /* This may occur during initialization. */
|
|
577 return Qnil;
|
|
578 else
|
|
579 /* We only check the bitmapFilePath resource on the original X device. */
|
|
580 display = DEVICE_X_DISPLAY (XDEVICE (Vdefault_x_device));
|
|
581
|
|
582 #ifdef USE_XBMLANGPATH
|
|
583 {
|
771
|
584 Intbyte *path = egetenv ("XBMLANGPATH");
|
|
585 Extbyte *pathext;
|
428
|
586 SubstitutionRec subs[1];
|
|
587 subs[0].match = 'B';
|
771
|
588 LISP_STRING_TO_EXTERNAL (name, subs[0].substitution, Qfile_name);
|
|
589 C_STRING_TO_EXTERNAL (path, pathext, Qfile_name);
|
428
|
590 /* #### Motif uses a big hairy default if $XBMLANGPATH isn't set.
|
|
591 We don't. If you want it used, set it. */
|
771
|
592 if (pathext &&
|
|
593 (pathext = XtResolvePathname (display, "bitmaps", 0, 0, pathext,
|
|
594 subs, XtNumber (subs), 0)))
|
428
|
595 {
|
771
|
596 name = build_ext_string (pathext, Qfile_name);
|
|
597 XtFree (pathext);
|
428
|
598 return (name);
|
|
599 }
|
|
600 }
|
|
601 #endif
|
|
602
|
|
603 if (NILP (Vx_bitmap_file_path))
|
|
604 {
|
|
605 char *type = 0;
|
|
606 XrmValue value;
|
|
607 if (XrmGetResource (XtDatabase (display),
|
|
608 "bitmapFilePath", "BitmapFilePath", &type, &value)
|
|
609 && !strcmp (type, "String"))
|
771
|
610 {
|
|
611 Intbyte *path;
|
|
612
|
|
613 EXTERNAL_TO_C_STRING (value.addr, path, Qfile_name);
|
|
614 Vx_bitmap_file_path = split_env_path (0, path);
|
|
615 }
|
428
|
616 Vx_bitmap_file_path = nconc2 (Vx_bitmap_file_path,
|
771
|
617 (split_external_path (BITMAPDIR)));
|
428
|
618 }
|
|
619
|
|
620 {
|
|
621 Lisp_Object found;
|
|
622 if (locate_file (Vx_bitmap_file_path, name, Qnil, &found, R_OK) < 0)
|
|
623 {
|
|
624 Lisp_Object temp = list1 (Vdata_directory);
|
|
625 struct gcpro gcpro1;
|
|
626
|
|
627 GCPRO1 (temp);
|
|
628 locate_file (temp, name, Qnil, &found, R_OK);
|
|
629 UNGCPRO;
|
|
630 }
|
|
631
|
|
632 return found;
|
|
633 }
|
|
634 }
|
|
635
|
|
636 static Lisp_Object
|
|
637 locate_pixmap_file (Lisp_Object name)
|
|
638 {
|
|
639 return x_locate_pixmap_file (name);
|
|
640 }
|
|
641
|
|
642
|
|
643 /************************************************************************/
|
|
644 /* cursor functions */
|
|
645 /************************************************************************/
|
|
646
|
|
647 /* Check that this server supports cursors of size WIDTH * HEIGHT. If
|
|
648 not, signal an error. INSTANTIATOR is only used in the error
|
|
649 message. */
|
|
650
|
|
651 static void
|
647
|
652 check_pointer_sizes (Screen *xs, int width, int height,
|
428
|
653 Lisp_Object instantiator)
|
|
654 {
|
|
655 unsigned int best_width, best_height;
|
|
656 if (! XQueryBestCursor (DisplayOfScreen (xs), RootWindowOfScreen (xs),
|
|
657 width, height, &best_width, &best_height))
|
|
658 /* this means that an X error of some sort occurred (we trap
|
|
659 these so they're not fatal). */
|
563
|
660 gui_error ("XQueryBestCursor() failed?", instantiator);
|
428
|
661
|
647
|
662 if (width > (int) best_width || height > (int) best_height)
|
563
|
663 signal_ferror_with_frob (Qgui_error, instantiator,
|
|
664 "pointer too large (%dx%d): "
|
|
665 "server requires %dx%d or smaller",
|
|
666 width, height, best_width, best_height);
|
428
|
667 }
|
|
668
|
|
669
|
|
670 static void
|
|
671 generate_cursor_fg_bg (Lisp_Object device, Lisp_Object *foreground,
|
|
672 Lisp_Object *background, XColor *xfg, XColor *xbg)
|
|
673 {
|
|
674 if (!NILP (*foreground) && !COLOR_INSTANCEP (*foreground))
|
|
675 *foreground =
|
|
676 Fmake_color_instance (*foreground, device,
|
|
677 encode_error_behavior_flag (ERROR_ME));
|
|
678 if (COLOR_INSTANCEP (*foreground))
|
|
679 *xfg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*foreground));
|
|
680 else
|
|
681 {
|
|
682 xfg->pixel = 0;
|
|
683 xfg->red = xfg->green = xfg->blue = 0;
|
|
684 }
|
|
685
|
|
686 if (!NILP (*background) && !COLOR_INSTANCEP (*background))
|
|
687 *background =
|
|
688 Fmake_color_instance (*background, device,
|
|
689 encode_error_behavior_flag (ERROR_ME));
|
|
690 if (COLOR_INSTANCEP (*background))
|
|
691 *xbg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*background));
|
|
692 else
|
|
693 {
|
|
694 xbg->pixel = 0;
|
460
|
695 xbg->red = xbg->green = xbg->blue = USHRT_MAX;
|
428
|
696 }
|
|
697 }
|
|
698
|
|
699 static void
|
|
700 maybe_recolor_cursor (Lisp_Object image_instance, Lisp_Object foreground,
|
|
701 Lisp_Object background)
|
|
702 {
|
|
703 Lisp_Object device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
704 XColor xfg, xbg;
|
|
705
|
|
706 generate_cursor_fg_bg (device, &foreground, &background, &xfg, &xbg);
|
|
707 if (!NILP (foreground) || !NILP (background))
|
|
708 {
|
|
709 XRecolorCursor (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
710 XIMAGE_INSTANCE_X_CURSOR (image_instance),
|
|
711 &xfg, &xbg);
|
|
712 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
713 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
714 }
|
|
715 }
|
|
716
|
|
717
|
|
718 /************************************************************************/
|
|
719 /* color pixmap functions */
|
|
720 /************************************************************************/
|
|
721
|
|
722 /* Initialize an image instance from an XImage.
|
|
723
|
|
724 DEST_MASK specifies the mask of allowed image types.
|
|
725
|
|
726 PIXELS and NPIXELS specify an array of pixels that are used in
|
|
727 the image. These need to be kept around for the duration of the
|
|
728 image. When the image instance is freed, XFreeColors() will
|
|
729 automatically be called on all the pixels specified here; thus,
|
|
730 you should have allocated the pixels yourself using XAllocColor()
|
|
731 or the like. The array passed in is used directly without
|
|
732 being copied, so it should be heap data created with xmalloc().
|
|
733 It will be freed using xfree() when the image instance is
|
|
734 destroyed.
|
|
735
|
|
736 If this fails, signal an error. INSTANTIATOR is only used
|
|
737 in the error message.
|
|
738
|
|
739 #### This should be able to handle conversion into `pointer'.
|
|
740 Use the same code as for `xpm'. */
|
|
741
|
|
742 static void
|
440
|
743 init_image_instance_from_x_image (Lisp_Image_Instance *ii,
|
428
|
744 XImage *ximage,
|
|
745 int dest_mask,
|
|
746 Colormap cmap,
|
|
747 unsigned long *pixels,
|
|
748 int npixels,
|
|
749 int slices,
|
|
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)))
|
563
|
759 gui_error ("Not an X device", device);
|
428
|
760
|
|
761 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
762 d = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
|
|
763
|
|
764 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
765 incompatible_image_types (instantiator, dest_mask,
|
|
766 IMAGE_COLOR_PIXMAP_MASK);
|
|
767
|
|
768 pixmap = XCreatePixmap (dpy, d, ximage->width,
|
|
769 ximage->height, ximage->depth);
|
|
770 if (!pixmap)
|
563
|
771 gui_error ("Unable to create pixmap", instantiator);
|
428
|
772
|
|
773 gc = XCreateGC (dpy, pixmap, 0, NULL);
|
|
774 if (!gc)
|
|
775 {
|
|
776 XFreePixmap (dpy, pixmap);
|
563
|
777 gui_error ("Unable to create GC", instantiator);
|
428
|
778 }
|
|
779
|
|
780 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
|
|
781 ximage->width, ximage->height);
|
|
782
|
|
783 XFreeGC (dpy, gc);
|
|
784
|
|
785 x_initialize_pixmap_image_instance (ii, slices, IMAGE_COLOR_PIXMAP);
|
|
786
|
|
787 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
788 find_keyword_in_vector (instantiator, Q_file);
|
|
789
|
|
790 /* Fixup a set of pixmaps. */
|
|
791 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
792
|
|
793 IMAGE_INSTANCE_PIXMAP_MASK (ii) = 0;
|
|
794 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width;
|
|
795 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height;
|
|
796 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth;
|
|
797 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap;
|
|
798 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
799 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
800 }
|
|
801
|
|
802 static void
|
440
|
803 image_instance_add_x_image (Lisp_Image_Instance *ii,
|
428
|
804 XImage *ximage,
|
|
805 int slice,
|
|
806 Lisp_Object instantiator)
|
|
807 {
|
|
808 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
809 Display *dpy;
|
|
810 GC gc;
|
|
811 Drawable d;
|
|
812 Pixmap pixmap;
|
|
813
|
|
814 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
815 d = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
|
|
816
|
|
817 pixmap = XCreatePixmap (dpy, d, ximage->width,
|
|
818 ximage->height, ximage->depth);
|
|
819 if (!pixmap)
|
563
|
820 gui_error ("Unable to create pixmap", instantiator);
|
428
|
821
|
|
822 gc = XCreateGC (dpy, pixmap, 0, NULL);
|
|
823 if (!gc)
|
|
824 {
|
|
825 XFreePixmap (dpy, pixmap);
|
563
|
826 gui_error ("Unable to create GC", instantiator);
|
428
|
827 }
|
|
828
|
|
829 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
|
|
830 ximage->width, ximage->height);
|
|
831
|
|
832 XFreeGC (dpy, gc);
|
|
833
|
|
834 IMAGE_INSTANCE_X_PIXMAP_SLICE (ii, slice) = pixmap;
|
|
835 }
|
|
836
|
|
837 static void
|
440
|
838 x_init_image_instance_from_eimage (Lisp_Image_Instance *ii,
|
428
|
839 int width, int height,
|
|
840 int slices,
|
771
|
841 UChar_Binary *eimage,
|
428
|
842 int dest_mask,
|
|
843 Lisp_Object instantiator,
|
|
844 Lisp_Object domain)
|
|
845 {
|
|
846 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
847 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
848 unsigned long *pixtbl = NULL;
|
|
849 int npixels = 0;
|
|
850 int slice;
|
|
851 XImage* ximage;
|
|
852
|
|
853 for (slice = 0; slice < slices; slice++)
|
|
854 {
|
438
|
855 ximage = convert_EImage_to_XImage (device, width, height,
|
428
|
856 eimage + (width * height * 3 * slice),
|
|
857 &pixtbl, &npixels);
|
|
858 if (!ximage)
|
|
859 {
|
|
860 if (pixtbl) xfree (pixtbl);
|
|
861 signal_image_error("EImage to XImage conversion failed", instantiator);
|
|
862 }
|
|
863
|
|
864 /* Now create the pixmap and set up the image instance */
|
|
865 if (slice == 0)
|
|
866 init_image_instance_from_x_image (ii, ximage, dest_mask,
|
|
867 cmap, pixtbl, npixels, slices,
|
|
868 instantiator);
|
|
869 else
|
|
870 image_instance_add_x_image (ii, ximage, slice, instantiator);
|
|
871
|
|
872 if (ximage)
|
|
873 {
|
|
874 if (ximage->data)
|
|
875 {
|
|
876 xfree (ximage->data);
|
|
877 ximage->data = 0;
|
|
878 }
|
|
879 XDestroyImage (ximage);
|
|
880 ximage = 0;
|
|
881 }
|
|
882 }
|
|
883 }
|
|
884
|
|
885 /* Given inline data for a mono pixmap, create and return the
|
|
886 corresponding X object. */
|
|
887
|
|
888 static Pixmap
|
|
889 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
|
771
|
890 Char_Binary *bits)
|
428
|
891 {
|
771
|
892 return XCreatePixmapFromBitmapData (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
893 XtWindow (DEVICE_XT_APP_SHELL
|
|
894 (XDEVICE (device))),
|
|
895 bits, width, height,
|
|
896 1, 0, 1);
|
428
|
897 }
|
|
898
|
|
899 /* Given inline data for a mono pixmap, initialize the given
|
|
900 image instance accordingly. */
|
|
901
|
|
902 static void
|
440
|
903 init_image_instance_from_xbm_inline (Lisp_Image_Instance *ii,
|
428
|
904 int width, int height,
|
771
|
905 Char_Binary *bits,
|
428
|
906 Lisp_Object instantiator,
|
|
907 Lisp_Object pointer_fg,
|
|
908 Lisp_Object pointer_bg,
|
|
909 int dest_mask,
|
|
910 Pixmap mask,
|
|
911 Lisp_Object mask_filename)
|
|
912 {
|
|
913 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
914 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
915 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
916 Display *dpy;
|
|
917 Screen *scr;
|
|
918 Drawable draw;
|
|
919 enum image_instance_type type;
|
|
920
|
|
921 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
922 gui_error ("Not an X device", device);
|
428
|
923
|
|
924 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
925 draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
|
|
926 scr = DefaultScreenOfDisplay (dpy);
|
|
927
|
|
928 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
929 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
930 {
|
|
931 if (!NILP (foreground) || !NILP (background))
|
|
932 type = IMAGE_COLOR_PIXMAP;
|
|
933 else
|
|
934 type = IMAGE_MONO_PIXMAP;
|
|
935 }
|
|
936 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
937 type = IMAGE_MONO_PIXMAP;
|
|
938 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
939 type = IMAGE_COLOR_PIXMAP;
|
|
940 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
941 type = IMAGE_POINTER;
|
|
942 else
|
|
943 incompatible_image_types (instantiator, dest_mask,
|
|
944 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
945 | IMAGE_POINTER_MASK);
|
|
946
|
|
947 x_initialize_pixmap_image_instance (ii, 1, type);
|
|
948 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
949 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
950 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
951 find_keyword_in_vector (instantiator, Q_file);
|
|
952
|
|
953 switch (type)
|
|
954 {
|
|
955 case IMAGE_MONO_PIXMAP:
|
|
956 {
|
|
957 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
771
|
958 pixmap_from_xbm_inline (device, width, height, bits);
|
428
|
959 }
|
|
960 break;
|
|
961
|
|
962 case IMAGE_COLOR_PIXMAP:
|
|
963 {
|
|
964 Dimension d = DEVICE_X_DEPTH (XDEVICE(device));
|
|
965 unsigned long fg = BlackPixelOfScreen (scr);
|
|
966 unsigned long bg = WhitePixelOfScreen (scr);
|
|
967
|
|
968 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
969 foreground =
|
|
970 Fmake_color_instance (foreground, device,
|
|
971 encode_error_behavior_flag (ERROR_ME));
|
|
972
|
|
973 if (COLOR_INSTANCEP (foreground))
|
|
974 fg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground)).pixel;
|
|
975
|
|
976 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
977 background =
|
|
978 Fmake_color_instance (background, device,
|
|
979 encode_error_behavior_flag (ERROR_ME));
|
|
980
|
|
981 if (COLOR_INSTANCEP (background))
|
|
982 bg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background)).pixel;
|
|
983
|
|
984 /* We used to duplicate the pixels using XAllocColor(), to protect
|
|
985 against their getting freed. Just as easy to just store the
|
|
986 color instances here and GC-protect them, so this doesn't
|
|
987 happen. */
|
|
988 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
989 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
990 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
|
991 XCreatePixmapFromBitmapData (dpy, draw,
|
771
|
992 (Char_Binary *) bits, width, height,
|
428
|
993 fg, bg, d);
|
|
994 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
995 }
|
|
996 break;
|
|
997
|
|
998 case IMAGE_POINTER:
|
|
999 {
|
|
1000 XColor fg_color, bg_color;
|
|
1001 Pixmap source;
|
|
1002
|
|
1003 check_pointer_sizes (scr, width, height, instantiator);
|
|
1004
|
|
1005 source =
|
|
1006 XCreatePixmapFromBitmapData (dpy, draw,
|
771
|
1007 (Char_Binary *) bits, width, height,
|
428
|
1008 1, 0, 1);
|
|
1009
|
|
1010 if (NILP (foreground))
|
|
1011 foreground = pointer_fg;
|
|
1012 if (NILP (background))
|
|
1013 background = pointer_bg;
|
|
1014 generate_cursor_fg_bg (device, &foreground, &background,
|
|
1015 &fg_color, &bg_color);
|
|
1016
|
|
1017 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
1018 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
1019 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
|
|
1020 find_keyword_in_vector (instantiator, Q_hotspot_x);
|
|
1021 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
|
|
1022 find_keyword_in_vector (instantiator, Q_hotspot_y);
|
|
1023 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1024 XCreatePixmapCursor
|
|
1025 (dpy, source, mask, &fg_color, &bg_color,
|
|
1026 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ?
|
|
1027 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) : 0,
|
|
1028 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) ?
|
|
1029 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) : 0);
|
|
1030 }
|
|
1031 break;
|
|
1032
|
|
1033 default:
|
|
1034 abort ();
|
|
1035 }
|
|
1036 }
|
|
1037
|
|
1038 static void
|
|
1039 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1040 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1041 int dest_mask, int width, int height,
|
771
|
1042 Char_Binary *bits)
|
428
|
1043 {
|
|
1044 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1045 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
440
|
1046 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
1047 Pixmap mask = 0;
|
|
1048
|
|
1049 if (!NILP (mask_data))
|
|
1050 {
|
771
|
1051 Char_Binary *ext_data;
|
|
1052
|
|
1053 LISP_STRING_TO_EXTERNAL (XCAR (XCDR (XCDR (mask_data))), ext_data,
|
|
1054 Qbinary);
|
440
|
1055 mask = pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
|
|
1056 XINT (XCAR (mask_data)),
|
|
1057 XINT (XCAR (XCDR (mask_data))),
|
444
|
1058 ext_data);
|
428
|
1059 }
|
|
1060
|
|
1061 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1062 instantiator, pointer_fg, pointer_bg,
|
|
1063 dest_mask, mask, mask_file);
|
|
1064 }
|
|
1065
|
|
1066 /* Instantiate method for XBM's. */
|
|
1067
|
|
1068 static void
|
|
1069 x_xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1070 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1071 int dest_mask, Lisp_Object domain)
|
|
1072 {
|
|
1073 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
771
|
1074 Char_Binary *ext_data;
|
428
|
1075
|
|
1076 assert (!NILP (data));
|
|
1077
|
442
|
1078 LISP_STRING_TO_EXTERNAL (XCAR (XCDR (XCDR (data))), ext_data, Qbinary);
|
428
|
1079
|
|
1080 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1081 pointer_bg, dest_mask, XINT (XCAR (data)),
|
440
|
1082 XINT (XCAR (XCDR (data))), ext_data);
|
428
|
1083 }
|
|
1084
|
|
1085
|
|
1086 #ifdef HAVE_XPM
|
|
1087
|
|
1088 /**********************************************************************
|
|
1089 * XPM *
|
|
1090 **********************************************************************/
|
|
1091 /* xpm 3.2g and better has XpmCreatePixmapFromBuffer()...
|
|
1092 There was no version number in xpm.h before 3.3, but this should do.
|
|
1093 */
|
|
1094 #if (XpmVersion >= 3) || defined(XpmExactColors)
|
|
1095 # define XPM_DOES_BUFFERS
|
|
1096 #endif
|
|
1097
|
|
1098 #ifndef XPM_DOES_BUFFERS
|
|
1099 Your version of XPM is too old. You cannot compile with it.
|
|
1100 Upgrade to version 3.2g or better or compile with --with-xpm=no.
|
|
1101 #endif /* !XPM_DOES_BUFFERS */
|
|
1102
|
|
1103 static XpmColorSymbol *
|
|
1104 extract_xpm_color_names (XpmAttributes *xpmattrs, Lisp_Object device,
|
|
1105 Lisp_Object domain,
|
|
1106 Lisp_Object color_symbol_alist)
|
|
1107 {
|
|
1108 /* This function can GC */
|
|
1109 Display *dpy = DEVICE_X_DISPLAY (XDEVICE(device));
|
|
1110 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
1111 XColor color;
|
|
1112 Lisp_Object rest;
|
|
1113 Lisp_Object results = Qnil;
|
|
1114 int i;
|
|
1115 XpmColorSymbol *symbols;
|
|
1116 struct gcpro gcpro1, gcpro2;
|
|
1117
|
|
1118 GCPRO2 (results, device);
|
|
1119
|
|
1120 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
1121 error happens we don't lose any malloc()ed data, or more importantly,
|
|
1122 leave any pixels allocated in the server. */
|
|
1123 i = 0;
|
|
1124 LIST_LOOP (rest, color_symbol_alist)
|
|
1125 {
|
|
1126 Lisp_Object cons = XCAR (rest);
|
|
1127 Lisp_Object name = XCAR (cons);
|
|
1128 Lisp_Object value = XCDR (cons);
|
|
1129 if (NILP (value))
|
|
1130 continue;
|
|
1131 if (STRINGP (value))
|
|
1132 value =
|
|
1133 Fmake_color_instance
|
793
|
1134 (value, device, encode_error_behavior_flag (ERROR_ME_DEBUG_WARN));
|
428
|
1135 else
|
|
1136 {
|
|
1137 assert (COLOR_SPECIFIERP (value));
|
|
1138 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
|
1139 }
|
|
1140 if (NILP (value))
|
|
1141 continue;
|
|
1142 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
1143 i++;
|
|
1144 }
|
|
1145 UNGCPRO; /* no more evaluation */
|
|
1146
|
|
1147 if (i == 0) return 0;
|
|
1148
|
|
1149 symbols = xnew_array (XpmColorSymbol, i);
|
|
1150 xpmattrs->valuemask |= XpmColorSymbols;
|
|
1151 xpmattrs->colorsymbols = symbols;
|
|
1152 xpmattrs->numsymbols = i;
|
|
1153
|
|
1154 while (--i >= 0)
|
|
1155 {
|
|
1156 Lisp_Object cons = XCAR (results);
|
|
1157 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
1158 /* Duplicate the pixel value so that we still have a lock on it if
|
|
1159 the pixel we were passed is later freed. */
|
|
1160 if (! XAllocColor (dpy, cmap, &color))
|
|
1161 abort (); /* it must be allocable since we're just duplicating it */
|
|
1162
|
771
|
1163 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (cons), C_STRING_MALLOC,
|
|
1164 symbols[i].name, Qctext);
|
|
1165 symbols[i].pixel = color.pixel;
|
|
1166 symbols[i].value = 0;
|
428
|
1167 free_cons (XCONS (cons));
|
|
1168 cons = results;
|
|
1169 results = XCDR (results);
|
|
1170 free_cons (XCONS (cons));
|
|
1171 }
|
|
1172 return symbols;
|
|
1173 }
|
|
1174
|
|
1175 static void
|
|
1176 xpm_free (XpmAttributes *xpmattrs)
|
|
1177 {
|
|
1178 /* Could conceivably lose if XpmXXX returned an error without first
|
|
1179 initializing this structure, if we didn't know that initializing it
|
|
1180 to all zeros was ok (and also that it's ok to call XpmFreeAttributes()
|
|
1181 multiple times, since it zeros slots as it frees them...) */
|
|
1182 XpmFreeAttributes (xpmattrs);
|
|
1183 }
|
|
1184
|
|
1185 static void
|
|
1186 x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
438
|
1187 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1188 int dest_mask, Lisp_Object domain)
|
428
|
1189 {
|
|
1190 /* This function can GC */
|
440
|
1191 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
1192 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1193 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1194 Display *dpy;
|
|
1195 Screen *xs;
|
|
1196 Colormap cmap;
|
|
1197 int depth;
|
|
1198 Visual *visual;
|
|
1199 Pixmap pixmap;
|
|
1200 Pixmap mask = 0;
|
|
1201 XpmAttributes xpmattrs;
|
|
1202 int result;
|
|
1203 XpmColorSymbol *color_symbols;
|
|
1204 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
1205 Q_color_symbols);
|
|
1206 enum image_instance_type type;
|
|
1207 int force_mono;
|
647
|
1208 int w, h;
|
428
|
1209
|
|
1210 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
1211 gui_error ("Not an X device", device);
|
428
|
1212
|
|
1213 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1214 xs = DefaultScreenOfDisplay (dpy);
|
|
1215
|
|
1216 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1217 type = IMAGE_COLOR_PIXMAP;
|
|
1218 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
1219 type = IMAGE_MONO_PIXMAP;
|
|
1220 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
1221 type = IMAGE_POINTER;
|
|
1222 else
|
|
1223 incompatible_image_types (instantiator, dest_mask,
|
|
1224 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
1225 | IMAGE_POINTER_MASK);
|
|
1226 force_mono = (type != IMAGE_COLOR_PIXMAP);
|
|
1227
|
|
1228 #if 1
|
|
1229 /* Although I haven't found it documented yet, it appears that pointers are
|
|
1230 always colored via the default window colormap... Sigh. */
|
|
1231 if (type == IMAGE_POINTER)
|
|
1232 {
|
|
1233 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
|
|
1234 depth = DefaultDepthOfScreen (xs);
|
|
1235 visual = DefaultVisualOfScreen (xs);
|
|
1236 }
|
|
1237 else
|
|
1238 {
|
|
1239 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
1240 depth = DEVICE_X_DEPTH (XDEVICE(device));
|
|
1241 visual = DEVICE_X_VISUAL (XDEVICE(device));
|
|
1242 }
|
|
1243 #else
|
|
1244 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
|
|
1245 depth = DEVICE_X_DEPTH (XDEVICE(device));
|
|
1246 visual = DEVICE_X_VISUAL (XDEVICE(device));
|
|
1247 #endif
|
|
1248
|
|
1249 x_initialize_pixmap_image_instance (ii, 1, type);
|
|
1250
|
|
1251 assert (!NILP (data));
|
|
1252
|
|
1253 retry:
|
|
1254
|
|
1255 xzero (xpmattrs); /* want XpmInitAttributes() */
|
|
1256 xpmattrs.valuemask = XpmReturnPixels;
|
|
1257 if (force_mono)
|
|
1258 {
|
|
1259 /* Without this, we get a 1-bit version of the color image, which
|
|
1260 isn't quite right. With this, we get the mono image, which might
|
|
1261 be very different looking. */
|
|
1262 xpmattrs.valuemask |= XpmColorKey;
|
|
1263 xpmattrs.color_key = XPM_MONO;
|
|
1264 xpmattrs.depth = 1;
|
|
1265 xpmattrs.valuemask |= XpmDepth;
|
|
1266 }
|
|
1267 else
|
|
1268 {
|
|
1269 xpmattrs.closeness = 65535;
|
|
1270 xpmattrs.valuemask |= XpmCloseness;
|
|
1271 xpmattrs.depth = depth;
|
|
1272 xpmattrs.valuemask |= XpmDepth;
|
|
1273 xpmattrs.visual = visual;
|
|
1274 xpmattrs.valuemask |= XpmVisual;
|
|
1275 xpmattrs.colormap = cmap;
|
|
1276 xpmattrs.valuemask |= XpmColormap;
|
|
1277 }
|
|
1278
|
|
1279 color_symbols = extract_xpm_color_names (&xpmattrs, device, domain,
|
|
1280 color_symbol_alist);
|
|
1281
|
771
|
1282 {
|
|
1283 Extbyte *dataext;
|
|
1284
|
|
1285 LISP_STRING_TO_EXTERNAL (data, dataext, Qctext);
|
|
1286
|
|
1287 result =
|
|
1288 XpmCreatePixmapFromBuffer (dpy,
|
|
1289 XtWindow
|
|
1290 (DEVICE_XT_APP_SHELL (XDEVICE(device))),
|
|
1291 dataext, &pixmap, &mask, &xpmattrs);
|
|
1292 }
|
428
|
1293
|
|
1294 if (color_symbols)
|
|
1295 {
|
771
|
1296 int i;
|
|
1297
|
|
1298 for (i = 0; i < (int) xpmattrs.numsymbols; i++)
|
|
1299 xfree (color_symbols[i].name);
|
428
|
1300 xfree (color_symbols);
|
|
1301 xpmattrs.colorsymbols = 0; /* in case XpmFreeAttr is too smart... */
|
|
1302 xpmattrs.numsymbols = 0;
|
|
1303 }
|
|
1304
|
|
1305 switch (result)
|
|
1306 {
|
|
1307 case XpmSuccess:
|
|
1308 break;
|
|
1309 case XpmFileInvalid:
|
|
1310 {
|
|
1311 xpm_free (&xpmattrs);
|
|
1312 signal_image_error ("invalid XPM data", data);
|
|
1313 }
|
|
1314 case XpmColorFailed:
|
|
1315 case XpmColorError:
|
|
1316 {
|
|
1317 xpm_free (&xpmattrs);
|
|
1318 if (force_mono)
|
|
1319 {
|
|
1320 /* second time; blow out. */
|
563
|
1321 gui_error ("XPM color allocation failed", data);
|
428
|
1322 }
|
|
1323 else
|
|
1324 {
|
563
|
1325 /* second time; blow out. */
|
428
|
1326 if (! (dest_mask & IMAGE_MONO_PIXMAP_MASK))
|
563
|
1327 gui_error ("XPM color allocation failed", data);
|
428
|
1328 force_mono = 1;
|
|
1329 IMAGE_INSTANCE_TYPE (ii) = IMAGE_MONO_PIXMAP;
|
|
1330 goto retry;
|
|
1331 }
|
|
1332 }
|
|
1333 case XpmNoMemory:
|
|
1334 {
|
|
1335 xpm_free (&xpmattrs);
|
563
|
1336 out_of_memory ("Parsing pixmap data", data);
|
428
|
1337 }
|
|
1338 default:
|
|
1339 {
|
|
1340 xpm_free (&xpmattrs);
|
563
|
1341 signal_error_2 (Qgui_error,
|
|
1342 "Parsing pixmap data: unknown error code",
|
|
1343 make_int (result), data);
|
428
|
1344 }
|
|
1345 }
|
|
1346
|
|
1347 w = xpmattrs.width;
|
|
1348 h = xpmattrs.height;
|
|
1349
|
|
1350 {
|
|
1351 int npixels = xpmattrs.npixels;
|
|
1352 Pixel *pixels;
|
|
1353
|
|
1354 if (npixels != 0)
|
|
1355 {
|
|
1356 pixels = xnew_array (Pixel, npixels);
|
|
1357 memcpy (pixels, xpmattrs.pixels, npixels * sizeof (Pixel));
|
|
1358 }
|
|
1359 else
|
|
1360 pixels = NULL;
|
|
1361
|
|
1362 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
1363 IMAGE_INSTANCE_PIXMAP_MASK (ii) = (void*)mask;
|
|
1364 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap;
|
|
1365 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
1366 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
1367 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
|
|
1368 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
|
|
1369 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
1370 find_keyword_in_vector (instantiator, Q_file);
|
|
1371 }
|
|
1372
|
|
1373 switch (type)
|
|
1374 {
|
|
1375 case IMAGE_MONO_PIXMAP:
|
|
1376 break;
|
|
1377
|
|
1378 case IMAGE_COLOR_PIXMAP:
|
|
1379 {
|
|
1380 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
|
|
1381 }
|
|
1382 break;
|
|
1383
|
|
1384 case IMAGE_POINTER:
|
|
1385 {
|
|
1386 int npixels = xpmattrs.npixels;
|
|
1387 Pixel *pixels = xpmattrs.pixels;
|
|
1388 XColor fg, bg;
|
|
1389 int i;
|
|
1390 int xhot = 0, yhot = 0;
|
|
1391
|
|
1392 if (xpmattrs.valuemask & XpmHotspot)
|
|
1393 {
|
|
1394 xhot = xpmattrs.x_hotspot;
|
793
|
1395 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int (xpmattrs.x_hotspot);
|
428
|
1396 }
|
|
1397 if (xpmattrs.valuemask & XpmHotspot)
|
|
1398 {
|
|
1399 yhot = xpmattrs.y_hotspot;
|
793
|
1400 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int (xpmattrs.y_hotspot);
|
428
|
1401 }
|
|
1402 check_pointer_sizes (xs, w, h, instantiator);
|
|
1403
|
|
1404 /* If the loaded pixmap has colors allocated (meaning it came from an
|
|
1405 XPM file), then use those as the default colors for the cursor we
|
|
1406 create. Otherwise, default to pointer_fg and pointer_bg.
|
|
1407 */
|
|
1408 if (npixels >= 2)
|
|
1409 {
|
|
1410 /* With an XBM file, it's obvious which bit is foreground
|
|
1411 and which is background, or rather, it's implicit: in
|
|
1412 an XBM file, a 1 bit is foreground, and a 0 bit is
|
|
1413 background.
|
|
1414
|
|
1415 XCreatePixmapCursor() assumes this property of the
|
|
1416 pixmap it is called with as well; the `foreground'
|
|
1417 color argument is used for the 1 bits.
|
|
1418
|
|
1419 With an XPM file, it's tricker, since the elements of
|
|
1420 the pixmap don't represent FG and BG, but are actual
|
|
1421 pixel values. So we need to figure out which of those
|
|
1422 pixels is the foreground color and which is the
|
|
1423 background. We do it by comparing RGB and assuming
|
|
1424 that the darker color is the foreground. This works
|
|
1425 with the result of xbmtopbm|ppmtoxpm, at least.
|
|
1426
|
|
1427 It might be nice if there was some way to tag the
|
|
1428 colors in the XPM file with whether they are the
|
|
1429 foreground - perhaps with logical color names somehow?
|
|
1430
|
|
1431 Once we have decided which color is the foreground, we
|
|
1432 need to ensure that that color corresponds to a `1' bit
|
|
1433 in the Pixmap. The XPM library wrote into the (1-bit)
|
|
1434 pixmap with XPutPixel, which will ignore all but the
|
|
1435 least significant bit.
|
|
1436
|
|
1437 This means that a 1 bit in the image corresponds to
|
|
1438 `fg' only if `fg.pixel' is odd.
|
|
1439
|
|
1440 (This also means that the image will be all the same
|
|
1441 color if both `fg' and `bg' are odd or even, but we can
|
|
1442 safely assume that that won't happen if the XPM file is
|
|
1443 sensible I think.)
|
|
1444
|
|
1445 The desired result is that the image use `1' to
|
|
1446 represent the foreground color, and `0' to represent
|
|
1447 the background color. So, we may need to invert the
|
|
1448 image to accomplish this; we invert if fg is
|
|
1449 odd. (Remember that WhitePixel and BlackPixel are not
|
|
1450 necessarily 1 and 0 respectively, though I think it
|
|
1451 might be safe to assume that one of them is always 1
|
|
1452 and the other is always 0. We also pretty much need to
|
|
1453 assume that one is even and the other is odd.)
|
|
1454 */
|
|
1455
|
|
1456 fg.pixel = pixels[0]; /* pick a pixel at random. */
|
|
1457 bg.pixel = fg.pixel;
|
|
1458 for (i = 1; i < npixels; i++) /* Look for an "other" pixel value.*/
|
|
1459 {
|
|
1460 bg.pixel = pixels[i];
|
|
1461 if (fg.pixel != bg.pixel)
|
|
1462 break;
|
|
1463 }
|
|
1464
|
|
1465 /* If (fg.pixel == bg.pixel) then probably something has
|
|
1466 gone wrong, but I don't think signalling an error would
|
|
1467 be appropriate. */
|
|
1468
|
|
1469 XQueryColor (dpy, cmap, &fg);
|
|
1470 XQueryColor (dpy, cmap, &bg);
|
|
1471
|
|
1472 /* If the foreground is lighter than the background, swap them.
|
|
1473 (This occurs semi-randomly, depending on the ordering of the
|
|
1474 color list in the XPM file.)
|
|
1475 */
|
|
1476 {
|
|
1477 unsigned short fg_total = ((fg.red / 3) + (fg.green / 3)
|
|
1478 + (fg.blue / 3));
|
|
1479 unsigned short bg_total = ((bg.red / 3) + (bg.green / 3)
|
|
1480 + (bg.blue / 3));
|
|
1481 if (fg_total > bg_total)
|
|
1482 {
|
|
1483 XColor swap;
|
|
1484 swap = fg;
|
|
1485 fg = bg;
|
|
1486 bg = swap;
|
|
1487 }
|
|
1488 }
|
|
1489
|
|
1490 /* If the fg pixel corresponds to a `0' in the bitmap, invert it.
|
|
1491 (This occurs (only?) on servers with Black=0, White=1.)
|
|
1492 */
|
|
1493 if ((fg.pixel & 1) == 0)
|
|
1494 {
|
|
1495 XGCValues gcv;
|
|
1496 GC gc;
|
|
1497 gcv.function = GXxor;
|
|
1498 gcv.foreground = 1;
|
|
1499 gc = XCreateGC (dpy, pixmap, (GCFunction | GCForeground),
|
|
1500 &gcv);
|
|
1501 XFillRectangle (dpy, pixmap, gc, 0, 0, w, h);
|
|
1502 XFreeGC (dpy, gc);
|
|
1503 }
|
|
1504 }
|
|
1505 else
|
|
1506 {
|
|
1507 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg,
|
|
1508 &fg, &bg);
|
|
1509 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg;
|
|
1510 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg;
|
|
1511 }
|
|
1512
|
|
1513 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1514 XCreatePixmapCursor
|
|
1515 (dpy, pixmap, mask, &fg, &bg, xhot, yhot);
|
|
1516 }
|
|
1517
|
|
1518 break;
|
|
1519
|
|
1520 default:
|
|
1521 abort ();
|
|
1522 }
|
|
1523
|
|
1524 xpm_free (&xpmattrs); /* after we've read pixels and hotspot */
|
|
1525 }
|
|
1526
|
|
1527 #endif /* HAVE_XPM */
|
|
1528
|
|
1529
|
|
1530 #ifdef HAVE_XFACE
|
|
1531
|
|
1532 /**********************************************************************
|
|
1533 * X-Face *
|
|
1534 **********************************************************************/
|
|
1535 #if defined(EXTERN)
|
|
1536 /* This is about to get redefined! */
|
|
1537 #undef EXTERN
|
|
1538 #endif
|
|
1539 /* We have to define SYSV32 so that compface.h includes string.h
|
|
1540 instead of strings.h. */
|
|
1541 #define SYSV32
|
|
1542 #ifdef __cplusplus
|
|
1543 extern "C" {
|
|
1544 #endif
|
|
1545 #include <compface.h>
|
|
1546 #ifdef __cplusplus
|
|
1547 }
|
|
1548 #endif
|
|
1549 /* JMP_BUF cannot be used here because if it doesn't get defined
|
|
1550 to jmp_buf we end up with a conflicting type error with the
|
|
1551 definition in compface.h */
|
|
1552 extern jmp_buf comp_env;
|
|
1553 #undef SYSV32
|
|
1554
|
|
1555 static void
|
|
1556 x_xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1557 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1558 int dest_mask, Lisp_Object domain)
|
|
1559 {
|
|
1560 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1561 int i, stattis;
|
771
|
1562 Char_Binary *bits, *bp;
|
|
1563 Char_Binary *p;
|
|
1564 const Intbyte * volatile emsg = 0;
|
|
1565 Char_Binary * volatile dstring;
|
428
|
1566
|
|
1567 assert (!NILP (data));
|
|
1568
|
442
|
1569 LISP_STRING_TO_EXTERNAL (data, dstring, Qbinary);
|
428
|
1570
|
|
1571 if ((p = strchr (dstring, ':')))
|
|
1572 {
|
|
1573 dstring = p + 1;
|
|
1574 }
|
|
1575
|
|
1576 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
1577 if (!(stattis = setjmp (comp_env)))
|
|
1578 {
|
771
|
1579 UnCompAll (dstring);
|
428
|
1580 UnGenFace ();
|
|
1581 }
|
|
1582
|
|
1583 switch (stattis)
|
|
1584 {
|
|
1585 case -2:
|
|
1586 emsg = "uncompface: internal error";
|
|
1587 break;
|
|
1588 case -1:
|
|
1589 emsg = "uncompface: insufficient or invalid data";
|
|
1590 break;
|
|
1591 case 1:
|
|
1592 emsg = "uncompface: excess data ignored";
|
|
1593 break;
|
|
1594 }
|
|
1595
|
|
1596 if (emsg)
|
563
|
1597 gui_error_2 (emsg, data, Qimage);
|
428
|
1598
|
771
|
1599 bp = bits = (Char_Binary *) alloca (PIXELS / 8);
|
428
|
1600
|
|
1601 /* the compface library exports char F[], which uses a single byte per
|
|
1602 pixel to represent a 48x48 bitmap. Yuck. */
|
|
1603 for (i = 0, p = F; i < (PIXELS / 8); ++i)
|
|
1604 {
|
|
1605 int n, b;
|
|
1606 /* reverse the bit order of each byte... */
|
|
1607 for (b = n = 0; b < 8; ++b)
|
|
1608 {
|
|
1609 n |= ((*p++) << b);
|
|
1610 }
|
771
|
1611 *bp++ = (Char_Binary) n;
|
428
|
1612 }
|
|
1613
|
|
1614 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1615 pointer_bg, dest_mask, 48, 48, bits);
|
|
1616 }
|
|
1617
|
|
1618 #endif /* HAVE_XFACE */
|
|
1619
|
|
1620
|
|
1621 /**********************************************************************
|
|
1622 * Autodetect *
|
|
1623 **********************************************************************/
|
|
1624
|
|
1625 static void
|
|
1626 autodetect_validate (Lisp_Object instantiator)
|
|
1627 {
|
|
1628 data_must_be_present (instantiator);
|
|
1629 }
|
|
1630
|
|
1631 static Lisp_Object
|
|
1632 autodetect_normalize (Lisp_Object instantiator,
|
442
|
1633 Lisp_Object console_type,
|
|
1634 Lisp_Object dest_mask)
|
428
|
1635 {
|
|
1636 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
1637 Lisp_Object filename = Qnil;
|
|
1638 Lisp_Object data = Qnil;
|
|
1639 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1640 Lisp_Object alist = Qnil;
|
|
1641
|
|
1642 GCPRO3 (filename, data, alist);
|
|
1643
|
|
1644 if (NILP (file)) /* no conversion necessary */
|
|
1645 RETURN_UNGCPRO (instantiator);
|
|
1646
|
|
1647 alist = tagged_vector_to_alist (instantiator);
|
|
1648
|
|
1649 filename = locate_pixmap_file (file);
|
|
1650 if (!NILP (filename))
|
|
1651 {
|
|
1652 int xhot, yhot;
|
|
1653 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
1654 called by pixmap_to_lisp_data, don't return an error value
|
|
1655 if the given file is not a valid XPM file. Instead, they
|
|
1656 just seg fault. It is definitely caused by passing a
|
|
1657 bitmap. To try and avoid this we check for bitmaps first. */
|
|
1658
|
|
1659 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
1660
|
|
1661 if (!EQ (data, Qt))
|
|
1662 {
|
|
1663 alist = remassq_no_quit (Q_data, alist);
|
|
1664 alist = Fcons (Fcons (Q_file, filename),
|
|
1665 Fcons (Fcons (Q_data, data), alist));
|
|
1666 if (xhot != -1)
|
|
1667 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
1668 alist);
|
|
1669 if (yhot != -1)
|
|
1670 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
1671 alist);
|
|
1672
|
|
1673 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type);
|
|
1674
|
|
1675 {
|
|
1676 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
1677 free_alist (alist);
|
|
1678 RETURN_UNGCPRO (result);
|
|
1679 }
|
|
1680 }
|
|
1681
|
|
1682 #ifdef HAVE_XPM
|
|
1683 data = pixmap_to_lisp_data (filename, 1);
|
|
1684
|
|
1685 if (!EQ (data, Qt))
|
|
1686 {
|
|
1687 alist = remassq_no_quit (Q_data, alist);
|
|
1688 alist = Fcons (Fcons (Q_file, filename),
|
|
1689 Fcons (Fcons (Q_data, data), alist));
|
|
1690 alist = Fcons (Fcons (Q_color_symbols,
|
|
1691 evaluate_xpm_color_symbols ()),
|
|
1692 alist);
|
|
1693 {
|
|
1694 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1695 free_alist (alist);
|
|
1696 RETURN_UNGCPRO (result);
|
|
1697 }
|
|
1698 }
|
|
1699 #endif
|
|
1700 }
|
|
1701
|
|
1702 /* If we couldn't convert it, just put it back as it is.
|
|
1703 We might try to further frob it later as a cursor-font
|
|
1704 specification. (We can't do that now because we don't know
|
|
1705 what dest-types it's going to be instantiated into.) */
|
|
1706 {
|
|
1707 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
|
1708 free_alist (alist);
|
|
1709 RETURN_UNGCPRO (result);
|
|
1710 }
|
|
1711 }
|
|
1712
|
|
1713 static int
|
|
1714 autodetect_possible_dest_types (void)
|
|
1715 {
|
|
1716 return
|
|
1717 IMAGE_MONO_PIXMAP_MASK |
|
|
1718 IMAGE_COLOR_PIXMAP_MASK |
|
|
1719 IMAGE_POINTER_MASK |
|
|
1720 IMAGE_TEXT_MASK;
|
|
1721 }
|
|
1722
|
|
1723 static void
|
|
1724 autodetect_instantiate (Lisp_Object image_instance,
|
438
|
1725 Lisp_Object instantiator,
|
|
1726 Lisp_Object pointer_fg,
|
|
1727 Lisp_Object pointer_bg,
|
|
1728 int dest_mask, Lisp_Object domain)
|
428
|
1729 {
|
|
1730 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1731 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1732 Lisp_Object alist = Qnil;
|
|
1733 Lisp_Object result = Qnil;
|
|
1734 int is_cursor_font = 0;
|
|
1735
|
|
1736 GCPRO3 (data, alist, result);
|
|
1737
|
|
1738 alist = tagged_vector_to_alist (instantiator);
|
|
1739 if (dest_mask & IMAGE_POINTER_MASK)
|
|
1740 {
|
442
|
1741 const char *name_ext;
|
|
1742 LISP_STRING_TO_EXTERNAL (data, name_ext, Qfile_name);
|
428
|
1743 if (XmuCursorNameToIndex (name_ext) != -1)
|
|
1744 {
|
|
1745 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
1746 is_cursor_font = 1;
|
|
1747 }
|
|
1748 }
|
|
1749
|
|
1750 if (!is_cursor_font)
|
|
1751 result = alist_to_tagged_vector (Qstring, alist);
|
|
1752 free_alist (alist);
|
|
1753
|
|
1754 if (is_cursor_font)
|
|
1755 cursor_font_instantiate (image_instance, result, pointer_fg,
|
|
1756 pointer_bg, dest_mask, domain);
|
|
1757 else
|
|
1758 string_instantiate (image_instance, result, pointer_fg,
|
|
1759 pointer_bg, dest_mask, domain);
|
|
1760
|
|
1761 UNGCPRO;
|
|
1762 }
|
|
1763
|
|
1764
|
|
1765 /**********************************************************************
|
|
1766 * Font *
|
|
1767 **********************************************************************/
|
|
1768
|
|
1769 static void
|
|
1770 font_validate (Lisp_Object instantiator)
|
|
1771 {
|
|
1772 data_must_be_present (instantiator);
|
|
1773 }
|
|
1774
|
|
1775 /* XmuCvtStringToCursor is bogus in the following ways:
|
|
1776
|
|
1777 - When it can't convert the given string to a real cursor, it will
|
|
1778 sometimes return a "success" value, after triggering a BadPixmap
|
|
1779 error. It then gives you a cursor that will itself generate BadCursor
|
|
1780 errors. So we install this error handler to catch/notice the X error
|
|
1781 and take that as meaning "couldn't convert."
|
|
1782
|
|
1783 - When you tell it to find a cursor file that doesn't exist, it prints
|
|
1784 an error message on stderr. You can't make it not do that.
|
|
1785
|
|
1786 - Also, using Xmu means we can't properly hack Lisp_Image_Instance
|
|
1787 objects, or XPM files, or $XBMLANGPATH.
|
|
1788 */
|
|
1789
|
|
1790 /* Duplicate the behavior of XmuCvtStringToCursor() to bypass its bogusness. */
|
|
1791
|
|
1792 static int XLoadFont_got_error;
|
|
1793
|
|
1794 static int
|
|
1795 XLoadFont_error_handler (Display *dpy, XErrorEvent *xerror)
|
|
1796 {
|
|
1797 XLoadFont_got_error = 1;
|
|
1798 return 0;
|
|
1799 }
|
|
1800
|
|
1801 static Font
|
771
|
1802 safe_XLoadFont (Display *dpy, Intbyte *name)
|
428
|
1803 {
|
|
1804 Font font;
|
|
1805 int (*old_handler) (Display *, XErrorEvent *);
|
771
|
1806 Extbyte *nameext;
|
|
1807
|
428
|
1808 XLoadFont_got_error = 0;
|
|
1809 XSync (dpy, 0);
|
|
1810 old_handler = XSetErrorHandler (XLoadFont_error_handler);
|
771
|
1811 C_STRING_TO_EXTERNAL (name, nameext, Qfile_name);
|
|
1812 font = XLoadFont (dpy, nameext);
|
428
|
1813 XSync (dpy, 0);
|
|
1814 XSetErrorHandler (old_handler);
|
|
1815 if (XLoadFont_got_error) return 0;
|
|
1816 return font;
|
|
1817 }
|
|
1818
|
|
1819 static int
|
|
1820 font_possible_dest_types (void)
|
|
1821 {
|
|
1822 return IMAGE_POINTER_MASK;
|
|
1823 }
|
|
1824
|
|
1825 static void
|
|
1826 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1827 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1828 int dest_mask, Lisp_Object domain)
|
|
1829 {
|
|
1830 /* This function can GC */
|
|
1831 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
440
|
1832 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
1833 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1834 Display *dpy;
|
|
1835 XColor fg, bg;
|
|
1836 Font source, mask;
|
771
|
1837 Intbyte source_name[PATH_MAX], mask_name[PATH_MAX], dummy;
|
428
|
1838 int source_char, mask_char;
|
|
1839 int count;
|
|
1840 Lisp_Object foreground, background;
|
|
1841
|
|
1842 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
1843 gui_error ("Not an X device", device);
|
428
|
1844
|
|
1845 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1846
|
|
1847 if (!STRINGP (data) ||
|
|
1848 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
563
|
1849 invalid_argument ("Invalid font-glyph instantiator",
|
428
|
1850 instantiator);
|
|
1851
|
|
1852 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1853 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1854
|
|
1855 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1856 if (NILP (foreground))
|
|
1857 foreground = pointer_fg;
|
|
1858 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1859 if (NILP (background))
|
|
1860 background = pointer_bg;
|
|
1861
|
|
1862 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
1863
|
|
1864 count = sscanf ((char *) XSTRING_DATA (data),
|
|
1865 "FONT %s %d %s %d %c",
|
|
1866 source_name, &source_char,
|
|
1867 mask_name, &mask_char, &dummy);
|
|
1868 /* Allow "%s %d %d" as well... */
|
771
|
1869 if (count == 3 && (1 == sscanf ((char *) mask_name, "%d %c", &mask_char,
|
|
1870 &dummy)))
|
428
|
1871 count = 4, mask_name[0] = 0;
|
|
1872
|
|
1873 if (count != 2 && count != 4)
|
563
|
1874 syntax_error ("invalid cursor specification", data);
|
428
|
1875 source = safe_XLoadFont (dpy, source_name);
|
|
1876 if (! source)
|
563
|
1877 signal_error_2 (Qgui_error,
|
771
|
1878 "couldn't load font", build_intstring (source_name), data);
|
428
|
1879 if (count == 2)
|
|
1880 mask = 0;
|
|
1881 else if (!mask_name[0])
|
|
1882 mask = source;
|
|
1883 else
|
|
1884 {
|
|
1885 mask = safe_XLoadFont (dpy, mask_name);
|
|
1886 if (!mask)
|
563
|
1887 signal_continuable_error_2 (Qgui_error,
|
|
1888 "couldn't load font",
|
771
|
1889 build_intstring (mask_name), data);
|
428
|
1890 }
|
|
1891 if (!mask)
|
|
1892 mask_char = 0;
|
|
1893
|
|
1894 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
1895
|
|
1896 x_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1897 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1898 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
1899 &fg, &bg);
|
|
1900 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
1901 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
1902 XUnloadFont (dpy, source);
|
|
1903 if (mask && mask != source) XUnloadFont (dpy, mask);
|
|
1904 }
|
|
1905
|
|
1906
|
|
1907 /**********************************************************************
|
|
1908 * Cursor-Font *
|
|
1909 **********************************************************************/
|
|
1910
|
|
1911 static void
|
|
1912 cursor_font_validate (Lisp_Object instantiator)
|
|
1913 {
|
|
1914 data_must_be_present (instantiator);
|
|
1915 }
|
|
1916
|
|
1917 static int
|
|
1918 cursor_font_possible_dest_types (void)
|
|
1919 {
|
|
1920 return IMAGE_POINTER_MASK;
|
|
1921 }
|
|
1922
|
|
1923 static void
|
|
1924 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1925 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1926 int dest_mask, Lisp_Object domain)
|
|
1927 {
|
|
1928 /* This function can GC */
|
|
1929 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
440
|
1930 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
1931 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1932 Display *dpy;
|
|
1933 int i;
|
771
|
1934 const Extbyte *name_ext;
|
428
|
1935 Lisp_Object foreground, background;
|
|
1936
|
|
1937 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
1938 gui_error ("Not an X device", device);
|
428
|
1939
|
|
1940 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1941
|
|
1942 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1943 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1944
|
442
|
1945 LISP_STRING_TO_EXTERNAL (data, name_ext, Qfile_name);
|
428
|
1946 if ((i = XmuCursorNameToIndex (name_ext)) == -1)
|
563
|
1947 invalid_argument ("Unrecognized cursor-font name", data);
|
428
|
1948
|
|
1949 x_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1950 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i);
|
|
1951 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1952 if (NILP (foreground))
|
|
1953 foreground = pointer_fg;
|
|
1954 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1955 if (NILP (background))
|
|
1956 background = pointer_bg;
|
|
1957 maybe_recolor_cursor (image_instance, foreground, background);
|
|
1958 }
|
|
1959
|
|
1960 static int
|
|
1961 x_colorize_image_instance (Lisp_Object image_instance,
|
|
1962 Lisp_Object foreground, Lisp_Object background)
|
|
1963 {
|
440
|
1964 Lisp_Image_Instance *p;
|
428
|
1965
|
|
1966 p = XIMAGE_INSTANCE (image_instance);
|
|
1967
|
|
1968 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1969 {
|
|
1970 case IMAGE_MONO_PIXMAP:
|
|
1971 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
1972 /* Make sure there aren't two pointers to the same mask, causing
|
|
1973 it to get freed twice. */
|
|
1974 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
|
|
1975 break;
|
|
1976
|
|
1977 default:
|
|
1978 return 0;
|
|
1979 }
|
|
1980
|
|
1981 {
|
|
1982 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
1983 Drawable draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
1984 Dimension d = DEVICE_X_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
1985 Pixmap new = XCreatePixmap (dpy, draw,
|
|
1986 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
1987 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d);
|
|
1988 XColor color;
|
|
1989 XGCValues gcv;
|
|
1990 GC gc;
|
|
1991 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground));
|
|
1992 gcv.foreground = color.pixel;
|
|
1993 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background));
|
|
1994 gcv.background = color.pixel;
|
|
1995 gc = XCreateGC (dpy, new, GCBackground|GCForeground, &gcv);
|
|
1996 XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP (p), new, gc, 0, 0,
|
|
1997 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
1998 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
1999 0, 0, 1);
|
|
2000 XFreeGC (dpy, gc);
|
|
2001 IMAGE_INSTANCE_X_PIXMAP (p) = new;
|
|
2002 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = d;
|
|
2003 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
2004 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
2005 return 1;
|
|
2006 }
|
|
2007 }
|
|
2008
|
|
2009
|
|
2010 /************************************************************************/
|
|
2011 /* subwindow and widget support */
|
|
2012 /************************************************************************/
|
|
2013
|
|
2014 /* unmap the image if it is a widget. This is used by redisplay via
|
|
2015 redisplay_unmap_subwindows */
|
|
2016 static void
|
440
|
2017 x_unmap_subwindow (Lisp_Image_Instance *p)
|
428
|
2018 {
|
|
2019 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
2020 {
|
438
|
2021 XUnmapWindow
|
|
2022 (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
428
|
2023 IMAGE_INSTANCE_X_CLIPWINDOW (p));
|
|
2024 }
|
|
2025 else /* must be a widget */
|
|
2026 {
|
450
|
2027 /* Since we are being unmapped we want the enclosing frame to
|
|
2028 get focus. The losing with simple scrolling but is the safest
|
|
2029 thing to do. */
|
|
2030 emacs_Xt_handle_widget_losing_focus
|
|
2031 ( XFRAME (IMAGE_INSTANCE_FRAME (p)),
|
|
2032 IMAGE_INSTANCE_X_WIDGET_ID (p));
|
428
|
2033 XtUnmapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
|
|
2034 }
|
|
2035 }
|
|
2036
|
|
2037 /* map the subwindow. This is used by redisplay via
|
|
2038 redisplay_output_subwindow */
|
|
2039 static void
|
440
|
2040 x_map_subwindow (Lisp_Image_Instance *p, int x, int y,
|
428
|
2041 struct display_glyph_area* dga)
|
|
2042 {
|
448
|
2043 assert (dga->width > 0 && dga->height > 0);
|
428
|
2044 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
2045 {
|
|
2046 Window subwindow = IMAGE_INSTANCE_X_SUBWINDOW_ID (p);
|
|
2047 XMoveResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
438
|
2048 IMAGE_INSTANCE_X_CLIPWINDOW (p),
|
428
|
2049 x, y, dga->width, dga->height);
|
|
2050 XMoveWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2051 subwindow, -dga->xoffset, -dga->yoffset);
|
442
|
2052 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
|
|
2053 XMapWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2054 IMAGE_INSTANCE_X_CLIPWINDOW (p));
|
428
|
2055 }
|
|
2056 else /* must be a widget */
|
|
2057 {
|
438
|
2058 XtConfigureWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p),
|
428
|
2059 x + IMAGE_INSTANCE_X_WIDGET_XOFFSET (p),
|
|
2060 y + IMAGE_INSTANCE_X_WIDGET_YOFFSET (p),
|
|
2061 dga->width, dga->height, 0);
|
|
2062 XtMoveWidget (IMAGE_INSTANCE_X_WIDGET_ID (p),
|
|
2063 -dga->xoffset, -dga->yoffset);
|
442
|
2064 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
|
|
2065 XtMapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
|
428
|
2066 }
|
|
2067 }
|
|
2068
|
|
2069 /* when you click on a widget you may activate another widget this
|
|
2070 needs to be checked and all appropriate widgets updated */
|
|
2071 static void
|
442
|
2072 x_redisplay_subwindow (Lisp_Image_Instance *p)
|
|
2073 {
|
|
2074 /* Update the subwindow size if necessary. */
|
|
2075 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
|
|
2076 {
|
|
2077 XResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2078 IMAGE_INSTANCE_X_SUBWINDOW_ID (p),
|
|
2079 IMAGE_INSTANCE_WIDTH (p),
|
|
2080 IMAGE_INSTANCE_HEIGHT (p));
|
|
2081 }
|
|
2082 }
|
|
2083
|
|
2084 /* Update all attributes that have changed. Lwlib actually does most
|
|
2085 of this for us. */
|
|
2086 static void
|
|
2087 x_redisplay_widget (Lisp_Image_Instance *p)
|
428
|
2088 {
|
442
|
2089 /* This function can GC if IN_REDISPLAY is false. */
|
771
|
2090 #ifdef HAVE_X_WIDGETS
|
442
|
2091 widget_value* wv = 0;
|
|
2092
|
|
2093 /* First get the items if they have changed since this is a
|
|
2094 structural change. As such it will nuke all added values so we
|
|
2095 need to update most other things after the items have changed.*/
|
|
2096 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2097 {
|
793
|
2098 Lisp_Object image_instance = wrap_image_instance (p);
|
|
2099
|
442
|
2100 wv = gui_items_to_widget_values
|
|
2101 (image_instance, IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (p),
|
|
2102 /* #### this is not right; we need to keep track of which widgets
|
|
2103 want accelerators and which don't */ 0);
|
|
2104 wv->change = STRUCTURAL_CHANGE;
|
|
2105 }
|
|
2106 else
|
428
|
2107 {
|
442
|
2108 /* Assume the lotus position, breath deeply and chant to
|
|
2109 yourself lwlibsux, lwlibsux ... lw_get_all_values returns a
|
|
2110 reference to the real values rather than a copy thus any
|
|
2111 changes we make to the values we get back will look like they
|
|
2112 have already been applied. If we rebuild the widget tree then
|
444
|
2113 we may lose properties. */
|
|
2114 wv = copy_widget_value_tree (lw_get_all_values
|
442
|
2115 (IMAGE_INSTANCE_X_WIDGET_LWID (p)),
|
|
2116 NO_CHANGE);
|
|
2117 }
|
|
2118
|
|
2119 /* Possibly update the colors and font */
|
|
2120 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p)
|
|
2121 ||
|
454
|
2122 /* #### This is not sufficient because it will not cope with widgets
|
|
2123 that are not currently visible. Once redisplay has done the
|
|
2124 visible ones it will clear this flag so that when new ones
|
|
2125 become visible they will not be updated. */
|
442
|
2126 XFRAME (IMAGE_INSTANCE_FRAME (p))->faces_changed
|
|
2127 ||
|
454
|
2128 XFRAME (IMAGE_INSTANCE_FRAME (p))->frame_changed
|
|
2129 ||
|
442
|
2130 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2131 {
|
|
2132 update_widget_face (wv, p, IMAGE_INSTANCE_FRAME (p));
|
|
2133 }
|
|
2134
|
|
2135 /* Possibly update the text. */
|
|
2136 if (IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2137 {
|
771
|
2138 Extbyte* str;
|
442
|
2139 Lisp_Object val = IMAGE_INSTANCE_WIDGET_TEXT (p);
|
|
2140 LISP_STRING_TO_EXTERNAL (val, str, Qnative);
|
|
2141 wv->value = str;
|
|
2142 }
|
|
2143
|
|
2144 /* Possibly update the size. */
|
|
2145 if (IMAGE_INSTANCE_SIZE_CHANGED (p)
|
|
2146 ||
|
|
2147 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p)
|
|
2148 ||
|
|
2149 IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2150 {
|
|
2151 assert (IMAGE_INSTANCE_X_WIDGET_ID (p) &&
|
|
2152 IMAGE_INSTANCE_X_CLIPWIDGET (p)) ;
|
|
2153
|
|
2154 if (IMAGE_INSTANCE_X_WIDGET_ID (p)->core.being_destroyed
|
|
2155 || !XtIsManaged(IMAGE_INSTANCE_X_WIDGET_ID (p)))
|
428
|
2156 {
|
793
|
2157 Lisp_Object sw = wrap_image_instance (p);
|
|
2158
|
563
|
2159 signal_error (Qinternal_error,
|
|
2160 "XEmacs bug: subwindow is deleted", sw);
|
434
|
2161 }
|
442
|
2162
|
|
2163 lw_add_widget_value_arg (wv, XtNwidth,
|
|
2164 (Dimension)IMAGE_INSTANCE_WIDTH (p));
|
|
2165 lw_add_widget_value_arg (wv, XtNheight,
|
|
2166 (Dimension)IMAGE_INSTANCE_HEIGHT (p));
|
428
|
2167 }
|
442
|
2168
|
448
|
2169 /* Adjust offsets within the frame. */
|
450
|
2170 if (XFRAME (IMAGE_INSTANCE_FRAME (p))->size_changed)
|
448
|
2171 {
|
|
2172 Arg al[2];
|
|
2173 XtSetArg (al [0], XtNx, &IMAGE_INSTANCE_X_WIDGET_XOFFSET (p));
|
|
2174 XtSetArg (al [1], XtNy, &IMAGE_INSTANCE_X_WIDGET_YOFFSET (p));
|
|
2175 XtGetValues (FRAME_X_TEXT_WIDGET
|
|
2176 (XFRAME (IMAGE_INSTANCE_FRAME (p))), al, 2);
|
|
2177 }
|
|
2178
|
442
|
2179 /* now modify the widget */
|
|
2180 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (p),
|
|
2181 wv, True);
|
|
2182 free_widget_value_tree (wv);
|
428
|
2183 #endif
|
|
2184 }
|
|
2185
|
|
2186 /* instantiate and x type subwindow */
|
|
2187 static void
|
|
2188 x_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2189 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2190 int dest_mask, Lisp_Object domain)
|
|
2191 {
|
|
2192 /* This function can GC */
|
440
|
2193 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2194 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
442
|
2195 Lisp_Object frame = DOMAIN_FRAME (domain);
|
428
|
2196 struct frame* f = XFRAME (frame);
|
|
2197 Display *dpy;
|
|
2198 Screen *xs;
|
|
2199 Window pw, win;
|
|
2200 XSetWindowAttributes xswa;
|
|
2201 Mask valueMask = 0;
|
647
|
2202 int w = IMAGE_INSTANCE_WIDTH (ii), h = IMAGE_INSTANCE_HEIGHT (ii);
|
428
|
2203
|
|
2204 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
2205 gui_error ("Not an X device", device);
|
428
|
2206
|
|
2207 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
2208 xs = DefaultScreenOfDisplay (dpy);
|
|
2209
|
|
2210 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
|
|
2211
|
|
2212 pw = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2213
|
|
2214 ii->data = xnew_and_zero (struct x_subwindow_data);
|
|
2215
|
|
2216 IMAGE_INSTANCE_X_SUBWINDOW_PARENT (ii) = pw;
|
|
2217 IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (ii) = DisplayOfScreen (xs);
|
|
2218
|
|
2219 xswa.backing_store = Always;
|
|
2220 valueMask |= CWBackingStore;
|
|
2221 xswa.colormap = DefaultColormapOfScreen (xs);
|
|
2222 valueMask |= CWColormap;
|
438
|
2223
|
428
|
2224 /* Create a window for clipping */
|
438
|
2225 IMAGE_INSTANCE_X_CLIPWINDOW (ii) =
|
428
|
2226 XCreateWindow (dpy, pw, 0, 0, w, h, 0, CopyFromParent,
|
|
2227 InputOutput, CopyFromParent, valueMask,
|
|
2228 &xswa);
|
|
2229
|
|
2230 /* Now put the subwindow inside the clip window. */
|
|
2231 win = XCreateWindow (dpy, IMAGE_INSTANCE_X_CLIPWINDOW (ii),
|
|
2232 0, 0, w, h, 0, CopyFromParent,
|
|
2233 InputOutput, CopyFromParent, valueMask,
|
|
2234 &xswa);
|
438
|
2235
|
428
|
2236 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)win;
|
|
2237 }
|
|
2238
|
|
2239 #if 0
|
|
2240 /* #### Should this function exist? If there's any doubt I'm not implementing it --andyp */
|
|
2241 DEFUN ("change-subwindow-property", Fchange_subwindow_property, 3, 3, 0, /*
|
|
2242 For the given SUBWINDOW, set PROPERTY to DATA, which is a string.
|
|
2243 Subwindows are not currently implemented.
|
|
2244 */
|
|
2245 (subwindow, property, data))
|
|
2246 {
|
|
2247 Atom property_atom;
|
440
|
2248 Lisp_Subwindow *sw;
|
428
|
2249 Display *dpy;
|
771
|
2250 Extbyte *propext, *dataext;
|
|
2251 Bytecount datalen;
|
428
|
2252
|
|
2253 CHECK_SUBWINDOW (subwindow);
|
|
2254 CHECK_STRING (property);
|
|
2255 CHECK_STRING (data);
|
|
2256
|
|
2257 sw = XSUBWINDOW (subwindow);
|
|
2258 dpy = DisplayOfScreen (LISP_DEVICE_TO_X_SCREEN
|
|
2259 (FRAME_DEVICE (XFRAME (sw->frame))));
|
|
2260
|
771
|
2261 LISP_TO_EXTERNAL (property, propext, Qctext);
|
|
2262 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
2263 ALLOCA, (dataext, datalen), Qctext);
|
|
2264 property_atom = XInternAtom (dpy, propext, False);
|
428
|
2265 XChangeProperty (dpy, sw->subwindow, property_atom, XA_STRING, 8,
|
771
|
2266 PropModeReplace, dataext, datalen);
|
428
|
2267 return property;
|
|
2268 }
|
|
2269 #endif
|
|
2270
|
|
2271
|
771
|
2272 #ifdef HAVE_X_WIDGETS
|
428
|
2273
|
|
2274 /************************************************************************/
|
|
2275 /* widgets */
|
|
2276 /************************************************************************/
|
|
2277
|
|
2278 static void
|
440
|
2279 update_widget_face (widget_value* wv, Lisp_Image_Instance *ii,
|
434
|
2280 Lisp_Object domain)
|
428
|
2281 {
|
|
2282 #ifdef LWLIB_WIDGETS_MOTIF
|
|
2283 XmFontList fontList;
|
|
2284 #endif
|
438
|
2285 /* Update the foreground. */
|
|
2286 Lisp_Object pixel = FACE_FOREGROUND
|
428
|
2287 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
434
|
2288 domain);
|
438
|
2289 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel)), bcolor;
|
434
|
2290 lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
|
438
|
2291
|
|
2292 /* Update the background. */
|
|
2293 pixel = FACE_BACKGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
|
2294 domain);
|
|
2295 bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2296 lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
|
|
2297
|
428
|
2298 #ifdef LWLIB_WIDGETS_MOTIF
|
|
2299 fontList = XmFontListCreate
|
438
|
2300 (FONT_INSTANCE_X_FONT
|
|
2301 (XFONT_INSTANCE (query_string_font
|
|
2302 (IMAGE_INSTANCE_WIDGET_TEXT (ii),
|
434
|
2303 IMAGE_INSTANCE_WIDGET_FACE (ii),
|
438
|
2304 domain))), XmSTRING_DEFAULT_CHARSET);
|
434
|
2305 lw_add_widget_value_arg (wv, XmNfontList, (XtArgVal)fontList);
|
428
|
2306 #endif
|
438
|
2307 lw_add_widget_value_arg
|
|
2308 (wv, XtNfont, (XtArgVal)FONT_INSTANCE_X_FONT
|
|
2309 (XFONT_INSTANCE (query_string_font
|
|
2310 (IMAGE_INSTANCE_WIDGET_TEXT (ii),
|
434
|
2311 IMAGE_INSTANCE_WIDGET_FACE (ii),
|
438
|
2312 domain))));
|
442
|
2313 wv->change = VISIBLE_CHANGE;
|
|
2314 /* #### Megahack - but its just getting too complicated to do this
|
|
2315 in the right place. */
|
|
2316 if (EQ (IMAGE_INSTANCE_WIDGET_TYPE (ii), Qtab_control))
|
|
2317 update_tab_widget_face (wv, ii, domain);
|
434
|
2318 }
|
|
2319
|
|
2320 static void
|
440
|
2321 update_tab_widget_face (widget_value* wv, Lisp_Image_Instance *ii,
|
434
|
2322 Lisp_Object domain)
|
|
2323 {
|
|
2324 if (wv->contents)
|
|
2325 {
|
|
2326 widget_value* val = wv->contents, *cur;
|
438
|
2327
|
434
|
2328 /* Give each child label the correct foreground color. */
|
438
|
2329 Lisp_Object pixel = FACE_FOREGROUND
|
434
|
2330 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
|
2331 domain);
|
|
2332 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2333 lw_add_widget_value_arg (val, XtNtabForeground, fcolor.pixel);
|
442
|
2334 wv->change = VISIBLE_CHANGE;
|
|
2335 val->change = VISIBLE_CHANGE;
|
434
|
2336
|
|
2337 for (cur = val->next; cur; cur = cur->next)
|
|
2338 {
|
442
|
2339 cur->change = VISIBLE_CHANGE;
|
434
|
2340 if (cur->value)
|
|
2341 {
|
|
2342 lw_copy_widget_value_args (val, cur);
|
|
2343 }
|
|
2344 }
|
|
2345 }
|
428
|
2346 }
|
|
2347
|
|
2348 static void
|
|
2349 x_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2350 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2351 int dest_mask, Lisp_Object domain,
|
442
|
2352 const char* type, widget_value* wv)
|
428
|
2353 {
|
440
|
2354 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2355 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), pixel;
|
|
2356 struct device* d = XDEVICE (device);
|
442
|
2357 Lisp_Object frame = DOMAIN_FRAME (domain);
|
428
|
2358 struct frame* f = XFRAME (frame);
|
|
2359 char* nm=0;
|
|
2360 Widget wid;
|
|
2361 Arg al [32];
|
|
2362 int ac = 0;
|
|
2363 int id = new_lwlib_id ();
|
|
2364 widget_value* clip_wv;
|
|
2365 XColor fcolor, bcolor;
|
|
2366
|
|
2367 if (!DEVICE_X_P (d))
|
563
|
2368 gui_error ("Not an X device", device);
|
428
|
2369
|
|
2370 /* have to set the type this late in case there is no device
|
|
2371 instantiation for a widget. But we can go ahead and do it without
|
|
2372 checking because there is always a generic instantiator. */
|
|
2373 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
|
|
2374
|
|
2375 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
|
442
|
2376 LISP_STRING_TO_EXTERNAL (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm, Qnative);
|
428
|
2377
|
|
2378 ii->data = xnew_and_zero (struct x_subwindow_data);
|
|
2379
|
|
2380 /* Create a clip window to contain the subwidget. Incredibly the
|
|
2381 XEmacs manager seems to be the most appropriate widget for
|
|
2382 this. Nothing else is simple enough and yet does what is
|
|
2383 required. */
|
|
2384 clip_wv = xmalloc_widget_value ();
|
|
2385
|
434
|
2386 lw_add_widget_value_arg (clip_wv, XtNresize, False);
|
438
|
2387 lw_add_widget_value_arg (clip_wv, XtNwidth,
|
442
|
2388 (Dimension)IMAGE_INSTANCE_WIDTH (ii));
|
438
|
2389 lw_add_widget_value_arg (clip_wv, XtNheight,
|
442
|
2390 (Dimension)IMAGE_INSTANCE_HEIGHT (ii));
|
428
|
2391 clip_wv->enabled = True;
|
434
|
2392
|
428
|
2393 clip_wv->name = xstrdup ("clip-window");
|
|
2394 clip_wv->value = xstrdup ("clip-window");
|
|
2395
|
|
2396 IMAGE_INSTANCE_X_CLIPWIDGET (ii)
|
|
2397 = lw_create_widget ("clip-window", "clip-window", new_lwlib_id (),
|
|
2398 clip_wv, FRAME_X_CONTAINER_WIDGET (f),
|
|
2399 False, 0, 0, 0);
|
|
2400
|
|
2401 free_widget_value_tree (clip_wv);
|
|
2402
|
|
2403 /* copy any args we were given */
|
|
2404 ac = 0;
|
434
|
2405 lw_add_value_args_to_args (wv, al, &ac);
|
428
|
2406
|
|
2407 /* Fixup the colors. We have to do this *before* the widget gets
|
|
2408 created so that Motif will fix up the shadow colors
|
|
2409 correctly. Once the widget is created Motif won't do this
|
|
2410 anymore...*/
|
438
|
2411 pixel = FACE_FOREGROUND
|
428
|
2412 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
442
|
2413 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2414 fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2415
|
|
2416 pixel = FACE_BACKGROUND
|
|
2417 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
442
|
2418 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2419 bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2420
|
434
|
2421 lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
|
|
2422 lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
|
428
|
2423 /* we cannot allow widgets to resize themselves */
|
434
|
2424 lw_add_widget_value_arg (wv, XtNresize, False);
|
438
|
2425 lw_add_widget_value_arg (wv, XtNwidth,
|
442
|
2426 (Dimension)IMAGE_INSTANCE_WIDTH (ii));
|
438
|
2427 lw_add_widget_value_arg (wv, XtNheight,
|
442
|
2428 (Dimension)IMAGE_INSTANCE_HEIGHT (ii));
|
434
|
2429 /* update the font. */
|
|
2430 update_widget_face (wv, ii, domain);
|
428
|
2431
|
|
2432 wid = lw_create_widget (type, wv->name, id, wv, IMAGE_INSTANCE_X_CLIPWIDGET (ii),
|
|
2433 False, 0, popup_selection_callback, 0);
|
|
2434
|
|
2435 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)wid;
|
|
2436 IMAGE_INSTANCE_X_WIDGET_LWID (ii) = id;
|
|
2437 /* because the EmacsManager is the widgets parent we have to
|
|
2438 offset the redisplay of the widget by the amount the text
|
|
2439 widget is inside the manager. */
|
|
2440 ac = 0;
|
|
2441 XtSetArg (al [ac], XtNx, &IMAGE_INSTANCE_X_WIDGET_XOFFSET (ii)); ac++;
|
|
2442 XtSetArg (al [ac], XtNy, &IMAGE_INSTANCE_X_WIDGET_YOFFSET (ii)); ac++;
|
|
2443 XtGetValues (FRAME_X_TEXT_WIDGET (f), al, ac);
|
|
2444
|
436
|
2445 XtSetMappedWhenManaged (wid, TRUE);
|
428
|
2446
|
|
2447 free_widget_value_tree (wv);
|
442
|
2448 /* A kludgy but simple way to make sure the callback for a widget
|
|
2449 doesn't get deleted. */
|
|
2450 gcpro_popup_callbacks (id);
|
428
|
2451 }
|
|
2452
|
|
2453 /* get properties of a control */
|
|
2454 static Lisp_Object
|
|
2455 x_widget_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2456 {
|
440
|
2457 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2458 /* get the text from a control */
|
|
2459 if (EQ (prop, Q_text))
|
|
2460 {
|
|
2461 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
|
440
|
2462 return build_ext_string (wv->value, Qnative);
|
428
|
2463 }
|
|
2464 return Qunbound;
|
|
2465 }
|
|
2466
|
442
|
2467 /* Instantiate a layout control for putting other widgets in. */
|
|
2468 static void
|
771
|
2469 x_native_layout_instantiate (Lisp_Object image_instance,
|
|
2470 Lisp_Object instantiator,
|
442
|
2471 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2472 int dest_mask, Lisp_Object domain)
|
|
2473 {
|
|
2474 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2475 pointer_bg, dest_mask, domain, "layout", 0);
|
|
2476 }
|
|
2477
|
428
|
2478 /* Instantiate a button widget. Unfortunately instantiated widgets are
|
|
2479 particular to a frame since they need to have a parent. It's not
|
|
2480 like images where you just select the image into the context you
|
|
2481 want to display it in and BitBlt it. So images instances can have a
|
|
2482 many-to-one relationship with things you see, whereas widgets can
|
|
2483 only be one-to-one (i.e. per frame) */
|
|
2484 static void
|
|
2485 x_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2486 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2487 int dest_mask, Lisp_Object domain)
|
|
2488 {
|
440
|
2489 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2490 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
|
2491 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
|
442
|
2492 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 1);
|
428
|
2493
|
|
2494 if (!NILP (glyph))
|
|
2495 {
|
|
2496 if (!IMAGE_INSTANCEP (glyph))
|
|
2497 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1);
|
|
2498 }
|
|
2499
|
|
2500 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2501 pointer_bg, dest_mask, domain, "button", wv);
|
|
2502
|
|
2503 /* add the image if one was given */
|
440
|
2504 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph)
|
|
2505 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (glyph)))
|
428
|
2506 {
|
|
2507 Arg al [2];
|
|
2508 int ac =0;
|
|
2509 #ifdef LWLIB_WIDGETS_MOTIF
|
|
2510 XtSetArg (al [ac], XmNlabelType, XmPIXMAP); ac++;
|
|
2511 XtSetArg (al [ac], XmNlabelPixmap, XIMAGE_INSTANCE_X_PIXMAP (glyph));ac++;
|
|
2512 #else
|
|
2513 XtSetArg (al [ac], XtNpixmap, XIMAGE_INSTANCE_X_PIXMAP (glyph)); ac++;
|
|
2514 #endif
|
|
2515 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, ac);
|
|
2516 }
|
|
2517 }
|
|
2518
|
442
|
2519 /* Update a button's clicked state.
|
|
2520
|
|
2521 #### This is overkill, but it works. Right now this causes all
|
|
2522 button instances to flash for some reason buried deep in lwlib. In
|
|
2523 theory this should be the Right Thing to do since lwlib should only
|
|
2524 merge in changed values - and if nothing has changed then nothing
|
|
2525 should get done. This may be because of the args stuff,
|
|
2526 i.e. although the arg contents may be the same the args look
|
|
2527 different and so are re-applied to the widget. */
|
|
2528 static void
|
|
2529 x_button_redisplay (Lisp_Object image_instance)
|
|
2530 {
|
|
2531 /* This function can GC if IN_REDISPLAY is false. */
|
|
2532 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
2533 widget_value* wv =
|
|
2534 gui_items_to_widget_values (image_instance,
|
|
2535 IMAGE_INSTANCE_WIDGET_ITEMS (p), 1);
|
|
2536
|
|
2537 /* now modify the widget */
|
|
2538 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (p),
|
|
2539 wv, True);
|
|
2540 free_widget_value_tree (wv);
|
|
2541 }
|
|
2542
|
428
|
2543 /* get properties of a button */
|
|
2544 static Lisp_Object
|
|
2545 x_button_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2546 {
|
440
|
2547 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2548 /* check the state of a button */
|
|
2549 if (EQ (prop, Q_selected))
|
|
2550 {
|
|
2551 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
|
|
2552
|
|
2553 if (wv->selected)
|
|
2554 return Qt;
|
|
2555 else
|
|
2556 return Qnil;
|
|
2557 }
|
|
2558 return Qunbound;
|
|
2559 }
|
|
2560
|
|
2561 /* instantiate a progress gauge */
|
|
2562 static void
|
|
2563 x_progress_gauge_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2564 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2565 int dest_mask, Lisp_Object domain)
|
|
2566 {
|
440
|
2567 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2568 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
442
|
2569 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 0);
|
428
|
2570
|
|
2571 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2572 pointer_bg, dest_mask, domain, "progress", wv);
|
|
2573 }
|
|
2574
|
442
|
2575 /* set the properties of a progress gauge */
|
|
2576 static void
|
|
2577 x_progress_gauge_redisplay (Lisp_Object image_instance)
|
428
|
2578 {
|
639
|
2579 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
2580
|
|
2581 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
428
|
2582 {
|
|
2583 Arg al [1];
|
442
|
2584 Lisp_Object val;
|
639
|
2585 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (p))->value;
|
428
|
2586 XtSetArg (al[0], XtNvalue, XINT (val));
|
639
|
2587 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (p), al, 1);
|
428
|
2588 }
|
|
2589 }
|
|
2590
|
|
2591 /* instantiate an edit control */
|
|
2592 static void
|
|
2593 x_edit_field_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
771
|
2594 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2595 int dest_mask, Lisp_Object domain)
|
428
|
2596 {
|
440
|
2597 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2598 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
442
|
2599 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 0);
|
438
|
2600
|
428
|
2601 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2602 pointer_bg, dest_mask, domain, "text-field", wv);
|
|
2603 }
|
|
2604
|
|
2605 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
|
2606 /* instantiate a combo control */
|
|
2607 static void
|
|
2608 x_combo_box_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
771
|
2609 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2610 int dest_mask, Lisp_Object domain)
|
428
|
2611 {
|
440
|
2612 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2613 widget_value * wv = 0;
|
|
2614 /* This is not done generically because of sizing problems under
|
|
2615 mswindows. */
|
438
|
2616 widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2617 pointer_bg, dest_mask, domain);
|
428
|
2618
|
442
|
2619 wv = gui_items_to_widget_values (image_instance,
|
|
2620 IMAGE_INSTANCE_WIDGET_ITEMS (ii), 0);
|
438
|
2621
|
428
|
2622 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2623 pointer_bg, dest_mask, domain, "combo-box", wv);
|
|
2624 }
|
|
2625 #endif
|
|
2626
|
|
2627 static void
|
|
2628 x_tab_control_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2629 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2630 int dest_mask, Lisp_Object domain)
|
|
2631 {
|
440
|
2632 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
438
|
2633 widget_value * wv =
|
442
|
2634 gui_items_to_widget_values (image_instance,
|
|
2635 IMAGE_INSTANCE_WIDGET_ITEMS (ii), 0);
|
438
|
2636 update_tab_widget_face (wv, ii,
|
442
|
2637 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2638 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2639 pointer_bg, dest_mask, domain, "tab-control", wv);
|
|
2640 }
|
|
2641
|
442
|
2642 /* Set the properties of a tab control */
|
|
2643 static void
|
|
2644 x_tab_control_redisplay (Lisp_Object image_instance)
|
428
|
2645 {
|
440
|
2646 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
438
|
2647
|
442
|
2648 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii)
|
|
2649 ||
|
|
2650 IMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (ii))
|
428
|
2651 {
|
442
|
2652 /* If only the order has changed then simply select the first
|
|
2653 one of the pending set. This stops horrendous rebuilding -
|
|
2654 and hence flicker - of the tabs each time you click on
|
|
2655 one. */
|
|
2656 if (tab_control_order_only_changed (image_instance))
|
|
2657 {
|
|
2658 Lisp_Object rest, selected =
|
|
2659 gui_item_list_find_selected
|
|
2660 (NILP (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)) ?
|
|
2661 XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)) :
|
|
2662 XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)));
|
|
2663
|
|
2664 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
|
|
2665 {
|
|
2666 if (gui_item_equal_sans_selected (XCAR (rest), selected, 0))
|
|
2667 {
|
|
2668 /* There may be an encapsulated way of doing this,
|
|
2669 but I couldn't find it. */
|
|
2670 Lisp_Object old_selected =gui_item_list_find_selected
|
|
2671 (XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)));
|
|
2672 Arg al [1];
|
|
2673 char* name;
|
|
2674 unsigned int num_children, i;
|
|
2675 Widget* children;
|
|
2676
|
|
2677 LISP_STRING_TO_EXTERNAL (XGUI_ITEM (XCAR (rest))->name,
|
|
2678 name, Qnative);
|
|
2679 /* The name may contain a `.' which confuses
|
|
2680 XtNameToWidget, so we do it ourselves. */
|
|
2681 children = XtCompositeChildren (IMAGE_INSTANCE_X_WIDGET_ID (ii),
|
|
2682 &num_children);
|
|
2683 for (i = 0; i < num_children; i++)
|
|
2684 {
|
|
2685 if (!strcmp (XtName (children [i]), name))
|
|
2686 {
|
|
2687 XtSetArg (al [0], XtNtopWidget, children [i]);
|
|
2688 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, 1);
|
|
2689 break;
|
|
2690 }
|
|
2691 }
|
|
2692 /* Pick up the new selected item. */
|
|
2693 XGUI_ITEM (old_selected)->selected =
|
|
2694 XGUI_ITEM (XCAR (rest))->selected;
|
|
2695 XGUI_ITEM (XCAR (rest))->selected =
|
|
2696 XGUI_ITEM (selected)->selected;
|
|
2697 /* We're not actually changing the items anymore. */
|
|
2698 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) = 0;
|
|
2699 IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii) = Qnil;
|
|
2700 break;
|
|
2701 }
|
|
2702 }
|
|
2703 }
|
|
2704 }
|
|
2705 /* Possibly update the face. */
|
|
2706 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (ii)
|
|
2707 ||
|
|
2708 XFRAME (IMAGE_INSTANCE_FRAME (ii))->faces_changed
|
|
2709 ||
|
|
2710 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
|
|
2711 {
|
|
2712 /* See previous comments on the brokeness of lwlib.
|
|
2713
|
|
2714 #### There's actually not much point in doing this here
|
|
2715 since, colors will have been set appropriately by
|
|
2716 x_redisplay_widget. */
|
|
2717 widget_value* wv =copy_widget_value_tree
|
|
2718 (lw_get_all_values
|
|
2719 (IMAGE_INSTANCE_X_WIDGET_LWID (ii)),
|
|
2720 NO_CHANGE);
|
438
|
2721
|
|
2722 update_tab_widget_face (wv, ii,
|
442
|
2723 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2724
|
|
2725 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (ii), wv, True);
|
|
2726 free_widget_value_tree (wv);
|
|
2727 }
|
|
2728 }
|
|
2729
|
|
2730 /* instantiate a static control possible for putting other things in */
|
|
2731 static void
|
|
2732 x_label_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2733 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2734 int dest_mask, Lisp_Object domain)
|
|
2735 {
|
440
|
2736 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2737 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
442
|
2738 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 0);
|
438
|
2739
|
428
|
2740 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2741 pointer_bg, dest_mask, domain, "button", wv);
|
|
2742 }
|
771
|
2743 #endif /* HAVE_X_WIDGETS */
|
428
|
2744
|
|
2745
|
|
2746 /************************************************************************/
|
|
2747 /* initialization */
|
|
2748 /************************************************************************/
|
|
2749
|
|
2750 void
|
|
2751 syms_of_glyphs_x (void)
|
|
2752 {
|
|
2753 #if 0
|
|
2754 DEFSUBR (Fchange_subwindow_property);
|
|
2755 #endif
|
|
2756 }
|
|
2757
|
|
2758 void
|
|
2759 console_type_create_glyphs_x (void)
|
|
2760 {
|
|
2761 /* image methods */
|
|
2762
|
|
2763 CONSOLE_HAS_METHOD (x, print_image_instance);
|
|
2764 CONSOLE_HAS_METHOD (x, finalize_image_instance);
|
|
2765 CONSOLE_HAS_METHOD (x, image_instance_equal);
|
|
2766 CONSOLE_HAS_METHOD (x, image_instance_hash);
|
|
2767 CONSOLE_HAS_METHOD (x, colorize_image_instance);
|
|
2768 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage);
|
|
2769 CONSOLE_HAS_METHOD (x, locate_pixmap_file);
|
|
2770 CONSOLE_HAS_METHOD (x, unmap_subwindow);
|
|
2771 CONSOLE_HAS_METHOD (x, map_subwindow);
|
442
|
2772 CONSOLE_HAS_METHOD (x, redisplay_widget);
|
|
2773 CONSOLE_HAS_METHOD (x, redisplay_subwindow);
|
428
|
2774 }
|
|
2775
|
|
2776 void
|
|
2777 image_instantiator_format_create_glyphs_x (void)
|
|
2778 {
|
|
2779 IIFORMAT_VALID_CONSOLE (x, nothing);
|
|
2780 IIFORMAT_VALID_CONSOLE (x, string);
|
771
|
2781 #ifdef HAVE_X_WIDGETS
|
428
|
2782 IIFORMAT_VALID_CONSOLE (x, layout);
|
442
|
2783 #endif
|
428
|
2784 IIFORMAT_VALID_CONSOLE (x, formatted_string);
|
|
2785 IIFORMAT_VALID_CONSOLE (x, inherit);
|
|
2786 #ifdef HAVE_XPM
|
|
2787 INITIALIZE_DEVICE_IIFORMAT (x, xpm);
|
|
2788 IIFORMAT_HAS_DEVMETHOD (x, xpm, instantiate);
|
|
2789 #endif
|
|
2790 #ifdef HAVE_JPEG
|
|
2791 IIFORMAT_VALID_CONSOLE (x, jpeg);
|
|
2792 #endif
|
|
2793 #ifdef HAVE_TIFF
|
|
2794 IIFORMAT_VALID_CONSOLE (x, tiff);
|
438
|
2795 #endif
|
428
|
2796 #ifdef HAVE_PNG
|
|
2797 IIFORMAT_VALID_CONSOLE (x, png);
|
438
|
2798 #endif
|
428
|
2799 #ifdef HAVE_GIF
|
|
2800 IIFORMAT_VALID_CONSOLE (x, gif);
|
438
|
2801 #endif
|
428
|
2802 INITIALIZE_DEVICE_IIFORMAT (x, xbm);
|
|
2803 IIFORMAT_HAS_DEVMETHOD (x, xbm, instantiate);
|
|
2804
|
|
2805 INITIALIZE_DEVICE_IIFORMAT (x, subwindow);
|
|
2806 IIFORMAT_HAS_DEVMETHOD (x, subwindow, instantiate);
|
771
|
2807 #ifdef HAVE_X_WIDGETS
|
442
|
2808 /* layout widget */
|
|
2809 INITIALIZE_DEVICE_IIFORMAT (x, native_layout);
|
|
2810 IIFORMAT_HAS_DEVMETHOD (x, native_layout, instantiate);
|
428
|
2811 /* button widget */
|
|
2812 INITIALIZE_DEVICE_IIFORMAT (x, button);
|
|
2813 IIFORMAT_HAS_DEVMETHOD (x, button, property);
|
|
2814 IIFORMAT_HAS_DEVMETHOD (x, button, instantiate);
|
442
|
2815 IIFORMAT_HAS_DEVMETHOD (x, button, redisplay);
|
|
2816 /* general widget methods. */
|
428
|
2817 INITIALIZE_DEVICE_IIFORMAT (x, widget);
|
|
2818 IIFORMAT_HAS_DEVMETHOD (x, widget, property);
|
|
2819 /* progress gauge */
|
|
2820 INITIALIZE_DEVICE_IIFORMAT (x, progress_gauge);
|
442
|
2821 IIFORMAT_HAS_DEVMETHOD (x, progress_gauge, redisplay);
|
428
|
2822 IIFORMAT_HAS_DEVMETHOD (x, progress_gauge, instantiate);
|
|
2823 /* text field */
|
|
2824 INITIALIZE_DEVICE_IIFORMAT (x, edit_field);
|
|
2825 IIFORMAT_HAS_DEVMETHOD (x, edit_field, instantiate);
|
|
2826 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
|
2827 /* combo box */
|
|
2828 INITIALIZE_DEVICE_IIFORMAT (x, combo_box);
|
|
2829 IIFORMAT_HAS_DEVMETHOD (x, combo_box, instantiate);
|
442
|
2830 IIFORMAT_HAS_SHARED_DEVMETHOD (x, combo_box, redisplay, tab_control);
|
428
|
2831 #endif
|
|
2832 /* tab control widget */
|
|
2833 INITIALIZE_DEVICE_IIFORMAT (x, tab_control);
|
|
2834 IIFORMAT_HAS_DEVMETHOD (x, tab_control, instantiate);
|
442
|
2835 IIFORMAT_HAS_DEVMETHOD (x, tab_control, redisplay);
|
428
|
2836 /* label */
|
|
2837 INITIALIZE_DEVICE_IIFORMAT (x, label);
|
|
2838 IIFORMAT_HAS_DEVMETHOD (x, label, instantiate);
|
|
2839 #endif
|
|
2840 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
2841 IIFORMAT_VALID_CONSOLE (x, cursor_font);
|
|
2842
|
|
2843 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
2844 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
2845 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
2846
|
|
2847 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
2848 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
2849 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
2850
|
|
2851 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
2852
|
|
2853 IIFORMAT_HAS_METHOD (font, validate);
|
|
2854 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
2855 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
2856 IIFORMAT_VALID_CONSOLE (x, font);
|
|
2857
|
|
2858 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
2859 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
2860 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
2861
|
|
2862 #ifdef HAVE_XFACE
|
|
2863 INITIALIZE_DEVICE_IIFORMAT (x, xface);
|
|
2864 IIFORMAT_HAS_DEVMETHOD (x, xface, instantiate);
|
|
2865 #endif
|
|
2866
|
|
2867 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect,
|
|
2868 "autodetect");
|
|
2869
|
|
2870 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
2871 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
2872 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
446
|
2873 /* #### autodetect is flawed IMO:
|
|
2874 1. It makes the assumption that you can detect whether the user
|
|
2875 wanted a cursor or a string based on the data, since the data is a
|
|
2876 string you have to prioritise cursors. Instead we will force users
|
|
2877 to pick the appropriate image type, this is what we do under
|
|
2878 MS-Windows anyway.
|
|
2879 2. It doesn't fit with the new domain model - you cannot tell which
|
|
2880 domain it needs to be instantiated in until you've actually
|
|
2881 instantiated it, which mucks up caching.
|
|
2882 3. It only copes with cursors and strings which seems bogus. */
|
|
2883 IIFORMAT_HAS_SHARED_METHOD (autodetect, governing_domain, subwindow);
|
428
|
2884 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
2885 IIFORMAT_VALID_CONSOLE (x, autodetect);
|
|
2886
|
|
2887 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
|
2888 }
|
|
2889
|
|
2890 void
|
|
2891 vars_of_glyphs_x (void)
|
|
2892 {
|
|
2893 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path /*
|
|
2894 A list of the directories in which X bitmap files may be found.
|
|
2895 If nil, this is initialized from the "*bitmapFilePath" resource.
|
|
2896 This is used by the `make-image-instance' function (however, note that if
|
|
2897 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
2898 */ );
|
|
2899 Vx_bitmap_file_path = Qnil;
|
|
2900 }
|
|
2901
|
|
2902 void
|
|
2903 complex_vars_of_glyphs_x (void)
|
|
2904 {
|
|
2905 #define BUILD_GLYPH_INST(variable, name) \
|
|
2906 Fadd_spec_to_specifier \
|
|
2907 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
2908 vector3 (Qxbm, Q_data, \
|
|
2909 list3 (make_int (name##_width), \
|
|
2910 make_int (name##_height), \
|
444
|
2911 make_ext_string ((Extbyte *) name##_bits, \
|
428
|
2912 sizeof (name##_bits), \
|
440
|
2913 Qbinary))), \
|
428
|
2914 Qglobal, Qx, Qnil)
|
|
2915
|
|
2916 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
2917 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
2918 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
|
2919 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
|
2920
|
|
2921 #undef BUILD_GLYPH_INST
|
|
2922 }
|