Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Catanzaro
b26348710d listbox: unparent new header only if it has a parent
It's no longer OK to unparent a widget that has no parent.
2021-01-07 11:39:41 -06:00
Michael Catanzaro
db059847b2 Add warning when widget with no parent is unparented
This is a little controversial -- Benjamin is not fond of adding new
warnings in GTK 4 -- but it is not really an API break, and will help
developers avoid adding unnecessary code to unparent widgets that are
already unparented elsewhere. Also, it's still quite early in the life
of GTK 4, before most apps have been ported. The earlier we add this
warning, the better.
2021-01-07 11:39:41 -06:00
2 changed files with 7 additions and 2 deletions

View File

@@ -2232,7 +2232,8 @@ gtk_list_box_update_header (GtkListBox *box,
if (new_header != NULL)
{
g_hash_table_insert (box->header_hash, new_header, row);
gtk_widget_unparent (new_header);
if (gtk_widget_get_parent (new_header) != NULL)
gtk_widget_unparent (new_header);
gtk_widget_set_parent (new_header, GTK_WIDGET (box));
gtk_widget_show (new_header);
}

View File

@@ -2497,7 +2497,11 @@ gtk_widget_unparent (GtkWidget *widget)
g_return_if_fail (GTK_IS_WIDGET (widget));
if (priv->parent == NULL)
return;
{
g_warning ("Attempted to unparent %s %p, but it already has no parent.",
G_OBJECT_TYPE_NAME (widget), widget);
return;
}
gtk_widget_push_verify_invariants (widget);