]> Pileus Git - ~andy/gtk/commitdiff
Pixmaps now grey out when insensitive, code thanks to GNOME stock by
authorCST 1998 Shawn T. Amundson <amundson@gtk.org>
Tue, 17 Nov 1998 01:34:07 +0000 (01:34 +0000)
committerShawn Amundson <amundson@src.gnome.org>
Tue, 17 Nov 1998 01:34:07 +0000 (01:34 +0000)
Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>

        * gtk/gtkpixmap.h
          gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
          code thanks to GNOME stock by Eckehard Berns.  New function
          gtk_pixmap_set_build_insensitive to provide ability to turn
          this off.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkpixmap.c
gtk/gtkpixmap.h

index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 45054c9c6bbc8547a20c10473f2098311e87854d..35e9a4b802e49f5977dda6418ee21d5c0a9706a9 100644 (file)
@@ -1,3 +1,11 @@
+Mon Nov 16 19:19:00 CST 1998 Shawn T. Amundson <amundson@gtk.org>
+
+       * gtk/gtkpixmap.h
+         gtk/gtkpixmap.c: Pixmaps now grey out when insensitive,
+         code thanks to GNOME stock by Eckehard Berns.  New function
+         gtk_pixmap_set_build_insensitive to provide ability to turn 
+         this off.
+
 Tue Nov 17 00:06:29 1998  Lars Hamann  <lars@gtk.org>
 
        * gtk/gtknotebook.h (struct _GtkNotebook): new flags : homogeneous;
