Re: MenutItem get and set label?



Philippe Laporte wrote:

     Why is there no get and set label access for menu items?
i.e., why no
gtk_menu_item_set_label
gtk_menu_item_get_label

There actually is a kind of that. However, they're called:
- gtk_label_get_text ()
- gtk_label_get_label ()
- gtk_label_set_text ()
- gtk_label_set_text_with_mnemonic ()
- gtk_label_set_markup ()
- gtk_label_set_markup_with_mnemonic ()

Note that the label / text is not a property of the menu_item. A menu
item is just an (initially empty) container to be filled with child
widgets of various types. Most commonly (but not necessarily) this is a
single GtkLabel. I think the gtk_menu_item_new_with_* functions (used by
Glade's output) are the only GTK-convenience functions to implicitly
deal with that.

You have to obtain (or maintain) a handle to that child-GtkLabel of a
GtkMenuIten by yourself before you can get / set the text. Obtaining the
child(ren) of a GtkmenuItem is best done by using
gtk_container_get_children ((GtkContainer *) your_menu_item);

You can write a menu_item_[gs]et_label function by yourself. If you
assume only GtkLabels as item children it can be kept pretty simple.
However, please do not forget to free the resulting GList which you
receive from gtk_container_get_children ().

See:
http://developer.gnome.org/doc/API/2.0/gtk/GtkContainer.html#gtk-container-get-children
http://developer.gnome.org/doc/API/2.0/gtk/GtkLabel.html



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