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