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