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