comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Gtkada: attach signals to menus
Date: Sun, 19 Jun 2016 08:02:04 -0700 (PDT)
Date: 2016-06-19T08:02:04-07:00	[thread overview]
Message-ID: <1df56f78-8ea3-4cdc-aa54-05249464495f@googlegroups.com> (raw)
In-Reply-To: <adda902e-cdbb-4b27-9336-c02b120d4cd9@googlegroups.com>

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

  reply	other threads:[~2016-06-19 15:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-18 17:05 Gtkada: attach signals to menus Stephen Leake
2016-06-18 18:07 ` Dmitry A. Kazakov
2016-06-18 18:21   ` Stephen Leake
2016-06-19 15:02     ` Stephen Leake [this message]
2016-06-19 18:33       ` Dmitry A. Kazakov
2016-06-20  9:18         ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox