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.
This commit is contained in:
Benjamin Otte 2010-08-14 06:38:11 +02:00
parent 8b4d50dd1d
commit 806a7239ae
6 changed files with 83 additions and 99 deletions

View File

@ -4827,8 +4827,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

View File

@ -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

View File

@ -3139,8 +3139,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);
}
}
@ -3327,7 +3335,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);
}

View File

@ -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))
{
@ -10027,32 +10021,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 */
@ -10060,12 +10044,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);
}
@ -10073,44 +10057,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 */
@ -10118,30 +10092,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);
}
}
@ -10157,7 +10125,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);
}

View File

@ -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;
@ -530,13 +529,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,
@ -919,16 +911,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);

View File

@ -7263,8 +7263,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
@ -7288,19 +7290,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",