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