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

Re: Dynamically changing menus



On Thu, 3 Jun 1999, Havoc Pennington wrote:
> On Thu, 3 Jun 1999, Richard Tew wrote:
> > So basically, what I am asking is, can I swap one of the menus in the menu
> > bar (and have the accelerator keypresses updated) at will?  I have looked
> > at the documentation and read the source but afaict cannot see a way to do
> > this.
> 
> To remove a menu, call gtk_container_remove(menubar, menuitem). To add
> one, use gtk_menubar_insert() or gtk_menubar_append().

Ahh, thats an idea :)

What I ended up doing was getting the menu item (gtk_factory_get_item or
something) that was the menu I wanted to change when the pages of the
notebook changed, and I just set the relevant submenu for that menu item
(gtk_menu_item_set_submenu) to the one of a given page when it was
switched to.  GTK makes it remarkably easy, even having a separate
accelerator table and item factory for each pages submenu was not too hard
to work out.

The other thing I would like to know is if there is any way to ghost menu
items, you know what I mean, so the items are there but can't be selected
and you can tell that the item is disabled when you look.  I know I could
just make the item do nothing, but a visual effect that showed that the
item was disabled would be nice.  I can't see anything like this in the
source, any ideas? 

> You need to gtk_widget_ref() the menu item before you remove it, or it
> will be destroyed when its parent container unreferences it. After you
> re-add the item, unref() it again.

Ahh, I worked this bit out for several things, but I was not sure on the
unreffing bit.  Does unreffing actually make a difference?

The reason I ask this is cause if I do not ref the submenu, the second
time I switch to the page it seg faults as the widget was destroyed.  BUT,
if I ref it once when its created, I never have a problem no matter how
many times I switch pages.

Thanks,
Richard.



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