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