This function returns the topmost widget in the container hierarchy widget is a part of. If widget has no parent widgets, it will be returned as the topmost widget. No reference will be added to the returned widget; it should not be unreferenced.
Note the difference in behavior vs. get_ancestor();
gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW) would return
0 if widget wasn't inside a toplevel window, and if the window was inside a Gtk::Window-derived widget which was in turn inside the toplevel Gtk::Window. While the second case may seem unlikely, it actually happens when a Gtk::Plug is embedded inside a Gtk::Socket within the same application.
To reliably find the toplevel Gtk::Window, use get_toplevel() and check if the T::OPLEVEL flags is set on the result.
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
if (GTK_WIDGET_TOPLEVEL (toplevel))
[ Perform action on toplevel. ]
- The topmost ancestor of widget , or widget itself if there's no ancestor.
Definition at line 5313 of file widget.cc.
Referenced by Gtk::MenuShell::accelerate().