inspector: Fix child widget life cycle

unparent them in dispose
This commit is contained in:
Timm Bäder 2020-03-22 15:41:21 +01:00
parent 56d99ab5cd
commit 3b2adf5d1f
4 changed files with 30 additions and 94 deletions

View File

@ -31,6 +31,7 @@
#include "gtkimage.h"
#include "gtkadjustment.h"
#include "gtkbox.h"
#include "gtkbinlayout.h"
#ifdef GDK_WINDOWING_X11
@ -881,34 +882,13 @@ gtk_inspector_general_constructed (GObject *object)
}
static void
measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
gtk_inspector_general_dispose (GObject *object)
{
GtkInspectorGeneral *gen = GTK_INSPECTOR_GENERAL (widget);
GtkInspectorGeneral *gen = GTK_INSPECTOR_GENERAL (object);
gtk_widget_measure (gen->priv->swin,
orientation,
for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
g_clear_pointer (&gen->priv->swin, gtk_widget_unparent);
static void
size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkInspectorGeneral *gen = GTK_INSPECTOR_GENERAL (widget);
gtk_widget_size_allocate (gen->priv->swin,
&(GtkAllocation) { 0, 0, width, height },
baseline);
G_OBJECT_CLASS (gtk_inspector_general_parent_class)->dispose (object);
}
static void
@ -918,9 +898,7 @@ gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = gtk_inspector_general_constructed;
widget_class->measure = measure;
widget_class->size_allocate = size_allocate;
object_class->dispose = gtk_inspector_general_dispose;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/general.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, swin);
@ -951,6 +929,8 @@ gtk_inspector_general_class_init (GtkInspectorGeneralClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, display_composited);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, display_rgba);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorGeneral, device_box);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
void

View File

@ -31,6 +31,7 @@
#include "gtkbutton.h"
#include "gtkmenubutton.h"
#include "gtkwidgetprivate.h"
#include "gtkbinlayout.h"
struct _GtkInspectorMiscInfoPrivate {
@ -570,34 +571,13 @@ set_property (GObject *object,
}
static void
measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
dispose (GObject *o)
{
GtkInspectorMiscInfo *sl = GTK_INSPECTOR_MISC_INFO (widget);
GtkInspectorMiscInfo *sl = GTK_INSPECTOR_MISC_INFO (o);
gtk_widget_measure (sl->priv->swin,
orientation,
for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
g_clear_pointer (&sl->priv->swin, gtk_widget_unparent);
static void
size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkInspectorMiscInfo *sl = GTK_INSPECTOR_MISC_INFO (widget);
gtk_widget_size_allocate (sl->priv->swin,
&(GtkAllocation) { 0, 0, width, height },
baseline);
G_OBJECT_CLASS (gtk_inspector_misc_info_parent_class)->dispose (o);
}
static void
@ -608,11 +588,10 @@ gtk_inspector_misc_info_class_init (GtkInspectorMiscInfoClass *klass)
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;
widget_class->map = map;
widget_class->unmap = unmap;
widget_class->measure = measure;
widget_class->size_allocate = size_allocate;
g_object_class_install_property (object_class, PROP_OBJECT_TREE,
g_param_spec_object ("object-tree", "Object Tree", "Object tree",
@ -669,6 +648,8 @@ gtk_inspector_misc_info_class_init (GtkInspectorMiscInfoClass *klass)
gtk_widget_class_bind_template_callback (widget_class, show_surface);
gtk_widget_class_bind_template_callback (widget_class, show_renderer);
gtk_widget_class_bind_template_callback (widget_class, show_frame_clock);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
// vim: set et sw=2 ts=2:

View File

@ -262,11 +262,6 @@ finalize (GObject *object)
cleanup_object (pl);
g_object_unref (pl->priv->names);
g_object_unref (pl->priv->types);
g_object_unref (pl->priv->values);
g_object_unref (pl->priv->origins);
G_OBJECT_CLASS (gtk_inspector_prop_list_parent_class)->finalize (object);
}

View File

@ -41,6 +41,7 @@
#include "gskdebugprivate.h"
#include "gskrendererprivate.h"
#include "gtknative.h"
#include "gtkbinlayout.h"
#include "fallback-c89.c"
@ -1081,6 +1082,16 @@ gtk_inspector_visual_constructed (GObject *object)
g_signal_connect (vis->priv->misc_box, "row-activated", G_CALLBACK (row_activated), vis);
}
static void
gtk_inspector_visual_dispose (GObject *object)
{
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (object);
g_clear_pointer (&vis->priv->swin, gtk_widget_unparent);
G_OBJECT_CLASS (gtk_inspector_visual_parent_class)->dispose (object);
}
static void
gtk_inspector_visual_finalize (GObject *object)
{
@ -1099,37 +1110,6 @@ gtk_inspector_visual_finalize (GObject *object)
G_OBJECT_CLASS (gtk_inspector_visual_parent_class)->finalize (object);
}
static void
measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (widget);
gtk_widget_measure (vis->priv->swin,
orientation,
for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (widget);
gtk_widget_size_allocate (vis->priv->swin,
&(GtkAllocation) { 0, 0, width, height },
baseline);
}
static void
gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
{
@ -1137,11 +1117,9 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = gtk_inspector_visual_constructed;
object_class->dispose = gtk_inspector_visual_dispose;
object_class->finalize = gtk_inspector_visual_finalize;
widget_class->measure = measure;
widget_class->size_allocate = size_allocate;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/visual.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, swin);
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, box);
@ -1182,6 +1160,8 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
gtk_widget_class_bind_template_callback (widget_class, widget_resize_activate);
gtk_widget_class_bind_template_callback (widget_class, focus_activate);
gtk_widget_class_bind_template_callback (widget_class, software_gl_activate);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}
void