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