------------------------------------------------------------------------------
--                                                                          --
--                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: 3769 $ $Date: 2010-10-24 03:16:28 +0400 (Sun, 24 Oct 2010) $
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with Interfaces.C.Strings;

with Qt4.Objects;
with Qt_Ada.Internals.Objects;

package body Qt4.Meta_Objects is

   function invokeMethod_wrapper
    (Object     : not null access Qt_Ada.Internals.Objects.QObject;
     Member     : Interfaces.C.char_array;
     The_Type   : Qt4.Connection_Type;
     Ret_Name   : access constant Interfaces.C.char;
     Ret_Data   : System.Address;
     Val_0_Name : access constant Interfaces.C.char;
     Val_0_Data : System.Address;
     Val_1_Name : access constant Interfaces.C.char;
     Val_1_Data : System.Address;
     Val_2_Name : access constant Interfaces.C.char;
     Val_2_Data : System.Address;
     Val_3_Name : access constant Interfaces.C.char;
     Val_3_Data : System.Address;
     Val_4_Name : access constant Interfaces.C.char;
     Val_4_Data : System.Address;
     Val_5_Name : access constant Interfaces.C.char;
     Val_5_Data : System.Address;
     Val_6_Name : access constant Interfaces.C.char;
     Val_6_Data : System.Address;
     Val_7_Name : access constant Interfaces.C.char;
     Val_7_Data : System.Address;
     Val_8_Name : access constant Interfaces.C.char;
     Val_8_Data : System.Address;
     Val_9_Name : access constant Interfaces.C.char;
     Val_9_Data : System.Address)
       return bool;
   pragma Import
    (C, invokeMethod_wrapper, "__Qt4Ada_QMetaObject_invokeMethod_wrapper");

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> ConnectSlotsByName_wrapper
   --!    <ImplementationNotes>
   ---------------------------------------------------------------------------
   procedure ConnectSlotsByName_wrapper
    (Object : access Qt_Ada.Internals.Objects.QObject);
   pragma Import (C,
                  ConnectSlotsByName_wrapper,
                  "__Qt4Ada_QMetaObject_connectSlotsByName_wrapper");

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Class_Name
   --!    <ImplementationNotes>
   ---------------------------------------------------------------------------
   function Class_Name (Self : not null access constant Q_Meta_Object)
     return String
   is
      type char_constant_access is access constant Interfaces.C.char;
      pragma Convention (C, char_constant_access);

      function To_chars_ptr is
        new Ada.Unchecked_Conversion (char_constant_access,
                                      Interfaces.C.Strings.chars_ptr);

   begin
      return
        Interfaces.C.Strings.Value
         (To_chars_ptr (char_constant_access (Self.String_Data)));
   end Class_Name;

   ---------------------------
   -- Connect_Slots_By_Name --
   ---------------------------

   procedure Connect_Slots_By_Name
    (Object : not null access Qt4.Objects.Q_Object'Class)
   is
   begin
      ConnectSlotsByName_wrapper (Object.QObject_View);
   end Connect_Slots_By_Name;

   -------------------
   -- Invoke_Method --
   -------------------

   procedure Invoke_Method
    (Object   : not null access Qt4.Objects.Q_Object'Class;
     Member   : String;
     The_Type : Qt4.Connection_Type;
     Returns  : Qt4.Generic_Return_Arguments.Q_Generic_Return_Argument;
     Val_0    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_1    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_2    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_3    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_4    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_5    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_6    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_7    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_8    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_9    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument)
   is
   begin
      if not invokeMethod_wrapper
              (Object.QObject_View,
               Interfaces.C.To_C (Member),
               The_Type,
               Qt4.Generic_Return_Arguments.Internals.Name (Returns),
               Qt4.Generic_Return_Arguments.Data (Returns),
               Qt4.Generic_Arguments.Internals.Name (Val_0),
               Qt4.Generic_Arguments.Data (Val_0),
               Qt4.Generic_Arguments.Internals.Name (Val_1),
               Qt4.Generic_Arguments.Data (Val_1),
               Qt4.Generic_Arguments.Internals.Name (Val_2),
               Qt4.Generic_Arguments.Data (Val_2),
               Qt4.Generic_Arguments.Internals.Name (Val_3),
               Qt4.Generic_Arguments.Data (Val_3),
               Qt4.Generic_Arguments.Internals.Name (Val_4),
               Qt4.Generic_Arguments.Data (Val_4),
               Qt4.Generic_Arguments.Internals.Name (Val_5),
               Qt4.Generic_Arguments.Data (Val_5),
               Qt4.Generic_Arguments.Internals.Name (Val_6),
               Qt4.Generic_Arguments.Data (Val_6),
               Qt4.Generic_Arguments.Internals.Name (Val_7),
               Qt4.Generic_Arguments.Data (Val_7),
               Qt4.Generic_Arguments.Internals.Name (Val_8),
               Qt4.Generic_Arguments.Data (Val_8),
               Qt4.Generic_Arguments.Internals.Name (Val_9),
               Qt4.Generic_Arguments.Data (Val_9))
      then
         raise Invoke_Error;
      end if;
   end Invoke_Method;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Invoke_Method
   --!    <ImplementationNotes>
   ---------------------------------------------------------------------------
   procedure Invoke_Method
    (Object   : not null access Qt4.Objects.Q_Object'Class;
     Member   : String;
     Returns  : Qt4.Generic_Return_Arguments.Q_Generic_Return_Argument;
     Val_0    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_1    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_2    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_3    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_4    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_5    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_6    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_7    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_8    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_9    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument)
   is
   begin
      Invoke_Method
       (Object,
        Member,
        Qt4.Auto_Connection,
        Returns,
        Val_0,
        Val_1,
        Val_2,
        Val_3,
        Val_4,
        Val_5,
        Val_6,
        Val_7,
        Val_8,
        Val_9);
   end Invoke_Method;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Invoke_Method
   --!    <ImplementationNotes>
   ---------------------------------------------------------------------------
   procedure Invoke_Method
    (Object   : not null access Qt4.Objects.Q_Object'Class;
     Member   : String;
     The_Type : Qt4.Connection_Type;
     Val_0    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_1    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_2    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_3    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_4    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_5    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_6    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_7    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_8    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_9    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument)
   is
   begin
      Invoke_Method
       (Object,
        Member,
        The_Type,
        Qt4.Generic_Return_Arguments.No_Return_Argument,
        Val_0,
        Val_1,
        Val_2,
        Val_3,
        Val_4,
        Val_5,
        Val_6,
        Val_7,
        Val_8,
        Val_9);
   end Invoke_Method;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Invoke_Method
   --!    <ImplementationNotes>
   ---------------------------------------------------------------------------
   procedure Invoke_Method
    (Object   : not null access Qt4.Objects.Q_Object'Class;
     Member   : String;
     Val_0    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_1    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_2    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_3    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_4    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_5    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_6    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_7    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_8    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument;
     Val_9    : Qt4.Generic_Arguments.Q_Generic_Argument
       := Qt4.Generic_Arguments.No_Argument)
   is
   begin
      Invoke_Method
       (Object,
        Member,
        Qt4.Auto_Connection,
        Qt4.Generic_Return_Arguments.No_Return_Argument,
        Val_0,
        Val_1,
        Val_2,
        Val_3,
        Val_4,
        Val_5,
        Val_6,
        Val_7,
        Val_8,
        Val_9);
   end Invoke_Method;

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

   package body Internals is

      --  Пакет содержит недокументированные подпрограммы класса QMetaClass,
      --  используемые в частности компилятором метаинформации.

      ------------------------------------------------------------------------
      --! <Subprogram>
      --!    <Unit> Activate
      --!    <Purpose> Связка для функции QMetaObject::activate.
      --!    <Exceptions>
      ------------------------------------------------------------------------
      procedure activate_wrapper
       (Sender             : not null access Qt_Ada.Internals.Objects.QObject;
        Meta               : not null access constant Q_Meta_Object;
        Local_Signal_Index : Q_Integer;
        Arguments          : System.Address);
      pragma Import (C, activate_wrapper,
                     "__Qt4Ada_QMetaObject_activate_wrapper");

      --------------
      -- Activate --
      --------------

      procedure Activate
       (Sender             : not null access Qt4.Objects.Q_Object'Class;
        Meta               : not null access constant Q_Meta_Object;
        Local_Signal_Index : Q_Integer;
        Arguments          : System.Address)
      is
      begin
         activate_wrapper
          (Sender.QObject_View,
           Meta,
           Local_Signal_Index,
           Arguments);
      end Activate;

   end Internals;

end Qt4.Meta_Objects;
