------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2007-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.                                      --
--                                                                          --
------------------------------------------------------------------------------
--    This file has been generated automatically. Please don't edit it.     --
------------------------------------------------------------------------------
pragma Style_Checks ("NM32766");
with Qt4.Points;
with Qt4.Polygons;
with System.Address_To_Access_Conversions;

package body Qt4.Regions is

   function initialize_QRegion
    (Storage : System.Address)
      return Internals.QRegion_Access;
   pragma Import (C, initialize_QRegion, "__QtAda_inititialize_QRegion");

   function initialize_QRegion_int_int_int_RegionType
    (Storage : System.Address;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     H : Qt4.Q_Integer;
     T : Region_Type)
      return Internals.QRegion_Access;
   pragma Import (C, initialize_QRegion_int_int_int_RegionType, "__QtAda_inititialize_QRegion_int_int_int_RegionType");

   function initialize_QRegion_QPolygonCR_FillRule
    (Storage : System.Address;
     Pa : Qt4.Polygons.Internals.QPolygon_Access;
     Fill_Rule : Qt4.Fill_Rule)
      return Internals.QRegion_Access;
   pragma Import (C, initialize_QRegion_QPolygonCR_FillRule, "__QtAda_inititialize_QRegion_QPolygonCR_FillRule");

   function initialize_QRegion_QRectR_RegionType
    (Storage : System.Address;
     R : Qt4.Rects.Internals.QRect_Access;
     T : Region_Type)
      return Internals.QRegion_Access;
   pragma Import (C, initialize_QRegion_QRectR_RegionType, "__QtAda_inititialize_QRegion_QRectR_RegionType");

   function adjust_QRegion
    (Storage : System.Address;
     From    : Internals.QRegion_Access)
       return Internals.QRegion_Access;
   pragma Import (C, adjust_QRegion, "__QtAda_adjust_QRegion");

   procedure finalize_QRegion (Object : Internals.QRegion_Access);
   pragma Import (C, finalize_QRegion, "__QtAda_finalize_QRegion");

   procedure QRegion_boundingRect
    (Returns : Qt4.Rects.Internals.QRect_Access;
     Self : Internals.QRegion_Access);
   pragma Import (C, QRegion_boundingRect, "__QtAda_QRegion_boundingRect_Q");

   function QRegion_contains_QPointCR
    (Self : Internals.QRegion_Access;
     P : Qt4.Points.Internals.QPoint_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QRegion_contains_QPointCR, "__QtAda_QRegion_contains_QPointCR_Q");

   function QRegion_contains_QRectCR
    (Self : Internals.QRegion_Access;
     R : Qt4.Rects.Internals.QRect_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QRegion_contains_QRectCR, "__QtAda_QRegion_contains_QRectCR_Q");

   procedure QRegion_intersected_QRegionCR
    (Returns : Internals.QRegion_Access;
     Self : Internals.QRegion_Access;
     R : Internals.QRegion_Access);
   pragma Import (C, QRegion_intersected_QRegionCR, "__QtAda_QRegion_intersected_QRegionCR_Q");

   function QRegion_intersects_QRegionCR
    (Self : Internals.QRegion_Access;
     R : Internals.QRegion_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QRegion_intersects_QRegionCR, "__QtAda_QRegion_intersects_QRegionCR_Q");

   function QRegion_intersects_QRectCR
    (Self : Internals.QRegion_Access;
     R : Qt4.Rects.Internals.QRect_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QRegion_intersects_QRectCR, "__QtAda_QRegion_intersects_QRectCR_Q");

   function QRegion_isEmpty
    (Self : Internals.QRegion_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QRegion_isEmpty, "__QtAda_QRegion_isEmpty_Q");

   procedure QRegion_subtracted_QRegionCR
    (Returns : Internals.QRegion_Access;
     Self : Internals.QRegion_Access;
     R : Internals.QRegion_Access);
   pragma Import (C, QRegion_subtracted_QRegionCR, "__QtAda_QRegion_subtracted_QRegionCR_Q");

   procedure QRegion_translate_int_int
    (Self : Internals.QRegion_Access;
     Dx : Qt4.Q_Integer;
     Dy : Qt4.Q_Integer);
   pragma Import (C, QRegion_translate_int_int, "__QtAda_QRegion_translate_int_int");

   procedure QRegion_translate_QPointCR
    (Self : Internals.QRegion_Access;
     P : Qt4.Points.Internals.QPoint_Access);
   pragma Import (C, QRegion_translate_QPointCR, "__QtAda_QRegion_translate_QPointCR");

   procedure QRegion_translated_int_int
    (Returns : Internals.QRegion_Access;
     Self : Internals.QRegion_Access;
     Dx : Qt4.Q_Integer;
     Dy : Qt4.Q_Integer);
   pragma Import (C, QRegion_translated_int_int, "__QtAda_QRegion_translated_int_int_Q");

   procedure QRegion_translated_QPointCR
    (Returns : Internals.QRegion_Access;
     Self : Internals.QRegion_Access;
     P : Qt4.Points.Internals.QPoint_Access);
   pragma Import (C, QRegion_translated_QPointCR, "__QtAda_QRegion_translated_QPointCR_Q");

   procedure QRegion_united_QRegionCR
    (Returns : Internals.QRegion_Access;
     Self : Internals.QRegion_Access;
     R : Internals.QRegion_Access);
   pragma Import (C, QRegion_united_QRegionCR, "__QtAda_QRegion_united_QRegionCR_Q");

   procedure QRegion_xored_QRegionCR
    (Returns : Internals.QRegion_Access;
     Self : Internals.QRegion_Access;
     R : Internals.QRegion_Access);
   pragma Import (C, QRegion_xored_QRegionCR, "__QtAda_QRegion_xored_QRegionCR_Q");

   function eq_QRegionCR
    (Self : Internals.QRegion_Access;
     R : Internals.QRegion_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QRegionCR, "__QtAda_QRegion_eq_QRegionCR_Q");

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

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

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

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

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

   overriding
   procedure Initialize (Self : in out Q_Region) is
      use type Internals.QRegion_Access;

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

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

   function Create
    (X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     H : Qt4.Q_Integer;
     T : Region_Type
       := Rectangle)
       return Q_Region
   is
   begin
      return Self : Q_Region
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QRegion_int_int_int_RegionType (Self.Storage'Address, X, Y, H, T);
      end return;
   end Create;

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

   function Create
    (Pa : Qt4.Polygons.Q_Polygon'Class;
     Fill_Rule : Qt4.Fill_Rule
       := Odd_Even_Fill)
       return Q_Region
   is
   begin
      return Self : Q_Region
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QRegion_QPolygonCR_FillRule (Self.Storage'Address, Qt4.Polygons.Internals.QPolygon_View (Pa), Fill_Rule);
      end return;
   end Create;

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

   function Create
    (R : Qt4.Rects.Q_Rect'Class;
     T : Region_Type
       := Rectangle)
       return Q_Region
   is
   begin
      return Self : Q_Region
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QRegion_QRectR_RegionType (Self.Storage'Address, Qt4.Rects.Internals.QRect_View (R), T);
      end return;
   end Create;

   -------------------
   -- Bounding_Rect --
   -------------------

   function Bounding_Rect
    (Self : Q_Region'Class)
       return Qt4.Rects.Q_Rect
   is
   begin
      return Returns : Qt4.Rects.Q_Rect do
         QRegion_boundingRect (Qt4.Rects.Internals.QRect_View (Returns), Self.Object);
      end return;
   end Bounding_Rect;

   --------------
   -- Contains --
   --------------

   function Contains
    (Self : Q_Region'Class;
     P : Qt4.Points.Q_Point'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QRegion_contains_QPointCR (Self.Object, Qt4.Points.Internals.QPoint_View (P)), 0);
   end Contains;

   --------------
   -- Contains --
   --------------

   function Contains
    (Self : Q_Region'Class;
     R : Qt4.Rects.Q_Rect'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QRegion_contains_QRectCR (Self.Object, Qt4.Rects.Internals.QRect_View (R)), 0);
   end Contains;

   -----------------
   -- Intersected --
   -----------------

   function Intersected
    (Self : Q_Region'Class;
     R : Q_Region'Class)
       return Q_Region
   is
   begin
      return Returns : Q_Region do
         QRegion_intersected_QRegionCR (Returns.Object, Self.Object, R.Object);
      end return;
   end Intersected;

   ----------------
   -- Intersects --
   ----------------

   function Intersects
    (Self : Q_Region'Class;
     R : Q_Region'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QRegion_intersects_QRegionCR (Self.Object, R.Object), 0);
   end Intersects;

   ----------------
   -- Intersects --
   ----------------

   function Intersects
    (Self : Q_Region'Class;
     R : Qt4.Rects.Q_Rect'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QRegion_intersects_QRectCR (Self.Object, Qt4.Rects.Internals.QRect_View (R)), 0);
   end Intersects;

   --------------
   -- Is_Empty --
   --------------

   function Is_Empty
    (Self : Q_Region'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QRegion_isEmpty (Self.Object), 0);
   end Is_Empty;

   ----------------
   -- Subtracted --
   ----------------

   function Subtracted
    (Self : Q_Region'Class;
     R : Q_Region'Class)
       return Q_Region
   is
   begin
      return Returns : Q_Region do
         QRegion_subtracted_QRegionCR (Returns.Object, Self.Object, R.Object);
      end return;
   end Subtracted;

   ---------------
   -- Translate --
   ---------------

   procedure Translate
    (Self : in out Q_Region'Class;
     Dx : Qt4.Q_Integer;
     Dy : Qt4.Q_Integer)
   is
   begin
      QRegion_translate_int_int (Self.Object, Dx, Dy);
   end Translate;

   ---------------
   -- Translate --
   ---------------

   procedure Translate
    (Self : in out Q_Region'Class;
     P : Qt4.Points.Q_Point'Class)
   is
   begin
      QRegion_translate_QPointCR (Self.Object, Qt4.Points.Internals.QPoint_View (P));
   end Translate;

   ----------------
   -- Translated --
   ----------------

   function Translated
    (Self : Q_Region'Class;
     Dx : Qt4.Q_Integer;
     Dy : Qt4.Q_Integer)
       return Q_Region
   is
   begin
      return Returns : Q_Region do
         QRegion_translated_int_int (Returns.Object, Self.Object, Dx, Dy);
      end return;
   end Translated;

   ----------------
   -- Translated --
   ----------------

   function Translated
    (Self : Q_Region'Class;
     P : Qt4.Points.Q_Point'Class)
       return Q_Region
   is
   begin
      return Returns : Q_Region do
         QRegion_translated_QPointCR (Returns.Object, Self.Object, Qt4.Points.Internals.QPoint_View (P));
      end return;
   end Translated;

   ------------
   -- United --
   ------------

   function United
    (Self : Q_Region'Class;
     R : Q_Region'Class)
       return Q_Region
   is
   begin
      return Returns : Q_Region do
         QRegion_united_QRegionCR (Returns.Object, Self.Object, R.Object);
      end return;
   end United;

   -----------
   -- Xored --
   -----------

   function Xored
    (Self : Q_Region'Class;
     R : Q_Region'Class)
       return Q_Region
   is
   begin
      return Returns : Q_Region do
         QRegion_xored_QRegionCR (Returns.Object, Self.Object, R.Object);
      end return;
   end Xored;

   ---------
   -- "=" --
   ---------

   function "="
    (Self : Q_Region;
     R : Q_Region)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (eq_QRegionCR (Self.Object, R.Object), 0);
   end "=";

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

   package body Internals is

   ------------------
   -- QRegion_View --
   ------------------

      function QRegion_View
       (Item : Q_Region'Class)
          return QRegion_Access
      is
      begin
         return Item.Object;
      end QRegion_View;

      package QRegion_Conversions is
        new System.Address_To_Access_Conversions
             (QRegion);

   -----------------------
   -- QRegionTo_Pointer --
   -----------------------

      function To_Pointer
       (Address : System.Address)
          return QRegion_Access
      is
      begin
         return
           QRegion_Access
            (QRegion_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   -----------------------
   -- QRegionTo_Address --
   -----------------------

      function To_Address
       (Pointer : QRegion_Access)
          return System.Address
      is
      begin
         return
           QRegion_Conversions.To_Address
            (QRegion_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

   --------------------
   -- Create_Wrapper --
   --------------------

      function Create_Wrapper
       (Item : Internals.QRegion_Access)
          return Q_Region
      is
      begin
         return Q_Region'
          (Ada.Finalization.Controlled with
             Object  => Item,
             Wrapper => True,
             others  => <>);
      end Create_Wrapper;

   end Internals;

end Qt4.Regions;
