aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2004-06-14 21:53:24 +0000
committerJan Djärv2004-06-14 21:53:24 +0000
commit5b1663230680f970f46341e6d8aa43121645816c (patch)
tree0d6c307545b62e58bb975abdcee39cc2ffa68390 /src
parent2f4a048d1ba9ef381d87fbe612bf95fc8afde39d (diff)
downloademacs-5b1663230680f970f46341e6d8aa43121645816c.tar.gz
emacs-5b1663230680f970f46341e6d8aa43121645816c.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/gtkutil.c115
2 files changed, 100 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 15ee5ed4585..e4bcca81ede 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12004-06-14 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2
3 * gtkutil.c (xg_get_image_for_pixmap): New function.
4 (xg_get_gdk_pixmap_and_mask): Removed.
5 (update_frame_tool_bar): Call xg_get_image_for_pixmap instead of
6 xg_get_gdk_pixmap_and_mask.
7
8 * xterm.h (struct x_display_info): Typo in comment fixed.
9
12004-06-14 Juanma Barranquero <lektu@terra.es> 102004-06-14 Juanma Barranquero <lektu@terra.es>
2 11
3 * dispextern.h (Vimage_types): Make it conditional on 12 * dispextern.h (Vimage_types): Make it conditional on
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 82d5135d2bc..84aa9f46d4d 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -229,23 +229,100 @@ xg_create_default_cursor (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
236static void 236 pixmap and mask directly. For monochrome displays, GTK doesn't seem
237xg_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. */
242static GtkWidget *
243xg_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
@@ -3205,12 +3282,8 @@ update_frame_tool_bar (f)
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;
3210 GtkWidget *w;
3211 3286
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,
@@ -3267,13 +3340,7 @@ update_frame_tool_bar (f)
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);