attaching to menus




hello everybody,

the problem with destruction of menus is solved.
in gtkmenu.h there are two new functions now:

typedef void (*GtkMenuDetachFunc)   (GtkWidget *attach_widget,
                                     GtkMenu   *menu);

void       gtk_menu_attach_to_widget      (GtkMenu             *menu,
                                           GtkWidget           *attach_widget,
                                           GtkMenuDetachFunc    detacher);
void       gtk_menu_detach                (GtkMenu             *menu);

gtk_menu_attach_to_widget() takes over the corresponding actions
from gtk_widget_set_parent.
gtk_menu_detach() takes over the corresponding actions from
gtk_widget_unparent.

GtkMenus are slightly different from the other widgets in
the toolkit in the fact that they are TOPLEVELs.
they also differ from an ordinary GtkWindow because they need
to be attached to either a menu item vie gtk_menu_item_set_submenu
or an option menu via gtk_option_menu_set_menu.
therefore some kind of action needs to be performed similar to
container_add/container_remove. namely sinking the GtkMenu via
gtk_object_sink, and proper destruction notification.

this is the purpose of gtk_menu_attach_to_widget/gtk_menu_detach.
once a menu item/option menu gets a GtkMenu set or removed, it calls
either of the attach/detach functions and this way takes care of
the FLOATING flag, the unrealization and the menus state (similar
to (un)parenting a normal widget).

upon the attachement of a menu to a widget a "detacher" function needs
to be provided. the detacher takes care of the stuff that is performed
in container_remove normaly (i.e. removal of a childs pointer the parent
holds to it and/or other cleanups).

since gtk_menu_attach_to_widget/gtk_menu_detach now take proper care
of the floating flag and hold the reference count from the parent
on the child, GtkMenus do *not* register as toplevels anymore (this
has been a mere hack and isn't justified, in fact they are not real
toplevels in the sence of being a self-contained window).
clearing the floating flag upon attachements will cause the menu to be
destroyed once it is removed from the option menu/menu item, this is
the right ting to do.

since the option menu is now notified about the destruction of its
submenu, the fileselection widget actually works. also, the automatic
destruction of the submenus should take care of the gazillions of
living GtkMenus once the gimp is quit.


---
ciaoTJ



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