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