0
|
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
|
|
7
|
|
8 This file is part of XEmacs.
|
|
9
|
|
10 XEmacs is free software; you can redistribute it and/or modify it
|
|
11 under the terms of the GNU General Public License as published by the
|
|
12 Free Software Foundation; either version 2, or (at your option) any
|
|
13 later version.
|
|
14
|
|
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
18 for more details.
|
|
19
|
|
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
|
|
27 /* Original author: Jamie Zawinski for 19.8
|
|
28 font-truename stuff added by Jamie Zawinski for 19.10
|
|
29 subwindow support added by Chuck Thompson
|
|
30 additional XPM support added by Chuck Thompson
|
|
31 initial X-Face support added by Stig
|
185
|
32 rewritten/restructured by Ben Wing for 19.12/19.13
|
0
|
33 GIF/JPEG support added by Ben Wing for 19.14
|
|
34 PNG support added by Bill Perry for 19.14
|
|
35 Improved GIF/JPEG support added by Bill Perry for 19.14
|
|
36 Cleanup/simplification of error handling by Ben Wing for 19.14
|
|
37 Pointer/icon overhaul, more restructuring by Ben Wing for 19.14
|
|
38
|
|
39 TODO:
|
207
|
40 ImageMagick support
|
0
|
41 Convert images.el to C and stick it in here?
|
|
42 */
|
|
43
|
|
44 #include <config.h>
|
|
45 #include "lisp.h"
|
|
46
|
|
47 #include "console-x.h"
|
|
48 #include "glyphs-x.h"
|
|
49 #include "objects-x.h"
|
|
50 #include "xmu.h"
|
|
51
|
|
52 #include "buffer.h"
|
|
53 #include "frame.h"
|
|
54 #include "insdel.h"
|
|
55 #include "opaque.h"
|
|
56
|
|
57 #include "sysfile.h"
|
|
58
|
207
|
59 #ifdef HAVE_IMAGEMAGICK
|
|
60 #define HAVE_X11_MAGICK_IMAGE_H
|
|
61 #endif /* HAVE_IMAGEMAGICK */
|
|
62
|
|
63 #ifdef HAVE_X11_MAGICK_IMAGE_H
|
|
64 #include <magick.h>
|
|
65 /* #include <image.h> */
|
|
66 #include <assert.h>
|
138
|
67 #endif
|
0
|
68
|
|
69 #define LISP_DEVICE_TO_X_SCREEN(dev) \
|
|
70 XDefaultScreenOfDisplay (DEVICE_X_DISPLAY (XDEVICE (dev)))
|
|
71
|
|
72 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xbm);
|
|
73 Lisp_Object Qxbm;
|
|
74
|
|
75 Lisp_Object Q_mask_file, Q_mask_data, Q_hotspot_x, Q_hotspot_y;
|
|
76 Lisp_Object Q_foreground, Q_background;
|
|
77
|
|
78 #ifdef HAVE_XPM
|
|
79 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xpm);
|
|
80 Lisp_Object Qxpm;
|
|
81 Lisp_Object Q_color_symbols;
|
|
82 #endif
|
|
83
|
|
84 #ifdef HAVE_XFACE
|
|
85 DEFINE_IMAGE_INSTANTIATOR_FORMAT (xface);
|
|
86 Lisp_Object Qxface;
|
|
87 #endif
|
|
88
|
207
|
89 #ifdef HAVE_IMAGEMAGICK
|
|
90 DEFINE_IMAGE_INSTANTIATOR_FORMAT (imagick);
|
|
91 Lisp_Object Qimagick;
|
0
|
92 #endif
|
|
93
|
|
94 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor_font);
|
|
95 Lisp_Object Qcursor_font;
|
|
96
|
|
97 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font);
|
|
98
|
122
|
99 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect);
|
0
|
100
|
|
101 static void cursor_font_instantiate (Lisp_Object image_instance,
|
|
102 Lisp_Object instantiator,
|
|
103 Lisp_Object pointer_fg,
|
|
104 Lisp_Object pointer_bg,
|
124
|
105 int dest_mask,
|
|
106 Lisp_Object domain);
|
0
|
107
|
|
108 #include "bitmaps.h"
|
|
109
|
|
110
|
|
111 /************************************************************************/
|
|
112 /* image instance methods */
|
|
113 /************************************************************************/
|
|
114
|
|
115 static void
|
|
116 x_print_image_instance (struct Lisp_Image_Instance *p,
|
|
117 Lisp_Object printcharfun,
|
|
118 int escapeflag)
|
|
119 {
|
|
120 char buf[100];
|
|
121
|
|
122 switch (IMAGE_INSTANCE_TYPE (p))
|
|
123 {
|
|
124 case IMAGE_MONO_PIXMAP:
|
|
125 case IMAGE_COLOR_PIXMAP:
|
|
126 case IMAGE_POINTER:
|
|
127 sprintf (buf, " (0x%lx", (unsigned long) IMAGE_INSTANCE_X_PIXMAP (p));
|
|
128 write_c_string (buf, printcharfun);
|
|
129 if (IMAGE_INSTANCE_X_MASK (p))
|
|
130 {
|
|
131 sprintf (buf, "/0x%lx", (unsigned long) IMAGE_INSTANCE_X_MASK (p));
|
|
132 write_c_string (buf, printcharfun);
|
|
133 }
|
|
134 write_c_string (")", printcharfun);
|
|
135 break;
|
114
|
136 #if HAVE_SUBWINDOWS
|
0
|
137 case IMAGE_SUBWINDOW:
|
|
138 /* #### implement me */
|
114
|
139 #endif
|
0
|
140 default:
|
|
141 break;
|
|
142 }
|
|
143 }
|
|
144
|
|
145 static void
|
|
146 x_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
147 {
|
|
148 if (!p->data)
|
|
149 return;
|
|
150
|
|
151 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
152 {
|
|
153 Screen *scr = LISP_DEVICE_TO_X_SCREEN (IMAGE_INSTANCE_DEVICE (p));
|
|
154
|
|
155 if (IMAGE_INSTANCE_X_PIXMAP (p))
|
|
156 XFreePixmap (DisplayOfScreen (scr), IMAGE_INSTANCE_X_PIXMAP (p));
|
|
157 if (IMAGE_INSTANCE_X_MASK (p) &&
|
|
158 IMAGE_INSTANCE_X_MASK (p) != IMAGE_INSTANCE_X_PIXMAP (p))
|
|
159 XFreePixmap (DisplayOfScreen (scr), IMAGE_INSTANCE_X_MASK (p));
|
|
160 IMAGE_INSTANCE_X_PIXMAP (p) = 0;
|
|
161 IMAGE_INSTANCE_X_MASK (p) = 0;
|
|
162
|
|
163 if (IMAGE_INSTANCE_X_CURSOR (p))
|
|
164 {
|
|
165 XFreeCursor (DisplayOfScreen (scr), IMAGE_INSTANCE_X_CURSOR (p));
|
|
166 IMAGE_INSTANCE_X_CURSOR (p) = 0;
|
|
167 }
|
|
168
|
|
169 if (IMAGE_INSTANCE_X_NPIXELS (p) != 0)
|
|
170 {
|
|
171 XFreeColors (DisplayOfScreen (scr),
|
|
172 DefaultColormapOfScreen (scr),
|
|
173 IMAGE_INSTANCE_X_PIXELS (p),
|
|
174 IMAGE_INSTANCE_X_NPIXELS (p), 0);
|
|
175 IMAGE_INSTANCE_X_NPIXELS (p) = 0;
|
|
176 }
|
|
177 }
|
|
178 if (IMAGE_INSTANCE_X_PIXELS (p))
|
|
179 {
|
|
180 xfree (IMAGE_INSTANCE_X_PIXELS (p));
|
|
181 IMAGE_INSTANCE_X_PIXELS (p) = 0;
|
|
182 }
|
|
183
|
|
184 xfree (p->data);
|
|
185 p->data = 0;
|
|
186 }
|
|
187
|
|
188 static int
|
|
189 x_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
190 struct Lisp_Image_Instance *p2, int depth)
|
|
191 {
|
|
192 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
193 {
|
|
194 case IMAGE_MONO_PIXMAP:
|
|
195 case IMAGE_COLOR_PIXMAP:
|
|
196 case IMAGE_POINTER:
|
|
197 if (IMAGE_INSTANCE_X_NPIXELS (p1) != IMAGE_INSTANCE_X_NPIXELS (p2))
|
|
198 return 0;
|
114
|
199 #if HAVE_SUBWINDOWS
|
0
|
200 case IMAGE_SUBWINDOW:
|
|
201 /* #### implement me */
|
114
|
202 #endif
|
56
|
203 break;
|
0
|
204 default:
|
|
205 break;
|
|
206 }
|
|
207
|
|
208 return 1;
|
|
209 }
|
|
210
|
|
211 static unsigned long
|
|
212 x_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
213 {
|
|
214 switch (IMAGE_INSTANCE_TYPE (p))
|
|
215 {
|
|
216 case IMAGE_MONO_PIXMAP:
|
|
217 case IMAGE_COLOR_PIXMAP:
|
|
218 case IMAGE_POINTER:
|
|
219 return IMAGE_INSTANCE_X_NPIXELS (p);
|
114
|
220 #if HAVE_SUBWINDOWS
|
0
|
221 case IMAGE_SUBWINDOW:
|
|
222 /* #### implement me */
|
149
|
223 return 0;
|
114
|
224 #endif
|
0
|
225 default:
|
|
226 return 0;
|
|
227 }
|
|
228 }
|
|
229
|
|
230 /* Set all the slots in an image instance structure to reasonable
|
|
231 default values. This is used somewhere within an instantiate
|
|
232 method. It is assumed that the device slot within the image
|
|
233 instance is already set -- this is the case when instantiate
|
|
234 methods are called. */
|
|
235
|
|
236 static void
|
|
237 x_initialize_pixmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
238 enum image_instance_type type)
|
|
239 {
|
185
|
240 ii->data = xnew_and_zero (struct x_image_instance_data);
|
0
|
241 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
242 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
243 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
244 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
245 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
246 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
247 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
248 }
|
|
249
|
|
250
|
|
251 /************************************************************************/
|
|
252 /* pixmap file functions */
|
|
253 /************************************************************************/
|
|
254
|
|
255 /* Where bitmaps are; initialized from resource database */
|
|
256 Lisp_Object Vx_bitmap_file_path;
|
|
257
|
|
258 #ifndef BITMAPDIR
|
|
259 #define BITMAPDIR "/usr/include/X11/bitmaps"
|
|
260 #endif
|
|
261
|
|
262 #define USE_XBMLANGPATH
|
|
263
|
|
264 /* Given a pixmap filename, look through all of the "standard" places
|
|
265 where the file might be located. Return a full pathname if found;
|
|
266 otherwise, return Qnil. */
|
|
267
|
|
268 static Lisp_Object
|
|
269 locate_pixmap_file (Lisp_Object name)
|
|
270 {
|
|
271 /* This function can GC if IN_REDISPLAY is false */
|
|
272 Display *display;
|
|
273
|
|
274 /* Check non-absolute pathnames with a directory component relative to
|
|
275 the search path; that's the way Xt does it. */
|
|
276 /* #### Unix-specific */
|
80
|
277 if (XSTRING_BYTE (name, 0) == '/' ||
|
|
278 (XSTRING_BYTE (name, 0) == '.' &&
|
|
279 (XSTRING_BYTE (name, 1) == '/' ||
|
|
280 (XSTRING_BYTE (name, 1) == '.' &&
|
|
281 (XSTRING_BYTE (name, 2) == '/')))))
|
0
|
282 {
|
|
283 if (!NILP (Ffile_readable_p (name)))
|
|
284 return name;
|
|
285 else
|
|
286 return Qnil;
|
|
287 }
|
|
288
|
|
289 if (NILP (Vdefault_x_device))
|
|
290 /* This may occur during intialization. */
|
|
291 return Qnil;
|
|
292 else
|
|
293 /* We only check the bitmapFilePath resource on the original X device. */
|
|
294 display = DEVICE_X_DISPLAY (XDEVICE (Vdefault_x_device));
|
|
295
|
|
296 #ifdef USE_XBMLANGPATH
|
|
297 {
|
|
298 char *path = egetenv ("XBMLANGPATH");
|
|
299 SubstitutionRec subs[1];
|
|
300 subs[0].match = 'B';
|
14
|
301 subs[0].substitution = (char *) XSTRING_DATA (name);
|
0
|
302 /* #### Motif uses a big hairy default if $XBMLANGPATH isn't set.
|
|
303 We don't. If you want it used, set it. */
|
|
304 if (path &&
|
|
305 (path = XtResolvePathname (display, "bitmaps", 0, 0, path,
|
|
306 subs, XtNumber (subs), 0)))
|
|
307 {
|
|
308 name = build_string (path);
|
|
309 XtFree (path);
|
|
310 return (name);
|
|
311 }
|
|
312 }
|
|
313 #endif
|
|
314
|
|
315 if (NILP (Vx_bitmap_file_path))
|
|
316 {
|
|
317 char *type = 0;
|
|
318 XrmValue value;
|
|
319 if (XrmGetResource (XtDatabase (display),
|
|
320 "bitmapFilePath", "BitmapFilePath", &type, &value)
|
|
321 && !strcmp (type, "String"))
|
|
322 Vx_bitmap_file_path = decode_env_path (0, (char *) value.addr);
|
|
323 Vx_bitmap_file_path = nconc2 (Vx_bitmap_file_path,
|
|
324 (list1 (build_string (BITMAPDIR))));
|
|
325 }
|
|
326
|
|
327 {
|
|
328 Lisp_Object found;
|
|
329 if (locate_file (Vx_bitmap_file_path, name, "", &found, R_OK) < 0)
|
|
330 {
|
|
331 Lisp_Object temp = list1 (Vdata_directory);
|
|
332 struct gcpro gcpro1;
|
|
333
|
|
334 GCPRO1 (temp);
|
|
335 locate_file (temp, name, "", &found, R_OK);
|
|
336 UNGCPRO;
|
|
337 }
|
|
338
|
|
339 return found;
|
|
340 }
|
|
341 }
|
|
342
|
|
343 /* If INSTANTIATOR refers to inline data, return Qnil.
|
|
344 If INSTANTIATOR refers to data in a file, return the full filename
|
|
345 if it exists; otherwise, return a cons of (filename).
|
|
346
|
|
347 FILE_KEYWORD and DATA_KEYWORD are symbols specifying the
|
|
348 keywords used to look up the file and inline data,
|
|
349 respectively, in the instantiator. Normally these would
|
|
350 be Q_file and Q_data, but might be different for mask data. */
|
|
351
|
|
352 static Lisp_Object
|
|
353 potential_pixmap_file_instantiator (Lisp_Object instantiator,
|
|
354 Lisp_Object file_keyword,
|
|
355 Lisp_Object data_keyword)
|
|
356 {
|
|
357 Lisp_Object file;
|
|
358 Lisp_Object data;
|
|
359
|
|
360 assert (VECTORP (instantiator));
|
185
|
361
|
0
|
362 data = find_keyword_in_vector (instantiator, data_keyword);
|
|
363 file = find_keyword_in_vector (instantiator, file_keyword);
|
|
364
|
|
365 if (!NILP (file) && NILP (data))
|
|
366 {
|
|
367 Lisp_Object retval = locate_pixmap_file (file);
|
|
368 if (!NILP (retval))
|
|
369 return retval;
|
|
370 else
|
|
371 return Fcons (file, Qnil); /* should have been file */
|
|
372 }
|
|
373
|
|
374 return Qnil;
|
|
375 }
|
|
376
|
|
377
|
|
378 static Lisp_Object
|
|
379 simple_image_type_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
380 Lisp_Object image_type_tag)
|
|
381 {
|
116
|
382 /* This function can call lisp */
|
0
|
383 Lisp_Object file = Qnil;
|
|
384 struct gcpro gcpro1, gcpro2;
|
|
385 Lisp_Object alist = Qnil;
|
185
|
386
|
0
|
387 GCPRO2 (file, alist);
|
|
388
|
|
389 /* Now, convert any file data into inline data. At the end of this,
|
|
390 `data' will contain the inline data (if any) or Qnil, and `file'
|
|
391 will contain the name this data was derived from (if known) or
|
|
392 Qnil.
|
|
393
|
|
394 Note that if we cannot generate any regular inline data, we
|
|
395 skip out. */
|
|
396
|
|
397 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
398
|
|
399 if (CONSP (file)) /* failure locating filename */
|
|
400 signal_double_file_error ("Opening pixmap file",
|
|
401 "no such file or directory",
|
|
402 Fcar (file));
|
|
403
|
|
404 if (NILP (file)) /* no conversion necessary */
|
|
405 RETURN_UNGCPRO (inst);
|
|
406
|
|
407 alist = tagged_vector_to_alist (inst);
|
|
408
|
|
409 {
|
|
410 Lisp_Object data = make_string_from_file (file);
|
|
411 alist = remassq_no_quit (Q_file, alist);
|
|
412 /* there can't be a :data at this point. */
|
|
413 alist = Fcons (Fcons (Q_file, file),
|
|
414 Fcons (Fcons (Q_data, data), alist));
|
|
415 }
|
|
416
|
|
417 {
|
|
418 Lisp_Object result = alist_to_tagged_vector (image_type_tag, alist);
|
|
419 free_alist (alist);
|
|
420 RETURN_UNGCPRO (result);
|
|
421 }
|
|
422 }
|
|
423
|
|
424 static void
|
|
425 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out)
|
|
426 {
|
|
427 Extbyte *bytes;
|
|
428 Extcount len;
|
|
429 FILE *stream;
|
185
|
430
|
0
|
431 /* #### This is a definite problem under Mule due to the amount of
|
|
432 stack data it might allocate. Need to be able to convert and
|
|
433 write out to a file. */
|
|
434 GET_STRING_BINARY_DATA_ALLOCA (string, bytes, len);
|
|
435
|
|
436 /* Write out to a temporary file ... */
|
|
437 sprintf (filename_out, "/tmp/emacs%d.XXXXXX", (int) getpid ());
|
|
438 mktemp (filename_out);
|
|
439 stream = fopen (filename_out, "w");
|
|
440 if (!stream)
|
|
441 {
|
|
442 temp_file_error:
|
|
443 if (stream)
|
|
444 {
|
|
445 int old_errno = errno;
|
|
446 fclose (stream);
|
|
447 unlink (filename_out);
|
|
448 errno = old_errno;
|
|
449 }
|
|
450 report_file_error ("Creating temp file",
|
|
451 list1 (build_string (filename_out)));
|
|
452 }
|
|
453
|
|
454 if (fwrite (bytes, len, 1, stream) != 1)
|
|
455 goto temp_file_error;
|
|
456
|
|
457 if (fclose (stream) != 0)
|
|
458 {
|
|
459 stream = 0;
|
|
460 goto temp_file_error;
|
|
461 }
|
|
462 }
|
|
463
|
|
464
|
|
465 /************************************************************************/
|
|
466 /* cursor functions */
|
|
467 /************************************************************************/
|
|
468
|
|
469 /* Check that this server supports cursors of size WIDTH * HEIGHT. If
|
|
470 not, signal an error. INSTANTIATOR is only used in the error
|
|
471 message. */
|
|
472
|
|
473 static void
|
|
474 check_pointer_sizes (Screen *xs, unsigned int width, unsigned int height,
|
|
475 Lisp_Object instantiator)
|
|
476 {
|
|
477 unsigned int best_width, best_height;
|
|
478 if (! XQueryBestCursor (DisplayOfScreen (xs), RootWindowOfScreen (xs),
|
|
479 width, height, &best_width, &best_height))
|
|
480 /* this means that an X error of some sort occurred (we trap
|
|
481 these so they're not fatal). */
|
|
482 signal_simple_error ("XQueryBestCursor() failed?", instantiator);
|
|
483
|
|
484 if (width > best_width || height > best_height)
|
|
485 error_with_frob (instantiator,
|
|
486 "pointer too large (%dx%d): "
|
|
487 "server requires %dx%d or smaller",
|
|
488 width, height, best_width, best_height);
|
|
489 }
|
|
490
|
|
491
|
|
492 static void
|
|
493 generate_cursor_fg_bg (Lisp_Object device, Lisp_Object *foreground,
|
|
494 Lisp_Object *background, XColor *xfg, XColor *xbg)
|
|
495 {
|
|
496 if (!NILP (*foreground) && !COLOR_INSTANCEP (*foreground))
|
|
497 *foreground =
|
|
498 Fmake_color_instance (*foreground, device,
|
|
499 encode_error_behavior_flag (ERROR_ME));
|
|
500 if (COLOR_INSTANCEP (*foreground))
|
|
501 *xfg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*foreground));
|
|
502 else
|
|
503 {
|
|
504 xfg->pixel = 0;
|
|
505 xfg->red = xfg->green = xfg->blue = 0;
|
|
506 }
|
185
|
507
|
0
|
508 if (!NILP (*background) && !COLOR_INSTANCEP (*background))
|
|
509 *background =
|
|
510 Fmake_color_instance (*background, device,
|
|
511 encode_error_behavior_flag (ERROR_ME));
|
|
512 if (COLOR_INSTANCEP (*background))
|
|
513 *xbg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (*background));
|
|
514 else
|
|
515 {
|
|
516 xbg->pixel = 0;
|
|
517 xbg->red = xbg->green = xbg->blue = ~0;
|
|
518 }
|
|
519 }
|
|
520
|
|
521 static void
|
|
522 maybe_recolor_cursor (Lisp_Object image_instance, Lisp_Object foreground,
|
|
523 Lisp_Object background)
|
|
524 {
|
|
525 Lisp_Object device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
526 XColor xfg, xbg;
|
|
527
|
|
528 generate_cursor_fg_bg (device, &foreground, &background, &xfg, &xbg);
|
|
529 if (!NILP (foreground) || !NILP (background))
|
|
530 {
|
|
531 XRecolorCursor (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
532 XIMAGE_INSTANCE_X_CURSOR (image_instance),
|
|
533 &xfg, &xbg);
|
|
534 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
535 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
536 }
|
|
537 }
|
|
538
|
|
539
|
|
540 /************************************************************************/
|
|
541 /* color pixmap functions */
|
|
542 /************************************************************************/
|
|
543
|
|
544 /* Initialize an image instance from an XImage.
|
|
545
|
|
546 DEST_MASK specifies the mask of allowed image types.
|
|
547
|
|
548 PIXELS and NPIXELS specify an array of pixels that are used in
|
|
549 the image. These need to be kept around for the duration of the
|
|
550 image. When the image instance is freed, XFreeColors() will
|
|
551 automatically be called on all the pixels specified here; thus,
|
|
552 you should have allocated the pixels yourself using XAllocColor()
|
|
553 or the like. The array passed in is used directly without
|
|
554 being copied, so it should be heap data created with xmalloc().
|
|
555 It will be freed using xfree() when the image instance is
|
|
556 destroyed.
|
|
557
|
|
558 If this fails, signal an error. INSTANTIATOR is only used
|
|
559 in the error message.
|
|
560
|
|
561 #### This should be able to handle conversion into `pointer'.
|
|
562 Use the same code as for `xpm'. */
|
|
563
|
|
564 static void
|
|
565 init_image_instance_from_x_image (struct Lisp_Image_Instance *ii,
|
|
566 XImage *ximage,
|
|
567 int dest_mask,
|
|
568 unsigned long *pixels,
|
|
569 int npixels,
|
|
570 Lisp_Object instantiator)
|
|
571 {
|
|
572 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
573 Display *dpy;
|
|
574 Screen *xs;
|
|
575 GC gc;
|
|
576 Drawable d;
|
|
577 Pixmap pixmap;
|
|
578
|
|
579 if (!DEVICE_X_P (XDEVICE (device)))
|
|
580 signal_simple_error ("Not an X device", device);
|
|
581
|
|
582 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
583 xs = DefaultScreenOfDisplay (dpy);
|
|
584 d = RootWindowOfScreen (xs);
|
|
585
|
|
586 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
587 incompatible_image_types (instantiator, dest_mask,
|
|
588 IMAGE_COLOR_PIXMAP_MASK);
|
185
|
589
|
0
|
590 pixmap = XCreatePixmap (dpy, d, ximage->width,
|
|
591 ximage->height, ximage->depth);
|
|
592 if (!pixmap)
|
|
593 signal_simple_error ("Unable to create pixmap", instantiator);
|
|
594
|
|
595 gc = XCreateGC (dpy, pixmap, 0, NULL);
|
|
596 if (!gc)
|
|
597 {
|
|
598 XFreePixmap (dpy, pixmap);
|
|
599 signal_simple_error ("Unable to create GC", instantiator);
|
|
600 }
|
185
|
601
|
0
|
602 XPutImage (dpy, pixmap, gc, ximage, 0, 0, 0, 0,
|
|
603 ximage->width, ximage->height);
|
185
|
604
|
0
|
605 XFreeGC (dpy, gc);
|
|
606
|
|
607 x_initialize_pixmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
608
|
|
609 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
610 find_keyword_in_vector (instantiator, Q_file);
|
185
|
611
|
0
|
612 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
613 IMAGE_INSTANCE_X_MASK (ii) = 0;
|
|
614 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = ximage->width;
|
|
615 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = ximage->height;
|
|
616 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = ximage->depth;
|
|
617 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
618 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
619 }
|
|
620
|
|
621
|
|
622 /**********************************************************************
|
|
623 * XBM *
|
|
624 **********************************************************************/
|
|
625
|
|
626 /* Check if DATA represents a valid inline XBM spec (i.e. a list
|
|
627 of (width height bits), with checking done on the dimensions).
|
|
628 If not, signal an error. */
|
|
629
|
|
630 static void
|
|
631 check_valid_xbm_inline (Lisp_Object data)
|
|
632 {
|
|
633 Lisp_Object width, height, bits;
|
|
634
|
|
635 CHECK_CONS (data);
|
|
636 if (!CONSP (XCDR (data)) || !CONSP (XCDR (XCDR (data))) ||
|
|
637 !NILP (XCDR (XCDR (XCDR (data)))))
|
|
638 signal_simple_error ("Must be list of 3 elements", data);
|
|
639
|
|
640 width = XCAR (data);
|
|
641 height = XCAR (XCDR (data));
|
|
642 bits = XCAR (XCDR (XCDR (data)));
|
|
643
|
|
644 if (!INTP (width) || !INTP (height) || !STRINGP (bits))
|
|
645 signal_simple_error ("Must be (width height bits)",
|
|
646 vector3 (width, height, bits));
|
|
647
|
|
648 if (XINT (width) <= 0)
|
|
649 signal_simple_error ("Width must be > 0", width);
|
|
650
|
|
651 if (XINT (height) <= 0)
|
|
652 signal_simple_error ("Height must be > 0", height);
|
|
653
|
|
654 if (((unsigned) (XINT (width) * XINT (height)) / 8)
|
|
655 > string_char_length (XSTRING (bits)))
|
|
656 signal_simple_error ("data is too short for W and H",
|
|
657 vector3 (width, height, bits));
|
|
658 }
|
|
659
|
|
660 /* Validate method for XBM's. */
|
|
661
|
|
662 static void
|
|
663 xbm_validate (Lisp_Object instantiator)
|
|
664 {
|
|
665 file_or_data_must_be_present (instantiator);
|
|
666 }
|
|
667
|
|
668 /* Given a filename that is supposed to contain XBM data, return
|
|
669 the inline representation of it as (width height bits). Return
|
|
670 the hotspot through XHOT and YHOT, if those pointers are not 0.
|
|
671 If there is no hotspot, XHOT and YHOT will contain -1.
|
|
672
|
|
673 If the function fails:
|
|
674
|
|
675 -- if OK_IF_DATA_INVALID is set and the data was invalid,
|
|
676 return Qt.
|
|
677 -- maybe return an error, or return Qnil.
|
|
678 */
|
185
|
679
|
0
|
680
|
|
681 static Lisp_Object
|
|
682 bitmap_to_lisp_data (Lisp_Object name, int *xhot, int *yhot,
|
|
683 int ok_if_data_invalid)
|
|
684 {
|
|
685 unsigned int w, h;
|
|
686 Extbyte *data;
|
|
687 int result;
|
|
688 CONST char *filename_ext;
|
|
689
|
|
690 GET_C_STRING_FILENAME_DATA_ALLOCA (name, filename_ext);
|
|
691 result = XmuReadBitmapDataFromFile (filename_ext, &w, &h, &data, xhot, yhot);
|
|
692
|
|
693 if (result == BitmapSuccess)
|
|
694 {
|
|
695 Lisp_Object retval;
|
|
696 int len = (w + 7) / 8 * h;
|
|
697
|
|
698 retval = list3 (make_int (w), make_int (h),
|
|
699 make_ext_string (data, len, FORMAT_BINARY));
|
|
700 XFree ((char *) data);
|
|
701 return retval;
|
|
702 }
|
|
703
|
|
704 switch (result)
|
|
705 {
|
|
706 case BitmapOpenFailed:
|
|
707 {
|
|
708 /* should never happen */
|
|
709 signal_double_file_error ("Opening bitmap file",
|
|
710 "no such file or directory",
|
|
711 name);
|
|
712 }
|
|
713 case BitmapFileInvalid:
|
|
714 {
|
|
715 if (ok_if_data_invalid)
|
|
716 return Qt;
|
|
717 signal_double_file_error ("Reading bitmap file",
|
|
718 "invalid data in file",
|
|
719 name);
|
|
720 }
|
|
721 case BitmapNoMemory:
|
|
722 {
|
|
723 signal_double_file_error ("Reading bitmap file",
|
|
724 "out of memory",
|
|
725 name);
|
|
726 }
|
|
727 default:
|
|
728 {
|
|
729 signal_double_file_error_2 ("Reading bitmap file",
|
|
730 "unknown error code",
|
|
731 make_int (result), name);
|
|
732 }
|
|
733 }
|
|
734
|
|
735 return Qnil; /* not reached */
|
|
736 }
|
|
737
|
|
738 static Lisp_Object
|
|
739 xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
|
|
740 Lisp_Object mask_file)
|
|
741 {
|
|
742 /* This is unclean but it's fairly standard -- a number of the
|
|
743 bitmaps in /usr/include/X11/bitmaps use it -- so we support
|
|
744 it. */
|
|
745 if (NILP (mask_file)
|
|
746 /* don't override explicitly specified mask data. */
|
|
747 && NILP (assq_no_quit (Q_mask_data, alist))
|
|
748 && !NILP (file))
|
|
749 {
|
|
750 mask_file =
|
|
751 locate_pixmap_file (concat2 (file, build_string ("Mask")));
|
|
752 if (NILP (mask_file))
|
|
753 mask_file =
|
|
754 locate_pixmap_file (concat2 (file, build_string ("msk")));
|
|
755 }
|
|
756
|
|
757 if (!NILP (mask_file))
|
|
758 {
|
|
759 Lisp_Object mask_data =
|
|
760 bitmap_to_lisp_data (mask_file, 0, 0, 0);
|
|
761 alist = remassq_no_quit (Q_mask_file, alist);
|
|
762 /* there can't be a :mask-data at this point. */
|
|
763 alist = Fcons (Fcons (Q_mask_file, mask_file),
|
|
764 Fcons (Fcons (Q_mask_data, mask_data), alist));
|
|
765 }
|
|
766
|
|
767 return alist;
|
|
768 }
|
|
769
|
|
770 /* Normalize method for XBM's. */
|
|
771
|
|
772 static Lisp_Object
|
|
773 xbm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
774 {
|
|
775 Lisp_Object file = Qnil, mask_file = Qnil;
|
|
776 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
777 Lisp_Object alist = Qnil;
|
185
|
778
|
0
|
779 GCPRO3 (file, mask_file, alist);
|
|
780
|
|
781 /* Now, convert any file data into inline data for both the regular
|
|
782 data and the mask data. At the end of this, `data' will contain
|
|
783 the inline data (if any) or Qnil, and `file' will contain
|
|
784 the name this data was derived from (if known) or Qnil.
|
|
785 Likewise for `mask_file' and `mask_data'.
|
|
786
|
|
787 Note that if we cannot generate any regular inline data, we
|
|
788 skip out. */
|
|
789
|
|
790 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
791 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
|
|
792 Q_mask_data);
|
|
793
|
|
794 if (CONSP (file)) /* failure locating filename */
|
|
795 signal_double_file_error ("Opening bitmap file",
|
|
796 "no such file or directory",
|
|
797 Fcar (file));
|
|
798
|
|
799 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
|
|
800 RETURN_UNGCPRO (inst);
|
|
801
|
|
802 alist = tagged_vector_to_alist (inst);
|
|
803
|
|
804 if (!NILP (file))
|
|
805 {
|
|
806 int xhot, yhot;
|
|
807 Lisp_Object data = bitmap_to_lisp_data (file, &xhot, &yhot, 0);
|
|
808 alist = remassq_no_quit (Q_file, alist);
|
|
809 /* there can't be a :data at this point. */
|
|
810 alist = Fcons (Fcons (Q_file, file),
|
|
811 Fcons (Fcons (Q_data, data), alist));
|
|
812
|
|
813 if (xhot != -1 && NILP (assq_no_quit (Q_hotspot_x, alist)))
|
|
814 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
815 alist);
|
|
816 if (yhot != -1 && NILP (assq_no_quit (Q_hotspot_y, alist)))
|
|
817 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
818 alist);
|
|
819 }
|
|
820
|
|
821 alist = xbm_mask_file_munging (alist, file, mask_file);
|
|
822
|
|
823 {
|
|
824 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
825 free_alist (alist);
|
|
826 RETURN_UNGCPRO (result);
|
|
827 }
|
|
828 }
|
|
829
|
|
830 /* Given inline data for a mono pixmap, create and return the
|
|
831 corresponding X object. */
|
|
832
|
|
833 static Pixmap
|
|
834 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
|
|
835 /* Note that data is in ext-format! */
|
|
836 CONST Extbyte *bits)
|
|
837 {
|
|
838 Screen *screen = LISP_DEVICE_TO_X_SCREEN (device);
|
|
839 return XCreatePixmapFromBitmapData (DisplayOfScreen (screen),
|
|
840 RootWindowOfScreen (screen),
|
|
841 (char *) bits, width, height,
|
|
842 1, 0, 1);
|
|
843 }
|
|
844
|
|
845 /* Given inline data for a mono pixmap, initialize the given
|
|
846 image instance accordingly. */
|
|
847
|
|
848 static void
|
|
849 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
|
|
850 int width, int height,
|
|
851 /* Note that data is in ext-format! */
|
|
852 CONST char *bits,
|
|
853 Lisp_Object instantiator,
|
|
854 Lisp_Object pointer_fg,
|
|
855 Lisp_Object pointer_bg,
|
|
856 int dest_mask,
|
|
857 Pixmap mask,
|
|
858 Lisp_Object mask_filename)
|
|
859 {
|
|
860 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
861 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
862 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
863 Display *dpy;
|
|
864 Screen *scr;
|
|
865 enum image_instance_type type;
|
|
866
|
|
867 if (!DEVICE_X_P (XDEVICE (device)))
|
|
868 signal_simple_error ("Not an X device", device);
|
|
869
|
|
870 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
871 scr = DefaultScreenOfDisplay (dpy);
|
|
872
|
|
873 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
874 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
875 {
|
|
876 if (!NILP (foreground) || !NILP (background))
|
|
877 type = IMAGE_COLOR_PIXMAP;
|
|
878 else
|
|
879 type = IMAGE_MONO_PIXMAP;
|
|
880 }
|
|
881 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
882 type = IMAGE_MONO_PIXMAP;
|
|
883 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
884 type = IMAGE_COLOR_PIXMAP;
|
|
885 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
886 type = IMAGE_POINTER;
|
|
887 else
|
|
888 incompatible_image_types (instantiator, dest_mask,
|
|
889 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
890 | IMAGE_POINTER_MASK);
|
|
891
|
|
892 x_initialize_pixmap_image_instance (ii, type);
|
|
893 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
894 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
895 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
896 find_keyword_in_vector (instantiator, Q_file);
|
|
897
|
|
898 switch (type)
|
|
899 {
|
|
900 case IMAGE_MONO_PIXMAP:
|
|
901 {
|
|
902 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
|
903 pixmap_from_xbm_inline (device, width, height, (Extbyte *) bits);
|
|
904 }
|
|
905 break;
|
|
906
|
|
907 case IMAGE_COLOR_PIXMAP:
|
|
908 {
|
|
909 Dimension d = DefaultDepthOfScreen (scr);
|
|
910 unsigned long fg = BlackPixelOfScreen (scr);
|
|
911 unsigned long bg = WhitePixelOfScreen (scr);
|
|
912
|
|
913 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
914 foreground =
|
|
915 Fmake_color_instance (foreground, device,
|
|
916 encode_error_behavior_flag (ERROR_ME));
|
|
917
|
|
918 if (COLOR_INSTANCEP (foreground))
|
|
919 fg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground)).pixel;
|
|
920
|
|
921 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
922 background =
|
|
923 Fmake_color_instance (background, device,
|
|
924 encode_error_behavior_flag (ERROR_ME));
|
|
925
|
|
926 if (COLOR_INSTANCEP (background))
|
|
927 bg = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background)).pixel;
|
|
928
|
|
929 /* We used to duplicate the pixels using XAllocColor(), to protect
|
|
930 against their getting freed. Just as easy to just store the
|
|
931 color instances here and GC-protect them, so this doesn't
|
|
932 happen. */
|
|
933 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
934 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
935 IMAGE_INSTANCE_X_PIXMAP (ii) =
|
|
936 XCreatePixmapFromBitmapData (DisplayOfScreen (scr),
|
|
937 RootWindowOfScreen (scr),
|
|
938 (char *) bits, width, height,
|
|
939 fg, bg, d);
|
|
940 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
941 }
|
|
942 break;
|
|
943
|
|
944 case IMAGE_POINTER:
|
207
|
945 {
|
0
|
946 XColor fg_color, bg_color;
|
|
947 Pixmap source;
|
|
948
|
|
949 check_pointer_sizes (scr, width, height, instantiator);
|
|
950
|
|
951 source =
|
|
952 XCreatePixmapFromBitmapData (DisplayOfScreen (scr),
|
|
953 RootWindowOfScreen (scr),
|
|
954 (char *) bits, width, height,
|
|
955 1, 0, 1);
|
|
956
|
|
957 if (NILP (foreground))
|
|
958 foreground = pointer_fg;
|
|
959 if (NILP (background))
|
|
960 background = pointer_bg;
|
|
961 generate_cursor_fg_bg (device, &foreground, &background,
|
|
962 &fg_color, &bg_color);
|
|
963
|
|
964 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
965 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
966 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
|
|
967 find_keyword_in_vector (instantiator, Q_hotspot_x);
|
|
968 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
|
|
969 find_keyword_in_vector (instantiator, Q_hotspot_y);
|
|
970 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
971 XCreatePixmapCursor
|
|
972 (dpy, source, mask, &fg_color, &bg_color,
|
|
973 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ?
|
|
974 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) : 0,
|
|
975 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) ?
|
|
976 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) : 0);
|
|
977 }
|
|
978 break;
|
|
979
|
|
980 default:
|
|
981 abort ();
|
|
982 }
|
|
983 }
|
207
|
984
|
0
|
985 static int
|
74
|
986 xbm_possible_dest_types (void)
|
0
|
987 {
|
74
|
988 return
|
|
989 IMAGE_MONO_PIXMAP_MASK |
|
|
990 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
991 IMAGE_POINTER_MASK;
|
|
992 }
|
|
993
|
|
994 static void
|
|
995 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
996 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
997 int dest_mask, int width, int height,
|
|
998 /* Note that data is in ext-format! */
|
|
999 CONST char *bits)
|
|
1000 {
|
|
1001 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1002 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
|
1003 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1004 Pixmap mask = 0;
|
|
1005 CONST char *gcc_may_you_rot_in_hell;
|
|
1006
|
|
1007 if (!NILP (mask_data))
|
207
|
1008 {
|
0
|
1009 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))),
|
|
1010 gcc_may_you_rot_in_hell);
|
|
1011 mask =
|
|
1012 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
|
|
1013 XINT (XCAR (mask_data)),
|
|
1014 XINT (XCAR (XCDR (mask_data))),
|
|
1015 (CONST unsigned char *)
|
|
1016 gcc_may_you_rot_in_hell);
|
207
|
1017 }
|
0
|
1018
|
|
1019 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1020 instantiator, pointer_fg, pointer_bg,
|
|
1021 dest_mask, mask, mask_file);
|
|
1022 }
|
|
1023
|
|
1024 /* Instantiate method for XBM's. */
|
|
1025
|
|
1026 static void
|
|
1027 xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
207
|
1028 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1029 int dest_mask, Lisp_Object domain)
|
0
|
1030 {
|
|
1031 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1032 CONST char *gcc_go_home;
|
|
1033
|
|
1034 assert (!NILP (data));
|
|
1035
|
|
1036 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (data))),
|
|
1037 gcc_go_home);
|
|
1038
|
|
1039 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1040 pointer_bg, dest_mask, XINT (XCAR (data)),
|
|
1041 XINT (XCAR (XCDR (data))), gcc_go_home);
|
|
1042 }
|
|
1043
|
|
1044
|
|
1045 #ifdef HAVE_XPM
|
|
1046
|
|
1047 /**********************************************************************
|
|
1048 * XPM *
|
|
1049 **********************************************************************/
|
|
1050
|
|
1051 static void
|
|
1052 check_valid_xpm_color_symbols (Lisp_Object data)
|
|
1053 {
|
|
1054 Lisp_Object rest;
|
185
|
1055
|
0
|
1056 for (rest = data; !NILP (rest); rest = XCDR (rest))
|
|
1057 {
|
|
1058 if (!CONSP (rest) ||
|
|
1059 !CONSP (XCAR (rest)) ||
|
|
1060 !STRINGP (XCAR (XCAR (rest))) ||
|
|
1061 (!STRINGP (XCDR (XCAR (rest))) &&
|
|
1062 !COLOR_SPECIFIERP (XCDR (XCAR (rest)))))
|
|
1063 signal_simple_error ("Invalid color symbol alist", data);
|
|
1064 }
|
|
1065 }
|
|
1066
|
|
1067 static void
|
|
1068 xpm_validate (Lisp_Object instantiator)
|
|
1069 {
|
|
1070 file_or_data_must_be_present (instantiator);
|
|
1071 }
|
|
1072
|
|
1073 static Lisp_Object
|
|
1074 pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid)
|
|
1075 {
|
|
1076 char **data;
|
|
1077 int result;
|
|
1078
|
14
|
1079 result = XpmReadFileToData ((char *) XSTRING_DATA (name), &data);
|
0
|
1080
|
|
1081 if (result == XpmSuccess)
|
|
1082 {
|
|
1083 Lisp_Object retval = Qnil;
|
|
1084 struct buffer *old_buffer = current_buffer;
|
|
1085 Lisp_Object temp_buffer =
|
|
1086 Fget_buffer_create (build_string (" *pixmap conversion*"));
|
|
1087 int elt;
|
|
1088 int height, width, ncolors;
|
|
1089 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1090 int speccount = specpdl_depth ();
|
|
1091
|
|
1092 GCPRO3 (name, retval, temp_buffer);
|
|
1093
|
|
1094 specbind (Qinhibit_quit, Qt);
|
|
1095 set_buffer_internal (XBUFFER (temp_buffer));
|
|
1096 Ferase_buffer (Fcurrent_buffer ());
|
|
1097
|
|
1098 buffer_insert_c_string (current_buffer, "/* XPM */\r");
|
|
1099 buffer_insert_c_string (current_buffer, "static char *pixmap[] = {\r");
|
|
1100
|
|
1101 sscanf (data[0], "%d %d %d", &height, &width, &ncolors);
|
|
1102 for (elt = 0; elt <= width + ncolors; elt++)
|
|
1103 {
|
|
1104 buffer_insert_c_string (current_buffer, "\"");
|
|
1105 buffer_insert_c_string (current_buffer, data[elt]);
|
|
1106
|
|
1107 if (elt < width + ncolors)
|
|
1108 buffer_insert_c_string (current_buffer, "\",\r");
|
|
1109 else
|
|
1110 buffer_insert_c_string (current_buffer, "\"};\r");
|
|
1111 }
|
|
1112
|
|
1113 retval = Fbuffer_substring (Qnil, Qnil, Fcurrent_buffer ());
|
|
1114 XpmFree (data);
|
|
1115
|
|
1116 set_buffer_internal (old_buffer);
|
|
1117 unbind_to (speccount, Qnil);
|
|
1118
|
|
1119 RETURN_UNGCPRO (retval);
|
|
1120 }
|
|
1121
|
|
1122 switch (result)
|
|
1123 {
|
|
1124 case XpmFileInvalid:
|
|
1125 {
|
|
1126 if (ok_if_data_invalid)
|
|
1127 return Qt;
|
|
1128 signal_simple_error ("invalid XPM data in file", name);
|
|
1129 }
|
|
1130 case XpmNoMemory:
|
|
1131 {
|
|
1132 signal_double_file_error ("Reading pixmap file",
|
|
1133 "out of memory", name);
|
|
1134 }
|
|
1135 case XpmOpenFailed:
|
|
1136 {
|
|
1137 /* should never happen? */
|
|
1138 signal_double_file_error ("Opening pixmap file",
|
|
1139 "no such file or directory", name);
|
|
1140 }
|
|
1141 default:
|
|
1142 {
|
|
1143 signal_double_file_error_2 ("Parsing pixmap file",
|
|
1144 "unknown error code",
|
|
1145 make_int (result), name);
|
|
1146 break;
|
|
1147 }
|
|
1148 }
|
|
1149
|
|
1150 return Qnil; /* not reached */
|
|
1151 }
|
|
1152
|
|
1153 Lisp_Object Vxpm_color_symbols;
|
|
1154
|
|
1155 static Lisp_Object
|
|
1156 evaluate_xpm_color_symbols (void)
|
|
1157 {
|
|
1158 Lisp_Object rest, results = Qnil;
|
|
1159 struct gcpro gcpro1, gcpro2;
|
|
1160
|
|
1161 GCPRO2 (rest, results);
|
|
1162 for (rest = Vxpm_color_symbols; !NILP (rest); rest = XCDR (rest))
|
|
1163 {
|
|
1164 Lisp_Object name, value, cons;
|
|
1165
|
|
1166 CHECK_CONS (rest);
|
|
1167 cons = XCAR (rest);
|
|
1168 CHECK_CONS (cons);
|
|
1169 name = XCAR (cons);
|
|
1170 CHECK_STRING (name);
|
|
1171 value = XCDR (cons);
|
|
1172 CHECK_CONS (value);
|
|
1173 value = XCAR (value);
|
|
1174 value = Feval (value);
|
|
1175 if (NILP (value))
|
|
1176 continue;
|
|
1177 if (!STRINGP (value) && !COLOR_SPECIFIERP (value))
|
|
1178 signal_simple_error
|
|
1179 ("Result from xpm-color-symbols eval must be nil, string, or color",
|
|
1180 value);
|
|
1181 results = Fcons (Fcons (name, value), results);
|
|
1182 }
|
|
1183 UNGCPRO; /* no more evaluation */
|
|
1184 return results;
|
|
1185 }
|
|
1186
|
|
1187 static Lisp_Object
|
|
1188 xpm_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1189 {
|
|
1190 Lisp_Object file = Qnil;
|
|
1191 Lisp_Object color_symbols;
|
|
1192 struct gcpro gcpro1, gcpro2;
|
|
1193 Lisp_Object alist = Qnil;
|
185
|
1194
|
0
|
1195 GCPRO2 (file, alist);
|
|
1196
|
|
1197 /* Now, convert any file data into inline data. At the end of this,
|
|
1198 `data' will contain the inline data (if any) or Qnil, and
|
|
1199 `file' will contain the name this data was derived from (if
|
|
1200 known) or Qnil.
|
|
1201
|
|
1202 Note that if we cannot generate any regular inline data, we
|
|
1203 skip out. */
|
|
1204
|
|
1205 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
1206
|
|
1207 if (CONSP (file)) /* failure locating filename */
|
|
1208 signal_double_file_error ("Opening pixmap file",
|
|
1209 "no such file or directory",
|
|
1210 Fcar (file));
|
|
1211
|
|
1212 color_symbols = find_keyword_in_vector_or_given (inst, Q_color_symbols,
|
|
1213 Qunbound);
|
|
1214
|
|
1215 if (NILP (file) && !UNBOUNDP (color_symbols))
|
|
1216 /* no conversion necessary */
|
|
1217 RETURN_UNGCPRO (inst);
|
|
1218
|
|
1219 alist = tagged_vector_to_alist (inst);
|
|
1220
|
|
1221 if (!NILP (file))
|
|
1222 {
|
|
1223 Lisp_Object data = pixmap_to_lisp_data (file, 0);
|
|
1224 alist = remassq_no_quit (Q_file, alist);
|
|
1225 /* there can't be a :data at this point. */
|
|
1226 alist = Fcons (Fcons (Q_file, file),
|
|
1227 Fcons (Fcons (Q_data, data), alist));
|
|
1228 }
|
|
1229
|
|
1230 if (UNBOUNDP (color_symbols))
|
|
1231 {
|
|
1232 color_symbols = evaluate_xpm_color_symbols ();
|
|
1233 alist = Fcons (Fcons (Q_color_symbols, color_symbols),
|
|
1234 alist);
|
|
1235 }
|
|
1236
|
|
1237 {
|
|
1238 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1239 free_alist (alist);
|
|
1240 RETURN_UNGCPRO (result);
|
|
1241 }
|
|
1242 }
|
|
1243
|
|
1244 static int
|
74
|
1245 xpm_possible_dest_types (void)
|
0
|
1246 {
|
74
|
1247 return
|
|
1248 IMAGE_MONO_PIXMAP_MASK |
|
|
1249 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
1250 IMAGE_POINTER_MASK;
|
|
1251 }
|
|
1252
|
|
1253 /* xpm 3.2g and better has XpmCreatePixmapFromBuffer()...
|
|
1254 There was no version number in xpm.h before 3.3, but this should do.
|
|
1255 */
|
|
1256 #if (XpmVersion >= 3) || defined(XpmExactColors)
|
|
1257 # define XPM_DOES_BUFFERS
|
|
1258 #endif
|
|
1259
|
|
1260 #ifndef XPM_DOES_BUFFERS
|
|
1261 Your version of XPM is too old. You cannot compile with it.
|
|
1262 Upgrade to version 3.2g or better or compile with --with-xpm=no.
|
|
1263 #endif /* !XPM_DOES_BUFFERS */
|
|
1264
|
|
1265 static XpmColorSymbol *
|
|
1266 extract_xpm_color_names (XpmAttributes *xpmattrs, Lisp_Object device,
|
124
|
1267 Lisp_Object domain,
|
0
|
1268 Lisp_Object color_symbol_alist)
|
|
1269 {
|
|
1270 /* This function can GC */
|
|
1271 Screen *xs = LISP_DEVICE_TO_X_SCREEN (device);
|
|
1272 Display *dpy = DisplayOfScreen (xs);
|
|
1273 Colormap cmap = DefaultColormapOfScreen (xs);
|
|
1274 XColor color;
|
|
1275 Lisp_Object rest;
|
|
1276 Lisp_Object results = Qnil;
|
|
1277 int i;
|
|
1278 XpmColorSymbol *symbols;
|
|
1279 struct gcpro gcpro1, gcpro2;
|
|
1280
|
|
1281 GCPRO2 (results, device);
|
|
1282
|
|
1283 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
1284 error happens we don't lose any malloc()ed data, or more importantly,
|
|
1285 leave any pixels allocated in the server. */
|
|
1286 i = 0;
|
|
1287 LIST_LOOP (rest, color_symbol_alist)
|
|
1288 {
|
|
1289 Lisp_Object cons = XCAR (rest);
|
|
1290 Lisp_Object name = XCAR (cons);
|
|
1291 Lisp_Object value = XCDR (cons);
|
|
1292 if (NILP (value))
|
|
1293 continue;
|
|
1294 if (STRINGP (value))
|
|
1295 value =
|
|
1296 Fmake_color_instance
|
|
1297 (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
|
|
1298 else
|
|
1299 {
|
|
1300 assert (COLOR_SPECIFIERP (value));
|
124
|
1301 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
0
|
1302 }
|
|
1303 if (NILP (value))
|
|
1304 continue;
|
|
1305 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
1306 i++;
|
|
1307 }
|
|
1308 UNGCPRO; /* no more evaluation */
|
|
1309
|
|
1310 if (i == 0) return 0;
|
|
1311
|
185
|
1312 symbols = xnew_array (XpmColorSymbol, i);
|
0
|
1313 xpmattrs->valuemask |= XpmColorSymbols;
|
|
1314 xpmattrs->colorsymbols = symbols;
|
|
1315 xpmattrs->numsymbols = i;
|
|
1316
|
|
1317 while (--i >= 0)
|
|
1318 {
|
|
1319 Lisp_Object cons = XCAR (results);
|
|
1320 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
1321 /* Duplicate the pixel value so that we still have a lock on it if
|
|
1322 the pixel we were passed is later freed. */
|
|
1323 if (! XAllocColor (dpy, cmap, &color))
|
|
1324 abort (); /* it must be allocable since we're just duplicating it */
|
|
1325
|
14
|
1326 symbols [i].name = (char *) XSTRING_DATA (XCAR (cons));
|
0
|
1327 symbols [i].pixel = color.pixel;
|
|
1328 symbols [i].value = 0;
|
|
1329 free_cons (XCONS (cons));
|
|
1330 cons = results;
|
|
1331 results = XCDR (results);
|
|
1332 free_cons (XCONS (cons));
|
|
1333 }
|
|
1334 return symbols;
|
|
1335 }
|
|
1336
|
|
1337 static void
|
|
1338 xpm_free (XpmAttributes *xpmattrs)
|
|
1339 {
|
|
1340 /* Could conceivably lose if XpmXXX returned an error without first
|
|
1341 initializing this structure, if we didn't know that initializing it
|
|
1342 to all zeros was ok (and also that it's ok to call XpmFreeAttributes()
|
|
1343 multiple times, since it zeros slots as it frees them...) */
|
|
1344 XpmFreeAttributes (xpmattrs);
|
|
1345 }
|
|
1346
|
|
1347 static void
|
|
1348 xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1349 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1350 int dest_mask, Lisp_Object domain)
|
0
|
1351 {
|
|
1352 /* This function can GC */
|
|
1353 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1354 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1355 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1356 Display *dpy;
|
|
1357 Screen *xs;
|
|
1358 Pixmap pixmap;
|
|
1359 Pixmap mask = 0;
|
|
1360 XpmAttributes xpmattrs;
|
|
1361 int result;
|
|
1362 XpmColorSymbol *color_symbols;
|
|
1363 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
1364 Q_color_symbols);
|
|
1365 enum image_instance_type type;
|
|
1366 int force_mono;
|
|
1367 unsigned int w, h;
|
|
1368
|
|
1369 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1370 signal_simple_error ("Not an X device", device);
|
|
1371
|
|
1372 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1373 xs = DefaultScreenOfDisplay (dpy);
|
|
1374
|
|
1375 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1376 type = IMAGE_COLOR_PIXMAP;
|
|
1377 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
1378 type = IMAGE_MONO_PIXMAP;
|
|
1379 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
1380 type = IMAGE_POINTER;
|
|
1381 else
|
|
1382 incompatible_image_types (instantiator, dest_mask,
|
|
1383 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
1384 | IMAGE_POINTER_MASK);
|
|
1385 force_mono = (type != IMAGE_COLOR_PIXMAP);
|
|
1386
|
|
1387 x_initialize_pixmap_image_instance (ii, type);
|
|
1388
|
|
1389 assert (!NILP (data));
|
|
1390
|
|
1391 retry:
|
|
1392
|
|
1393 memset (&xpmattrs, 0, sizeof (xpmattrs)); /* want XpmInitAttributes() */
|
|
1394 xpmattrs.valuemask = XpmReturnPixels;
|
|
1395 if (force_mono)
|
|
1396 {
|
|
1397 /* Without this, we get a 1-bit version of the color image, which
|
|
1398 isn't quite right. With this, we get the mono image, which might
|
|
1399 be very different looking. */
|
|
1400 xpmattrs.valuemask |= XpmColorKey;
|
|
1401 xpmattrs.color_key = XPM_MONO;
|
|
1402 xpmattrs.depth = 1;
|
|
1403 xpmattrs.valuemask |= XpmDepth;
|
|
1404 }
|
|
1405 else
|
|
1406 {
|
|
1407 xpmattrs.closeness = 65535;
|
|
1408 xpmattrs.valuemask |= XpmCloseness;
|
|
1409 }
|
185
|
1410
|
124
|
1411 color_symbols = extract_xpm_color_names (&xpmattrs, device, domain,
|
0
|
1412 color_symbol_alist);
|
|
1413
|
|
1414 result = XpmCreatePixmapFromBuffer (dpy,
|
|
1415 RootWindowOfScreen (xs),
|
14
|
1416 (char *) XSTRING_DATA (data),
|
0
|
1417 &pixmap, &mask, &xpmattrs);
|
|
1418
|
|
1419 if (color_symbols)
|
|
1420 {
|
|
1421 xfree (color_symbols);
|
|
1422 xpmattrs.colorsymbols = 0; /* in case XpmFreeAttr is too smart... */
|
|
1423 xpmattrs.numsymbols = 0;
|
|
1424 }
|
|
1425
|
|
1426 switch (result)
|
|
1427 {
|
|
1428 case XpmSuccess:
|
|
1429 break;
|
|
1430 case XpmFileInvalid:
|
|
1431 {
|
|
1432 xpm_free (&xpmattrs);
|
|
1433 signal_simple_error ("invalid XPM data", data);
|
|
1434 }
|
|
1435 case XpmColorFailed:
|
|
1436 case XpmColorError:
|
|
1437 {
|
|
1438 xpm_free (&xpmattrs);
|
|
1439 if (force_mono)
|
|
1440 {
|
|
1441 /* second time; blow out. */
|
|
1442 signal_double_file_error ("Reading pixmap data",
|
|
1443 "color allocation failed",
|
|
1444 data);
|
|
1445 }
|
|
1446 else
|
|
1447 {
|
|
1448 if (! (dest_mask & IMAGE_MONO_PIXMAP_MASK))
|
|
1449 {
|
|
1450 /* second time; blow out. */
|
|
1451 signal_double_file_error ("Reading pixmap data",
|
|
1452 "color allocation failed",
|
|
1453 data);
|
|
1454 }
|
|
1455 force_mono = 1;
|
|
1456 IMAGE_INSTANCE_TYPE (ii) = IMAGE_MONO_PIXMAP;
|
|
1457 goto retry;
|
|
1458 }
|
|
1459 }
|
|
1460 case XpmNoMemory:
|
|
1461 {
|
|
1462 xpm_free (&xpmattrs);
|
|
1463 signal_double_file_error ("Parsing pixmap data",
|
|
1464 "out of memory", data);
|
|
1465 }
|
|
1466 default:
|
|
1467 {
|
|
1468 xpm_free (&xpmattrs);
|
|
1469 signal_double_file_error_2 ("Parsing pixmap data",
|
|
1470 "unknown error code",
|
|
1471 make_int (result), data);
|
|
1472 }
|
|
1473 }
|
|
1474
|
|
1475 w = xpmattrs.width;
|
|
1476 h = xpmattrs.height;
|
|
1477
|
|
1478 {
|
|
1479 int npixels = xpmattrs.npixels;
|
185
|
1480 Pixel *pixels;
|
0
|
1481
|
|
1482 if (npixels != 0)
|
|
1483 {
|
185
|
1484 pixels = xnew_array (Pixel, npixels);
|
0
|
1485 memcpy (pixels, xpmattrs.pixels, npixels * sizeof (Pixel));
|
|
1486 }
|
|
1487 else
|
185
|
1488 pixels = NULL;
|
0
|
1489
|
|
1490 IMAGE_INSTANCE_X_PIXMAP (ii) = pixmap;
|
|
1491 IMAGE_INSTANCE_X_MASK (ii) = mask;
|
|
1492 IMAGE_INSTANCE_X_PIXELS (ii) = pixels;
|
|
1493 IMAGE_INSTANCE_X_NPIXELS (ii) = npixels;
|
|
1494 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
|
|
1495 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
|
|
1496 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
1497 find_keyword_in_vector (instantiator, Q_file);
|
|
1498 }
|
|
1499
|
|
1500 switch (type)
|
|
1501 {
|
|
1502 case IMAGE_MONO_PIXMAP:
|
|
1503 break;
|
|
1504
|
|
1505 case IMAGE_COLOR_PIXMAP:
|
|
1506 {
|
|
1507 /* XpmReadFileToPixmap() doesn't return the depth (bogus!) so
|
|
1508 we need to get it ourself. (No, xpmattrs.depth is not it;
|
|
1509 that's an input slot, not output.) We could just assume
|
|
1510 that it has the same depth as the root window, but some
|
|
1511 devices allow more than one depth, so that isn't
|
|
1512 necessarily correct (I guess?) */
|
|
1513 Window root;
|
|
1514 int x, y;
|
|
1515 unsigned int w2, h2, bw;
|
|
1516
|
|
1517 unsigned int d;
|
|
1518
|
|
1519 if (!XGetGeometry (dpy, pixmap, &root, &x, &y, &w2, &h2, &bw, &d))
|
|
1520 abort ();
|
|
1521 if (w != w2 || h != h2)
|
|
1522 abort ();
|
|
1523
|
|
1524 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
1525 }
|
|
1526 break;
|
|
1527
|
|
1528 case IMAGE_POINTER:
|
|
1529 {
|
|
1530 int npixels = xpmattrs.npixels;
|
|
1531 Pixel *pixels = xpmattrs.pixels;
|
|
1532 XColor fg, bg;
|
|
1533 int i;
|
|
1534 int xhot = 0, yhot = 0;
|
|
1535
|
|
1536 if (xpmattrs.valuemask & XpmHotspot)
|
|
1537 {
|
|
1538 xhot = xpmattrs.x_hotspot;
|
|
1539 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), xpmattrs.x_hotspot);
|
|
1540 }
|
|
1541 if (xpmattrs.valuemask & XpmHotspot)
|
|
1542 {
|
|
1543 yhot = xpmattrs.y_hotspot;
|
|
1544 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), xpmattrs.y_hotspot);
|
|
1545 }
|
|
1546 check_pointer_sizes (xs, w, h, instantiator);
|
|
1547
|
|
1548 /* If the loaded pixmap has colors allocated (meaning it came from an
|
|
1549 XPM file), then use those as the default colors for the cursor we
|
|
1550 create. Otherwise, default to pointer_fg and pointer_bg.
|
|
1551 */
|
|
1552 if (npixels >= 2)
|
|
1553 {
|
|
1554 /* With an XBM file, it's obvious which bit is foreground
|
|
1555 and which is background, or rather, it's implicit: in
|
|
1556 an XBM file, a 1 bit is foreground, and a 0 bit is
|
|
1557 background.
|
185
|
1558
|
0
|
1559 XCreatePixmapCursor() assumes this property of the
|
|
1560 pixmap it is called with as well; the `foreground'
|
|
1561 color argument is used for the 1 bits.
|
|
1562
|
|
1563 With an XPM file, it's tricker, since the elements of
|
|
1564 the pixmap don't represent FG and BG, but are actual
|
|
1565 pixel values. So we need to figure out which of those
|
|
1566 pixels is the foreground color and which is the
|
|
1567 background. We do it by comparing RGB and assuming
|
|
1568 that the darker color is the foreground. This works
|
|
1569 with the result of xbmtopbm|ppmtoxpm, at least.
|
185
|
1570
|
0
|
1571 It might be nice if there was some way to tag the
|
|
1572 colors in the XPM file with whether they are the
|
|
1573 foreground - perhaps with logical color names somehow?
|
185
|
1574
|
0
|
1575 Once we have decided which color is the foreground, we
|
|
1576 need to ensure that that color corresponds to a `1' bit
|
|
1577 in the Pixmap. The XPM library wrote into the (1-bit)
|
|
1578 pixmap with XPutPixel, which will ignore all but the
|
|
1579 least significant bit.
|
185
|
1580
|
0
|
1581 This means that a 1 bit in the image corresponds to
|
|
1582 `fg' only if `fg.pixel' is odd.
|
185
|
1583
|
0
|
1584 (This also means that the image will be all the same
|
|
1585 color if both `fg' and `bg' are odd or even, but we can
|
|
1586 safely assume that that won't happen if the XPM file is
|
|
1587 sensible I think.)
|
185
|
1588
|
0
|
1589 The desired result is that the image use `1' to
|
|
1590 represent the foreground color, and `0' to represent
|
|
1591 the background color. So, we may need to invert the
|
|
1592 image to accomplish this; we invert if fg is
|
|
1593 odd. (Remember that WhitePixel and BlackPixel are not
|
|
1594 necessarily 1 and 0 respectively, though I think it
|
|
1595 might be safe to assume that one of them is always 1
|
|
1596 and the other is always 0. We also pretty much need to
|
|
1597 assume that one is even and the other is odd.)
|
|
1598 */
|
|
1599
|
|
1600 fg.pixel = pixels[0]; /* pick a pixel at random. */
|
|
1601 bg.pixel = fg.pixel;
|
|
1602 for (i = 1; i < npixels; i++) /* Look for an "other" pixel value.*/
|
|
1603 {
|
|
1604 bg.pixel = pixels[i];
|
|
1605 if (fg.pixel != bg.pixel)
|
|
1606 break;
|
|
1607 }
|
|
1608
|
|
1609 /* If (fg.pixel == bg.pixel) then probably something has
|
|
1610 gone wrong, but I don't think signalling an error would
|
|
1611 be appropriate. */
|
|
1612
|
|
1613 XQueryColor (dpy, DefaultColormapOfScreen (xs), &fg);
|
|
1614 XQueryColor (dpy, DefaultColormapOfScreen (xs), &bg);
|
|
1615
|
|
1616 /* If the foreground is lighter than the background, swap them.
|
|
1617 (This occurs semi-randomly, depending on the ordering of the
|
|
1618 color list in the XPM file.)
|
|
1619 */
|
|
1620 {
|
|
1621 unsigned short fg_total = ((fg.red / 3) + (fg.green / 3)
|
|
1622 + (fg.blue / 3));
|
|
1623 unsigned short bg_total = ((bg.red / 3) + (bg.green / 3)
|
|
1624 + (bg.blue / 3));
|
|
1625 if (fg_total > bg_total)
|
|
1626 {
|
|
1627 XColor swap;
|
|
1628 swap = fg;
|
|
1629 fg = bg;
|
|
1630 bg = swap;
|
|
1631 }
|
|
1632 }
|
185
|
1633
|
0
|
1634 /* If the fg pixel corresponds to a `0' in the bitmap, invert it.
|
|
1635 (This occurs (only?) on servers with Black=0, White=1.)
|
|
1636 */
|
|
1637 if ((fg.pixel & 1) == 0)
|
|
1638 {
|
|
1639 XGCValues gcv;
|
|
1640 GC gc;
|
|
1641 gcv.function = GXxor;
|
|
1642 gcv.foreground = 1;
|
|
1643 gc = XCreateGC (dpy, pixmap, (GCFunction | GCForeground),
|
|
1644 &gcv);
|
|
1645 XFillRectangle (dpy, pixmap, gc, 0, 0, w, h);
|
|
1646 XFreeGC (dpy, gc);
|
|
1647 }
|
|
1648 }
|
|
1649 else
|
|
1650 {
|
|
1651 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg,
|
|
1652 &fg, &bg);
|
|
1653 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg;
|
|
1654 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg;
|
|
1655 }
|
|
1656
|
|
1657 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
1658 XCreatePixmapCursor
|
|
1659 (dpy, pixmap, mask, &fg, &bg, xhot, yhot);
|
|
1660 }
|
|
1661
|
|
1662 break;
|
|
1663
|
|
1664 default:
|
|
1665 abort ();
|
|
1666 }
|
185
|
1667
|
0
|
1668 xpm_free (&xpmattrs); /* after we've read pixels and hotspot */
|
|
1669 }
|
|
1670
|
|
1671 #endif /* HAVE_XPM */
|
|
1672
|
|
1673
|
207
|
1674 #ifdef HAVE_IMAGEMAGICK
|
|
1675 /**********************************************************************
|
|
1676 * ImageMagick *
|
|
1677 **********************************************************************/
|
|
1678 static void
|
|
1679 imagick_validate (Lisp_Object instantiator)
|
|
1680 {
|
|
1681 file_or_data_must_be_present (instantiator);
|
|
1682 }
|
|
1683
|
|
1684 static Lisp_Object
|
|
1685 imagick_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1686 {
|
|
1687 return simple_image_type_normalize (inst, console_type, Qimagick);
|
|
1688 }
|
|
1689
|
|
1690 static int
|
|
1691 imagick_possible_dest_types (void)
|
|
1692 {
|
|
1693 return IMAGE_COLOR_PIXMAP_MASK;
|
|
1694 }
|
|
1695
|
|
1696 struct imagick_unwind_data
|
|
1697 {
|
|
1698 /* FIXME - what goes here...*/
|
|
1699 Display *dpy;
|
|
1700 FILE *instream;
|
|
1701 Image *image;
|
|
1702 XImage *ximage;
|
|
1703 unsigned long *pixels;
|
|
1704 unsigned long npixels;
|
|
1705 char tempfile[50];
|
|
1706 int tempfile_needs_to_be_removed;
|
|
1707 };
|
|
1708
|
|
1709 static Lisp_Object
|
|
1710 imagick_instantiate_unwind (Lisp_Object unwind_obj)
|
|
1711 {
|
|
1712 struct imagick_unwind_data *data =
|
|
1713 (struct imagick_unwind_data *) get_opaque_ptr (unwind_obj);
|
|
1714
|
|
1715 free_opaque_ptr (unwind_obj);
|
|
1716 if (data->instream)
|
|
1717 fclose (data->instream);
|
|
1718 if (data->tempfile_needs_to_be_removed)
|
|
1719 unlink (data->tempfile);
|
|
1720
|
|
1721 if (data->image) {
|
|
1722 DestroyImage(data->image);
|
|
1723 }
|
|
1724
|
|
1725 if (data->ximage)
|
|
1726 {
|
|
1727 if (data->ximage->data)
|
|
1728 {
|
|
1729 xfree (data->ximage->data);
|
|
1730 data->ximage->data = NULL;
|
|
1731 }
|
|
1732 XDestroyImage (data->ximage);
|
|
1733 }
|
|
1734
|
|
1735 return Qnil;
|
|
1736 }
|
|
1737
|
|
1738 static void XDitherImage(Image *image,XImage *ximage);
|
|
1739
|
|
1740 static void
|
|
1741 imagick_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1742 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1743 int dest_mask, Lisp_Object domain)
|
|
1744 {
|
|
1745 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1746 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1747 Display *dpy;
|
|
1748 Screen *scr;
|
|
1749 Dimension depth;
|
|
1750 struct imagick_unwind_data unwind;
|
|
1751 int speccount = specpdl_depth ();
|
|
1752 ImageInfo image_info;
|
|
1753
|
|
1754 /* ImageMagick variables */
|
|
1755
|
|
1756 /* Basic error checking */
|
|
1757 if (!DEVICE_X_P (XDEVICE (device)))
|
|
1758 signal_simple_error ("Not an X device", device);
|
|
1759
|
|
1760 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1761 scr = DefaultScreenOfDisplay (dpy);
|
|
1762 depth = DefaultDepthOfScreen (scr);
|
|
1763 /* Set up the unwind */
|
|
1764 memset (&unwind, 0, sizeof (unwind));
|
|
1765 unwind.dpy = dpy;
|
|
1766 record_unwind_protect(imagick_instantiate_unwind,make_opaque_ptr(&unwind));
|
|
1767
|
|
1768 /* Write out to a temp file - not sure if ImageMagick supports the
|
|
1769 ** notion of an abstrat 'data source' right now.
|
|
1770 */
|
|
1771 {
|
|
1772 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1773
|
|
1774 assert (!NILP (data));
|
|
1775
|
|
1776 write_lisp_string_to_temp_file (data, unwind.tempfile);
|
|
1777 unwind.tempfile_needs_to_be_removed = 1;
|
|
1778
|
|
1779 if ((unwind.instream = fopen (unwind.tempfile, "rb")) == NULL)
|
|
1780 report_file_error ("Opening ImageMagick temp file",
|
|
1781 list1 (build_string (unwind.tempfile)));
|
|
1782 }
|
|
1783
|
|
1784 /* Initialize structures and read in the image */
|
|
1785 GetImageInfo(&image_info);
|
|
1786 strcpy(image_info.filename,unwind.tempfile);
|
|
1787 unwind.image = ReadImage(&image_info);
|
|
1788 if (unwind.image == (Image *) NULL) {
|
|
1789 signal_simple_error ("Unable to read image.",instantiator);
|
|
1790 }
|
|
1791
|
|
1792 unwind.ximage = XCreateImage(dpy, DefaultVisualOfScreen (scr),
|
|
1793 depth,
|
|
1794 (depth == 1) ? XYPixmap : ZPixmap,
|
|
1795 0, 0,
|
|
1796 unwind.image->columns,
|
|
1797 unwind.image->rows,
|
|
1798 XBitmapPad(dpy), 0);
|
|
1799
|
|
1800 if (!unwind.ximage) {
|
|
1801 signal_simple_error("Unable to allocate XImage structure",
|
|
1802 instantiator);
|
|
1803 }
|
|
1804
|
|
1805 unwind.ximage->data = (char *) xmalloc(unwind.ximage->bytes_per_line *
|
|
1806 unwind.ximage->height *
|
|
1807 unwind.ximage->depth);
|
|
1808
|
|
1809 if (unwind.ximage->data == (char *)NULL) {
|
|
1810 signal_simple_error("Unable to allocate pixel information",
|
|
1811 instantiator);
|
|
1812 }
|
|
1813
|
|
1814 /* Need to pull the data from the 'Image' structure in
|
|
1815 ** unwind.image and convert it to an 'XImage' in unwind.ximage
|
|
1816 **
|
|
1817 ** FIXME IM FUCKED
|
|
1818 **
|
|
1819 ** WMP 10/30/97
|
|
1820 */
|
|
1821
|
|
1822 init_image_instance_from_x_image (ii, unwind.ximage, dest_mask,
|
|
1823 unwind.pixels, unwind.npixels,
|
|
1824 instantiator);
|
|
1825 }
|
|
1826
|
|
1827 #endif /* HAVE_IMAGEMAGICK */
|
|
1828
|
|
1829
|
0
|
1830 #ifdef HAVE_XFACE
|
|
1831
|
|
1832 /**********************************************************************
|
|
1833 * X-Face *
|
|
1834 **********************************************************************/
|
|
1835
|
|
1836 static void
|
|
1837 xface_validate (Lisp_Object instantiator)
|
|
1838 {
|
|
1839 file_or_data_must_be_present (instantiator);
|
|
1840 }
|
|
1841
|
|
1842 static Lisp_Object
|
|
1843 xface_normalize (Lisp_Object inst, Lisp_Object console_type)
|
|
1844 {
|
116
|
1845 /* This funcation can call lisp */
|
0
|
1846 Lisp_Object file = Qnil, mask_file = Qnil;
|
|
1847 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1848 Lisp_Object alist = Qnil;
|
185
|
1849
|
0
|
1850 GCPRO3 (file, mask_file, alist);
|
|
1851
|
|
1852 /* Now, convert any file data into inline data for both the regular
|
|
1853 data and the mask data. At the end of this, `data' will contain
|
|
1854 the inline data (if any) or Qnil, and `file' will contain
|
|
1855 the name this data was derived from (if known) or Qnil.
|
|
1856 Likewise for `mask_file' and `mask_data'.
|
|
1857
|
|
1858 Note that if we cannot generate any regular inline data, we
|
|
1859 skip out. */
|
|
1860
|
|
1861 file = potential_pixmap_file_instantiator (inst, Q_file, Q_data);
|
|
1862 mask_file = potential_pixmap_file_instantiator (inst, Q_mask_file,
|
|
1863 Q_mask_data);
|
|
1864
|
|
1865 if (CONSP (file)) /* failure locating filename */
|
|
1866 signal_double_file_error ("Opening bitmap file",
|
|
1867 "no such file or directory",
|
|
1868 Fcar (file));
|
|
1869
|
|
1870 if (NILP (file) && NILP (mask_file)) /* no conversion necessary */
|
|
1871 RETURN_UNGCPRO (inst);
|
|
1872
|
|
1873 alist = tagged_vector_to_alist (inst);
|
|
1874
|
|
1875 {
|
|
1876 Lisp_Object data = make_string_from_file (file);
|
|
1877 alist = remassq_no_quit (Q_file, alist);
|
|
1878 /* there can't be a :data at this point. */
|
|
1879 alist = Fcons (Fcons (Q_file, file),
|
|
1880 Fcons (Fcons (Q_data, data), alist));
|
|
1881 }
|
|
1882
|
|
1883 alist = xbm_mask_file_munging (alist, file, mask_file);
|
|
1884
|
|
1885 {
|
|
1886 Lisp_Object result = alist_to_tagged_vector (Qxface, alist);
|
|
1887 free_alist (alist);
|
|
1888 RETURN_UNGCPRO (result);
|
|
1889 }
|
|
1890 }
|
|
1891
|
|
1892 static int
|
74
|
1893 xface_possible_dest_types (void)
|
0
|
1894 {
|
74
|
1895 return
|
|
1896 IMAGE_MONO_PIXMAP_MASK |
|
|
1897 IMAGE_COLOR_PIXMAP_MASK |
|
0
|
1898 IMAGE_POINTER_MASK;
|
|
1899 }
|
|
1900
|
|
1901 #if defined(EXTERN)
|
|
1902 /* This is about to get redefined! */
|
|
1903 #undef EXTERN
|
|
1904 #endif
|
|
1905 /* We have to define SYSV32 so that compface.h includes string.h
|
|
1906 instead of strings.h. */
|
|
1907 #define SYSV32
|
185
|
1908 #ifdef __cplusplus
|
|
1909 extern "C" {
|
|
1910 #endif
|
0
|
1911 #include <compface.h>
|
185
|
1912 #ifdef __cplusplus
|
|
1913 }
|
|
1914 #endif
|
0
|
1915 /* JMP_BUF cannot be used here because if it doesn't get defined
|
|
1916 to jmp_buf we end up with a conflicting type error with the
|
|
1917 definition in compface.h */
|
|
1918 extern jmp_buf comp_env;
|
|
1919 #undef SYSV32
|
|
1920
|
|
1921 static void
|
|
1922 xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1923 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
1924 int dest_mask, Lisp_Object domain)
|
0
|
1925 {
|
|
1926 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1927 int i, stattis;
|
|
1928 char *p, *bits, *bp;
|
16
|
1929 CONST char * volatile emsg = 0;
|
|
1930 CONST char * volatile dstring;
|
0
|
1931
|
|
1932 assert (!NILP (data));
|
|
1933
|
|
1934 GET_C_STRING_BINARY_DATA_ALLOCA (data, dstring);
|
|
1935
|
|
1936 if ((p = strchr (dstring, ':')))
|
|
1937 {
|
|
1938 dstring = p + 1;
|
|
1939 }
|
|
1940
|
|
1941 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
1942 if (!(stattis = setjmp (comp_env)))
|
|
1943 {
|
|
1944 UnCompAll ((char *) dstring);
|
|
1945 UnGenFace ();
|
|
1946 }
|
|
1947
|
|
1948 switch (stattis)
|
|
1949 {
|
|
1950 case -2:
|
|
1951 emsg = "uncompface: internal error";
|
|
1952 break;
|
|
1953 case -1:
|
|
1954 emsg = "uncompface: insufficient or invalid data";
|
|
1955 break;
|
|
1956 case 1:
|
|
1957 emsg = "uncompface: excess data ignored";
|
|
1958 break;
|
|
1959 }
|
|
1960
|
|
1961 if (emsg)
|
|
1962 signal_simple_error_2 (emsg, data, Qimage);
|
|
1963
|
|
1964 bp = bits = (char *) alloca (PIXELS / 8);
|
|
1965
|
|
1966 /* the compface library exports char F[], which uses a single byte per
|
|
1967 pixel to represent a 48x48 bitmap. Yuck. */
|
|
1968 for (i = 0, p = F; i < (PIXELS / 8); ++i)
|
|
1969 {
|
|
1970 int n, b;
|
|
1971 /* reverse the bit order of each byte... */
|
|
1972 for (b = n = 0; b < 8; ++b)
|
|
1973 {
|
|
1974 n |= ((*p++) << b);
|
|
1975 }
|
|
1976 *bp++ = (char) n;
|
|
1977 }
|
|
1978
|
|
1979 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1980 pointer_bg, dest_mask, 48, 48, bits);
|
|
1981 }
|
|
1982
|
|
1983 #endif /* HAVE_XFACE */
|
|
1984
|
|
1985
|
|
1986 /**********************************************************************
|
122
|
1987 * Autodetect *
|
0
|
1988 **********************************************************************/
|
|
1989
|
|
1990 static void
|
122
|
1991 autodetect_validate (Lisp_Object instantiator)
|
0
|
1992 {
|
|
1993 data_must_be_present (instantiator);
|
|
1994 }
|
|
1995
|
|
1996 static Lisp_Object
|
122
|
1997 autodetect_normalize (Lisp_Object instantiator,
|
120
|
1998 Lisp_Object console_type)
|
0
|
1999 {
|
|
2000 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
2001 Lisp_Object filename = Qnil;
|
|
2002 Lisp_Object data = Qnil;
|
|
2003 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2004 Lisp_Object alist = Qnil;
|
|
2005
|
|
2006 GCPRO3 (filename, data, alist);
|
|
2007
|
|
2008 if (NILP (file)) /* no conversion necessary */
|
|
2009 RETURN_UNGCPRO (instantiator);
|
|
2010
|
|
2011 alist = tagged_vector_to_alist (instantiator);
|
|
2012
|
|
2013 filename = locate_pixmap_file (file);
|
|
2014 if (!NILP (filename))
|
|
2015 {
|
|
2016 int xhot, yhot;
|
|
2017 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
2018 called by pixmap_to_lisp_data, don't return an error value
|
|
2019 if the given file is not a valid XPM file. Instead, they
|
|
2020 just seg fault. It is definitely caused by passing a
|
|
2021 bitmap. To try and avoid this we check for bitmaps first. */
|
185
|
2022
|
0
|
2023 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
2024
|
|
2025 if (!EQ (data, Qt))
|
|
2026 {
|
|
2027 alist = remassq_no_quit (Q_data, alist);
|
|
2028 alist = Fcons (Fcons (Q_file, filename),
|
|
2029 Fcons (Fcons (Q_data, data), alist));
|
|
2030 if (xhot != -1)
|
|
2031 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
2032 alist);
|
|
2033 if (yhot != -1)
|
|
2034 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
2035 alist);
|
|
2036
|
|
2037 alist = xbm_mask_file_munging (alist, filename, Qnil);
|
|
2038
|
|
2039 {
|
|
2040 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
2041 free_alist (alist);
|
|
2042 RETURN_UNGCPRO (result);
|
|
2043 }
|
|
2044 }
|
|
2045
|
|
2046 #ifdef HAVE_XPM
|
|
2047 data = pixmap_to_lisp_data (filename, 1);
|
|
2048
|
|
2049 if (!EQ (data, Qt))
|
|
2050 {
|
|
2051 alist = remassq_no_quit (Q_data, alist);
|
|
2052 alist = Fcons (Fcons (Q_file, filename),
|
|
2053 Fcons (Fcons (Q_data, data), alist));
|
|
2054 alist = Fcons (Fcons (Q_color_symbols,
|
|
2055 evaluate_xpm_color_symbols ()),
|
|
2056 alist);
|
|
2057 {
|
|
2058 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
2059 free_alist (alist);
|
|
2060 RETURN_UNGCPRO (result);
|
|
2061 }
|
|
2062 }
|
|
2063 #endif
|
|
2064 }
|
|
2065
|
|
2066 /* If we couldn't convert it, just put it back as it is.
|
|
2067 We might try to further frob it later as a cursor-font
|
|
2068 specification. (We can't do that now because we don't know
|
|
2069 what dest-types it's going to be instantiated into.) */
|
|
2070 {
|
122
|
2071 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
0
|
2072 free_alist (alist);
|
|
2073 RETURN_UNGCPRO (result);
|
|
2074 }
|
|
2075 }
|
|
2076
|
|
2077 static int
|
122
|
2078 autodetect_possible_dest_types (void)
|
0
|
2079 {
|
74
|
2080 return
|
|
2081 IMAGE_MONO_PIXMAP_MASK |
|
|
2082 IMAGE_COLOR_PIXMAP_MASK |
|
|
2083 IMAGE_POINTER_MASK |
|
|
2084 IMAGE_TEXT_MASK;
|
0
|
2085 }
|
|
2086
|
|
2087 static void
|
122
|
2088 autodetect_instantiate (Lisp_Object image_instance,
|
120
|
2089 Lisp_Object instantiator,
|
|
2090 Lisp_Object pointer_fg,
|
|
2091 Lisp_Object pointer_bg,
|
124
|
2092 int dest_mask, Lisp_Object domain)
|
0
|
2093 {
|
|
2094 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
2095 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2096 Lisp_Object alist = Qnil;
|
|
2097 Lisp_Object result = Qnil;
|
|
2098 int is_cursor_font = 0;
|
|
2099
|
|
2100 GCPRO3 (data, alist, result);
|
|
2101
|
|
2102 alist = tagged_vector_to_alist (instantiator);
|
|
2103 if (dest_mask & IMAGE_POINTER_MASK)
|
|
2104 {
|
|
2105 CONST char *name_ext;
|
|
2106 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext);
|
|
2107 if (XmuCursorNameToIndex (name_ext) != -1)
|
|
2108 {
|
|
2109 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
2110 is_cursor_font = 1;
|
|
2111 }
|
|
2112 }
|
|
2113
|
|
2114 if (!is_cursor_font)
|
|
2115 result = alist_to_tagged_vector (Qstring, alist);
|
|
2116 free_alist (alist);
|
|
2117
|
|
2118 if (is_cursor_font)
|
|
2119 cursor_font_instantiate (image_instance, result, pointer_fg,
|
124
|
2120 pointer_bg, dest_mask, domain);
|
0
|
2121 else
|
|
2122 string_instantiate (image_instance, result, pointer_fg,
|
124
|
2123 pointer_bg, dest_mask, domain);
|
0
|
2124
|
|
2125 UNGCPRO;
|
|
2126 }
|
|
2127
|
|
2128
|
|
2129 /**********************************************************************
|
|
2130 * Font *
|
|
2131 **********************************************************************/
|
|
2132
|
|
2133 static void
|
|
2134 font_validate (Lisp_Object instantiator)
|
|
2135 {
|
|
2136 data_must_be_present (instantiator);
|
|
2137 }
|
|
2138
|
|
2139 /* XmuCvtStringToCursor is bogus in the following ways:
|
|
2140
|
|
2141 - When it can't convert the given string to a real cursor, it will
|
|
2142 sometimes return a "success" value, after triggering a BadPixmap
|
|
2143 error. It then gives you a cursor that will itself generate BadCursor
|
|
2144 errors. So we install this error handler to catch/notice the X error
|
|
2145 and take that as meaning "couldn't convert."
|
|
2146
|
|
2147 - When you tell it to find a cursor file that doesn't exist, it prints
|
|
2148 an error message on stderr. You can't make it not do that.
|
|
2149
|
|
2150 - Also, using Xmu means we can't properly hack Lisp_Image_Instance
|
|
2151 objects, or XPM files, or $XBMLANGPATH.
|
|
2152 */
|
|
2153
|
|
2154 /* Duplicate the behavior of XmuCvtStringToCursor() to bypass its bogusness. */
|
|
2155
|
|
2156 static int XLoadFont_got_error;
|
|
2157
|
|
2158 static int
|
|
2159 XLoadFont_error_handler (Display *dpy, XErrorEvent *xerror)
|
|
2160 {
|
|
2161 XLoadFont_got_error = 1;
|
|
2162 return 0;
|
|
2163 }
|
|
2164
|
|
2165 static Font
|
|
2166 safe_XLoadFont (Display *dpy, char *name)
|
|
2167 {
|
|
2168 Font font;
|
|
2169 int (*old_handler) (Display *, XErrorEvent *);
|
|
2170 XLoadFont_got_error = 0;
|
|
2171 XSync (dpy, 0);
|
|
2172 old_handler = XSetErrorHandler (XLoadFont_error_handler);
|
|
2173 font = XLoadFont (dpy, name);
|
|
2174 XSync (dpy, 0);
|
|
2175 XSetErrorHandler (old_handler);
|
|
2176 if (XLoadFont_got_error) return 0;
|
|
2177 return font;
|
|
2178 }
|
|
2179
|
|
2180 static int
|
74
|
2181 font_possible_dest_types (void)
|
0
|
2182 {
|
|
2183 return IMAGE_POINTER_MASK;
|
|
2184 }
|
|
2185
|
|
2186 static void
|
|
2187 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2188 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
2189 int dest_mask, Lisp_Object domain)
|
0
|
2190 {
|
|
2191 /* This function can GC */
|
|
2192 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
2193 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2194 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
2195 Display *dpy;
|
|
2196 XColor fg, bg;
|
|
2197 Font source, mask;
|
|
2198 char source_name[MAXPATHLEN], mask_name[MAXPATHLEN], dummy;
|
|
2199 int source_char, mask_char;
|
|
2200 int count;
|
|
2201 Lisp_Object foreground, background;
|
|
2202
|
|
2203 if (!DEVICE_X_P (XDEVICE (device)))
|
|
2204 signal_simple_error ("Not an X device", device);
|
|
2205
|
|
2206 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
2207
|
|
2208 if (!STRINGP (data) ||
|
14
|
2209 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
0
|
2210 signal_simple_error ("Invalid font-glyph instantiator",
|
|
2211 instantiator);
|
|
2212
|
|
2213 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
2214 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
2215
|
|
2216 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
2217 if (NILP (foreground))
|
|
2218 foreground = pointer_fg;
|
|
2219 background = find_keyword_in_vector (instantiator, Q_background);
|
|
2220 if (NILP (background))
|
|
2221 background = pointer_bg;
|
|
2222
|
|
2223 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
2224
|
14
|
2225 count = sscanf ((char *) XSTRING_DATA (data),
|
0
|
2226 "FONT %s %d %s %d %c",
|
|
2227 source_name, &source_char,
|
|
2228 mask_name, &mask_char, &dummy);
|
|
2229 /* Allow "%s %d %d" as well... */
|
|
2230 if (count == 3 && (1 == sscanf (mask_name, "%d %c", &mask_char, &dummy)))
|
|
2231 count = 4, mask_name[0] = 0;
|
|
2232
|
|
2233 if (count != 2 && count != 4)
|
|
2234 signal_simple_error ("invalid cursor specification", data);
|
|
2235 source = safe_XLoadFont (dpy, source_name);
|
|
2236 if (! source)
|
|
2237 signal_simple_error_2 ("couldn't load font",
|
|
2238 build_string (source_name),
|
|
2239 data);
|
|
2240 if (count == 2)
|
|
2241 mask = 0;
|
|
2242 else if (!mask_name[0])
|
|
2243 mask = source;
|
|
2244 else
|
|
2245 {
|
|
2246 mask = safe_XLoadFont (dpy, mask_name);
|
|
2247 if (!mask)
|
|
2248 /* continuable */
|
|
2249 Fsignal (Qerror, list3 (build_string ("couldn't load font"),
|
|
2250 build_string (mask_name), data));
|
|
2251 }
|
|
2252 if (!mask)
|
|
2253 mask_char = 0;
|
|
2254
|
|
2255 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
2256
|
|
2257 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER);
|
|
2258 IMAGE_INSTANCE_X_CURSOR (ii) =
|
|
2259 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
2260 &fg, &bg);
|
|
2261 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
2262 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
2263 XUnloadFont (dpy, source);
|
|
2264 if (mask && mask != source) XUnloadFont (dpy, mask);
|
|
2265 }
|
|
2266
|
|
2267
|
|
2268 /**********************************************************************
|
|
2269 * Cursor-Font *
|
|
2270 **********************************************************************/
|
|
2271
|
|
2272 static void
|
|
2273 cursor_font_validate (Lisp_Object instantiator)
|
|
2274 {
|
|
2275 data_must_be_present (instantiator);
|
|
2276 }
|
|
2277
|
|
2278 static int
|
74
|
2279 cursor_font_possible_dest_types (void)
|
0
|
2280 {
|
|
2281 return IMAGE_POINTER_MASK;
|
|
2282 }
|
|
2283
|
|
2284 static void
|
|
2285 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2286 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
124
|
2287 int dest_mask, Lisp_Object domain)
|
0
|
2288 {
|
|
2289 /* This function can GC */
|
|
2290 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
2291 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2292 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
2293 Display *dpy;
|
|
2294 int i;
|
|
2295 CONST char *name_ext;
|
|
2296 Lisp_Object foreground, background;
|
|
2297
|
|
2298 if (!DEVICE_X_P (XDEVICE (device)))
|
|
2299 signal_simple_error ("Not an X device", device);
|
|
2300
|
|
2301 dpy = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
2302
|
|
2303 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
2304 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
2305
|
|
2306 GET_C_STRING_FILENAME_DATA_ALLOCA (data, name_ext);
|
|
2307 if ((i = XmuCursorNameToIndex (name_ext)) == -1)
|
|
2308 signal_simple_error ("Unrecognized cursor-font name", data);
|
|
2309
|
|
2310 x_initialize_pixmap_image_instance (ii, IMAGE_POINTER);
|
|
2311 IMAGE_INSTANCE_X_CURSOR (ii) = XCreateFontCursor (dpy, i);
|
|
2312 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
2313 if (NILP (foreground))
|
|
2314 foreground = pointer_fg;
|
|
2315 background = find_keyword_in_vector (instantiator, Q_background);
|
|
2316 if (NILP (background))
|
|
2317 background = pointer_bg;
|
|
2318 maybe_recolor_cursor (image_instance, foreground, background);
|
|
2319 }
|
|
2320
|
|
2321 static int
|
|
2322 x_colorize_image_instance (Lisp_Object image_instance,
|
|
2323 Lisp_Object foreground, Lisp_Object background)
|
|
2324 {
|
|
2325 struct Lisp_Image_Instance *p;
|
|
2326
|
|
2327 p = XIMAGE_INSTANCE (image_instance);
|
|
2328
|
|
2329 switch (IMAGE_INSTANCE_TYPE (p))
|
|
2330 {
|
|
2331 case IMAGE_MONO_PIXMAP:
|
|
2332 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
2333 /* Make sure there aren't two pointers to the same mask, causing
|
|
2334 it to get freed twice. */
|
|
2335 IMAGE_INSTANCE_X_MASK (p) = 0;
|
|
2336 break;
|
|
2337
|
|
2338 default:
|
|
2339 return 0;
|
|
2340 }
|
|
2341
|
|
2342 {
|
|
2343 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
2344 Screen *scr = DefaultScreenOfDisplay (dpy);
|
|
2345 Dimension d = DefaultDepthOfScreen (scr);
|
|
2346 Pixmap new = XCreatePixmap (dpy, RootWindowOfScreen (scr),
|
|
2347 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2348 IMAGE_INSTANCE_PIXMAP_HEIGHT (p), d);
|
|
2349 XColor color;
|
|
2350 XGCValues gcv;
|
|
2351 GC gc;
|
|
2352 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (foreground));
|
|
2353 gcv.foreground = color.pixel;
|
|
2354 color = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (background));
|
|
2355 gcv.background = color.pixel;
|
|
2356 gc = XCreateGC (dpy, new, GCBackground|GCForeground, &gcv);
|
|
2357 XCopyPlane (dpy, IMAGE_INSTANCE_X_PIXMAP (p), new, gc, 0, 0,
|
|
2358 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2359 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2360 0, 0, 1);
|
|
2361 XFreeGC (dpy, gc);
|
|
2362 IMAGE_INSTANCE_X_PIXMAP (p) = new;
|
|
2363 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = d;
|
|
2364 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
2365 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
2366 return 1;
|
|
2367 }
|
|
2368 }
|
|
2369
|
|
2370
|
114
|
2371 #if HAVE_SUBWINDOWS
|
0
|
2372 /************************************************************************/
|
|
2373 /* subwindows */
|
|
2374 /************************************************************************/
|
|
2375
|
|
2376 Lisp_Object Qsubwindowp;
|
|
2377 static Lisp_Object mark_subwindow (Lisp_Object, void (*) (Lisp_Object));
|
|
2378 static void print_subwindow (Lisp_Object, Lisp_Object, int);
|
|
2379 static void finalize_subwindow (void *, int);
|
|
2380 static int subwindow_equal (Lisp_Object o1, Lisp_Object o2, int depth);
|
|
2381 static unsigned long subwindow_hash (Lisp_Object obj, int depth);
|
|
2382 DEFINE_LRECORD_IMPLEMENTATION ("subwindow", subwindow,
|
|
2383 mark_subwindow, print_subwindow,
|
|
2384 finalize_subwindow, subwindow_equal,
|
|
2385 subwindow_hash, struct Lisp_Subwindow);
|
|
2386
|
|
2387 static Lisp_Object
|
|
2388 mark_subwindow (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2389 {
|
|
2390 struct Lisp_Subwindow *sw = XSUBWINDOW (obj);
|
|
2391 return sw->frame;
|
|
2392 }
|
|
2393
|
|
2394 static void
|
|
2395 print_subwindow (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
2396 {
|
|
2397 char buf[100];
|
|
2398 struct Lisp_Subwindow *sw = XSUBWINDOW (obj);
|
|
2399 struct frame *frm = XFRAME (sw->frame);
|
|
2400
|
|
2401 if (print_readably)
|
|
2402 error ("printing unreadable object #<subwindow 0x%x>",
|
|
2403 sw->header.uid);
|
|
2404
|
|
2405 write_c_string ("#<subwindow", printcharfun);
|
|
2406 sprintf (buf, " %dx%d", sw->width, sw->height);
|
|
2407 write_c_string (buf, printcharfun);
|
|
2408
|
|
2409 /* This is stolen from frame.c. Subwindows are strange in that they
|
|
2410 are specific to a particular frame so we want to print in their
|
|
2411 description what that frame is. */
|
185
|
2412
|
0
|
2413 write_c_string (" on #<", printcharfun);
|
|
2414 if (!FRAME_LIVE_P (frm))
|
|
2415 write_c_string ("dead", printcharfun);
|
|
2416 else if (FRAME_TTY_P (frm))
|
|
2417 write_c_string ("tty", printcharfun);
|
|
2418 else if (FRAME_X_P (frm))
|
|
2419 write_c_string ("x", printcharfun);
|
|
2420 else
|
|
2421 write_c_string ("UNKNOWN", printcharfun);
|
|
2422 write_c_string ("-frame ", printcharfun);
|
|
2423 print_internal (frm->name, printcharfun, 1);
|
|
2424 sprintf (buf, " 0x%x>", frm->header.uid);
|
|
2425 write_c_string (buf, printcharfun);
|
|
2426
|
|
2427 sprintf (buf, ") 0x%x>", sw->header.uid);
|
|
2428 write_c_string (buf, printcharfun);
|
|
2429 }
|
|
2430
|
|
2431 static void
|
|
2432 finalize_subwindow (void *header, int for_disksave)
|
|
2433 {
|
|
2434 struct Lisp_Subwindow *sw = (struct Lisp_Subwindow *) header;
|
|
2435 if (for_disksave) finalose (sw);
|
|
2436 if (sw->subwindow)
|
|
2437 {
|
|
2438 XDestroyWindow (DisplayOfScreen (sw->xscreen), sw->subwindow);
|
|
2439 sw->subwindow = 0;
|
|
2440 }
|
|
2441 }
|
|
2442
|
|
2443 /* subwindows are equal iff they have the same window XID */
|
|
2444 static int
|
|
2445 subwindow_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
2446 {
|
|
2447 return (XSUBWINDOW (o1)->subwindow == XSUBWINDOW (o2)->subwindow);
|
|
2448 }
|
|
2449
|
|
2450 static unsigned long
|
|
2451 subwindow_hash (Lisp_Object obj, int depth)
|
|
2452 {
|
|
2453 return XSUBWINDOW (obj)->subwindow;
|
|
2454 }
|
|
2455
|
|
2456 /* #### PROBLEM: The display routines assume that the glyph is only
|
|
2457 being displayed in one buffer. If it is in two different buffers
|
|
2458 which are both being displayed simultaneously you will lose big time.
|
|
2459 This can be dealt with in the new redisplay. */
|
|
2460
|
70
|
2461 /* #### These are completely un-re-implemented in 19.14. Get it done
|
|
2462 for 19.15. */
|
0
|
2463
|
20
|
2464 DEFUN ("make-subwindow", Fmake_subwindow, 0, 3, 0, /*
|
0
|
2465 Creates a new `subwindow' object of size WIDTH x HEIGHT.
|
|
2466 The default is a window of size 1x1, which is also the minimum allowed
|
|
2467 window size. Subwindows are per-frame. A buffer being shown in two
|
|
2468 different frames will only display a subwindow glyph in the frame in
|
|
2469 which it was actually created. If two windows on the same frame are
|
|
2470 displaying the buffer then the most recently used window will actually
|
|
2471 display the window. If the frame is not specified, the selected frame
|
|
2472 is used.
|
|
2473
|
|
2474 Subwindows are not currently implemented.
|
20
|
2475 */
|
|
2476 (width, height, frame))
|
0
|
2477 {
|
|
2478 Display *dpy;
|
|
2479 Screen *xs;
|
|
2480 Window pw;
|
|
2481 struct frame *f;
|
|
2482 unsigned int iw, ih;
|
|
2483 XSetWindowAttributes xswa;
|
|
2484 Mask valueMask = 0;
|
|
2485
|
140
|
2486 error ("subwindows are not functional in 20.2; they may be again someday");
|
0
|
2487
|
|
2488 f = decode_x_frame (frame);
|
|
2489
|
|
2490 xs = LISP_DEVICE_TO_X_SCREEN (FRAME_DEVICE (f));
|
|
2491 dpy = DisplayOfScreen (xs);
|
|
2492 pw = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
2493
|
|
2494 if (NILP (width))
|
|
2495 iw = 1;
|
|
2496 else
|
|
2497 {
|
|
2498 CHECK_INT (width);
|
|
2499 iw = XINT (width);
|
|
2500 if (iw < 1) iw = 1;
|
|
2501 }
|
|
2502 if (NILP (height))
|
|
2503 ih = 1;
|
|
2504 else
|
|
2505 {
|
|
2506 CHECK_INT (height);
|
|
2507 ih = XINT (height);
|
|
2508 if (ih < 1) ih = 1;
|
|
2509 }
|
|
2510
|
|
2511 {
|
185
|
2512 struct Lisp_Subwindow *sw =
|
|
2513 alloc_lcrecord_type (struct Lisp_Subwindow, lrecord_subwindow);
|
0
|
2514 Lisp_Object val;
|
|
2515 sw->frame = frame;
|
|
2516 sw->xscreen = xs;
|
|
2517 sw->parent_window = pw;
|
|
2518 sw->height = ih;
|
|
2519 sw->width = iw;
|
|
2520
|
|
2521 xswa.backing_store = Always;
|
|
2522 valueMask |= CWBackingStore;
|
|
2523
|
|
2524 xswa.colormap = DefaultColormapOfScreen (xs);
|
|
2525 valueMask |= CWColormap;
|
|
2526
|
|
2527 sw->subwindow = XCreateWindow (dpy, pw, 0, 0, iw, ih, 0, CopyFromParent,
|
|
2528 InputOutput, CopyFromParent, valueMask,
|
|
2529 &xswa);
|
|
2530
|
|
2531 XSETSUBWINDOW (val, sw);
|
|
2532 return val;
|
|
2533 }
|
|
2534 }
|
|
2535
|
|
2536 /* #### Should this function exist? */
|
20
|
2537 DEFUN ("change-subwindow-property", Fchange_subwindow_property, 3, 3, 0, /*
|
0
|
2538 For the given SUBWINDOW, set PROPERTY to DATA, which is a string.
|
|
2539 Subwindows are not currently implemented.
|
20
|
2540 */
|
|
2541 (subwindow, property, data))
|
0
|
2542 {
|
|
2543 Atom property_atom;
|
|
2544 struct Lisp_Subwindow *sw;
|
|
2545 Display *dpy;
|
|
2546
|
|
2547 CHECK_SUBWINDOW (subwindow);
|
|
2548 CHECK_STRING (property);
|
|
2549 CHECK_STRING (data);
|
|
2550
|
|
2551 sw = XSUBWINDOW (subwindow);
|
|
2552 dpy = DisplayOfScreen (LISP_DEVICE_TO_X_SCREEN
|
|
2553 (FRAME_DEVICE (XFRAME (sw->frame))));
|
|
2554
|
16
|
2555 property_atom = XInternAtom (dpy, (char *) XSTRING_DATA (property), False);
|
0
|
2556 XChangeProperty (dpy, sw->subwindow, property_atom, XA_STRING, 8,
|
16
|
2557 PropModeReplace,
|
|
2558 XSTRING_DATA (data),
|
14
|
2559 XSTRING_LENGTH (data));
|
0
|
2560
|
|
2561 return (property);
|
|
2562 }
|
|
2563
|
20
|
2564 DEFUN ("subwindowp", Fsubwindowp, 1, 1, 0, /*
|
0
|
2565 Return non-nil if OBJECT is a subwindow.
|
|
2566 Subwindows are not currently implemented.
|
20
|
2567 */
|
|
2568 (object))
|
0
|
2569 {
|
|
2570 return (SUBWINDOWP (object) ? Qt : Qnil);
|
|
2571 }
|
|
2572
|
20
|
2573 DEFUN ("subwindow-width", Fsubwindow_width, 1, 1, 0, /*
|
0
|
2574 Width of SUBWINDOW.
|
|
2575 Subwindows are not currently implemented.
|
20
|
2576 */
|
|
2577 (subwindow))
|
0
|
2578 {
|
|
2579 CHECK_SUBWINDOW (subwindow);
|
|
2580 return (make_int (XSUBWINDOW (subwindow)->width));
|
|
2581 }
|
|
2582
|
20
|
2583 DEFUN ("subwindow-height", Fsubwindow_height, 1, 1, 0, /*
|
0
|
2584 Height of SUBWINDOW.
|
|
2585 Subwindows are not currently implemented.
|
20
|
2586 */
|
|
2587 (subwindow))
|
0
|
2588 {
|
|
2589 CHECK_SUBWINDOW (subwindow);
|
|
2590 return (make_int (XSUBWINDOW (subwindow)->height));
|
|
2591 }
|
|
2592
|
20
|
2593 DEFUN ("subwindow-xid", Fsubwindow_xid, 1, 1, 0, /*
|
0
|
2594 Return the xid of SUBWINDOW as a number.
|
|
2595 Subwindows are not currently implemented.
|
20
|
2596 */
|
|
2597 (subwindow))
|
0
|
2598 {
|
|
2599 CHECK_SUBWINDOW (subwindow);
|
|
2600 return (make_int (XSUBWINDOW (subwindow)->subwindow));
|
|
2601 }
|
|
2602
|
20
|
2603 DEFUN ("resize-subwindow", Fresize_subwindow, 1, 3, 0, /*
|
0
|
2604 Resize SUBWINDOW to WIDTH x HEIGHT.
|
|
2605 If a value is nil that parameter is not changed.
|
|
2606 Subwindows are not currently implemented.
|
20
|
2607 */
|
|
2608 (subwindow, width, height))
|
0
|
2609 {
|
|
2610 int neww, newh;
|
|
2611 struct Lisp_Subwindow *sw;
|
|
2612
|
|
2613 CHECK_SUBWINDOW (subwindow);
|
|
2614 sw = XSUBWINDOW (subwindow);
|
|
2615
|
|
2616 if (NILP (width))
|
|
2617 neww = sw->width;
|
|
2618 else
|
|
2619 neww = XINT (width);
|
|
2620
|
|
2621 if (NILP (height))
|
|
2622 newh = sw->height;
|
|
2623 else
|
|
2624 newh = XINT (height);
|
|
2625
|
|
2626 XResizeWindow (DisplayOfScreen (sw->xscreen), sw->subwindow, neww, newh);
|
|
2627
|
|
2628 sw->height = newh;
|
|
2629 sw->width = neww;
|
|
2630
|
|
2631 return subwindow;
|
|
2632 }
|
|
2633
|
20
|
2634 DEFUN ("force-subwindow-map", Fforce_subwindow_map, 1, 1, 0, /*
|
0
|
2635 Generate a Map event for SUBWINDOW.
|
|
2636 Subwindows are not currently implemented.
|
20
|
2637 */
|
|
2638 (subwindow))
|
0
|
2639 {
|
|
2640 CHECK_SUBWINDOW (subwindow);
|
|
2641
|
|
2642 XMapWindow (DisplayOfScreen (XSUBWINDOW (subwindow)->xscreen),
|
|
2643 XSUBWINDOW (subwindow)->subwindow);
|
|
2644
|
|
2645 return subwindow;
|
|
2646 }
|
114
|
2647 #endif
|
0
|
2648
|
|
2649 /************************************************************************/
|
|
2650 /* initialization */
|
|
2651 /************************************************************************/
|
|
2652
|
|
2653 void
|
|
2654 syms_of_glyphs_x (void)
|
|
2655 {
|
114
|
2656 #if HAVE_SUBWINDOWS
|
0
|
2657 defsymbol (&Qsubwindowp, "subwindowp");
|
|
2658
|
20
|
2659 DEFSUBR (Fmake_subwindow);
|
|
2660 DEFSUBR (Fchange_subwindow_property);
|
|
2661 DEFSUBR (Fsubwindowp);
|
|
2662 DEFSUBR (Fsubwindow_width);
|
|
2663 DEFSUBR (Fsubwindow_height);
|
|
2664 DEFSUBR (Fsubwindow_xid);
|
|
2665 DEFSUBR (Fresize_subwindow);
|
|
2666 DEFSUBR (Fforce_subwindow_map);
|
114
|
2667 #endif
|
0
|
2668
|
|
2669 defkeyword (&Q_mask_file, ":mask-file");
|
|
2670 defkeyword (&Q_mask_data, ":mask-data");
|
|
2671 defkeyword (&Q_hotspot_x, ":hotspot-x");
|
|
2672 defkeyword (&Q_hotspot_y, ":hotspot-y");
|
|
2673 defkeyword (&Q_foreground, ":foreground");
|
|
2674 defkeyword (&Q_background, ":background");
|
|
2675
|
|
2676 #ifdef HAVE_XPM
|
|
2677 defkeyword (&Q_color_symbols, ":color-symbols");
|
|
2678 #endif
|
|
2679 }
|
|
2680
|
|
2681 void
|
|
2682 console_type_create_glyphs_x (void)
|
|
2683 {
|
|
2684 /* image methods */
|
|
2685
|
|
2686 CONSOLE_HAS_METHOD (x, print_image_instance);
|
|
2687 CONSOLE_HAS_METHOD (x, finalize_image_instance);
|
|
2688 CONSOLE_HAS_METHOD (x, image_instance_equal);
|
|
2689 CONSOLE_HAS_METHOD (x, image_instance_hash);
|
|
2690 CONSOLE_HAS_METHOD (x, colorize_image_instance);
|
|
2691 }
|
|
2692
|
|
2693 void
|
|
2694 image_instantiator_format_create_glyphs_x (void)
|
|
2695 {
|
|
2696 /* image-instantiator types */
|
|
2697
|
|
2698 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xbm, "xbm");
|
|
2699
|
|
2700 IIFORMAT_HAS_METHOD (xbm, validate);
|
|
2701 IIFORMAT_HAS_METHOD (xbm, normalize);
|
|
2702 IIFORMAT_HAS_METHOD (xbm, possible_dest_types);
|
|
2703 IIFORMAT_HAS_METHOD (xbm, instantiate);
|
|
2704
|
|
2705 IIFORMAT_VALID_KEYWORD (xbm, Q_data, check_valid_xbm_inline);
|
|
2706 IIFORMAT_VALID_KEYWORD (xbm, Q_file, check_valid_string);
|
|
2707 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_data, check_valid_xbm_inline);
|
|
2708 IIFORMAT_VALID_KEYWORD (xbm, Q_mask_file, check_valid_string);
|
|
2709 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_x, check_valid_int);
|
|
2710 IIFORMAT_VALID_KEYWORD (xbm, Q_hotspot_y, check_valid_int);
|
|
2711 IIFORMAT_VALID_KEYWORD (xbm, Q_foreground, check_valid_string);
|
|
2712 IIFORMAT_VALID_KEYWORD (xbm, Q_background, check_valid_string);
|
|
2713
|
|
2714 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
2715
|
|
2716 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
2717 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
2718 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
2719
|
|
2720 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
2721 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
2722 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
2723
|
|
2724 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
2725
|
|
2726 IIFORMAT_HAS_METHOD (font, validate);
|
|
2727 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
2728 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
2729
|
|
2730 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
2731 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
2732 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
2733
|
207
|
2734 #ifdef HAVE_IMAGEMAGICK
|
|
2735 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (imagick, "imagick");
|
|
2736
|
|
2737 IIFORMAT_HAS_METHOD (imagick, validate);
|
|
2738 IIFORMAT_HAS_METHOD (imagick, normalize);
|
|
2739 IIFORMAT_HAS_METHOD (imagick, possible_dest_types);
|
|
2740 IIFORMAT_HAS_METHOD (imagick, instantiate);
|
|
2741
|
|
2742 IIFORMAT_VALID_KEYWORD (imagick, Q_data, check_valid_string);
|
|
2743 IIFORMAT_VALID_KEYWORD (imagick, Q_file, check_valid_string);
|
0
|
2744 #endif
|
|
2745
|
|
2746 #ifdef HAVE_XPM
|
|
2747 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xpm, "xpm");
|
|
2748
|
|
2749 IIFORMAT_HAS_METHOD (xpm, validate);
|
|
2750 IIFORMAT_HAS_METHOD (xpm, normalize);
|
|
2751 IIFORMAT_HAS_METHOD (xpm, possible_dest_types);
|
|
2752 IIFORMAT_HAS_METHOD (xpm, instantiate);
|
|
2753
|
|
2754 IIFORMAT_VALID_KEYWORD (xpm, Q_data, check_valid_string);
|
|
2755 IIFORMAT_VALID_KEYWORD (xpm, Q_file, check_valid_string);
|
|
2756 IIFORMAT_VALID_KEYWORD (xpm, Q_color_symbols, check_valid_xpm_color_symbols);
|
|
2757 #endif
|
|
2758
|
|
2759 #ifdef HAVE_XFACE
|
|
2760 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (xface, "xface");
|
|
2761
|
|
2762 IIFORMAT_HAS_METHOD (xface, validate);
|
|
2763 IIFORMAT_HAS_METHOD (xface, normalize);
|
|
2764 IIFORMAT_HAS_METHOD (xface, possible_dest_types);
|
|
2765 IIFORMAT_HAS_METHOD (xface, instantiate);
|
|
2766
|
|
2767 IIFORMAT_VALID_KEYWORD (xface, Q_data, check_valid_string);
|
|
2768 IIFORMAT_VALID_KEYWORD (xface, Q_file, check_valid_string);
|
|
2769 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_x, check_valid_int);
|
|
2770 IIFORMAT_VALID_KEYWORD (xface, Q_hotspot_y, check_valid_int);
|
|
2771 IIFORMAT_VALID_KEYWORD (xface, Q_foreground, check_valid_string);
|
|
2772 IIFORMAT_VALID_KEYWORD (xface, Q_background, check_valid_string);
|
185
|
2773 #endif
|
0
|
2774
|
122
|
2775 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect,
|
|
2776 "autodetect");
|
|
2777
|
|
2778 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
2779 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
2780 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
|
2781 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
2782
|
|
2783 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
0
|
2784 }
|
|
2785
|
|
2786 void
|
|
2787 vars_of_glyphs_x (void)
|
|
2788 {
|
|
2789 #ifdef HAVE_XPM
|
|
2790 Fprovide (Qxpm);
|
|
2791
|
|
2792 DEFVAR_LISP ("xpm-color-symbols", &Vxpm_color_symbols /*
|
|
2793 Definitions of logical color-names used when reading XPM files.
|
|
2794 Elements of this list should be of the form (COLOR-NAME FORM-TO-EVALUATE).
|
|
2795 The COLOR-NAME should be a string, which is the name of the color to define;
|
|
2796 the FORM should evaluate to a `color' specifier object, or a string to be
|
|
2797 passed to `make-color-instance'. If a loaded XPM file references a symbolic
|
|
2798 color called COLOR-NAME, it will display as the computed color instead.
|
|
2799
|
|
2800 The default value of this variable defines the logical color names
|
|
2801 \"foreground\" and \"background\" to be the colors of the `default' face.
|
|
2802 */ );
|
|
2803 Vxpm_color_symbols = Qnil; /* initialized in x-faces.el */
|
185
|
2804 #endif
|
0
|
2805
|
207
|
2806 #ifdef HAVE_IMAGEMAGICK
|
|
2807 Fprovide (Qimagick);
|
|
2808 #endif
|
|
2809
|
0
|
2810 #ifdef HAVE_XFACE
|
|
2811 Fprovide (Qxface);
|
185
|
2812 #endif
|
0
|
2813
|
|
2814 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path /*
|
|
2815 A list of the directories in which X bitmap files may be found.
|
185
|
2816 If nil, this is initialized from the "*bitmapFilePath" resource.
|
0
|
2817 This is used by the `make-image-instance' function (however, note that if
|
|
2818 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
2819 */ );
|
|
2820 Vx_bitmap_file_path = Qnil;
|
|
2821 }
|
|
2822
|
|
2823 void
|
|
2824 complex_vars_of_glyphs_x (void)
|
|
2825 {
|
|
2826 #define BUILD_GLYPH_INST(variable, name) \
|
|
2827 Fadd_spec_to_specifier \
|
|
2828 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
2829 vector3 (Qxbm, Q_data, \
|
|
2830 list3 (make_int (name##_width), \
|
|
2831 make_int (name##_height), \
|
|
2832 make_ext_string (name##_bits, \
|
|
2833 sizeof (name##_bits), \
|
|
2834 FORMAT_BINARY))), \
|
|
2835 Qglobal, Qx, Qnil)
|
|
2836
|
|
2837 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
2838 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
2839 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
74
|
2840 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
0
|
2841
|
|
2842 #undef BUILD_GLYPH_INST
|
|
2843 }
|