248 |
{ |
{ |
249 |
GdkPixmap *gpix; |
GdkPixmap *gpix; |
250 |
GdkPixmap *gmask; |
GdkPixmap *gmask; |
251 |
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); |
GdkDisplay *gdpy; |
252 |
|
|
253 |
|
/* If we are on a one bit display, let GTK do all the image handling. |
254 |
|
This seems to be the only way to make insensitive and activated icons |
255 |
|
look good. */ |
256 |
|
if (x_screen_planes (f) == 1) |
257 |
|
{ |
258 |
|
Lisp_Object specified_file = Qnil; |
259 |
|
Lisp_Object tail; |
260 |
|
extern Lisp_Object QCfile; |
261 |
|
|
262 |
|
for (tail = XCDR (img->spec); |
263 |
|
NILP (specified_file) && CONSP (tail) && CONSP (XCDR (tail)); |
264 |
|
tail = XCDR (XCDR (tail))) |
265 |
|
if (EQ (XCAR (tail), QCfile)) |
266 |
|
specified_file = XCAR (XCDR (tail)); |
267 |
|
|
268 |
|
if (STRINGP (specified_file)) |
269 |
|
{ |
270 |
|
|
271 |
|
Lisp_Object file = Qnil; |
272 |
|
struct gcpro gcpro1; |
273 |
|
GCPRO1 (file); |
274 |
|
|
275 |
|
file = x_find_image_file (specified_file); |
276 |
|
/* We already loaded the image once before calling this |
277 |
|
function, so this should not fail. */ |
278 |
|
xassert (STRINGP (file) != 0); |
279 |
|
|
280 |
|
if (! old_widget) |
281 |
|
old_widget = GTK_IMAGE (gtk_image_new_from_file (SDATA (file))); |
282 |
|
else |
283 |
|
gtk_image_set_from_file (old_widget, SDATA (file)); |
284 |
|
|
285 |
|
UNGCPRO; |
286 |
|
return GTK_WIDGET (old_widget); |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); |
291 |
gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap); |
gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap); |
292 |
gmask = img->mask ? gdk_pixmap_foreign_new_for_display (gdpy, img->mask) : 0; |
gmask = img->mask ? gdk_pixmap_foreign_new_for_display (gdpy, img->mask) : 0; |
293 |
|
|
300 |
} |
} |
301 |
else |
else |
302 |
{ |
{ |
303 |
|
/* This is a workaround to make icons look good on pseudo color |
304 |
|
displays. Apparently GTK expects the images to have an alpha |
305 |
|
channel. If they don't, insensitive and activated icons will |
306 |
|
look bad. This workaround does not work on monochrome displays, |
307 |
|
and is not needed on true color/static color displays (i.e. |
308 |
|
16 bits and higher). */ |
309 |
int x, y, width, height, rowstride, mask_rowstride; |
int x, y, width, height, rowstride, mask_rowstride; |
310 |
GdkPixbuf *icon_buf, *tmp_buf; |
GdkPixbuf *icon_buf, *tmp_buf; |
311 |
guchar *pixels; |
guchar *pixels; |
352 |
} |
} |
353 |
} |
} |
354 |
|
|
|
g_object_unref (G_OBJECT (gmask)); |
|
355 |
g_object_unref (G_OBJECT (mask_buf)); |
g_object_unref (G_OBJECT (mask_buf)); |
356 |
} |
} |
357 |
|
|
|
g_object_unref (G_OBJECT (gpix)); |
|
|
|
|
358 |
if (! old_widget) |
if (! old_widget) |
359 |
old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf)); |
old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf)); |
360 |
else |
else |
363 |
g_object_unref (G_OBJECT (icon_buf)); |
g_object_unref (G_OBJECT (icon_buf)); |
364 |
} |
} |
365 |
|
|
366 |
|
g_object_unref (G_OBJECT (gpix)); |
367 |
|
if (gmask) g_object_unref (G_OBJECT (gmask)); |
368 |
|
|
369 |
return GTK_WIDGET (old_widget); |
return GTK_WIDGET (old_widget); |
370 |
} |
} |
371 |
|
|