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