------------------------------------------------------------------------------
--                                                                          --
--                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: 3791 $ $Date: 2010-10-28 19:45:44 +0400 (Thu, 28 Oct 2010) $
------------------------------------------------------------------------------
with Qt_Ada.Internals.Events.Registry;

package body Qt4.Events is

   procedure accept_wrapper
    (Self : not null access Qt_Ada.Internals.Events.QEvent);
   pragma Import (C, accept_wrapper, "__Qt4Ada_QEvent_accept_wrapper");

   procedure ignore_wrapper
    (Self : not null access Qt_Ada.Internals.Events.QEvent);
   pragma Import (C, ignore_wrapper, "__Qt4Ada_QEvent_ignore_wrapper");

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

   procedure set_accepted_wrapper
    (Self  : not null access Qt_Ada.Internals.Events.QEvent;
     Value : Qt4.bool);
   pragma Import (C,
                  set_accepted_wrapper,
                  "__Qt4Ada_QEvent_set_accepted_wrapper");

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

   function type_wrapper
    (Self : not null access Qt_Ada.Internals.Events.QEvent)
       return Interfaces.C.int;
   pragma Import (C, type_wrapper, "__Qt4Ada_QEvent_type_wrapper");

   ------------------
   -- Accept_Event --
   ------------------

   procedure Accept_Event (Self : not null access Q_Event'Class) is
   begin
      accept_wrapper (Self.QEvent_View);
   end Accept_Event;

   ------------
   -- Ignore --
   ------------

   procedure Ignore (Self : not null access Q_Event'Class) is
   begin
      ignore_wrapper (Self.QEvent_View);
   end Ignore;

   ---------------
   -- Internals --
   ---------------

   package body Internals is

      -------------------------
      -- Create_Null_Wrapper --
      -------------------------

      function Create_Null_Wrapper
       (Cpp_Object : access Qt_Ada.Internals.Events.QEvent)
          return access Q_Event'Class is
      begin
         if Cpp_Object = null then
            return null;

         else
            return
              Qt_Ada.Internals.Events.Registry.Create_Wrapper (Cpp_Object);
         end if;
      end Create_Null_Wrapper;

      ------------------
      -- Create_Event --
      ------------------

      function Create_Event
       (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_Event
         do
            Qt_Ada.Internals.Events.Initialize (Result, Object);
         end return;
      end Create_Event;

   end Internals;

   -----------------
   -- Is_Accepted --
   -----------------

   function Is_Accepted (Self : not null access constant Q_Event'Class)
     return Boolean
   is
   begin
      return Qt4.To_Boolean (is_accepted_wrapper (Self.QEvent_View));
   end Is_Accepted;

   ------------------
   -- Set_Accepted --
   ------------------

   procedure Set_Accepted
    (Self  : not null access Q_Event'Class;
     Value : Boolean) is
   begin
      set_accepted_wrapper (Self.QEvent_View, Qt4.To_bool (Value));
   end Set_Accepted;

   -----------------
   -- Spontaneous --
   -----------------

   function Spontaneous (Self : not null access constant Q_Event'Class)
     return Boolean
   is
   begin
      return To_Boolean (spontaneous_wrapper (Self.QEvent_View));
   end Spontaneous;

   -------------------
   -- Type_Of_Event --
   -------------------

   function Type_Of_Event (Self : not null access constant Q_Event'Class)
     return Event_Type
   is
   begin
      return Event_Type (type_wrapper (Self.QEvent_View));
   end Type_Of_Event;

end Qt4.Events;
