[gtk+/rendering-cleanup: 33/141] widget: shape_combine_mask => shape_cobine_region
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/rendering-cleanup: 33/141] widget: shape_combine_mask => shape_cobine_region
- Date: Mon, 13 Sep 2010 23:47:39 +0000 (UTC)
commit a5b399ba150368ef23672d0659c4a10c2c74e6f5
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 | 102 ++++++++++++----------------------
gtk/gtkwidget.h | 22 ++------
tests/testgtk.c | 25 ++++++---
6 files changed, 83 insertions(+), 99 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 581b363..15584ce 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -4831,8 +4831,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 c69b315..0ce1995 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -4332,8 +4332,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 8c10008..04f71f5 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -3149,8 +3149,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);
}
}
@@ -3337,7 +3345,18 @@ gtk_drag_set_icon_pixmap (GdkDragContext *context,
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 fa383f3..61579fa 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3803,7 +3803,7 @@ gtk_widget_realize (GtkWidget *widget)
{
GtkWidgetPrivate *priv;
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) ||
@@ -3837,19 +3837,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 (priv->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 (priv->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 (priv->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 (priv->window, region, 0, 0);
mode = gtk_widget_get_extension_events (widget);
if (mode != GDK_EXTENSION_EVENTS_NONE)
@@ -3876,10 +3870,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))
{
@@ -10022,32 +10016,22 @@ 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)
{
GtkWidgetPrivate *priv;
- GtkWidgetShapeInfo* shape_info;
g_return_if_fail (GTK_IS_WIDGET (widget));
/* set_shape doesn't work on widgets without gdk window */
@@ -10055,12 +10039,12 @@ gtk_widget_shape_combine_mask (GtkWidget *widget,
priv = widget->priv;
- if (!shape_mask)
+ if (region == NULL)
{
GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
-
+
if (priv->window)
- gdk_window_shape_combine_mask (priv->window, NULL, 0, 0);
+ gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
}
@@ -10068,44 +10052,34 @@ 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 (priv->window)
- gdk_window_shape_combine_mask (priv->window, shape_mask,
- offset_x, offset_y);
+ gdk_window_shape_combine_region (priv->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)
{
GtkWidgetPrivate *priv;
- GtkWidgetShapeInfo* shape_info;
g_return_if_fail (GTK_IS_WIDGET (widget));
/* set_shape doesn't work on widgets without gdk window */
@@ -10113,30 +10087,24 @@ gtk_widget_input_shape_combine_mask (GtkWidget *widget,
priv = widget->priv;
- if (!shape_mask)
+ if (region == NULL)
{
if (priv->window)
- gdk_window_input_shape_combine_mask (priv->window, NULL, 0, 0);
-
+ gdk_window_input_shape_combine_region (priv->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 (priv->window)
- gdk_window_input_shape_combine_mask (priv->window, shape_mask,
- offset_x, offset_y);
+ gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
}
}
@@ -10152,7 +10120,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 59e3a38..eef03fe 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -199,7 +199,6 @@ typedef struct _GtkSelectionData GtkSelectionData;
typedef struct _GtkWidgetPrivate GtkWidgetPrivate;
typedef struct _GtkWidgetClass GtkWidgetClass;
typedef struct _GtkWidgetAuxInfo GtkWidgetAuxInfo;
-typedef struct _GtkWidgetShapeInfo GtkWidgetShapeInfo;
typedef struct _GtkClipboard GtkClipboard;
typedef struct _GtkTooltip GtkTooltip;
typedef struct _GtkWindow GtkWindow;
@@ -509,13 +508,6 @@ struct _GtkWidgetAuxInfo
GtkBorder margin;
};
-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,
@@ -896,16 +888,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 56bd022..bfdbb21 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -7262,8 +7262,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
@@ -7287,19 +7289,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]