------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2009-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 Qt_Ada.Internals.Objects.Object_Utilities;

package body Qt4.List_Of_Q_Objects is

   function initialize_QListOfQObject
    (Storage : System.Address) return Internals.QListOfQObject_Access;
   pragma Import
           (C, initialize_QListOfQObject, "__QtAda_initialize_QListOfQObject");

   function adjust_QListOfQObject
    (Storage : System.Address;
     From    : Internals.QListOfQObject_Access)
       return Internals.QListOfQObject_Access;
   pragma Import (C, adjust_QListOfQObject, "__QtAda_adjust_QListOfQObject");

   procedure finalize_QListOfQObject
    (Object : Internals.QListOfQObject_Access);
   pragma Import
           (C, finalize_QListOfQObject, "__QtAda_finalize_QListOfQObject");

   function QListOfQObject_size
    (Self : not null Internals.QListOfQObject_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QListOfQObject_size, "__QtAda_QListOfQObject_size");

   function QListOfQObject_value_int
    (Self  : not null Internals.QListOfQObject_Access;
     Index : Qt4.Q_Integer)
       return Qt_Ada.Internals.Objects.QObject_Access;
   pragma Import
           (C, QListOfQObject_value_int, "__QtAda_QListOfQObject_value_int");

   ------------
   -- Adjust --
   ------------

   overriding
   procedure Adjust (Self : in out Q_List_Of_Q_Object) is
   begin
      Self.Object := adjust_QListOfQObject (Self.Storage'Address, Self.Object);
      Self.Wrapper := False;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   overriding
   procedure Finalize (Self : in out Q_List_Of_Q_Object) is
   begin
      if not Self.Wrapper then
         finalize_QListOfQObject (Self.Object);
      end if;
   end Finalize;

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

   overriding
   procedure Initialize (Self : in out Q_List_Of_Q_Object) is
      use type Internals.QListOfQObject_Access;

   begin
      if Self.Object = null then
         Self.Object := initialize_QListOfQObject (Self.Storage'Address);
      end if;
   end Initialize;

   ----------
   -- Size --
   ----------

   function Size (Self : Q_List_Of_Q_Object'Class) return Qt4.Q_Integer is
   begin
      return QListOfQObject_size (Self.Object);
   end Size;

   -----------
   -- Value --
   -----------

   function Value
    (Self  : Q_List_Of_Q_Object'Class;
     Index : Qt4.Q_Integer)
       return access Qt4.Objects.Q_Object'Class is
   begin
      return
        Qt_Ada.Internals.Objects.Object_Utilities.Corresponding_Q_Object
         (QListOfQObject_value_int (Self.Object, Index));
   end Value;

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

   package body Internals is

      -------------------------
      -- QListOfQObject_View --
      -------------------------

      function QListOfQObject_View
       (Item : Q_List_Of_Q_Object'Class) return QListOfQObject_Access is
      begin
         return Item.Object;
      end QListOfQObject_View;

   end Internals;

end Qt4.List_Of_Q_Objects;
