------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2008-2010 Vadim Godunko <vgodunko@gmail.com>                 --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT 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 QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, 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.                                      --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 3779 $ $Date: 2010-10-24 14:24:12 +0400 (Sun, 24 Oct 2010) $
------------------------------------------------------------------------------
with Qt_Ada.Internals.Events.Registry;
with Qt_Ada.Internals.Objects.Object_Utilities;

package body Qt4.Child_Events is

   function added_wrapper
    (Self : not null access constant Qt_Ada.Internals.Events.QEvent)
       return Qt4.bool;
   pragma Import (C, added_wrapper, "__Qt4Ada_QChildEvent_added_wrapper");

   function polished_wrapper
    (Self : not null access constant Qt_Ada.Internals.Events.QEvent)
       return Qt4.bool;
   pragma Import
    (C, polished_wrapper, "__Qt4Ada_QChildEvent_polished_wrapper");

   function removed_wrapper
    (Self : not null access constant Qt_Ada.Internals.Events.QEvent)
       return Qt4.bool;
   pragma Import (C, removed_wrapper, "__Qt4Ada_QChildEvent_removed_wrapper");

   function child_wrapper
    (Self : not null access constant Qt_Ada.Internals.Events.QEvent)
       return access Qt_Ada.Internals.Objects.QObject;
   pragma Import (C, child_wrapper, "__Qt4Ada_QChildEvent_child_wrapper");

   function Create
    (Object : not null Qt_Ada.Internals.Events.QEvent_Access)
       return not null Qt4.Events.Q_Event_Access;

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

   function Create
    (Object : not null Qt_Ada.Internals.Events.QEvent_Access)
       return not null Qt4.Events.Q_Event_Access
   is
   begin
      return Result : constant not null Qt4.Events.Q_Event_Access
        := new Q_Child_Event
      do
         Qt_Ada.Internals.Events.Initialize (Result, Object);
      end return;
   end Create;

   -----------
   -- Added --
   -----------

   function Added (Self : not null access constant Q_Child_Event'Class)
     return Boolean
   is
   begin
      return To_Boolean (added_wrapper (Self.QEvent_View));
   end Added;

   -----------
   -- Child --
   -----------

   function Child (Self : not null access constant Q_Child_Event'Class)
     return access Qt4.Objects.Q_Object'Class
   is
   begin
      return
        Qt_Ada.Internals.Objects.Object_Utilities.Corresponding_Q_Object
         (child_wrapper (Self.QEvent_View));
   end Child;

   --------------
   -- Polished --
   --------------

   function Polished (Self : not null access constant Q_Child_Event'Class)
     return Boolean
   is
   begin
      return To_Boolean (polished_wrapper (Self.QEvent_View));
   end Polished;

   -------------
   -- Removed --
   -------------

   function Removed (Self : not null access constant Q_Child_Event'Class)
     return Boolean
   is
   begin
      return To_Boolean (removed_wrapper (Self.QEvent_View));
   end Removed;

begin
   Qt_Ada.Internals.Events.Registry.Register
    (Qt4.Events.Child_Added, Create'Access);
   Qt_Ada.Internals.Events.Registry.Register
    (Qt4.Events.Child_Polished, Create'Access);
   Qt_Ada.Internals.Events.Registry.Register
    (Qt4.Events.Child_Removed, Create'Access);

   --  Событие введено для совместимости с Qt3.
   Qt_Ada.Internals.Events.Registry.Register
    (Qt4.Events.Child_Inserted_Request, Create'Access);
   Qt_Ada.Internals.Events.Registry.Register
    (Qt4.Events.Child_Inserted, Create'Access);
end Qt4.Child_Events;
