[gtk+/rendering-cleanup: 10/30] widget: shape_combine_mask => shape_cobine_region



commit 19997ea6f43f3e5f5c1c7d68b07f3b797acf6d8c
Author: Benjamin Otte <otte redhat com>
Date:   Sat Aug 14 06:38:11 2010 +0200

    widget: shape_combine_mask => shape_cobine_region
    
    Replace gtk_widget_shape_combine_region() with
    gtk_widget_shape_combine_mask() and
    gtk_widget_input_shape_combine_region() with
    gtk_widget_input_shape_combine_mask().
    As GdkBitmap is going away, and the region equivalents already exist,
    this seems like pretty much the default step to take.
    
    Includes code to fix up the users.

 docs/reference/gtk/gtk3-sections.txt |    4 +-
 gtk/gtk.symbols                      |    4 +-
 gtk/gtkdnd.c                         |   25 ++++++++-
 gtk/gtkwidget.c                      |  100 +++++++++++-----------------------
 gtk/gtkwidget.h                      |   22 ++------
 tests/testgtk.c                      |   25 ++++++---
 6 files changed, 81 insertions(+), 99 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 90cea58..f4a285a 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -4833,8 +4833,8 @@ GtkTextDirection
 gtk_widget_get_direction
 gtk_widget_set_default_direction
 gtk_widget_get_default_direction
-gtk_widget_shape_combine_mask
-gtk_widget_input_shape_combine_mask
+gtk_widget_shape_combine_region
+gtk_widget_input_shape_combine_region
 gtk_widget_path
 gtk_widget_class_path
 gtk_widget_get_composite_name
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 8c46dec..ba2faf5 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -4454,8 +4454,8 @@ gtk_widget_set_tooltip_text
 gtk_widget_set_tooltip_window
 gtk_widget_set_visible
 gtk_widget_set_window
-gtk_widget_shape_combine_mask
-gtk_widget_input_shape_combine_mask
+gtk_widget_shape_combine_region
+gtk_widget_input_shape_combine_region
 gtk_widget_show
 gtk_widget_show_all
 gtk_widget_show_now
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 78f63c1..94913e4 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -3133,8 +3133,16 @@ icon_window_realize (GtkWidget *window,
   
   if (mask)
     {
-      gtk_widget_shape_combine_mask (window, mask, 0, 0);
-      g_object_unref (mask);
+      cairo_region_t *region;
+      cairo_t *cr;
+
+      /* XXX: Clean this up properly */
+      cr = gdk_cairo_create (mask);
+      region = gdk_cairo_region_create_from_surface (cairo_get_target (cr));
+      cairo_destroy (cr);
+
+      gtk_widget_shape_combine_region (window, region);
+      cairo_region_destroy (region);
     }
 }
 
