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