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