-------------------------------------------------------------------
--           RAPID - RAPID ADA PORTABLE INTERFACE DESIGNER         
--           MCC GUI PACKAGE LIBRARY                               
--           Copyright (C) 1999 Martin C. Carlisle.                
--                                                                 
-- RAPID is free software; you can redistribute it and/or modify
-- it under terms of the GNU General Public License as published  
-- by the Free Software Foundation; either version 2, or (at your
-- option) any later version.  RAPID is distributed in the hope that 
-- it will be useful, but WITHOUT ANY WARRANTY; without even the 
-- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE.  See the GNU General Public License for more details.  
-- You should have received a copy of the GNU General Public License
-- distributed with RAPID; see file COPYING.  If not, write to the 
-- Free Software Foundation,  59 Temple Place - Suite 330,  Boston, 
-- MA 02111-1307, USA.                                                 
--                                                                     
-- As a special exception, if other files instantiate generics from
-- this unit, or you link this unit with other files to produce an 
-- executable, this unit does not by itself cause the resulting 
-- executable to be covered by the GNU General Public License.  
-- This exception does not however invalidate any other reasons 
-- why the executable file might be covered by the GNU Public 
-- License.  This exception does not apply to executables which
-- are GUI design tools, or that could act as a replacement
-- for RAPID.
------------------------------------------------------------------------------
with Gdk;
with Glib;
with gtk.accel_group;
with Gtk.Box;
with Gtk.Fixed;
with gtk.menu;
with gtk.menu_item;
with gtk.menu_bar;
with Gtk.Widget;
with Mcc.Gui.Container.Window;
with Peer.Frame;
use Peer.Frame;
with System;
with ada.text_io;
package body Mcc.Gui.Menu is

   ----------------
   -- Add_Choice --
   ----------------

   procedure Add_Choice(Obj         : in out Choice;
                         To_Menu     : in     Menu'Class;
                         Text        : in     String;
                         Action      : in     Menu_Callback;
                         Underline   : in     Natural;
                         Accelerator : in     String := "")is
   begin
      null;
   end Add_Choice;

   ----------------
   -- Add_Choice --
   ----------------

   procedure Add_Choice(Obj         : in out Choice;
                        To_Menu     : in     Menu'Class;
                        Text        : in     String;
                        Action      : in     Menu_Callback;
                        Underline   : in     Natural;
                        Location    : in     Natural;
                        Accelerator : in     String := "")is
   begin
      null;
   end Add_Choice;

   -----------------
   -- Add_Submenu --
   -----------------

   procedure Add_Submenu(Obj         : in out Submenu;
                         Text        : in     String;
                         Underline   : in     Natural;
                         Parent_Menu : in     Menu'Class;
                         On_Post     : in     Menu_Callback := null)is

      submenu_item : gtk.menu_item.Gtk_Menu_Item;
      new_submenu  : gtk.menu.gtk_menu;
      accel_group  : gtk.accel_group.Gtk_Accel_Group;
      Underlines   : String(1..Text'Length) := (others => '_');

   begin
      if Underline > 0 and Underline <= Text'Length then
         Underlines(Underline) := '_';
         Underlines(Underline+1) := '_';
      end if;
      
      gtk.menu_item.Gtk_New(menu_item => submenu_item,
                            Label     => Text);
      gtk.menu_bar.append(Menu_bar  => gtk.menu_bar.gtk_menu_bar(parent_menu.my_peer),
                          Child     => submenu_item);
      gtk.menu_item.show(submenu_item);
      declare
         Label    : Gtk.Widget.Gtk_Widget;
         Children : Gtk.Widget.Widget_List.Glist;
         use Gtk.Widget;
      begin
         children := gtk.menu_item.children(submenu_item);
         -- all good C programmers have a 0th child
         Label := gtk.widget.widget_list.nth_data(children,0);
         Set_Pattern(Label,Underlines);
      end;
      --Add the submenu to the label
      gtk.menu.Gtk_New(Widget => new_submenu);
      gtk.menu_item.Set_Submenu(Menu_Item => submenu_item,
                                Submenu   => new_submenu);
--                                
--      --Add the accel key to the submenu
--      gtk.accel_group.Gtk_New(Widget => accel_group);

--      gtk.accel_group.Attach(Accel_Group => accel_group,
--                             Object      => gtk.menu_bar.Get_Window(
--                                                          gtk.menu_bar.gtk_menu_bar(parent_menu.my_peer)));

----      gtk.menu_item.Add_Accelerator(Widget => submenu_item,
----                                    Accel_Signal => "activate",
----                                    Accel_Group  => accel_group,
----                                    Accel_Key    => in Gdk.Types.Gdk_Key_Type;
----                                    Accel_Mods   => in Gdk.Types.Gdk_Modifier_Type;
----                                    Accel_Flags  => in Gtk.Accel_Group.Gtk_Accel_Flags);
--      
--      Obj.My_Peer := gdk.root_type_access(new_submenu);
   end Add_Submenu;

   -----------------
   -- Add_Submenu --
   -----------------

   procedure Add_Submenu(Obj         : in out Submenu;
                         Text        : in     String;
                         Underline   : in     Natural;
                         Parent_Menu : in     Menu'Class;
                         Location    : in     Natural;
                         On_Post     : in     Menu_Callback := null)is
   begin
      null;
   end Add_Submenu;

   ------------
   -- Create --
   ------------

   procedure Create(Obj    : in out Window_Menu;
                    Window : in     Mcc.Gui.Container.Container'Class)is

      Item_Factory : Gtk.Item_Factory.Gtk_Item_Factory;
   begin
      gtk.Item_Factory.Gtk_New(
         Factory => Item_Factory,
         );
      
      if Window in Mcc.Gui.Container.Window.Window'Class then
         gtk.box.Pack_Start(
            In_Box  => gtk.box.Gtk_Vbox(
               Gtk.Widget.Get_Parent(Gtk.Widget.Gtk_Widget(window.my_peer))),
            Child   => menu_bar);  
      else
         gtk.box.Pack_Start(
            In_Box  => Gtk.Box.Gtk_Vbox(
               Gtk.Fixed.Get_Parent(Mcc_Frame(window.my_peer).Fixed)),
            Child   => menu_bar);  
      end if;
      Gtk.Menu_Bar.Show(Menu_Bar);
      --Have Object point to menu bar Widget
      Obj.My_Peer := gdk.root_type_access(menu_bar);
      
   end Create;

   ------------
   -- Delete --
   ------------

   procedure Delete (Obj : in out Menu_Item) is
   begin
      null;
   end Delete;

   -------------
   -- Disable --
   -------------

   procedure Disable (Obj : in out Choice) is
   begin
      null;
   end Disable;

   ------------
   -- Enable --
   ------------

   procedure Enable (Obj : in out Choice) is
   begin
      null;
   end Enable;

   procedure Add_Separator(
      Obj         : in out Separator;
      To_Menu     : in     Menu'Class) is
   begin
      null;
   end;
      
   procedure Add_Separator(
      Obj         : in out Separator;
      To_Menu     : in     Menu'Class;
      Location    : in     Natural) is
   begin
      null;
   end;

end Mcc.Gui.Menu;

