iconhelper: Require a widget as construction argument

Note that the caller needs to ensure the widget lives as long as the
iconhelper as the iconhelper will not ref the widget.
This commit is contained in:
Benjamin Otte 2015-12-08 15:39:10 +01:00
parent ee5758a4e1
commit c9d1a45d30
7 changed files with 23 additions and 13 deletions

View File

@ -1394,7 +1394,7 @@ gtk_status_icon_update_image (GtkStatusIcon *status_icon)
context = gtk_widget_get_style_context (widget);
round_size = round_pixel_size (widget, priv->size);
icon_helper = _gtk_icon_helper_new ();
icon_helper = _gtk_icon_helper_new (widget);
_gtk_icon_helper_set_force_scale_pixbuf (icon_helper, TRUE);
_gtk_icon_helper_set_definition (icon_helper, priv->image_def);
_gtk_icon_helper_set_icon_size (icon_helper, GTK_ICON_SIZE_SMALL_TOOLBAR);

View File

@ -440,12 +440,13 @@ gtk_cell_renderer_pixbuf_new (void)
}
static GtkIconHelper *
create_icon_helper (GtkCellRendererPixbuf *cellpixbuf)
create_icon_helper (GtkCellRendererPixbuf *cellpixbuf,
GtkWidget *widget)
{
GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
GtkIconHelper *helper;
helper = _gtk_icon_helper_new ();
helper = _gtk_icon_helper_new (widget);
_gtk_icon_helper_set_force_scale_pixbuf (helper, TRUE);
_gtk_icon_helper_set_definition (helper, priv->image_def);
_gtk_icon_helper_set_icon_size (helper, priv->icon_size);
@ -475,7 +476,7 @@ gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer *cell,
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
icon_helper = create_icon_helper (cellpixbuf);
icon_helper = create_icon_helper (cellpixbuf, widget);
if (!_gtk_icon_helper_get_is_empty (icon_helper))
_gtk_icon_helper_get_size (icon_helper,
@ -579,18 +580,18 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer *cell,
if (is_expanded && priv->pixbuf_expander_open != NULL)
{
icon_helper = _gtk_icon_helper_new ();
icon_helper = _gtk_icon_helper_new (widget);
_gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_open);
}
else if (!is_expanded && priv->pixbuf_expander_closed != NULL)
{
icon_helper = _gtk_icon_helper_new ();
icon_helper = _gtk_icon_helper_new (widget);
_gtk_icon_helper_set_pixbuf (icon_helper, priv->pixbuf_expander_closed);
}
}
if (icon_helper == NULL)
icon_helper = create_icon_helper (cellpixbuf);
icon_helper = create_icon_helper (cellpixbuf, widget);
_gtk_icon_helper_set_window (icon_helper,
gtk_widget_get_window (widget));

View File

@ -3260,7 +3260,7 @@ construct_icon_info (GtkWidget *widget,
icon_info = g_slice_new0 (EntryIconInfo);
priv->icons[icon_pos] = icon_info;
icon_info->icon_helper = _gtk_icon_helper_new ();
icon_info->icon_helper = _gtk_icon_helper_new (widget);
_gtk_icon_helper_set_force_scale_pixbuf (icon_info->icon_helper, TRUE);
widget_node = get_entry_node (widget);

View File

@ -34,6 +34,7 @@
struct _GtkIconHelperPrivate {
GtkImageDefinition *def;
GtkWidget *owner;
GdkWindow *window;
GtkIconSize icon_size;
@ -804,9 +805,17 @@ _gtk_icon_helper_get_icon_name (GtkIconHelper *self)
}
GtkIconHelper *
_gtk_icon_helper_new (void)
_gtk_icon_helper_new (GtkWidget *owner)
{
return g_object_new (GTK_TYPE_ICON_HELPER, NULL);
GtkIconHelper *helper;
g_return_val_if_fail (GTK_IS_WIDGET (owner), NULL);
helper = g_object_new (GTK_TYPE_ICON_HELPER, NULL);
helper->priv->owner = owner;
return helper;
}
void

View File

@ -67,7 +67,7 @@ struct _GtkIconHelperClass
GType _gtk_icon_helper_get_type (void) G_GNUC_CONST;
GtkIconHelper *_gtk_icon_helper_new (void);
GtkIconHelper *_gtk_icon_helper_new (GtkWidget *owner);
void _gtk_icon_helper_clear (GtkIconHelper *self);
void _gtk_icon_helper_invalidate (GtkIconHelper *self);

View File

@ -402,7 +402,7 @@ gtk_image_init (GtkImage *image)
priv = image->priv;
gtk_widget_set_has_window (GTK_WIDGET (image), FALSE);
priv->icon_helper = _gtk_icon_helper_new ();
priv->icon_helper = _gtk_icon_helper_new (GTK_WIDGET (image));
_gtk_icon_helper_set_icon_size (priv->icon_helper, DEFAULT_ICON_SIZE);
}

View File

@ -1099,7 +1099,7 @@ gtk_spin_button_panel_draw (GtkSpinButton *spin_button,
height = gdk_window_get_height (panel);
width = gdk_window_get_width (panel);
icon_helper = _gtk_icon_helper_new ();
icon_helper = _gtk_icon_helper_new (widget);
_gtk_icon_helper_set_window (icon_helper, panel);
_gtk_icon_helper_set_use_fallback (icon_helper, TRUE);