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