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