229 |
return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR); |
return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR); |
230 |
} |
} |
231 |
|
|
232 |
/* For the image defined in IMG, make and return a GdkPixmap for |
/* For the image defined in IMG, make and return a GtkImage. For displays with |
233 |
the pixmap in *GPIX, and a GdkBitmap for the mask in *GMASK. |
8 planes or less we must make a GdkPixbuf and apply the mask manually. |
234 |
If IMG has no mask, *GMASK is set to NULL. |
Otherwise the highlightning and dimming the tool bar code in GTK does |
235 |
The image is defined on the display where frame F is. */ |
will look bad. For display with more than 8 planes we just use the |
236 |
static void |
pixmap and mask directly. For monochrome displays, GTK doesn't seem |
237 |
xg_get_gdk_pixmap_and_mask (f, img, gpix, gmask) |
able to use external pixmaps, it looks bad whatever we do. |
238 |
|
The image is defined on the display where frame F is. |
239 |
|
WIDGET is used to find the GdkColormap to use for the GdkPixbuf. |
240 |
|
If OLD_WIDGET is NULL, a new widget is constructed and returned. |
241 |
|
If OLD_WIDGET is not NULL, that widget is modified. */ |
242 |
|
static GtkWidget * |
243 |
|
xg_get_image_for_pixmap (f, img, widget, old_widget) |
244 |
FRAME_PTR f; |
FRAME_PTR f; |
245 |
struct image *img; |
struct image *img; |
246 |
GdkPixmap **gpix; |
GtkWidget *widget; |
247 |
GdkBitmap **gmask; |
GtkImage *old_widget; |
248 |
{ |
{ |
249 |
|
GdkPixmap *gpix; |
250 |
|
GdkPixmap *gmask; |
251 |
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); |
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); |
252 |
|
|
253 |
*gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap); |
gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap); |
254 |
*gmask = img->mask ? |
gmask = img->mask ? gdk_pixmap_foreign_new_for_display (gdpy, img->mask) : 0; |
255 |
(GdkBitmap*) gdk_pixmap_foreign_new_for_display (gdpy, img->mask) |
|
256 |
: 0; |
if (x_screen_planes (f) > 8 || x_screen_planes (f) == 1) |
257 |
|
{ |
258 |
|
if (! old_widget) |
259 |
|
old_widget = GTK_IMAGE (gtk_image_new_from_pixmap (gpix, gmask)); |
260 |
|
else |
261 |
|
gtk_image_set_from_pixmap (old_widget, gpix, gmask); |
262 |
|
} |
263 |
|
else |
264 |
|
{ |
265 |
|
int x, y, width, height, rowstride, mask_rowstride; |
266 |
|
GdkPixbuf *icon_buf, *tmp_buf; |
267 |
|
guchar *pixels; |
268 |
|
guchar *mask_pixels; |
269 |
|
|
270 |
|
gdk_drawable_get_size (gpix, &width, &height); |
271 |
|
tmp_buf = gdk_pixbuf_get_from_drawable (NULL, |
272 |
|
gpix, |
273 |
|
gtk_widget_get_colormap (widget), |
274 |
|
0, 0, 0, 0, width, height); |
275 |
|
icon_buf = gdk_pixbuf_add_alpha (tmp_buf, FALSE, 0, 0, 0); |
276 |
|
g_object_unref (G_OBJECT (tmp_buf)); |
277 |
|
|
278 |
|
if (gmask) |
279 |
|
{ |
280 |
|
GdkPixbuf *mask_buf = gdk_pixbuf_get_from_drawable (NULL, |
281 |
|
gmask, |
282 |
|
NULL, |
283 |
|
0, 0, 0, 0, |
284 |
|
width, height); |
285 |
|
guchar *pixels = gdk_pixbuf_get_pixels (icon_buf); |
286 |
|
guchar *mask_pixels = gdk_pixbuf_get_pixels (mask_buf); |
287 |
|
int rowstride = gdk_pixbuf_get_rowstride (icon_buf); |
288 |
|
int mask_rowstride = gdk_pixbuf_get_rowstride (mask_buf); |
289 |
|
int y; |
290 |
|
|
291 |
|
for (y = 0; y < height; ++y) |
292 |
|
{ |
293 |
|
guchar *iconptr, *maskptr; |
294 |
|
int x; |
295 |
|
|
296 |
|
iconptr = pixels + y * rowstride; |
297 |
|
maskptr = mask_pixels + y * mask_rowstride; |
298 |
|
|
299 |
|
for (x = 0; x < width; ++x) |
300 |
|
{ |
301 |
|
/* In a bitmap, RGB is either 255/255/255 or 0/0/0. Checking |
302 |
|
just R is sufficient. */ |
303 |
|
if (maskptr[0] == 0) |
304 |
|
iconptr[3] = 0; /* 0, 1, 2 is R, G, B. 3 is alpha. */ |
305 |
|
|
306 |
|
iconptr += rowstride/width; |
307 |
|
maskptr += mask_rowstride/width; |
308 |
|
} |
309 |
|
} |
310 |
|
|
311 |
|
g_object_unref (G_OBJECT (gmask)); |
312 |
|
g_object_unref (G_OBJECT (mask_buf)); |
313 |
|
} |
314 |
|
|
315 |
|
g_object_unref (G_OBJECT (gpix)); |
316 |
|
|
317 |
|
if (! old_widget) |
318 |
|
old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf)); |
319 |
|
else |
320 |
|
gtk_image_set_from_pixbuf (old_widget, icon_buf); |
321 |
|
|
322 |
|
g_object_unref (G_OBJECT (icon_buf)); |
323 |
|
} |
324 |
|
|
325 |
|
return GTK_WIDGET (old_widget); |
326 |
} |
} |
327 |
|
|
328 |
|
|
3282 |
|
|
3283 |
if (! wicon) |
if (! wicon) |
3284 |
{ |
{ |
3285 |
GdkPixmap *gpix; |
GtkWidget *w = xg_get_image_for_pixmap (f, img, x->widget, NULL); |
|
GdkBitmap *gmask; |
|
|
GtkWidget *w; |
|
3286 |
|
|
|
xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask); |
|
|
w = gtk_image_new_from_pixmap (gpix, gmask); |
|
3287 |
gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget), |
gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget), |
3288 |
0, 0, 0, |
0, 0, 0, |
3289 |
w, |
w, |
3340 |
g_list_free (chlist); |
g_list_free (chlist); |
3341 |
|
|
3342 |
if (old_img != img->pixmap) |
if (old_img != img->pixmap) |
3343 |
{ |
(void) xg_get_image_for_pixmap (f, img, x->widget, wimage); |
|
GdkPixmap *gpix; |
|
|
GdkBitmap *gmask; |
|
|
|
|
|
xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask); |
|
|
gtk_image_set_from_pixmap (wimage, gpix, gmask); |
|
|
} |
|
3344 |
|
|
3345 |
g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, |
g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, |
3346 |
(gpointer)img->pixmap); |
(gpointer)img->pixmap); |