comparison src/gtkutil.c @ 56112:e4cfda8330d5

* gtkutil.c (xg_get_image_for_pixmap): New function. (xg_get_gdk_pixmap_and_mask): Removed. (update_frame_tool_bar): Call xg_get_image_for_pixmap instead of xg_get_gdk_pixmap_and_mask.
author Jan Djärv <jan.h.d@swipnet.se>
date Mon, 14 Jun 2004 21:53:24 +0000
parents 44d086f5e08a
children 9853134cd610 4c90ffeb71c5
comparison
equal deleted inserted replaced
56111:54633f72f8db 56112:e4cfda8330d5
227 { 227 {
228 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy); 228 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (dpy);
229 return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR); 229 return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR);
230 } 230 }
231 231
232 /* For the image defined in IMG, make and return a GdkPixmap for 232 /* 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. 233 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. 234 Otherwise the highlightning and dimming the tool bar code in GTK does
235 The image is defined on the display where frame F is. */ 235 will look bad. For display with more than 8 planes we just use the
236 static void 236 pixmap and mask directly. For monochrome displays, GTK doesn't seem
237 xg_get_gdk_pixmap_and_mask (f, img, gpix, gmask) 237 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)
238 FRAME_PTR f; 244 FRAME_PTR f;
239 struct image *img; 245 struct image *img;
240 GdkPixmap **gpix; 246 GtkWidget *widget;
241 GdkBitmap **gmask; 247 GtkImage *old_widget;
242 { 248 {
249 GdkPixmap *gpix;
250 GdkPixmap *gmask;
243 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); 251 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
244 252
245 *gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap); 253 gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap);
246 *gmask = img->mask ? 254 gmask = img->mask ? gdk_pixmap_foreign_new_for_display (gdpy, img->mask) : 0;
247 (GdkBitmap*) gdk_pixmap_foreign_new_for_display (gdpy, img->mask) 255
248 : 0; 256 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);
249 } 326 }
250 327
251 328
252 /* Set CURSOR on W and all widgets W contain. We must do like this 329 /* Set CURSOR on W and all widgets W contain. We must do like this
253 for scroll bars and menu because they create widgets internally, 330 for scroll bars and menu because they create widgets internally,
3203 continue; 3280 continue;
3204 } 3281 }
3205 3282
3206 if (! wicon) 3283 if (! wicon)
3207 { 3284 {
3208 GdkPixmap *gpix; 3285 GtkWidget *w = xg_get_image_for_pixmap (f, img, x->widget, NULL);
3209 GdkBitmap *gmask; 3286
3210 GtkWidget *w;
3211
3212 xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask);
3213 w = gtk_image_new_from_pixmap (gpix, gmask);
3214 gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget), 3287 gtk_toolbar_append_item (GTK_TOOLBAR (x->toolbar_widget),
3215 0, 0, 0, 3288 0, 0, 0,
3216 w, 3289 w,
3217 GTK_SIGNAL_FUNC (xg_tool_bar_callback), 3290 GTK_SIGNAL_FUNC (xg_tool_bar_callback),
3218 (gpointer)i); 3291 (gpointer)i);
3265 Pixmap old_img = (Pixmap)g_object_get_data (G_OBJECT (wimage), 3338 Pixmap old_img = (Pixmap)g_object_get_data (G_OBJECT (wimage),
3266 XG_TOOL_BAR_IMAGE_DATA); 3339 XG_TOOL_BAR_IMAGE_DATA);
3267 g_list_free (chlist); 3340 g_list_free (chlist);
3268 3341
3269 if (old_img != img->pixmap) 3342 if (old_img != img->pixmap)
3270 { 3343 (void) xg_get_image_for_pixmap (f, img, x->widget, wimage);
3271 GdkPixmap *gpix;
3272 GdkBitmap *gmask;
3273
3274 xg_get_gdk_pixmap_and_mask (f, img, &gpix, &gmask);
3275 gtk_image_set_from_pixmap (wimage, gpix, gmask);
3276 }
3277 3344
3278 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, 3345 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA,
3279 (gpointer)img->pixmap); 3346 (gpointer)img->pixmap);
3280 3347
3281 gtk_widget_set_sensitive (wicon, enabled_p); 3348 gtk_widget_set_sensitive (wicon, enabled_p);