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;
|
853
|
1167 free_cons (cons);
|
428
|
1168 cons = results;
|
|
1169 results = XCDR (results);
|
853
|
1170 free_cons (cons);
|
428
|
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;
|
853
|
1562 UChar_Binary *p, *bits, *bp;
|
|
1563 const CIntbyte * volatile emsg = 0;
|
|
1564 const UChar_Binary * volatile dstring;
|
428
|
1565
|
|
1566 assert (!NILP (data));
|
|
1567
|
853
|
1568 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
1569 C_STRING_ALLOCA, dstring,
|
|
1570 Qbinary);
|
|
1571
|
|
1572 if ((p = (UChar_Binary *) strchr ((char *) dstring, ':')))
|
428
|
1573 {
|
|
1574 dstring = p + 1;
|
|
1575 }
|
|
1576
|
|
1577 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
1578 if (!(stattis = setjmp (comp_env)))
|
|
1579 {
|
853
|
1580 UnCompAll ((char *) dstring);
|
428
|
1581 UnGenFace ();
|
|
1582 }
|
|
1583
|
|
1584 switch (stattis)
|
|
1585 {
|
|
1586 case -2:
|
|
1587 emsg = "uncompface: internal error";
|
|
1588 break;
|
|
1589 case -1:
|
|
1590 emsg = "uncompface: insufficient or invalid data";
|
|
1591 break;
|
|
1592 case 1:
|
|
1593 emsg = "uncompface: excess data ignored";
|
|
1594 break;
|
|
1595 }
|
|
1596
|
|
1597 if (emsg)
|
853
|
1598 signal_image_error_2 (emsg, data, Qimage);
|
|
1599
|
|
1600 bp = bits = (UChar_Binary *) ALLOCA (PIXELS / 8);
|
428
|
1601
|
|
1602 /* the compface library exports char F[], which uses a single byte per
|
|
1603 pixel to represent a 48x48 bitmap. Yuck. */
|
853
|
1604 for (i = 0, p = (UChar_Binary *) F; i < (PIXELS / 8); ++i)
|
428
|
1605 {
|
|
1606 int n, b;
|
|
1607 /* reverse the bit order of each byte... */
|
|
1608 for (b = n = 0; b < 8; ++b)
|
|
1609 {
|
|
1610 n |= ((*p++) << b);
|
|
1611 }
|
853
|
1612 *bp++ = (UChar_Binary) n;
|
428
|
1613 }
|
|
1614
|
|
1615 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
853
|
1616 pointer_bg, dest_mask, 48, 48, (Char_Binary *) bits);
|
428
|
1617 }
|
|
1618
|
|
1619 #endif /* HAVE_XFACE */
|
|
1620
|
|
1621
|
|
1622 /**********************************************************************
|
|
1623 * Autodetect *
|
|
1624 **********************************************************************/
|
|
1625
|
|
1626 static void
|
|
1627 autodetect_validate (Lisp_Object instantiator)
|
|
1628 {
|
|
1629 data_must_be_present (instantiator);
|
|
1630 }
|
|
1631
|
|
1632 static Lisp_Object
|
|
1633 autodetect_normalize (Lisp_Object instantiator,
|
442
|
1634 Lisp_Object console_type,
|
|
1635 Lisp_Object dest_mask)
|
428
|
1636 {
|
|
1637 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
1638 Lisp_Object filename = Qnil;
|
|
1639 Lisp_Object data = Qnil;
|
|
1640 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1641 Lisp_Object alist = Qnil;
|
|
1642
|
|
1643 GCPRO3 (filename, data, alist);
|
|
1644
|
|
1645 if (NILP (file)) /* no conversion necessary */
|
|
1646 RETURN_UNGCPRO (instantiator);
|
|
1647
|
|
1648 alist = tagged_vector_to_alist (instantiator);
|
|
1649
|
|
1650 filename = locate_pixmap_file (file);
|
|
1651 if (!NILP (filename))
|
|
1652 {
|
|
1653 int xhot, yhot;
|
|
1654 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
1655 called by pixmap_to_lisp_data, don't return an error value
|
|
1656 if the given file is not a valid XPM file. Instead, they
|
|
1657 just seg fault. It is definitely caused by passing a
|
|
1658 bitmap. To try and avoid this we check for bitmaps first. */
|
|
1659
|
|
1660 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
1661
|
|
1662 if (!EQ (data, Qt))
|
|
1663 {
|
|
1664 alist = remassq_no_quit (Q_data, alist);
|
|
1665 alist = Fcons (Fcons (Q_file, filename),
|
|
1666 Fcons (Fcons (Q_data, data), alist));
|
|
1667 if (xhot != -1)
|
|
1668 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
1669 alist);
|
|
1670 if (yhot != -1)
|
|
1671 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
1672 alist);
|
|
1673
|
|
1674 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type);
|
|
1675
|
|
1676 {
|
|
1677 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
1678 free_alist (alist);
|
|
1679 RETURN_UNGCPRO (result);
|
|
1680 }
|
|
1681 }
|
|
1682
|
|
1683 #ifdef HAVE_XPM
|
|
1684 data = pixmap_to_lisp_data (filename, 1);
|
|
1685
|
|
1686 if (!EQ (data, Qt))
|
|
1687 {
|
|
1688 alist = remassq_no_quit (Q_data, alist);
|
|
1689 alist = Fcons (Fcons (Q_file, filename),
|
|
1690 Fcons (Fcons (Q_data, data), alist));
|
|
1691 alist = Fcons (Fcons (Q_color_symbols,
|
|
1692 evaluate_xpm_color_symbols ()),
|
|
1693 alist);
|
|
1694 {
|
|
1695 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1696 free_alist (alist);
|
|
1697 RETURN_UNGCPRO (result);
|
|
1698 }
|
|
1699 }
|
|
1700 #endif
|
|
1701 }
|
|
1702
|
|
1703 /* If we couldn't convert it, just put it back as it is.
|
|
1704 We might try to further frob it later as a cursor-font
|
|
1705 specification. (We can't do that now because we don't know
|
|
1706 what dest-types it's going to be instantiated into.) */
|
|
1707 {
|
|
1708 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
|
1709 free_alist (alist);
|
|
1710 RETURN_UNGCPRO (result);
|
|
1711 }
|
|
1712 }
|
|
1713
|
|
1714 static int
|
|
1715 autodetect_possible_dest_types (void)
|
|
1716 {
|
|
1717 return
|
|
1718 IMAGE_MONO_PIXMAP_MASK |
|
|
1719 IMAGE_COLOR_PIXMAP_MASK |
|
|
1720 IMAGE_POINTER_MASK |
|
|
1721 IMAGE_TEXT_MASK;
|
|
1722 }
|
|
1723
|
|
1724 static void
|
|
1725 autodetect_instantiate (Lisp_Object image_instance,
|
438
|
1726 Lisp_Object instantiator,
|
|
1727 Lisp_Object pointer_fg,
|
|
1728 Lisp_Object pointer_bg,
|
|
1729 int dest_mask, Lisp_Object domain)
|
428
|
1730 {
|
|
1731 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1732 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1733 Lisp_Object alist = Qnil;
|
|
1734 Lisp_Object result = Qnil;
|
|
1735 int is_cursor_font = 0;
|
|
1736
|
|
1737 GCPRO3 (data, alist, result);
|
|
1738
|
|
1739 alist = tagged_vector_to_alist (instantiator);
|
|
1740 if (dest_mask & IMAGE_POINTER_MASK)
|
|
1741 {
|
442
|
1742 const char *name_ext;
|
|
1743 LISP_STRING_TO_EXTERNAL (data, name_ext, Qfile_name);
|
428
|
1744 if (XmuCursorNameToIndex (name_ext) != -1)
|
|
1745 {
|
|
1746 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
1747 is_cursor_font = 1;
|
|
1748 }
|
|
1749 }
|
|
1750
|
|
1751 if (!is_cursor_font)
|
|
1752 result = alist_to_tagged_vector (Qstring, alist);
|
|
1753 free_alist (alist);
|
|
1754
|
|
1755 if (is_cursor_font)
|
|
1756 cursor_font_instantiate (image_instance, result, pointer_fg,
|
|
1757 pointer_bg, dest_mask, domain);
|
|
1758 else
|
|
1759 string_instantiate (image_instance, result, pointer_fg,
|
|
1760 pointer_bg, dest_mask, domain);
|
|
1761
|
|
1762 UNGCPRO;
|
|
1763 }
|
|
1764
|
|
1765
|
|
1766 /**********************************************************************
|
|
1767 * Font *
|
|
1768 **********************************************************************/
|
|
1769
|
|
1770 static void
|
|
1771 font_validate (Lisp_Object instantiator)
|
|
1772 {
|
|
1773 data_must_be_present (instantiator);
|
|
1774 }
|
|
1775
|
|
1776 /* XmuCvtStringToCursor is bogus in the following ways:
|
|
1777
|
|
1778 - When it can't convert the given string to a real cursor, it will
|
|
1779 sometimes return a "success" value, after triggering a BadPixmap
|
|
1780 error. It then gives you a cursor that will itself generate BadCursor
|
|
1781 errors. So we install this error handler to catch/notice the X error
|
|
1782 and take that as meaning "couldn't convert."
|
|
1783
|
|
1784 - When you tell it to find a cursor file that doesn't exist, it prints
|
|
1785 an error message on stderr. You can't make it not do that.
|
|
1786
|
|
1787 - Also, using Xmu means we can't properly hack Lisp_Image_Instance
|
|
1788 objects, or XPM files, or $XBMLANGPATH.
|
|
1789 */
|
|
1790
|
|
1791 /* Duplicate the behavior of XmuCvtStringToCursor() to bypass its bogusness. */
|
|
1792
|
|
1793 static int XLoadFont_got_error;
|
|
1794
|
|
1795 static int
|
|
1796 XLoadFont_error_handler (Display *dpy, XErrorEvent *xerror)
|
|
1797 {
|
|
1798 XLoadFont_got_error = 1;
|
|
1799 return 0;
|
|
1800 }
|
|
1801
|
|
1802 static Font
|
771
|
1803 safe_XLoadFont (Display *dpy, Intbyte *name)
|
428
|
1804 {
|
|
1805 Font font;
|
|
1806 int (*old_handler) (Display *, XErrorEvent *);
|
771
|
1807 Extbyte *nameext;
|
|
1808
|
428
|
1809 XLoadFont_got_error = 0;
|
|
1810 XSync (dpy, 0);
|
|
1811 old_handler = XSetErrorHandler (XLoadFont_error_handler);
|
771
|
1812 C_STRING_TO_EXTERNAL (name, nameext, Qfile_name);
|
|
1813 font = XLoadFont (dpy, nameext);
|
428
|
1814 XSync (dpy, 0);
|
|
1815 XSetErrorHandler (old_handler);
|
|
1816 if (XLoadFont_got_error) return 0;
|
|
1817 return font;
|
|
1818 }
|
|
1819
|
|
1820 static int
|
|
1821 font_possible_dest_types (void)
|
|
1822 {
|
|
1823 return IMAGE_POINTER_MASK;
|
|
1824 }
|
|
1825
|
|
1826 static void
|
|
1827 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1828 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1829 int dest_mask, Lisp_Object domain)
|
|
1830 {
|
|
1831 /* This function can GC */
|
|
1832 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
440
|
1833 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
1834 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1835 Display *dpy;
|
|
1836 XColor fg, bg;
|
|
1837 Font source, mask;
|
771
|
1838 Intbyte source_name[PATH_MAX], mask_name[PATH_MAX], dummy;
|
428
|
1839 int source_char, mask_char;
|
|
1840 int count;
|
|
1841 Lisp_Object foreground, background;
|
|
1842
|
|
1843 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
1844 gui_error ("Not an X device", device);
|
428
|
1845
|
|
1846 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1847
|
|
1848 if (!STRINGP (data) ||
|
|
1849 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
563
|
1850 invalid_argument ("Invalid font-glyph instantiator",
|
428
|
1851 instantiator);
|
|
1852
|
|
1853 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1854 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1855
|
|
1856 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1857 if (NILP (foreground))
|
|
1858 foreground = pointer_fg;
|
|
1859 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1860 if (NILP (background))
|
|
1861 background = pointer_bg;
|
|
1862
|
|
1863 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
1864
|
|
1865 count = sscanf ((char *) XSTRING_DATA (data),
|
|
1866 "FONT %s %d %s %d %c",
|
|
1867 source_name, &source_char,
|
|
1868 mask_name, &mask_char, &dummy);
|
|
1869 /* Allow "%s %d %d" as well... */
|
771
|
1870 if (count == 3 && (1 == sscanf ((char *) mask_name, "%d %c", &mask_char,
|
|
1871 &dummy)))
|
428
|
1872 count = 4, mask_name[0] = 0;
|
|
1873
|
|
1874 if (count != 2 && count != 4)
|
563
|
1875 syntax_error ("invalid cursor specification", data);
|
428
|
1876 source = safe_XLoadFont (dpy, source_name);
|
|
1877 if (! source)
|
563
|
1878 signal_error_2 (Qgui_error,
|
771
|
1879 "couldn't load font", build_intstring (source_name), data);
|
428
|
1880 if (count == 2)
|
|
1881 mask = 0;
|
|
1882 else if (!mask_name[0])
|
|
1883 mask = source;
|
|
1884 else
|
|
1885 {
|
|
1886 mask = safe_XLoadFont (dpy, mask_name);
|
|
1887 if (!mask)
|
563
|
1888 signal_continuable_error_2 (Qgui_error,
|
|
1889 "couldn't load font",
|
771
|
1890 build_intstring (mask_name), data);
|
428
|
1891 }
|
|
1892 if (!mask)
|
|
1893 mask_char = 0;
|
|
1894
|
|
1895 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
1896
|
|
1897 x_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1898 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1899 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
1900 &fg, &bg);
|
|
1901 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
1902 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
1903 XUnloadFont (dpy, source);
|
|
1904 if (mask && mask != source) XUnloadFont (dpy, mask);
|
|
1905 }
|
|
1906
|
|
1907
|
|
1908 /**********************************************************************
|
|
1909 * Cursor-Font *
|
|
1910 **********************************************************************/
|
|
1911
|
|
1912 static void
|
|
1913 cursor_font_validate (Lisp_Object instantiator)
|
|
1914 {
|
|
1915 data_must_be_present (instantiator);
|
|
1916 }
|
|
1917
|
|
1918 static int
|
|
1919 cursor_font_possible_dest_types (void)
|
|
1920 {
|
|
1921 return IMAGE_POINTER_MASK;
|
|
1922 }
|
|
1923
|
|
1924 static void
|
|
1925 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1926 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1927 int dest_mask, Lisp_Object domain)
|
|
1928 {
|
|
1929 /* This function can GC */
|
|
1930 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
440
|
1931 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
1932 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1933 Display *dpy;
|
|
1934 int i;
|
771
|
1935 const Extbyte *name_ext;
|
428
|
1936 Lisp_Object foreground, background;
|
|
1937
|
|
1938 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
1939 gui_error ("Not an X device", device);
|
428
|
1940
|
|
1941 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1942
|
|
1943 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1944 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1945
|
442
|
1946 LISP_STRING_TO_EXTERNAL (data, name_ext, Qfile_name);
|
428
|
1947 if ((i = XmuCursorNameToIndex (name_ext)) == -1)
|
563
|
1948 invalid_argument ("Unrecognized cursor-font name", data);
|
428
|
1949
|
|
1950 x_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1951 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i);
|
|
1952 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1953 if (NILP (foreground))
|
|
1954 foreground = pointer_fg;
|
|
1955 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1956 if (NILP (background))
|
|
1957 background = pointer_bg;
|
|
1958 maybe_recolor_cursor (image_instance, foreground, background);
|
|
1959 }
|
|
1960
|
|
1961 static int
|
|
1962 x_colorize_image_instance (Lisp_Object image_instance,
|
|
1963 Lisp_Object foreground, Lisp_Object background)
|
|
1964 {
|
440
|
1965 Lisp_Image_Instance *p;
|
428
|
1966
|
|
1967 p = XIMAGE_INSTANCE (image_instance);
|
|
1968
|
|
1969 switch (IMAGE_INSTANCE_TYPE (p))
|
|
1970 {
|
|
1971 case IMAGE_MONO_PIXMAP:
|
|
1972 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
1973 /* Make sure there aren't two pointers to the same mask, causing
|
|
1974 it to get freed twice. */
|
|
1975 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
|
|
1976 break;
|
|
1977
|
|
1978 default:
|
|
1979 return 0;
|
|
1980 }
|
|
1981
|
|
1982 {
|
|
1983 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
1984 Drawable draw = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
1985 Dimension d = DEVICE_X_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
1986 Pixmap new = XCreatePixmap (dpy, draw,
|
|
1987 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
1988 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d);
|
|
1989 XColor color;
|
|
1990 XGCValues gcv;
|
|
1991 GC gc;
|
|
1992 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground));
|
|
1993 gcv.foreground = color.pixel;
|
|
1994 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background));
|
|
1995 gcv.background = color.pixel;
|
|
1996 gc = XCreateGC (dpy, new, GCBackground|GCForeground, &gcv);
|
|
1997 XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP (p), new, gc, 0, 0,
|
|
1998 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
1999 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2000 0, 0, 1);
|
|
2001 XFreeGC (dpy, gc);
|
|
2002 IMAGE_INSTANCE_X_PIXMAP (p) = new;
|
|
2003 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = d;
|
|
2004 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
2005 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
2006 return 1;
|
|
2007 }
|
|
2008 }
|
|
2009
|
|
2010
|
|
2011 /************************************************************************/
|
|
2012 /* subwindow and widget support */
|
|
2013 /************************************************************************/
|
|
2014
|
|
2015 /* unmap the image if it is a widget. This is used by redisplay via
|
|
2016 redisplay_unmap_subwindows */
|
|
2017 static void
|
440
|
2018 x_unmap_subwindow (Lisp_Image_Instance *p)
|
428
|
2019 {
|
|
2020 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
2021 {
|
438
|
2022 XUnmapWindow
|
|
2023 (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
428
|
2024 IMAGE_INSTANCE_X_CLIPWINDOW (p));
|
|
2025 }
|
|
2026 else /* must be a widget */
|
|
2027 {
|
450
|
2028 /* Since we are being unmapped we want the enclosing frame to
|
|
2029 get focus. The losing with simple scrolling but is the safest
|
|
2030 thing to do. */
|
|
2031 emacs_Xt_handle_widget_losing_focus
|
|
2032 ( XFRAME (IMAGE_INSTANCE_FRAME (p)),
|
|
2033 IMAGE_INSTANCE_X_WIDGET_ID (p));
|
428
|
2034 XtUnmapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
|
|
2035 }
|
|
2036 }
|
|
2037
|
|
2038 /* map the subwindow. This is used by redisplay via
|
|
2039 redisplay_output_subwindow */
|
|
2040 static void
|
440
|
2041 x_map_subwindow (Lisp_Image_Instance *p, int x, int y,
|
428
|
2042 struct display_glyph_area* dga)
|
|
2043 {
|
448
|
2044 assert (dga->width > 0 && dga->height > 0);
|
428
|
2045 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
2046 {
|
|
2047 Window subwindow = IMAGE_INSTANCE_X_SUBWINDOW_ID (p);
|
|
2048 XMoveResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
438
|
2049 IMAGE_INSTANCE_X_CLIPWINDOW (p),
|
428
|
2050 x, y, dga->width, dga->height);
|
|
2051 XMoveWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2052 subwindow, -dga->xoffset, -dga->yoffset);
|
442
|
2053 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
|
|
2054 XMapWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2055 IMAGE_INSTANCE_X_CLIPWINDOW (p));
|
428
|
2056 }
|
|
2057 else /* must be a widget */
|
|
2058 {
|
438
|
2059 XtConfigureWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p),
|
428
|
2060 x + IMAGE_INSTANCE_X_WIDGET_XOFFSET (p),
|
|
2061 y + IMAGE_INSTANCE_X_WIDGET_YOFFSET (p),
|
|
2062 dga->width, dga->height, 0);
|
|
2063 XtMoveWidget (IMAGE_INSTANCE_X_WIDGET_ID (p),
|
|
2064 -dga->xoffset, -dga->yoffset);
|
442
|
2065 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
|
|
2066 XtMapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
|
428
|
2067 }
|
|
2068 }
|
|
2069
|
|
2070 /* when you click on a widget you may activate another widget this
|
|
2071 needs to be checked and all appropriate widgets updated */
|
|
2072 static void
|
442
|
2073 x_redisplay_subwindow (Lisp_Image_Instance *p)
|
|
2074 {
|
|
2075 /* Update the subwindow size if necessary. */
|
|
2076 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
|
|
2077 {
|
|
2078 XResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2079 IMAGE_INSTANCE_X_SUBWINDOW_ID (p),
|
|
2080 IMAGE_INSTANCE_WIDTH (p),
|
|
2081 IMAGE_INSTANCE_HEIGHT (p));
|
|
2082 }
|
|
2083 }
|
|
2084
|
|
2085 /* Update all attributes that have changed. Lwlib actually does most
|
|
2086 of this for us. */
|
|
2087 static void
|
|
2088 x_redisplay_widget (Lisp_Image_Instance *p)
|
428
|
2089 {
|
442
|
2090 /* This function can GC if IN_REDISPLAY is false. */
|
771
|
2091 #ifdef HAVE_X_WIDGETS
|
442
|
2092 widget_value* wv = 0;
|
|
2093
|
|
2094 /* First get the items if they have changed since this is a
|
|
2095 structural change. As such it will nuke all added values so we
|
|
2096 need to update most other things after the items have changed.*/
|
|
2097 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2098 {
|
793
|
2099 Lisp_Object image_instance = wrap_image_instance (p);
|
|
2100
|
442
|
2101 wv = gui_items_to_widget_values
|
|
2102 (image_instance, IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (p),
|
|
2103 /* #### this is not right; we need to keep track of which widgets
|
|
2104 want accelerators and which don't */ 0);
|
|
2105 wv->change = STRUCTURAL_CHANGE;
|
|
2106 }
|
|
2107 else
|
428
|
2108 {
|
442
|
2109 /* Assume the lotus position, breath deeply and chant to
|
|
2110 yourself lwlibsux, lwlibsux ... lw_get_all_values returns a
|
|
2111 reference to the real values rather than a copy thus any
|
|
2112 changes we make to the values we get back will look like they
|
|
2113 have already been applied. If we rebuild the widget tree then
|
444
|
2114 we may lose properties. */
|
|
2115 wv = copy_widget_value_tree (lw_get_all_values
|
442
|
2116 (IMAGE_INSTANCE_X_WIDGET_LWID (p)),
|
|
2117 NO_CHANGE);
|
|
2118 }
|
|
2119
|
|
2120 /* Possibly update the colors and font */
|
|
2121 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p)
|
|
2122 ||
|
454
|
2123 /* #### This is not sufficient because it will not cope with widgets
|
|
2124 that are not currently visible. Once redisplay has done the
|
|
2125 visible ones it will clear this flag so that when new ones
|
|
2126 become visible they will not be updated. */
|
442
|
2127 XFRAME (IMAGE_INSTANCE_FRAME (p))->faces_changed
|
|
2128 ||
|
454
|
2129 XFRAME (IMAGE_INSTANCE_FRAME (p))->frame_changed
|
|
2130 ||
|
442
|
2131 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2132 {
|
|
2133 update_widget_face (wv, p, IMAGE_INSTANCE_FRAME (p));
|
|
2134 }
|
|
2135
|
|
2136 /* Possibly update the text. */
|
|
2137 if (IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2138 {
|
771
|
2139 Extbyte* str;
|
442
|
2140 Lisp_Object val = IMAGE_INSTANCE_WIDGET_TEXT (p);
|
|
2141 LISP_STRING_TO_EXTERNAL (val, str, Qnative);
|
|
2142 wv->value = str;
|
|
2143 }
|
|
2144
|
|
2145 /* Possibly update the size. */
|
|
2146 if (IMAGE_INSTANCE_SIZE_CHANGED (p)
|
|
2147 ||
|
|
2148 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p)
|
|
2149 ||
|
|
2150 IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2151 {
|
|
2152 assert (IMAGE_INSTANCE_X_WIDGET_ID (p) &&
|
|
2153 IMAGE_INSTANCE_X_CLIPWIDGET (p)) ;
|
|
2154
|
|
2155 if (IMAGE_INSTANCE_X_WIDGET_ID (p)->core.being_destroyed
|
|
2156 || !XtIsManaged(IMAGE_INSTANCE_X_WIDGET_ID (p)))
|
428
|
2157 {
|
793
|
2158 Lisp_Object sw = wrap_image_instance (p);
|
|
2159
|
563
|
2160 signal_error (Qinternal_error,
|
|
2161 "XEmacs bug: subwindow is deleted", sw);
|
434
|
2162 }
|
442
|
2163
|
|
2164 lw_add_widget_value_arg (wv, XtNwidth,
|
|
2165 (Dimension)IMAGE_INSTANCE_WIDTH (p));
|
|
2166 lw_add_widget_value_arg (wv, XtNheight,
|
|
2167 (Dimension)IMAGE_INSTANCE_HEIGHT (p));
|
428
|
2168 }
|
442
|
2169
|
448
|
2170 /* Adjust offsets within the frame. */
|
450
|
2171 if (XFRAME (IMAGE_INSTANCE_FRAME (p))->size_changed)
|
448
|
2172 {
|
|
2173 Arg al[2];
|
|
2174 XtSetArg (al [0], XtNx, &IMAGE_INSTANCE_X_WIDGET_XOFFSET (p));
|
|
2175 XtSetArg (al [1], XtNy, &IMAGE_INSTANCE_X_WIDGET_YOFFSET (p));
|
|
2176 XtGetValues (FRAME_X_TEXT_WIDGET
|
|
2177 (XFRAME (IMAGE_INSTANCE_FRAME (p))), al, 2);
|
|
2178 }
|
|
2179
|
442
|
2180 /* now modify the widget */
|
|
2181 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (p),
|
|
2182 wv, True);
|
|
2183 free_widget_value_tree (wv);
|
428
|
2184 #endif
|
|
2185 }
|
|
2186
|
|
2187 /* instantiate and x type subwindow */
|
|
2188 static void
|
|
2189 x_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2190 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2191 int dest_mask, Lisp_Object domain)
|
|
2192 {
|
|
2193 /* This function can GC */
|
440
|
2194 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2195 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
442
|
2196 Lisp_Object frame = DOMAIN_FRAME (domain);
|
428
|
2197 struct frame* f = XFRAME (frame);
|
|
2198 Display *dpy;
|
|
2199 Screen *xs;
|
|
2200 Window pw, win;
|
|
2201 XSetWindowAttributes xswa;
|
|
2202 Mask valueMask = 0;
|
647
|
2203 int w = IMAGE_INSTANCE_WIDTH (ii), h = IMAGE_INSTANCE_HEIGHT (ii);
|
428
|
2204
|
|
2205 if (!DEVICE_X_P (XDEVICE (device)))
|
563
|
2206 gui_error ("Not an X device", device);
|
428
|
2207
|
|
2208 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
2209 xs = DefaultScreenOfDisplay (dpy);
|
|
2210
|
|
2211 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
|
|
2212
|
|
2213 pw = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2214
|
|
2215 ii->data = xnew_and_zero (struct x_subwindow_data);
|
|
2216
|
|
2217 IMAGE_INSTANCE_X_SUBWINDOW_PARENT (ii) = pw;
|
|
2218 IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (ii) = DisplayOfScreen (xs);
|
|
2219
|
|
2220 xswa.backing_store = Always;
|
|
2221 valueMask |= CWBackingStore;
|
|
2222 xswa.colormap = DefaultColormapOfScreen (xs);
|
|
2223 valueMask |= CWColormap;
|
438
|
2224
|
428
|
2225 /* Create a window for clipping */
|
438
|
2226 IMAGE_INSTANCE_X_CLIPWINDOW (ii) =
|
428
|
2227 XCreateWindow (dpy, pw, 0, 0, w, h, 0, CopyFromParent,
|
|
2228 InputOutput, CopyFromParent, valueMask,
|
|
2229 &xswa);
|
|
2230
|
|
2231 /* Now put the subwindow inside the clip window. */
|
|
2232 win = XCreateWindow (dpy, IMAGE_INSTANCE_X_CLIPWINDOW (ii),
|
|
2233 0, 0, w, h, 0, CopyFromParent,
|
|
2234 InputOutput, CopyFromParent, valueMask,
|
|
2235 &xswa);
|
438
|
2236
|
428
|
2237 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)win;
|
|
2238 }
|
|
2239
|
|
2240 #if 0
|
|
2241 /* #### Should this function exist? If there's any doubt I'm not implementing it --andyp */
|
|
2242 DEFUN ("change-subwindow-property", Fchange_subwindow_property, 3, 3, 0, /*
|
|
2243 For the given SUBWINDOW, set PROPERTY to DATA, which is a string.
|
|
2244 Subwindows are not currently implemented.
|
|
2245 */
|
|
2246 (subwindow, property, data))
|
|
2247 {
|
|
2248 Atom property_atom;
|
440
|
2249 Lisp_Subwindow *sw;
|
428
|
2250 Display *dpy;
|
771
|
2251 Extbyte *propext, *dataext;
|
|
2252 Bytecount datalen;
|
428
|
2253
|
|
2254 CHECK_SUBWINDOW (subwindow);
|
|
2255 CHECK_STRING (property);
|
|
2256 CHECK_STRING (data);
|
|
2257
|
|
2258 sw = XSUBWINDOW (subwindow);
|
|
2259 dpy = DisplayOfScreen (LISP_DEVICE_TO_X_SCREEN
|
|
2260 (FRAME_DEVICE (XFRAME (sw->frame))));
|
|
2261
|
771
|
2262 LISP_TO_EXTERNAL (property, propext, Qctext);
|
|
2263 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
2264 ALLOCA, (dataext, datalen), Qctext);
|
|
2265 property_atom = XInternAtom (dpy, propext, False);
|
428
|
2266 XChangeProperty (dpy, sw->subwindow, property_atom, XA_STRING, 8,
|
771
|
2267 PropModeReplace, dataext, datalen);
|
428
|
2268 return property;
|
|
2269 }
|
|
2270 #endif
|
|
2271
|
|
2272
|
771
|
2273 #ifdef HAVE_X_WIDGETS
|
428
|
2274
|
|
2275 /************************************************************************/
|
|
2276 /* widgets */
|
|
2277 /************************************************************************/
|
|
2278
|
|
2279 static void
|
440
|
2280 update_widget_face (widget_value* wv, Lisp_Image_Instance *ii,
|
434
|
2281 Lisp_Object domain)
|
428
|
2282 {
|
|
2283 #ifdef LWLIB_WIDGETS_MOTIF
|
|
2284 XmFontList fontList;
|
|
2285 #endif
|
438
|
2286 /* Update the foreground. */
|
|
2287 Lisp_Object pixel = FACE_FOREGROUND
|
428
|
2288 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
434
|
2289 domain);
|
438
|
2290 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel)), bcolor;
|
434
|
2291 lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
|
438
|
2292
|
|
2293 /* Update the background. */
|
|
2294 pixel = FACE_BACKGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
|
2295 domain);
|
|
2296 bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2297 lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
|
|
2298
|
428
|
2299 #ifdef LWLIB_WIDGETS_MOTIF
|
|
2300 fontList = XmFontListCreate
|
438
|
2301 (FONT_INSTANCE_X_FONT
|
|
2302 (XFONT_INSTANCE (query_string_font
|
|
2303 (IMAGE_INSTANCE_WIDGET_TEXT (ii),
|
434
|
2304 IMAGE_INSTANCE_WIDGET_FACE (ii),
|
438
|
2305 domain))), XmSTRING_DEFAULT_CHARSET);
|
434
|
2306 lw_add_widget_value_arg (wv, XmNfontList, (XtArgVal)fontList);
|
428
|
2307 #endif
|
438
|
2308 lw_add_widget_value_arg
|
|
2309 (wv, XtNfont, (XtArgVal)FONT_INSTANCE_X_FONT
|
|
2310 (XFONT_INSTANCE (query_string_font
|
|
2311 (IMAGE_INSTANCE_WIDGET_TEXT (ii),
|
434
|
2312 IMAGE_INSTANCE_WIDGET_FACE (ii),
|
438
|
2313 domain))));
|
442
|
2314 wv->change = VISIBLE_CHANGE;
|
|
2315 /* #### Megahack - but its just getting too complicated to do this
|
|
2316 in the right place. */
|
|
2317 if (EQ (IMAGE_INSTANCE_WIDGET_TYPE (ii), Qtab_control))
|
|
2318 update_tab_widget_face (wv, ii, domain);
|
434
|
2319 }
|
|
2320
|
|
2321 static void
|
440
|
2322 update_tab_widget_face (widget_value* wv, Lisp_Image_Instance *ii,
|
434
|
2323 Lisp_Object domain)
|
|
2324 {
|
|
2325 if (wv->contents)
|
|
2326 {
|
|
2327 widget_value* val = wv->contents, *cur;
|
438
|
2328
|
434
|
2329 /* Give each child label the correct foreground color. */
|
438
|
2330 Lisp_Object pixel = FACE_FOREGROUND
|
434
|
2331 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
|
2332 domain);
|
|
2333 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2334 lw_add_widget_value_arg (val, XtNtabForeground, fcolor.pixel);
|
442
|
2335 wv->change = VISIBLE_CHANGE;
|
|
2336 val->change = VISIBLE_CHANGE;
|
434
|
2337
|
|
2338 for (cur = val->next; cur; cur = cur->next)
|
|
2339 {
|
442
|
2340 cur->change = VISIBLE_CHANGE;
|
434
|
2341 if (cur->value)
|
|
2342 {
|
|
2343 lw_copy_widget_value_args (val, cur);
|
|
2344 }
|
|
2345 }
|
|
2346 }
|
428
|
2347 }
|
|
2348
|
|
2349 static void
|
|
2350 x_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2351 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2352 int dest_mask, Lisp_Object domain,
|
442
|
2353 const char* type, widget_value* wv)
|
428
|
2354 {
|
440
|
2355 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2356 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), pixel;
|
|
2357 struct device* d = XDEVICE (device);
|
442
|
2358 Lisp_Object frame = DOMAIN_FRAME (domain);
|
428
|
2359 struct frame* f = XFRAME (frame);
|
|
2360 char* nm=0;
|
|
2361 Widget wid;
|
|
2362 Arg al [32];
|
|
2363 int ac = 0;
|
|
2364 int id = new_lwlib_id ();
|
|
2365 widget_value* clip_wv;
|
|
2366 XColor fcolor, bcolor;
|
|
2367
|
|
2368 if (!DEVICE_X_P (d))
|
563
|
2369 gui_error ("Not an X device", device);
|
428
|
2370
|
|
2371 /* have to set the type this late in case there is no device
|
|
2372 instantiation for a widget. But we can go ahead and do it without
|
|
2373 checking because there is always a generic instantiator. */
|
|
2374 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
|
|
2375
|
|
2376 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
|
442
|
2377 LISP_STRING_TO_EXTERNAL (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm, Qnative);
|
428
|
2378
|
|
2379 ii->data = xnew_and_zero (struct x_subwindow_data);
|
|
2380
|
|
2381 /* Create a clip window to contain the subwidget. Incredibly the
|
|
2382 XEmacs manager seems to be the most appropriate widget for
|
|
2383 this. Nothing else is simple enough and yet does what is
|
|
2384 required. */
|
|
2385 clip_wv = xmalloc_widget_value ();
|
|
2386
|
434
|
2387 lw_add_widget_value_arg (clip_wv, XtNresize, False);
|
438
|
2388 lw_add_widget_value_arg (clip_wv, XtNwidth,
|
442
|
2389 (Dimension)IMAGE_INSTANCE_WIDTH (ii));
|
438
|
2390 lw_add_widget_value_arg (clip_wv, XtNheight,
|
442
|
2391 (Dimension)IMAGE_INSTANCE_HEIGHT (ii));
|
428
|
2392 clip_wv->enabled = True;
|
434
|
2393
|
428
|
2394 clip_wv->name = xstrdup ("clip-window");
|
|
2395 clip_wv->value = xstrdup ("clip-window");
|
|
2396
|
|
2397 IMAGE_INSTANCE_X_CLIPWIDGET (ii)
|
|
2398 = lw_create_widget ("clip-window", "clip-window", new_lwlib_id (),
|
|
2399 clip_wv, FRAME_X_CONTAINER_WIDGET (f),
|
|
2400 False, 0, 0, 0);
|
|
2401
|
|
2402 free_widget_value_tree (clip_wv);
|
|
2403
|
|
2404 /* copy any args we were given */
|
|
2405 ac = 0;
|
434
|
2406 lw_add_value_args_to_args (wv, al, &ac);
|
428
|
2407
|
|
2408 /* Fixup the colors. We have to do this *before* the widget gets
|
|
2409 created so that Motif will fix up the shadow colors
|
|
2410 correctly. Once the widget is created Motif won't do this
|
|
2411 anymore...*/
|
438
|
2412 pixel = FACE_FOREGROUND
|
428
|
2413 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
442
|
2414 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2415 fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2416
|
|
2417 pixel = FACE_BACKGROUND
|
|
2418 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
442
|
2419 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2420 bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2421
|
434
|
2422 lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
|
|
2423 lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
|
428
|
2424 /* we cannot allow widgets to resize themselves */
|
434
|
2425 lw_add_widget_value_arg (wv, XtNresize, False);
|
438
|
2426 lw_add_widget_value_arg (wv, XtNwidth,
|
442
|
2427 (Dimension)IMAGE_INSTANCE_WIDTH (ii));
|
438
|
2428 lw_add_widget_value_arg (wv, XtNheight,
|
442
|
2429 (Dimension)IMAGE_INSTANCE_HEIGHT (ii));
|
434
|
2430 /* update the font. */
|
|
2431 update_widget_face (wv, ii, domain);
|
428
|
2432
|
|
2433 wid = lw_create_widget (type, wv->name, id, wv, IMAGE_INSTANCE_X_CLIPWIDGET (ii),
|
|
2434 False, 0, popup_selection_callback, 0);
|
|
2435
|
|
2436 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)wid;
|
|
2437 IMAGE_INSTANCE_X_WIDGET_LWID (ii) = id;
|
|
2438 /* because the EmacsManager is the widgets parent we have to
|
|
2439 offset the redisplay of the widget by the amount the text
|
|
2440 widget is inside the manager. */
|
|
2441 ac = 0;
|
|
2442 XtSetArg (al [ac], XtNx, &IMAGE_INSTANCE_X_WIDGET_XOFFSET (ii)); ac++;
|
|
2443 XtSetArg (al [ac], XtNy, &IMAGE_INSTANCE_X_WIDGET_YOFFSET (ii)); ac++;
|
|
2444 XtGetValues (FRAME_X_TEXT_WIDGET (f), al, ac);
|
|
2445
|
436
|
2446 XtSetMappedWhenManaged (wid, TRUE);
|
428
|
2447
|
|
2448 free_widget_value_tree (wv);
|
442
|
2449 /* A kludgy but simple way to make sure the callback for a widget
|
|
2450 doesn't get deleted. */
|
|
2451 gcpro_popup_callbacks (id);
|
428
|
2452 }
|
|
2453
|
|
2454 /* get properties of a control */
|
|
2455 static Lisp_Object
|
|
2456 x_widget_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2457 {
|
440
|
2458 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2459 /* get the text from a control */
|
|
2460 if (EQ (prop, Q_text))
|
|
2461 {
|
|
2462 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
|
440
|
2463 return build_ext_string (wv->value, Qnative);
|
428
|
2464 }
|
|
2465 return Qunbound;
|
|
2466 }
|
|
2467
|
442
|
2468 /* Instantiate a layout control for putting other widgets in. */
|
|
2469 static void
|
771
|
2470 x_native_layout_instantiate (Lisp_Object image_instance,
|
|
2471 Lisp_Object instantiator,
|
442
|
2472 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2473 int dest_mask, Lisp_Object domain)
|
|
2474 {
|
|
2475 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2476 pointer_bg, dest_mask, domain, "layout", 0);
|
|
2477 }
|
|
2478
|
428
|
2479 /* Instantiate a button widget. Unfortunately instantiated widgets are
|
|
2480 particular to a frame since they need to have a parent. It's not
|
|
2481 like images where you just select the image into the context you
|
|
2482 want to display it in and BitBlt it. So images instances can have a
|
|
2483 many-to-one relationship with things you see, whereas widgets can
|
|
2484 only be one-to-one (i.e. per frame) */
|
|
2485 static void
|
|
2486 x_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2487 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2488 int dest_mask, Lisp_Object domain)
|
|
2489 {
|
440
|
2490 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2491 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
|
2492 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
|
442
|
2493 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 1);
|
428
|
2494
|
|
2495 if (!NILP (glyph))
|
|
2496 {
|
|
2497 if (!IMAGE_INSTANCEP (glyph))
|
|
2498 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1);
|
|
2499 }
|
|
2500
|
|
2501 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2502 pointer_bg, dest_mask, domain, "button", wv);
|
|
2503
|
|
2504 /* add the image if one was given */
|
440
|
2505 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph)
|
|
2506 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (glyph)))
|
428
|
2507 {
|
|
2508 Arg al [2];
|
|
2509 int ac =0;
|
|
2510 #ifdef LWLIB_WIDGETS_MOTIF
|
|
2511 XtSetArg (al [ac], XmNlabelType, XmPIXMAP); ac++;
|
|
2512 XtSetArg (al [ac], XmNlabelPixmap, XIMAGE_INSTANCE_X_PIXMAP (glyph));ac++;
|
|
2513 #else
|
|
2514 XtSetArg (al [ac], XtNpixmap, XIMAGE_INSTANCE_X_PIXMAP (glyph)); ac++;
|
|
2515 #endif
|
|
2516 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, ac);
|
|
2517 }
|
|
2518 }
|
|
2519
|
442
|
2520 /* Update a button's clicked state.
|
|
2521
|
|
2522 #### This is overkill, but it works. Right now this causes all
|
|
2523 button instances to flash for some reason buried deep in lwlib. In
|
|
2524 theory this should be the Right Thing to do since lwlib should only
|
|
2525 merge in changed values - and if nothing has changed then nothing
|
|
2526 should get done. This may be because of the args stuff,
|
|
2527 i.e. although the arg contents may be the same the args look
|
|
2528 different and so are re-applied to the widget. */
|
|
2529 static void
|
|
2530 x_button_redisplay (Lisp_Object image_instance)
|
|
2531 {
|
|
2532 /* This function can GC if IN_REDISPLAY is false. */
|
|
2533 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
2534 widget_value* wv =
|
|
2535 gui_items_to_widget_values (image_instance,
|
|
2536 IMAGE_INSTANCE_WIDGET_ITEMS (p), 1);
|
|
2537
|
|
2538 /* now modify the widget */
|
|
2539 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (p),
|
|
2540 wv, True);
|
|
2541 free_widget_value_tree (wv);
|
|
2542 }
|
|
2543
|
428
|
2544 /* get properties of a button */
|
|
2545 static Lisp_Object
|
|
2546 x_button_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2547 {
|
440
|
2548 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2549 /* check the state of a button */
|
|
2550 if (EQ (prop, Q_selected))
|
|
2551 {
|
|
2552 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
|
|
2553
|
|
2554 if (wv->selected)
|
|
2555 return Qt;
|
|
2556 else
|
|
2557 return Qnil;
|
|
2558 }
|
|
2559 return Qunbound;
|
|
2560 }
|
|
2561
|
|
2562 /* instantiate a progress gauge */
|
|
2563 static void
|
|
2564 x_progress_gauge_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2565 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2566 int dest_mask, Lisp_Object domain)
|
|
2567 {
|
440
|
2568 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2569 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
442
|
2570 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 0);
|
428
|
2571
|
|
2572 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2573 pointer_bg, dest_mask, domain, "progress", wv);
|
|
2574 }
|
|
2575
|
442
|
2576 /* set the properties of a progress gauge */
|
|
2577 static void
|
|
2578 x_progress_gauge_redisplay (Lisp_Object image_instance)
|
428
|
2579 {
|
639
|
2580 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
2581
|
|
2582 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
428
|
2583 {
|
|
2584 Arg al [1];
|
442
|
2585 Lisp_Object val;
|
639
|
2586 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (p))->value;
|
428
|
2587 XtSetArg (al[0], XtNvalue, XINT (val));
|
639
|
2588 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (p), al, 1);
|
428
|
2589 }
|
|
2590 }
|
|
2591
|
|
2592 /* instantiate an edit control */
|
|
2593 static void
|
|
2594 x_edit_field_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
771
|
2595 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2596 int dest_mask, Lisp_Object domain)
|
428
|
2597 {
|
440
|
2598 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2599 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
442
|
2600 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 0);
|
438
|
2601
|
428
|
2602 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2603 pointer_bg, dest_mask, domain, "text-field", wv);
|
|
2604 }
|
|
2605
|
|
2606 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
|
2607 /* instantiate a combo control */
|
|
2608 static void
|
|
2609 x_combo_box_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
771
|
2610 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2611 int dest_mask, Lisp_Object domain)
|
428
|
2612 {
|
440
|
2613 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2614 widget_value * wv = 0;
|
|
2615 /* This is not done generically because of sizing problems under
|
|
2616 mswindows. */
|
438
|
2617 widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2618 pointer_bg, dest_mask, domain);
|
428
|
2619
|
442
|
2620 wv = gui_items_to_widget_values (image_instance,
|
|
2621 IMAGE_INSTANCE_WIDGET_ITEMS (ii), 0);
|
438
|
2622
|
428
|
2623 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2624 pointer_bg, dest_mask, domain, "combo-box", wv);
|
|
2625 }
|
|
2626 #endif
|
|
2627
|
|
2628 static void
|
|
2629 x_tab_control_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2630 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2631 int dest_mask, Lisp_Object domain)
|
|
2632 {
|
440
|
2633 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
438
|
2634 widget_value * wv =
|
442
|
2635 gui_items_to_widget_values (image_instance,
|
|
2636 IMAGE_INSTANCE_WIDGET_ITEMS (ii), 0);
|
438
|
2637 update_tab_widget_face (wv, ii,
|
442
|
2638 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2639 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2640 pointer_bg, dest_mask, domain, "tab-control", wv);
|
|
2641 }
|
|
2642
|
442
|
2643 /* Set the properties of a tab control */
|
|
2644 static void
|
|
2645 x_tab_control_redisplay (Lisp_Object image_instance)
|
428
|
2646 {
|
440
|
2647 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
438
|
2648
|
442
|
2649 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii)
|
|
2650 ||
|
|
2651 IMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (ii))
|
428
|
2652 {
|
442
|
2653 /* If only the order has changed then simply select the first
|
|
2654 one of the pending set. This stops horrendous rebuilding -
|
|
2655 and hence flicker - of the tabs each time you click on
|
|
2656 one. */
|
|
2657 if (tab_control_order_only_changed (image_instance))
|
|
2658 {
|
|
2659 Lisp_Object rest, selected =
|
|
2660 gui_item_list_find_selected
|
|
2661 (NILP (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)) ?
|
|
2662 XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)) :
|
|
2663 XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)));
|
|
2664
|
|
2665 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
|
|
2666 {
|
|
2667 if (gui_item_equal_sans_selected (XCAR (rest), selected, 0))
|
|
2668 {
|
|
2669 /* There may be an encapsulated way of doing this,
|
|
2670 but I couldn't find it. */
|
|
2671 Lisp_Object old_selected =gui_item_list_find_selected
|
|
2672 (XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)));
|
|
2673 Arg al [1];
|
|
2674 char* name;
|
|
2675 unsigned int num_children, i;
|
|
2676 Widget* children;
|
|
2677
|
|
2678 LISP_STRING_TO_EXTERNAL (XGUI_ITEM (XCAR (rest))->name,
|
|
2679 name, Qnative);
|
|
2680 /* The name may contain a `.' which confuses
|
|
2681 XtNameToWidget, so we do it ourselves. */
|
|
2682 children = XtCompositeChildren (IMAGE_INSTANCE_X_WIDGET_ID (ii),
|
|
2683 &num_children);
|
|
2684 for (i = 0; i < num_children; i++)
|
|
2685 {
|
|
2686 if (!strcmp (XtName (children [i]), name))
|
|
2687 {
|
|
2688 XtSetArg (al [0], XtNtopWidget, children [i]);
|
|
2689 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, 1);
|
|
2690 break;
|
|
2691 }
|
|
2692 }
|
|
2693 /* Pick up the new selected item. */
|
|
2694 XGUI_ITEM (old_selected)->selected =
|
|
2695 XGUI_ITEM (XCAR (rest))->selected;
|
|
2696 XGUI_ITEM (XCAR (rest))->selected =
|
|
2697 XGUI_ITEM (selected)->selected;
|
|
2698 /* We're not actually changing the items anymore. */
|
|
2699 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) = 0;
|
|
2700 IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii) = Qnil;
|
|
2701 break;
|
|
2702 }
|
|
2703 }
|
|
2704 }
|
|
2705 }
|
|
2706 /* Possibly update the face. */
|
|
2707 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (ii)
|
|
2708 ||
|
|
2709 XFRAME (IMAGE_INSTANCE_FRAME (ii))->faces_changed
|
|
2710 ||
|
|
2711 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
|
|
2712 {
|
|
2713 /* See previous comments on the brokeness of lwlib.
|
|
2714
|
|
2715 #### There's actually not much point in doing this here
|
|
2716 since, colors will have been set appropriately by
|
|
2717 x_redisplay_widget. */
|
|
2718 widget_value* wv =copy_widget_value_tree
|
|
2719 (lw_get_all_values
|
|
2720 (IMAGE_INSTANCE_X_WIDGET_LWID (ii)),
|
|
2721 NO_CHANGE);
|
438
|
2722
|
|
2723 update_tab_widget_face (wv, ii,
|
442
|
2724 IMAGE_INSTANCE_FRAME (ii));
|
428
|
2725
|
|
2726 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (ii), wv, True);
|
|
2727 free_widget_value_tree (wv);
|
|
2728 }
|
|
2729 }
|
|
2730
|
|
2731 /* instantiate a static control possible for putting other things in */
|
|
2732 static void
|
|
2733 x_label_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2734 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2735 int dest_mask, Lisp_Object domain)
|
|
2736 {
|
440
|
2737 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
428
|
2738 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
|
442
|
2739 widget_value* wv = gui_items_to_widget_values (image_instance, gui, 0);
|
438
|
2740
|
428
|
2741 x_widget_instantiate (image_instance, instantiator, pointer_fg,
|
|
2742 pointer_bg, dest_mask, domain, "button", wv);
|
|
2743 }
|
771
|
2744 #endif /* HAVE_X_WIDGETS */
|
428
|
2745
|
|
2746
|
|
2747 /************************************************************************/
|
|
2748 /* initialization */
|
|
2749 /************************************************************************/
|
|
2750
|
|
2751 void
|
|
2752 syms_of_glyphs_x (void)
|
|
2753 {
|
|
2754 #if 0
|
|
2755 DEFSUBR (Fchange_subwindow_property);
|
|
2756 #endif
|
|
2757 }
|
|
2758
|
|
2759 void
|
|
2760 console_type_create_glyphs_x (void)
|
|
2761 {
|
|
2762 /* image methods */
|
|
2763
|
|
2764 CONSOLE_HAS_METHOD (x, print_image_instance);
|
|
2765 CONSOLE_HAS_METHOD (x, finalize_image_instance);
|
|
2766 CONSOLE_HAS_METHOD (x, image_instance_equal);
|
|
2767 CONSOLE_HAS_METHOD (x, image_instance_hash);
|
|
2768 CONSOLE_HAS_METHOD (x, colorize_image_instance);
|
|
2769 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage);
|
|
2770 CONSOLE_HAS_METHOD (x, locate_pixmap_file);
|
|
2771 CONSOLE_HAS_METHOD (x, unmap_subwindow);
|
|
2772 CONSOLE_HAS_METHOD (x, map_subwindow);
|
442
|
2773 CONSOLE_HAS_METHOD (x, redisplay_widget);
|
|
2774 CONSOLE_HAS_METHOD (x, redisplay_subwindow);
|
428
|
2775 }
|
|
2776
|
|
2777 void
|
|
2778 image_instantiator_format_create_glyphs_x (void)
|
|
2779 {
|
|
2780 IIFORMAT_VALID_CONSOLE (x, nothing);
|
|
2781 IIFORMAT_VALID_CONSOLE (x, string);
|
771
|
2782 #ifdef HAVE_X_WIDGETS
|
428
|
2783 IIFORMAT_VALID_CONSOLE (x, layout);
|
442
|
2784 #endif
|
428
|
2785 IIFORMAT_VALID_CONSOLE (x, formatted_string);
|
|
2786 IIFORMAT_VALID_CONSOLE (x, inherit);
|
|
2787 #ifdef HAVE_XPM
|
|
2788 INITIALIZE_DEVICE_IIFORMAT (x, xpm);
|
|
2789 IIFORMAT_HAS_DEVMETHOD (x, xpm, instantiate);
|
|
2790 #endif
|
|
2791 #ifdef HAVE_JPEG
|
|
2792 IIFORMAT_VALID_CONSOLE (x, jpeg);
|
|
2793 #endif
|
|
2794 #ifdef HAVE_TIFF
|
|
2795 IIFORMAT_VALID_CONSOLE (x, tiff);
|
438
|
2796 #endif
|
428
|
2797 #ifdef HAVE_PNG
|
|
2798 IIFORMAT_VALID_CONSOLE (x, png);
|
438
|
2799 #endif
|
428
|
2800 #ifdef HAVE_GIF
|
|
2801 IIFORMAT_VALID_CONSOLE (x, gif);
|
438
|
2802 #endif
|
428
|
2803 INITIALIZE_DEVICE_IIFORMAT (x, xbm);
|
|
2804 IIFORMAT_HAS_DEVMETHOD (x, xbm, instantiate);
|
|
2805
|
|
2806 INITIALIZE_DEVICE_IIFORMAT (x, subwindow);
|
|
2807 IIFORMAT_HAS_DEVMETHOD (x, subwindow, instantiate);
|
771
|
2808 #ifdef HAVE_X_WIDGETS
|
442
|
2809 /* layout widget */
|
|
2810 INITIALIZE_DEVICE_IIFORMAT (x, native_layout);
|
|
2811 IIFORMAT_HAS_DEVMETHOD (x, native_layout, instantiate);
|
428
|
2812 /* button widget */
|
|
2813 INITIALIZE_DEVICE_IIFORMAT (x, button);
|
|
2814 IIFORMAT_HAS_DEVMETHOD (x, button, property);
|
|
2815 IIFORMAT_HAS_DEVMETHOD (x, button, instantiate);
|
442
|
2816 IIFORMAT_HAS_DEVMETHOD (x, button, redisplay);
|
|
2817 /* general widget methods. */
|
428
|
2818 INITIALIZE_DEVICE_IIFORMAT (x, widget);
|
|
2819 IIFORMAT_HAS_DEVMETHOD (x, widget, property);
|
|
2820 /* progress gauge */
|
|
2821 INITIALIZE_DEVICE_IIFORMAT (x, progress_gauge);
|
442
|
2822 IIFORMAT_HAS_DEVMETHOD (x, progress_gauge, redisplay);
|
428
|
2823 IIFORMAT_HAS_DEVMETHOD (x, progress_gauge, instantiate);
|
|
2824 /* text field */
|
|
2825 INITIALIZE_DEVICE_IIFORMAT (x, edit_field);
|
|
2826 IIFORMAT_HAS_DEVMETHOD (x, edit_field, instantiate);
|
|
2827 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
|
|
2828 /* combo box */
|
|
2829 INITIALIZE_DEVICE_IIFORMAT (x, combo_box);
|
|
2830 IIFORMAT_HAS_DEVMETHOD (x, combo_box, instantiate);
|
442
|
2831 IIFORMAT_HAS_SHARED_DEVMETHOD (x, combo_box, redisplay, tab_control);
|
428
|
2832 #endif
|
|
2833 /* tab control widget */
|
|
2834 INITIALIZE_DEVICE_IIFORMAT (x, tab_control);
|
|
2835 IIFORMAT_HAS_DEVMETHOD (x, tab_control, instantiate);
|
442
|
2836 IIFORMAT_HAS_DEVMETHOD (x, tab_control, redisplay);
|
428
|
2837 /* label */
|
|
2838 INITIALIZE_DEVICE_IIFORMAT (x, label);
|
|
2839 IIFORMAT_HAS_DEVMETHOD (x, label, instantiate);
|
|
2840 #endif
|
|
2841 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
2842 IIFORMAT_VALID_CONSOLE (x, cursor_font);
|
|
2843
|
|
2844 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
2845 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
2846 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
2847
|
|
2848 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
2849 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
2850 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
2851
|
|
2852 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
2853
|
|
2854 IIFORMAT_HAS_METHOD (font, validate);
|
|
2855 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
2856 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
2857 IIFORMAT_VALID_CONSOLE (x, font);
|
|
2858
|
|
2859 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
2860 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
2861 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
2862
|
|
2863 #ifdef HAVE_XFACE
|
|
2864 INITIALIZE_DEVICE_IIFORMAT (x, xface);
|
|
2865 IIFORMAT_HAS_DEVMETHOD (x, xface, instantiate);
|
|
2866 #endif
|
|
2867
|
|
2868 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect,
|
|
2869 "autodetect");
|
|
2870
|
|
2871 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
2872 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
2873 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
446
|
2874 /* #### autodetect is flawed IMO:
|
|
2875 1. It makes the assumption that you can detect whether the user
|
|
2876 wanted a cursor or a string based on the data, since the data is a
|
|
2877 string you have to prioritise cursors. Instead we will force users
|
|
2878 to pick the appropriate image type, this is what we do under
|
|
2879 MS-Windows anyway.
|
|
2880 2. It doesn't fit with the new domain model - you cannot tell which
|
|
2881 domain it needs to be instantiated in until you've actually
|
|
2882 instantiated it, which mucks up caching.
|
|
2883 3. It only copes with cursors and strings which seems bogus. */
|
|
2884 IIFORMAT_HAS_SHARED_METHOD (autodetect, governing_domain, subwindow);
|
428
|
2885 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
2886 IIFORMAT_VALID_CONSOLE (x, autodetect);
|
|
2887
|
|
2888 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
|
2889 }
|
|
2890
|
|
2891 void
|
|
2892 vars_of_glyphs_x (void)
|
|
2893 {
|
|
2894 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path /*
|
|
2895 A list of the directories in which X bitmap files may be found.
|
|
2896 If nil, this is initialized from the "*bitmapFilePath" resource.
|
|
2897 This is used by the `make-image-instance' function (however, note that if
|
|
2898 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
2899 */ );
|
|
2900 Vx_bitmap_file_path = Qnil;
|
|
2901 }
|
|
2902
|
|
2903 void
|
|
2904 complex_vars_of_glyphs_x (void)
|
|
2905 {
|
|
2906 #define BUILD_GLYPH_INST(variable, name) \
|
|
2907 Fadd_spec_to_specifier \
|
|
2908 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
2909 vector3 (Qxbm, Q_data, \
|
|
2910 list3 (make_int (name##_width), \
|
|
2911 make_int (name##_height), \
|
444
|
2912 make_ext_string ((Extbyte *) name##_bits, \
|
428
|
2913 sizeof (name##_bits), \
|
440
|
2914 Qbinary))), \
|
428
|
2915 Qglobal, Qx, Qnil)
|
|
2916
|
|
2917 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
2918 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
2919 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
|
2920 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
|
2921
|
|
2922 #undef BUILD_GLYPH_INST
|
|
2923 }
|