Re: [gtk-list] Re: getting the optionmenu text in gtk--
- From: Marsel Osipov <virtuoso jps net>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: getting the optionmenu text in gtk--
- Date: Mon, 28 Sep 1998 15:43:15 -0700
Havoc Pennington wrote:
> On Sun, 27 Sep 1998, Marsel Osipov wrote:
> > Hello.
> > I have a Gtk_OptionMenu widget, and I was wondering how can I get
> > the text of the selected item?
> >
>
> You could extract the text from the label in the item, but it would be
> suboptimal because you'd be doing a lot of casts that weren't guaranteed
> to work (for example, if you later decided to add a pixmap to the menu
> item, or the GtkLabel struct changed, your code would break).
>
> The best way is probably to do
>
> /* pointer_to_data is a pointer to your string */
> gtk_object_set_data(GTK_OBJECT(menuitem), "my_data_key",
> pointer_to_data);
>
> then:
>
> gchar* text_of_item = (gchar*)gtk_object_get_data(GTK_OBJECT(menuitem),
> "my_data_key");
>
> if (text_of_item == NULL) g_error("Bug! no data");
> else {
> /* Use text */
> }
>
> If you aren't setting any other data you can use the
> gtk_object_[get|set]_user_data shortcut functions, they let you set a
> single item of data without having to type a key.
>
Ok. But how would I get that menuitem from the menu?
> Havoc
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]