From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.194.20.233 with SMTP id q9mr1153416wje.1.1466348524799; Sun, 19 Jun 2016 08:02:04 -0700 (PDT) X-Received: by 10.157.39.133 with SMTP id c5mr335064otb.6.1466348524675; Sun, 19 Jun 2016 08:02:04 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!goblin1!goblin.stu.neva.ru!w10no3182691lbo.0!news-out.google.com!f5ni11941lbb.0!nntp.google.com!oe3no4983503lbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 19 Jun 2016 08:02:04 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.218.37.33; posting-account=W2gdXQoAAADxIuhBWhPFjUps3wUp4RhQ NNTP-Posting-Host: 76.218.37.33 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1df56f78-8ea3-4cdc-aa54-05249464495f@googlegroups.com> Subject: Re: Gtkada: attach signals to menus From: Stephen Leake Injection-Date: Sun, 19 Jun 2016 15:02:04 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:30811 Date: 2016-06-19T08:02:04-07:00 List-Id: Basic menus work, but I can't figure out how to compute the submenu on the fly. Here's my attempt: pragma License (GPL); with Ada.Text_IO; with Gtk.Main; with Gtk.Menu; with Gtk.Menu_Bar; with Gtk.Menu_Item; with Gtk.Widget; package body Menu_Demo_Pkg is procedure On_Window_Destroy (Widget : access Gtk.Widget.Gtk_Widget_Record'Class) is pragma Unreferenced (Widget); begin Gtk.Main.Main_Quit; end On_Window_Destroy; procedure On_Menu_Table (Self : access Gtk.Menu_Item.Gtk_Menu_Item_Record'Class) is use Gtk.Menu_Item; Table_Item : constant Gtk_Menu_Item := Gtk_Menu_Item (Self); Menu : constant Gtk.Menu.Gtk_Menu := Gtk.Menu.Gtk_Menu_New; Item : Gtk_Menu_Item; begin Item := Gtk_Menu_Item_New_With_Mnemonic ("_Add"); Menu.Append (Item); Item := Gtk_Menu_Item_New_With_Mnemonic ("_Edit"); Menu.Append (Item); Item := Gtk_Menu_Item_New_With_Mnemonic ("_Delete"); Menu.Append (Item); Table_Item.Set_Submenu (Menu); end On_Menu_Table; procedure On_Quit (Self : access Gtk.Menu_Item.Gtk_Menu_Item_Record'Class) is pragma Unreferenced (Self); begin Ada.Text_IO.Put_Line ("On_Quit"); end On_Quit; function Gtk_New return Gtk.Window.Gtk_Window is use Gtk.Menu; use Gtk.Menu_Item; Main_Window : constant Gtk.Window.Gtk_Window := Gtk.Window.Gtk_Window_New; Menu_Bar : constant Gtk.Menu_Bar.Gtk_Menu_Bar := Gtk.Menu_Bar.Gtk_Menu_Bar_New; Menu : constant Gtk_Menu := Gtk_Menu_New; Item : Gtk_Menu_Item; begin Main_Window.On_Destroy (On_Window_Destroy'Access); Item := Gtk_Menu_Item_New_With_Mnemonic ("_Quit"); Item.On_Activate (On_Quit'Access); Menu.Append (Item); Item := Gtk_Menu_Item_New_With_Mnemonic ("_File"); Item.Set_Submenu (Menu); Menu_Bar.Append (Item); Item := Gtk_Menu_Item_New_With_Mnemonic ("_Table"); -- Submenu computed in On_Menu_Table -- Item.On_Activate (On_Menu_Table'Access); Item.On_Select (On_Menu_Table'Access); Menu_Bar.Append (Item); Menu_Bar.Show_All; Main_Window.Add (Menu_Bar); return Main_Window; end Gtk_New; end Menu_Demo_Pkg; pragma License (GPL); with Gtk.Window; package Menu_Demo_Pkg is function Gtk_New return Gtk.Window.Gtk_Window; end Menu_Demo_Pkg; pragma License (GPL); with Ada.Exceptions; with Ada.Text_IO; with GNAT.Traceback.Symbolic; with Gtk.Main; with Gtk.Window; with Menu_Demo_Pkg; procedure Menu_Demo is Main_Window : Gtk.Window.Gtk_Window; begin Gtk.Main.Init; Main_Window := Menu_Demo_Pkg.Gtk_New; Main_Window.Show; Gtk.Main.Main; exception when E : others => Ada.Text_IO.Put_Line ("Unhandled exception " & Ada.Exceptions.Exception_Name (E) & ": " & Ada.Exceptions.Exception_Message (E)); Ada.Text_IO.Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E)); end Menu_Demo; If I use "On_Activate" for On_Menu_Table, the submenu is not shown. So I tried "On_Select"; still no submenu, and it crashes with (menu_demo.exe:5884): Gtk-WARNING **: GtkWindow 001915B0 is mapped but visible child GtkMenu 08B2C468 is not mapped I know how to compute a dynamic submenu in Emacs and Win32; there must be a way to do this in Gtk. -- Stephe