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 }
|
|
263 xfree(qtable);
|
|
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 }
|
|
417 xfree (IMAGE_INSTANCE_GTK_PIXMAP_SLICES (p));
|
|
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 {
|
|
445 xfree (IMAGE_INSTANCE_GTK_PIXELS (p));
|
|
446 IMAGE_INSTANCE_GTK_PIXELS (p) = 0;
|
|
447 }
|
|
448
|
|
449 xfree (p->data);
|
|
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 {
|
|
841 if (pixtbl) xfree (pixtbl);
|
|
842 signal_image_error("EImage to GdkImage conversion failed", instantiator);
|
|
843 }
|
|
844
|
|
845 if (slice == 0)
|
|
846 /* Now create the pixmap and set up the image instance */
|
|
847 init_image_instance_from_gdk_image (ii, gdk_image, dest_mask,
|
|
848 cmap, pixtbl, npixels, slices,
|
|
849 instantiator);
|
|
850 else
|
|
851 image_instance_add_gdk_image (ii, gdk_image, slice, instantiator);
|
|
852
|
|
853 if (gdk_image)
|
|
854 {
|
|
855 gdk_image_destroy (gdk_image);
|
|
856 }
|
|
857 gdk_image = 0;
|
|
858 }
|
|
859 }
|
|
860
|
|
861 /* Given inline data for a mono pixmap, create and return the
|
|
862 corresponding X object. */
|
|
863
|
|
864 static GdkPixmap *
|
|
865 pixmap_from_xbm_inline (Lisp_Object device, int width, int height,
|
|
866 /* Note that data is in ext-format! */
|
771
|
867 const Extbyte *bits)
|
462
|
868 {
|
|
869 return (gdk_bitmap_create_from_data (GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device))),
|
|
870 (char *) bits, width, height));
|
|
871 }
|
|
872
|
|
873 /* Given inline data for a mono pixmap, initialize the given
|
|
874 image instance accordingly. */
|
|
875
|
|
876 static void
|
|
877 init_image_instance_from_xbm_inline (struct Lisp_Image_Instance *ii,
|
|
878 int width, int height,
|
|
879 /* Note that data is in ext-format! */
|
771
|
880 const char *bits,
|
462
|
881 Lisp_Object instantiator,
|
|
882 Lisp_Object pointer_fg,
|
|
883 Lisp_Object pointer_bg,
|
|
884 int dest_mask,
|
|
885 GdkPixmap *mask,
|
|
886 Lisp_Object mask_filename)
|
|
887 {
|
|
888 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
889 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
890 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background);
|
|
891 GdkColor fg;
|
|
892 GdkColor bg;
|
|
893 enum image_instance_type type;
|
|
894 GdkWindow *draw = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device)));
|
|
895 GdkColormap *cmap = DEVICE_GTK_COLORMAP (XDEVICE(device));
|
|
896 GdkColor black;
|
|
897 GdkColor white;
|
|
898
|
|
899 gdk_color_black(cmap, &black);
|
|
900 gdk_color_white(cmap, &white);
|
|
901
|
|
902 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
903 gui_error ("Not a Gtk device", device);
|
462
|
904
|
|
905 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) &&
|
|
906 (dest_mask & IMAGE_COLOR_PIXMAP_MASK))
|
|
907 {
|
|
908 if (!NILP (foreground) || !NILP (background))
|
|
909 type = IMAGE_COLOR_PIXMAP;
|
|
910 else
|
|
911 type = IMAGE_MONO_PIXMAP;
|
|
912 }
|
|
913 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
914 type = IMAGE_MONO_PIXMAP;
|
|
915 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
916 type = IMAGE_COLOR_PIXMAP;
|
|
917 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
918 type = IMAGE_POINTER;
|
|
919 else
|
|
920 incompatible_image_types (instantiator, dest_mask,
|
|
921 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
922 | IMAGE_POINTER_MASK);
|
|
923
|
|
924 gtk_initialize_pixmap_image_instance (ii, 1, type);
|
|
925 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width;
|
|
926 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height;
|
|
927 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
928 find_keyword_in_vector (instantiator, Q_file);
|
|
929
|
|
930 switch (type)
|
|
931 {
|
|
932 case IMAGE_MONO_PIXMAP:
|
|
933 {
|
|
934 IMAGE_INSTANCE_GTK_PIXMAP (ii) =
|
|
935 pixmap_from_xbm_inline (device, width, height, (Extbyte *) bits);
|
|
936 }
|
|
937 break;
|
|
938
|
|
939 case IMAGE_COLOR_PIXMAP:
|
|
940 {
|
|
941 gint d = DEVICE_GTK_DEPTH (XDEVICE(device));
|
|
942
|
|
943 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground))
|
|
944 foreground =
|
|
945 Fmake_color_instance (foreground, device,
|
|
946 encode_error_behavior_flag (ERROR_ME));
|
|
947
|
|
948 if (COLOR_INSTANCEP (foreground))
|
|
949 fg = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (foreground));
|
|
950
|
|
951 if (!NILP (background) && !COLOR_INSTANCEP (background))
|
|
952 background =
|
|
953 Fmake_color_instance (background, device,
|
|
954 encode_error_behavior_flag (ERROR_ME));
|
|
955
|
|
956 if (COLOR_INSTANCEP (background))
|
|
957 bg = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (background));
|
|
958
|
|
959 /* We used to duplicate the pixels using XAllocColor(), to protect
|
|
960 against their getting freed. Just as easy to just store the
|
|
961 color instances here and GC-protect them, so this doesn't
|
|
962 happen. */
|
|
963 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
964 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
965 IMAGE_INSTANCE_GTK_PIXMAP (ii) =
|
|
966 gdk_pixmap_create_from_data (draw, (char *) bits, width, height, d, &fg, &bg);
|
|
967 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = d;
|
|
968 }
|
|
969 break;
|
|
970
|
|
971 case IMAGE_POINTER:
|
|
972 {
|
|
973 GdkColor fg_color, bg_color;
|
|
974 GdkPixmap *source;
|
|
975
|
|
976 check_pointer_sizes (width, height, instantiator);
|
|
977
|
|
978 source = gdk_pixmap_create_from_data (draw, (char *) bits, width, height, 1, &black, &white);
|
|
979
|
|
980 if (NILP (foreground))
|
|
981 foreground = pointer_fg;
|
|
982 if (NILP (background))
|
|
983 background = pointer_bg;
|
|
984 generate_cursor_fg_bg (device, &foreground, &background,
|
|
985 &fg_color, &bg_color);
|
|
986
|
|
987 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground;
|
|
988 IMAGE_INSTANCE_PIXMAP_BG (ii) = background;
|
|
989 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) =
|
|
990 find_keyword_in_vector (instantiator, Q_hotspot_x);
|
|
991 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) =
|
|
992 find_keyword_in_vector (instantiator, Q_hotspot_y);
|
|
993 IMAGE_INSTANCE_GTK_CURSOR (ii) =
|
|
994 gdk_cursor_new_from_pixmap (source, mask, &fg_color, &bg_color,
|
|
995 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) ?
|
|
996 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii)) : 0,
|
|
997 !NILP (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) ?
|
|
998 XINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii)) : 0);
|
|
999 }
|
|
1000 break;
|
|
1001
|
|
1002 default:
|
|
1003 abort ();
|
|
1004 }
|
|
1005 }
|
|
1006
|
|
1007 static void
|
|
1008 xbm_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1009 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1010 int dest_mask, int width, int height,
|
|
1011 /* Note that data is in ext-format! */
|
771
|
1012 const char *bits)
|
462
|
1013 {
|
|
1014 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data);
|
|
1015 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file);
|
|
1016 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1017 GdkPixmap *mask = 0;
|
771
|
1018 const char *gcc_may_you_rot_in_hell;
|
462
|
1019
|
|
1020 if (!NILP (mask_data))
|
|
1021 {
|
|
1022 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (mask_data))),
|
|
1023 C_STRING_ALLOCA, gcc_may_you_rot_in_hell,
|
|
1024 Qfile_name);
|
|
1025 mask =
|
|
1026 pixmap_from_xbm_inline (IMAGE_INSTANCE_DEVICE (ii),
|
|
1027 XINT (XCAR (mask_data)),
|
|
1028 XINT (XCAR (XCDR (mask_data))),
|
771
|
1029 (const unsigned char *)
|
462
|
1030 gcc_may_you_rot_in_hell);
|
|
1031 }
|
|
1032
|
|
1033 init_image_instance_from_xbm_inline (ii, width, height, bits,
|
|
1034 instantiator, pointer_fg, pointer_bg,
|
|
1035 dest_mask, mask, mask_file);
|
|
1036 }
|
|
1037
|
|
1038 /* Instantiate method for XBM's. */
|
|
1039
|
|
1040 static void
|
|
1041 gtk_xbm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1042 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1043 int dest_mask, Lisp_Object domain)
|
|
1044 {
|
|
1045 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
771
|
1046 const char *gcc_go_home;
|
462
|
1047
|
|
1048 assert (!NILP (data));
|
|
1049
|
|
1050 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (XCDR (XCDR (data))),
|
|
1051 C_STRING_ALLOCA, gcc_go_home,
|
|
1052 Qbinary);
|
|
1053
|
|
1054 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1055 pointer_bg, dest_mask, XINT (XCAR (data)),
|
|
1056 XINT (XCAR (XCDR (data))), gcc_go_home);
|
|
1057 }
|
|
1058
|
|
1059
|
|
1060 #ifdef HAVE_XPM
|
|
1061 /**********************************************************************
|
|
1062 * XPM *
|
|
1063 **********************************************************************/
|
771
|
1064 static Lisp_Object
|
|
1065 write_lisp_string_to_temp_file (Lisp_Object string)
|
462
|
1066 {
|
|
1067 Lisp_Object instream, outstream;
|
|
1068 Lstream *istr, *ostr;
|
771
|
1069 Char_Binary tempbuf[1024]; /* some random amount */
|
462
|
1070 int fubar = 0;
|
|
1071 FILE *tmpfil;
|
|
1072 static Extbyte_dynarr *conversion_out_dynarr;
|
|
1073 Bytecount bstart, bend;
|
771
|
1074 Lisp_Object tempfile;
|
778
|
1075 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
462
|
1076 Lisp_Object conv_out_stream;
|
|
1077 Lstream *costr;
|
|
1078
|
|
1079 /* This function can GC */
|
|
1080 if (!conversion_out_dynarr)
|
|
1081 conversion_out_dynarr = Dynarr_new (Extbyte);
|
|
1082 else
|
|
1083 Dynarr_reset (conversion_out_dynarr);
|
|
1084
|
|
1085 /* Create the temporary file ... */
|
771
|
1086 tempfile = Fmake_temp_name (build_string ("/tmp/emacs"));
|
|
1087 tmpfil = qxe_fopen (XSTRING_DATA (tempfile), "w");
|
462
|
1088 if (!tmpfil)
|
|
1089 {
|
|
1090 if (tmpfil)
|
|
1091 {
|
|
1092 int old_errno = errno;
|
771
|
1093 retry_fclose (tmpfil);
|
|
1094 qxe_unlink (XSTRING_DATA (tempfile));
|
462
|
1095 errno = old_errno;
|
|
1096 }
|
771
|
1097 report_file_error ("Creating temp file", tempfile);
|
462
|
1098 }
|
|
1099
|
|
1100 CHECK_STRING (string);
|
|
1101 get_string_range_byte (string, Qnil, Qnil, &bstart, &bend,
|
|
1102 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1103 instream = make_lisp_string_input_stream (string, bstart, bend);
|
|
1104 istr = XLSTREAM (instream);
|
|
1105 /* setup the out stream */
|
771
|
1106 outstream =
|
|
1107 make_dynarr_output_stream ((unsigned_char_dynarr *) conversion_out_dynarr);
|
462
|
1108 ostr = XLSTREAM (outstream);
|
|
1109 /* setup the conversion stream */
|
771
|
1110 conv_out_stream =
|
800
|
1111 make_coding_output_stream (ostr, Qbinary, CODING_ENCODE, 0);
|
462
|
1112 costr = XLSTREAM (conv_out_stream);
|
771
|
1113 GCPRO4 (tempfile, instream, outstream, conv_out_stream);
|
462
|
1114
|
|
1115 /* Get the data while doing the conversion */
|
|
1116 while (1)
|
|
1117 {
|
|
1118 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
|
|
1119 if (!size_in_bytes)
|
|
1120 break;
|
|
1121 /* It does seem the flushes are necessary... */
|
|
1122 Lstream_write (costr, tempbuf, size_in_bytes);
|
|
1123 Lstream_flush (costr);
|
|
1124 Lstream_flush (ostr);
|
771
|
1125 if (retry_fwrite ((unsigned char *)Dynarr_atp(conversion_out_dynarr, 0),
|
462
|
1126 Dynarr_length(conversion_out_dynarr), 1, tmpfil) != 1)
|
|
1127 {
|
|
1128 fubar = 1;
|
|
1129 break;
|
|
1130 }
|
|
1131 /* reset the dynarr */
|
|
1132 Lstream_rewind(ostr);
|
|
1133 }
|
|
1134
|
771
|
1135 if (retry_fclose (tmpfil) != 0)
|
462
|
1136 fubar = 1;
|
|
1137 Lstream_close (istr);
|
|
1138 Lstream_close (costr);
|
|
1139 Lstream_close (ostr);
|
|
1140
|
771
|
1141 Lstream_delete (istr);
|
|
1142 Lstream_delete (ostr);
|
|
1143 Lstream_delete (costr);
|
|
1144
|
|
1145 if (fubar)
|
|
1146 report_file_error ("Writing temp file", tempfile);
|
|
1147
|
462
|
1148 UNGCPRO;
|
771
|
1149 return tempfile;
|
462
|
1150 }
|
|
1151
|
739
|
1152 struct color_symbol
|
|
1153 {
|
|
1154 char* name;
|
|
1155 GdkColor color;
|
|
1156 };
|
|
1157
|
|
1158 static struct color_symbol*
|
|
1159 extract_xpm_color_names (Lisp_Object device,
|
|
1160 Lisp_Object domain,
|
|
1161 Lisp_Object color_symbol_alist,
|
|
1162 int* nsymbols)
|
|
1163 {
|
|
1164 /* This function can GC */
|
|
1165 Lisp_Object rest;
|
|
1166 Lisp_Object results = Qnil;
|
|
1167 int i, j;
|
|
1168 struct color_symbol *colortbl;
|
|
1169 struct gcpro gcpro1, gcpro2;
|
|
1170
|
|
1171 GCPRO2 (results, device);
|
|
1172
|
|
1173 /* We built up results to be (("name" . #<color>) ...) so that if an
|
|
1174 error happens we don't lose any malloc()ed data, or more importantly,
|
|
1175 leave any pixels allocated in the server. */
|
|
1176 i = 0;
|
|
1177 LIST_LOOP (rest, color_symbol_alist)
|
|
1178 {
|
|
1179 Lisp_Object cons = XCAR (rest);
|
|
1180 Lisp_Object name = XCAR (cons);
|
|
1181 Lisp_Object value = XCDR (cons);
|
|
1182 if (NILP (value))
|
|
1183 continue;
|
|
1184 if (STRINGP (value))
|
|
1185 value =
|
|
1186 Fmake_color_instance
|
793
|
1187 (value, device, encode_error_behavior_flag (ERROR_ME_DEBUG_WARN));
|
739
|
1188 else
|
|
1189 {
|
|
1190 assert (COLOR_SPECIFIERP (value));
|
|
1191 value = Fspecifier_instance (value, domain, Qnil, Qnil);
|
|
1192 }
|
|
1193
|
|
1194 if (NILP (value))
|
|
1195 continue;
|
|
1196 results = noseeum_cons (noseeum_cons (name, value), results);
|
|
1197 i++;
|
|
1198 }
|
|
1199 UNGCPRO; /* no more evaluation */
|
|
1200
|
|
1201 *nsymbols=i;
|
|
1202 if (i == 0) return 0;
|
|
1203
|
|
1204 colortbl = xnew_array_and_zero (struct color_symbol, i);
|
|
1205
|
|
1206 for (j=0; j<i; j++)
|
|
1207 {
|
|
1208 Lisp_Object cons = XCAR (results);
|
|
1209 colortbl[j].color =
|
|
1210 * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
|
|
1211
|
|
1212 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
|
|
1213 free_cons (XCONS (cons));
|
|
1214 cons = results;
|
|
1215 results = XCDR (results);
|
|
1216 free_cons (XCONS (cons));
|
|
1217 }
|
|
1218 return colortbl;
|
|
1219 }
|
|
1220
|
462
|
1221 static void
|
739
|
1222 gtk_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
462
|
1223 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1224 int dest_mask, Lisp_Object domain)
|
|
1225 {
|
|
1226 /* This function can GC */
|
|
1227 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1228 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1229 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1230 GdkColormap *cmap;
|
|
1231 int depth;
|
|
1232 GdkVisual *visual;
|
|
1233 GdkPixmap *pixmap;
|
|
1234 GdkPixmap *mask = 0;
|
|
1235 GdkWindow *window = 0;
|
739
|
1236 int nsymbols = 0, i = 0;
|
|
1237 struct color_symbol *color_symbols = NULL;
|
|
1238 GdkColor *transparent_color = NULL;
|
462
|
1239 Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
|
|
1240 Q_color_symbols);
|
|
1241 enum image_instance_type type;
|
|
1242 int force_mono;
|
|
1243 unsigned int w, h;
|
771
|
1244 Lisp_Object tempfile = Qnil;
|
|
1245 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
462
|
1246
|
|
1247 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1248 gui_error ("Not a Gtk device", device);
|
462
|
1249
|
|
1250 if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1251 type = IMAGE_COLOR_PIXMAP;
|
|
1252 else if (dest_mask & IMAGE_MONO_PIXMAP_MASK)
|
|
1253 type = IMAGE_MONO_PIXMAP;
|
|
1254 else if (dest_mask & IMAGE_POINTER_MASK)
|
|
1255 type = IMAGE_POINTER;
|
|
1256 else
|
|
1257 incompatible_image_types (instantiator, dest_mask,
|
|
1258 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK
|
|
1259 | IMAGE_POINTER_MASK);
|
|
1260 force_mono = (type != IMAGE_COLOR_PIXMAP);
|
|
1261
|
771
|
1262 GCPRO4 (device, data, color_symbol_alist, tempfile);
|
|
1263
|
462
|
1264 window = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (device)));
|
|
1265 cmap = DEVICE_GTK_COLORMAP (XDEVICE (device));
|
|
1266 depth = DEVICE_GTK_DEPTH (XDEVICE (device));
|
|
1267 visual = DEVICE_GTK_VISUAL (XDEVICE (device));
|
|
1268
|
|
1269 gtk_initialize_pixmap_image_instance (ii, 1, type);
|
|
1270
|
|
1271 assert (!NILP (data));
|
|
1272
|
739
|
1273 /* Need to get the transparent color here */
|
771
|
1274 color_symbols = extract_xpm_color_names (device, domain, color_symbol_alist,
|
|
1275 &nsymbols);
|
739
|
1276 for (i = 0; i < nsymbols; i++)
|
|
1277 {
|
771
|
1278 if (!qxestrcasecmp ("BgColor", color_symbols[i].name) ||
|
|
1279 !qxestrcasecmp ("None", color_symbols[i].name))
|
739
|
1280 {
|
|
1281 transparent_color = &color_symbols[i].color;
|
|
1282 }
|
|
1283 }
|
|
1284
|
771
|
1285 tempfile = write_lisp_string_to_temp_file (data);
|
|
1286 {
|
|
1287 Extbyte *tempfileout;
|
|
1288
|
|
1289 LISP_STRING_TO_EXTERNAL (tempfile, tempfileout, Qfile_name);
|
|
1290 pixmap = gdk_pixmap_create_from_xpm (window, &mask, transparent_color,
|
|
1291 tempfileout);
|
|
1292 }
|
|
1293 qxe_unlink (XSTRING_DATA (tempfile));
|
462
|
1294
|
739
|
1295 if (color_symbols) xfree (color_symbols);
|
|
1296
|
462
|
1297 if (!pixmap)
|
|
1298 signal_image_error ("Error reading pixmap", data);
|
|
1299
|
|
1300 gdk_window_get_geometry (pixmap, NULL, NULL, &w, &h, &depth);
|
|
1301
|
|
1302 IMAGE_INSTANCE_GTK_PIXMAP (ii) = pixmap;
|
|
1303 IMAGE_INSTANCE_GTK_MASK (ii) = mask;
|
|
1304 IMAGE_INSTANCE_GTK_COLORMAP (ii) = cmap;
|
|
1305 IMAGE_INSTANCE_GTK_PIXELS (ii) = 0;
|
|
1306 IMAGE_INSTANCE_GTK_NPIXELS (ii) = 0;
|
|
1307 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = w;
|
|
1308 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = h;
|
|
1309 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) =
|
|
1310 find_keyword_in_vector (instantiator, Q_file);
|
|
1311
|
|
1312 switch (type)
|
|
1313 {
|
|
1314 case IMAGE_MONO_PIXMAP:
|
|
1315 break;
|
|
1316
|
|
1317 case IMAGE_COLOR_PIXMAP:
|
771
|
1318 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = depth;
|
462
|
1319 break;
|
|
1320
|
|
1321 case IMAGE_POINTER:
|
|
1322 {
|
|
1323 GdkColor fg, bg;
|
|
1324 unsigned int xhot, yhot;
|
|
1325
|
|
1326 /* #### Gtk does not give us access to the hotspots of a pixmap */
|
|
1327 xhot = yhot = 1;
|
793
|
1328 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = make_int (xhot);
|
|
1329 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = make_int (yhot);
|
462
|
1330
|
|
1331 check_pointer_sizes (w, h, instantiator);
|
|
1332
|
|
1333 /* If the loaded pixmap has colors allocated (meaning it came from an
|
|
1334 XPM file), then use those as the default colors for the cursor we
|
|
1335 create. Otherwise, default to pointer_fg and pointer_bg.
|
|
1336 */
|
|
1337 if (depth > 1)
|
|
1338 {
|
|
1339 warn_when_safe (Qunimplemented, Qnotice,
|
|
1340 "GTK does not support XPM cursors...\n");
|
|
1341 IMAGE_INSTANCE_GTK_CURSOR (ii) = gdk_cursor_new (GDK_COFFEE_MUG);
|
|
1342 }
|
|
1343 else
|
|
1344 {
|
|
1345 generate_cursor_fg_bg (device, &pointer_fg, &pointer_bg,
|
|
1346 &fg, &bg);
|
|
1347 IMAGE_INSTANCE_PIXMAP_FG (ii) = pointer_fg;
|
|
1348 IMAGE_INSTANCE_PIXMAP_BG (ii) = pointer_bg;
|
771
|
1349 IMAGE_INSTANCE_GTK_CURSOR (ii) =
|
|
1350 gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, xhot, yhot);
|
462
|
1351 }
|
|
1352 }
|
|
1353
|
|
1354 break;
|
|
1355
|
|
1356 default:
|
|
1357 abort ();
|
|
1358 }
|
771
|
1359
|
|
1360 UNGCPRO;
|
462
|
1361 }
|
|
1362 #endif /* HAVE_XPM */
|
|
1363
|
|
1364
|
|
1365 #ifdef HAVE_XFACE
|
|
1366
|
|
1367 /**********************************************************************
|
|
1368 * X-Face *
|
|
1369 **********************************************************************/
|
|
1370 #if defined(EXTERN)
|
|
1371 /* This is about to get redefined! */
|
|
1372 #undef EXTERN
|
|
1373 #endif
|
|
1374 /* We have to define SYSV32 so that compface.h includes string.h
|
|
1375 instead of strings.h. */
|
|
1376 #define SYSV32
|
|
1377 #ifdef __cplusplus
|
|
1378 extern "C" {
|
|
1379 #endif
|
|
1380 #include <compface.h>
|
|
1381 #ifdef __cplusplus
|
|
1382 }
|
|
1383 #endif
|
|
1384 /* JMP_BUF cannot be used here because if it doesn't get defined
|
|
1385 to jmp_buf we end up with a conflicting type error with the
|
|
1386 definition in compface.h */
|
|
1387 extern jmp_buf comp_env;
|
|
1388 #undef SYSV32
|
|
1389
|
|
1390 static void
|
|
1391 gtk_xface_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1392 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1393 int dest_mask, Lisp_Object domain)
|
|
1394 {
|
|
1395 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1396 int i, stattis;
|
|
1397 char *p, *bits, *bp;
|
771
|
1398 const char * volatile emsg = 0;
|
|
1399 const char * volatile dstring;
|
462
|
1400
|
|
1401 assert (!NILP (data));
|
|
1402
|
|
1403 LISP_STRING_TO_EXTERNAL (data, dstring, Qbinary);
|
|
1404
|
|
1405 if ((p = strchr (dstring, ':')))
|
|
1406 {
|
|
1407 dstring = p + 1;
|
|
1408 }
|
|
1409
|
|
1410 /* Must use setjmp not SETJMP because we used jmp_buf above not JMP_BUF */
|
|
1411 if (!(stattis = setjmp (comp_env)))
|
|
1412 {
|
|
1413 UnCompAll ((char *) dstring);
|
|
1414 UnGenFace ();
|
|
1415 }
|
|
1416
|
|
1417 switch (stattis)
|
|
1418 {
|
|
1419 case -2:
|
|
1420 emsg = "uncompface: internal error";
|
|
1421 break;
|
|
1422 case -1:
|
|
1423 emsg = "uncompface: insufficient or invalid data";
|
|
1424 break;
|
|
1425 case 1:
|
|
1426 emsg = "uncompface: excess data ignored";
|
|
1427 break;
|
|
1428 }
|
|
1429
|
|
1430 if (emsg)
|
563
|
1431 gui_error_2 (emsg, data, Qimage);
|
462
|
1432
|
851
|
1433 bp = bits = (char *) ALLOCA (PIXELS / 8);
|
462
|
1434
|
|
1435 /* the compface library exports char F[], which uses a single byte per
|
|
1436 pixel to represent a 48x48 bitmap. Yuck. */
|
|
1437 for (i = 0, p = F; i < (PIXELS / 8); ++i)
|
|
1438 {
|
|
1439 int n, b;
|
|
1440 /* reverse the bit order of each byte... */
|
|
1441 for (b = n = 0; b < 8; ++b)
|
|
1442 {
|
|
1443 n |= ((*p++) << b);
|
|
1444 }
|
|
1445 *bp++ = (char) n;
|
|
1446 }
|
|
1447
|
|
1448 xbm_instantiate_1 (image_instance, instantiator, pointer_fg,
|
|
1449 pointer_bg, dest_mask, 48, 48, bits);
|
|
1450 }
|
|
1451
|
|
1452 #endif /* HAVE_XFACE */
|
|
1453
|
|
1454 /**********************************************************************
|
|
1455 * RESOURCES *
|
|
1456 **********************************************************************/
|
|
1457
|
|
1458 static void
|
|
1459 gtk_resource_validate (Lisp_Object instantiator)
|
|
1460 {
|
|
1461 if ((NILP (find_keyword_in_vector (instantiator, Q_file))
|
|
1462 &&
|
|
1463 NILP (find_keyword_in_vector (instantiator, Q_resource_id)))
|
|
1464 ||
|
|
1465 NILP (find_keyword_in_vector (instantiator, Q_resource_type)))
|
563
|
1466 sferror ("Must supply :file, :resource-id and :resource-type",
|
462
|
1467 instantiator);
|
|
1468 }
|
|
1469
|
|
1470 static Lisp_Object
|
563
|
1471 gtk_resource_normalize (Lisp_Object inst, Lisp_Object console_type,
|
|
1472 Lisp_Object dest_mask)
|
462
|
1473 {
|
563
|
1474 return shared_resource_normalize (inst, console_type, dest_mask,
|
|
1475 Qgtk_resource);
|
462
|
1476 }
|
|
1477
|
|
1478 static int
|
|
1479 gtk_resource_possible_dest_types (void)
|
|
1480 {
|
|
1481 return IMAGE_POINTER_MASK | IMAGE_COLOR_PIXMAP_MASK;
|
|
1482 }
|
|
1483
|
|
1484 extern guint symbol_to_enum (Lisp_Object, GtkType);
|
|
1485
|
|
1486 static guint resource_name_to_resource (Lisp_Object name, int type)
|
|
1487 {
|
|
1488 if (type == IMAGE_POINTER)
|
|
1489 return (symbol_to_enum (name, GTK_TYPE_GDK_CURSOR_TYPE));
|
|
1490 else
|
|
1491 return (0);
|
|
1492 }
|
|
1493
|
|
1494 static int
|
|
1495 resource_symbol_to_type (Lisp_Object data)
|
|
1496 {
|
|
1497 if (EQ (data, Qcursor))
|
|
1498 return IMAGE_POINTER;
|
|
1499 #if 0
|
|
1500 else if (EQ (data, Qicon))
|
|
1501 return IMAGE_ICON;
|
|
1502 else if (EQ (data, Qbitmap))
|
|
1503 return IMAGE_BITMAP;
|
|
1504 #endif
|
|
1505 else
|
|
1506 return 0;
|
|
1507 }
|
|
1508
|
|
1509 static void
|
|
1510 gtk_resource_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1511 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1512 int dest_mask, Lisp_Object domain)
|
|
1513 {
|
|
1514 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1515 GdkCursor *c = NULL;
|
|
1516 unsigned int type = 0;
|
|
1517 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1518 Lisp_Object resource_type = find_keyword_in_vector (instantiator, Q_resource_type);
|
|
1519 Lisp_Object resource_id = find_keyword_in_vector (instantiator, Q_resource_id);
|
|
1520
|
|
1521 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1522 gui_error ("Not a GTK device", device);
|
462
|
1523
|
|
1524 type = resource_symbol_to_type (resource_type);
|
|
1525
|
595
|
1526 #if 0
|
|
1527 if (dest_mask & IMAGE_POINTER_MASK && type == IMAGE_POINTER_MASK)
|
|
1528 iitype = IMAGE_POINTER;
|
|
1529 else if (dest_mask & IMAGE_COLOR_PIXMAP_MASK)
|
|
1530 iitype = IMAGE_COLOR_PIXMAP;
|
|
1531 else
|
|
1532 incompatible_image_types (instantiator, dest_mask,
|
|
1533 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
|
|
1534 #endif
|
|
1535
|
462
|
1536 /* mess with the keyword info we were provided with */
|
|
1537 gtk_initialize_pixmap_image_instance (ii, 1, type);
|
|
1538 c = gdk_cursor_new (resource_name_to_resource (resource_id, type));
|
|
1539 IMAGE_INSTANCE_GTK_CURSOR (ii) = c;
|
|
1540 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = resource_id;
|
|
1541 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = 10;
|
|
1542 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = 10;
|
|
1543 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1;
|
|
1544 }
|
|
1545
|
|
1546 static void
|
|
1547 check_valid_resource_symbol (Lisp_Object data)
|
|
1548 {
|
|
1549 CHECK_SYMBOL (data);
|
|
1550 if (!resource_symbol_to_type (data))
|
563
|
1551 invalid_constant ("invalid resource type", data);
|
462
|
1552 }
|
|
1553
|
|
1554 static void
|
|
1555 check_valid_resource_id (Lisp_Object data)
|
|
1556 {
|
|
1557 if (!resource_name_to_resource (data, IMAGE_POINTER)
|
|
1558 &&
|
|
1559 !resource_name_to_resource (data, IMAGE_COLOR_PIXMAP)
|
|
1560 #if 0
|
|
1561 &&
|
|
1562 !resource_name_to_resource (data, IMAGE_BITMAP)
|
|
1563 #endif
|
|
1564 )
|
563
|
1565 invalid_constant ("invalid resource identifier", data);
|
462
|
1566 }
|
|
1567
|
|
1568 #if 0
|
|
1569 void
|
|
1570 check_valid_string_or_int (Lisp_Object data)
|
|
1571 {
|
|
1572 if (!INTP (data))
|
|
1573 CHECK_STRING (data);
|
|
1574 else
|
|
1575 CHECK_INT (data);
|
|
1576 }
|
|
1577 #endif
|
|
1578
|
|
1579
|
|
1580 /**********************************************************************
|
|
1581 * Autodetect *
|
|
1582 **********************************************************************/
|
|
1583
|
|
1584 static void
|
|
1585 autodetect_validate (Lisp_Object instantiator)
|
|
1586 {
|
|
1587 data_must_be_present (instantiator);
|
|
1588 }
|
|
1589
|
|
1590 static Lisp_Object
|
|
1591 autodetect_normalize (Lisp_Object instantiator,
|
|
1592 Lisp_Object console_type,
|
|
1593 Lisp_Object dest_mask)
|
|
1594 {
|
|
1595 Lisp_Object file = find_keyword_in_vector (instantiator, Q_data);
|
|
1596 Lisp_Object filename = Qnil;
|
|
1597 Lisp_Object data = Qnil;
|
|
1598 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1599 Lisp_Object alist = Qnil;
|
|
1600
|
|
1601 GCPRO3 (filename, data, alist);
|
|
1602
|
|
1603 if (NILP (file)) /* no conversion necessary */
|
|
1604 RETURN_UNGCPRO (instantiator);
|
|
1605
|
|
1606 alist = tagged_vector_to_alist (instantiator);
|
|
1607
|
|
1608 filename = locate_pixmap_file (file);
|
|
1609 if (!NILP (filename))
|
|
1610 {
|
|
1611 int xhot, yhot;
|
|
1612 /* #### Apparently some versions of XpmReadFileToData, which is
|
|
1613 called by pixmap_to_lisp_data, don't return an error value
|
|
1614 if the given file is not a valid XPM file. Instead, they
|
|
1615 just seg fault. It is definitely caused by passing a
|
|
1616 bitmap. To try and avoid this we check for bitmaps first. */
|
|
1617
|
|
1618 data = bitmap_to_lisp_data (filename, &xhot, &yhot, 1);
|
|
1619
|
|
1620 if (!EQ (data, Qt))
|
|
1621 {
|
|
1622 alist = remassq_no_quit (Q_data, alist);
|
|
1623 alist = Fcons (Fcons (Q_file, filename),
|
|
1624 Fcons (Fcons (Q_data, data), alist));
|
|
1625 if (xhot != -1)
|
|
1626 alist = Fcons (Fcons (Q_hotspot_x, make_int (xhot)),
|
|
1627 alist);
|
|
1628 if (yhot != -1)
|
|
1629 alist = Fcons (Fcons (Q_hotspot_y, make_int (yhot)),
|
|
1630 alist);
|
|
1631
|
|
1632 alist = xbm_mask_file_munging (alist, filename, Qnil, console_type);
|
|
1633
|
|
1634 {
|
|
1635 Lisp_Object result = alist_to_tagged_vector (Qxbm, alist);
|
|
1636 free_alist (alist);
|
|
1637 RETURN_UNGCPRO (result);
|
|
1638 }
|
|
1639 }
|
|
1640
|
|
1641 #ifdef HAVE_XPM
|
|
1642 data = pixmap_to_lisp_data (filename, 1);
|
|
1643
|
|
1644 if (!EQ (data, Qt))
|
|
1645 {
|
|
1646 alist = remassq_no_quit (Q_data, alist);
|
|
1647 alist = Fcons (Fcons (Q_file, filename),
|
|
1648 Fcons (Fcons (Q_data, data), alist));
|
|
1649 alist = Fcons (Fcons (Q_color_symbols,
|
|
1650 evaluate_xpm_color_symbols ()),
|
|
1651 alist);
|
|
1652 {
|
|
1653 Lisp_Object result = alist_to_tagged_vector (Qxpm, alist);
|
|
1654 free_alist (alist);
|
|
1655 RETURN_UNGCPRO (result);
|
|
1656 }
|
|
1657 }
|
|
1658 #endif
|
|
1659 }
|
|
1660
|
|
1661 /* If we couldn't convert it, just put it back as it is.
|
|
1662 We might try to further frob it later as a cursor-font
|
|
1663 specification. (We can't do that now because we don't know
|
|
1664 what dest-types it's going to be instantiated into.) */
|
|
1665 {
|
|
1666 Lisp_Object result = alist_to_tagged_vector (Qautodetect, alist);
|
|
1667 free_alist (alist);
|
|
1668 RETURN_UNGCPRO (result);
|
|
1669 }
|
|
1670 }
|
|
1671
|
|
1672 static int
|
|
1673 autodetect_possible_dest_types (void)
|
|
1674 {
|
|
1675 return
|
|
1676 IMAGE_MONO_PIXMAP_MASK |
|
|
1677 IMAGE_COLOR_PIXMAP_MASK |
|
|
1678 IMAGE_POINTER_MASK |
|
|
1679 IMAGE_TEXT_MASK;
|
|
1680 }
|
|
1681
|
|
1682 static void
|
|
1683 autodetect_instantiate (Lisp_Object image_instance,
|
|
1684 Lisp_Object instantiator,
|
|
1685 Lisp_Object pointer_fg,
|
|
1686 Lisp_Object pointer_bg,
|
|
1687 int dest_mask, Lisp_Object domain)
|
|
1688 {
|
|
1689 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1690 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1691 Lisp_Object alist = Qnil;
|
|
1692 Lisp_Object result = Qnil;
|
|
1693 int is_cursor_font = 0;
|
|
1694
|
|
1695 GCPRO3 (data, alist, result);
|
|
1696
|
|
1697 alist = tagged_vector_to_alist (instantiator);
|
|
1698 if (dest_mask & IMAGE_POINTER_MASK)
|
|
1699 {
|
771
|
1700 const char *name_ext;
|
462
|
1701
|
|
1702 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
1703 C_STRING_ALLOCA, name_ext,
|
|
1704 Qfile_name);
|
|
1705
|
|
1706 if (cursor_name_to_index (name_ext) != -1)
|
|
1707 {
|
|
1708 result = alist_to_tagged_vector (Qcursor_font, alist);
|
|
1709 is_cursor_font = 1;
|
|
1710 }
|
|
1711 }
|
|
1712
|
|
1713 if (!is_cursor_font)
|
|
1714 result = alist_to_tagged_vector (Qstring, alist);
|
|
1715 free_alist (alist);
|
|
1716
|
|
1717 if (is_cursor_font)
|
|
1718 cursor_font_instantiate (image_instance, result, pointer_fg,
|
|
1719 pointer_bg, dest_mask, domain);
|
|
1720 else
|
|
1721 string_instantiate (image_instance, result, pointer_fg,
|
|
1722 pointer_bg, dest_mask, domain);
|
|
1723
|
|
1724 UNGCPRO;
|
|
1725 }
|
|
1726
|
|
1727
|
|
1728 /**********************************************************************
|
|
1729 * Font *
|
|
1730 **********************************************************************/
|
|
1731
|
|
1732 static void
|
|
1733 font_validate (Lisp_Object instantiator)
|
|
1734 {
|
|
1735 data_must_be_present (instantiator);
|
|
1736 }
|
|
1737
|
|
1738 static int
|
|
1739 font_possible_dest_types (void)
|
|
1740 {
|
|
1741 return IMAGE_POINTER_MASK;
|
|
1742 }
|
|
1743
|
|
1744 static void
|
|
1745 font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1746 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1747 int dest_mask, Lisp_Object domain)
|
|
1748 {
|
|
1749 /* This function can GC */
|
|
1750 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1751 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1752 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1753 GdkColor fg, bg;
|
|
1754 GdkFont *source, *mask;
|
771
|
1755 char source_name[PATH_MAX], mask_name[PATH_MAX], dummy;
|
462
|
1756 int source_char, mask_char;
|
|
1757 int count;
|
|
1758 Lisp_Object foreground, background;
|
|
1759
|
|
1760 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1761 gui_error ("Not a Gtk device", device);
|
462
|
1762
|
|
1763 if (!STRINGP (data) ||
|
|
1764 strncmp ("FONT ", (char *) XSTRING_DATA (data), 5))
|
563
|
1765 invalid_argument ("Invalid font-glyph instantiator",
|
462
|
1766 instantiator);
|
|
1767
|
|
1768 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1769 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1770
|
|
1771 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1772 if (NILP (foreground))
|
|
1773 foreground = pointer_fg;
|
|
1774 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1775 if (NILP (background))
|
|
1776 background = pointer_bg;
|
|
1777
|
|
1778 generate_cursor_fg_bg (device, &foreground, &background, &fg, &bg);
|
|
1779
|
|
1780 count = sscanf ((char *) XSTRING_DATA (data),
|
|
1781 "FONT %s %d %s %d %c",
|
|
1782 source_name, &source_char,
|
|
1783 mask_name, &mask_char, &dummy);
|
|
1784 /* Allow "%s %d %d" as well... */
|
|
1785 if (count == 3 && (1 == sscanf (mask_name, "%d %c", &mask_char, &dummy)))
|
|
1786 count = 4, mask_name[0] = 0;
|
|
1787
|
|
1788 if (count != 2 && count != 4)
|
563
|
1789 syntax_error ("invalid cursor specification", data);
|
462
|
1790 source = gdk_font_load (source_name);
|
|
1791 if (! source)
|
563
|
1792 gui_error_2 ("couldn't load font",
|
462
|
1793 build_string (source_name),
|
|
1794 data);
|
|
1795 if (count == 2)
|
|
1796 mask = 0;
|
|
1797 else if (!mask_name[0])
|
|
1798 mask = source;
|
|
1799 else
|
|
1800 {
|
|
1801 mask = gdk_font_load (mask_name);
|
|
1802 if (!mask)
|
|
1803 /* continuable */
|
771
|
1804 Fsignal (Qgui_error, list3 (build_msg_string ("couldn't load font"),
|
563
|
1805 build_string (mask_name), data));
|
462
|
1806 }
|
|
1807 if (!mask)
|
|
1808 mask_char = 0;
|
|
1809
|
|
1810 /* #### call XQueryTextExtents() and check_pointer_sizes() here. */
|
|
1811
|
|
1812 gtk_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1813
|
|
1814 IMAGE_INSTANCE_GTK_CURSOR (ii) = NULL;
|
|
1815
|
|
1816 #if 0
|
|
1817 /* #### BILL!!! There is no way to call this function from Gdk */
|
|
1818 XCreateGlyphCursor (dpy, source, mask, source_char, mask_char,
|
|
1819 &fg, &bg);
|
|
1820 #endif
|
|
1821 XIMAGE_INSTANCE_PIXMAP_FG (image_instance) = foreground;
|
|
1822 XIMAGE_INSTANCE_PIXMAP_BG (image_instance) = background;
|
|
1823
|
|
1824 gdk_font_unref (source);
|
|
1825 if (mask && mask != source) gdk_font_unref (mask);
|
|
1826 }
|
|
1827
|
|
1828
|
|
1829 /**********************************************************************
|
|
1830 * Cursor-Font *
|
|
1831 **********************************************************************/
|
|
1832
|
|
1833 static void
|
|
1834 cursor_font_validate (Lisp_Object instantiator)
|
|
1835 {
|
|
1836 data_must_be_present (instantiator);
|
|
1837 }
|
|
1838
|
|
1839 static int
|
|
1840 cursor_font_possible_dest_types (void)
|
|
1841 {
|
|
1842 return IMAGE_POINTER_MASK;
|
|
1843 }
|
|
1844
|
|
1845 static char *__downcase (const char *name)
|
|
1846 {
|
|
1847 char *converted = strdup(name);
|
|
1848 char *work = converted;
|
|
1849
|
|
1850 while (*work)
|
|
1851 {
|
|
1852 *work = tolower(*work);
|
|
1853 work++;
|
|
1854 }
|
|
1855 return(converted);
|
|
1856 }
|
|
1857
|
|
1858 /* This is basically the equivalent of XmuCursorNameToIndex */
|
|
1859 static gint
|
|
1860 cursor_name_to_index (const char *name)
|
|
1861 {
|
|
1862 int i;
|
|
1863 static char *the_gdk_cursors[GDK_NUM_GLYPHS];
|
|
1864
|
|
1865 if (!the_gdk_cursors[GDK_BASED_ARROW_UP])
|
|
1866 {
|
|
1867 /* Need to initialize the array */
|
|
1868 /* Supposedly since this array is static it should be
|
|
1869 initialized to NULLs for us, but I'm very paranoid. */
|
|
1870 for (i = 0; i < GDK_NUM_GLYPHS; i++)
|
|
1871 {
|
|
1872 the_gdk_cursors[i] = NULL;
|
|
1873 }
|
|
1874
|
|
1875 #define FROB_CURSOR(x) the_gdk_cursors[GDK_##x] = __downcase(#x)
|
|
1876 FROB_CURSOR(ARROW); FROB_CURSOR(BASED_ARROW_DOWN);
|
|
1877 FROB_CURSOR(BASED_ARROW_UP); FROB_CURSOR(BOAT);
|
|
1878 FROB_CURSOR(BOGOSITY); FROB_CURSOR(BOTTOM_LEFT_CORNER);
|
|
1879 FROB_CURSOR(BOTTOM_RIGHT_CORNER); FROB_CURSOR(BOTTOM_SIDE);
|
|
1880 FROB_CURSOR(BOTTOM_TEE); FROB_CURSOR(BOX_SPIRAL);
|
|
1881 FROB_CURSOR(CENTER_PTR); FROB_CURSOR(CIRCLE);
|
|
1882 FROB_CURSOR(CLOCK); FROB_CURSOR(COFFEE_MUG);
|
|
1883 FROB_CURSOR(CROSS); FROB_CURSOR(CROSS_REVERSE);
|
|
1884 FROB_CURSOR(CROSSHAIR); FROB_CURSOR(DIAMOND_CROSS);
|
|
1885 FROB_CURSOR(DOT); FROB_CURSOR(DOTBOX);
|
|
1886 FROB_CURSOR(DOUBLE_ARROW); FROB_CURSOR(DRAFT_LARGE);
|
|
1887 FROB_CURSOR(DRAFT_SMALL); FROB_CURSOR(DRAPED_BOX);
|
|
1888 FROB_CURSOR(EXCHANGE); FROB_CURSOR(FLEUR);
|
|
1889 FROB_CURSOR(GOBBLER); FROB_CURSOR(GUMBY);
|
|
1890 FROB_CURSOR(HAND1); FROB_CURSOR(HAND2);
|
|
1891 FROB_CURSOR(HEART); FROB_CURSOR(ICON);
|
|
1892 FROB_CURSOR(IRON_CROSS); FROB_CURSOR(LEFT_PTR);
|
|
1893 FROB_CURSOR(LEFT_SIDE); FROB_CURSOR(LEFT_TEE);
|
|
1894 FROB_CURSOR(LEFTBUTTON); FROB_CURSOR(LL_ANGLE);
|
|
1895 FROB_CURSOR(LR_ANGLE); FROB_CURSOR(MAN);
|
|
1896 FROB_CURSOR(MIDDLEBUTTON); FROB_CURSOR(MOUSE);
|
|
1897 FROB_CURSOR(PENCIL); FROB_CURSOR(PIRATE);
|
|
1898 FROB_CURSOR(PLUS); FROB_CURSOR(QUESTION_ARROW);
|
|
1899 FROB_CURSOR(RIGHT_PTR); FROB_CURSOR(RIGHT_SIDE);
|
|
1900 FROB_CURSOR(RIGHT_TEE); FROB_CURSOR(RIGHTBUTTON);
|
|
1901 FROB_CURSOR(RTL_LOGO); FROB_CURSOR(SAILBOAT);
|
|
1902 FROB_CURSOR(SB_DOWN_ARROW); FROB_CURSOR(SB_H_DOUBLE_ARROW);
|
|
1903 FROB_CURSOR(SB_LEFT_ARROW); FROB_CURSOR(SB_RIGHT_ARROW);
|
|
1904 FROB_CURSOR(SB_UP_ARROW); FROB_CURSOR(SB_V_DOUBLE_ARROW);
|
|
1905 FROB_CURSOR(SHUTTLE); FROB_CURSOR(SIZING);
|
|
1906 FROB_CURSOR(SPIDER); FROB_CURSOR(SPRAYCAN);
|
|
1907 FROB_CURSOR(STAR); FROB_CURSOR(TARGET);
|
|
1908 FROB_CURSOR(TCROSS); FROB_CURSOR(TOP_LEFT_ARROW);
|
|
1909 FROB_CURSOR(TOP_LEFT_CORNER); FROB_CURSOR(TOP_RIGHT_CORNER);
|
|
1910 FROB_CURSOR(TOP_SIDE); FROB_CURSOR(TOP_TEE);
|
|
1911 FROB_CURSOR(TREK); FROB_CURSOR(UL_ANGLE);
|
|
1912 FROB_CURSOR(UMBRELLA); FROB_CURSOR(UR_ANGLE);
|
|
1913 FROB_CURSOR(WATCH); FROB_CURSOR(XTERM);
|
|
1914 FROB_CURSOR(X_CURSOR);
|
|
1915 #undef FROB_CURSOR
|
|
1916 }
|
|
1917
|
|
1918 for (i = 0; i < GDK_NUM_GLYPHS; i++)
|
|
1919 {
|
|
1920 if (!the_gdk_cursors[i]) continue;
|
|
1921 if (!strcmp (the_gdk_cursors[i], name))
|
|
1922 {
|
|
1923 return (i);
|
|
1924 }
|
|
1925 }
|
|
1926 return(-1);
|
|
1927 }
|
|
1928
|
|
1929 static void
|
|
1930 cursor_font_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
1931 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
1932 int dest_mask, Lisp_Object domain)
|
|
1933 {
|
|
1934 /* This function can GC */
|
|
1935 Lisp_Object data = find_keyword_in_vector (instantiator, Q_data);
|
|
1936 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
1937 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
1938 int i;
|
771
|
1939 const char *name_ext;
|
462
|
1940 Lisp_Object foreground, background;
|
|
1941
|
|
1942 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
1943 gui_error ("Not a Gtk device", device);
|
462
|
1944
|
|
1945 if (!(dest_mask & IMAGE_POINTER_MASK))
|
|
1946 incompatible_image_types (instantiator, dest_mask, IMAGE_POINTER_MASK);
|
|
1947
|
|
1948 TO_EXTERNAL_FORMAT (LISP_STRING, data,
|
|
1949 C_STRING_ALLOCA, name_ext,
|
|
1950 Qfile_name);
|
|
1951
|
|
1952 if ((i = cursor_name_to_index (name_ext)) == -1)
|
563
|
1953 invalid_argument ("Unrecognized cursor-font name", data);
|
462
|
1954
|
|
1955 gtk_initialize_pixmap_image_instance (ii, 1, IMAGE_POINTER);
|
|
1956 IMAGE_INSTANCE_GTK_CURSOR (ii) = gdk_cursor_new (i);
|
|
1957 foreground = find_keyword_in_vector (instantiator, Q_foreground);
|
|
1958 if (NILP (foreground))
|
|
1959 foreground = pointer_fg;
|
|
1960 background = find_keyword_in_vector (instantiator, Q_background);
|
|
1961 if (NILP (background))
|
|
1962 background = pointer_bg;
|
|
1963 maybe_recolor_cursor (image_instance, foreground, background);
|
|
1964 }
|
|
1965
|
|
1966 static int
|
|
1967 gtk_colorize_image_instance (Lisp_Object image_instance,
|
|
1968 Lisp_Object foreground, Lisp_Object background);
|
|
1969
|
|
1970
|
|
1971 /************************************************************************/
|
|
1972 /* subwindow and widget support */
|
|
1973 /************************************************************************/
|
|
1974
|
|
1975 /* unmap the image if it is a widget. This is used by redisplay via
|
|
1976 redisplay_unmap_subwindows */
|
|
1977 static void
|
|
1978 gtk_unmap_subwindow (Lisp_Image_Instance *p)
|
|
1979 {
|
|
1980 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
1981 {
|
|
1982 /* We don't support subwindows, but we do support widgets... */
|
|
1983 abort ();
|
|
1984 }
|
|
1985 else /* must be a widget */
|
|
1986 {
|
|
1987 /* Since we are being unmapped we want the enclosing frame to
|
|
1988 get focus. The losing with simple scrolling but is the safest
|
|
1989 thing to do. */
|
|
1990 if (IMAGE_INSTANCE_GTK_CLIPWIDGET (p))
|
|
1991 gtk_widget_unmap (IMAGE_INSTANCE_GTK_CLIPWIDGET (p));
|
|
1992 }
|
|
1993 }
|
|
1994
|
|
1995 /* map the subwindow. This is used by redisplay via
|
|
1996 redisplay_output_subwindow */
|
|
1997 static void
|
|
1998 gtk_map_subwindow (Lisp_Image_Instance *p, int x, int y,
|
691
|
1999 struct display_glyph_area* dga)
|
462
|
2000 {
|
|
2001 assert (dga->width > 0 && dga->height > 0);
|
|
2002
|
|
2003 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
|
|
2004 {
|
|
2005 /* No subwindow support... */
|
|
2006 abort ();
|
|
2007 }
|
|
2008 else /* must be a widget */
|
|
2009 {
|
|
2010 struct frame *f = XFRAME (IMAGE_INSTANCE_FRAME (p));
|
|
2011 GtkWidget *wid = IMAGE_INSTANCE_GTK_CLIPWIDGET (p);
|
|
2012 GtkAllocation a;
|
|
2013
|
|
2014 if (!wid) return;
|
|
2015
|
|
2016 a.x = x + IMAGE_INSTANCE_GTK_WIDGET_XOFFSET (p);
|
|
2017 a.y = y + IMAGE_INSTANCE_GTK_WIDGET_YOFFSET (p);
|
|
2018 a.width = dga->width;
|
|
2019 a.height = dga->height;
|
|
2020
|
|
2021 if ((a.width != wid->allocation.width) ||
|
|
2022 (a.height != wid->allocation.height))
|
|
2023 {
|
|
2024 gtk_widget_size_allocate (IMAGE_INSTANCE_GTK_CLIPWIDGET (p), &a);
|
|
2025 }
|
|
2026
|
|
2027 /* #### FIXME DAMMIT */
|
|
2028 if ((wid->allocation.x != -dga->xoffset) ||
|
|
2029 (wid->allocation.y != -dga->yoffset))
|
|
2030 {
|
|
2031 guint32 old_flags = GTK_WIDGET_FLAGS (FRAME_GTK_TEXT_WIDGET (f));
|
|
2032
|
|
2033 /* Fucking GtkFixed widget queues a resize when you add a widget.
|
|
2034 ** But only if it is visible.
|
|
2035 ** losers.
|
|
2036 */
|
|
2037 GTK_WIDGET_FLAGS(FRAME_GTK_TEXT_WIDGET (f)) &= ~GTK_VISIBLE;
|
|
2038 if (IMAGE_INSTANCE_GTK_ALREADY_PUT(p))
|
|
2039 {
|
|
2040 gtk_fixed_move (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
2041 wid,
|
|
2042 -dga->xoffset, -dga->yoffset);
|
|
2043 }
|
|
2044 else
|
|
2045 {
|
|
2046 IMAGE_INSTANCE_GTK_ALREADY_PUT(p) = TRUE;
|
|
2047 gtk_fixed_put (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
2048 wid,
|
|
2049 -dga->xoffset, -dga->yoffset);
|
|
2050 }
|
|
2051 GTK_WIDGET_FLAGS(FRAME_GTK_TEXT_WIDGET (f)) = old_flags;
|
|
2052 }
|
691
|
2053 else
|
|
2054 {
|
|
2055 if (IMAGE_INSTANCE_GTK_ALREADY_PUT(p))
|
|
2056 {
|
|
2057 /* Do nothing... */
|
|
2058 }
|
|
2059 else
|
|
2060 {
|
|
2061 /* Must make sure we have put the image at least once! */
|
|
2062 IMAGE_INSTANCE_GTK_ALREADY_PUT(p) = TRUE;
|
|
2063 gtk_fixed_put (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
2064 wid,
|
|
2065 -dga->xoffset, -dga->yoffset);
|
|
2066 }
|
|
2067 }
|
462
|
2068
|
|
2069 if (!IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (p))
|
|
2070 {
|
|
2071 gtk_widget_map (wid);
|
|
2072 }
|
|
2073
|
|
2074 gtk_widget_draw (wid, NULL);
|
|
2075 }
|
|
2076 }
|
|
2077
|
|
2078 /* when you click on a widget you may activate another widget this
|
|
2079 needs to be checked and all appropriate widgets updated */
|
|
2080 static void
|
|
2081 gtk_redisplay_subwindow (Lisp_Image_Instance *p)
|
|
2082 {
|
|
2083 /* Update the subwindow size if necessary. */
|
|
2084 if (IMAGE_INSTANCE_SIZE_CHANGED (p))
|
|
2085 {
|
|
2086 #if 0
|
|
2087 XResizeWindow (IMAGE_INSTANCE_X_SUBWINDOW_DISPLAY (p),
|
|
2088 IMAGE_INSTANCE_X_SUBWINDOW_ID (p),
|
|
2089 IMAGE_INSTANCE_WIDTH (p),
|
|
2090 IMAGE_INSTANCE_HEIGHT (p));
|
|
2091 #endif
|
|
2092 }
|
|
2093 }
|
|
2094
|
|
2095 /* Update all attributes that have changed. */
|
|
2096 static void
|
|
2097 gtk_redisplay_widget (Lisp_Image_Instance *p)
|
|
2098 {
|
|
2099 /* This function can GC if IN_REDISPLAY is false. */
|
|
2100
|
|
2101 if (!IMAGE_INSTANCE_GTK_CLIPWIDGET (p))
|
|
2102 return;
|
|
2103
|
|
2104 #ifdef HAVE_WIDGETS
|
|
2105 /* First get the items if they have changed since this is a
|
|
2106 structural change. As such it will nuke all added values so we
|
|
2107 need to update most other things after the items have changed.*/
|
|
2108 gtk_widget_show_all (IMAGE_INSTANCE_GTK_CLIPWIDGET (p));
|
|
2109 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2110 {
|
793
|
2111 Lisp_Object image_instance = wrap_image_instance (p);
|
|
2112
|
462
|
2113
|
|
2114 /* Need to update GtkArgs that might have changed... */
|
|
2115 /* #### FIXME!!! */
|
|
2116 }
|
|
2117 else
|
|
2118 {
|
|
2119 /* #### FIXME!!! */
|
|
2120 /* No items changed, so do nothing, right? */
|
|
2121 }
|
|
2122
|
|
2123 /* Possibly update the colors and font */
|
|
2124 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (p)
|
|
2125 ||
|
|
2126 /* #### This is not sufficient because it will not cope with widgets
|
|
2127 that are not currently visible. Once redisplay has done the
|
|
2128 visible ones it will clear this flag so that when new ones
|
|
2129 become visible they will not be updated. */
|
|
2130 XFRAME (IMAGE_INSTANCE_FRAME (p))->faces_changed
|
|
2131 ||
|
|
2132 XFRAME (IMAGE_INSTANCE_FRAME (p))->frame_changed
|
|
2133 ||
|
|
2134 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p))
|
|
2135 {
|
|
2136 /* #### Write this function BILL! */
|
|
2137 update_widget_face (NULL, p, IMAGE_INSTANCE_FRAME (p));
|
|
2138 }
|
|
2139
|
|
2140 /* Possibly update the text. */
|
|
2141 if (IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2142 {
|
|
2143 char* str;
|
|
2144 Lisp_Object val = IMAGE_INSTANCE_WIDGET_TEXT (p);
|
|
2145 LISP_STRING_TO_EXTERNAL (val, str, Qnative);
|
|
2146
|
|
2147 /* #### Need to special case each type of GtkWidget here! */
|
|
2148 }
|
|
2149
|
|
2150 /* Possibly update the size. */
|
|
2151 if (IMAGE_INSTANCE_SIZE_CHANGED (p)
|
|
2152 ||
|
|
2153 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (p)
|
|
2154 ||
|
|
2155 IMAGE_INSTANCE_TEXT_CHANGED (p))
|
|
2156 {
|
|
2157 assert (IMAGE_INSTANCE_GTK_WIDGET_ID (p) &&
|
|
2158 IMAGE_INSTANCE_GTK_CLIPWIDGET (p)) ;
|
|
2159
|
|
2160 /* #### Resize the widget! */
|
|
2161 /* gtk_widget_size_allocate () */
|
|
2162 }
|
|
2163
|
|
2164 /* Adjust offsets within the frame. */
|
|
2165 if (XFRAME (IMAGE_INSTANCE_FRAME (p))->size_changed)
|
|
2166 {
|
|
2167 /* I don't think we need to do anything for Gtk here... */
|
|
2168 }
|
|
2169
|
|
2170 /* now modify the widget */
|
|
2171 #endif
|
|
2172 }
|
|
2173
|
|
2174 /* instantiate and gtk type subwindow */
|
|
2175 static void
|
|
2176 gtk_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2177 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2178 int dest_mask, Lisp_Object domain)
|
|
2179 {
|
|
2180 /* This function can GC */
|
|
2181 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2182 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
|
|
2183
|
|
2184 if (!DEVICE_GTK_P (XDEVICE (device)))
|
563
|
2185 gui_error ("Not a GTK device", device);
|
462
|
2186
|
|
2187 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
|
|
2188
|
|
2189 ii->data = xnew_and_zero (struct gtk_subwindow_data);
|
|
2190
|
|
2191 /* Create a window for clipping */
|
|
2192 IMAGE_INSTANCE_GTK_CLIPWINDOW (ii) = NULL;
|
|
2193
|
|
2194 /* Now put the subwindow inside the clip window. */
|
|
2195 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void *) NULL;
|
|
2196 }
|
|
2197
|
|
2198 #ifdef HAVE_WIDGETS
|
|
2199
|
|
2200 /************************************************************************/
|
|
2201 /* widgets */
|
|
2202 /************************************************************************/
|
|
2203 static void
|
|
2204 update_widget_face (GtkWidget *w, Lisp_Image_Instance *ii,
|
|
2205 Lisp_Object domain)
|
|
2206 {
|
|
2207 if (0)
|
|
2208 {
|
|
2209 GtkStyle *style = gtk_widget_get_style (w);
|
|
2210 Lisp_Object pixel = Qnil;
|
|
2211 GdkColor *fcolor, *bcolor;
|
|
2212
|
|
2213 style = gtk_style_copy (style);
|
|
2214
|
|
2215 /* Update the foreground. */
|
|
2216 pixel = FACE_FOREGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain);
|
|
2217 fcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2218
|
|
2219 /* Update the background. */
|
|
2220 pixel = FACE_BACKGROUND (IMAGE_INSTANCE_WIDGET_FACE (ii), domain);
|
|
2221 bcolor = COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2222
|
|
2223 /* Update the font */
|
|
2224 /* #### FIXME!!! Need to copy the widgets style, dick with it, and
|
|
2225 ** set the widgets style to the new style...
|
|
2226 */
|
|
2227 gtk_widget_set_style (w, style);
|
|
2228
|
|
2229 /* #### Megahack - but its just getting too complicated to do this
|
|
2230 in the right place. */
|
|
2231 #if 0
|
|
2232 if (EQ (IMAGE_INSTANCE_WIDGET_TYPE (ii), Qtab_control))
|
|
2233 update_tab_widget_face (wv, ii, domain);
|
|
2234 #endif
|
|
2235 }
|
|
2236 }
|
|
2237
|
|
2238 #if 0
|
|
2239 static void
|
|
2240 update_tab_widget_face (GtkWidget *w, Lisp_Image_Instance *ii,
|
|
2241 Lisp_Object domain)
|
|
2242 {
|
|
2243 if (wv->contents)
|
|
2244 {
|
|
2245 widget_value* val = wv->contents, *cur;
|
|
2246
|
|
2247 /* Give each child label the correct foreground color. */
|
|
2248 Lisp_Object pixel = FACE_FOREGROUND
|
|
2249 (IMAGE_INSTANCE_WIDGET_FACE (ii),
|
|
2250 domain);
|
|
2251 XColor fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
|
|
2252 lw_add_widget_value_arg (val, XtNtabForeground, fcolor.pixel);
|
|
2253 wv->change = VISIBLE_CHANGE;
|
|
2254 val->change = VISIBLE_CHANGE;
|
|
2255
|
|
2256 for (cur = val->next; cur; cur = cur->next)
|
|
2257 {
|
|
2258 cur->change = VISIBLE_CHANGE;
|
|
2259 if (cur->value)
|
|
2260 {
|
|
2261 lw_copy_widget_value_args (val, cur);
|
|
2262 }
|
|
2263 }
|
|
2264 }
|
|
2265 }
|
|
2266 #endif
|
|
2267
|
|
2268 static Lisp_Object
|
|
2269 gtk_widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2270 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2271 Lisp_Object domain)
|
|
2272 {
|
|
2273 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2274 Lisp_Object widget = Qnil;
|
|
2275 char *nm = NULL;
|
|
2276 GtkWidget *w = NULL;
|
|
2277 struct gcpro gcpro1;
|
|
2278
|
|
2279 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
|
|
2280
|
|
2281 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
|
|
2282 {
|
|
2283 LISP_STRING_TO_EXTERNAL (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm, Qnative);
|
|
2284 }
|
|
2285
|
|
2286 ii->data = xnew_and_zero (struct gtk_subwindow_data);
|
|
2287
|
|
2288 /* Create a clipping widget */
|
|
2289 IMAGE_INSTANCE_GTK_CLIPWIDGET (ii) = NULL;
|
|
2290 IMAGE_INSTANCE_GTK_ALREADY_PUT(ii) = FALSE;
|
|
2291
|
|
2292 /* Create the actual widget */
|
|
2293 GCPRO1 (widget);
|
|
2294 widget = call5 (Qgtk_widget_instantiate_internal,
|
|
2295 image_instance, instantiator,
|
|
2296 pointer_fg, pointer_bg,
|
|
2297 domain);
|
|
2298
|
|
2299 if (!NILP (widget))
|
|
2300 {
|
|
2301 CHECK_GTK_OBJECT (widget);
|
|
2302 w = GTK_WIDGET (XGTK_OBJECT (widget)->object);
|
|
2303 }
|
|
2304 else
|
|
2305 {
|
|
2306 stderr_out ("Lisp-level creation of widget failed... falling back\n");
|
|
2307 w = gtk_label_new ("Widget Creation Failed...");
|
|
2308 }
|
|
2309
|
|
2310 UNGCPRO;
|
|
2311
|
|
2312 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void *) w;
|
|
2313
|
|
2314 /* #### HACK!!!! We should make this do the right thing if we
|
|
2315 ** really need a clip widget!
|
|
2316 */
|
|
2317 IMAGE_INSTANCE_GTK_CLIPWIDGET (ii) = w;
|
|
2318
|
|
2319 return (Qt);
|
|
2320 }
|
|
2321
|
|
2322 static void
|
|
2323 gtk_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
|
|
2324 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
|
|
2325 int dest_mask, Lisp_Object domain)
|
|
2326 {
|
|
2327 call_with_suspended_errors ((lisp_fn_t) gtk_widget_instantiate_1,
|
|
2328 Qnil, Qimage,
|
|
2329 ERROR_ME_WARN, 5,
|
|
2330 image_instance, instantiator,
|
|
2331 pointer_fg,
|
|
2332 pointer_bg,
|
|
2333 domain);
|
|
2334 }
|
|
2335
|
|
2336 /* get properties of a control */
|
|
2337 static Lisp_Object
|
|
2338 gtk_widget_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2339 {
|
|
2340 /* Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); */
|
|
2341
|
|
2342 /* get the text from a control */
|
|
2343 if (EQ (prop, Q_text))
|
|
2344 {
|
|
2345 return Qnil;
|
|
2346 }
|
|
2347 return Qunbound;
|
|
2348 }
|
|
2349
|
|
2350 #define FAKE_GTK_WIDGET_INSTANTIATOR(x) \
|
|
2351 static void \
|
|
2352 gtk_##x##_instantiate (Lisp_Object image_instance, \
|
|
2353 Lisp_Object instantiator, \
|
|
2354 Lisp_Object pointer_fg, \
|
|
2355 Lisp_Object pointer_bg, \
|
|
2356 int dest_mask, Lisp_Object domain) \
|
|
2357 { \
|
|
2358 gtk_widget_instantiate (image_instance, instantiator, pointer_fg, \
|
|
2359 pointer_bg, dest_mask, domain); \
|
|
2360 }
|
|
2361
|
|
2362 FAKE_GTK_WIDGET_INSTANTIATOR(native_layout);
|
|
2363 FAKE_GTK_WIDGET_INSTANTIATOR(button);
|
|
2364 FAKE_GTK_WIDGET_INSTANTIATOR(progress_gauge);
|
|
2365 FAKE_GTK_WIDGET_INSTANTIATOR(edit_field);
|
|
2366 FAKE_GTK_WIDGET_INSTANTIATOR(combo_box);
|
|
2367 FAKE_GTK_WIDGET_INSTANTIATOR(tab_control);
|
|
2368 FAKE_GTK_WIDGET_INSTANTIATOR(label);
|
|
2369
|
|
2370 /* Update a button's clicked state. */
|
|
2371 static void
|
|
2372 gtk_button_redisplay (Lisp_Object image_instance)
|
|
2373 {
|
|
2374 /* This function can GC if IN_REDISPLAY is false. */
|
|
2375 Lisp_Image_Instance *p = XIMAGE_INSTANCE (image_instance);
|
|
2376 GtkWidget *w = IMAGE_INSTANCE_GTK_CLIPWIDGET (p);
|
|
2377
|
|
2378 if (GTK_WIDGET_TYPE (w) == gtk_button_get_type ())
|
|
2379 {
|
|
2380 }
|
|
2381 else if (GTK_WIDGET_TYPE (w) == gtk_check_button_get_type ())
|
|
2382 {
|
|
2383 }
|
|
2384 else if (GTK_WIDGET_TYPE (w) == gtk_radio_button_get_type ())
|
|
2385 {
|
|
2386 }
|
|
2387 else
|
|
2388 {
|
|
2389 /* Unknown button type... */
|
|
2390 abort();
|
|
2391 }
|
|
2392 }
|
|
2393
|
|
2394 /* get properties of a button */
|
|
2395 static Lisp_Object
|
|
2396 gtk_button_property (Lisp_Object image_instance, Lisp_Object prop)
|
|
2397 {
|
|
2398 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2399
|
|
2400 /* check the state of a button */
|
|
2401 if (EQ (prop, Q_selected))
|
|
2402 {
|
|
2403 if (GTK_WIDGET_HAS_FOCUS (IMAGE_INSTANCE_SUBWINDOW_ID (ii)))
|
|
2404 return Qt;
|
|
2405 else
|
|
2406 return Qnil;
|
|
2407 }
|
|
2408 return Qunbound;
|
|
2409 }
|
|
2410
|
|
2411 /* set the properties of a progress gauge */
|
|
2412 static void
|
|
2413 gtk_progress_gauge_redisplay (Lisp_Object image_instance)
|
|
2414 {
|
|
2415 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2416
|
|
2417 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
|
|
2418 {
|
|
2419 gfloat f;
|
|
2420 Lisp_Object val;
|
|
2421
|
|
2422 val = XGUI_ITEM (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii))->value;
|
|
2423 f = XFLOATINT (val);
|
|
2424
|
|
2425 gtk_progress_set_value (GTK_PROGRESS (IMAGE_INSTANCE_SUBWINDOW_ID (ii)),
|
|
2426 f);
|
|
2427 }
|
|
2428 }
|
|
2429
|
|
2430 /* Set the properties of a tab control */
|
|
2431 static void
|
|
2432 gtk_tab_control_redisplay (Lisp_Object image_instance)
|
|
2433 {
|
|
2434 /* #### Convert this to GTK baby! */
|
|
2435 Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
|
|
2436
|
|
2437 if (IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) ||
|
|
2438 IMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (ii))
|
|
2439 {
|
|
2440 /* If only the order has changed then simply select the first
|
|
2441 one of the pending set. This stops horrendous rebuilding -
|
|
2442 and hence flicker - of the tabs each time you click on
|
|
2443 one. */
|
|
2444 if (tab_control_order_only_changed (image_instance))
|
|
2445 {
|
|
2446 Lisp_Object rest, selected =
|
|
2447 gui_item_list_find_selected
|
|
2448 (NILP (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)) ?
|
|
2449 XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)) :
|
|
2450 XCDR (IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii)));
|
|
2451
|
|
2452 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
|
|
2453 {
|
1318
|
2454 if (gui_item_equal_sans_selected (XCAR (rest), selected, 0, 1))
|
462
|
2455 {
|
|
2456 Lisp_Object old_selected =gui_item_list_find_selected
|
|
2457 (XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)));
|
|
2458
|
|
2459 /* Need to focus on the widget... */
|
|
2460 stderr_out ("Hey, change the tab-focus you boob...\n");
|
|
2461
|
|
2462 /* Pick up the new selected item. */
|
|
2463 XGUI_ITEM (old_selected)->selected =
|
|
2464 XGUI_ITEM (XCAR (rest))->selected;
|
|
2465 XGUI_ITEM (XCAR (rest))->selected =
|
|
2466 XGUI_ITEM (selected)->selected;
|
|
2467 /* We're not actually changing the items anymore. */
|
|
2468 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii) = 0;
|
|
2469 IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (ii) = Qnil;
|
|
2470 break;
|
|
2471 }
|
|
2472 }
|
|
2473 }
|
|
2474 else
|
|
2475 {
|
|
2476 /* More than just the order has changed... let's get busy! */
|
|
2477 GtkNotebook *nb = GTK_NOTEBOOK (IMAGE_INSTANCE_GTK_CLIPWIDGET (ii));
|
|
2478 guint num_pages = g_list_length (nb->children);
|
|
2479 Lisp_Object rest;
|
|
2480
|
|
2481 if (num_pages >= 0)
|
|
2482 {
|
|
2483 int i;
|
|
2484 for (i = num_pages; i >= 0; --i)
|
|
2485 {
|
|
2486 gtk_notebook_remove_page (nb, i);
|
|
2487 }
|
|
2488 }
|
|
2489
|
|
2490 LIST_LOOP (rest, XCDR (IMAGE_INSTANCE_WIDGET_ITEMS (ii)))
|
|
2491 {
|
|
2492 Lisp_Gui_Item *pgui = XGUI_ITEM (XCAR (rest));
|
|
2493 char *c_name = NULL;
|
|
2494
|
|
2495 if (!STRINGP (pgui->name))
|
1318
|
2496 pgui->name = eval_within_redisplay (pgui->name);
|
|
2497
|
|
2498 if (!STRINGP (pgui->name))
|
|
2499 warn_when_safe (Qredisplay, Qwarning,
|
|
2500 "Name does not evaluate to string");
|
|
2501 else
|
|
2502 {
|
|
2503 TO_EXTERNAL_FORMAT (LISP_STRING, pgui->name,
|
|
2504 C_STRING_ALLOCA, c_name,
|
|
2505 Qctext);
|
|
2506
|
|
2507 gtk_notebook_append_page (nb,
|
|
2508 gtk_vbox_new (FALSE, 3),
|
|
2509 gtk_label_new (c_name));
|
|
2510 }
|
462
|
2511 }
|
|
2512
|
|
2513 /* Show all the new widgets we just added... */
|
|
2514 gtk_widget_show_all (GTK_WIDGET (nb));
|
|
2515 }
|
|
2516 }
|
|
2517
|
|
2518 /* Possibly update the face. */
|
|
2519 #if 0
|
|
2520 if (IMAGE_INSTANCE_WIDGET_FACE_CHANGED (ii)
|
|
2521 ||
|
|
2522 XFRAME (IMAGE_INSTANCE_FRAME (ii))->faces_changed
|
|
2523 ||
|
|
2524 IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED (ii))
|
|
2525 {
|
|
2526 update_tab_widget_face (wv, ii,
|
|
2527 IMAGE_INSTANCE_FRAME (ii));
|
|
2528 }
|
|
2529 #endif
|
|
2530 }
|
|
2531 #endif /* HAVE_WIDGETS */
|
|
2532
|
|
2533
|
|
2534 /************************************************************************/
|
|
2535 /* initialization */
|
|
2536 /************************************************************************/
|
|
2537 void
|
|
2538 syms_of_glyphs_gtk (void)
|
|
2539 {
|
|
2540 #ifdef HAVE_WIDGETS
|
563
|
2541 DEFSYMBOL (Qgtk_widget_instantiate_internal);
|
|
2542 DEFSYMBOL (Qgtk_widget_property_internal);
|
|
2543 DEFSYMBOL (Qgtk_widget_redisplay_internal);
|
|
2544 DEFSYMBOL (Qgtk_widget_set_style);
|
462
|
2545 #endif
|
|
2546 }
|
|
2547
|
|
2548 void
|
|
2549 console_type_create_glyphs_gtk (void)
|
|
2550 {
|
|
2551 /* image methods */
|
|
2552 CONSOLE_HAS_METHOD (gtk, print_image_instance);
|
|
2553 CONSOLE_HAS_METHOD (gtk, finalize_image_instance);
|
|
2554 CONSOLE_HAS_METHOD (gtk, image_instance_equal);
|
|
2555 CONSOLE_HAS_METHOD (gtk, image_instance_hash);
|
|
2556 CONSOLE_HAS_METHOD (gtk, colorize_image_instance);
|
|
2557 CONSOLE_HAS_METHOD (gtk, init_image_instance_from_eimage);
|
|
2558 CONSOLE_HAS_METHOD (gtk, locate_pixmap_file);
|
|
2559 CONSOLE_HAS_METHOD (gtk, unmap_subwindow);
|
|
2560 CONSOLE_HAS_METHOD (gtk, map_subwindow);
|
|
2561 CONSOLE_HAS_METHOD (gtk, redisplay_widget);
|
|
2562 CONSOLE_HAS_METHOD (gtk, redisplay_subwindow);
|
|
2563 }
|
|
2564
|
|
2565 void
|
|
2566 image_instantiator_format_create_glyphs_gtk (void)
|
|
2567 {
|
|
2568 IIFORMAT_VALID_CONSOLE (gtk, nothing);
|
|
2569 IIFORMAT_VALID_CONSOLE (gtk, string);
|
|
2570 #ifdef HAVE_WIDGETS
|
|
2571 IIFORMAT_VALID_CONSOLE (gtk, layout);
|
|
2572 #endif
|
|
2573 IIFORMAT_VALID_CONSOLE (gtk, formatted_string);
|
|
2574 IIFORMAT_VALID_CONSOLE (gtk, inherit);
|
|
2575 #ifdef HAVE_XPM
|
|
2576 INITIALIZE_DEVICE_IIFORMAT (gtk, xpm);
|
|
2577 IIFORMAT_HAS_DEVMETHOD (gtk, xpm, instantiate);
|
|
2578 #endif
|
|
2579 #ifdef HAVE_JPEG
|
|
2580 IIFORMAT_VALID_CONSOLE (gtk, jpeg);
|
|
2581 #endif
|
|
2582 #ifdef HAVE_TIFF
|
|
2583 IIFORMAT_VALID_CONSOLE (gtk, tiff);
|
|
2584 #endif
|
|
2585 #ifdef HAVE_PNG
|
|
2586 IIFORMAT_VALID_CONSOLE (gtk, png);
|
|
2587 #endif
|
|
2588 #ifdef HAVE_GIF
|
|
2589 IIFORMAT_VALID_CONSOLE (gtk, gif);
|
|
2590 #endif
|
|
2591
|
|
2592 INITIALIZE_DEVICE_IIFORMAT (gtk, subwindow);
|
|
2593 IIFORMAT_HAS_DEVMETHOD (gtk, subwindow, instantiate);
|
|
2594
|
|
2595 #ifdef HAVE_WIDGETS
|
|
2596 /* layout widget */
|
|
2597 INITIALIZE_DEVICE_IIFORMAT (gtk, native_layout);
|
|
2598 IIFORMAT_HAS_DEVMETHOD (gtk, native_layout, instantiate);
|
|
2599
|
|
2600 /* button widget */
|
|
2601 INITIALIZE_DEVICE_IIFORMAT (gtk, button);
|
|
2602 IIFORMAT_HAS_DEVMETHOD (gtk, button, property);
|
|
2603 IIFORMAT_HAS_DEVMETHOD (gtk, button, instantiate);
|
|
2604 IIFORMAT_HAS_DEVMETHOD (gtk, button, redisplay);
|
|
2605 /* general widget methods. */
|
|
2606 INITIALIZE_DEVICE_IIFORMAT (gtk, widget);
|
|
2607 IIFORMAT_HAS_DEVMETHOD (gtk, widget, property);
|
|
2608
|
|
2609 /* progress gauge */
|
|
2610 INITIALIZE_DEVICE_IIFORMAT (gtk, progress_gauge);
|
|
2611 IIFORMAT_HAS_DEVMETHOD (gtk, progress_gauge, redisplay);
|
|
2612 IIFORMAT_HAS_DEVMETHOD (gtk, progress_gauge, instantiate);
|
|
2613 /* text field */
|
|
2614 INITIALIZE_DEVICE_IIFORMAT (gtk, edit_field);
|
|
2615 IIFORMAT_HAS_DEVMETHOD (gtk, edit_field, instantiate);
|
|
2616 INITIALIZE_DEVICE_IIFORMAT (gtk, combo_box);
|
|
2617 IIFORMAT_HAS_DEVMETHOD (gtk, combo_box, instantiate);
|
|
2618 IIFORMAT_HAS_SHARED_DEVMETHOD (gtk, combo_box, redisplay, tab_control);
|
|
2619 /* tab control widget */
|
|
2620 INITIALIZE_DEVICE_IIFORMAT (gtk, tab_control);
|
|
2621 IIFORMAT_HAS_DEVMETHOD (gtk, tab_control, instantiate);
|
|
2622 IIFORMAT_HAS_DEVMETHOD (gtk, tab_control, redisplay);
|
|
2623 /* label */
|
|
2624 INITIALIZE_DEVICE_IIFORMAT (gtk, label);
|
|
2625 IIFORMAT_HAS_DEVMETHOD (gtk, label, instantiate);
|
|
2626 #endif
|
|
2627
|
|
2628 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (cursor_font, "cursor-font");
|
|
2629 IIFORMAT_VALID_CONSOLE (gtk, cursor_font);
|
|
2630
|
|
2631 IIFORMAT_HAS_METHOD (cursor_font, validate);
|
|
2632 IIFORMAT_HAS_METHOD (cursor_font, possible_dest_types);
|
|
2633 IIFORMAT_HAS_METHOD (cursor_font, instantiate);
|
|
2634
|
|
2635 IIFORMAT_VALID_KEYWORD (cursor_font, Q_data, check_valid_string);
|
|
2636 IIFORMAT_VALID_KEYWORD (cursor_font, Q_foreground, check_valid_string);
|
|
2637 IIFORMAT_VALID_KEYWORD (cursor_font, Q_background, check_valid_string);
|
|
2638
|
|
2639 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (font, "font");
|
|
2640 IIFORMAT_VALID_CONSOLE (gtk, font);
|
|
2641
|
|
2642 IIFORMAT_HAS_METHOD (font, validate);
|
|
2643 IIFORMAT_HAS_METHOD (font, possible_dest_types);
|
|
2644 IIFORMAT_HAS_METHOD (font, instantiate);
|
|
2645
|
|
2646 IIFORMAT_VALID_KEYWORD (font, Q_data, check_valid_string);
|
|
2647 IIFORMAT_VALID_KEYWORD (font, Q_foreground, check_valid_string);
|
|
2648 IIFORMAT_VALID_KEYWORD (font, Q_background, check_valid_string);
|
|
2649
|
|
2650 #ifdef HAVE_XPM
|
|
2651 INITIALIZE_DEVICE_IIFORMAT (gtk, xpm);
|
|
2652 IIFORMAT_HAS_DEVMETHOD (gtk, xpm, instantiate);
|
|
2653 #endif
|
|
2654
|
|
2655 #ifdef HAVE_XFACE
|
|
2656 INITIALIZE_DEVICE_IIFORMAT (gtk, xface);
|
|
2657 IIFORMAT_HAS_DEVMETHOD (gtk, xface, instantiate);
|
|
2658 #endif
|
|
2659
|
|
2660 INITIALIZE_DEVICE_IIFORMAT (gtk, xbm);
|
|
2661 IIFORMAT_HAS_DEVMETHOD (gtk, xbm, instantiate);
|
|
2662 IIFORMAT_VALID_CONSOLE (gtk, xbm);
|
|
2663
|
|
2664 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (gtk_resource, "gtk-resource");
|
|
2665 IIFORMAT_VALID_CONSOLE (gtk, gtk_resource);
|
|
2666
|
|
2667 IIFORMAT_HAS_METHOD (gtk_resource, validate);
|
|
2668 IIFORMAT_HAS_METHOD (gtk_resource, normalize);
|
|
2669 IIFORMAT_HAS_METHOD (gtk_resource, possible_dest_types);
|
|
2670 IIFORMAT_HAS_METHOD (gtk_resource, instantiate);
|
|
2671
|
|
2672 IIFORMAT_VALID_KEYWORD (gtk_resource, Q_resource_type, check_valid_resource_symbol);
|
|
2673 IIFORMAT_VALID_KEYWORD (gtk_resource, Q_resource_id, check_valid_resource_id);
|
|
2674 IIFORMAT_VALID_KEYWORD (gtk_resource, Q_file, check_valid_string);
|
|
2675
|
|
2676 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (autodetect, "autodetect");
|
|
2677 IIFORMAT_VALID_CONSOLE (gtk, autodetect);
|
|
2678
|
|
2679 IIFORMAT_HAS_METHOD (autodetect, validate);
|
|
2680 IIFORMAT_HAS_METHOD (autodetect, normalize);
|
|
2681 IIFORMAT_HAS_METHOD (autodetect, possible_dest_types);
|
|
2682 IIFORMAT_HAS_METHOD (autodetect, instantiate);
|
|
2683
|
|
2684 IIFORMAT_VALID_KEYWORD (autodetect, Q_data, check_valid_string);
|
|
2685 }
|
|
2686
|
|
2687 void
|
|
2688 vars_of_glyphs_gtk (void)
|
|
2689 {
|
|
2690 #ifdef HAVE_XFACE
|
|
2691 Fprovide (Qxface);
|
|
2692 #endif
|
|
2693
|
|
2694 DEFVAR_LISP ("gtk-bitmap-file-path", &Vgtk_bitmap_file_path /*
|
|
2695 A list of the directories in which X bitmap files may be found.
|
|
2696 If nil, this is initialized from the "*bitmapFilePath" resource.
|
|
2697 This is used by the `make-image-instance' function (however, note that if
|
|
2698 the environment variable XBMLANGPATH is set, it is consulted first).
|
|
2699 */ );
|
|
2700 Vgtk_bitmap_file_path = Qnil;
|
|
2701 }
|
|
2702
|
|
2703 void
|
|
2704 complex_vars_of_glyphs_gtk (void)
|
|
2705 {
|
|
2706 #define BUILD_GLYPH_INST(variable, name) \
|
|
2707 Fadd_spec_to_specifier \
|
|
2708 (GLYPH_IMAGE (XGLYPH (variable)), \
|
|
2709 vector3 (Qxbm, Q_data, \
|
|
2710 list3 (make_int (name##_width), \
|
|
2711 make_int (name##_height), \
|
|
2712 make_ext_string (name##_bits, \
|
|
2713 sizeof (name##_bits), \
|
|
2714 Qbinary))), \
|
|
2715 Qglobal, Qgtk, Qnil)
|
|
2716
|
|
2717 BUILD_GLYPH_INST (Vtruncation_glyph, truncator);
|
|
2718 BUILD_GLYPH_INST (Vcontinuation_glyph, continuer);
|
|
2719 BUILD_GLYPH_INST (Vxemacs_logo, xemacs);
|
|
2720 BUILD_GLYPH_INST (Vhscroll_glyph, hscroll);
|
|
2721
|
|
2722 #undef BUILD_GLYPH_INST
|
|
2723 }
|
|
2724
|
|
2725 /* X specific crap */
|
|
2726 #include <gdk/gdkx.h>
|
|
2727 /* #### Should remove all this X specific stuff when GTK/GDK matures a
|
|
2728 bit more and provides an abstraction for it. */
|
|
2729 static int
|
|
2730 gtk_colorize_image_instance (Lisp_Object image_instance,
|
|
2731 Lisp_Object foreground, Lisp_Object background)
|
|
2732 {
|
|
2733 struct Lisp_Image_Instance *p;
|
|
2734
|
|
2735 p = XIMAGE_INSTANCE (image_instance);
|
|
2736
|
|
2737 switch (IMAGE_INSTANCE_TYPE (p))
|
|
2738 {
|
|
2739 case IMAGE_MONO_PIXMAP:
|
|
2740 IMAGE_INSTANCE_TYPE (p) = IMAGE_COLOR_PIXMAP;
|
|
2741 /* Make sure there aren't two pointers to the same mask, causing
|
|
2742 it to get freed twice. */
|
|
2743 IMAGE_INSTANCE_GTK_MASK (p) = 0;
|
|
2744 break;
|
|
2745
|
|
2746 default:
|
|
2747 return 0;
|
|
2748 }
|
|
2749
|
|
2750 {
|
|
2751 GdkWindow *draw = GET_GTK_WIDGET_WINDOW (DEVICE_GTK_APP_SHELL (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
2752 GdkPixmap *new_pxmp = gdk_pixmap_new (draw,
|
|
2753 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2754 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2755 DEVICE_GTK_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p))));
|
|
2756 GdkGCValues gcv;
|
|
2757 GdkGC *gc;
|
|
2758
|
|
2759 gcv.foreground = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (foreground));
|
|
2760 gcv.background = * COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (background));
|
|
2761 gc = gdk_gc_new_with_values (new_pxmp, &gcv, GDK_GC_BACKGROUND | GDK_GC_FOREGROUND);
|
|
2762
|
|
2763 XCopyPlane (GDK_WINDOW_XDISPLAY (draw),
|
|
2764 GDK_WINDOW_XWINDOW (IMAGE_INSTANCE_GTK_PIXMAP (p)),
|
|
2765 GDK_WINDOW_XWINDOW (new_pxmp),
|
|
2766 GDK_GC_XGC (gc), 0, 0,
|
|
2767 IMAGE_INSTANCE_PIXMAP_WIDTH (p),
|
|
2768 IMAGE_INSTANCE_PIXMAP_HEIGHT (p),
|
|
2769 0, 0, 1);
|
|
2770
|
|
2771 gdk_gc_destroy (gc);
|
|
2772 IMAGE_INSTANCE_GTK_PIXMAP (p) = new_pxmp;
|
|
2773 IMAGE_INSTANCE_PIXMAP_DEPTH (p) = DEVICE_GTK_DEPTH (XDEVICE (IMAGE_INSTANCE_DEVICE (p)));
|
|
2774 IMAGE_INSTANCE_PIXMAP_FG (p) = foreground;
|
|
2775 IMAGE_INSTANCE_PIXMAP_BG (p) = background;
|
|
2776 return 1;
|
|
2777 }
|
|
2778 }
|
|
2779
|