Stop using gtk_widget_is_toplevel

This commit is contained in:
Matthias Clasen 2019-05-20 03:31:03 +00:00
parent 8af89b3380
commit 948347afa9
23 changed files with 44 additions and 109 deletions

View File

@ -164,7 +164,7 @@ run_example_for_row (GtkWidget *window,
cbdata->model = model;
cbdata->path = gtk_tree_model_get_path (model, iter);
if (gtk_widget_is_toplevel (demo))
if (GTK_IS_WINDOW (demo))
{
gtk_window_set_transient_for (GTK_WINDOW (demo), GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (demo), TRUE);

View File

@ -1159,7 +1159,7 @@ gtk_tree_view_accessible_grab_cell_focus (GtkCellAccessibleParent *parent,
gtk_tree_path_free (path);
gtk_widget_grab_focus (widget);
toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_window_present (GTK_WINDOW (toplevel));

View File

@ -585,7 +585,7 @@ gtk_widget_accessible_grab_focus (AtkComponent *component)
gtk_widget_grab_focus (widget);
toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_window_present (GTK_WINDOW (toplevel));

View File

@ -380,15 +380,6 @@ gtk_window_accessible_get_extents (AtkComponent *component,
if (widget == NULL)
return;
if (!gtk_widget_is_toplevel (widget))
{
AtkComponentIface *parent_iface;
parent_iface = (AtkComponentIface *) g_type_interface_peek_parent (ATK_COMPONENT_GET_IFACE (component));
parent_iface->get_extents (component, x, y, width, height, coord_type);
return;
}
surface = gtk_native_get_surface (GTK_NATIVE (widget));
if (surface == NULL)
return;
@ -427,15 +418,6 @@ gtk_window_accessible_get_size (AtkComponent *component,
if (widget == NULL)
return;
if (!gtk_widget_is_toplevel (widget))
{
AtkComponentIface *parent_iface;
parent_iface = (AtkComponentIface *) g_type_interface_peek_parent (ATK_COMPONENT_GET_IFACE (component));
parent_iface->get_size (component, width, height);
return;
}
surface = gtk_native_get_surface (GTK_NATIVE (widget));
if (surface == NULL)
return;

View File

@ -1779,7 +1779,6 @@ gtk_assistant_insert_page (GtkAssistant *assistant,
g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
page_info = g_object_new (GTK_TYPE_ASSISTANT_PAGE, NULL);
page_info->page = g_object_ref (page);

View File

@ -70,7 +70,8 @@ gtk_css_widget_node_queue_validate (GtkCssNode *node)
{
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
if (widget_node->widget && _gtk_widget_is_toplevel (widget_node->widget) &&
if (widget_node->widget &&
GTK_IS_ROOT (widget_node->widget) &&
GTK_IS_CONTAINER (widget_node->widget))
widget_node->validate_cb_id = gtk_widget_add_tick_callback (widget_node->widget,
gtk_css_widget_node_queue_callback,
@ -83,7 +84,8 @@ gtk_css_widget_node_dequeue_validate (GtkCssNode *node)
{
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
if (widget_node->widget && _gtk_widget_is_toplevel (widget_node->widget) &&
if (widget_node->widget &&
GTK_IS_ROOT (widget_node->widget) &&
GTK_IS_CONTAINER (widget_node->widget))
gtk_widget_remove_tick_callback (widget_node->widget,
widget_node->validate_cb_id);

View File

@ -2608,7 +2608,7 @@ open_dialog (GtkFileChooserButton *button)
{
if (!gtk_widget_get_visible (priv->dialog))
{
if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
if (GTK_WINDOW (toplevel) != gtk_window_get_transient_for (GTK_WINDOW (priv->dialog)))
gtk_window_set_transient_for (GTK_WINDOW (priv->dialog),
@ -2623,7 +2623,7 @@ open_dialog (GtkFileChooserButton *button)
{
if (!gtk_native_dialog_get_visible (GTK_NATIVE_DIALOG (priv->native)))
{
if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
if (GTK_WINDOW (toplevel) != gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (priv->native)))
gtk_native_dialog_set_transient_for (GTK_NATIVE_DIALOG (priv->native),

View File

@ -713,10 +713,10 @@ get_toplevel (GtkWidget *widget)
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
if (!gtk_widget_is_toplevel (toplevel))
return NULL;
else
if (GTK_IS_WINDOW (toplevel))
return GTK_WINDOW (toplevel);
else
return NULL;
}
/* Shows an error dialog for the file chooser */
@ -1682,7 +1682,7 @@ open_folder_cb (GSimpleAction *action,
files = get_selected_files (impl);
/* Sigh, just use the first one */
if (files && gtk_widget_is_toplevel (toplevel))
if (files && GTK_IS_WINDOW (toplevel))
{
GFile *file = files->data;
gchar *uri;

View File

@ -980,7 +980,7 @@ gtk_font_button_clicked (GtkButton *button,
priv->font_filter_data_destroy = NULL;
}
if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
if (GTK_IS_WINDOW (parent))
{
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog)))
gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent));

View File

@ -280,7 +280,8 @@ void
_gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
{
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
GtkWidget *widget = GTK_WIDGET (bar), *toplevel;
GtkWidget *widget = GTK_WIDGET (bar);
GtkWidget *toplevel;
GtkWindow *window;
gchar *layout_desc;
gchar **tokens, **t;
@ -290,7 +291,7 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
gboolean is_sovereign_window;
toplevel = gtk_widget_get_toplevel (widget);
if (!gtk_widget_is_toplevel (toplevel))
if (!GTK_IS_WINDOW (toplevel))
return;
if (priv->titlebar_start_box)

View File

@ -1457,7 +1457,7 @@ claim_status_window (GtkIMContextXIM *context_xim)
if (!context_xim->status_window && context_xim->client_widget)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget);
if (toplevel && gtk_widget_is_toplevel (toplevel))
if (toplevel)
{
StatusWindow *status_window = status_window_get (toplevel);
@ -1491,7 +1491,7 @@ update_in_toplevel (GtkIMContextXIM *context_xim)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget);
context_xim->in_toplevel = (toplevel && gtk_widget_is_toplevel (toplevel));
context_xim->in_toplevel = toplevel != NULL;
}
else
context_xim->in_toplevel = FALSE;

View File

@ -1764,16 +1764,16 @@ gtk_label_setup_mnemonic (GtkLabel *label,
mnemonic_menu = NULL;
}
}
if (priv->mnemonic_keyval == GDK_KEY_VoidSymbol)
goto done;
connect_mnemonics_visible_notify (GTK_LABEL (widget));
if (toplevel && gtk_widget_is_toplevel (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
GtkWidget *menu_shell;
menu_shell = gtk_widget_get_ancestor (widget,
GTK_TYPE_MENU_SHELL);
@ -1784,7 +1784,7 @@ gtk_label_setup_mnemonic (GtkLabel *label,
widget);
mnemonic_menu = menu_shell;
}
if (!GTK_IS_MENU (menu_shell))
{
gtk_window_add_mnemonic (GTK_WINDOW (toplevel),
@ -1793,7 +1793,7 @@ gtk_label_setup_mnemonic (GtkLabel *label,
priv->mnemonic_window = GTK_WINDOW (toplevel);
}
}
done:
g_object_set_qdata (G_OBJECT (label), quark_mnemonic_menu, mnemonic_menu);
}

View File

@ -396,7 +396,7 @@ _gtk_menu_bar_cycle_focus (GtkMenuBar *menubar,
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menubar));
GtkMenuItem *to_activate = NULL;
if (gtk_widget_is_toplevel (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
GList *tmp_menubars = _gtk_menu_bar_get_viewable_menu_bars (GTK_WINDOW (toplevel));
GList *l;

View File

@ -1536,7 +1536,7 @@ gtk_notebook_move_focus_out (GtkNotebook *notebook,
* do this by setting a flag, then propagating the focus motion to the notebook.
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
if (!gtk_widget_is_toplevel (toplevel))
if (!GTK_IS_ROOT (toplevel))
return;
g_object_ref (notebook);
@ -3808,7 +3808,7 @@ gtk_notebook_set_focus_child (GtkContainer *container,
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
if (toplevel && gtk_widget_is_toplevel (toplevel))
if (GTK_IS_WINDOW (toplevel))
{
page_child = gtk_window_get_focus (GTK_WINDOW (toplevel));
while (page_child)

View File

@ -1847,7 +1847,7 @@ paned_get_focus_widget (GtkPaned *paned)
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned));
if (gtk_widget_is_toplevel (toplevel))
if (GTK_IS_WINDOW (toplevel))
return gtk_window_get_focus (GTK_WINDOW (toplevel));
return NULL;

View File

@ -312,10 +312,10 @@ get_toplevel (GtkWidget *widget)
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
if (!gtk_widget_is_toplevel (toplevel))
return NULL;
else
if (GTK_IS_WINDOW (toplevel))
return GTK_WINDOW (toplevel);
else
return NULL;
}
static void

View File

@ -581,10 +581,10 @@ get_toplevel (GtkWidget *widget)
GtkWidget *toplevel = NULL;
toplevel = gtk_widget_get_toplevel (widget);
if (!gtk_widget_is_toplevel (toplevel))
return NULL;
else
if (GTK_IS_WINDOW (toplevel))
return GTK_WINDOW (toplevel);
else
return NULL;
}
static void

View File

@ -2904,7 +2904,7 @@ gtk_scrolled_window_move_focus_out (GtkScrolledWindow *scrolled_window,
* a flag, then propagating the focus motion to the notebook.
*/
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scrolled_window));
if (!gtk_widget_is_toplevel (toplevel))
if (!GTK_IS_ROOT (toplevel))
return;
g_object_ref (scrolled_window);

View File

@ -493,7 +493,7 @@ gtk_widget_measure (GtkWidget *widget,
* possibly queries the widget class to compute the size if it's
* not cached.
*/
if (!_gtk_widget_get_visible (widget) && !_gtk_widget_is_toplevel (widget))
if (!_gtk_widget_get_visible (widget) && !GTK_IS_ROOT (widget))
{
if (minimum)
*minimum = 0;

View File

@ -507,7 +507,6 @@ gtk_tooltip_set_last_surface (GtkTooltip *tooltip,
if (window_widget &&
window_widget != tooltip->window &&
gtk_widget_is_toplevel (window_widget) &&
GTK_IS_WINDOW (window_widget))
gtk_window_set_transient_for (GTK_WINDOW (tooltip->window),
GTK_WINDOW (window_widget));

View File

@ -3503,7 +3503,7 @@ gtk_widget_connect_frame_clock (GtkWidget *widget)
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GdkFrameClock *frame_clock;
if (GTK_IS_CONTAINER (widget) && _gtk_widget_is_toplevel (widget))
if (GTK_IS_CONTAINER (widget) && GTK_IS_ROOT (widget))
gtk_container_start_idle_sizer (GTK_CONTAINER (widget));
frame_clock = gtk_widget_get_frame_clock (widget);
@ -3524,7 +3524,7 @@ gtk_widget_disconnect_frame_clock (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
if (GTK_IS_CONTAINER (widget) && _gtk_widget_is_toplevel (widget))
if (GTK_IS_CONTAINER (widget) && GTK_IS_ROOT (widget))
gtk_container_stop_idle_sizer (GTK_CONTAINER (widget));
gtk_css_node_invalidate_frame_clock (priv->cssnode, FALSE);
@ -3850,8 +3850,7 @@ gtk_widget_realize (GtkWidget *widget)
g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
*/
if (priv->parent == NULL &&
!_gtk_widget_is_toplevel (widget))
if (priv->parent == NULL && !GTK_IS_ROOT (widget))
g_warning ("Calling gtk_widget_realize() on a widget that isn't "
"inside a toplevel window is not going to work very well. "
"Widgets must be inside a toplevel container before realizing them.");
@ -4278,7 +4277,7 @@ gtk_widget_allocate (GtkWidget *widget,
gtk_widget_push_verify_invariants (widget);
if (!priv->visible && !_gtk_widget_is_toplevel (widget))
if (!priv->visible && !GTK_IS_ROOT (widget))
goto out;
#ifdef G_ENABLE_DEBUG
@ -7124,7 +7123,7 @@ gtk_widget_set_child_visible (GtkWidget *widget,
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (!_gtk_widget_is_toplevel (widget));
g_return_if_fail (!GTK_IS_ROOT (widget));
child_visible = !!child_visible;
@ -11271,7 +11270,7 @@ gtk_widget_update_alpha (GtkWidget *widget)
if (_gtk_widget_get_realized (widget))
{
if (_gtk_widget_is_toplevel (widget))
if (GTK_IS_NATIVE (widget))
gdk_surface_set_opacity (priv->surface, priv->alpha / 255.0);
gtk_widget_queue_draw (widget);
@ -11461,7 +11460,7 @@ gtk_widget_set_alloc_needed (GtkWidget *widget)
if (!priv->visible)
break;
if (_gtk_widget_is_toplevel (widget))
if (GTK_IS_ROOT (widget))
{
gtk_container_start_idle_sizer (GTK_CONTAINER (widget));
break;

View File

@ -4954,12 +4954,6 @@ gtk_window_show (GtkWidget *widget)
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
if (!_gtk_widget_is_toplevel (GTK_WIDGET (widget)))
{
GTK_WIDGET_CLASS (gtk_window_parent_class)->show (widget);
return;
}
_gtk_widget_set_visible_flag (widget, TRUE);
gtk_css_node_validate (gtk_widget_get_css_node (widget));
@ -4988,12 +4982,6 @@ gtk_window_hide (GtkWidget *widget)
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
if (!_gtk_widget_is_toplevel (GTK_WIDGET (widget)))
{
GTK_WIDGET_CLASS (gtk_window_parent_class)->hide (widget);
return;
}
_gtk_widget_set_visible_flag (widget, FALSE);
gtk_widget_unmap (widget);
@ -5009,12 +4997,6 @@ gtk_window_map (GtkWidget *widget)
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
GdkSurface *surface;
if (!_gtk_widget_is_toplevel (widget))
{
GTK_WIDGET_CLASS (gtk_window_parent_class)->map (widget);
return;
}
GTK_WIDGET_CLASS (gtk_window_parent_class)->map (widget);
child = gtk_bin_get_child (GTK_BIN (window));
@ -5110,12 +5092,6 @@ gtk_window_unmap (GtkWidget *widget)
GtkWindowGeometryInfo *info;
GdkSurfaceState state;
if (!_gtk_widget_is_toplevel (GTK_WIDGET (widget)))
{
GTK_WIDGET_CLASS (gtk_window_parent_class)->unmap (widget);
return;
}
GTK_WIDGET_CLASS (gtk_window_parent_class)->unmap (widget);
gdk_surface_hide (priv->surface);
@ -5429,9 +5405,6 @@ get_shadow_width (GtkWindow *window,
priv->fullscreen)
return;
if (!_gtk_widget_is_toplevel (GTK_WIDGET (window)))
return;
context = _gtk_widget_get_style_context (GTK_WIDGET (window));
gtk_style_context_save_to_node (context, priv->decoration_node);
@ -5606,9 +5579,6 @@ update_realized_window_properties (GtkWindow *window,
{
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
if (!_gtk_widget_is_toplevel (GTK_WIDGET (window)))
return;
if (priv->client_decorated && priv->use_client_shadow)
update_shadow_width (window, window_border);
@ -5974,11 +5944,6 @@ _gtk_window_set_allocation (GtkWindow *window,
priv->title_height;
}
if (!_gtk_widget_is_toplevel (widget) && _gtk_widget_get_realized (widget))
{
gdk_surface_move_resize (priv->surface, 0, 0, width, height);
}
*allocation_out = child_allocation;
for (link = priv->popovers.head; link; link = link->next)
@ -6017,9 +5982,6 @@ gtk_window_configure (GtkWindow *window,
check_scale_changed (window);
if (!_gtk_widget_is_toplevel (widget))
return FALSE;
/* If this is a gratuitous ConfigureNotify that's already
* the same as our allocation, then we can fizzle it out.
* This is the case for dragging windows around.
@ -6427,9 +6389,6 @@ gtk_window_focus (GtkWidget *widget,
GtkWidget *old_focus_child;
GtkWidget *parent;
if (!_gtk_widget_is_toplevel (widget))
return GTK_WIDGET_CLASS (gtk_window_parent_class)->focus (widget, direction);
container = GTK_CONTAINER (widget);
bin = GTK_BIN (widget);
@ -6495,12 +6454,6 @@ static void
gtk_window_move_focus (GtkWidget *widget,
GtkDirectionType dir)
{
if (!_gtk_widget_is_toplevel (widget))
{
GTK_WIDGET_CLASS (gtk_window_parent_class)->move_focus (widget, dir);
return;
}
gtk_widget_child_focus (widget, dir);
if (!gtk_widget_get_focus_child (widget))

View File

@ -279,7 +279,7 @@ update_info (gpointer data)
gtk_label_set_text (GTK_LABEL (sl->priv->accessible_description), atk_object_get_description (accessible));
gtk_widget_set_visible (sl->priv->mapped, gtk_widget_get_mapped (GTK_WIDGET (sl->priv->object)));
gtk_widget_set_visible (sl->priv->realized, gtk_widget_get_realized (GTK_WIDGET (sl->priv->object)));
gtk_widget_set_visible (sl->priv->is_toplevel, gtk_widget_is_toplevel (GTK_WIDGET (sl->priv->object)));
gtk_widget_set_visible (sl->priv->is_toplevel, GTK_IS_ROOT (sl->priv->object));
gtk_widget_set_visible (sl->priv->child_visible, gtk_widget_get_child_visible (GTK_WIDGET (sl->priv->object)));
update_frame_clock (sl);