-------------------------------------------------------------------
--           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.Types;
use type Gdk.Types.Gdk_Event_Mask;
with glib; use glib;
with Gtk.Box;
with Gtk.Container;
with Gtk.Fixed;
with Gtk.Frame;
with Gtk.Widget;
with gdk;
with Peer.Frame;
use Peer.Frame;

package body Mcc.Gui.Container.Frame is
   
   ------------
   -- Create --
   ------------

   procedure Create(Obj          : in out Frame;
                    Parent       : in     Container'Class;
                    X            : in     Integer;
                    Y            : in     Integer;
                    Width        : in     Natural;
                    Height       : in     Natural;
                    Border_Width : in     Natural := 1)
   is
      Frame_Container : Mcc_Frame;
      Vbox            : Gtk.Box.Gtk_Vbox;
   begin
      Obj.Key_Handler := null;
      Obj.Mouse_Handler := null;
      
      Frame_Container := new Mcc_Frame_Record;
      --Create new fixed 
      Gtk.Frame.Gtk_New(Frame_Container.Frame);
      Gtk.Box.Gtk_New_Vbox(
         Box         => Vbox,
         Homogeneous => False,
         Spacing     => 0);
      Gtk.Frame.Add(
        Container => Frame_Container.Frame, 
        Widget    => Vbox);
      Gtk.Box.Show(Vbox);

      --Add Frame to window
      Gtk.Fixed.Initialize(Gtk.Fixed.Gtk_Fixed(Frame_Container));
      -- We must set the event mask first, because it must be done
      -- before the widget is "realized" (whatever that means).
      Gtk.Widget.Set_Events(
         Widget => Gtk.Widget.Gtk_Widget(Frame_Container),
         Events => Gdk.Types.Button_Motion_Mask +
            Gdk.Types.Button_Press_Mask +
            Gdk.Types.Button_Release_Mask +
            Gdk.Types.Key_Release_Mask +
            Gdk.Types.Key_Press_Mask +
            Gdk.Types.Pointer_Motion_Mask
            );
      Gtk.Box.Pack_End(
        In_Box  => Vbox, 
        Child   => Gtk.Fixed.Gtk_Fixed(Frame_Container),
        Expand  => True,
        Fill    => True,
        Padding => 0);
      Gtk.Fixed.Show(Gtk.Fixed.Gtk_Fixed(Frame_Container));
      
      --Set border width
      if Border_Width /= 0 then
         gtk.Frame.Set_Border_Width(
            Container    => Frame_Container.Frame,
            Border_Width => Gint(Border_Width));
      end if;

      --Have Object point to fixed Container Frame
      Obj.My_Peer := gtk.root_type_access(Frame_Container);

      --Set smallest size possible, can grow but won't shink any smaller
      Gtk.Widget.Set_USize (
         Widget => Gtk.Widget.Gtk_Widget(Frame_Container.Frame), 
         Width  => Glib.Gint(Width),
         Height => Glib.Gint(Height));
         
      Gtk.Fixed.Put(Fixed  => Gtk.Fixed.Gtk_Fixed(Parent.My_Peer),
                    Widget => Gtk.Widget.Gtk_Widget(Frame_Container.Frame),
                    X      => Glib.Gint(X),
                    Y      => Glib.Gint(Y));
      Gtk.Widget.Show(Gtk.Widget.Gtk_Widget(Frame_Container.Frame));
   end Create;

end Mcc.Gui.Container.Frame;
