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