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