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