------------------------------------------------------------------------------
--                                                                          --
--                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.                                      --
--                                                                          --
------------------------------------------------------------------------------
--    This file has been generated automatically. Please don't edit it.     --
------------------------------------------------------------------------------
with System.Address_To_Access_Conversions;

package body Qt4.Font_Metrics is

   use type Internals.QFontMetrics_Access;

   function initialize_QFontMetrics_QFontCR
    (Storage : System.Address;
     Font : Qt4.Fonts.Internals.QFont_Access)
      return Internals.QFontMetrics_Access;
   pragma Import (C, initialize_QFontMetrics_QFontCR, "__QtAda_inititialize_QFontMetrics_QFontCR");

   function adjust_QFontMetrics
    (Storage : System.Address;
     From    : Internals.QFontMetrics_Access)
       return Internals.QFontMetrics_Access;
   pragma Import (C, adjust_QFontMetrics, "__QtAda_adjust_QFontMetrics");

   procedure finalize_QFontMetrics (Object : Internals.QFontMetrics_Access);
   pragma Import (C, finalize_QFontMetrics, "__QtAda_finalize_QFontMetrics");

   function QFontMetrics_ascent
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_ascent, "__QtAda_QFontMetrics_ascent_Q");

   function QFontMetrics_averageCharWidth
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_averageCharWidth, "__QtAda_QFontMetrics_averageCharWidth_Q");

   procedure QFontMetrics_boundingRect_QChar
    (Returns : Qt4.Rects.Internals.QRect_Access;
     Self : Internals.QFontMetrics_Access;
     Ch : Qt4.Chars.Internals.QChar_Access);
   pragma Import (C, QFontMetrics_boundingRect_QChar, "__QtAda_QFontMetrics_boundingRect_QChar_Q");

   procedure QFontMetrics_boundingRect_QStringCR
    (Returns : Qt4.Rects.Internals.QRect_Access;
     Self : Internals.QFontMetrics_Access;
     Text : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QFontMetrics_boundingRect_QStringCR, "__QtAda_QFontMetrics_boundingRect_QStringCR_Q");

   function QFontMetrics_charWidth_QStringCR_int
    (Self : Internals.QFontMetrics_Access;
     Str : Qt4.Strings.Internals.QString_Access;
     Pos : Qt4.Q_Integer)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_charWidth_QStringCR_int, "__QtAda_QFontMetrics_charWidth_QStringCR_int_Q");

   function QFontMetrics_descent
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_descent, "__QtAda_QFontMetrics_descent_Q");

   function QFontMetrics_height
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_height, "__QtAda_QFontMetrics_height_Q");

   function QFontMetrics_inFont_QChar
    (Self : Internals.QFontMetrics_Access;
     Ch : Qt4.Chars.Internals.QChar_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QFontMetrics_inFont_QChar, "__QtAda_QFontMetrics_inFont_QChar_Q");

   function QFontMetrics_leading
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_leading, "__QtAda_QFontMetrics_leading_Q");

   function QFontMetrics_leftBearing_QChar
    (Self : Internals.QFontMetrics_Access;
     Ch : Qt4.Chars.Internals.QChar_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_leftBearing_QChar, "__QtAda_QFontMetrics_leftBearing_QChar_Q");

   function QFontMetrics_lineSpacing
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_lineSpacing, "__QtAda_QFontMetrics_lineSpacing_Q");

   function QFontMetrics_lineWidth
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_lineWidth, "__QtAda_QFontMetrics_lineWidth_Q");

   function QFontMetrics_maxWidth
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_maxWidth, "__QtAda_QFontMetrics_maxWidth_Q");

   function QFontMetrics_minLeftBearing
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_minLeftBearing, "__QtAda_QFontMetrics_minLeftBearing_Q");

   function QFontMetrics_minRightBearing
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_minRightBearing, "__QtAda_QFontMetrics_minRightBearing_Q");

   function QFontMetrics_overlinePos
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_overlinePos, "__QtAda_QFontMetrics_overlinePos_Q");

   function QFontMetrics_rightBearing_QChar
    (Self : Internals.QFontMetrics_Access;
     Ch : Qt4.Chars.Internals.QChar_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_rightBearing_QChar, "__QtAda_QFontMetrics_rightBearing_QChar_Q");

   function QFontMetrics_strikeOutPos
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_strikeOutPos, "__QtAda_QFontMetrics_strikeOutPos_Q");

   procedure QFontMetrics_tightBoundingRect_QStringCR
    (Returns : Qt4.Rects.Internals.QRect_Access;
     Self : Internals.QFontMetrics_Access;
     Str : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QFontMetrics_tightBoundingRect_QStringCR, "__QtAda_QFontMetrics_tightBoundingRect_QStringCR_Q");

   function QFontMetrics_underlinePos
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_underlinePos, "__QtAda_QFontMetrics_underlinePos_Q");

   function QFontMetrics_width_QStringCR_int
    (Self : Internals.QFontMetrics_Access;
     Text : Qt4.Strings.Internals.QString_Access;
     Len : Qt4.Q_Integer)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_width_QStringCR_int, "__QtAda_QFontMetrics_width_QStringCR_int_Q");

   function QFontMetrics_width_QChar
    (Self : Internals.QFontMetrics_Access;
     Ch : Qt4.Chars.Internals.QChar_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_width_QChar, "__QtAda_QFontMetrics_width_QChar_Q");

   function QFontMetrics_xHeight
    (Self : Internals.QFontMetrics_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QFontMetrics_xHeight, "__QtAda_QFontMetrics_xHeight_Q");

   function eq_QFontMetricsCR
    (Self : Internals.QFontMetrics_Access;
     Other : Internals.QFontMetrics_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QFontMetricsCR, "__QtAda_QFontMetrics_eq_QFontMetricsCR_Q");

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

   overriding
   procedure Adjust (Self : in out Q_Font_Metrics) is
   begin
      if Self.Object /= null then
         Self.Object :=
           adjust_QFontMetrics (Self.Storage'Address, Self.Object);
         Self.Wrapper := False;
      end if;
   end Adjust;

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

   overriding
   procedure Finalize (Self : in out Q_Font_Metrics) is
   begin
      if not Self.Wrapper and then Self.Object /= null then
         finalize_QFontMetrics (Self.Object);
      end if;
   end Finalize;

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

   function Create
    (Font : Qt4.Fonts.Q_Font'Class)
       return Q_Font_Metrics
   is
   begin
      return Self : Q_Font_Metrics
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QFontMetrics_QFontCR (Self.Storage'Address, Qt4.Fonts.Internals.QFont_View (Font));
      end return;
   end Create;

   ------------
   -- Ascent --
   ------------

   function Ascent
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_ascent (Self.Object);
   end Ascent;

   ------------------------
   -- Average_Char_Width --
   ------------------------

   function Average_Char_Width
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_averageCharWidth (Self.Object);
   end Average_Char_Width;

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

   function Bounding_Rect
    (Self : Q_Font_Metrics'Class;
     Ch : Qt4.Chars.Q_Char'Class)
       return Qt4.Rects.Q_Rect
   is
   begin
      return Returns : Qt4.Rects.Q_Rect do
         QFontMetrics_boundingRect_QChar (Qt4.Rects.Internals.QRect_View (Returns), Self.Object, Qt4.Chars.Internals.QChar_View (Ch));
      end return;
   end Bounding_Rect;

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

   function Bounding_Rect
    (Self : Q_Font_Metrics'Class;
     Text : Qt4.Strings.Q_String'Class)
       return Qt4.Rects.Q_Rect
   is
   begin
      return Returns : Qt4.Rects.Q_Rect do
         QFontMetrics_boundingRect_QStringCR (Qt4.Rects.Internals.QRect_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Text));
      end return;
   end Bounding_Rect;

   ----------------
   -- Char_Width --
   ----------------

   function Char_Width
    (Self : Q_Font_Metrics'Class;
     Str : Qt4.Strings.Q_String'Class;
     Pos : Qt4.Q_Integer)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_charWidth_QStringCR_int (Self.Object, Qt4.Strings.Internals.QString_View (Str), Pos);
   end Char_Width;

   -------------
   -- Descent --
   -------------

   function Descent
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_descent (Self.Object);
   end Descent;

   ------------
   -- Height --
   ------------

   function Height
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_height (Self.Object);
   end Height;

   -------------
   -- In_Font --
   -------------

   function In_Font
    (Self : Q_Font_Metrics'Class;
     Ch : Qt4.Chars.Q_Char'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QFontMetrics_inFont_QChar (Self.Object, Qt4.Chars.Internals.QChar_View (Ch)), 0);
   end In_Font;

   -------------
   -- Leading --
   -------------

   function Leading
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_leading (Self.Object);
   end Leading;

   ------------------
   -- Left_Bearing --
   ------------------

   function Left_Bearing
    (Self : Q_Font_Metrics'Class;
     Ch : Qt4.Chars.Q_Char'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_leftBearing_QChar (Self.Object, Qt4.Chars.Internals.QChar_View (Ch));
   end Left_Bearing;

   ------------------
   -- Line_Spacing --
   ------------------

   function Line_Spacing
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_lineSpacing (Self.Object);
   end Line_Spacing;

   ----------------
   -- Line_Width --
   ----------------

   function Line_Width
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_lineWidth (Self.Object);
   end Line_Width;

   ---------------
   -- Max_Width --
   ---------------

   function Max_Width
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_maxWidth (Self.Object);
   end Max_Width;

   ----------------------
   -- Min_Left_Bearing --
   ----------------------

   function Min_Left_Bearing
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_minLeftBearing (Self.Object);
   end Min_Left_Bearing;

   -----------------------
   -- Min_Right_Bearing --
   -----------------------

   function Min_Right_Bearing
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_minRightBearing (Self.Object);
   end Min_Right_Bearing;

   ------------------
   -- Overline_Pos --
   ------------------

   function Overline_Pos
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_overlinePos (Self.Object);
   end Overline_Pos;

   -------------------
   -- Right_Bearing --
   -------------------

   function Right_Bearing
    (Self : Q_Font_Metrics'Class;
     Ch : Qt4.Chars.Q_Char'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_rightBearing_QChar (Self.Object, Qt4.Chars.Internals.QChar_View (Ch));
   end Right_Bearing;

   --------------------
   -- Strike_Out_Pos --
   --------------------

   function Strike_Out_Pos
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_strikeOutPos (Self.Object);
   end Strike_Out_Pos;

   -------------------------
   -- Tight_Bounding_Rect --
   -------------------------

   function Tight_Bounding_Rect
    (Self : Q_Font_Metrics'Class;
     Str : Qt4.Strings.Q_String'Class)
       return Qt4.Rects.Q_Rect
   is
   begin
      return Returns : Qt4.Rects.Q_Rect do
         QFontMetrics_tightBoundingRect_QStringCR (Qt4.Rects.Internals.QRect_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Str));
      end return;
   end Tight_Bounding_Rect;

   -------------------
   -- Underline_Pos --
   -------------------

   function Underline_Pos
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_underlinePos (Self.Object);
   end Underline_Pos;

   -----------
   -- Width --
   -----------

   function Width
    (Self : Q_Font_Metrics'Class;
     Text : Qt4.Strings.Q_String'Class;
     Len : Qt4.Q_Integer
       := -1)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_width_QStringCR_int (Self.Object, Qt4.Strings.Internals.QString_View (Text), Len);
   end Width;

   -----------
   -- Width --
   -----------

   function Width
    (Self : Q_Font_Metrics'Class;
     Ch : Qt4.Chars.Q_Char'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_width_QChar (Self.Object, Qt4.Chars.Internals.QChar_View (Ch));
   end Width;

   --------------
   -- X_Height --
   --------------

   function X_Height
    (Self : Q_Font_Metrics'Class)
       return Qt4.Q_Integer
   is
   begin
      return QFontMetrics_xHeight (Self.Object);
   end X_Height;

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

   overriding function "="
    (Self : Q_Font_Metrics;
     Other : Q_Font_Metrics)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (eq_QFontMetricsCR (Self.Object, Other.Object), 0);
   end "=";

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

   package body Internals is

   -----------------------
   -- QFontMetrics_View --
   -----------------------

      function QFontMetrics_View
       (Item : Q_Font_Metrics'Class)
          return QFontMetrics_Access
      is
      begin
         return Item.Object;
      end QFontMetrics_View;

      package QFontMetrics_Conversions is
        new System.Address_To_Access_Conversions
             (QFontMetrics);

   ----------------------------
   -- QFontMetricsTo_Pointer --
   ----------------------------

      function To_Pointer
       (Address : System.Address)
          return QFontMetrics_Access
      is
      begin
         return
           QFontMetrics_Access
            (QFontMetrics_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   ----------------------------
   -- QFontMetricsTo_Address --
   ----------------------------

      function To_Address
       (Pointer : QFontMetrics_Access)
          return System.Address
      is
      begin
         return
           QFontMetrics_Conversions.To_Address
            (QFontMetrics_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

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

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

   --------------------------
   -- Create_Uninitialized --
   --------------------------

      function Create_Uninitialized return Q_Font_Metrics is
      begin
         return Q_Font_Metrics'
          (Ada.Finalization.Controlled with others => <>);
      end Create_Uninitialized;

   -------------
   -- Storage --
   -------------

      function Storage
       (Item : Q_Font_Metrics'Class)
          return System.Address
      is
      begin
         return Item.Storage'Address;
      end Storage;

   ---------------------------
   -- Set_QFontMetrics_View --
   ---------------------------

      procedure Set_QFontMetrics_View
       (Item : in out Q_Font_Metrics'Class;
        View : QFontMetrics_Access)
      is
      begin
         Item.Object := View;
      end Set_QFontMetrics_View;

   end Internals;

end Qt4.Font_Metrics;
