------------------------------------------------------------------------------
--                                                                          --
--                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 Interfaces.C;

with Qt4_Entities;
with Qt4.Strings;
with Qt4.Text_Char_Formats;
limited with Qt4.Text_Frames;
with Qt4.Text_Table_Formats;

package Qt4.Text_Cursors is

   type Move_Mode is (Move_Anchor, Keep_Anchor);
   pragma Convention (C, Move_Mode);
   for Move_Mode'Size use Interfaces.C.unsigned'Size;
   for Move_Mode use (Move_Anchor => 0, Keep_Anchor => 1);

   type Move_Operation is
    (No_Move,
     Start,
     Up,
     Start_Of_Line,
     Start_Of_Block,
     Start_Of_Word,
     Previous_Block,
     Previous_Character,
     Previous_Word,
     Left,
     Word_Left,
     To_End,  --  XXX Вместо зарезервированного слова End используется To_End.
     Down,
     End_Of_Line,
     End_Of_Word,
     End_Of_Block,
     Next_Block,
     Next_Character,
     Next_Word,
     Right,
     Word_Right);
   pragma Convention (C, Move_Operation);
   for Move_Operation'Size use Interfaces.C.unsigned'Size;
   for Move_Operation use
   (No_Move            => 0,
    Start              => 1,
    Up                 => 2,
    Start_Of_Line      => 3,
    Start_Of_Block     => 4,
    Start_Of_Word      => 5,
    Previous_Block     => 6,
    Previous_Character => 7,
    Previous_Word      => 8,
    Left               => 9,
    Word_Left          => 10,
    To_End             => 11,
    End_Of_Line        => 13,
    End_Of_Word        => 14,
    End_Of_Block       => 15,
    Next_Block         => 16,
    Next_Character     => 17,
    Next_Word          => 18,
    Down               => 12,
    Right              => 19,
    Word_Right         => 20);

   package Thin is

      subtype QTextCursor is Qt4_Entities.Cpp_Class;

   end Thin;

   type Q_Text_Cursor is tagged private;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Begin_Edit_Block
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Begin_Edit_Block (Self : Q_Text_Cursor);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Current_Frame
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   function Current_Frame (Self : Q_Text_Cursor)
     return not null access Qt4.Text_Frames.Q_Text_Frame'Class;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Begin_Edit_Block
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure End_Edit_Block (Self : Q_Text_Cursor);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Is_Null
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   function Is_Null (Self : Q_Text_Cursor) return Boolean;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Move_Position
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   function Move_Position (Self      : Q_Text_Cursor;
                           Operation : Move_Operation;
                           Mode      : Move_Mode := Move_Anchor;
                           N         : Qt4.Q_Integer := 1)
     return Boolean;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Move_Position
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Move_Position (Self      : Q_Text_Cursor;
                            Operation : Move_Operation;
                            Mode      : Move_Mode := Move_Anchor;
                            N         : Qt4.Q_Integer := 1);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Insert_Block
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Insert_Block (Self : Q_Text_Cursor);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Insert_Table
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Insert_Table (Self : Q_Text_Cursor;
                           Row : Q_Integer;
                           Col : Q_Integer);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Insert_Table
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Insert_Table
    (Self   : Q_Text_Cursor;
     Row    : Q_Integer;
     Col    : Q_Integer;
     Format : Qt4.Text_Table_Formats.Q_Text_Table_Format);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Insert_Text
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Insert_Text (Self : Q_Text_Cursor;
                          Text : Qt4.Strings.Q_String);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Insert_Text
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Insert_Text
    (Self   : Q_Text_Cursor;
     Text   : Qt4.Strings.Q_String;
     Format : Qt4.Text_Char_Formats.Q_Text_Char_Format);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Set_Position
   --!    <Purpose>
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   procedure Set_Position (Self : Q_Text_Cursor;
                           Pos  : Q_Integer;
                           Mode : Move_Mode := Move_Anchor);

   package Internals is

      ------------------------------------------------------------------------
      --! <Subprogram>
      --!    <Unit> Cpp_Object
      --!    <Purpose> Возвращает ссылку на ассоциированный объект C++.
      --! Вместо этой подпрограммы необходимо использовать QTextCursor_View.
      --! Со временем эта подпрограмма будет удалена.
      --!    <Exceptions>
      ------------------------------------------------------------------------
      function Cpp_Object (Self : Q_Text_Cursor)
        return not null access Thin.QTextCursor;

      ------------------------------------------------------------------------
      --! <Subprogram>
      --!    <Unit> QTextCursor_View
      --!    <Purpose> Возвращает ссылку на ассоциированный объект C++.
      --!    <Exceptions>
      ------------------------------------------------------------------------
      function QTextCursor_View (Self : Q_Text_Cursor)
        return not null access Thin.QTextCursor
          renames Cpp_Object;

      ------------------------------------------------------------------------
      --! <Subprogram>
      --!    <Unit> To_Q_Text_Cursor
      --!    <Purpose> Возвращает эквивалентный объект Ada.
      --!    <Exceptions>
      ------------------------------------------------------------------------
      function To_Q_Text_Cursor
       (Item : not null access constant Thin.QTextCursor)
          return Q_Text_Cursor;

   end Internals;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Create
   --!    <Purpose> Создаёт объект со значением по умолчанию. Используется для
   --! объявления значений по умолчанию для параметров подпрограмм. Не должна
   --! использоваться приложением.
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   function Create return Q_Text_Cursor;

private

   type Q_Text_Cursor is new Qt4_Entities.Entity with null record;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Copy_Cpp_Object
   --!    <Purpose> Осуществляет копирование ассоциированного объекта C++.
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   overriding
   function Copy_Cpp_Object (Self : not null access Q_Text_Cursor)
     return not null access Qt4_Entities.Cpp_Class;

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Delete_Cpp_Object
   --!    <Purpose> Осуществляет уничтожение ассоциированного объекта C++.
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   overriding
   procedure Delete_Cpp_Object (Self : not null access Q_Text_Cursor);

   ---------------------------------------------------------------------------
   --! <Subprogram>
   --!    <Unit> Default_Cpp_Object
   --!    <Purpose> Возвращает новый пустой экземпляр класса QTextCursor.
   --!    <Exceptions>
   ---------------------------------------------------------------------------
   overriding
   function Default_Cpp_Object (Self : not null access Q_Text_Cursor)
     return access Qt4_Entities.Cpp_Class;

end Qt4.Text_Cursors;