@@ -3320,7 +3328,18 @@ gtk_drag_set_icon_pixmap (GdkDragContext    *context,
   gdk_window_set_back_pixmap (window->window, pixmap, FALSE);
   
   if (mask)
-    gtk_widget_shape_combine_mask (window, mask, 0, 0);
+    {
+      cairo_region_t *region;
+      cairo_t *cr;
+
+      /* XXX: Clean this up properly */
+      cr = gdk_cairo_create (mask);
+      region = gdk_cairo_region_create_from_surface (cairo_get_target (cr));
+      cairo_destroy (cr);
+
+      gtk_widget_shape_combine_region (window, region);
+      cairo_region_destroy (region);
+    }
 
   gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
 }
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index a859bf2..ad214bf 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3529,7 +3529,7 @@ void
 gtk_widget_realize (GtkWidget *widget)
 {
   GdkExtensionMode mode;
-  GtkWidgetShapeInfo *shape_info;
+  cairo_region_t *region;
   
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
@@ -3561,19 +3561,13 @@ gtk_widget_realize (GtkWidget *widget)
 
       if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
 	{
-	  shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
-	  gdk_window_shape_combine_mask (widget->window,
-					 shape_info->shape_mask,
-					 shape_info->offset_x,
-					 shape_info->offset_y);
+	  region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
+	  gdk_window_shape_combine_region (widget->window, region, 0, 0);
 	}
       
-      shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
-      if (shape_info)
-	gdk_window_input_shape_combine_mask (widget->window,
-					     shape_info->shape_mask,
-					     shape_info->offset_x,
-					     shape_info->offset_y);
+      region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
+      if (region)
+	gdk_window_input_shape_combine_region (widget->window, region, 0, 0);
 
       mode = gtk_widget_get_extension_events (widget);
       if (mode != GDK_EXTENSION_EVENTS_NONE)
@@ -3600,10 +3594,10 @@ gtk_widget_unrealize (GtkWidget *widget)
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
-    gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
+    gtk_widget_shape_combine_region (widget, NULL);
 
   if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
-    gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
+    gtk_widget_input_shape_combine_region (widget, NULL);
 
   if (gtk_widget_get_realized (widget))
     {
@@ -9499,42 +9493,31 @@ gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
   g_slice_free (GtkWidgetAuxInfo, aux_info);
 }
 
-static void
-gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
-{
-  g_object_unref (info->shape_mask);
-  g_slice_free (GtkWidgetShapeInfo, info);
-}
-
 /**
- * gtk_widget_shape_combine_mask: 
+ * gtk_widget_shape_combine_region: 
  * @widget: a #GtkWidget
- * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
- * @offset_x: X position of shape mask with respect to @window
- * @offset_y: Y position of shape mask with respect to @window
+ * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
  * 
  * Sets a shape for this widget's GDK window. This allows for
- * transparent windows etc., see gdk_window_shape_combine_mask()
+ * transparent windows etc., see gdk_window_shape_combine_region()
  * for more information.
+ *
+ * Since: 3.0
  **/
 void
-gtk_widget_shape_combine_mask (GtkWidget *widget,
-			       GdkBitmap *shape_mask,
-			       gint	  offset_x,
-			       gint	  offset_y)
+gtk_widget_shape_combine_region (GtkWidget *widget,
+                                 cairo_region_t *region)
 {
-  GtkWidgetShapeInfo* shape_info;
-  
   g_return_if_fail (GTK_IS_WIDGET (widget));
   /*  set_shape doesn't work on widgets without gdk window */
   g_return_if_fail (gtk_widget_get_has_window (widget));
 
-  if (!shape_mask)
+  if (region == NULL)
     {
       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
       
       if (widget->window)
-	gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
+	gdk_window_shape_combine_region (widget->window, NULL, 0, 0);
       
       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
     }
@@ -9542,72 +9525,55 @@ gtk_widget_shape_combine_mask (GtkWidget *widget,
     {
       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
       
-      shape_info = g_slice_new (GtkWidgetShapeInfo);
-      g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
-			       (GDestroyNotify) gtk_widget_shape_info_destroy);
-      
-      shape_info->shape_mask = g_object_ref (shape_mask);
-      shape_info->offset_x = offset_x;
-      shape_info->offset_y = offset_y;
+      g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
+                               cairo_region_copy (region),
+			       (GDestroyNotify) cairo_region_destroy);
       
       /* set shape if widget has a gdk window already.
        * otherwise the shape is scheduled to be set by gtk_widget_realize().
        */
       if (widget->window)
-	gdk_window_shape_combine_mask (widget->window, shape_mask,
-				       offset_x, offset_y);
+	gdk_window_shape_combine_region (widget->window, region, 0, 0);
     }
 }
 
 /**
- * gtk_widget_input_shape_combine_mask:
+ * gtk_widget_input_shape_combine_region:
  * @widget: a #GtkWidget
- * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
- * @offset_x: X position of shape mask with respect to @window
- * @offset_y: Y position of shape mask with respect to @window
+ * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
  *
  * Sets an input shape for this widget's GDK window. This allows for
  * windows which react to mouse click in a nonrectangular region, see 
- * gdk_window_input_shape_combine_mask() for more information.
+ * gdk_window_input_shape_combine_region() for more information.
  *
- * Since: 2.10
+ * Since: 3.0
  **/
 void
-gtk_widget_input_shape_combine_mask (GtkWidget *widget,
-				     GdkBitmap *shape_mask,
-				     gint       offset_x,
-				     gint	offset_y)
+gtk_widget_input_shape_combine_region (GtkWidget *widget,
+                                       cairo_region_t *region)
 {
-  GtkWidgetShapeInfo* shape_info;
-  
   g_return_if_fail (GTK_IS_WIDGET (widget));
   /*  set_shape doesn't work on widgets without gdk window */
   g_return_if_fail (gtk_widget_get_has_window (widget));
 
-  if (!shape_mask)
+  if (region == NULL)
     {
       if (widget->window)
-	gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
+	gdk_window_input_shape_combine_region (widget->window, NULL, 0, 0);
       
       g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
     }
   else
     {
-      shape_info = g_slice_new (GtkWidgetShapeInfo);
       g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info, 
-			       shape_info,
-			       (GDestroyNotify) gtk_widget_shape_info_destroy);
-      
-      shape_info->shape_mask = g_object_ref (shape_mask);
-      shape_info->offset_x = offset_x;
-      shape_info->offset_y = offset_y;
+			       cairo_region_copy (region),
+			       (GDestroyNotify) cairo_region_destroy);
       
       /* set shape if widget has a gdk window already.
        * otherwise the shape is scheduled to be set by gtk_widget_realize().
        */
       if (widget->window)