index 9cc6ec007676ef55c2de436ca15f7be21df17650..e38bd8d8078021147f2cf78ebf6973bc2b392da3 100644 (file)
@@ -1,6 +1,9 @@
 /* GTK - The GIMP Toolkit
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
+ * Insensitive pixmap building code by Eckehard Berns from GNOME Stock
+ * Copyright (C) 1997, 1998 Free Software Foundation
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
@@ -25,6 +28,7 @@ static void gtk_pixmap_init       (GtkPixmap       *pixmap);
 static gint gtk_pixmap_expose     (GtkWidget       *widget,
                                   GdkEventExpose  *event);
 static void gtk_pixmap_finalize   (GtkObject       *object);
+static void build_insensitive_pixmap (GtkPixmap *gtkpixmap);
 
 static GtkWidgetClass *parent_class;
 
@@ -86,6 +90,7 @@ gtk_pixmap_new (GdkPixmap *val,
   
   pixmap = gtk_type_new (gtk_pixmap_get_type ());
   
+  pixmap->build_insensitive = TRUE;
   gtk_pixmap_set (pixmap, val, mask);
   
   return GTK_WIDGET (pixmap);
@@ -117,7 +122,10 @@ gtk_pixmap_set (GtkPixmap *pixmap,
       oldheight = GTK_WIDGET (pixmap)->requisition.height;
       if (pixmap->pixmap)
        gdk_pixmap_unref (pixmap->pixmap);
+      if (pixmap->pixmap_insensitive)
+       gdk_pixmap_unref (pixmap->pixmap_insensitive);
       pixmap->pixmap = val;
+      pixmap->pixmap_insensitive = NULL;
       if (pixmap->pixmap)
        {
          gdk_pixmap_ref (pixmap->pixmap);
@@ -166,7 +174,6 @@ gtk_pixmap_get (GtkPixmap  *pixmap,
     *mask = pixmap->mask;
 }
 
-
 static gint
 gtk_pixmap_expose (GtkWidget      *widget,
                   GdkEventExpose *event)
@@ -199,10 +206,23 @@ gtk_pixmap_expose (GtkWidget      *widget,
          gdk_gc_set_clip_origin (widget->style->black_gc, x, y);
        }
 
-      gdk_draw_pixmap (widget->window,
-                      widget->style->black_gc,
-                      pixmap->pixmap,
-                      0, 0, x, y, -1, -1);
+      if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE
+          && pixmap->build_insensitive)
+        {
+         if (!pixmap->pixmap_insensitive)
+           build_insensitive_pixmap (pixmap);
+          gdk_draw_pixmap (widget->window,
+                          widget->style->black_gc,
+                          pixmap->pixmap_insensitive,
+                          0, 0, x, y, -1, -1);
+        }
+      else
+       {
+          gdk_draw_pixmap (widget->window,
+                          widget->style->black_gc,
+                          pixmap->pixmap,
+                          0, 0, x, y, -1, -1);
+       }
 
       if (pixmap->mask)
        {
@@ -212,3 +232,94 @@ gtk_pixmap_expose (GtkWidget      *widget,
     }
   return FALSE;
 }
+
+void
+gtk_pixmap_set_build_insensitive (GtkPixmap *pixmap, guint build)
+{
+  g_return_if_fail (pixmap != NULL);
+  g_return_if_fail (GTK_IS_PIXMAP (pixmap));
+
+  pixmap->build_insensitive = build;
+
+  if (GTK_WIDGET_VISIBLE (pixmap))
+    {
+      gtk_widget_queue_clear (GTK_WIDGET (pixmap));
+    }
+}
+
+static void
+build_insensitive_pixmap(GtkPixmap *gtkpixmap)
+{
+  GdkGC *gc;
+  GdkPixmap *pixmap = gtkpixmap->pixmap;
+  GdkPixmap *insensitive;
+  gint w, h, x, y;
+  GdkGCValues vals;
+  GdkVisual *visual;
+  GdkImage *image;
+  GdkColorContext *cc;
+  GdkColor color;
+  GdkColormap *cmap;
+  gint32 red, green, blue;
+  GtkStyle *style;
+  GtkWidget *window;
+
+  window = GTK_WIDGET (gtkpixmap);
+
+  g_return_if_fail(window != NULL);
+
+  gdk_window_get_size(pixmap, &w, &h);
+  visual = gtk_widget_get_visual(GTK_WIDGET(gtkpixmap));
+  cmap = gtk_widget_get_colormap(GTK_WIDGET(gtkpixmap));
+  gc = gdk_gc_new (pixmap);
+
+  cc = gdk_color_context_new(visual, cmap);
+  if ((cc->mode != GDK_CC_MODE_TRUE) && (cc->mode != GDK_CC_MODE_MY_GRAY)) 
+    {
+      gdk_color_context_free(cc);
+      style = gtk_widget_get_style(window);
+      color = style->bg[0];
+      gdk_gc_set_foreground (gc, &color);
+      for (y = 0; y < h; y ++) 
+        {
+          for (x = y % 2; x < w; x += 2) 
+           {
+              gdk_draw_point(pixmap, gc, x, y);
+            }
+        }
+                gdk_gc_destroy(gc);
+                return;
+     }
+
+   image = gdk_image_get(pixmap, 0, 0, w, h);
+   gdk_gc_get_values(gc, &vals);
+   style = gtk_widget_get_style(window);
+   color = style->bg[0];
+   red = color.red;
+   green = color.green;
+   blue = color.blue;
+   for (y = 0; y < h; y++) 
+     {
+       for (x = 0; x < w; x++) 
+         {
+           GdkColor c;
+           int failed;
+           c.pixel = gdk_image_get_pixel(image, x, y);
+           gdk_color_context_query_color(cc, &c);
+           c.red = (((gint32)c.red - red) >> 1) + red;
+           c.green = (((gint32)c.green - green) >> 1) + green;
+           c.blue = (((gint32)c.blue - blue) >> 1) + blue;
+           c.pixel = gdk_color_context_get_pixel(cc, c.red, c.green, c.blue,
+                                                 &failed);
+           gdk_image_put_pixel(image, x, y, c.pixel);
+         }
+     }
+     insensitive = gdk_pixmap_new(GTK_WIDGET (gtkpixmap)->window, w, h, -1);
+     gdk_draw_image(insensitive, gc, image, 0, 0, 0, 0, w, h);
+     gtkpixmap->pixmap_insensitive = insensitive;
+     gdk_image_destroy(image);
+     gdk_gc_destroy(gc);
+     gdk_color_context_free(cc);
+}
+
+
index 1694579ab47e27eb25566a7a83a8423eaba7b9a5..9f97f5a2e18a8f6c01ca4f74a794c164cf1e1f3e 100644 (file)
@@ -45,6 +45,9 @@ struct _GtkPixmap
   
   GdkPixmap *pixmap;
   GdkBitmap *mask;
+
+  GdkPixmap *pixmap_insensitive;
+  guint build_insensitive : 1;
 };
 
 struct _GtkPixmapClass
@@ -63,6 +66,9 @@ void     gtk_pixmap_get        (GtkPixmap  *pixmap,
                                  GdkPixmap **val,
                                  GdkBitmap **mask);
 
+void       gtk_pixmap_set_build_insensitive (GtkPixmap *pixmap,
+                                            guint build);
+
 
 #ifdef __cplusplus
 }