Re: [gtk-list] Re: Getting at widget toplevel parent...
- From: Damon Chaplin <damon karuna freeserve co uk>
 
- To: gtk-list redhat com
 
- Subject: Re: [gtk-list] Re: Getting at widget toplevel parent...
 
- Date: Wed, 14 Jul 1999 00:32:44 +0100
 
Ron Forrester wrote:
> 
> On Tue, Jul 13, 1999 at 03:41:58PM -0400, Owen Taylor wrote:
> > GtkWidget*   gtk_widget_get_toplevel  (GtkWidget      *widget);
> 
> As usual, I found that just after sending the question out ;)
> 
> However, it doesn't seem to be working. But I may have something else
> wrong. I am calling it against a widget that represents a menu item in
> the menu bar of an app. It doesn't return null, but I don't think it
> is returning the gtkwidget for the toplevel window.
Yes, gtk_widget_get_toplevel() doesn't work for menus, since each popup
menu is considered a 'toplevel' widget in GTK+.
Glade uses this instead:
/* This returns the toplevel window/dialog/menu that contains the given
   widget. It even walks up menus, which gtk_widget_get_toplevel() does not. */
GtkWidget*
glade_util_get_toplevel (GtkWidget *widget)
{
  GtkWidget *parent;
  for (;;)
    {
      if (GTK_IS_MENU (widget))
        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
      else
        parent = widget->parent;
      if (parent == NULL)
        break;
      widget = parent;
    }
  return widget;
}
Damon
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]