[gtkada] Option Menu?

Aidan Skinner aidan at velvet.net
Sat May 4 19:16:58 CEST 2002


On Sat, May 04, 2002 at 06:28:45PM +0200, Preben Randhol wrote

> appropriate in some cases. For the Combo box widget it is easy to get
> what the user chose by doing Get_Chars on the Gentry widget, but how can
> one do something similar with the Option Menu. I don't quite understand
> how it works and I don't find examples on how to use it.

I had this problem too. The C solution involves casting the
option_menu to gtk_button, getting the child (a gtklabel) and getting
the text from that (this is from memory, the order may be wrong or I
may have missed a couple of states, but that's the basic idea AFAICT).

I can't get that approach to work in GtkAda, my child is always null. :(

However, since I was presenting an enumeration type for the user to
select from I something similar to this:

declare
  Widgets : Gtk.Widget.Widget_List.Glist;
  Position : Gint;
begin
  Widgets := Gtk.Menu.Get_Children (Gtk.Option_Menu.Get_Menu (My_Option_Menu));
  Position := Gtk.Widget.Widget_List.Index
	        (Widgets, Gtk.Widget.Gtk_Widget
                  (Gtk.Menu.Get_Active (Gtk.Option_Menu.Get_Menu
                                          (My_Option_Menu))));
end;

which allowed me to do a Enum_Type'Image(Enum_Type'Val(Position)) for the string.

It's by no means perfect, and I'd really like to know the proper way
of doing it, but it allowed me to do what I needed to do.

- Aidan
-- 
aidan at velvet.net  http://www.velvet.net/~aidan/  aim:aidans42
finger for pgp key fingerprint |Unix Programmer/Admin actively seeking work
01AA 1594 2DB0 09E3 B850       |CV at http://www.velvet.net/~aidan/cv.txt
C2D0 9A2C 4CC9 3EC4 75E1       |Gis a job, go on, I can do that, go on, gis it.




More information about the gtkada mailing list