Re: [gtk-list] gtk_widget_get_toplevel() weirdness.



John C Atkeson wrote:
> 
> 
>   I'm getting weird behavior out of gtk_widget_get_toplevel in KDE under
> RH Linux, but no similar problems in gtk-Win32....
> 
>   For example if I retrieve a widget's toplevel window in Linux:
> 
>   GtkWidget *Top=gtk_widget_get_toplevel(child);
> 
> and then print the top's name:
> 
>   g_print("Top is:%s \n",gtk_widget_get_name(Top));
> 
>   It *always* returns the string "GtkWindow", no matter what the
> toplevel's name really was set to.  In Win32 on the other hand it returns
> the right answer.
>   More importantly though, none of Top's user-data is accessible either;
> it's almost as if Top is a completely different widget from the real top.
> 
> 
>   My theory is that somehow the KDE wm is holding my gtk windows in
> higher-level containers, and gtk_widget_get_toplevel is finding those
> instead.
> 
>   Any workarounds for this?  I am using Glade-generated code, which
> nicely allows one to access every sub-widget by name *if* one can get a
> pointer to the toplevel...
>   Each menu widget must therefore find its top-mother before it can talk
> to any of its brothers.


I think the problem is that you are using gtk_widget_get_toplevel() inside
a popup menu. Each GtkMenu has its own 'toplevel' GtkWindow, so that is what
will be returned.

If you look at the code Glade outputs in lookup_widget() in support.c you can
see how we get around this. When Glade tries to walk up the hierarchy it does this:

      if (GTK_IS_MENU (widget))
        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
      else
        parent = widget->parent;



Damon




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]