-	gdk_window_input_shape_combine_mask (widget->window, shape_mask,
-					     offset_x, offset_y);
+	gdk_window_input_shape_combine_region (widget->window, region, 0, 0);
     }
 }
 
@@ -9623,7 +9589,7 @@ gtk_reset_shapes_recurse (GtkWidget *widget,
   if (data != widget)
     return;
 
-  gdk_window_shape_combine_mask (window, NULL, 0, 0);
+  gdk_window_shape_combine_region (window, NULL, 0, 0);
   for (list = gdk_window_peek_children (window); list; list = list->next)
     gtk_reset_shapes_recurse (widget, list->data);
 }
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 0bae2c6..a4be13e 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -198,7 +198,6 @@ typedef struct _GtkRequisition	   GtkRequisition;
 typedef struct _GtkSelectionData   GtkSelectionData;
 typedef struct _GtkWidgetClass	   GtkWidgetClass;
 typedef struct _GtkWidgetAuxInfo   GtkWidgetAuxInfo;
-typedef struct _GtkWidgetShapeInfo GtkWidgetShapeInfo;
 typedef struct _GtkClipboard	   GtkClipboard;
 typedef struct _GtkTooltip         GtkTooltip;
 typedef struct _GtkWindow          GtkWindow;
@@ -544,13 +543,6 @@ struct _GtkWidgetAuxInfo
   guint y_set : 1;
 };
 
-struct _GtkWidgetShapeInfo
-{
-  gint16     offset_x;
-  gint16     offset_y;
-  GdkBitmap *shape_mask;
-};
-
 GType	   gtk_widget_get_type		  (void) G_GNUC_CONST;
 GtkWidget* gtk_widget_new		  (GType		type,
 					   const gchar	       *first_property_name,
@@ -907,16 +899,12 @@ GtkTextDirection gtk_widget_get_default_direction (void);
 /* Compositing manager functionality */
 gboolean gtk_widget_is_composited (GtkWidget *widget);
 
-/* Counterpart to gdk_window_shape_combine_mask.
+/* Counterpart to gdk_window_shape_combine_region.
  */
-void	     gtk_widget_shape_combine_mask (GtkWidget *widget,
-					    GdkBitmap *shape_mask,
-					    gint       offset_x,
-					    gint       offset_y);
-void	     gtk_widget_input_shape_combine_mask (GtkWidget *widget,
-						  GdkBitmap *shape_mask,
-						  gint       offset_x,
-						  gint       offset_y);
+void	     gtk_widget_shape_combine_region (GtkWidget *widget,
+                                              cairo_region_t *region);
+void	     gtk_widget_input_shape_combine_region (GtkWidget *widget,
+                                                    cairo_region_t *region);
 
 /* internal function */
 void	     gtk_widget_reset_shapes	   (GtkWidget *widget);
diff --git a/tests/testgtk.c b/tests/testgtk.c
index ceba195..ab02bf0 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -7257,8 +7257,10 @@ shape_create_icon (GdkScreen *screen,
   GtkWidget *image;
   GtkWidget *fixed;
   CursorOffset* icon_pos;
-  GdkBitmap *mask;
+  cairo_surface_t *mask;
+  cairo_region_t *mask_region;
   GdkPixbuf *pixbuf;
+  cairo_t *cr;
 
   /*
    * GDK_WINDOW_TOPLEVEL works also, giving you a title border
@@ -7282,19 +7284,26 @@ shape_create_icon (GdkScreen *screen,
   pixbuf = gdk_pixbuf_new_from_file (xpm_file, NULL);
   g_assert (pixbuf); /* FIXME: error handling */
 
-  gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf,
-                                                  gtk_widget_get_colormap (window),
-                                                  NULL,
-                                                  &mask,
-                                                  128);
+  mask = cairo_image_surface_create (CAIRO_FORMAT_A1,
+                                     gdk_pixbuf_get_width (pixbuf),
+                                     gdk_pixbuf_get_height (pixbuf));
+  cr = cairo_create (mask);
+  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+  cairo_paint (cr);
+  cairo_destroy (cr);
+
+  mask_region = gdk_cairo_region_create_from_surface (mask);
                                                   
+  cairo_region_translate (mask_region, px, py);
+
   image = gtk_image_new_from_pixbuf (pixbuf);
   gtk_fixed_put (GTK_FIXED (fixed), image, px,py);
   gtk_widget_show (image);
   
-  gtk_widget_shape_combine_mask (window, mask, px, py);
+  gtk_widget_shape_combine_region (window, mask_region);
   
-  g_object_unref (mask);
+  cairo_region_destroy (mask_region);
+  cairo_surface_destroy (mask);
   g_object_unref (pixbuf);
 
   g_signal_connect (window, "button_press_event",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]