714
|
1 /* GTK-specific Lisp objects.
|
462
|
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
|
800
|
5 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing
|
462
|
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
|
|
32 rewritten/restructured by Ben Wing for 19.12/19.13
|
|
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 GIF support changed to external GIFlib 3.1 by Jareth Hein for 21.0
|
|
39 Many changes for color work and optimizations by Jareth Hein for 21.0
|
|
40 Switch of GIF/JPEG/PNG to new EImage intermediate code by Jareth Hein for 21.0
|
|
41 TIFF code by Jareth Hein for 21.0
|
|
42 GIF/JPEG/PNG/TIFF code moved to new glyph-eimage.c for 21.0
|
|
43 Gtk version by William Perry for 21.1
|
|
44
|
|
45 TODO:
|
|
46 Support the GrayScale, StaticColor and StaticGray visual classes.
|
|
47 Convert images.el to C and stick it in here?
|
|
48 */
|
|
49
|
|
50 #include <config.h>
|
|
51 #include "lisp.h"
|
|
52
|
|
53 #include "buffer.h"
|
872
|
54 #include "device-impl.h"
|
|
55 #include "faces.h"
|
|
56 #include "file-coding.h"
|
|
57 #include "frame-impl.h"
|
|
58 #include "glyphs.h"
|
809
|
59 #include "gui.h"
|
872
|
60 #include "imgproc.h"
|
462
|
61 #include "insdel.h"
|
872
|
62 #include "lstream.h"
|
462
|
63 #include "opaque.h"
|
872
|
64 #include "window.h"
|
|
65
|
|
66 #include "console-gtk-impl.h"
|
|
67 #include "glyphs-gtk.h"
|
|
68 #include "objects-gtk-impl.h"
|
|
69 #include "ui-gtk.h"
|
462
|
70
|
|
71 #include "sysfile.h"
|
|
72
|
|
73 #include <setjmp.h>
|
|
74
|
|
75 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing);
|
|
76 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string);
|
|
77 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
|
|
78 DECLARE_IMAGE_INSTANTIATOR_FORMAT (inherit);
|
|
79 #ifdef HAVE_JPEG
|
|
80 DECLARE_IMAGE_INSTANTIATOR_FORMAT (jpeg);
|
|
81 #endif
|
|
82 #ifdef HAVE_TIFF
|
|
83 DECLARE_IMAGE_INSTANTIATOR_FORMAT (tiff);
|
|
84 #endif
|
|
85 #ifdef HAVE_PNG
|
|
86 DECLARE_IMAGE_INSTANTIATOR_FORMAT (png);
|
|
87 #endif
|
|
88 #ifdef HAVE_GIF
|
|
89 DECLARE_IMAGE_INSTANTIATOR_FORMAT (gif);
|
|
90 #endif
|
|
91
|
|
92 #ifdef HAVE_XFACE
|
|
93 DEFINE_DEVICE_IIFORMAT (gtk, xface);
|
|
94 Lisp_Object Qxface;
|
|
95 #endif
|
|
96
|
|
97 #ifdef HAVE_XPM
|
|
98 DEFINE_DEVICE_IIFORMAT (gtk, xpm);
|
|
99 #endif
|
|
100
|
|
101 DEFINE_DEVICE_IIFORMAT (gtk, xbm);
|
|
102 DEFINE_DEVICE_IIFORMAT (gtk, subwindow);
|
|
103
|
|
104 DEFINE_IMAGE_INSTANTIATOR_FORMAT (cursor_font);
|
|
105 Lisp_Object Qcursor_font;
|
|
106
|
|
107 DEFINE_IMAGE_INSTANTIATOR_FORMAT (font);
|
|
108
|
|
109 DEFINE_IMAGE_INSTANTIATOR_FORMAT (autodetect);
|
|
110
|
|
111 #ifdef HAVE_WIDGETS
|
|
112 DECLARE_IMAGE_INSTANTIATOR_FORMAT (layout);
|
|
113 DEFINE_DEVICE_IIFORMAT (gtk, widget);
|
|
114 DEFINE_DEVICE_IIFORMAT (gtk, native_layout);
|
|
115 DEFINE_DEVICE_IIFORMAT (gtk, button);
|
|
116 DEFINE_DEVICE_IIFORMAT (gtk, progress_gauge);
|
|
117 DEFINE_DEVICE_IIFORMAT (gtk, edit_field);
|
|
118 DEFINE_DEVICE_IIFORMAT (gtk, combo_box);
|
|
119 DEFINE_DEVICE_IIFORMAT (gtk, tab_control);
|
|
120 DEFINE_DEVICE_IIFORMAT (gtk, label);
|
|
121 #endif
|
|
122
|
|
123 static void update_widget_face (GtkWidget *w, Lisp_Image_Instance *ii,
|
|
124 Lisp_Object domain);
|
|
125 static void cursor_font_instantiate (Lisp_Object image_instance,
|
|
126 Lisp_Object instantiator,
|
|
127 Lisp_Object pointer_fg,
|
|
128 Lisp_Object pointer_bg,
|
|
129 int dest_mask,
|
|
130 Lisp_Object domain);
|
|
131
|
|
132 static gint cursor_name_to_index (const char *name);
|
|
133
|
|
134 #ifndef BitmapSuccess
|
|
135 #define BitmapSuccess 0
|
|
136 #define BitmapOpenFailed 1
|
|
137 #define BitmapFileInvalid 2
|
|
138 #define BitmapNoMemory 3
|
|
139 #endif
|
|
140
|
|
141 #include "bitmaps.h"
|
|
142
|
|
143 DEFINE_IMAGE_INSTANTIATOR_FORMAT (gtk_resource);
|
|
144 Lisp_Object Qgtk_resource;
|
|
145 #ifdef HAVE_WIDGETS
|
|
146 Lisp_Object Qgtk_widget_instantiate_internal, Qgtk_widget_property_internal;
|
|
147 Lisp_Object Qgtk_widget_redisplay_internal, Qgtk_widget_set_style;
|
|
148 #endif
|
|
149
|
|
150
|
|
151 /************************************************************************/
|
|
152 /* image instance methods */
|
|
153 /************************************************************************/
|
|
154
|
|
155 /************************************************************************/
|
|
156 /* convert from a series of RGB triples to an XImage formated for the */
|
|
157 /* proper display */
|
|
158 /************************************************************************/
|
|
159 static GdkImage *
|
|
160 convert_EImage_to_GDKImage (Lisp_Object device, int width, int height,
|
|
161 unsigned char *pic, unsigned long **pixtbl,
|
|
162 int *npixels)
|
|
163 {
|
|
164 GdkColormap *cmap;
|
|
165 GdkVisual *vis;
|
|
166 GdkImage *outimg;
|
|
167 int depth, byte_cnt, i, j;
|
|
168 int rd,gr,bl,q;
|
|
169 unsigned char *data, *ip, *dp = NULL;
|
|
170 quant_table *qtable = NULL;
|
|
171 union {
|
826
|
172 UINT_32_BIT val;
|
462
|
173 char cp[4];
|
|
174 } conv;
|
|
175
|
|
176 cmap = DEVICE_GTK_COLORMAP (XDEVICE(device));
|
|
177 vis = DEVICE_GTK_VISUAL (XDEVICE(device));
|
|
178 depth = DEVICE_GTK_DEPTH(XDEVICE(device));
|
|
179
|
|
180 if (vis->type == GDK_VISUAL_GRAYSCALE || vis->type == GDK_VISUAL_STATIC_COLOR ||
|
|
181 vis->type == GDK_VISUAL_STATIC_GRAY)
|
|
182 {
|
|
183 /* #### Implement me!!! */
|
|
184 return NULL;
|
|
185 }
|
|
186
|
|
187 if (vis->type == GDK_VISUAL_PSEUDO_COLOR)
|
|
188 {
|
|
189 /* Quantize the image and get a histogram while we're at it.
|
|
190 Do this first to save memory */
|
|
191 qtable = build_EImage_quantable(pic, width, height, 256);
|
|
192 if (qtable == NULL) return NULL;
|
|
193 }
|
|
194
|
|
195 /* The first parameter (GdkWindow *) is allowed to be NULL if we
|
|
196 ** specify the depth */
|
|
197 outimg = gdk_image_new (GDK_IMAGE_FASTEST, vis, width, height);
|
|
198
|
|
199 if (!outimg) return NULL;
|
|
200
|
|
201 byte_cnt = outimg->bpp;
|
|
202
|
|
203 data = (unsigned char *) outimg->mem;
|
|
204
|
|
205 if (!data)
|
|
206 {
|
|
207 gdk_image_destroy (outimg);
|
|
208 return NULL;
|
|
209 }
|
|
210
|
|
211 if (vis->type == GDK_VISUAL_PSEUDO_COLOR)
|
|
212 {
|
|
213 unsigned long pixarray[256];
|
|
214 int pixcount, n;
|
|
215 /* use our quantize table to allocate the colors */
|
|
216 pixcount = 32;
|
|
217 *pixtbl = xnew_array (unsigned long, pixcount);
|
|
218 *npixels = 0;
|
|
219
|
|
220 /* ### should implement a sort by popularity to assure proper allocation */
|
|
221 n = *npixels;
|
|
222 for (i = 0; i < qtable->num_active_colors; i++)
|
|
223 {
|
|
224 GdkColor color;
|
|
225 int res;
|
|
226
|
|
227 color.red = qtable->rm[i] ? qtable->rm[i] << 8 : 0;
|
|
228 color.green = qtable->gm[i] ? qtable->gm[i] << 8 : 0;
|
|
229 color.blue = qtable->bm[i] ? qtable->bm[i] << 8 : 0;
|
|
230 res = allocate_nearest_color (cmap, vis, &color);
|
|
231 if (res > 0 && res < 3)
|
|
232 {
|
|
233 DO_REALLOC(*pixtbl, pixcount, n+1, unsigned long);
|
|
234 (*pixtbl)[n] = color.pixel;
|
|
235 n++;
|
|
236 }
|
|
237 pixarray[i] = color.pixel;
|
|
238 }
|
|
239 *npixels = n;
|
|
240 ip = pic;
|
|
241 for (i = 0; i < height; i++)
|
|
242 {
|
|
243 dp = data + (i * outimg->bpl);
|
|
244 for (j = 0; j < width; j++)
|
|
245 {
|
|
246 rd = *ip++;
|
|
247 gr = *ip++;
|
|
248 bl = *ip++;
|
|
249 conv.val = pixarray[QUANT_GET_COLOR(qtable,rd,gr,bl)];
|
|
250 #if WORDS_BIGENDIAN
|
|
251 if (outimg->byte_order == GDK_MSB_FIRST)
|
|
252 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q];
|
|
253 else
|
|
254 for (q = 3; q >= 4-byte_cnt; q--) *dp++ = conv.cp[q];
|
|
255 #else
|
|
256 if (outimg->byte_order == GDK_MSB_FIRST)
|
|
257 for (q = byte_cnt-1; q >= 0; q--) *dp++ = conv.cp[q];
|
|
258 else
|
|
259 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
|
|
260 #endif
|
|
261 }
|
|
262 }
|
1726
|
263 xfree(qtable, quant_table *);
|
462
|
264 } else {
|
|
265 unsigned long rshift,gshift,bshift,rbits,gbits,bbits,junk;
|
|
266 junk = vis->red_mask;
|
|
267 rshift = 0;
|
|
268 while ((junk & 0x1) == 0)
|
|
269 {
|
|
270 junk = junk >> 1;
|
|
271 rshift ++;
|
|
272 }
|
|
273 rbits = 0;
|
|
274 while (junk != 0)
|
|
275 {
|
|
276 junk = junk >> 1;
|
|
277 rbits++;
|
|
278 }
|
|
279 junk = vis->green_mask;
|
|
280 gshift = 0;
|
|
281 while ((junk & 0x1) == 0)
|
|
282 {
|
|
283 junk = junk >> 1;
|
|
284 gshift ++;
|
|
285 }
|
|
286 gbits = 0;
|
|
287 while (junk != 0)
|
|
288 {
|
|
289 junk = junk >> 1;
|
|
290 gbits++;
|
|
291 }
|
|
292 junk = vis->blue_mask;
|
|
293 bshift = 0;
|
|
294 while ((junk & 0x1) == 0)
|
|
295 {
|
|
296 junk = junk >> 1;
|
|
297 bshift ++;
|
|
298 }
|
|
299 bbits = 0;
|
|
300 while (junk != 0)
|
|
301 {
|
|
302 junk = junk >> 1;
|
|
303 bbits++;
|
|
304 }
|
|
305 ip = pic;
|
|
306 for (i = 0; i < height; i++)
|
|
307 {
|
|
308 dp = data + (i * outimg->bpl);
|
|
309 for (j = 0; j < width; j++)
|
|
310 {
|
|
311 if (rbits > 8)
|
|
312 rd = *ip++ << (rbits - 8);
|
|
313 else
|
|
314 rd = *ip++ >> (8 - rbits);
|
|
315 if (gbits > 8)
|
|
316 gr = *ip++ << (gbits - 8);
|
|
317 else
|
|
318 gr = *ip++ >> (8 - gbits);
|
|
319 if (bbits > 8)
|
|
320 bl = *ip++ << (bbits - 8);
|
|
321 else
|
|
322 bl = *ip++ >> (8 - bbits);
|
|
323
|
|
324 conv.val = (rd << rshift) | (gr << gshift) | (bl << bshift);
|
|
325 #if WORDS_BIGENDIAN
|
|
326 if (outimg->byte_order == GDK_MSB_FIRST)
|
|
327 for (q = 4-byte_cnt; q < 4; q++) *dp++ = conv.cp[q];
|
|
328 else
|
|
329 for (q = 3; q >= 4-byte_cnt; q--) *dp++ = conv.cp[q];
|
|
330 #else
|
|
331 if (outimg->byte_order == GDK_MSB_FIRST)
|
|
332 for (q = byte_cnt-1; q >= 0; q--) *dp++ = conv.cp[q];
|
|
333 else
|
|
334 for (q = 0; q < byte_cnt; q++) *dp++ = conv.cp[q];
|
|
335 #endif
|
|
336 }
|
|
337 }
|
|
338 }
|
|
339 return outimg;
|
|
340 }
|
|
341
|
|
342 static void
|
|
343 gtk_print_image_instance (struct Lisp_Image_Instance *p,
|
|
344 Lisp_Object printcharfun,
|
|
345 int escapeflag)
|
|
346 {
|
|
347 switch (IMAGE_INSTANCE_TYPE (p))
|
|
348 {
|
|
349 case IMAGE_MONO_PIXMAP:
|
|
350 case IMAGE_COLOR_PIXMAP:
|
|
351 case IMAGE_POINTER:
|
800
|
352 write_fmt_string (printcharfun, " (0x%lx",
|
|
353 (unsigned long) IMAGE_INSTANCE_GTK_PIXMAP (p));
|
462
|
354 if (IMAGE_INSTANCE_GTK_MASK (p))
|
800
|
355 write_fmt_string (printcharfun, "/0x%lx",
|
|
356 (unsigned long) IMAGE_INSTANCE_GTK_MASK (p));
|
826
|
357 write_c_string (printcharfun, ")");
|
462
|
358 break;
|
|
359 #if HAVE_SUBWINDOWS
|
|
360 case IMAGE_SUBWINDOW:
|
|
361 /* #### implement me */
|
|
362 #endif
|
|
363 default:
|
|
364 break;
|
|
365 }
|
|
366 }
|
|
367
|
|
368 static void
|
|
369 gtk_finalize_image_instance (struct Lisp_Image_Instance *p)
|
|
370 {
|
|
371 if (!p->data)
|
|
372 return;
|
|
373
|
|
374 if (DEVICE_LIVE_P (XDEVICE (p->device)))
|
|
375 {
|
|
376 if (0)
|
|
377 ;
|
|
378 #ifdef HAVE_WIDGETS
|
|
379 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET)
|
|
380 {
|
|
381 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
|
|
382 {
|
|
383 gtk_widget_destroy (IMAGE_INSTANCE_SUBWINDOW_ID (p));
|
|
384
|
|
385 /* We can release the callbacks again. */
|
|
386 /* #### FIXME! */
|
|
387 /* ungcpro_popup_callbacks (...); */
|
|
388
|
|
389 /* IMAGE_INSTANCE_GTK_WIDGET_ID (p) = 0; */
|
|
390 IMAGE_INSTANCE_GTK_CLIPWIDGET (p) = 0;
|
|
391 }
|
|
392 }
|
|
393 #endif
|
|
394 else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
395 {
|
|
396 abort();
|
|
397 }
|
|
398 else
|
|
399 {
|
|
400 int i;
|
|
401 if (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p))
|
|
402 disable_glyph_animated_timeout (IMAGE_INSTANCE_PIXMAP_TIMEOUT (p));
|
|
403
|
|
404 if (IMAGE_INSTANCE_GTK_MASK (p) &&
|
|
405 IMAGE_INSTANCE_GTK_MASK (p) != IMAGE_INSTANCE_GTK_PIXMAP (p))
|
|
406 gdk_pixmap_unref (IMAGE_INSTANCE_GTK_MASK (p));
|
|
407 IMAGE_INSTANCE_PIXMAP_MASK (p) = 0;
|
|
408
|
|
409 if (IMAGE_INSTANCE_GTK_PIXMAP_SLICES (p))
|
|
410 {
|
|
411 for (i = 0; i < IMAGE_INSTANCE_PIXMAP_MAXSLICE (p); i++)
|
|
412 if (IMAGE_INSTANCE_GTK_PIXMAP_SLICE (p,i))
|
|
413 {
|
|
414 gdk_pixmap_unref (IMAGE_INSTANCE_GTK_PIXMAP_SLICE (p,i));
|
|
415 IMAGE_INSTANCE_GTK_PIXMAP_SLICE (p, i) = 0;
|
|
416 }
|
1726
|
417 xfree (IMAGE_INSTANCE_GTK_PIXMAP_SLICES (p), GdkPixmap **);
|
462
|
418 IMAGE_INSTANCE_GTK_PIXMAP_SLICES (p) = 0;
|
|
419 }
|
|
420
|
|
421 if (IMAGE_INSTANCE_GTK_CURSOR (p))
|
|
422 {
|
|
423 gdk_cursor_destroy (IMAGE_INSTANCE_GTK_CURSOR (p));
|
|
424 IMAGE_INSTANCE_GTK_CURSOR (p) = 0;
|
|
425 }
|
|
426 }
|
|
427
|
|
428 #if 0
|
|
429 /* #### BILL!!! */
|
|
430 if (IMAGE_INSTANCE_GTK_NPIXELS (p) != 0)
|
|
431 {
|
|
432 XFreeColors (dpy,
|
|
433 IMAGE_INSTANCE_GTK_COLORMAP (p),
|
|
434 IMAGE_INSTANCE_GTK_PIXELS (p),
|
|
435 IMAGE_INSTANCE_GTK_NPIXELS (p), 0);
|
|
436 IMAGE_INSTANCE_GTK_NPIXELS (p) = 0;
|
|
437 }
|
|
438 #endif
|
|
439 }
|
|
440
|
|
441 if (IMAGE_INSTANCE_TYPE (p) != IMAGE_WIDGET
|
|
442 && IMAGE_INSTANCE_TYPE (p) != IMAGE_SUBWINDOW
|
|
443 && IMAGE_INSTANCE_GTK_PIXELS (p))
|
|
444 {
|
1726
|
445 xfree (IMAGE_INSTANCE_GTK_PIXELS (p), unsigned long *);
|
462
|
446 IMAGE_INSTANCE_GTK_PIXELS (p) = 0;
|
|
447 }
|
|
448
|
1726
|
449 xfree (p->data, void *);
|
462
|
450 p->data = 0;
|
|
451 }
|
|
452
|
|
453 static int
|
|
454 gtk_image_instance_equal (struct Lisp_Image_Instance *p1,
|
|
455 struct Lisp_Image_Instance *p2, int depth)
|
|
456 {
|
|
457 switch (IMAGE_INSTANCE_TYPE (p1))
|
|
458 {
|
|
459 case IMAGE_MONO_PIXMAP:
|
|
460 case IMAGE_COLOR_PIXMAP:
|
|
461 case IMAGE_POINTER:
|
|
462 if (IMAGE_INSTANCE_GTK_COLORMAP (p1) != IMAGE_INSTANCE_GTK_COLORMAP (p2) ||
|
|
463 IMAGE_INSTANCE_GTK_NPIXELS (p1) != IMAGE_INSTANCE_GTK_NPIXELS (p2))
|
|
464 return 0;
|
|
465 #if HAVE_SUBWINDOWS
|
|
466 case IMAGE_SUBWINDOW:
|
|
467 /* #### implement me */
|
|
468 #endif
|
|
469 break;
|
|
470 default:
|
|
471 break;
|
|
472 }
|
|
473
|
|
474 return 1;
|
|
475 }
|
|
476
|
|
477 static unsigned long
|
|
478 gtk_image_instance_hash (struct Lisp_Image_Instance *p, int depth)
|
|
479 {
|
|
480 switch (IMAGE_INSTANCE_TYPE (p))
|
|
481 {
|
|
482 case IMAGE_MONO_PIXMAP:
|
|
483 case IMAGE_COLOR_PIXMAP:
|
|
484 case IMAGE_POINTER:
|
|
485 return IMAGE_INSTANCE_GTK_NPIXELS (p);
|
|
486 #if HAVE_SUBWINDOWS
|
|
487 case IMAGE_SUBWINDOW:
|
|
488 /* #### implement me */
|
|
489 return 0;
|
|
490 #endif
|
|
491 default:
|
|
492 return 0;
|
|
493 }
|
|
494 }
|
|
495
|
|
496 /* Set all the slots in an image instance structure to reasonable
|
|
497 default values. This is used somewhere within an instantiate
|
|
498 method. It is assumed that the device slot within the image
|
|
499 instance is already set -- this is the case when instantiate
|
|
500 methods are called. */
|
|
501
|
|
502 static void
|
|
503 gtk_initialize_pixmap_image_instance (struct Lisp_Image_Instance *ii,
|
|
504 int slices,
|
|
505 enum image_instance_type type)
|
|
506 {
|
|
507 ii->data = xnew_and_zero (struct gtk_image_instance_data);
|
|
508 IMAGE_INSTANCE_PIXMAP_MAXSLICE (ii) = slices;
|
|
509 IMAGE_INSTANCE_GTK_PIXMAP_SLICES (ii) =
|
|
510 xnew_array_and_zero (GdkPixmap *, slices);
|
|
511 IMAGE_INSTANCE_TYPE (ii) = type;
|
|
512 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
513 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
|
|
514 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = Qnil;
|
|
515 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = Qnil;
|
|
516 IMAGE_INSTANCE_PIXMAP_FG (ii) = Qnil;
|
|
517 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
|
|
518 }
|
|
519
|
|
520
|
|
521 /************************************************************************/
|
|
522 /* pixmap file functions */
|
|
523 /************************************************************************/
|
|
524
|
|
525 /* Where bitmaps are; initialized from resource database */
|
|
526 Lisp_Object Vgtk_bitmap_file_path;
|
|
527
|
|
528 #ifndef BITMAPDIR
|
|
529 #define BITMAPDIR "/usr/include/X11/bitmaps"
|
|
530 #endif
|
|
531
|
|
532 /* Given a pixmap filename, look through all of the "standard" places
|
|
533 where the file might be located. Return a full pathname if found;
|
|
534 otherwise, return Qnil. */
|
|
535
|
|
536 static Lisp_Object
|
|
537 gtk_locate_pixmap_file (Lisp_Object name)
|
|
538 {
|
|
539 /* This function can GC if IN_REDISPLAY is false */
|
|
540
|
|
541 /* Check non-absolute pathnames with a directory component relative to
|
|
542 the search path; that's the way Xt does it. */
|
|
543 /* #### Unix-specific */
|
826
|
544 if (string_byte (name, 0) == '/' ||
|
|
545 (string_byte (name, 0) == '.' &&
|
|
546 (string_byte (name, 1) == '/' ||
|
|
547 (string_byte (name, 1) == '.' &&
|
|
548 (string_byte (name, 2) == '/')))))
|
462
|
549 {
|
|
550 if (!NILP (Ffile_readable_p (name)))
|
|
551 return name;
|
|
552 else
|
|
553 return Qnil;
|
|
554 }
|
|
555
|
|
556 if (NILP (Vgtk_bitmap_file_path))
|
|
557 {
|
|
558 Vgtk_bitmap_file_path = nconc2 (Vgtk_bitmap_file_path,
|
778
|
559 (split_external_path (BITMAPDIR)));
|
462
|
560 }
|
|
561
|
|
562 {
|
|
563 Lisp_Object found;
|
|
564 if (locate_file (Vgtk_bitmap_file_path, name, Qnil, &found, R_OK) < 0)
|
|
565 {
|
|
566 Lisp_Object temp = list1 (Vdata_directory);
|
|
567 struct gcpro gcpro1;
|
|
568
|
|
569 GCPRO1 (temp);
|
|
570 locate_file (temp, name, Qnil, &found, R_OK);
|
|
571 UNGCPRO;
|
|
572 }
|
|
573
|
|
574 return found;
|
|
575 }
|
|
576 }
|
|
577
|
|
578 static Lisp_Object
|
|
579 locate_pixmap_file (Lisp_Object name)
|
|
580 {
|
|
581 return gtk_locate_pixmap_file (name);
|
|
582 }
|
|
583
|
|
584
|
|
585 /************************************************************************/
|
|
586 /* cursor functions */
|
|
587 /************************************************************************/
|
|
588
|
|
589 /* Check that this server supports cursors of size WIDTH * HEIGHT. If
|
|
590 not, signal an error. INSTANTIATOR is only used in the error
|
|
591 message. */
|
|
592
|
|
593 static void
|
|
594 check_pointer_sizes (unsigned int width, unsigned int height,
|
|
595 Lisp_Object instantiator)
|
|
596 {
|
|
597 /* #### BILL!!! There is no way to call XQueryBestCursor from Gdk! */
|
|
598 #if 0
|
|
599 unsigned int best_width, best_height;
|
|
600 if (! XQueryBestCursor (DisplayOfScreen (xs), RootWindowOfScreen (xs),
|
|
601 width, height, &best_width, &best_height))
|
|
602 /* this means that an X error of some sort occurred (we trap
|
|
603 these so they're not fatal). */
|
563
|
604 gui_error ("XQueryBestCursor() failed?", instantiator);
|
462
|
605
|
|
606 if (width > best_width || height > best_height)
|
563
|
607 signal_ferror_with_frob (Qgui_error, instantiator,
|
|
608 "pointer too large (%dx%d): "
|
|
609 "server requires %dx%d or smaller",
|
|
610 width, height, best_width, best_height);
|
462
|
611 #endif
|
|
612 }
|
|
613
|
|
614 static void
|
|
615 generate_cursor_fg_bg (Lisp_Object device, Lisp_Object *foreground,
|
|
616 Lisp_Object *background, GdkColor *xfg, GdkColor *xbg)
|
|
617 {
|
|
618 if (!NILP (*foreground) && !COLOR_INSTANCEP (*foreground))
|
|
619 *foreground =
|
|
620 Fmake_color_instance (*foreground, device,
|
|
621 encode_error_behavior_flag (ERROR_ME));
|
|
622 if (COLOR_INSTANCEP (*foreground))
|
|
623 *xfg = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (*foreground));
|
|
624 else
|
|
625 {
|
|
626 xfg->pixel = 0;
|
|
627 xfg->red = xfg->green = xfg->blue = 0;
|
|
628 }
|
|
629
|
|
630 if (!NILP (*background) && !COLOR_INSTANCEP (*background))
|
|
631 *background =
|
|
632 Fmake_color_instance (*background, device,
|
|
633 encode_error_behavior_flag (ERROR_ME));
|
|
634 if (COLOR_INSTANCEP (*background))
|
|
635 *xbg = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (*background));
|
|
636 else
|
|
637 {
|
|
638 xbg->pixel = 0;
|
|
639 xbg->red = xbg->green = xbg->blue = ~0;
|
|
640 }
|
|
641 }
|
|
642
|
|
643 static void
|
|
644 maybe_recolor_cursor (Lisp_Object image_instance, Lisp_Object foreground,
|
|
645 Lisp_Object background)
|
|
646 {
|
|
647 #if 0
|
|
648 /* #### BILL!!! */
|
|
649 Lisp_Object device = XIMAGE_INSTANCE_DEVICE (image_instance);
|
|
650 GdkColor xfg, xbg;
|
|
651
|
|
652 generate_cursor_fg_bg (device, &foreground, &background, &xfg, &xbg);
|
|
653 if (!NILP (foreground) || !NILP (background))
|
|
654 {
|
|
655 XRecolorCursor (DEVICE_X_DISPLAY (XDEVICE (device)),
|
|
656 XIMAGE_INSTANCE_GTK_CURSOR (image_instance),
|
|
657 &xfg, &xbg);
|
|
658 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
659 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
660 }
|
|
661 #else
|
|
662 /* stderr_out ("Don't know how to recolor cursors in Gtk!\n"); */
|
|
663 #endif
|
|
664 }
|
|
665
|
|
666
|
|
667 /************************************************************************/
|
|
668 /* color pixmap functions */
|
|
669 /************************************************************************/
|
|
670
|
|
671 /* Initialize an image instance from an XImage.
|
|
672
|
|
673 DEST_MASK specifies the mask of allowed image types.
|
|
674
|
|
675 PIXELS and NPIXELS specify an array of pixels that are used in
|
|
676 the image. These need to be kept around for the duration of the
|
|
677 image. When the image instance is freed, XFreeColors() will
|
|
678 automatically be called on all the pixels specified here; thus,
|
|
679 you should have allocated the pixels yourself using XAllocColor()
|
|
680 or the like. The array passed in is used directly without
|
|
681 being copied, so it should be heap data created with xmalloc().
|
|
682 It will be freed using xfree() when the image instance is
|
|
683 destroyed.
|
|
684
|
|
685 If this fails, signal an error. INSTANTIATOR is only used
|
|
686 in the error message.
|
|
687
|
|
688 #### This should be able to handle conversion into `pointer'.
|
|
689 Use the same code as for `xpm'. */
|
|
690
|
|
691 static void
|
|
692 init_image_instance_from_gdk_image (struct Lisp_Image_Instance *ii,
|
|
693 GdkImage *gdk_image,
|
|
694 int dest_mask,
|
|
695 GdkColormap *cmap,
|
|
696 unsigned long *pixels,
|
|
697 int npixels,
|
|
698 int slices,
|
|
699 Lisp_Object instantiator)
|
|
700 {
|
|
701 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
702 GdkGC *gc;
|
|
703 GdkWindow *d;
|
|
704 GdkPixmap *pixmap;
|
|
705
|
|
706 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
707 gui_error ("Not a Gtk device", device);
|
462
|
708
|
|
709 d = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device)));
|
|
710
|
|
711 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
712 incompatible_image_types (instantiator, dest_mask,
|
|
713 IMAGE_COLOR_PIXMAP_MASK);
|
|
714
|
|
715 pixmap = gdk_pixmap_new (d, gdk_image->width, gdk_image->height, gdk_image->depth);
|
|
716 if (!pixmap)
|
563
|
717 gui_error ("Unable to create pixmap", instantiator);
|
462
|
718
|
|
719 gc = gdk_gc_new (pixmap);
|
|
720 if (!gc)
|
|
721 {
|
|
722 gdk_pixmap_unref (pixmap);
|
563
|
723 gui_error ("Unable to create GC", instantiator);
|
462
|
724 }
|
|
725
|
|
726 gdk_draw_image (GDK_DRAWABLE (pixmap), gc, gdk_image,
|
|
727 0, 0, 0, 0, gdk_image->width, gdk_image->height);
|
|
728
|
|
729 gdk_gc_destroy (gc);
|
|
730
|
|
731 gtk_initialize_pixmap_image_instance (ii, slices, IMAGE_COLOR_PIXMAP);
|
|
732
|
|
733 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
734 find_keyword_in_vector (instantiator, Q_file);
|
|
735
|
|
736 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap;
|
|
737 IMAGE_INSTANCE_GTK_MASK (ii) = 0;
|
|
738 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = gdk_image->width;
|
|
739 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = gdk_image->height;
|
|
740 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = gdk_image->depth;
|
|
741 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap;
|
|
742 IMAGE_INSTANCE_GTK_PIXELS (ii) = pixels;
|
|
743 IMAGE_INSTANCE_GTK_NPIXELS (ii) = npixels;
|
|
744 }
|
|
745
|
|
746 #if 0
|
|
747 void init_image_instance_from_gdk_pixmap (struct Lisp_Image_Instance *ii,
|
|
748 struct device *device,
|
|
749 GdkPixmap *gdk_pixmap,
|
|
750 int dest_mask,
|
|
751 Lisp_Object instantiator)
|
|
752 {
|
|
753 GdkWindow *d;
|
|
754 gint width, height, depth;
|
|
755
|
|
756 if (!DEVICE_GTK_P (device))
|
|
757 abort ();
|
|
758
|
|
759 IMAGE_INSTANCE_DEVICE (ii) = device;
|
|
760 IMAGE_INSTANCE_TYPE (ii) = IMAGE_COLOR_PIXMAP;
|
|
761
|
|
762 d = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (device));
|
|
763
|
|
764 if (!(dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
765 incompatible_image_types (instantiator, dest_mask,
|
|
766 IMAGE_COLOR_PIXMAP_MASK);
|
|
767
|
|
768 gtk_initialize_pixmap_image_instance (ii, IMAGE_COLOR_PIXMAP);
|
|
769
|
|
770 gdk_window_get_geometry (gdk_pixmap, NULL, NULL, &width, &height, &depth);
|
|
771
|
|
772 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
|
|
773 IMAGE_INSTANCE_GTK_PIXMAP (ii) = gdk_pixmap;
|
|
774 IMAGE_INSTANCE_GTK_MASK (ii) = 0;
|
|
775 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
776 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
777 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
|
|
778 IMAGE_INSTANCE_GTK_COLORMAP (ii) = gdk_window_get_colormap (gdk_pixmap);
|
|
779 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0;
|
|
780 IMAGE_INSTANCE_GTK_NPIXELS (ii) = 0;
|
|
781 }
|
|
782 #endif
|
|
783
|
|
784 static void
|
|
785 image_instance_add_gdk_image (Lisp_Image_Instance *ii,
|
|
786 GdkImage *gdk_image,
|
|
787 int slice,
|
|
788 Lisp_Object instantiator)
|
|
789 {
|
|
790 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
791 GdkWindow *d;
|
|
792 GdkPixmap *pixmap;
|
|
793 GdkGC *gc;
|
|
794
|
|
795 d = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device)));
|
|
796
|
|
797 pixmap = gdk_pixmap_new (d, gdk_image->width, gdk_image->height, gdk_image->depth);
|
|
798
|
|
799 if (!pixmap)
|
563
|
800 gui_error ("Unable to create pixmap", instantiator);
|
462
|
801
|
|
802 gc = gdk_gc_new (pixmap);
|
|
803
|
|
804 if (!gc)
|
|
805 {
|
|
806 gdk_pixmap_unref (pixmap);
|
563
|
807 gui_error ("Unable to create GC", instantiator);
|
462
|
808 }
|
|
809
|
|
810 gdk_draw_image (GDK_DRAWABLE (pixmap), gc, gdk_image, 0, 0, 0, 0,
|
|
811 gdk_image->width, gdk_image->height);
|
|
812
|
|
813 gdk_gc_destroy (gc);
|
|
814
|
|
815 IMAGE_INSTANCE_GTK_PIXMAP_SLICE (ii, slice) = pixmap;
|
|
816 }
|
|
817
|
|
818 static void
|
|
819 gtk_init_image_instance_from_eimage (struct Lisp_Image_Instance *ii,
|
|
820 int width, int height,
|
|
821 int slices,
|
|
822 unsigned char *eimage,
|
|
823 int dest_mask,
|
|
824 Lisp_Object instantiator,
|
|
825 Lisp_Object domain)
|
|
826 {
|
|
827 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
828 GdkColormap *cmap = DEVICE_GTK_COLORMAP (XDEVICE(device));
|
|
829 unsigned long *pixtbl = NULL;
|
|
830 int npixels = 0;
|
|
831 int slice;
|
|
832 GdkImage* gdk_image;
|
|
833
|
|
834
|
|
835 for (slice = 0; slice < slices; slice++)
|
|
836 {
|
|
837 gdk_image = convert_EImage_to_GDKImage (device, width, height, eimage,
|
|
838 &pixtbl, &npixels);
|
|
839 if (!gdk_image)
|
|
840 {
|
1726
|
841 if (pixtbl)
|
|
842 xfree (pixtbl, unsigned long *);
|
462
|
843 signal_image_error("EImage to GdkImage conversion failed", instantiator);
|
|
844 }
|
|
845
|
|
846 if (slice == 0)
|
|
847 /* Now create the pixmap and set up the image instance */
|
|
848 init_image_instance_from_gdk_image (ii, gdk_image, dest_mask,
|
|
849 cmap, pixtbl, npixels, slices,
|
|
850 instantiator);
|
|
851 else
|
|
852 image_instance_add_gdk_image (ii, gdk_image, slice, instantiator);
|
|
853
|
|
854 if (gdk_image)
|
|
855 {
|
|
856 gdk_image_destroy (gdk_image);
|
|
857 }
|
|
858 gdk_image = 0;
|
|
859 }
|
|
860 }
|
|
861
|
|
862 /* Given inline data for a mono pixmap, create and return the
|
|
863 corresponding X object. */
|
|
864
|
|
865 static GdkPixmap *
|
|
866 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
|
|
867 /* Note that data is in ext-format! */
|
771
|
868 const Extbyte *bits)
|
462
|
869 {
|
|
870 return (gdk_bitmap_create_from_data (GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device))),
|
|
871 (char *) bits, width, height));
|
|
872 }
|
|
873
|
|
874 /* Given inline data for a mono pixmap, initialize the given
|
|
875 image instance accordingly. */
|
|
876
|
|
877 static void
|
|
878 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
|
|
879 int width, int height,
|
|
880 /* Note that data is in ext-format! */
|
771
|
881 const char *bits,
|
462
|
882 Lisp_Object instantiator,
|
|
883 Lisp_Object pointer_fg,
|
|
884 Lisp_Object pointer_bg,
|
|
885 int dest_mask,
|
|
886 GdkPixmap *mask,
|
|
887 Lisp_Object mask_filename)
|
|
888 {
|
|
889 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
890 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
891 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
892 GdkColor fg;
|
|
893 GdkColor bg;
|
|
894 enum image_instance_type type;
|
|
895 GdkWindow *draw = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device)));
|
|
896 GdkColormap *cmap = DEVICE_GTK_COLORMAP (XDEVICE(device));
|
|
897 GdkColor black;
|
|
898 GdkColor white;
|
|
899
|
|
900 gdk_color_black(cmap, &black);
|
|
901 gdk_color_white(cmap, &white);
|
|
902
|
|
903 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
904 gui_error ("Not a Gtk device", device);
|
462
|
905
|
|
906 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
907 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
908 {
|
|
909 if (!NILP (foreground) || !NILP (background))
|
|
910 type = IMAGE_COLOR_PIXMAP;
|
|
911 else
|
|
912 type = IMAGE_MONO_PIXMAP;
|
|
913 }
|
|
914 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
915 type = IMAGE_MONO_PIXMAP;
|
|
916 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
917 type = IMAGE_COLOR_PIXMAP;
|
|
918 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
919 type = IMAGE_POINTER;
|
|
920 else
|
|
921 incompatible_image_types (instantiator, dest_mask,
|
|
922 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
923 | IMAGE_POINTER_MASK);
|
|
924
|
|
925 gtk_initialize_pixmap_image_instance (ii, 1, type);
|
|
926 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
927 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
928 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
929 find_keyword_in_vector (instantiator, Q_file);
|
|
930
|
|
931 switch (type)
|
|
932 {
|
|
933 case IMAGE_MONO_PIXMAP:
|
|
934 {
|
|
935 IMAGE_INSTANCE_GTK_PIXMAP (ii) =
|
|
936 pixmap_from_xbm_inline (device, width, height, (Extbyte *) bits);
|
|
937 }
|
|
938 break;
|
|
939
|
|
940 case IMAGE_COLOR_PIXMAP:
|
|
941 {
|
|
942 gint d = DEVICE_GTK_DEPTH (XDEVICE(device));
|
|
943
|
|
944 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
945 foreground =
|
|
946 Fmake_color_instance (foreground, device,
|
|
947 encode_error_behavior_flag (ERROR_ME));
|
|
948
|
|
949 if (COLOR_INSTANCEP (foreground))
|
|
950 fg = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (foreground));
|
|
951
|
|
952 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
953 background =
|
|
954 Fmake_color_instance (background, device,
|
|
955 encode_error_behavior_flag (ERROR_ME));
|
|
956
|
|
957 if (COLOR_INSTANCEP (background))
|
|
958 bg = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (background));
|
|
959
|
|
960 /* We used to duplicate the pixels using XAllocColor(), to protect
|
|
961 against their getting freed. Just as easy to just store the
|
|
962 color instances here and GC-protect them, so this doesn't
|
|
963 happen. */
|
|
964 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
965 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
966 IMAGE_INSTANCE_GTK_PIXMAP (ii) =
|
|
967 gdk_pixmap_create_from_data (draw, (char *) bits, width, height, d, &fg, &bg);
|
|
968 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
969 }
|
|
970 break;
|
|
971
|
|
972 case IMAGE_POINTER:
|
|
973 {
|
|
974 GdkColor fg_color, bg_color;
|
|
975 GdkPixmap *source;
|
|
976
|
|
977 check_pointer_sizes (width, height, instantiator);
|
|
978
|
|
979 source = gdk_pixmap_create_from_data (draw, (char *) bits, width, height, 1, &black, &white);
|
|
980
|
|
981 if (NILP (foreground))
|
|
982 foreground = pointer_fg;
|
|
983 if (NILP (background))
|
|
984 background = pointer_bg;
|
|
985 generate_cursor_fg_bg (device, &foreground, &background,
|
|
986 &fg_color, &bg_color);
|
|
987
|
|
988 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
989 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
990 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
|
|
991 find_keyword_in_vector (instantiator, Q_hotspot_x);
|
|
992 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
|
|
993 find_keyword_in_vector (instantiator, Q_hotspot_y);
|
|
994 IMAGE_INSTANCE_GTK_CURSOR (ii) =
|
|
995 gdk_cursor_new_from_pixmap (source, mask, &fg_color, &bg_color,
|
|
996 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ?
|
|
997 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) : 0,
|
|
998 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) ?
|
|
999 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) : 0);
|
|
1000 }
|
|
1001 break;
|
|
1002
|
|
1003 default:
|
|
1004 abort ();
|
|
1005 }
|
|
1006 }
|
|
1007
|
|
1008 static void
|
|
1009 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1010 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1011 int dest_mask, int width, int height,
|
|
1012 /* Note that data is in ext-format! */
|
771
|
1013 const char *bits)
|
462
|
1014 {
|
|
1015 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1016 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
|
1017 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1018 GdkPixmap *mask = 0;
|
771
|
1019 const char *gcc_may_you_rot_in_hell;
|
462
|
1020
|
|
1021 if (!NILP (mask_data))
|
|
1022 {
|
|
1023 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (mask_data))),
|
|
1024 C_STRING_ALLOCA, gcc_may_you_rot_in_hell,
|
|
1025 Qfile_name);
|
|
1026 mask =
|
|
1027 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
|
|
1028 XINT (XCAR (mask_data)),
|
|
1029 XINT (XCAR (XCDR (mask_data))),
|
771
|
1030 (const unsigned char *)
|
462
|
1031 gcc_may_you_rot_in_hell);
|
|
1032 }
|
|
1033
|
|
1034 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1035 instantiator, pointer_fg, pointer_bg,
|
|
1036 dest_mask, mask, mask_file);
|
|
1037 }
|
|
1038
|
|
1039 /* Instantiate method for XBM's. */
|
|
1040
|
|
1041 static void
|
|
1042 gtk_xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1043 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1044 int dest_mask, Lisp_Object domain)
|
|
1045 {
|
|
1046 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
771
|
1047 const char *gcc_go_home;
|
462
|
1048
|
|
1049 assert (!NILP (data));
|
|
1050
|
|
1051 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (data))),
|
|
1052 C_STRING_ALLOCA, gcc_go_home,
|
|
1053 Qbinary);
|
|
1054
|
|
1055 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1056 pointer_bg, dest_mask, XINT (XCAR (data)),
|
|
1057 XINT (XCAR (XCDR (data))), gcc_go_home);
|
|
1058 }
|
|
1059
|
|
1060
|
|
1061 #ifdef HAVE_XPM
|
|
1062 /**********************************************************************
|
|
1063 * XPM *
|
|
1064 **********************************************************************/
|
771
|
1065 static Lisp_Object
|
|
1066 write_lisp_string_to_temp_file (Lisp_Object string)
|
462
|
1067 {
|
|
1068 Lisp_Object instream, outstream;
|
|
1069 Lstream *istr, *ostr;
|
771
|
1070 Char_Binary tempbuf[1024]; /* some random amount */
|
462
|
1071 int fubar = 0;
|
|
1072 FILE *tmpfil;
|
|
1073 static Extbyte_dynarr *conversion_out_dynarr;
|
|
1074 Bytecount bstart, bend;
|
771
|
1075 Lisp_Object tempfile;
|
778
|
1076 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
462
|
1077 Lisp_Object conv_out_stream;
|
|
1078 Lstream *costr;
|
|
1079
|
|
1080 /* This function can GC */
|
|
1081 if (!conversion_out_dynarr)
|
|
1082 conversion_out_dynarr = Dynarr_new (Extbyte);
|
|
1083 else
|
|
1084 Dynarr_reset (conversion_out_dynarr);
|
|
1085
|
|
1086 /* Create the temporary file ... */
|
771
|
1087 tempfile = Fmake_temp_name (build_string ("/tmp/emacs"));
|
|
1088 tmpfil = qxe_fopen (XSTRING_DATA (tempfile), "w");
|
462
|
1089 if (!tmpfil)
|
|
1090 {
|
|
1091 if (tmpfil)
|
|
1092 {
|
|
1093 int old_errno = errno;
|
771
|
1094 retry_fclose (tmpfil);
|
|
1095 qxe_unlink (XSTRING_DATA (tempfile));
|
462
|
1096 errno = old_errno;
|
|
1097 }
|
771
|
1098 report_file_error ("Creating temp file", tempfile);
|
462
|
1099 }
|
|
1100
|
|
1101 CHECK_STRING (string);
|
|
1102 get_string_range_byte (string, Qnil, Qnil, &bstart, &bend,
|
|
1103 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1104 instream = make_lisp_string_input_stream (string, bstart, bend);
|
|
1105 istr = XLSTREAM (instream);
|
|
1106 /* setup the out stream */
|
771
|
1107 outstream =
|
|
1108 make_dynarr_output_stream ((unsigned_char_dynarr *) conversion_out_dynarr);
|
462
|
1109 ostr = XLSTREAM (outstream);
|
|
1110 /* setup the conversion stream */
|
771
|
1111 conv_out_stream =
|
800
|
1112 make_coding_output_stream (ostr, Qbinary, CODING_ENCODE, 0);
|
462
|
1113 costr = XLSTREAM (conv_out_stream);
|
771
|
1114 GCPRO4 (tempfile, instream, outstream, conv_out_stream);
|
462
|
1115
|
|
1116 /* Get the data while doing the conversion */
|
|
1117 while (1)
|
|
1118 {
|
|
1119 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
|
|
1120 if (!size_in_bytes)
|
|
1121 break;
|
|
1122 /* It does seem the flushes are necessary... */
|
|
1123 Lstream_write (costr, tempbuf, size_in_bytes);
|
|
1124 Lstream_flush (costr);
|
|
1125 Lstream_flush (ostr);
|
771
|
1126 if (retry_fwrite ((unsigned char *)Dynarr_atp(conversion_out_dynarr, 0),
|
462
|
1127 Dynarr_length(conversion_out_dynarr), 1, tmpfil) != 1)
|
|
1128 {
|
|
1129 fubar = 1;
|
|
1130 break;
|
|
1131 }
|
|
1132 /* reset the dynarr */
|
|
1133 Lstream_rewind(ostr);
|
|
1134 }
|
|
1135
|
771
|
1136 if (retry_fclose (tmpfil) != 0)
|
462
|
1137 fubar = 1;
|
|
1138 Lstream_close (istr);
|
|
1139 Lstream_close (costr);
|
|
1140 Lstream_close (ostr);
|
|
1141
|
771
|
1142 Lstream_delete (istr);
|
|
1143 Lstream_delete (ostr);
|
|
1144 Lstream_delete (costr);
|
|
1145
|
|
1146 if (fubar)
|
|
1147 report_file_error ("Writing temp file", tempfile);
|
|
1148
|
462
|
1149 UNGCPRO;
|
771
|
1150 return tempfile;
|
462
|
1151 }
|
|
1152
|
739
|
1153 struct color_symbol
|
|
1154 {
|
|
1155 char* name;
|
|
1156 GdkColor color;
|
|
1157 };
|
|
1158
|
|
1159 static struct color_symbol*
|
|
1160 extract_xpm_color_names (Lisp_Object device,
|
|
1161 Lisp_Object domain,
|
|
1162 Lisp_Object color_symbol_alist,
|
|
1163 int* nsymbols)
|
|
1164 {
|
|
1165 /* This function can GC */
|
|
1166 Lisp_Object rest;
|
|
1167 Lisp_Object results = Qnil;
|
|
1168 int i, j;
|
|
1169 struct color_symbol *colortbl;
|
|
1170 struct gcpro gcpro1, gcpro2;
|
|
1171
|
|
1172 GCPRO2 (results, device);
|
|
1173
|
|
1174 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
1175 error happens we don't lose any malloc()ed data, or more importantly,
|
|
1176 leave any pixels allocated in the server. */
|
|
1177 i = 0;
|
|
1178 LIST_LOOP (rest, color_symbol_alist)
|
|
1179 {
|
|
1180 Lisp_Object cons = XCAR (rest);
|
|
1181 Lisp_Object name = XCAR (cons);
|
|
1182 Lisp_Object value = XCDR (cons);
|
|
1183 if (NILP (value))
|
|
1184 continue;
|
|
1185 if (STRINGP (value))
|
|
1186 value =
|
|
1187 Fmake_color_instance
|
793
|
1188 (value, device, encode_error_behavior_flag (ERROR_ME_DEBUG_WARN));
|
739
|
1189 else
|
|
1190 {
|
|
1191 assert (COLOR_SPECIFIERP (value));
|
|
1192 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
|
1193 }
|
|
1194
|
|
1195 if (NILP (value))
|
|
1196 continue;
|
|
1197 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
1198 i++;
|
|
1199 }
|
|
1200 UNGCPRO; /* no more evaluation */
|
|
1201
|
|
1202 *nsymbols=i;
|
|
1203 if (i == 0) return 0;
|
|
1204
|
|
1205 colortbl = xnew_array_and_zero (struct color_symbol, i);
|
|
1206
|
|
1207 for (j=0; j<i; j++)
|
|
1208 {
|
|
1209 Lisp_Object cons = XCAR (results);
|
|
1210 colortbl[j].color =
|
|
1211 * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
1212
|
|
1213 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
|
|
1214 free_cons (XCONS (cons));
|
|
1215 cons = results;
|
|
1216 results = XCDR (results);
|
|
1217 free_cons (XCONS (cons));
|
|
1218 }
|
|
1219 return colortbl;
|
|
1220 }
|
|
1221
|
462
|
1222 static void
|
739
|
1223 gtk_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
462
|
1224 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1225 int dest_mask, Lisp_Object domain)
|
|
1226 {
|
|
1227 /* This function can GC */
|
|
1228 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1229 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1230 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1231 GdkColormap *cmap;
|
|
1232 int depth;
|
|
1233 GdkVisual *visual;
|
|
1234 GdkPixmap *pixmap;
|
|
1235 GdkPixmap *mask = 0;
|
|
1236 GdkWindow *window = 0;
|
739
|
1237 int nsymbols = 0, i = 0;
|
|
1238 struct color_symbol *color_symbols = NULL;
|
|
1239 GdkColor *transparent_color = NULL;
|
462
|
1240 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
1241 Q_color_symbols);
|
|
1242 enum image_instance_type type;
|
|
1243 int force_mono;
|
|
1244 unsigned int w, h;
|
771
|
1245 Lisp_Object tempfile = Qnil;
|
|
1246 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
462
|
1247
|
|
1248 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1249 gui_error ("Not a Gtk device", device);
|
462
|
1250
|
|
1251 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1252 type = IMAGE_COLOR_PIXMAP;
|
|
1253 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
1254 type = IMAGE_MONO_PIXMAP;
|
|
1255 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
1256 type = IMAGE_POINTER;
|
|
1257 else
|
|
1258 incompatible_image_types (instantiator, dest_mask,
|
|
1259 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
1260 | IMAGE_POINTER_MASK);
|
|
1261 force_mono = (type != IMAGE_COLOR_PIXMAP);
|
|
1262
|
771
|
1263 GCPRO4 (device, data, color_symbol_alist, tempfile);
|
|
1264
|
462
|
1265 window = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device)));
|
|
1266 cmap = DEVICE_GTK_COLORMAP (XDEVICE (device));
|
|
1267 depth = DEVICE_GTK_DEPTH (XDEVICE (device));
|
|
1268 visual = DEVICE_GTK_VISUAL (XDEVICE (device));
|
|
1269
|
|
1270 gtk_initialize_pixmap_image_instance (ii, 1, type);
|
|
1271
|
|
1272 assert (!NILP (data));
|
|
1273
|
739
|
1274 /* Need to get the transparent color here */
|
771
|
1275 color_symbols = extract_xpm_color_names (device, domain, color_symbol_alist,
|
|
1276 &nsymbols);
|
739
|
1277 for (i = 0; i < nsymbols; i++)
|
|
1278 {
|
771
|
1279 if (!qxestrcasecmp ("BgColor", color_symbols[i].name) ||
|
|
1280 !qxestrcasecmp ("None", color_symbols[i].name))
|
739
|
1281 {
|
|
1282 transparent_color = &color_symbols[i].color;
|
|
1283 }
|
|
1284 }
|
|
1285
|
771
|
1286 tempfile = write_lisp_string_to_temp_file (data);
|
|
1287 {
|
|
1288 Extbyte *tempfileout;
|
|
1289
|
|
1290 LISP_STRING_TO_EXTERNAL (tempfile, tempfileout, Qfile_name);
|
|
1291 pixmap = gdk_pixmap_create_from_xpm (window, &mask, transparent_color,
|
|
1292 tempfileout);
|
|
1293 }
|
|
1294 qxe_unlink (XSTRING_DATA (tempfile));
|
462
|
1295
|
1726
|
1296 if (color_symbols)
|
|
1297 xfree (color_symbols, struct color_symbol *);
|
739
|
1298
|
462
|
1299 if (!pixmap)
|
|
1300 signal_image_error ("Error reading pixmap", data);
|
|
1301
|
|
1302 gdk_window_get_geometry (pixmap, NULL, NULL, &w, &h, &depth);
|
|
1303
|
|
1304 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap;
|
|
1305 IMAGE_INSTANCE_GTK_MASK (ii) = mask;
|
|
1306 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap;
|
|
1307 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0;
|
|
1308 IMAGE_INSTANCE_GTK_NPIXELS (ii) = 0;
|
|
1309 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
|
|
1310 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
|
|
1311 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
1312 find_keyword_in_vector (instantiator, Q_file);
|
|
1313
|
|
1314 switch (type)
|
|
1315 {
|
|
1316 case IMAGE_MONO_PIXMAP:
|
|
1317 break;
|
|
1318
|
|
1319 case IMAGE_COLOR_PIXMAP:
|
771
|
1320 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
|
462
|
1321 break;
|
|
1322
|
|
1323 case IMAGE_POINTER:
|
|
1324 {
|
|
1325 GdkColor fg, bg;
|
|
1326 unsigned int xhot, yhot;
|
|
1327
|
|
1328 /* #### Gtk does not give us access to the hotspots of a pixmap */
|
|
1329 xhot = yhot = 1;
|
793
|
1330 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int (xhot);
|
|
1331 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int (yhot);
|
462
|
1332
|
|
1333 check_pointer_sizes (w, h, instantiator);
|
|
1334
|
|
1335 /* If the loaded pixmap has colors allocated (meaning it came from an
|
|
1336 XPM file), then use those as the default colors for the cursor we
|
|
1337 create. Otherwise, default to pointer_fg and pointer_bg.
|
|
1338 */
|
|
1339 if (depth > 1)
|
|
1340 {
|
|
1341 warn_when_safe (Qunimplemented, Qnotice,
|
|
1342 "GTK does not support XPM cursors...\n");
|
|
1343 IMAGE_INSTANCE_GTK_CURSOR (ii) = gdk_cursor_new (GDK_COFFEE_MUG);
|
|
1344 }
|
|
1345 else
|
|
1346 {
|
|
1347 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg,
|
|
1348 &fg, &bg);
|
|
1349 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg;
|
|
1350 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg;
|
771
|
1351 IMAGE_INSTANCE_GTK_CURSOR (ii) =
|
|
1352 gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, xhot, yhot);
|
462
|
1353 }
|
|
1354 }
|
|
1355
|
|
1356 break;
|
|
1357
|
|
1358 default:
|
|
1359 abort ();
|
|
1360 }
|
771
|
1361
|
|
1362 UNGCPRO;
|
462
|
1363 }
|
|
1364 #endif /* HAVE_XPM */
|
|
1365
|
|
1366
|
|
1367 #ifdef HAVE_XFACE
|
|
1368
|
|
1369 /**********************************************************************
|
|
1370 * X-Face *
|
|
1371 **********************************************************************/
|
|
1372 #if defined(EXTERN)
|
|
1373 /* This is about to get redefined! */
|
|
1374 #undef EXTERN
|
|
1375 #endif
|
|
1376 /* We have to define SYSV32 so that compface.h includes string.h
|
|
1377 instead of strings.h. */
|
|
1378 #define SYSV32
|
1743
|
1379 BEGIN_C_DECLS
|
462
|
1380 #include <compface.h>
|
1743
|
1381 END_C_DECLS
|
|
1382
|
462
|
1383 /* JMP_BUF cannot be used here because if it doesn't get defined
|
|
1384 to jmp_buf we end up with a conflicting type error with the
|
|
1385 definition in compface.h */
|
|
1386 extern jmp_buf comp_env;
|
|
1387 #undef SYSV32
|
|
1388
|
|
1389 static void
|
|
1390 gtk_xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1391 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1392 int dest_mask, Lisp_Object domain)
|
|
1393 {
|
|
1394 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1395 int i, stattis;
|
|
1396 char *p, *bits, *bp;
|
771
|
1397 const char * volatile emsg = 0;
|
|
1398 const char * volatile dstring;
|
462
|
1399
|
|
1400 assert (!NILP (data));
|
|
1401
|
|
1402 LISP_STRING_TO_EXTERNAL (data, dstring, Qbinary);
|
|
1403
|
|
1404 if ((p = strchr (dstring, ':')))
|
|
1405 {
|
|
1406 dstring = p + 1;
|
|
1407 }
|
|
1408
|
|
1409 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
1410 if (!(stattis = setjmp (comp_env)))
|
|
1411 {
|
|
1412 UnCompAll ((char *) dstring);
|
|
1413 UnGenFace ();
|
|
1414 }
|
|
1415
|
|
1416 switch (stattis)
|
|
1417 {
|
|
1418 case -2:
|
|
1419 emsg = "uncompface: internal error";
|
|
1420 break;
|
|
1421 case -1:
|
|
1422 emsg = "uncompface: insufficient or invalid data";
|
|
1423 break;
|
|
1424 case 1:
|
|
1425 emsg = "uncompface: excess data ignored";
|
|
1426 break;
|
|
1427 }
|
|
1428
|
|
1429 if (emsg)
|
563
|
1430 gui_error_2 (emsg, data, Qimage);
|
462
|
1431
|
851
|
1432 bp = bits = (char *) ALLOCA (PIXELS / 8);
|
462
|
1433
|
|
1434 /* the compface library exports char F[], which uses a single byte per
|
|
1435 pixel to represent a 48x48 bitmap. Yuck. */
|
|
1436 for (i = 0, p = F; i < (PIXELS / 8); ++i)
|
|
1437 {
|
|
1438 int n, b;
|
|
1439 /* reverse the bit order of each byte... */
|
|
1440 for (b = n = 0; b < 8; ++b)
|
|
1441 {
|
|
1442 n |= ((*p++) << b);
|
|
1443 }
|
|
1444 *bp++ = (char) n;
|
|
1445 }
|
|
1446
|
|
1447 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1448 pointer_bg, dest_mask, 48, 48, bits);
|
|
1449 }
|
|
1450
|
|
1451 #endif /* HAVE_XFACE */
|
|
1452
|
|
1453 /**********************************************************************
|
|
1454 * RESOURCES *
|
|
1455 **********************************************************************/
|
|
1456
|
|
1457 static void
|
|
1458 gtk_resource_validate (Lisp_Object instantiator)
|
|
1459 {
|
|
1460 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
|
|
1461 &&
|
|
1462 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
|
|
1463 ||
|
|
1464 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
|
563
|
1465 sferror ("Must supply :file, :resource-id and :resource-type",
|
462
|
1466 instantiator);
|
|
1467 }
|
|
1468
|
|
1469 static Lisp_Object
|
563
|
1470 gtk_resource_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
1471 Lisp_Object dest_mask)
|
462
|
1472 {
|
563
|
1473 return shared_resource_normalize (inst, console_type, dest_mask,
|
|
1474 Qgtk_resource);
|
462
|
1475 }
|
|
1476
|
|
1477 static int
|
|
1478 gtk_resource_possible_dest_types (void)
|
|
1479 {
|
|
1480 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
|
|
1481 }
|
|
1482
|
|
1483 extern guint symbol_to_enum (Lisp_Object, GtkType);
|
|
1484
|
|
1485 static guint resource_name_to_resource (Lisp_Object name, int type)
|
|
1486 {
|
|
1487 if (type == IMAGE_POINTER)
|
|
1488 return (symbol_to_enum (name, GTK_TYPE_GDK_CURSOR_TYPE));
|
|
1489 else
|
|
1490 return (0);
|
|
1491 }
|
|
1492
|
|
1493 static int
|
|
1494 resource_symbol_to_type (Lisp_Object data)
|
|
1495 {
|
|
1496 if (EQ (data, Qcursor))
|
|
1497 return IMAGE_POINTER;
|
|
1498 #if 0
|
|
1499 else if (EQ (data, Qicon))
|
|
1500 return IMAGE_ICON;
|
|
1501 else if (EQ (data, Qbitmap))
|
|
1502 return IMAGE_BITMAP;
|
|
1503 #endif
|
|
1504 else
|
|
1505 return 0;
|
|
1506 }
|
|
1507
|
|
1508 static void
|
|
1509 gtk_resource_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1510 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1511 int dest_mask, Lisp_Object domain)
|
|
1512 {
|
|
1513 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1514 GdkCursor *c = NULL;
|
|
1515 unsigned int type = 0;
|
|
1516 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1517 Lisp_Object resource_type = find_keyword_in_vector (instantiator, Q_resource_type);
|
|
1518 Lisp_Object resource_id = find_keyword_in_vector (instantiator, Q_resource_id);
|
|
1519
|
|
1520 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1521 gui_error ("Not a GTK device", device);
|
462
|
1522
|
|
1523 type = resource_symbol_to_type (resource_type);
|
|
1524
|
595
|
1525 #if 0
|
|
1526 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_POINTER_MASK)
|
|
1527 iitype = IMAGE_POINTER;
|
|
1528 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1529 iitype = IMAGE_COLOR_PIXMAP;
|
|
1530 else
|
|
1531 incompatible_image_types (instantiator, dest_mask,
|
|
1532 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
|
|
1533 #endif
|
|
1534
|
462
|
1535 /* mess with the keyword info we were provided with */
|
|
1536 gtk_initialize_pixmap_image_instance (ii, 1, type);
|
|
1537 c = gdk_cursor_new (resource_name_to_resource (resource_id, type));
|
|
1538 IMAGE_INSTANCE_GTK_CURSOR (ii) = c;
|
|
1539 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = resource_id;
|
|
1540 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = 10;
|
|
1541 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = 10;
|
|
1542 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
|
|
1543 }
|
|
1544
|
|
1545 static void
|
|
1546 check_valid_resource_symbol (Lisp_Object data)
|
|
1547 {
|
|
1548 CHECK_SYMBOL (data);
|
|
1549 if (!resource_symbol_to_type (data))
|
563
|
1550 invalid_constant ("invalid resource type", data);
|
462
|
1551 }
|
|
1552
|
|
1553 static void
|
|
1554 check_valid_resource_id (Lisp_Object data)
|
|
1555 {
|
|
1556 if (!resource_name_to_resource (data, IMAGE_POINTER)
|
|
1557 &&
|
|
1558 !resource_name_to_resource (data, IMAGE_COLOR_PIXMAP)
|
|
1559 #if 0
|
|
1560 &&
|
|
1561 !resource_name_to_resource (data, IMAGE_BITMAP)
|
|
1562 #endif
|
|
1563 )
|
563
|
1564 invalid_constant ("invalid resource identifier", data);
|
462
|
1565 }
|
|
1566
|
|
1567 #if 0
|
|
1568 void
|
|
1569 check_valid_string_or_int (Lisp_Object data)
|
|
1570 {
|
|
1571 if (!INTP (data))
|
|
1572 CHECK_STRING (data);
|
|
1573 else
|
|
1574 CHECK_INT (data);
|
|
1575 }
|
|
1576 #endif
|
|
1577
|
|
1578
|
|
1579 /**********************************************************************
|
|
1580 * Autodetect *
|
|
1581 **********************************************************************/
|
|
1582
|
|
1583 static void
|
|
1584 autodetect_validate (Lisp_Object instantiator)
|
|
1585 {
|
|
1586 data_must_be_present (instantiator);
|
|
1587 }
|
|
1588
|
|
1589 static Lisp_Object
|
|
1590 autodetect_normalize (Lisp_Object instantiator,
|
|
1591 Lisp_Object console_type,
|
|
1592 Lisp_Object dest_mask)
|
|
1593 {
|
|
1594 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
1595 Lisp_Object filename = Qnil;
|
|
1596 Lisp_Object data = Qnil;
|
|
1597 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1598 Lisp_Object alist = Qnil;
|
|
1599
|
|
1600 GCPRO3 (filename, data, alist);
|
|
1601
|
|
1602 if (NILP (file)) /* no conversion necessary */
|
|
1603 RETURN_UNGCPRO (instantiator);
|
|
1604
|
|
1605 alist = tagged_vector_to_alist (instantiator);
|
|
1606
|
|
1607 filename = locate_pixmap_file (file);
|
|
1608 if (!NILP (filename))
|
|
1609 {
|
|
1610 int xhot, yhot;
|
|
1611 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
1612 called by pixmap_to_lisp_data, don't return an error value
|
|
1613 if the given file is not a valid XPM file. Instead, they
|
|
1614 just seg fault. It is definitely caused by passing a
|
|
1615 bitmap. To try and avoid this we check for bitmaps first. */
|
|
1616
|
|
1617 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
1618
|
|
1619 if (!EQ (data, Qt))
|
|
1620 {
|
|
1621 alist = remassq_no_quit (Q_data, alist);
|
|
1622 alist = Fcons (Fcons (Q_file, filename),
|
|
1623 Fcons (Fcons (Q_data, data), alist));
|
|
1624 if (xhot != -1)
|
|
1625 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
1626 alist);
|
|
1627 if (yhot != -1)
|
|
1628 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
1629 alist);
|
|
1630
|
|
1631 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type);
|
|
1632
|
|
1633 {
|
|
1634 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
1635 free_alist (alist);
|
|
1636 RETURN_UNGCPRO (result);
|
|
1637 }
|
|
1638 }
|
|
1639
|
|
1640 #ifdef HAVE_XPM
|
|
1641 data = pixmap_to_lisp_data (filename, 1);
|
|
1642
|
|
1643 if (!EQ (data, Qt))
|
|
1644 {
|
|
1645 alist = remassq_no_quit (Q_data, alist);
|
|
1646 alist = Fcons (Fcons (Q_file, filename),
|
|
1647 Fcons (Fcons (Q_data, data), alist));
|
|
1648 alist = Fcons (Fcons (Q_color_symbols,
|
|
1649 evaluate_xpm_color_symbols ()),
|
|
1650 alist);
|
|
1651 {
|
|
1652 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1653 free_alist (alist);
|
|
1654 RETURN_UNGCPRO (result);
|
|
1655 }
|
|
1656 }
|
|
1657 #endif
|
|
1658 }
|
|
1659
|
|
1660 /* If we couldn't convert it, just put it back as it is.
|
|
1661 We might try to further frob it later as a cursor-font
|
|
1662 specification. (We can't do that now because we don't know
|
|
1663 what dest-types it's going to be instantiated into.) */
|
|
1664 {
|
|
1665 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
|
1666 free_alist (alist);
|
|
1667 RETURN_UNGCPRO (result);
|
|
1668 }
|
|
1669 }
|
|
1670
|
|
1671 static int
|
|
1672 autodetect_possible_dest_types (void)
|
|
1673 {
|
|
1674 return
|
|
1675 IMAGE_MONO_PIXMAP_MASK |
|
|
1676 IMAGE_COLOR_PIXMAP_MASK |
|
|
1677 IMAGE_POINTER_MASK |
|
|
1678 IMAGE_TEXT_MASK;
|
|
1679 }
|
|
1680
|
|
1681 static void
|
|
1682 autodetect_instantiate (Lisp_Object image_instance,
|
|
1683 Lisp_Object instantiator,
|
|
1684 Lisp_Object pointer_fg,
|
|
1685 Lisp_Object pointer_bg,
|
|
1686 int dest_mask, Lisp_Object domain)
|
|
1687 {
|
|
1688 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1689 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1690 Lisp_Object alist = Qnil;
|
|
1691 Lisp_Object result = Qnil;
|
|
1692 int is_cursor_font = 0;
|
|
1693
|
|
1694 GCPRO3 (data, alist, result);
|
|
1695
|
|
1696 alist = tagged_vector_to_alist (instantiator);
|
|
1697 if (dest_mask & IMAGE_POINTER_MASK)
|
|
1698 {
|
771
|
1699 const char *name_ext;
|
462
|
1700
|
|
1701 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
1702 C_STRING_ALLOCA, name_ext,
|
|
1703 Qfile_name);
|
|
1704
|
|
1705 if (cursor_name_to_index (name_ext) != -1)
|
|
1706 {
|
|
1707 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
1708 is_cursor_font = 1;
|
|
1709 }
|
|
1710 }
|
|
1711
|
|
1712 if (!is_cursor_font)
|
|
1713 result = alist_to_tagged_vector (Qstring, alist);
|
|
1714 free_alist (alist);
|
|
1715
|
|
1716 if (is_cursor_font)
|
|
1717 cursor_font_instantiate (image_instance, result, pointer_fg,
|
|
1718 pointer_bg, dest_mask, domain);
|
|
1719 else
|
|
1720 string_instantiate (image_instance, result, pointer_fg,
|
|
1721 pointer_bg, dest_mask, domain);
|
|
1722
|
|
1723 UNGCPRO;
|
|
1724 }
|
|
1725
|
|
1726
|
|
1727 /**********************************************************************
|
|
1728 * Font *
|
|
1729 **********************************************************************/
|
|
1730
|
|
1731 static void
|
|
1732 font_validate (Lisp_Object instantiator)
|
|
1733 {
|
|
1734 data_must_be_present (instantiator);
|
|
1735 }
|
|
1736
|
|
1737 static int
|
|
1738 font_possible_dest_types (void)
|
|
1739 {
|
|
1740 return IMAGE_POINTER_MASK;
|
|
1741 }
|
|
1742
|
|
1743 static void
|
|
1744 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1745 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1746 int dest_mask, Lisp_Object domain)
|
|
1747 {
|
|
1748 /* This function can GC */
|
|
1749 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1750 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1751 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1752 GdkColor fg, bg;
|
|
1753 GdkFont *source, *mask;
|
771
|
1754 char source_name[PATH_MAX], mask_name[PATH_MAX], dummy;
|
462
|
1755 int source_char, mask_char;
|
|
1756 int count;
|
|
1757 Lisp_Object foreground, background;
|
|
1758
|
|
1759 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1760 gui_error ("Not a Gtk device", device);
|
462
|
1761
|
|
1762 if (!STRINGP (data) ||
|
|
1763 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
563
|
1764 invalid_argument ("Invalid font-glyph instantiator",
|
462
|
1765 instantiator);
|
|
1766
|
|
1767 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1768 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1769
|
|
1770 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1771 if (NILP (foreground))
|
|
1772 foreground = pointer_fg;
|
|
1773 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1774 if (NILP (background))
|
|
1775 background = pointer_bg;
|
|
1776
|
|
1777 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
1778
|
|
1779 count = sscanf ((char *) XSTRING_DATA (data),
|
|
1780 "FONT %s %d %s %d %c",
|
|
1781 source_name, &source_char,
|
|
1782 mask_name, &mask_char, &dummy);
|
|
1783 /* Allow "%s %d %d" as well... */
|
|
1784 if (count == 3 && (1 == sscanf (mask_name, "%d %c", &mask_char, &dummy)))
|
|
1785 count = 4, mask_name[0] = 0;
|
|
1786
|
|
1787 if (count != 2 && count != 4)
|
563
|
1788 syntax_error ("invalid cursor specification", data);
|
462
|
1789 source = gdk_font_load (source_name);
|
|
1790 if (! source)
|
563
|
1791 gui_error_2 ("couldn't load font",
|
462
|
1792 build_string (source_name),
|
|
1793 data);
|
|
1794 if (count == 2)
|
|
1795 mask = 0;
|
|
1796 else if (!mask_name[0])
|
|
1797 mask = source;
|
|
1798 else
|
|
1799 {
|
|
1800 mask = gdk_font_load (mask_name);
|
|
1801 if (!mask)
|
|
1802 /* continuable */
|
771
|
1803 Fsignal (Qgui_error, list3 (build_msg_string ("couldn't load font"),
|
563
|
1804 build_string (mask_name), data));
|
462
|
1805 }
|
|
1806 if (!mask)
|
|
1807 mask_char = 0;
|
|
1808
|
|
1809 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
1810
|
|
1811 gtk_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1812
|
|
1813 IMAGE_INSTANCE_GTK_CURSOR (ii) = NULL;
|
|
1814
|
|
1815 #if 0
|
|
1816 /* #### BILL!!! There is no way to call this function from Gdk */
|
|
1817 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
1818 &fg, &bg);
|
|
1819 #endif
|
|
1820 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
1821 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
1822
|
|
1823 gdk_font_unref (source);
|
|
1824 if (mask && mask != source) gdk_font_unref (mask);
|
|
1825 }
|
|
1826
|
|
1827
|
|
1828 /**********************************************************************
|
|
1829 * Cursor-Font *
|
|
1830 **********************************************************************/
|
|
1831
|
|
1832 static void
|
|
1833 cursor_font_validate (Lisp_Object instantiator)
|
|
1834 {
|
|
1835 data_must_be_present (instantiator);
|
|
1836 }
|
|
1837
|
|
1838 static int
|
|
1839 cursor_font_possible_dest_types (void)
|
|
1840 {
|
|
1841 return IMAGE_POINTER_MASK;
|
|
1842 }
|
|
1843
|
|
1844 static char *__downcase (const char *name)
|
|
1845 {
|
|
1846 char *converted = strdup(name);
|
|
1847 char *work = converted;
|
|
1848
|
|
1849 while (*work)
|
|
1850 {
|
|
1851 *work = tolower(*work);
|
|
1852 work++;
|
|
1853 }
|
|
1854 return(converted);
|
|
1855 }
|
|
1856
|
|
1857 /* This is basically the equivalent of XmuCursorNameToIndex */
|
|
1858 static gint
|
|
1859 cursor_name_to_index (const char *name)
|
|
1860 {
|
|
1861 int i;
|
|
1862 static char *the_gdk_cursors[GDK_NUM_GLYPHS];
|
|
1863
|
|
1864 if (!the_gdk_cursors[GDK_BASED_ARROW_UP])
|
|
1865 {
|
|
1866 /* Need to initialize the array */
|
|
1867 /* Supposedly since this array is static it should be
|
|
1868 initialized to NULLs for us, but I'm very paranoid. */
|
|
1869 for (i = 0; i < GDK_NUM_GLYPHS; i++)
|
|
1870 {
|
|
1871 the_gdk_cursors[i] = NULL;
|
|
1872 }
|
|
1873
|
|
1874 #define FROB_CURSOR(x) the_gdk_cursors[GDK_##x] = __downcase(#x)
|
|
1875 FROB_CURSOR(ARROW); FROB_CURSOR(BASED_ARROW_DOWN);
|
|
1876 FROB_CURSOR(BASED_ARROW_UP); FROB_CURSOR(BOAT);
|
|
1877 FROB_CURSOR(BOGOSITY); FROB_CURSOR(BOTTOM_LEFT_CORNER);
|
|
1878 FROB_CURSOR(BOTTOM_RIGHT_CORNER); FROB_CURSOR(BOTTOM_SIDE);
|
|
1879 FROB_CURSOR(BOTTOM_TEE); FROB_CURSOR(BOX_SPIRAL);
|
|
1880 FROB_CURSOR(CENTER_PTR); FROB_CURSOR(CIRCLE);
|
|
1881 FROB_CURSOR(CLOCK); FROB_CURSOR(COFFEE_MUG);
|
|
1882 FROB_CURSOR(CROSS); FROB_CURSOR(CROSS_REVERSE);
|
|
1883 FROB_CURSOR(CROSSHAIR); FROB_CURSOR(DIAMOND_CROSS);
|
|
1884 FROB_CURSOR(DOT); FROB_CURSOR(DOTBOX);
|
|
1885 FROB_CURSOR(DOUBLE_ARROW); FROB_CURSOR(DRAFT_LARGE);
|
|
1886 FROB_CURSOR(DRAFT_SMALL); FROB_CURSOR(DRAPED_BOX);
|
|
1887 FROB_CURSOR(EXCHANGE); FROB_CURSOR(FLEUR);
|
|
1888 FROB_CURSOR(GOBBLER); FROB_CURSOR(GUMBY);
|
|
1889 FROB_CURSOR(HAND1); FROB_CURSOR(HAND2);
|
|
1890 FROB_CURSOR(HEART); FROB_CURSOR(ICON);
|
|
1891 FROB_CURSOR(IRON_CROSS); FROB_CURSOR(LEFT_PTR);
|
|
1892 FROB_CURSOR(LEFT_SIDE); FROB_CURSOR(LEFT_TEE);
|
|
1893 FROB_CURSOR(LEFTBUTTON); FROB_CURSOR(LL_ANGLE);
|
|
1894 FROB_CURSOR(LR_ANGLE); FROB_CURSOR(MAN);
|
|
1895 FROB_CURSOR(MIDDLEBUTTON); FROB_CURSOR(MOUSE);
|
|
1896 FROB_CURSOR(PENCIL); FROB_CURSOR(PIRATE);
|
|
1897 FROB_CURSOR(PLUS); FROB_CURSOR(QUESTION_ARROW);
|
|
1898 FROB_CURSOR(RIGHT_PTR); FROB_CURSOR(RIGHT_SIDE);
|
|
1899 FROB_CURSOR(RIGHT_TEE); FROB_CURSOR(RIGHTBUTTON);
|
|
1900 FROB_CURSOR(RTL_LOGO); FROB_CURSOR(SAILBOAT);
|
|
1901 FROB_CURSOR(SB_DOWN_ARROW); FROB_CURSOR(SB_H_DOUBLE_ARROW);
|
|
1902 FROB_CURSOR(SB_LEFT_ARROW); FROB_CURSOR(SB_RIGHT_ARROW);
|
|
1903 FROB_CURSOR(SB_UP_ARROW); FROB_CURSOR(SB_V_DOUBLE_ARROW);
|
|
1904 FROB_CURSOR(SHUTTLE); FROB_CURSOR(SIZING);
|
|
1905 FROB_CURSOR(SPIDER); FROB_CURSOR(SPRAYCAN);
|
|
1906 FROB_CURSOR(STAR); FROB_CURSOR(TARGET);
|
|
1907 FROB_CURSOR(TCROSS); FROB_CURSOR(TOP_LEFT_ARROW);
|
|
1908 FROB_CURSOR(TOP_LEFT_CORNER); FROB_CURSOR(TOP_RIGHT_CORNER);
|
|
1909 FROB_CURSOR(TOP_SIDE); FROB_CURSOR(TOP_TEE);
|
|
1910 FROB_CURSOR(TREK); FROB_CURSOR(UL_ANGLE);
|
|
1911 FROB_CURSOR(UMBRELLA); FROB_CURSOR(UR_ANGLE);
|
|
1912 FROB_CURSOR(WATCH); FROB_CURSOR(XTERM);
|
|
1913 FROB_CURSOR(X_CURSOR);
|
|
1914 #undef FROB_CURSOR
|
|
1915 }
|
|
1916
|
|
1917 for (i = 0; i < GDK_NUM_GLYPHS; i++)
|
|
1918 {
|
|
1919 if (!the_gdk_cursors[i]) continue;
|
|
1920 if (!strcmp (the_gdk_cursors[i], name))
|
|
1921 {
|
|
1922 return (i);
|
|
1923 }
|
|
1924 }
|
|
1925 return(-1);
|
|
1926 }
|
|
1927
|
|
1928 static void
|
|
1929 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1930 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1931 int dest_mask, Lisp_Object domain)
|
|
1932 {
|
|
1933 /* This function can GC */
|
|
1934 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1935 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1936 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1937 int i;
|
771
|
1938 const char *name_ext;
|
462
|
1939 Lisp_Object foreground, background;
|
|
1940
|
|
1941 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1942 gui_error ("Not a Gtk device", device);
|
462
|
1943
|
|
1944 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1945 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1946
|
|
1947 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
1948 C_STRING_ALLOCA, name_ext,
|
|
1949 Qfile_name);
|
|
1950
|
|
1951 if ((i = cursor_name_to_index (name_ext)) == -1)
|
563
|
1952 invalid_argument ("Unrecognized cursor-font name", data);
|
462
|
1953
|
|
1954 gtk_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1955 IMAGE_INSTANCE_GTK_CURSOR (ii) = gdk_cursor_new (i);
|
|
1956 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1957 if (NILP (foreground))
|
|
1958 foreground = pointer_fg;
|
|
1959 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1960 if (NILP (background))
|
|
1961 background = pointer_bg;
|
|
1962 maybe_recolor_cursor (image_instance, foreground, background);
|
|
1963 }
|
|
1964
|
|
1965 static int
|
|
1966 gtk_colorize_image_instance (Lisp_Object image_instance,
|
|
1967 Lisp_Object foreground, Lisp_Object background);
|
|
1968
|
|
1969
|
|
1970 /************************************************************************/
|
|
1971 /* subwindow and widget support */
|
|
1972 /************************************************************************/
|
|
1973
|
|
1974 /* unmap the image if it is a widget. This is used by redisplay via
|
|
1975 redisplay_unmap_subwindows */
|
|
1976 static void
|
|
1977 gtk_unmap_subwindow (Lisp_Image_Instance *p)
|
|
1978 {
|
|
1979 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
1980 {
|
|
1981 /* We don't support subwindows, but we do support widgets... */
|
|
1982 abort ();
|
|
1983 }
|
|
1984 else /* must be a widget */
|
|
1985 {
|
|
1986 /* Since we are being unmapped we want the enclosing frame to
|
|
1987 get focus. The losing with simple scrolling but is the safest
|
|
1988 thing to do. */
|
|
1989 if (IMAGE_INSTANCE_GTK_CLIPWIDGET (p))
|
|
1990 gtk_widget_unmap (IMAGE_INSTANCE_GTK_CLIPWIDGET (p));
|
|
1991 }
|
|
1992 }
|
|
1993
|
|
1994 /* map the subwindow. This is used by redisplay via
|
|
1995 redisplay_output_subwindow */
|
|
1996 static void
|
|
1997 gtk_map_subwindow (Lisp_Image_Instance *p, int x, int y,
|
691
|
1998 struct display_glyph_area* dga)
|
462
|
1999 {
|
|
2000 assert (dga->width > 0 && dga->height > 0);
|
|
2001
|
|
2002 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
2003 {
|
|
2004 /* No subwindow support... */
|
|
2005 abort ();
|
|
2006 }
|
|
2007 else /* must be a widget */
|
|
2008 {
|
|
2009 struct frame *f = XFRAME (IMAGE_INSTANCE_FRAME (p));
|
|
2010 GtkWidget *wid = IMAGE_INSTANCE_GTK_CLIPWIDGET (p);
|
|
2011 GtkAllocation a;
|
|
2012
|
|
2013 if (!wid) return;
|
|
2014
|
|
2015 a.x = x + IMAGE_INSTANCE_GTK_WIDGET_XOFFSET (p);
|
|
2016 a.y = y + IMAGE_INSTANCE_GTK_WIDGET_YOFFSET (p);
|
|
2017 a.width = dga->width;
|
|
2018 a.height = dga->height;
|
|
2019
|
|
2020 if ((a.width != wid->allocation.width) ||
|
|
2021 (a.height != wid->allocation.height))
|
|
2022 {
|
|
2023 gtk_widget_size_allocate (IMAGE_INSTANCE_GTK_CLIPWIDGET (p), &a);
|
|
2024 }
|
|
2025
|
|
2026 /* #### FIXME DAMMIT */
|
|
2027 if ((wid->allocation.x != -dga->xoffset) ||
|
|
2028 (wid->allocation.y != -dga->yoffset))
|
|
2029 {
|
|
2030 guint32 old_flags = GTK_WIDGET_FLAGS (FRAME_GTK_TEXT_WIDGET (f));
|
|
2031
|
|
2032 /* Fucking GtkFixed widget queues a resize when you add a widget.
|
|
2033 ** But only if it is visible.
|
|
2034 ** losers.
|
|
2035 */
|
|
2036 GTK_WIDGET_FLAGS(FRAME_GTK_TEXT_WIDGET (f)) &= ~GTK_VISIBLE;
|
|
2037 if (IMAGE_INSTANCE_GTK_ALREADY_PUT(p))
|
|
2038 {
|
|
2039 gtk_fixed_move (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
2040 wid,
|
|
2041 -dga->xoffset, -dga->yoffset);
|
|
2042 }
|
|
2043 else
|
|
2044 {
|
|
2045 IMAGE_INSTANCE_GTK_ALREADY_PUT(p) = TRUE;
|
|
2046 gtk_fixed_put (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
2047 wid,
|
|
2048 -dga->xoffset, -dga->yoffset);
|
|
2049 }
|
|
2050 GTK_WIDGET_FLAGS(FRAME_GTK_TEXT_WIDGET (f)) = old_flags;
|
|
2051 }
|
691
|
2052 else
|
|
2053 {
|
|
2054 if (IMAGE_INSTANCE_GTK_ALREADY_PUT(p))
|
|
2055 {
|
|
2056 /* Do nothing... */
|
|
2057 }
|
|
2058 else
|
|
2059 {
|
|
2060 /* Must make sure we have put the image at least once! */
|
|
2061 IMAGE_INSTANCE_GTK_ALREADY_PUT(p) = TRUE;
|
|
2062 gtk_fixed_put (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
2063 wid,
|
|
2064 -dga->xoffset, -dga->yoffset);
|
|
2065 }
|
|
2066 }
|
462
|
2067
|
|
2068 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
|
|
2069 {
|
|
2070 gtk_widget_map (wid);
|
|
2071 }
|
|
2072
|
|
2073 gtk_widget_draw (wid, NULL);
|
|
2074 }
|
|
2075 }
|
|
2076
|
|
2077 /* when you click on a widget you may activate another widget this
|
|
2078 needs to be checked and all appropriate widgets updated */
|
|
2079 static void
|
|
2080 gtk_redisplay_subwindow (Lisp_Image_Instance *p)
|
|
2081 {
|
|
2082 /* Update the subwindow size if necessary. */
|
|
2083 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
|
|
2084 {
|
|
2085 #if 0
|
|
2086 XResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2087 IMAGE_INSTANCE_X_SUBWINDOW_ID (p),
|
|
2088 IMAGE_INSTANCE_WIDTH (p),
|
|
2089 IMAGE_INSTANCE_HEIGHT (p));
|
|
2090 #endif
|
|
2091 }
|
|
2092 }
|
|
2093
|
|
2094 /* Update all attributes that have changed. */
|
|
2095 static void
|
|
2096 gtk_redisplay_widget (Lisp_Image_Instance *p)
|
|
2097 {
|
|
2098 /* This function can GC if IN_REDISPLAY is false. */
|
|
2099
|
|
2100 if (!IMAGE_INSTANCE_GTK_CLIPWIDGET (p))
|
|
2101 return;
|
|
2102
|
|
2103 #ifdef HAVE_WIDGETS
|
|
2104 /* First get the items if they have changed since this is a
|
|
2105 structural change. As such it will nuke all added values so we
|
|
2106 need to update most other things after the items have changed.*/
|
|
2107 gtk_widget_show_all (IMAGE_INSTANCE_GTK_CLIPWIDGET (p));
|
|
2108 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2109 {
|
793
|
2110 Lisp_Object image_instance = wrap_image_instance (p);
|
|
2111
|
462
|
2112
|
|
2113 /* Need to update GtkArgs that might have changed... */
|
|
2114 /* #### FIXME!!! */
|
|
2115 }
|
|
2116 else
|
|
2117 {
|
|
2118 /* #### FIXME!!! */
|
|
2119 /* No items changed, so do nothing, right? */
|
|
2120 }
|
|
2121
|
|
2122 /* Possibly update the colors and font */
|
|
2123 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p)
|
|
2124 ||
|
|
2125 /* #### This is not sufficient because it will not cope with widgets
|
|
2126 that are not currently visible. Once redisplay has done the
|
|
2127 visible ones it will clear this flag so that when new ones
|
|
2128 become visible they will not be updated. */
|
|
2129 XFRAME (IMAGE_INSTANCE_FRAME (p))->faces_changed
|
|
2130 ||
|
|
2131 XFRAME (IMAGE_INSTANCE_FRAME (p))->frame_changed
|
|
2132 ||
|
|
2133 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2134 {
|
|
2135 /* #### Write this function BILL! */
|
|
2136 update_widget_face (NULL, p, IMAGE_INSTANCE_FRAME (p));
|
|
2137 }
|
|
2138
|
|
2139 /* Possibly update the text. */
|
|
2140 if (IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2141 {
|
|
2142 char* str;
|
|
2143 Lisp_Object val = IMAGE_INSTANCE_WIDGET_TEXT (p);
|
|
2144 LISP_STRING_TO_EXTERNAL (val, str, Qnative);
|
|
2145
|
|
2146 /* #### Need to special case each type of GtkWidget here! */
|
|
2147 }
|
|
2148
|
|
2149 /* Possibly update the size. */
|
|
2150 if (IMAGE_INSTANCE_SIZE_CHANGED (p)
|
|
2151 ||
|
|
2152 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p)
|
|
2153 ||
|
|
2154 IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2155 {
|
|
2156 assert (IMAGE_INSTANCE_GTK_WIDGET_ID (p) &&
|
|
2157 IMAGE_INSTANCE_GTK_CLIPWIDGET (p)) ;
|
|
2158
|
|
2159 /* #### Resize the widget! */
|
|
2160 /* gtk_widget_size_allocate () */
|
|
2161 }
|
|
2162
|
|
2163 /* Adjust offsets within the frame. */
|
|
2164 if (XFRAME (IMAGE_INSTANCE_FRAME (p))->size_changed)
|
|
2165 {
|
|
2166 /* I don't think we need to do anything for Gtk here... */
|
|
2167 }
|
|
2168
|
|
2169 /* now modify the widget */
|
|
2170 #endif
|
|
2171 }
|
|
2172
|
|
2173 /* instantiate and gtk type subwindow */
|
|
2174 static void
|
|
2175 gtk_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2176 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2177 int dest_mask, Lisp_Object domain)
|
|
2178 {
|
|
2179 /* This function can GC */
|
|
2180 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2181 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
2182
|
|
2183 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
2184 gui_error ("Not a GTK device", device);
|
462
|
2185
|
|
2186 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
|
|
2187
|
|
2188 ii->data = xnew_and_zero (struct gtk_subwindow_data);
|
|
2189
|
|
2190 /* Create a window for clipping */
|
|
2191 IMAGE_INSTANCE_GTK_CLIPWINDOW (ii) = NULL;
|
|
2192
|
|
2193 /* Now put the subwindow inside the clip window. */
|
|
2194 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void *) NULL;
|
|
2195 }
|
|
2196
|
|
2197 #ifdef HAVE_WIDGETS
|
|
2198
|
|
2199 /************************************************************************/
|
|
2200 /* widgets */
|
|
2201 /************************************************************************/
|
|
2202 static void
|
|
2203 update_widget_face (GtkWidget *w, Lisp_Image_Instance *ii,
|
|
2204 Lisp_Object domain)
|
|
2205 {
|
|
2206 if (0)
|
|
2207 {
|
|
2208 GtkStyle *style = gtk_widget_get_style (w);
|
|
2209 Lisp_Object pixel = Qnil;
|
|
2210 GdkColor *fcolor, *bcolor;
|
|
2211
|
|
2212 style = gtk_style_copy (style);
|
|
2213
|
|
2214 /* Update the foreground. */
|
|
2215 pixel = FACE_FOREGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain);
|
|
2216 fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2217
|
|
2218 /* Update the background. */
|
|
2219 pixel = FACE_BACKGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain);
|
|
2220 bcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2221
|
|
2222 /* Update the font */
|
|
2223 /* #### FIXME!!! Need to copy the widgets style, dick with it, and
|
|
2224 ** set the widgets style to the new style...
|
|
2225 */
|
|
2226 gtk_widget_set_style (w, style);
|
|
2227
|
|
2228 /* #### Megahack - but its just getting too complicated to do this
|
|
2229 in the right place. */
|
|
2230 #if 0
|
|
2231 if (EQ (IMAGE_INSTANCE_WIDGET_TYPE (ii), Qtab_control))
|
|
2232 update_tab_widget_face (wv, ii, domain);
|
|
2233 #endif
|
|
2234 }
|
|
2235 }
|
|
2236
|
|
2237 #if 0
|
|
2238 static void
|
|
2239 update_tab_widget_face (GtkWidget *w, Lisp_Image_Instance *ii,
|
|
2240 Lisp_Object domain)
|
|
2241 {
|
|
2242 if (wv->contents)
|
|
2243 {
|
|
2244 widget_value* val = wv->contents, *cur;
|
|
2245
|
|
2246 /* Give each child label the correct foreground color. */
|
|
2247 Lisp_Object pixel = FACE_FOREGROUND
|
|
2248 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
|
2249 domain);
|
|
2250 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2251 lw_add_widget_value_arg (val, XtNtabForeground, fcolor.pixel);
|
|
2252 wv->change = VISIBLE_CHANGE;
|
|
2253 val->change = VISIBLE_CHANGE;
|
|
2254
|
|
2255 for (cur = val->next; cur; cur = cur->next)
|
|
2256 {
|
|
2257 cur->change = VISIBLE_CHANGE;
|
|
2258 if (cur->value)
|
|
2259 {
|
|
2260 lw_copy_widget_value_args (val, cur);
|
|
2261 }
|
|
2262 }
|
|
2263 }
|
|
2264 }
|
|
2265 #endif
|
|
2266
|
|
2267 static Lisp_Object
|
|
2268 gtk_widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2269 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2270 Lisp_Object domain)
|
|
2271 {
|
|
2272 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2273 Lisp_Object widget = Qnil;
|
|
2274 char *nm = NULL;
|
|
2275 GtkWidget *w = NULL;
|
|
2276 struct gcpro gcpro1;
|
|
2277
|
|
2278 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
|
|
2279
|
|
2280 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
|
|
2281 {
|
|
2282 LISP_STRING_TO_EXTERNAL (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm, Qnative);
|
|
2283 }
|
|
2284
|
|
2285 ii->data = xnew_and_zero (struct gtk_subwindow_data);
|
|
2286
|
|
2287 /* Create a clipping widget */
|
|
2288 IMAGE_INSTANCE_GTK_CLIPWIDGET (ii) = NULL;
|
|
2289 IMAGE_INSTANCE_GTK_ALREADY_PUT(ii) = FALSE;
|
|
2290
|
|
2291 /* Create the actual widget */
|
|
2292 GCPRO1 (widget);
|
|
2293 widget = call5 (Qgtk_widget_instantiate_internal,
|
|
2294 image_instance, instantiator,
|
|
2295 pointer_fg, pointer_bg,
|
|
2296 domain);
|
|
2297
|
|
2298 if (!NILP (widget))
|
|
2299 {
|
|
2300 CHECK_GTK_OBJECT (widget);
|
|
2301 w = GTK_WIDGET (XGTK_OBJECT (widget)->object);
|
|
2302 }
|
|
2303 else
|
|
2304 {
|
|
2305 stderr_out ("Lisp-level creation of widget failed... falling back\n");
|
|
2306 w = gtk_label_new ("Widget Creation Failed...");
|
|
2307 }
|
|
2308
|
|
2309 UNGCPRO;
|
|
2310
|
|
2311 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void *) w;
|
|
2312
|
|
2313 /* #### HACK!!!! We should make this do the right thing if we
|
|
2314 ** really need a clip widget!
|
|
2315 */
|
|
2316 IMAGE_INSTANCE_GTK_CLIPWIDGET (ii) = w;
|
|
2317
|
|
2318 return (Qt);
|
|
2319 }
|
|
2320
|
|
2321 static void
|
|
2322 gtk_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2323 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2324 int dest_mask, Lisp_Object domain)
|
|
2325 {
|
|
2326 call_with_suspended_errors ((lisp_fn_t) gtk_widget_instantiate_1,
|
|
2327 Qnil, Qimage,
|
|
2328 ERROR_ME_WARN, 5,
|
|
2329 image_instance, instantiator,
|
|
2330 pointer_fg,
|
|
2331 pointer_bg,
|
|
2332 domain);
|
|
2333 }
|
|
2334
|
|
2335 /* get properties of a control */
|
|
2336 static Lisp_Object
|
|
2337 gtk_widget_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2338 {
|
|
2339 /* Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); */
|
|
2340
|
|
2341 /* get the text from a control */
|
|
2342 if (EQ (prop, Q_text))
|
|
2343 {
|
|
2344 return Qnil;
|
|
2345 }
|
|
2346 return Qunbound;
|
|
2347 }
|
|
2348
|
|
2349 #define FAKE_GTK_WIDGET_INSTANTIATOR(x) \
|
|
2350 static void \
|
|
2351 gtk_##x##_instantiate (Lisp_Object image_instance, \
|
|
2352 Lisp_Object instantiator, \
|
|
2353 Lisp_Object pointer_fg, \
|
|
2354 Lisp_Object pointer_bg, \
|
|
2355 int dest_mask, Lisp_Object domain) \
|
|
2356 { \
|
|
2357 gtk_widget_instantiate (image_instance, instantiator, pointer_fg, \
|
|
2358 pointer_bg, dest_mask, domain); \
|
|
2359 }
|
|
2360
|
|
2361 FAKE_GTK_WIDGET_INSTANTIATOR(native_layout);
|
|
2362 FAKE_GTK_WIDGET_INSTANTIATOR(button);
|
|
2363 FAKE_GTK_WIDGET_INSTANTIATOR(progress_gauge);
|
|
2364 FAKE_GTK_WIDGET_INSTANTIATOR(edit_field);
|
|
2365 FAKE_GTK_WIDGET_INSTANTIATOR(combo_box);
|
|
2366 FAKE_GTK_WIDGET_INSTANTIATOR(tab_control);
|
|
2367 FAKE_GTK_WIDGET_INSTANTIATOR(label);
|
|
2368
|
|
2369 /* Update a button's clicked state. */
|
|
2370 static void
|
|
2371 gtk_button_redisplay (Lisp_Object image_instance)
|
|
2372 {
|
|
2373 /* This function can GC if IN_REDISPLAY is false. */
|
|
2374 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
2375 GtkWidget *w = IMAGE_INSTANCE_GTK_CLIPWIDGET (p);
|
|
2376
|
|
2377 if (GTK_WIDGET_TYPE (w) == gtk_button_get_type ())
|
|
2378 {
|
|
2379 }
|
|
2380 else if (GTK_WIDGET_TYPE (w) == gtk_check_button_get_type ())
|
|
2381 {
|
|
2382 }
|
|
2383 else if (GTK_WIDGET_TYPE (w) == gtk_radio_button_get_type ())
|
|
2384 {
|
|
2385 }
|
|
2386 else
|
|
2387 {
|
|
2388 /* Unknown button type... */
|
|
2389 abort();
|
|
2390 }
|
|
2391 }
|
|
2392
|
|
2393 /* get properties of a button */
|
|
2394 static Lisp_Object
|
|
2395 gtk_button_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2396 {
|
|
2397 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2398
|
|
2399 /* check the state of a button */
|
|
2400 if (EQ (prop, Q_selected))
|
|
2401 {
|
|
2402 if (GTK_WIDGET_HAS_FOCUS (IMAGE_INSTANCE_SUBWINDOW_ID (ii)))
|
|
2403 return Qt;
|
|
2404 else
|
|
2405 return Qnil;
|
|
2406 }
|
|
2407 return Qunbound;
|
|
2408 }
|
|
2409
|
|
2410 /* set the properties of a progress gauge */
|
|
2411 static void
|
|
2412 gtk_progress_gauge_redisplay (Lisp_Object image_instance)
|
|
2413 {
|
|
2414 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2415
|
|
2416 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
|
|
2417 {
|
|
2418 gfloat f;
|
|
2419 Lisp_Object val;
|
|
2420
|
|
2421 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))->value;
|
|
2422 f = XFLOATINT (val);
|
|
2423
|
|
2424 gtk_progress_set_value (GTK_PROGRESS (IMAGE_INSTANCE_SUBWINDOW_ID (ii)),
|
|
2425 f);
|
|
2426 }
|
|
2427 }
|
|
2428
|
|
2429 /* Set the properties of a tab control */
|
|
2430 static void
|
|
2431 gtk_tab_control_redisplay (Lisp_Object image_instance)
|
|
2432 {
|
|
2433 /* #### Convert this to GTK baby! */
|
|
2434 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2435
|
|
2436 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) ||
|
|
2437 IMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (ii))
|
|
2438 {
|
|
2439 /* If only the order has changed then simply select the first
|
|
2440 one of the pending set. This stops horrendous rebuilding -
|
|
2441 and hence flicker - of the tabs each time you click on
|
|
2442 one. */
|
|
2443 if (tab_control_order_only_changed (image_instance))
|
|
2444 {
|
|
2445 Lisp_Object rest, selected =
|
|
2446 gui_item_list_find_selected
|
|
2447 (NILP (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)) ?
|
|
2448 XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)) :
|
|
2449 XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)));
|
|
2450
|
|
2451 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
|
|
2452 {
|
1318
|
2453 if (gui_item_equal_sans_selected (XCAR (rest), selected, 0, 1))
|
462
|
2454 {
|
|
2455 Lisp_Object old_selected =gui_item_list_find_selected
|
|
2456 (XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)));
|
|
2457
|
|
2458 /* Need to focus on the widget... */
|
|
2459 stderr_out ("Hey, change the tab-focus you boob...\n");
|
|
2460
|
|
2461 /* Pick up the new selected item. */
|
|
2462 XGUI_ITEM (old_selected)->selected =
|
|
2463 XGUI_ITEM (XCAR (rest))->selected;
|
|
2464 XGUI_ITEM (XCAR (rest))->selected =
|
|
2465 XGUI_ITEM (selected)->selected;
|
|
2466 /* We're not actually changing the items anymore. */
|
|
2467 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) = 0;
|
|
2468 IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii) = Qnil;
|
|
2469 break;
|
|
2470 }
|
|
2471 }
|
|
2472 }
|
|
2473 else
|
|
2474 {
|
|
2475 /* More than just the order has changed... let's get busy! */
|
|
2476 GtkNotebook *nb = GTK_NOTEBOOK (IMAGE_INSTANCE_GTK_CLIPWIDGET (ii));
|
|
2477 guint num_pages = g_list_length (nb->children);
|
|
2478 Lisp_Object rest;
|
|
2479
|
|
2480 if (num_pages >= 0)
|
|
2481 {
|
|
2482 int i;
|
|
2483 for (i = num_pages; i >= 0; --i)
|
|
2484 {
|
|
2485 gtk_notebook_remove_page (nb, i);
|
|
2486 }
|
|
2487 }
|
|
2488
|
|
2489 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
|
|
2490 {
|
|
2491 Lisp_Gui_Item *pgui = XGUI_ITEM (XCAR (rest));
|
|
2492 char *c_name = NULL;
|
|
2493
|
|
2494 if (!STRINGP (pgui->name))
|
1318
|
2495 pgui->name = eval_within_redisplay (pgui->name);
|
|
2496
|
|
2497 if (!STRINGP (pgui->name))
|
|
2498 warn_when_safe (Qredisplay, Qwarning,
|
|
2499 "Name does not evaluate to string");
|
|
2500 else
|
|
2501 {
|
|
2502 TO_EXTERNAL_FORMAT (LISP_STRING, pgui->name,
|
|
2503 C_STRING_ALLOCA, c_name,
|
|
2504 Qctext);
|
|
2505
|
|
2506 gtk_notebook_append_page (nb,
|
|
2507 gtk_vbox_new (FALSE, 3),
|
|
2508 gtk_label_new (c_name));
|
|
2509 }
|
462
|
2510 }
|
|
2511
|
|
2512 /* Show all the new widgets we just added... */
|
|
2513 gtk_widget_show_all (GTK_WIDGET (nb));
|
|
2514 }
|
|
2515 }
|
|
2516
|
|
2517 /* Possibly update the face. */
|
|
2518 #if 0
|
|
2519 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (ii)
|
|
2520 ||
|
|
2521 XFRAME (IMAGE_INSTANCE_FRAME (ii))->faces_changed
|
|
2522 ||
|
|
2523 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
|
|
2524 {
|
|
2525 update_tab_widget_face (wv, ii,
|
|
2526 IMAGE_INSTANCE_FRAME (ii));
|
|
2527 }
|
|
2528 #endif
|
|
2529 }
|
|
2530 #endif /* HAVE_WIDGETS */
|
|
2531
|
|
2532
|
|
2533 /************************************************************************/
|
|
2534 /* initialization */
|
|
2535 /************************************************************************/
|
|
2536 void
|
|
2537 syms_of_glyphs_gtk (void)
|
|
2538 {
|
|
2539 #ifdef HAVE_WIDGETS
|
563
|
2540 DEFSYMBOL (Qgtk_widget_instantiate_internal);
|
|
2541 DEFSYMBOL (Qgtk_widget_property_internal);
|
|
2542 DEFSYMBOL (Qgtk_widget_redisplay_internal);
|
|
2543 DEFSYMBOL (Qgtk_widget_set_style);
|
462
|
2544 #endif
|
|
2545 }
|
|
2546
|
|
2547 void
|
|
2548 console_type_create_glyphs_gtk (void)
|
|
2549 {
|
|
2550 /* image methods */
|
|
2551 CONSOLE_HAS_METHOD (gtk, print_image_instance);
|
|
2552 CONSOLE_HAS_METHOD (gtk, finalize_image_instance);
|
|
2553 CONSOLE_HAS_METHOD (gtk, image_instance_equal);
|
|
2554 CONSOLE_HAS_METHOD (gtk, image_instance_hash);
|
|
2555 CONSOLE_HAS_METHOD (gtk, colorize_image_instance);
|
|
2556 CONSOLE_HAS_METHOD (gtk, init_image_instance_from_eimage);
|
|
2557 CONSOLE_HAS_METHOD (gtk, locate_pixmap_file);
|
|
2558 CONSOLE_HAS_METHOD (gtk, unmap_subwindow);
|
|
2559 CONSOLE_HAS_METHOD (gtk, map_subwindow);
|
|
2560 CONSOLE_HAS_METHOD (gtk, redisplay_widget);
|
|
2561 CONSOLE_HAS_METHOD (gtk, redisplay_subwindow);
|
|
2562 }
|
|
2563
|
|
2564 void
|
|
2565 image_instantiator_format_create_glyphs_gtk (void)
|
|
2566 {
|
|
2567 IIFORMAT_VALID_CONSOLE (gtk, nothing);
|
|
2568 IIFORMAT_VALID_CONSOLE (gtk, string);
|
|
2569 #ifdef HAVE_WIDGETS
|
|
2570 IIFORMAT_VALID_CONSOLE (gtk, layout);
|
|
2571 #endif
|
|
2572 IIFORMAT_VALID_CONSOLE (gtk, formatted_string);
|
|
2573 IIFORMAT_VALID_CONSOLE (gtk, inherit);
|
|
2574 #ifdef HAVE_XPM
|
|
2575 INITIALIZE_DEVICE_IIFORMAT (gtk, xpm);
|
|
2576 IIFORMAT_HAS_DEVMETHOD (gtk, xpm, instantiate);
|
|
2577 #endif
|
|
2578 #ifdef HAVE_JPEG
|
|
2579 IIFORMAT_VALID_CONSOLE (gtk, jpeg);
|
|
2580 #endif
|
|
2581 #ifdef HAVE_TIFF
|
|
2582 IIFORMAT_VALID_CONSOLE (gtk, tiff);
|
|
2583 #endif
|
|
2584 #ifdef HAVE_PNG
|
|
2585 IIFORMAT_VALID_CONSOLE (gtk, png);
|
|
2586 #endif
|
|
2587 #ifdef HAVE_GIF
|
|
2588 IIFORMAT_VALID_CONSOLE (gtk, gif);
|
|
2589 #endif
|
|
2590
|
|
2591 INITIALIZE_DEVICE_IIFORMAT (gtk, subwindow);
|
|
2592 IIFORMAT_HAS_DEVMETHOD (gtk, subwindow, instantiate);
|
|
2593
|
|
2594 #ifdef HAVE_WIDGETS
|
|
2595 /* layout widget */
|
|
2596 INITIALIZE_DEVICE_IIFORMAT (gtk, native_layout);
|
|
2597 IIFORMAT_HAS_DEVMETHOD (gtk, native_layout, instantiate);
|
|
2598
|
|
2599 /* button widget */
|
|
2600 INITIALIZE_DEVICE_IIFORMAT (gtk, button);
|
|
2601 IIFORMAT_HAS_DEVMETHOD (gtk, button, property);
|
|
2602 IIFORMAT_HAS_DEVMETHOD (gtk, button, instantiate);
|
|
2603 IIFORMAT_HAS_DEVMETHOD (gtk, button, redisplay);
|
|
2604 /* general widget methods. */
|
|
2605 INITIALIZE_DEVICE_IIFORMAT (gtk, widget);
|
|
2606 IIFORMAT_HAS_DEVMETHOD (gtk, widget, property);
|
|
2607
|
|
2608 /* progress gauge */
|
|
2609 INITIALIZE_DEVICE_IIFORMAT (gtk, progress_gauge);
|
|
2610 IIFORMAT_HAS_DEVMETHOD (gtk, progress_gauge, redisplay);
|
|
2611 IIFORMAT_HAS_DEVMETHOD (gtk, progress_gauge, instantiate);
|
|
2612 /* text field */
|
|
2613 INITIALIZE_DEVICE_IIFORMAT (gtk, edit_field);
|
|
2614 IIFORMAT_HAS_DEVMETHOD (gtk, edit_field, instantiate);
|
|
2615 INITIALIZE_DEVICE_IIFORMAT (gtk, combo_box);
|
|
2616 IIFORMAT_HAS_DEVMETHOD (gtk, combo_box, instantiate);
|
|
2617 IIFORMAT_HAS_SHARED_DEVMETHOD (gtk, combo_box, redisplay, tab_control);
|
|
2618 /* tab control widget */
|
|
2619 INITIALIZE_DEVICE_IIFORMAT (gtk, tab_control);
|
|
2620 IIFORMAT_HAS_DEVMETHOD (gtk, tab_control, instantiate);
|
|
2621 IIFORMAT_HAS_DEVMETHOD (gtk, tab_control, redisplay);
|
|
2622 /* label */
|
|
2623 INITIALIZE_DEVICE_IIFORMAT (gtk, label);
|
|
2624 IIFORMAT_HAS_DEVMETHOD (gtk, label, instantiate);
|
|
2625 #endif
|
|
2626
|
|
2627 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
2628 IIFORMAT_VALID_CONSOLE (gtk, cursor_font);
|
|
2629
|
|
2630 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
2631 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
2632 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
2633
|
|
2634 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
2635 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
2636 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
2637
|
|
2638 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
2639 IIFORMAT_VALID_CONSOLE (gtk, font);
|
|
2640
|
|
2641 IIFORMAT_HAS_METHOD (font, validate);
|
|
2642 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
2643 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
2644
|
|
2645 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
2646 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
2647 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
2648
|
|
2649 #ifdef HAVE_XPM
|
|
2650 INITIALIZE_DEVICE_IIFORMAT (gtk, xpm);
|
|
2651 IIFORMAT_HAS_DEVMETHOD (gtk, xpm, instantiate);
|
|
2652 #endif
|
|
2653
|
|
2654 #ifdef HAVE_XFACE
|
|
2655 INITIALIZE_DEVICE_IIFORMAT (gtk, xface);
|
|
2656 IIFORMAT_HAS_DEVMETHOD (gtk, xface, instantiate);
|
|
2657 #endif
|
|
2658
|
|
2659 INITIALIZE_DEVICE_IIFORMAT (gtk, xbm);
|
|
2660 IIFORMAT_HAS_DEVMETHOD (gtk, xbm, instantiate);
|
|
2661 IIFORMAT_VALID_CONSOLE (gtk, xbm);
|
|
2662
|
|
2663 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (gtk_resource, "gtk-resource");
|
|
2664 IIFORMAT_VALID_CONSOLE (gtk, gtk_resource);
|
|
2665
|
|
2666 IIFORMAT_HAS_METHOD (gtk_resource, validate);
|
|
2667 IIFORMAT_HAS_METHOD (gtk_resource, normalize);
|
|
2668 IIFORMAT_HAS_METHOD (gtk_resource, possible_dest_types);
|
|
2669 IIFORMAT_HAS_METHOD (gtk_resource, instantiate);
|
|
2670
|
|
2671 IIFORMAT_VALID_KEYWORD (gtk_resource, Q_resource_type, check_valid_resource_symbol);
|
|
2672 IIFORMAT_VALID_KEYWORD (gtk_resource, Q_resource_id, check_valid_resource_id);
|
|
2673 IIFORMAT_VALID_KEYWORD (gtk_resource, Q_file, check_valid_string);
|
|
2674
|
|
2675 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect, "autodetect");
|
|
2676 IIFORMAT_VALID_CONSOLE (gtk, autodetect);
|
|
2677
|
|
2678 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
2679 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
2680 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
|
2681 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
2682
|
|
2683 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
|
2684 }
|
|
2685
|
|
2686 void
|
|
2687 vars_of_glyphs_gtk (void)
|
|
2688 {
|
|
2689 #ifdef HAVE_XFACE
|
|
2690 Fprovide (Qxface);
|
|
2691 #endif
|
|
2692
|
|
2693 DEFVAR_LISP ("gtk-bitmap-file-path", &Vgtk_bitmap_file_path /*
|
|
2694 A list of the directories in which X bitmap files may be found.
|
|
2695 If nil, this is initialized from the "*bitmapFilePath" resource.
|
|
2696 This is used by the `make-image-instance' function (however, note that if
|
|
2697 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
2698 */ );
|
|
2699 Vgtk_bitmap_file_path = Qnil;
|
|
2700 }
|
|
2701
|
|
2702 void
|
|
2703 complex_vars_of_glyphs_gtk (void)
|
|
2704 {
|
|
2705 #define BUILD_GLYPH_INST(variable, name) \
|
|
2706 Fadd_spec_to_specifier \
|
|
2707 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
2708 vector3 (Qxbm, Q_data, \
|
|
2709 list3 (make_int (name##_width), \
|
|
2710 make_int (name##_height), \
|
|
2711 make_ext_string (name##_bits, \
|
|
2712 sizeof (name##_bits), \
|
|
2713 Qbinary))), \
|
|
2714 Qglobal, Qgtk, Qnil)
|
|
2715
|
|
2716 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
2717 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
2718 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
|
2719 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
|
2720
|
|
2721 #undef BUILD_GLYPH_INST
|
|
2722 }
|
|
2723
|
|
2724 /* X specific crap */
|
|
2725 #include <gdk/gdkx.h>
|
|
2726 /* #### Should remove all this X specific stuff when GTK/GDK matures a
|
|
2727 bit more and provides an abstraction for it. */
|
|
2728 static int
|
|
2729 gtk_colorize_image_instance (Lisp_Object image_instance,
|
|
2730 Lisp_Object foreground, Lisp_Object background)
|
|
2731 {
|
|
2732 struct Lisp_Image_Instance *p;
|
|
2733
|
|
2734 p = XIMAGE_INSTANCE (image_instance);
|
|
2735
|
|
2736 switch (IMAGE_INSTANCE_TYPE (p))
|
|
2737 {
|
|
2738 case IMAGE_MONO_PIXMAP:
|
|
2739 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
2740 /* Make sure there aren't two pointers to the same mask, causing
|
|
2741 it to get freed twice. */
|
|
2742 IMAGE_INSTANCE_GTK_MASK (p) = 0;
|
|
2743 break;
|
|
2744
|
|
2745 default:
|
|
2746 return 0;
|
|
2747 }
|
|
2748
|
|
2749 {
|
|
2750 GdkWindow *draw = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
2751 GdkPixmap *new_pxmp = gdk_pixmap_new (draw,
|
|
2752 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2753 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2754 DEVICE_GTK_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
2755 GdkGCValues gcv;
|
|
2756 GdkGC *gc;
|
|
2757
|
|
2758 gcv.foreground = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (foreground));
|
|
2759 gcv.background = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (background));
|
|
2760 gc = gdk_gc_new_with_values (new_pxmp, &gcv, GDK_GC_BACKGROUND | GDK_GC_FOREGROUND);
|
|
2761
|
|
2762 XCopyPlane (GDK_WINDOW_XDISPLAY (draw),
|
|
2763 GDK_WINDOW_XWINDOW (IMAGE_INSTANCE_GTK_PIXMAP (p)),
|
|
2764 GDK_WINDOW_XWINDOW (new_pxmp),
|
|
2765 GDK_GC_XGC (gc), 0, 0,
|
|
2766 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2767 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2768 0, 0, 1);
|
|
2769
|
|
2770 gdk_gc_destroy (gc);
|
|
2771 IMAGE_INSTANCE_GTK_PIXMAP (p) = new_pxmp;
|
|
2772 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = DEVICE_GTK_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
2773 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
2774 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
2775 return 1;
|
|
2776 }
|
|
2777 }
|
|
2778
|