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