-----------------------------------------------------------------------
--          GtkAda - Ada95 binding for the Gimp Toolkit              --
--                                                                   --
--                     Copyright (C) 1998-1999                       --
--        Emmanuel Briot, Joel Brobecker and Arnaud Charlet          --
--                                                                   --
-- Item_Factory Copyright (c) 1999 by Martin C. Carlisle             --
--                                    carlislem@acm.org              --
--                                                                   --
-- This library is free software; you can redistribute it and/or     --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This library 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 along with this library; if not, write to the             --
-- Free Software Foundation, Inc., 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.     --
-----------------------------------------------------------------------
package body Gtk.Item_Factory is

   -----------------
   -- Create_Item --
   -----------------

   procedure Create_Item
     (Factory_Entry  : access Gtk_Item_Factory_Entry_Record;
      Factory        : access Gtk_Item_Factory_Record'Class)
   is
      procedure Internal(
         Ifactory      : System.Address;
         IEntry        : System.Address;
         Callback_Data : System.Address;
         Callback_Type : Glib.Guint);
      pragma Import(C,Internal,"gtk_item_factory_create_item");
   begin
      ada.text_io.put_line(interfaces.c.strings.value(factory_entry.path));
      Internal(Get_Object(Factory),
         Factory_Entry.all'Address,System.Null_Address,1);
   end Create_Item;

   ------------------
   -- Delete_Entry --
   ------------------

   procedure Delete_Entry
     (Factory_Entry  : access Gtk_Item_Factory_Entry_Record;
      Factory        : access Gtk_Item_Factory_Record'Class)
   is
      procedure Internal(
         Ifactory : System.Address;
         IEntry   : System.Address);
      pragma Import(C,Internal,"gtk_item_factory_delete_entry");
   begin
      Internal(Get_Object(Factory),Factory_Entry.all'Address);
   end Delete_Entry;

   -----------------
   -- Delete_Item --
   -----------------

   procedure Delete_Item
     (Factory        : access Gtk_Item_Factory_Record;
      Path           : in     String)
   is
      procedure Internal(
         Ifactory : System.Address;
         Path     : String);
      pragma Import(C,Internal,"gtk_item_factory_delete_item");
   begin
      Internal(Get_Object(Factory),Path & ASCII.NUL);
   end Delete_Item;

   ----------------
   -- Get_Widget --
   ----------------

   function Get_Widget
     (Factory        : access Gtk_Item_Factory_Record;
      Path           : in     String)
      return Gtk.Widget.Gtk_Widget
   is
      function Gtk_Item_Factory_Get_Widget(
         Ifactory : System.Address;
         Path     : String) return System.Address;
      pragma Import(C,gtk_item_factory_get_widget,
         "gtk_item_factory_get_widget");
      Value : System.Address;
      Stub : Gtk.Widget.Gtk_Widget_Record;
   begin
      Value := Gtk_Item_Factory_Get_Widget (
         Get_Object(Factory), Path & ASCII.NUL);
      return Gtk.Widget.Gtk_Widget (Get_User_Data (Value, Stub));
   end Get_Widget;

   -------------
   -- Gtk_New --
   -------------

   procedure Gtk_New
     (Factory        :    out Gtk_Item_Factory;
      Container_Type : in     Gtk.Enums.Gtk_Menu_Factory_Type;
      Path           : in     String;
      Accel_Group    : in     Gtk.Accel_Group.Gtk_Accel_Group'Class)
   is
   begin
      Factory := new Gtk_Item_Factory_Record;
      Initialize(Factory,Container_Type,Path,Accel_Group);
   end Gtk_New;

   -------------
   -- Gtk_New --
   -------------

   procedure Gtk_New
     (Factory_Entry  :    out Gtk_Item_Factory_Entry;
      Path           : in     String;
      Accelerator    : in     String;
      Callback       : in     Gtk_Item_Factory_Callback;
      Item_Type      : in     Item_Type_Enum)
   is
   begin
      Factory_Entry := new Gtk_Item_Factory_Entry_Record;
      Initialize(Factory_Entry,Path,Accelerator,Callback,Item_Type);
   end Gtk_New;

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize
     (Factory        : access Gtk_Item_Factory_Record;
      Container_Type : in     Gtk.Enums.Gtk_Menu_Factory_Type;
      Path           : in     String;
      Accel_Group    : in     Gtk.Accel_Group.Gtk_Accel_Group'Class)
   is
      function Gtk_Option_Menu_Get_Type return Glib.Guint;
      pragma Import(C,Gtk_Option_Menu_Get_Type,"gtk_option_menu_get_type");
      function Gtk_Menu_Bar_Get_Type return Glib.Guint;
      pragma Import(C,Gtk_Menu_Bar_Get_Type,"gtk_menu_bar_get_type");
      function Gtk_Menu_Get_Type return Glib.Guint;
      pragma Import(C,Gtk_Menu_Get_Type,"gtk_menu_get_type");
      function Gtk_Item_Factory_New(
         Container_Type : Glib.Guint;
         Path           : String;
         Accel_Group    : System.Address) return System.Address;
      pragma Import(C,Gtk_Item_Factory_New,"gtk_item_factory_new");
      Gtk_Type : Glib.Guint;
      use Gtk.Enums;
   begin
      case Container_Type is
         when Menu_Factory_Option_Menu =>
            Gtk_Type := Gtk_Option_Menu_Get_Type;
         when Menu_Factory_Menu_Bar =>
            Gtk_Type := Gtk_Menu_Bar_Get_Type;
         when Menu_Factory_Menu =>
            Gtk_Type := Gtk_Menu_Get_Type;
      end case;
      Set_Object(Factory,
         Gtk_Item_Factory_New(
            Gtk_Type,
            Path & ASCII.NUL,
            Get_Object(Accel_Group)));
   end Initialize;

   Item_Types : array(Item_Type_Enum) of Interfaces.C.Strings.Chars_Ptr :=
     (Title       => Interfaces.C.Strings.New_String("<Title>"),
      Item        => Interfaces.C.Strings.New_String("<Item>"),
      Check_Item  => Interfaces.C.Strings.New_String("<CheckItem>"),
      Toggle_Item => Interfaces.C.Strings.New_String("<ToggleItem>"),
      Radio_Item  => Interfaces.C.Strings.New_String("<RadioItem>"),
      Separator   => Interfaces.C.Strings.New_String("<Separator>"),
      Branch      => Interfaces.C.Strings.New_String("<Branch>"),
      Last_Branch => Interfaces.C.Strings.New_String("<LastBranch>"));

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize
     (Factory_Entry  : access Gtk_Item_Factory_Entry_Record;
      Path           : in     String;
      Accelerator    : in     String;
      Callback       : in     Gtk_Item_Factory_Callback;
      Item_Type      : in     Item_Type_Enum)
   is
   begin
      Factory_Entry.Path        := Interfaces.C.Strings.New_String(Path);
      Factory_Entry.Accelerator := Interfaces.C.Strings.New_String(Accelerator);
      Factory_Entry.Callback    := Callback;
      Factory_Entry.Item_Type   := Item_Types(Item_Type);
   end Initialize;

end Gtk.Item_Factory;

