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