diff options
author | Benjamin Otte <otte@redhat.com> | 2022-06-28 16:25:31 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2022-06-28 16:37:11 +0200 |
commit | c00b234440abf36e18e0430f66305a3e9434e99d (patch) | |
tree | 7b03406ccad03ea3695a593cbcdd30890c20cd98 | |
parent | 354f1a783a92c389b0f2fbf58c3a16c36033034b (diff) | |
download | gtk+-c00b234440abf36e18e0430f66305a3e9434e99d.tar.gz |
picture: Clear the paintable properly
Add a clear() function and call it from dispose() instead of using
set_paintable().
-rw-r--r-- | gtk/gtkpicture.c | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/gtk/gtkpicture.c b/gtk/gtkpicture.c index 8de6cc0832..0712d1844f 100644 --- a/gtk/gtkpicture.c +++ b/gtk/gtkpicture.c @@ -296,11 +296,48 @@ gtk_picture_get_property (GObject *object, } static void +gtk_picture_paintable_invalidate_contents (GdkPaintable *paintable, + GtkPicture *self) +{ + gtk_widget_queue_draw (GTK_WIDGET (self)); +} + +static void +gtk_picture_paintable_invalidate_size (GdkPaintable *paintable, + GtkPicture *self) +{ + gtk_widget_queue_resize (GTK_WIDGET (self)); +} + +static void +gtk_picture_clear_paintable (GtkPicture *self) +{ + guint flags; + + if (self->paintable == NULL) + return; + + flags = gdk_paintable_get_flags (self->paintable); + + if ((flags & GDK_PAINTABLE_STATIC_CONTENTS) == 0) + g_signal_handlers_disconnect_by_func (self->paintable, + gtk_picture_paintable_invalidate_contents, + self); + + if ((flags & GDK_PAINTABLE_STATIC_SIZE) == 0) + g_signal_handlers_disconnect_by_func (self->paintable, + gtk_picture_paintable_invalidate_size, + self); + + g_object_unref (self->paintable); +} + +static void gtk_picture_dispose (GObject *object) { GtkPicture *self = GTK_PICTURE (object); - gtk_picture_set_paintable (self, NULL); + gtk_picture_clear_paintable (self); g_clear_object (&self->file); g_clear_pointer (&self->alternative_text, g_free); @@ -707,20 +744,6 @@ gtk_picture_set_pixbuf (GtkPicture *self, g_object_unref (texture); } -static void -gtk_picture_paintable_invalidate_contents (GdkPaintable *paintable, - GtkPicture *self) -{ - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static void -gtk_picture_paintable_invalidate_size (GdkPaintable *paintable, - GtkPicture *self) -{ - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - /** * gtk_picture_set_paintable: (attributes org.gtk.Method.set_property=paintable) * @self: a `GtkPicture` @@ -747,22 +770,7 @@ gtk_picture_set_paintable (GtkPicture *self, if (paintable) g_object_ref (paintable); - if (self->paintable) - { - const guint flags = gdk_paintable_get_flags (self->paintable); - - if ((flags & GDK_PAINTABLE_STATIC_CONTENTS) == 0) - g_signal_handlers_disconnect_by_func (self->paintable, - gtk_picture_paintable_invalidate_contents, - self); - - if ((flags & GDK_PAINTABLE_STATIC_SIZE) == 0) - g_signal_handlers_disconnect_by_func (self->paintable, - gtk_picture_paintable_invalidate_size, - self); - - g_object_unref (self->paintable); - } + gtk_picture_clear_paintable (self); self->paintable = paintable; |