comparison src/glyphs-x.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 1f50e6fe4f3f
children a86b2b5e0111
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc. 2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3 Copyright (C) 1995 Board of Trustees, University of Illinois. 3 Copyright (C) 1995 Board of Trustees, University of Illinois.
4 Copyright (C) 1995 Tinker Systems 4 Copyright (C) 1995 Tinker Systems
5 Copyright (C) 1995, 1996 Ben Wing 5 Copyright (C) 1995, 1996 Ben Wing
6 Copyright (C) 1995 Sun Microsystems 6 Copyright (C) 1995 Sun Microsystems
7 Copyright (C) 1999, 2000 Andy Piper
7 8
8 This file is part of XEmacs. 9 This file is part of XEmacs.
9 10
10 XEmacs is free software; you can redistribute it and/or modify it 11 XEmacs is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the 12 under the terms of the GNU General Public License as published by the
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14 38 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
38 GIF support changed to external GIFlib 3.1 by Jareth Hein for 21.0 39 GIF support changed to external GIFlib 3.1 by Jareth Hein for 21.0
39 Many changes for color work and optimizations by Jareth Hein for 21.0 40 Many changes for color work and optimizations by Jareth Hein for 21.0
40 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0 41 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0
41 TIFF code by Jareth Hein for 21.0 42 TIFF code by Jareth Hein for 21.0
42 GIF/JPEG/PNG/TIFF code moved to new glyph-eimage.c for 21.0 43 GIF/JPEG/PNG/TIFF code moved to new glyph-eimage.c by Andy Piper for 21.0
44 Subwindow and Widget support by Andy Piper for 21.2
43 45
44 TODO: 46 TODO:
47 Support the GrayScale, StaticColor and StaticGray visual classes.
45 Convert images.el to C and stick it in here? 48 Convert images.el to C and stick it in here?
46 */ 49 */
47 50
48 #include <config.h> 51 #include <config.h>
49 #include "lisp.h" 52 #include "lisp.h"
50 #include "lstream.h" 53 #include "lstream.h"
51 #include "console-x.h" 54 #include "console-x.h"
52 #include "glyphs-x.h" 55 #include "glyphs-x.h"
53 #include "objects-x.h" 56 #include "objects-x.h"
57 #ifdef HAVE_WIDGETS
58 #include "gui-x.h"
59 #endif
54 #include "xmu.h" 60 #include "xmu.h"
55 61
56 #include "buffer.h" 62 #include "buffer.h"
57 #include "window.h" 63 #include "window.h"
58 #include "frame.h" 64 #include "frame.h"
59 #include "insdel.h" 65 #include "insdel.h"
60 #include "opaque.h" 66 #include "opaque.h"
67 #include "gui.h"
68 #include "faces.h"
61 69
62 #include "imgproc.h" 70 #include "imgproc.h"
63 71
64 #include "sysfile.h" 72 #include "sysfile.h"
65 73
66 #include <setjmp.h> 74 #include <setjmp.h>
67 75
68 #ifdef FILE_CODING 76 #ifdef FILE_CODING
69 #include "file-coding.h" 77 #include "file-coding.h"
70 #endif 78 #endif
79
80 #ifdef LWLIB_WIDGETS_MOTIF
81 #include <Xm/Xm.h>
82 #endif
83 #include <X11/IntrinsicP.h>
71 84
72 #if INTBITS == 32 85 #if INTBITS == 32
73 # define FOUR_BYTE_TYPE unsigned int 86 # define FOUR_BYTE_TYPE unsigned int
74 #elif LONGBITS == 32 87 #elif LONGBITS == 32
75 # define FOUR_BYTE_TYPE unsigned long 88 # define FOUR_BYTE_TYPE unsigned long
79 #error What kind of strange-ass system are we running on? 92 #error What kind of strange-ass system are we running on?
80 #endif 93 #endif
81 94
82 #define LISP_DEVICE_TO_X_SCREEN(dev) XDefaultScreenOfDisplay (DEVICE_X_DISPLAY (XDEVICE (dev))) 95 #define LISP_DEVICE_TO_X_SCREEN(dev) XDefaultScreenOfDisplay (DEVICE_X_DISPLAY (XDEVICE (dev)))
83 96
97 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing);
98 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string);
99 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
100 DECLARE_IMAGE_INSTANTIATOR_FORMAT (inherit);
101 DECLARE_IMAGE_INSTANTIATOR_FORMAT (layout);
102 #ifdef HAVE_JPEG
103 DECLARE_IMAGE_INSTANTIATOR_FORMAT (jpeg);
104 #endif
105 #ifdef HAVE_TIFF
106 DECLARE_IMAGE_INSTANTIATOR_FORMAT (tiff);
107 #endif
108 #ifdef HAVE_PNG
109 DECLARE_IMAGE_INSTANTIATOR_FORMAT (png);
110 #endif
111 #ifdef HAVE_GIF
112 DECLARE_IMAGE_INSTANTIATOR_FORMAT (gif);
113 #endif
84 #ifdef HAVE_XPM 114 #ifdef HAVE_XPM
85 DEFINE_DEVICE_IIFORMAT (x, xpm); 115 DEFINE_DEVICE_IIFORMAT (x, xpm);
86 #endif 116 #endif
87 DEFINE_DEVICE_IIFORMAT (x, xbm); 117 DEFINE_DEVICE_IIFORMAT (x, xbm);
88 DEFINE_DEVICE_IIFORMAT (x, subwindow); 118 DEFINE_DEVICE_IIFORMAT (x, subwindow);
94 Lisp_Object Qcursor_font; 124 Lisp_Object Qcursor_font;
95 125
96 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font); 126 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font);
97 127
98 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect); 128 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect);
129
130 #ifdef HAVE_WIDGETS
131 DEFINE_DEVICE_IIFORMAT (x, widget);
132 DEFINE_DEVICE_IIFORMAT (x, button);
133 DEFINE_DEVICE_IIFORMAT (x, progress_gauge);
134 DEFINE_DEVICE_IIFORMAT (x, edit_field);
135 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
136 DEFINE_DEVICE_IIFORMAT (x, combo_box);
137 #endif
138 DEFINE_DEVICE_IIFORMAT (x, tab_control);
139 DEFINE_DEVICE_IIFORMAT (x, label);
140 #endif
99 141
100 static void cursor_font_instantiate (Lisp_Object image_instance, 142 static void cursor_font_instantiate (Lisp_Object image_instance,
101 Lisp_Object instantiator, 143 Lisp_Object instantiator,
102 Lisp_Object pointer_fg, 144 Lisp_Object pointer_fg,
103 Lisp_Object pointer_bg, 145 Lisp_Object pointer_bg,
104 int dest_mask, 146 int dest_mask,
105 Lisp_Object domain); 147 Lisp_Object domain);
148
149 #ifdef HAVE_WIDGETS
150 static void
151 update_widget_face (widget_value* wv,
152 Lisp_Image_Instance* ii, Lisp_Object domain);
153 static void
154 update_tab_widget_face (widget_value* wv,
155 Lisp_Image_Instance* ii, Lisp_Object domain);
156 #endif
106 157
107 #include "bitmaps.h" 158 #include "bitmaps.h"
108 159
109 160
110 /************************************************************************/ 161 /************************************************************************/
136 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 187 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
137 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); 188 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
138 vis = DEVICE_X_VISUAL (XDEVICE(device)); 189 vis = DEVICE_X_VISUAL (XDEVICE(device));
139 depth = DEVICE_X_DEPTH(XDEVICE(device)); 190 depth = DEVICE_X_DEPTH(XDEVICE(device));
140 191
192 if (vis->class == GrayScale || vis->class == StaticColor ||
193 vis->class == StaticGray)
194 {
195 /* #### Implement me!!! */
196 return NULL;
197 }
198
141 if (vis->class == PseudoColor) 199 if (vis->class == PseudoColor)
142 { 200 {
143 /* Quantize the image and get a histogram while we're at it. 201 /* Quantize the image and get a histogram while we're at it.
144 Do this first to save memory */ 202 Do this first to save memory */
145 qtable = build_EImage_quantable(pic, width, height, 256); 203 qtable = build_EImage_quantable(pic, width, height, 256);
173 /* use our quantize table to allocate the colors */ 231 /* use our quantize table to allocate the colors */
174 pixcount = 32; 232 pixcount = 32;
175 *pixtbl = xnew_array (unsigned long, pixcount); 233 *pixtbl = xnew_array (unsigned long, pixcount);
176 *npixels = 0; 234 *npixels = 0;
177 235
178 /* ### should implement a sort by popularity to assure proper allocation */ 236 /* #### should implement a sort by popularity to assure proper allocation */
179 n = *npixels; 237 n = *npixels;
180 for (i = 0; i < qtable->num_active_colors; i++) 238 for (i = 0; i < qtable->num_active_colors; i++)
181 { 239 {
182 XColor color; 240 XColor color;
183 int res; 241 int res;
299 } 357 }
300 358
301 359
302 360
303 static void 361 static void
304 x_print_image_instance (struct Lisp_Image_Instance *p, 362 x_print_image_instance (Lisp_Image_Instance *p,
305 Lisp_Object printcharfun, 363 Lisp_Object printcharfun,
306 int escapeflag) 364 int escapeflag)
307 { 365 {
308 char buf[100]; 366 char buf[100];
309 367
324 default: 382 default:
325 break; 383 break;
326 } 384 }
327 } 385 }
328 386
329 static void 387 #ifdef DEBUG_WIDGETS
330 x_finalize_image_instance (struct Lisp_Image_Instance *p) 388 extern int debug_widget_instances;
389 #endif
390
391 static void
392 x_finalize_image_instance (Lisp_Image_Instance *p)
331 { 393 {
332 if (!p->data) 394 if (!p->data)
333 return; 395 return;
334 396
335 if (DEVICE_LIVE_P (XDEVICE (p->device))) 397 if (DEVICE_LIVE_P (XDEVICE (p->device)))
336 { 398 {
337 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (p->device)); 399 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (p->device));
338 400
339 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET 401 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET)
340 || 402 {
341 IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW) 403 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
404 {
405 #ifdef DEBUG_WIDGETS
406 debug_widget_instances--;
407 stderr_out ("widget destroyed, %d left\n", debug_widget_instances);
408 #endif
409 lw_destroy_widget (IMAGE_INSTANCE_X_WIDGET_ID (p));
410 lw_destroy_widget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
411 IMAGE_INSTANCE_X_WIDGET_ID (p) = 0;
412 IMAGE_INSTANCE_X_CLIPWIDGET (p) = 0;
413 }
414 }
415 else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
342 { 416 {
343 if (IMAGE_INSTANCE_SUBWINDOW_ID (p)) 417 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
344 XDestroyWindow (dpy, IMAGE_INSTANCE_X_SUBWINDOW_ID (p)); 418 XDestroyWindow (dpy, IMAGE_INSTANCE_X_SUBWINDOW_ID (p));
345 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0; 419 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0;
346 } 420 }
347 else 421 else
348 { 422 {
349 if (IMAGE_INSTANCE_X_PIXMAP (p)) 423 int i;
350 XFreePixmap (dpy, IMAGE_INSTANCE_X_PIXMAP (p)); 424 if (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p))
425 disable_glyph_animated_timeout (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p));
426
351 if (IMAGE_INSTANCE_X_MASK (p) && 427 if (IMAGE_INSTANCE_X_MASK (p) &&
352 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p)) 428 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p))
353 XFreePixmap (dpy, IMAGE_INSTANCE_X_MASK (p)); 429 XFreePixmap (dpy, IMAGE_INSTANCE_X_MASK (p));
354 IMAGE_INSTANCE_X_PIXMAP (p) = 0; 430 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
355 IMAGE_INSTANCE_X_MASK (p) = 0; 431
356 432 if (IMAGE_INSTANCE_X_PIXMAP_SLICES (p))
433 {
434 for (i = 0; i < IMAGE_INSTANCE_PIXMAP_MAXSLICE (p); i++)
435 if (IMAGE_INSTANCE_X_PIXMAP_SLICE (p,i))
436 {
437 XFreePixmap (dpy, IMAGE_INSTANCE_X_PIXMAP_SLICE (p,i));
438 IMAGE_INSTANCE_X_PIXMAP_SLICE (p, i) = 0;
439 }
440 xfree (IMAGE_INSTANCE_X_PIXMAP_SLICES (p));
441 IMAGE_INSTANCE_X_PIXMAP_SLICES (p) = 0;
442 }
443
357 if (IMAGE_INSTANCE_X_CURSOR (p)) 444 if (IMAGE_INSTANCE_X_CURSOR (p))
358 { 445 {
359 XFreeCursor (dpy, IMAGE_INSTANCE_X_CURSOR (p)); 446 XFreeCursor (dpy, IMAGE_INSTANCE_X_CURSOR (p));
360 IMAGE_INSTANCE_X_CURSOR (p) = 0; 447 IMAGE_INSTANCE_X_CURSOR (p) = 0;
361 } 448 }
362 449
363 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0) 450 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0)
364 { 451 {
365 XFreeColors (dpy, 452 XFreeColors (dpy,
366 IMAGE_INSTANCE_X_COLORMAP (p), 453 IMAGE_INSTANCE_X_COLORMAP (p),
367 IMAGE_INSTANCE_X_PIXELS (p), 454 IMAGE_INSTANCE_X_PIXELS (p),
368 IMAGE_INSTANCE_X_NPIXELS (p), 0); 455 IMAGE_INSTANCE_X_NPIXELS (p), 0);
369 IMAGE_INSTANCE_X_NPIXELS (p) = 0; 456 IMAGE_INSTANCE_X_NPIXELS (p) = 0;
370 } 457 }
371 } 458 }
372 } 459 }
373 if (IMAGE_INSTANCE_X_PIXELS (p)) 460 /* You can sometimes have pixels without a live device. I forget
461 why, but that's why we free them here if we have a pixmap type
462 image instance. It probably means that we might also get a memory
463 leak with widgets. */
464 if (IMAGE_INSTANCE_TYPE (p) != IMAGE_WIDGET
465 && IMAGE_INSTANCE_TYPE (p) != IMAGE_SUBWINDOW
466 && IMAGE_INSTANCE_X_PIXELS (p))
374 { 467 {
375 xfree (IMAGE_INSTANCE_X_PIXELS (p)); 468 xfree (IMAGE_INSTANCE_X_PIXELS (p));
376 IMAGE_INSTANCE_X_PIXELS (p) = 0; 469 IMAGE_INSTANCE_X_PIXELS (p) = 0;
377 } 470 }
378 471
379 xfree (p->data); 472 xfree (p->data);
380 p->data = 0; 473 p->data = 0;
381 } 474 }
382 475
383 static int 476 static int
384 x_image_instance_equal (struct Lisp_Image_Instance *p1, 477 x_image_instance_equal (Lisp_Image_Instance *p1,
385 struct Lisp_Image_Instance *p2, int depth) 478 Lisp_Image_Instance *p2, int depth)
386 { 479 {
387 switch (IMAGE_INSTANCE_TYPE (p1)) 480 switch (IMAGE_INSTANCE_TYPE (p1))
388 { 481 {
389 case IMAGE_MONO_PIXMAP: 482 case IMAGE_MONO_PIXMAP:
390 case IMAGE_COLOR_PIXMAP: 483 case IMAGE_COLOR_PIXMAP:
399 492
400 return 1; 493 return 1;
401 } 494 }
402 495
403 static unsigned long 496 static unsigned long
404 x_image_instance_hash (struct Lisp_Image_Instance *p, int depth) 497 x_image_instance_hash (Lisp_Image_Instance *p, int depth)
405 { 498 {
406 switch (IMAGE_INSTANCE_TYPE (p)) 499 switch (IMAGE_INSTANCE_TYPE (p))
407 { 500 {
408 case IMAGE_MONO_PIXMAP: 501 case IMAGE_MONO_PIXMAP:
409 case IMAGE_COLOR_PIXMAP: 502 case IMAGE_COLOR_PIXMAP:
419 method. It is assumed that the device slot within the image 512 method. It is assumed that the device slot within the image
420 instance is already set -- this is the case when instantiate 513 instance is already set -- this is the case when instantiate
421 methods are called. */ 514 methods are called. */
422 515
423 static void 516 static void
424 x_initialize_pixmap_image_instance (struct Lisp_Image_Instance *ii, 517 x_initialize_pixmap_image_instance (Lisp_Image_Instance *ii,
518 int slices,
425 enum image_instance_type type) 519 enum image_instance_type type)
426 { 520 {
427 ii->data = xnew_and_zero (struct x_image_instance_data); 521 ii->data = xnew_and_zero (struct x_image_instance_data);
522 IMAGE_INSTANCE_PIXMAP_MAXSLICE (ii) = slices;
523 IMAGE_INSTANCE_X_PIXMAP_SLICES (ii) =
524 xnew_array_and_zero (Pixmap, slices);
428 IMAGE_INSTANCE_TYPE (ii) = type; 525 IMAGE_INSTANCE_TYPE (ii) = type;
429 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil; 526 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
430 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil; 527 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
431 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil; 528 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
432 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil; 529 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
466 (XSTRING_BYTE (name, 1) == '/' || 563 (XSTRING_BYTE (name, 1) == '/' ||
467 (XSTRING_BYTE (name, 1) == '.' && 564 (XSTRING_BYTE (name, 1) == '.' &&
468 (XSTRING_BYTE (name, 2) == '/'))))) 565 (XSTRING_BYTE (name, 2) == '/')))))
469 { 566 {
470 if (!NILP (Ffile_readable_p (name))) 567 if (!NILP (Ffile_readable_p (name)))
471 return name; 568 return Fexpand_file_name (name, Qnil);
472 else 569 else
473 return Qnil; 570 return Qnil;
474 } 571 }
475 572
476 if (NILP (Vdefault_x_device)) 573 if (NILP (Vdefault_x_device))
511 (decode_path (BITMAPDIR))); 608 (decode_path (BITMAPDIR)));
512 } 609 }
513 610
514 { 611 {
515 Lisp_Object found; 612 Lisp_Object found;
516 if (locate_file (Vx_bitmap_file_path, name, "", &found, R_OK) < 0) 613 if (locate_file (Vx_bitmap_file_path, name, Qnil, &found, R_OK) < 0)
517 { 614 {
518 Lisp_Object temp = list1 (Vdata_directory); 615 Lisp_Object temp = list1 (Vdata_directory);
519 struct gcpro gcpro1; 616 struct gcpro gcpro1;
520 617
521 GCPRO1 (temp); 618 GCPRO1 (temp);
522 locate_file (temp, name, "", &found, R_OK); 619 locate_file (temp, name, Qnil, &found, R_OK);
523 UNGCPRO; 620 UNGCPRO;
524 } 621 }
525 622
526 return found; 623 return found;
527 } 624 }
592 #endif 689 #endif
593 690
594 /* Get the data while doing the conversion */ 691 /* Get the data while doing the conversion */
595 while (1) 692 while (1)
596 { 693 {
597 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf)); 694 ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
598 if (!size_in_bytes) 695 if (!size_in_bytes)
599 break; 696 break;
600 /* It does seem the flushes are necessary... */ 697 /* It does seem the flushes are necessary... */
601 #ifdef FILE_CODING 698 #ifdef FILE_CODING
602 Lstream_write (costr, tempbuf, size_in_bytes); 699 Lstream_write (costr, tempbuf, size_in_bytes);
735 832
736 #### This should be able to handle conversion into `pointer'. 833 #### This should be able to handle conversion into `pointer'.
737 Use the same code as for `xpm'. */ 834 Use the same code as for `xpm'. */
738 835
739 static void 836 static void
740 init_image_instance_from_x_image (struct Lisp_Image_Instance *ii, 837 init_image_instance_from_x_image (Lisp_Image_Instance *ii,
741 XImage *ximage, 838 XImage *ximage,
742 int dest_mask, 839 int dest_mask,
743 Colormap cmap, 840 Colormap cmap,
744 unsigned long *pixels, 841 unsigned long *pixels,
745 int npixels, 842 int npixels,
843 int slices,
746 Lisp_Object instantiator) 844 Lisp_Object instantiator)
747 { 845 {
748 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 846 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
749 Display *dpy; 847 Display *dpy;
750 GC gc; 848 GC gc;
776 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0, 874 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
777 ximage->width, ximage->height); 875 ximage->width, ximage->height);
778 876
779 XFreeGC (dpy, gc); 877 XFreeGC (dpy, gc);
780 878
781 x_initialize_pixmap_image_instance (ii, IMAGE_COLOR_PIXMAP); 879 x_initialize_pixmap_image_instance (ii, slices, IMAGE_COLOR_PIXMAP);
782 880
783 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = 881 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
784 find_keyword_in_vector (instantiator, Q_file); 882 find_keyword_in_vector (instantiator, Q_file);
785 883
884 /* Fixup a set of pixmaps. */
786 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap; 885 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
787 IMAGE_INSTANCE_X_MASK (ii) = 0; 886
887 IMAGE_INSTANCE_PIXMAP_MASK (ii) = 0;
788 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width; 888 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width;
789 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height; 889 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height;
790 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth; 890 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth;
791 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap; 891 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap;
792 IMAGE_INSTANCE_X_PIXELS (ii) = pixels; 892 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
793 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels; 893 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
794 } 894 }
795 895
796 static void 896 static void
797 x_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii, 897 image_instance_add_x_image (Lisp_Image_Instance *ii,
898 XImage *ximage,
899 int slice,
900 Lisp_Object instantiator)
901 {
902 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
903 Display *dpy;
904 GC gc;
905 Drawable d;
906 Pixmap pixmap;
907
908 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
909 d = XtWindow(DEVICE_XT_APP_SHELL (XDEVICE (device)));
910
911 pixmap = XCreatePixmap (dpy, d, ximage->width,
912 ximage->height, ximage->depth);
913 if (!pixmap)
914 signal_simple_error ("Unable to create pixmap", instantiator);
915
916 gc = XCreateGC (dpy, pixmap, 0, NULL);
917 if (!gc)
918 {
919 XFreePixmap (dpy, pixmap);
920 signal_simple_error ("Unable to create GC", instantiator);
921 }
922
923 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
924 ximage->width, ximage->height);
925
926 XFreeGC (dpy, gc);
927
928 IMAGE_INSTANCE_X_PIXMAP_SLICE (ii, slice) = pixmap;
929 }
930
931 static void
932 x_init_image_instance_from_eimage (Lisp_Image_Instance *ii,
798 int width, int height, 933 int width, int height,
934 int slices,
799 unsigned char *eimage, 935 unsigned char *eimage,
800 int dest_mask, 936 int dest_mask,
801 Lisp_Object instantiator, 937 Lisp_Object instantiator,
802 Lisp_Object domain) 938 Lisp_Object domain)
803 { 939 {
804 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 940 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
805 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device)); 941 Colormap cmap = DEVICE_X_COLORMAP (XDEVICE(device));
806 unsigned long *pixtbl = NULL; 942 unsigned long *pixtbl = NULL;
807 int npixels = 0; 943 int npixels = 0;
944 int slice;
808 XImage* ximage; 945 XImage* ximage;
809 946
810 ximage = convert_EImage_to_XImage (device, width, height, eimage, 947 for (slice = 0; slice < slices; slice++)
811 &pixtbl, &npixels); 948 {
812 if (!ximage) 949 ximage = convert_EImage_to_XImage (device, width, height,
813 { 950 eimage + (width * height * 3 * slice),
814 if (pixtbl) xfree (pixtbl); 951 &pixtbl, &npixels);
815 signal_image_error("EImage to XImage conversion failed", instantiator); 952 if (!ximage)
816 } 953 {
817 954 if (pixtbl) xfree (pixtbl);
818 /* Now create the pixmap and set up the image instance */ 955 signal_image_error("EImage to XImage conversion failed", instantiator);
819 init_image_instance_from_x_image (ii, ximage, dest_mask, 956 }
820 cmap, pixtbl, npixels, 957
821 instantiator); 958 /* Now create the pixmap and set up the image instance */
822 959 if (slice == 0)
823 if (ximage) 960 init_image_instance_from_x_image (ii, ximage, dest_mask,
824 { 961 cmap, pixtbl, npixels, slices,
825 if (ximage->data) 962 instantiator);
826 { 963 else
827 xfree (ximage->data); 964 image_instance_add_x_image (ii, ximage, slice, instantiator);
828 ximage->data = 0; 965
829 } 966 if (ximage)
830 XDestroyImage (ximage); 967 {
831 } 968 if (ximage->data)
832 } 969 {
833 970 xfree (ximage->data);
834 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width, 971 ximage->data = 0;
972 }
973 XDestroyImage (ximage);
974 ximage = 0;
975 }
976 }
977 }
978
979 int read_bitmap_data_from_file (const char *filename, unsigned int *width,
835 unsigned int *height, unsigned char **datap, 980 unsigned int *height, unsigned char **datap,
836 int *x_hot, int *y_hot) 981 int *x_hot, int *y_hot)
837 { 982 {
838 return XmuReadBitmapDataFromFile (filename, width, height, 983 return XmuReadBitmapDataFromFile (filename, width, height,
839 datap, x_hot, y_hot); 984 datap, x_hot, y_hot);
843 corresponding X object. */ 988 corresponding X object. */
844 989
845 static Pixmap 990 static Pixmap
846 pixmap_from_xbm_inline (Lisp_Object device, int width, int height, 991 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
847 /* Note that data is in ext-format! */ 992 /* Note that data is in ext-format! */
848 CONST Extbyte *bits) 993 const Extbyte *bits)
849 { 994 {
850 return XCreatePixmapFromBitmapData (DEVICE_X_DISPLAY (XDEVICE(device)), 995 return XCreatePixmapFromBitmapData (DEVICE_X_DISPLAY (XDEVICE(device)),
851 XtWindow (DEVICE_XT_APP_SHELL (XDEVICE (device))), 996 XtWindow (DEVICE_XT_APP_SHELL (XDEVICE (device))),
852 (char *) bits, width, height, 997 (char *) bits, width, height,
853 1, 0, 1); 998 1, 0, 1);
855 1000
856 /* Given inline data for a mono pixmap, initialize the given 1001 /* Given inline data for a mono pixmap, initialize the given
857 image instance accordingly. */ 1002 image instance accordingly. */
858 1003
859 static void 1004 static void
860 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii, 1005 init_image_instance_from_xbm_inline (Lisp_Image_Instance *ii,
861 int width, int height, 1006 int width, int height,
862 /* Note that data is in ext-format! */ 1007 /* Note that data is in ext-format! */
863 CONST char *bits, 1008 const char *bits,
864 Lisp_Object instantiator, 1009 Lisp_Object instantiator,
865 Lisp_Object pointer_fg, 1010 Lisp_Object pointer_fg,
866 Lisp_Object pointer_bg, 1011 Lisp_Object pointer_bg,
867 int dest_mask, 1012 int dest_mask,
868 Pixmap mask, 1013 Pixmap mask,
900 else 1045 else
901 incompatible_image_types (instantiator, dest_mask, 1046 incompatible_image_types (instantiator, dest_mask,
902 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK 1047 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
903 | IMAGE_POINTER_MASK); 1048 | IMAGE_POINTER_MASK);
904 1049
905 x_initialize_pixmap_image_instance (ii, type); 1050 x_initialize_pixmap_image_instance (ii, 1, type);
906 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width; 1051 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
907 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height; 1052 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
908 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = 1053 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
909 find_keyword_in_vector (instantiator, Q_file); 1054 find_keyword_in_vector (instantiator, Q_file);
910 1055
996 static void 1141 static void
997 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator, 1142 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
998 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1143 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
999 int dest_mask, int width, int height, 1144 int dest_mask, int width, int height,
1000 /* Note that data is in ext-format! */ 1145 /* Note that data is in ext-format! */
1001 CONST char *bits) 1146 const char *bits)
1002 { 1147 {
1003 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data); 1148 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
1004 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file); 1149 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
1005 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 1150 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1006 Pixmap mask = 0; 1151 Pixmap mask = 0;
1007 CONST char *gcc_may_you_rot_in_hell;
1008 1152
1009 if (!NILP (mask_data)) 1153 if (!NILP (mask_data))
1010 { 1154 {
1011 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))), 1155 const char *ext_data;
1012 gcc_may_you_rot_in_hell); 1156
1013 mask = 1157 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (mask_data))),
1014 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii), 1158 C_STRING_ALLOCA, ext_data,
1015 XINT (XCAR (mask_data)), 1159 Qbinary);
1016 XINT (XCAR (XCDR (mask_data))), 1160 mask = pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
1017 (CONST unsigned char *) 1161 XINT (XCAR (mask_data)),
1018 gcc_may_you_rot_in_hell); 1162 XINT (XCAR (XCDR (mask_data))),
1163 (const unsigned char *) ext_data);
1019 } 1164 }
1020 1165
1021 init_image_instance_from_xbm_inline (ii, width, height, bits, 1166 init_image_instance_from_xbm_inline (ii, width, height, bits,
1022 instantiator, pointer_fg, pointer_bg, 1167 instantiator, pointer_fg, pointer_bg,
1023 dest_mask, mask, mask_file); 1168 dest_mask, mask, mask_file);
1029 x_xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 1174 x_xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1030 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1175 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1031 int dest_mask, Lisp_Object domain) 1176 int dest_mask, Lisp_Object domain)
1032 { 1177 {
1033 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 1178 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1034 CONST char *gcc_go_home; 1179 const char *ext_data;
1035 1180
1036 assert (!NILP (data)); 1181 assert (!NILP (data));
1037 1182
1038 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))), 1183 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (data))),
1039 gcc_go_home); 1184 C_STRING_ALLOCA, ext_data,
1185 Qbinary);
1040 1186
1041 xbm_instantiate_1 (image_instance, instantiator, pointer_fg, 1187 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
1042 pointer_bg, dest_mask, XINT (XCAR (data)), 1188 pointer_bg, dest_mask, XINT (XCAR (data)),
1043 XINT (XCAR (XCDR (data))), gcc_go_home); 1189 XINT (XCAR (XCDR (data))), ext_data);
1044 } 1190 }
1045 1191
1046 1192
1047 #ifdef HAVE_XPM 1193 #ifdef HAVE_XPM
1048 1194
1142 XpmFreeAttributes (xpmattrs); 1288 XpmFreeAttributes (xpmattrs);
1143 } 1289 }
1144 1290
1145 static void 1291 static void
1146 x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 1292 x_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1147 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1293 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1148 int dest_mask, Lisp_Object domain) 1294 int dest_mask, Lisp_Object domain)
1149 { 1295 {
1150 /* This function can GC */ 1296 /* This function can GC */
1151 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 1297 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1152 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 1298 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1153 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 1299 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1154 Display *dpy; 1300 Display *dpy;
1155 Screen *xs; 1301 Screen *xs;
1156 Colormap cmap; 1302 Colormap cmap;
1204 cmap = DEVICE_X_COLORMAP (XDEVICE(device)); 1350 cmap = DEVICE_X_COLORMAP (XDEVICE(device));
1205 depth = DEVICE_X_DEPTH (XDEVICE(device)); 1351 depth = DEVICE_X_DEPTH (XDEVICE(device));
1206 visual = DEVICE_X_VISUAL (XDEVICE(device)); 1352 visual = DEVICE_X_VISUAL (XDEVICE(device));
1207 #endif 1353 #endif
1208 1354
1209 x_initialize_pixmap_image_instance (ii, type); 1355 x_initialize_pixmap_image_instance (ii, 1, type);
1210 1356
1211 assert (!NILP (data)); 1357 assert (!NILP (data));
1212 1358
1213 retry: 1359 retry:
1214 1360
1314 } 1460 }
1315 else 1461 else
1316 pixels = NULL; 1462 pixels = NULL;
1317 1463
1318 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap; 1464 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
1319 IMAGE_INSTANCE_X_MASK (ii) = mask; 1465 IMAGE_INSTANCE_PIXMAP_MASK (ii) = (void*)mask;
1320 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap; 1466 IMAGE_INSTANCE_X_COLORMAP (ii) = cmap;
1321 IMAGE_INSTANCE_X_PIXELS (ii) = pixels; 1467 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
1322 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels; 1468 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
1323 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w; 1469 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
1324 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h; 1470 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
1514 int dest_mask, Lisp_Object domain) 1660 int dest_mask, Lisp_Object domain)
1515 { 1661 {
1516 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 1662 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1517 int i, stattis; 1663 int i, stattis;
1518 char *p, *bits, *bp; 1664 char *p, *bits, *bp;
1519 CONST char * volatile emsg = 0; 1665 const char * volatile emsg = 0;
1520 CONST char * volatile dstring; 1666 const char * volatile dstring;
1521 1667
1522 assert (!NILP (data)); 1668 assert (!NILP (data));
1523 1669
1524 GET_C_STRING_BINARY_DATA_ALLOCA (data, dstring); 1670 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1671 C_STRING_ALLOCA, dstring,
1672 Qbinary);
1525 1673
1526 if ((p = strchr (dstring, ':'))) 1674 if ((p = strchr (dstring, ':')))
1527 { 1675 {
1528 dstring = p + 1; 1676 dstring = p + 1;
1529 } 1677 }
1583 data_must_be_present (instantiator); 1731 data_must_be_present (instantiator);
1584 } 1732 }
1585 1733
1586 static Lisp_Object 1734 static Lisp_Object
1587 autodetect_normalize (Lisp_Object instantiator, 1735 autodetect_normalize (Lisp_Object instantiator,
1588 Lisp_Object console_type) 1736 Lisp_Object console_type)
1589 { 1737 {
1590 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data); 1738 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
1591 Lisp_Object filename = Qnil; 1739 Lisp_Object filename = Qnil;
1592 Lisp_Object data = Qnil; 1740 Lisp_Object data = Qnil;
1593 struct gcpro gcpro1, gcpro2, gcpro3; 1741 struct gcpro gcpro1, gcpro2, gcpro3;
1674 IMAGE_TEXT_MASK; 1822 IMAGE_TEXT_MASK;
1675 } 1823 }
1676 1824
1677 static void 1825 static void
1678 autodetect_instantiate (Lisp_Object image_instance, 1826 autodetect_instantiate (Lisp_Object image_instance,
1679 Lisp_Object instantiator, 1827 Lisp_Object instantiator,
1680 Lisp_Object pointer_fg, 1828 Lisp_Object pointer_fg,
1681 Lisp_Object pointer_bg, 1829 Lisp_Object pointer_bg,
1682 int dest_mask, Lisp_Object domain) 1830 int dest_mask, Lisp_Object domain)
1683 { 1831 {
1684 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 1832 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1685 struct gcpro gcpro1, gcpro2, gcpro3; 1833 struct gcpro gcpro1, gcpro2, gcpro3;
1686 Lisp_Object alist = Qnil; 1834 Lisp_Object alist = Qnil;
1687 Lisp_Object result = Qnil; 1835 Lisp_Object result = Qnil;
1690 GCPRO3 (data, alist, result); 1838 GCPRO3 (data, alist, result);
1691 1839
1692 alist = tagged_vector_to_alist (instantiator); 1840 alist = tagged_vector_to_alist (instantiator);
1693 if (dest_mask & IMAGE_POINTER_MASK) 1841 if (dest_mask & IMAGE_POINTER_MASK)
1694 { 1842 {
1695 CONST char *name_ext; 1843 const char *name_ext;
1696 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext); 1844 TO_EXTERNAL_FORMAT (LISP_STRING, data,
1845 C_STRING_ALLOCA, name_ext,
1846 Qfile_name);
1697 if (XmuCursorNameToIndex (name_ext) != -1) 1847 if (XmuCursorNameToIndex (name_ext) != -1)
1698 { 1848 {
1699 result = alist_to_tagged_vector (Qcursor_font, alist); 1849 result = alist_to_tagged_vector (Qcursor_font, alist);
1700 is_cursor_font = 1; 1850 is_cursor_font = 1;
1701 } 1851 }
1778 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 1928 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1779 int dest_mask, Lisp_Object domain) 1929 int dest_mask, Lisp_Object domain)
1780 { 1930 {
1781 /* This function can GC */ 1931 /* This function can GC */
1782 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 1932 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1783 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 1933 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1784 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 1934 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1785 Display *dpy; 1935 Display *dpy;
1786 XColor fg, bg; 1936 XColor fg, bg;
1787 Font source, mask; 1937 Font source, mask;
1788 char source_name[MAXPATHLEN], mask_name[MAXPATHLEN], dummy; 1938 char source_name[MAXPATHLEN], mask_name[MAXPATHLEN], dummy;
1842 if (!mask) 1992 if (!mask)
1843 mask_char = 0; 1993 mask_char = 0;
1844 1994
1845 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */ 1995 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
1846 1996
1847 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER); 1997 x_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
1848 IMAGE_INSTANCE_X_CURSOR (ii) = 1998 IMAGE_INSTANCE_X_CURSOR (ii) =
1849 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char, 1999 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
1850 &fg, &bg); 2000 &fg, &bg);
1851 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground; 2001 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
1852 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background; 2002 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
1876 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 2026 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1877 int dest_mask, Lisp_Object domain) 2027 int dest_mask, Lisp_Object domain)
1878 { 2028 {
1879 /* This function can GC */ 2029 /* This function can GC */
1880 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data); 2030 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
1881 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 2031 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1882 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 2032 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1883 Display *dpy; 2033 Display *dpy;
1884 int i; 2034 int i;
1885 CONST char *name_ext; 2035 const char *name_ext;
1886 Lisp_Object foreground, background; 2036 Lisp_Object foreground, background;
1887 2037
1888 if (!DEVICE_X_P (XDEVICE (device))) 2038 if (!DEVICE_X_P (XDEVICE (device)))
1889 signal_simple_error ("Not an X device", device); 2039 signal_simple_error ("Not an X device", device);
1890 2040
1891 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 2041 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
1892 2042
1893 if (!(dest_mask & IMAGE_POINTER_MASK)) 2043 if (!(dest_mask & IMAGE_POINTER_MASK))
1894 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK); 2044 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
1895 2045
1896 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext); 2046 TO_EXTERNAL_FORMAT (LISP_STRING, data,
2047 C_STRING_ALLOCA, name_ext,
2048 Qfile_name);
1897 if ((i = XmuCursorNameToIndex (name_ext)) == -1) 2049 if ((i = XmuCursorNameToIndex (name_ext)) == -1)
1898 signal_simple_error ("Unrecognized cursor-font name", data); 2050 signal_simple_error ("Unrecognized cursor-font name", data);
1899 2051
1900 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER); 2052 x_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
1901 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i); 2053 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i);
1902 foreground = find_keyword_in_vector (instantiator, Q_foreground); 2054 foreground = find_keyword_in_vector (instantiator, Q_foreground);
1903 if (NILP (foreground)) 2055 if (NILP (foreground))
1904 foreground = pointer_fg; 2056 foreground = pointer_fg;
1905 background = find_keyword_in_vector (instantiator, Q_background); 2057 background = find_keyword_in_vector (instantiator, Q_background);
1910 2062
1911 static int 2063 static int
1912 x_colorize_image_instance (Lisp_Object image_instance, 2064 x_colorize_image_instance (Lisp_Object image_instance,
1913 Lisp_Object foreground, Lisp_Object background) 2065 Lisp_Object foreground, Lisp_Object background)
1914 { 2066 {
1915 struct Lisp_Image_Instance *p; 2067 Lisp_Image_Instance *p;
1916 2068
1917 p = XIMAGE_INSTANCE (image_instance); 2069 p = XIMAGE_INSTANCE (image_instance);
1918 2070
1919 switch (IMAGE_INSTANCE_TYPE (p)) 2071 switch (IMAGE_INSTANCE_TYPE (p))
1920 { 2072 {
1921 case IMAGE_MONO_PIXMAP: 2073 case IMAGE_MONO_PIXMAP:
1922 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP; 2074 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
1923 /* Make sure there aren't two pointers to the same mask, causing 2075 /* Make sure there aren't two pointers to the same mask, causing
1924 it to get freed twice. */ 2076 it to get freed twice. */
1925 IMAGE_INSTANCE_X_MASK (p) = 0; 2077 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
1926 break; 2078 break;
1927 2079
1928 default: 2080 default:
1929 return 0; 2081 return 0;
1930 } 2082 }
1963 /************************************************************************/ 2115 /************************************************************************/
1964 2116
1965 /* unmap the image if it is a widget. This is used by redisplay via 2117 /* unmap the image if it is a widget. This is used by redisplay via
1966 redisplay_unmap_subwindows */ 2118 redisplay_unmap_subwindows */
1967 static void 2119 static void
1968 x_unmap_subwindow (struct Lisp_Image_Instance *p) 2120 x_unmap_subwindow (Lisp_Image_Instance *p)
1969 { 2121 {
1970 XUnmapWindow (DisplayOfScreen (IMAGE_INSTANCE_X_SUBWINDOW_SCREEN (p)), 2122 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
1971 IMAGE_INSTANCE_X_SUBWINDOW_ID (p)); 2123 {
2124 XUnmapWindow
2125 (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
2126 IMAGE_INSTANCE_X_CLIPWINDOW (p));
2127 }
2128 else /* must be a widget */
2129 {
2130 XtUnmapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
2131 }
1972 } 2132 }
1973 2133
1974 /* map the subwindow. This is used by redisplay via 2134 /* map the subwindow. This is used by redisplay via
1975 redisplay_output_subwindow */ 2135 redisplay_output_subwindow */
1976 static void 2136 static void
1977 x_map_subwindow (struct Lisp_Image_Instance *p, int x, int y) 2137 x_map_subwindow (Lisp_Image_Instance *p, int x, int y,
1978 { 2138 struct display_glyph_area* dga)
1979 XMapWindow (DisplayOfScreen (IMAGE_INSTANCE_X_SUBWINDOW_SCREEN (p)), 2139 {
1980 IMAGE_INSTANCE_X_SUBWINDOW_ID (p)); 2140 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
1981 XMoveWindow (DisplayOfScreen (IMAGE_INSTANCE_X_SUBWINDOW_SCREEN (p)), 2141 {
1982 IMAGE_INSTANCE_X_SUBWINDOW_ID (p), x, y); 2142 Window subwindow = IMAGE_INSTANCE_X_SUBWINDOW_ID (p);
2143 XMoveResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
2144 IMAGE_INSTANCE_X_CLIPWINDOW (p),
2145 x, y, dga->width, dga->height);
2146 XMoveWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
2147 subwindow, -dga->xoffset, -dga->yoffset);
2148 XMapWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
2149 IMAGE_INSTANCE_X_CLIPWINDOW (p));
2150 }
2151 else /* must be a widget */
2152 {
2153 XtConfigureWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p),
2154 x + IMAGE_INSTANCE_X_WIDGET_XOFFSET (p),
2155 y + IMAGE_INSTANCE_X_WIDGET_YOFFSET (p),
2156 dga->width, dga->height, 0);
2157 XtMoveWidget (IMAGE_INSTANCE_X_WIDGET_ID (p),
2158 -dga->xoffset, -dga->yoffset);
2159 XtMapWidget (IMAGE_INSTANCE_X_CLIPWIDGET (p));
2160 }
2161 }
2162
2163 /* when you click on a widget you may activate another widget this
2164 needs to be checked and all appropriate widgets updated */
2165 static void
2166 x_update_subwindow (Lisp_Image_Instance *p)
2167 {
2168 /* Update the subwindow size if necessary. */
2169 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
2170 {
2171 XResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
2172 IMAGE_INSTANCE_X_SUBWINDOW_ID (p),
2173 IMAGE_INSTANCE_WIDTH (p),
2174 IMAGE_INSTANCE_HEIGHT (p));
2175 }
2176 }
2177
2178 /* Update all attributes that have changed. Lwlib actually does most
2179 of this for us. */
2180 static void
2181 x_update_widget (Lisp_Image_Instance *p)
2182 {
2183 #ifdef HAVE_WIDGETS
2184 widget_value* wv = 0;
2185 Boolean deep_p = False;
2186 /* Possibly update the size. */
2187 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
2188 {
2189 Arg al[2];
2190
2191 assert (IMAGE_INSTANCE_X_WIDGET_ID (p) &&
2192 IMAGE_INSTANCE_X_CLIPWIDGET (p)) ;
2193
2194 if ( !XtIsManaged(IMAGE_INSTANCE_X_WIDGET_ID (p))
2195 ||
2196 IMAGE_INSTANCE_X_WIDGET_ID (p)->core.being_destroyed )
2197 {
2198 Lisp_Object sw;
2199 XSETIMAGE_INSTANCE (sw, p);
2200 signal_simple_error ("XEmacs bug: subwindow is deleted", sw);
2201 }
2202
2203 XtSetArg (al [0], XtNwidth, (Dimension)IMAGE_INSTANCE_WIDTH (p));
2204 XtSetArg (al [1], XtNheight, (Dimension)IMAGE_INSTANCE_HEIGHT (p));
2205 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (p), al, 2);
2206 }
2207
2208 /* First get the items if they have changed since this is a structural change. */
2209 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
2210 {
2211 wv = gui_items_to_widget_values
2212 (IMAGE_INSTANCE_WIDGET_ITEMS (p));
2213 deep_p = True;
2214 }
2215
2216 /* Possibly update the colors and font */
2217 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p))
2218 {
2219 update_widget_face (wv, p, IMAGE_INSTANCE_SUBWINDOW_FRAME (p));
2220 }
2221
2222 /* Possibly update the text. */
2223 if (IMAGE_INSTANCE_TEXT_CHANGED (p))
2224 {
2225 char* str;
2226 Lisp_Object val = IMAGE_INSTANCE_WIDGET_TEXT (p);
2227 TO_EXTERNAL_FORMAT (LISP_STRING, val,
2228 C_STRING_ALLOCA, str,
2229 Qnative);
2230 wv->value = str;
2231 }
2232
2233 /* now modify the widget */
2234 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (p),
2235 wv, deep_p);
2236 free_widget_value_tree (wv);
2237 #endif
1983 } 2238 }
1984 2239
1985 /* instantiate and x type subwindow */ 2240 /* instantiate and x type subwindow */
1986 static void 2241 static void
1987 x_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 2242 x_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1988 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 2243 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1989 int dest_mask, Lisp_Object domain) 2244 int dest_mask, Lisp_Object domain)
1990 { 2245 {
1991 /* This function can GC */ 2246 /* This function can GC */
1992 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 2247 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1993 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); 2248 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1994 Lisp_Object frame = FW_FRAME (domain); 2249 Lisp_Object frame = FW_FRAME (domain);
1995 struct frame* f = XFRAME (frame); 2250 struct frame* f = XFRAME (frame);
1996 Display *dpy; 2251 Display *dpy;
1997 Screen *xs; 2252 Screen *xs;
1998 Window pw, win; 2253 Window pw, win;
1999 XSetWindowAttributes xswa; 2254 XSetWindowAttributes xswa;
2000 Mask valueMask = 0; 2255 Mask valueMask = 0;
2001 unsigned int w = IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii), 2256 unsigned int w = IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii),
2002 h = IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii); 2257 h = IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii);
2003 2258
2004 if (!DEVICE_X_P (XDEVICE (device))) 2259 if (!DEVICE_X_P (XDEVICE (device)))
2005 signal_simple_error ("Not an X device", device); 2260 signal_simple_error ("Not an X device", device);
2006 2261
2007 dpy = DEVICE_X_DISPLAY (XDEVICE (device)); 2262 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
2008 xs = DefaultScreenOfDisplay (dpy); 2263 xs = DefaultScreenOfDisplay (dpy);
2009 2264
2010 if (dest_mask & IMAGE_SUBWINDOW_MASK) 2265 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
2011 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
2012 else
2013 incompatible_image_types (instantiator, dest_mask,
2014 IMAGE_SUBWINDOW_MASK);
2015 2266
2016 pw = XtWindow (FRAME_X_TEXT_WIDGET (f)); 2267 pw = XtWindow (FRAME_X_TEXT_WIDGET (f));
2017 2268
2018 ii->data = xnew_and_zero (struct x_subwindow_data); 2269 ii->data = xnew_and_zero (struct x_subwindow_data);
2019 2270
2020 IMAGE_INSTANCE_X_SUBWINDOW_PARENT (ii) = pw; 2271 IMAGE_INSTANCE_X_SUBWINDOW_PARENT (ii) = pw;
2021 IMAGE_INSTANCE_X_SUBWINDOW_SCREEN (ii) = xs; 2272 IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (ii) = DisplayOfScreen (xs);
2022 2273
2023 xswa.backing_store = Always; 2274 xswa.backing_store = Always;
2024 valueMask |= CWBackingStore; 2275 valueMask |= CWBackingStore;
2025 xswa.colormap = DefaultColormapOfScreen (xs); 2276 xswa.colormap = DefaultColormapOfScreen (xs);
2026 valueMask |= CWColormap; 2277 valueMask |= CWColormap;
2027 2278
2028 win = XCreateWindow (dpy, pw, 0, 0, w, h, 0, CopyFromParent, 2279 /* Create a window for clipping */
2280 IMAGE_INSTANCE_X_CLIPWINDOW (ii) =
2281 XCreateWindow (dpy, pw, 0, 0, w, h, 0, CopyFromParent,
2282 InputOutput, CopyFromParent, valueMask,
2283 &xswa);
2284
2285 /* Now put the subwindow inside the clip window. */
2286 win = XCreateWindow (dpy, IMAGE_INSTANCE_X_CLIPWINDOW (ii),
2287 0, 0, w, h, 0, CopyFromParent,
2029 InputOutput, CopyFromParent, valueMask, 2288 InputOutput, CopyFromParent, valueMask,
2030 &xswa); 2289 &xswa);
2031 2290
2032 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)win; 2291 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)win;
2033 } 2292 }
2034 2293
2035 #if 0 2294 #if 0
2036 /* #### Should this function exist? If there's any doubt I'm not implementing it --andyp */ 2295 /* #### Should this function exist? If there's any doubt I'm not implementing it --andyp */
2039 Subwindows are not currently implemented. 2298 Subwindows are not currently implemented.
2040 */ 2299 */
2041 (subwindow, property, data)) 2300 (subwindow, property, data))
2042 { 2301 {
2043 Atom property_atom; 2302 Atom property_atom;
2044 struct Lisp_Subwindow *sw; 2303 Lisp_Subwindow *sw;
2045 Display *dpy; 2304 Display *dpy;
2046 2305
2047 CHECK_SUBWINDOW (subwindow); 2306 CHECK_SUBWINDOW (subwindow);
2048 CHECK_STRING (property); 2307 CHECK_STRING (property);
2049 CHECK_STRING (data); 2308 CHECK_STRING (data);
2060 2319
2061 return property; 2320 return property;
2062 } 2321 }
2063 #endif 2322 #endif
2064 2323
2065 static void 2324
2066 x_resize_subwindow (struct Lisp_Image_Instance* ii, int w, int h) 2325 #ifdef HAVE_WIDGETS
2067 { 2326
2068 XResizeWindow (DisplayOfScreen (IMAGE_INSTANCE_X_SUBWINDOW_SCREEN (ii)), 2327 /************************************************************************/
2069 IMAGE_INSTANCE_X_SUBWINDOW_ID (ii), 2328 /* widgets */
2070 w, h); 2329 /************************************************************************/
2071 } 2330
2331 static void
2332 update_widget_face (widget_value* wv, Lisp_Image_Instance *ii,
2333 Lisp_Object domain)
2334 {
2335 #ifdef LWLIB_WIDGETS_MOTIF
2336 XmFontList fontList;
2337 #endif
2338 /* Update the foreground. */
2339 Lisp_Object pixel = FACE_FOREGROUND
2340 (IMAGE_INSTANCE_WIDGET_FACE (ii),
2341 domain);
2342 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel)), bcolor;
2343 lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
2344
2345 /* Update the background. */
2346 pixel = FACE_BACKGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii),
2347 domain);
2348 bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
2349 lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
2350
2351 #ifdef LWLIB_WIDGETS_MOTIF
2352 fontList = XmFontListCreate
2353 (FONT_INSTANCE_X_FONT
2354 (XFONT_INSTANCE (query_string_font
2355 (IMAGE_INSTANCE_WIDGET_TEXT (ii),
2356 IMAGE_INSTANCE_WIDGET_FACE (ii),
2357 domain))), XmSTRING_DEFAULT_CHARSET);
2358 lw_add_widget_value_arg (wv, XmNfontList, (XtArgVal)fontList);
2359 #endif
2360 lw_add_widget_value_arg
2361 (wv, XtNfont, (XtArgVal)FONT_INSTANCE_X_FONT
2362 (XFONT_INSTANCE (query_string_font
2363 (IMAGE_INSTANCE_WIDGET_TEXT (ii),
2364 IMAGE_INSTANCE_WIDGET_FACE (ii),
2365 domain))));
2366 }
2367
2368 static void
2369 update_tab_widget_face (widget_value* wv, Lisp_Image_Instance *ii,
2370 Lisp_Object domain)
2371 {
2372 if (wv->contents)
2373 {
2374 widget_value* val = wv->contents, *cur;
2375
2376 /* Give each child label the correct foreground color. */
2377 Lisp_Object pixel = FACE_FOREGROUND
2378 (IMAGE_INSTANCE_WIDGET_FACE (ii),
2379 domain);
2380 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
2381 lw_add_widget_value_arg (val, XtNtabForeground, fcolor.pixel);
2382
2383 for (cur = val->next; cur; cur = cur->next)
2384 {
2385 if (cur->value)
2386 {
2387 lw_copy_widget_value_args (val, cur);
2388 }
2389 }
2390 }
2391 }
2392
2393 static void
2394 x_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2395 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2396 int dest_mask, Lisp_Object domain,
2397 const char* type, widget_value* wv)
2398 {
2399 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2400 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), pixel;
2401 struct device* d = XDEVICE (device);
2402 Lisp_Object frame = FW_FRAME (domain);
2403 struct frame* f = XFRAME (frame);
2404 char* nm=0;
2405 Widget wid;
2406 Arg al [32];
2407 int ac = 0;
2408 int id = new_lwlib_id ();
2409 widget_value* clip_wv;
2410 XColor fcolor, bcolor;
2411
2412 if (!DEVICE_X_P (d))
2413 signal_simple_error ("Not an X device", device);
2414
2415 /* have to set the type this late in case there is no device
2416 instantiation for a widget. But we can go ahead and do it without
2417 checking because there is always a generic instantiator. */
2418 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
2419
2420 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
2421 TO_EXTERNAL_FORMAT (LISP_STRING, IMAGE_INSTANCE_WIDGET_TEXT (ii),
2422 C_STRING_ALLOCA, nm,
2423 Qnative);
2424
2425 ii->data = xnew_and_zero (struct x_subwindow_data);
2426
2427 /* Create a clip window to contain the subwidget. Incredibly the
2428 XEmacs manager seems to be the most appropriate widget for
2429 this. Nothing else is simple enough and yet does what is
2430 required. */
2431 clip_wv = xmalloc_widget_value ();
2432
2433 lw_add_widget_value_arg (clip_wv, XtNresize, False);
2434 lw_add_widget_value_arg (clip_wv, XtNwidth,
2435 (Dimension)IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii));
2436 lw_add_widget_value_arg (clip_wv, XtNheight,
2437 (Dimension)IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii));
2438 clip_wv->enabled = True;
2439
2440 clip_wv->name = xstrdup ("clip-window");
2441 clip_wv->value = xstrdup ("clip-window");
2442
2443 IMAGE_INSTANCE_X_CLIPWIDGET (ii)
2444 = lw_create_widget ("clip-window", "clip-window", new_lwlib_id (),
2445 clip_wv, FRAME_X_CONTAINER_WIDGET (f),
2446 False, 0, 0, 0);
2447
2448 free_widget_value_tree (clip_wv);
2449
2450 /* copy any args we were given */
2451 ac = 0;
2452 lw_add_value_args_to_args (wv, al, &ac);
2453
2454 /* Fixup the colors. We have to do this *before* the widget gets
2455 created so that Motif will fix up the shadow colors
2456 correctly. Once the widget is created Motif won't do this
2457 anymore...*/
2458 pixel = FACE_FOREGROUND
2459 (IMAGE_INSTANCE_WIDGET_FACE (ii),
2460 IMAGE_INSTANCE_SUBWINDOW_FRAME (ii));
2461 fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
2462
2463 pixel = FACE_BACKGROUND
2464 (IMAGE_INSTANCE_WIDGET_FACE (ii),
2465 IMAGE_INSTANCE_SUBWINDOW_FRAME (ii));
2466 bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
2467
2468 lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
2469 lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
2470 /* we cannot allow widgets to resize themselves */
2471 lw_add_widget_value_arg (wv, XtNresize, False);
2472 lw_add_widget_value_arg (wv, XtNwidth,
2473 (Dimension)IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii));
2474 lw_add_widget_value_arg (wv, XtNheight,
2475 (Dimension)IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii));
2476 /* update the font. */
2477 update_widget_face (wv, ii, domain);
2478
2479 wid = lw_create_widget (type, wv->name, id, wv, IMAGE_INSTANCE_X_CLIPWIDGET (ii),
2480 False, 0, popup_selection_callback, 0);
2481
2482 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)wid;
2483 IMAGE_INSTANCE_X_WIDGET_LWID (ii) = id;
2484
2485 /* Resize the widget here so that the values do not get copied by
2486 lwlib. */
2487 ac = 0;
2488 XtSetArg (al [ac], XtNwidth,
2489 (Dimension)IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii)); ac++;
2490 XtSetArg (al [ac], XtNheight,
2491 (Dimension)IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii)); ac++;
2492 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, ac);
2493 /* because the EmacsManager is the widgets parent we have to
2494 offset the redisplay of the widget by the amount the text
2495 widget is inside the manager. */
2496 ac = 0;
2497 XtSetArg (al [ac], XtNx, &IMAGE_INSTANCE_X_WIDGET_XOFFSET (ii)); ac++;
2498 XtSetArg (al [ac], XtNy, &IMAGE_INSTANCE_X_WIDGET_YOFFSET (ii)); ac++;
2499 XtGetValues (FRAME_X_TEXT_WIDGET (f), al, ac);
2500
2501 XtSetMappedWhenManaged (wid, TRUE);
2502
2503 free_widget_value_tree (wv);
2504 }
2505
2506 /* get properties of a control */
2507 static Lisp_Object
2508 x_widget_property (Lisp_Object image_instance, Lisp_Object prop)
2509 {
2510 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2511 /* get the text from a control */
2512 if (EQ (prop, Q_text))
2513 {
2514 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
2515 return build_ext_string (wv->value, Qnative);
2516 }
2517 return Qunbound;
2518 }
2519
2520 /* Instantiate a button widget. Unfortunately instantiated widgets are
2521 particular to a frame since they need to have a parent. It's not
2522 like images where you just select the image into the context you
2523 want to display it in and BitBlt it. So images instances can have a
2524 many-to-one relationship with things you see, whereas widgets can
2525 only be one-to-one (i.e. per frame) */
2526 static void
2527 x_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2528 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2529 int dest_mask, Lisp_Object domain)
2530 {
2531 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2532 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
2533 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
2534 widget_value* wv = xmalloc_widget_value ();
2535
2536 button_item_to_widget_value (gui, wv, 1, 1);
2537
2538 if (!NILP (glyph))
2539 {
2540 if (!IMAGE_INSTANCEP (glyph))
2541 glyph = glyph_image_instance (glyph, domain, ERROR_ME, 1);
2542 }
2543
2544 x_widget_instantiate (image_instance, instantiator, pointer_fg,
2545 pointer_bg, dest_mask, domain, "button", wv);
2546
2547 /* add the image if one was given */
2548 if (!NILP (glyph) && IMAGE_INSTANCEP (glyph)
2549 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (glyph)))
2550 {
2551 Arg al [2];
2552 int ac =0;
2553 #ifdef LWLIB_WIDGETS_MOTIF
2554 XtSetArg (al [ac], XmNlabelType, XmPIXMAP); ac++;
2555 XtSetArg (al [ac], XmNlabelPixmap, XIMAGE_INSTANCE_X_PIXMAP (glyph));ac++;
2556 #else
2557 XtSetArg (al [ac], XtNpixmap, XIMAGE_INSTANCE_X_PIXMAP (glyph)); ac++;
2558 #endif
2559 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, ac);
2560 }
2561 }
2562
2563 /* get properties of a button */
2564 static Lisp_Object
2565 x_button_property (Lisp_Object image_instance, Lisp_Object prop)
2566 {
2567 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2568 /* check the state of a button */
2569 if (EQ (prop, Q_selected))
2570 {
2571 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
2572
2573 if (wv->selected)
2574 return Qt;
2575 else
2576 return Qnil;
2577 }
2578 return Qunbound;
2579 }
2580
2581 /* instantiate a progress gauge */
2582 static void
2583 x_progress_gauge_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2584 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2585 int dest_mask, Lisp_Object domain)
2586 {
2587 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2588 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
2589 widget_value* wv = xmalloc_widget_value ();
2590
2591 button_item_to_widget_value (gui, wv, 1, 1);
2592
2593 x_widget_instantiate (image_instance, instantiator, pointer_fg,
2594 pointer_bg, dest_mask, domain, "progress", wv);
2595 }
2596
2597 /* set the properties of a progres guage */
2598 static void
2599 x_progress_gauge_update (Lisp_Object image_instance)
2600 {
2601 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2602
2603 if (IMAGE_INSTANCE_WIDGET_PERCENT_CHANGED (ii))
2604 {
2605 Arg al [1];
2606 /* #### I'm not convinced we should store this in the plist. */
2607 Lisp_Object val = Fplist_get (IMAGE_INSTANCE_WIDGET_PROPS (ii),
2608 Q_percent, Qnil);
2609 XtSetArg (al[0], XtNvalue, XINT (val));
2610 XtSetValues (IMAGE_INSTANCE_X_WIDGET_ID (ii), al, 1);
2611 }
2612 }
2613
2614 /* instantiate an edit control */
2615 static void
2616 x_edit_field_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2617 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2618 int dest_mask, Lisp_Object domain)
2619 {
2620 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2621 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
2622 widget_value* wv = xmalloc_widget_value ();
2623
2624 button_item_to_widget_value (gui, wv, 1, 1);
2625
2626 x_widget_instantiate (image_instance, instantiator, pointer_fg,
2627 pointer_bg, dest_mask, domain, "text-field", wv);
2628 }
2629
2630 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
2631 /* instantiate a combo control */
2632 static void
2633 x_combo_box_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2634 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2635 int dest_mask, Lisp_Object domain)
2636 {
2637 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2638 widget_value * wv = 0;
2639 /* This is not done generically because of sizing problems under
2640 mswindows. */
2641 widget_instantiate (image_instance, instantiator, pointer_fg,
2642 pointer_bg, dest_mask, domain);
2643
2644 wv = gui_items_to_widget_values (IMAGE_INSTANCE_WIDGET_ITEMS (ii));
2645
2646 x_widget_instantiate (image_instance, instantiator, pointer_fg,
2647 pointer_bg, dest_mask, domain, "combo-box", wv);
2648 }
2649 #endif
2650
2651 static void
2652 x_tab_control_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2653 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2654 int dest_mask, Lisp_Object domain)
2655 {
2656 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2657 widget_value * wv =
2658 gui_items_to_widget_values (IMAGE_INSTANCE_WIDGET_ITEMS (ii));
2659
2660 update_tab_widget_face (wv, ii,
2661 IMAGE_INSTANCE_SUBWINDOW_FRAME (ii));
2662
2663 x_widget_instantiate (image_instance, instantiator, pointer_fg,
2664 pointer_bg, dest_mask, domain, "tab-control", wv);
2665 }
2666
2667 /* set the properties of a tab control */
2668 static void
2669 x_tab_control_update (Lisp_Object image_instance)
2670 {
2671 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2672
2673 /* Possibly update the face. */
2674 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (ii))
2675 {
2676 widget_value* wv = lw_get_all_values (IMAGE_INSTANCE_X_WIDGET_LWID (ii));
2677 update_tab_widget_face (wv, ii,
2678 IMAGE_INSTANCE_SUBWINDOW_FRAME (ii));
2679
2680 lw_modify_all_widgets (IMAGE_INSTANCE_X_WIDGET_LWID (ii), wv, True);
2681 free_widget_value_tree (wv);
2682 }
2683 }
2684
2685 /* instantiate a static control possible for putting other things in */
2686 static void
2687 x_label_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 {
2691 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2692 Lisp_Object gui = IMAGE_INSTANCE_WIDGET_ITEM (ii);
2693 widget_value* wv = xmalloc_widget_value ();
2694
2695 button_item_to_widget_value (gui, wv, 1, 1);
2696
2697 x_widget_instantiate (image_instance, instantiator, pointer_fg,
2698 pointer_bg, dest_mask, domain, "button", wv);
2699 }
2700 #endif /* HAVE_WIDGETS */
2072 2701
2073 2702
2074 /************************************************************************/ 2703 /************************************************************************/
2075 /* initialization */ 2704 /* initialization */
2076 /************************************************************************/ 2705 /************************************************************************/
2095 CONSOLE_HAS_METHOD (x, colorize_image_instance); 2724 CONSOLE_HAS_METHOD (x, colorize_image_instance);
2096 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage); 2725 CONSOLE_HAS_METHOD (x, init_image_instance_from_eimage);
2097 CONSOLE_HAS_METHOD (x, locate_pixmap_file); 2726 CONSOLE_HAS_METHOD (x, locate_pixmap_file);
2098 CONSOLE_HAS_METHOD (x, unmap_subwindow); 2727 CONSOLE_HAS_METHOD (x, unmap_subwindow);
2099 CONSOLE_HAS_METHOD (x, map_subwindow); 2728 CONSOLE_HAS_METHOD (x, map_subwindow);
2100 CONSOLE_HAS_METHOD (x, resize_subwindow); 2729 CONSOLE_HAS_METHOD (x, update_widget);
2730 CONSOLE_HAS_METHOD (x, update_subwindow);
2101 } 2731 }
2102 2732
2103 void 2733 void
2104 image_instantiator_format_create_glyphs_x (void) 2734 image_instantiator_format_create_glyphs_x (void)
2105 { 2735 {
2736 IIFORMAT_VALID_CONSOLE (x, nothing);
2737 IIFORMAT_VALID_CONSOLE (x, string);
2738 IIFORMAT_VALID_CONSOLE (x, layout);
2739 IIFORMAT_VALID_CONSOLE (x, formatted_string);
2740 IIFORMAT_VALID_CONSOLE (x, inherit);
2106 #ifdef HAVE_XPM 2741 #ifdef HAVE_XPM
2107 INITIALIZE_DEVICE_IIFORMAT (x, xpm); 2742 INITIALIZE_DEVICE_IIFORMAT (x, xpm);
2108 IIFORMAT_HAS_DEVMETHOD (x, xpm, instantiate); 2743 IIFORMAT_HAS_DEVMETHOD (x, xpm, instantiate);
2109 #endif 2744 #endif
2745 #ifdef HAVE_JPEG
2746 IIFORMAT_VALID_CONSOLE (x, jpeg);
2747 #endif
2748 #ifdef HAVE_TIFF
2749 IIFORMAT_VALID_CONSOLE (x, tiff);
2750 #endif
2751 #ifdef HAVE_PNG
2752 IIFORMAT_VALID_CONSOLE (x, png);
2753 #endif
2754 #ifdef HAVE_GIF
2755 IIFORMAT_VALID_CONSOLE (x, gif);
2756 #endif
2110 INITIALIZE_DEVICE_IIFORMAT (x, xbm); 2757 INITIALIZE_DEVICE_IIFORMAT (x, xbm);
2111 IIFORMAT_HAS_DEVMETHOD (x, xbm, instantiate); 2758 IIFORMAT_HAS_DEVMETHOD (x, xbm, instantiate);
2112 2759
2113 INITIALIZE_DEVICE_IIFORMAT (x, subwindow); 2760 INITIALIZE_DEVICE_IIFORMAT (x, subwindow);
2114 IIFORMAT_HAS_DEVMETHOD (x, subwindow, instantiate); 2761 IIFORMAT_HAS_DEVMETHOD (x, subwindow, instantiate);
2115 2762 #ifdef HAVE_WIDGETS
2763 /* button widget */
2764 INITIALIZE_DEVICE_IIFORMAT (x, button);
2765 IIFORMAT_HAS_DEVMETHOD (x, button, property);
2766 IIFORMAT_HAS_DEVMETHOD (x, button, instantiate);
2767
2768 INITIALIZE_DEVICE_IIFORMAT (x, widget);
2769 IIFORMAT_HAS_DEVMETHOD (x, widget, property);
2770 /* progress gauge */
2771 INITIALIZE_DEVICE_IIFORMAT (x, progress_gauge);
2772 IIFORMAT_HAS_DEVMETHOD (x, progress_gauge, update);
2773 IIFORMAT_HAS_DEVMETHOD (x, progress_gauge, instantiate);
2774 /* text field */
2775 INITIALIZE_DEVICE_IIFORMAT (x, edit_field);
2776 IIFORMAT_HAS_DEVMETHOD (x, edit_field, instantiate);
2777 #if defined (LWLIB_WIDGETS_MOTIF) && XmVERSION > 1
2778 /* combo box */
2779 INITIALIZE_DEVICE_IIFORMAT (x, combo_box);
2780 IIFORMAT_HAS_DEVMETHOD (x, combo_box, instantiate);
2781 IIFORMAT_HAS_SHARED_DEVMETHOD (x, combo_box, update, tab_control);
2782 #endif
2783 /* tab control widget */
2784 INITIALIZE_DEVICE_IIFORMAT (x, tab_control);
2785 IIFORMAT_HAS_DEVMETHOD (x, tab_control, instantiate);
2786 IIFORMAT_HAS_DEVMETHOD (x, tab_control, update);
2787 /* label */
2788 INITIALIZE_DEVICE_IIFORMAT (x, label);
2789 IIFORMAT_HAS_DEVMETHOD (x, label, instantiate);
2790 #endif
2116 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font"); 2791 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
2792 IIFORMAT_VALID_CONSOLE (x, cursor_font);
2117 2793
2118 IIFORMAT_HAS_METHOD (cursor_font, validate); 2794 IIFORMAT_HAS_METHOD (cursor_font, validate);
2119 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types); 2795 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
2120 IIFORMAT_HAS_METHOD (cursor_font, instantiate); 2796 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
2121 2797
2126 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font"); 2802 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
2127 2803
2128 IIFORMAT_HAS_METHOD (font, validate); 2804 IIFORMAT_HAS_METHOD (font, validate);
2129 IIFORMAT_HAS_METHOD (font, possible_dest_types); 2805 IIFORMAT_HAS_METHOD (font, possible_dest_types);
2130 IIFORMAT_HAS_METHOD (font, instantiate); 2806 IIFORMAT_HAS_METHOD (font, instantiate);
2807 IIFORMAT_VALID_CONSOLE (x, font);
2131 2808
2132 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string); 2809 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
2133 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string); 2810 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
2134 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string); 2811 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
2135 2812
2143 2820
2144 IIFORMAT_HAS_METHOD (autodetect, validate); 2821 IIFORMAT_HAS_METHOD (autodetect, validate);
2145 IIFORMAT_HAS_METHOD (autodetect, normalize); 2822 IIFORMAT_HAS_METHOD (autodetect, normalize);
2146 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types); 2823 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
2147 IIFORMAT_HAS_METHOD (autodetect, instantiate); 2824 IIFORMAT_HAS_METHOD (autodetect, instantiate);
2825 IIFORMAT_VALID_CONSOLE (x, autodetect);
2148 2826
2149 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string); 2827 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
2150 } 2828 }
2151 2829
2152 void 2830 void
2170 vector3 (Qxbm, Q_data, \ 2848 vector3 (Qxbm, Q_data, \
2171 list3 (make_int (name##_width), \ 2849 list3 (make_int (name##_width), \
2172 make_int (name##_height), \ 2850 make_int (name##_height), \
2173 make_ext_string (name##_bits, \ 2851 make_ext_string (name##_bits, \
2174 sizeof (name##_bits), \ 2852 sizeof (name##_bits), \
2175 FORMAT_BINARY))), \ 2853 Qbinary))), \
2176 Qglobal, Qx, Qnil) 2854 Qglobal, Qx, Qnil)
2177 2855
2178 BUILD_GLYPH_INST (Vtruncation_glyph, truncator); 2856 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
2179 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer); 2857 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
2180 BUILD_GLYPH_INST (Vxemacs_logo, xemacs); 2858 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);