1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  The Gtk.Editable.Gtk_Editable interface is an interface which should be 
  26. --  implemented by text editing widgets, such as Gtk.GEntry.Gtk_Entry and 
  27. --  Gtk.Spin_Button.Gtk_Spin_Button. It contains functions for generically 
  28. --  manipulating an editable widget, a large number of action signals used for 
  29. --  key bindings, and several signals that an application can connect to to 
  30. --  modify the behavior of a widget. 
  31. -- 
  32. --  As an example of the latter usage, by connecting the following handler to 
  33. --  Gtk.Editable.Gtk_Editable::insert-text, an application can convert all 
  34. --  entry into a widget into uppercase. 
  35. -- 
  36. --  == Forcing entry to uppercase. == 
  37. -- 
  38. --    include <ctype.h> 
  39. --    void 
  40. --    insert_text_handler (GtkEditable *editable, 
  41. --       const gchar *text, 
  42. --       gint         length, 
  43. --       gint        *position, 
  44. --       gpointer     data) 
  45. --    { 
  46. --       gchar *result = g_utf8_strup (text, length); 
  47. --       g_signal_handlers_block_by_func (editable, 
  48. --            (gpointer) insert_text_handler, data); 
  49. --       gtk_editable_insert_text (editable, result, length, position); 
  50. --       g_signal_handlers_unblock_by_func (editable, 
  51. --            (gpointer) insert_text_handler, data); 
  52. --       g_signal_stop_emission_by_name (editable, "insert_text"); 
  53. --       g_free (result); 
  54. --    } 
  55. -- 
  56. -- 
  57. --  </description> 
  58. pragma Ada_2005; 
  59.  
  60. pragma Warnings (Off, "*is already use-visible*"); 
  61. with Glib;        use Glib; 
  62. with Glib.Object; use Glib.Object; 
  63. with Glib.Types;  use Glib.Types; 
  64.  
  65. package Gtk.Editable is 
  66.  
  67.    type Gtk_Editable is new Glib.Types.GType_Interface; 
  68.    Null_Gtk_Editable : constant Gtk_Editable; 
  69.  
  70.    ------------------ 
  71.    -- Constructors -- 
  72.    ------------------ 
  73.  
  74.    function Get_Type return Glib.GType; 
  75.    pragma Import (C, Get_Type, "gtk_editable_get_type"); 
  76.  
  77.    ------------- 
  78.    -- Methods -- 
  79.    ------------- 
  80.  
  81.    procedure Copy_Clipboard (Editable : Gtk_Editable); 
  82.    pragma Import (C, Copy_Clipboard, "gtk_editable_copy_clipboard"); 
  83.    --  Copies the contents of the currently selected content in the editable 
  84.    --  and puts it on the clipboard. 
  85.  
  86.    procedure Cut_Clipboard (Editable : Gtk_Editable); 
  87.    pragma Import (C, Cut_Clipboard, "gtk_editable_cut_clipboard"); 
  88.    --  Removes the contents of the currently selected content in the editable 
  89.    --  and puts it on the clipboard. 
  90.  
  91.    procedure Delete_Selection (Editable : Gtk_Editable); 
  92.    pragma Import (C, Delete_Selection, "gtk_editable_delete_selection"); 
  93.    --  Deletes the currently selected text of the editable. This call doesn't 
  94.    --  do anything if there is no selected text. 
  95.  
  96.    procedure Delete_Text 
  97.       (Editable  : Gtk_Editable; 
  98.        Start_Pos : Gint; 
  99.        End_Pos   : Gint := -1); 
  100.    pragma Import (C, Delete_Text, "gtk_editable_delete_text"); 
  101.    --  Deletes a sequence of characters. The characters that are deleted are 
  102.    --  those characters at positions from Start_Pos up to, but not including 
  103.    --  End_Pos. If End_Pos is negative, then the characters deleted are those 
  104.    --  from Start_Pos to the end of the text. 
  105.    --  Note that the positions are specified in characters, not bytes. 
  106.    --  "start_pos": start position 
  107.    --  "end_pos": end position 
  108.  
  109.    function Get_Chars 
  110.       (Editable  : Gtk_Editable; 
  111.        Start_Pos : Gint; 
  112.        End_Pos   : Gint := -1) return UTF8_String; 
  113.    --  Retrieves a sequence of characters. The characters that are retrieved 
  114.    --  are those characters at positions from Start_Pos up to, but not 
  115.    --  including End_Pos. If End_Pos is negative, then the characters retrieved 
  116.    --  are those characters from Start_Pos to the end of the text. 
  117.    --  Note that positions are specified in characters, not bytes. 
  118.    --  "start_pos": start of text 
  119.    --  "end_pos": end of text 
  120.  
  121.    function Get_Editable (Editable : Gtk_Editable) return Boolean; 
  122.    --  Retrieves whether Editable is editable. See Gtk.Editable.Set_Editable. 
  123.  
  124.    procedure Set_Editable (Editable : Gtk_Editable; Is_Editable : Boolean); 
  125.    --  Determines if the user can edit the text in the editable widget or not. 
  126.    --  "is_editable": True if the user is allowed to edit the text in the 
  127.    --  widget 
  128.  
  129.    function Get_Position (Editable : Gtk_Editable) return Gint; 
  130.    pragma Import (C, Get_Position, "gtk_editable_get_position"); 
  131.    --  Retrieves the current position of the cursor relative to the start of 
  132.    --  the content of the editable. 
  133.    --  Note that this position is in characters, not in bytes. 
  134.  
  135.    procedure Set_Position (Editable : Gtk_Editable; Position : Gint); 
  136.    pragma Import (C, Set_Position, "gtk_editable_set_position"); 
  137.    --  Sets the cursor position in the editable to the given value. 
  138.    --  The cursor is displayed before the character with the given (base 0) 
  139.    --  index in the contents of the editable. The value must be less than or 
  140.    --  equal to the number of characters in the editable. A value of -1 
  141.    --  indicates that the position should be set after the last character of 
  142.    --  the editable. Note that Position is in characters, not in bytes. 
  143.    --  "position": the position of the cursor 
  144.  
  145.    procedure Get_Selection_Bounds 
  146.       (Editable      : Gtk_Editable; 
  147.        Start_Pos     : out Gint; 
  148.        End_Pos       : out Gint; 
  149.        Has_Selection : out Boolean); 
  150.    --  Retrieves the selection bound of the editable. start_pos will be filled 
  151.    --  with the start of the selection and End_Pos with end. If no text was 
  152.    --  selected both will be identical and False will be returned. 
  153.    --  Note that positions are specified in characters, not bytes. 
  154.    --  "start_pos": location to store the starting position, or null 
  155.    --  "end_pos": location to store the end position, or null 
  156.  
  157.    procedure Insert_Text 
  158.       (Editable        : Gtk_Editable; 
  159.        New_Text        : UTF8_String; 
  160.        New_Text_Length : Gint; 
  161.        Position        : in out Gint); 
  162.    --  Inserts New_Text_Length bytes of New_Text into the contents of the 
  163.    --  widget, at position Position. 
  164.    --  Note that the position is in characters, not in bytes. The function 
  165.    --  updates Position to point after the newly inserted text. 
  166.    --  "new_text": the text to append 
  167.    --  "new_text_length": the length of the text in bytes, or -1 
  168.    --  "position": location of the position text will be inserted at 
  169.  
  170.    procedure Paste_Clipboard (Editable : Gtk_Editable); 
  171.    pragma Import (C, Paste_Clipboard, "gtk_editable_paste_clipboard"); 
  172.    --  Pastes the content of the clipboard to the current position of the 
  173.    --  cursor in the editable. 
  174.  
  175.    procedure Select_Region 
  176.       (Editable  : Gtk_Editable; 
  177.        Start_Pos : Gint; 
  178.        End_Pos   : Gint := -1); 
  179.    pragma Import (C, Select_Region, "gtk_editable_select_region"); 
  180.    --  Selects a region of text. The characters that are selected are those 
  181.    --  characters at positions from Start_Pos up to, but not including End_Pos. 
  182.    --  If End_Pos is negative, then the characters selected are those 
  183.    --  characters from Start_Pos to the end of the text. 
  184.    --  Note that positions are specified in characters, not bytes. 
  185.    --  "start_pos": start of region 
  186.    --  "end_pos": end of region 
  187.  
  188.    ---------------------- 
  189.    -- GtkAda additions -- 
  190.    ---------------------- 
  191.  
  192.    procedure Insert_Text 
  193.      (Editable : Gtk_Editable; 
  194.       New_Text : UTF8_String; 
  195.       Position : in out Gint); 
  196.    --  Convenience subprogram, identical to Insert_Text above without 
  197.    --  the requirement to supply the New_Text_Length argument. 
  198.  
  199.    ------------- 
  200.    -- Signals -- 
  201.    ------------- 
  202.  
  203.    type Cb_Gtk_Editable_Void is not null access procedure (Self : Gtk_Editable); 
  204.  
  205.    type Cb_GObject_Void is not null access procedure 
  206.      (Self : access Glib.Object.GObject_Record'Class); 
  207.  
  208.    Signal_Changed : constant Glib.Signal_Name := "changed"; 
  209.    procedure On_Changed 
  210.       (Self  : Gtk_Editable; 
  211.        Call  : Cb_Gtk_Editable_Void; 
  212.        After : Boolean := False); 
  213.    procedure On_Changed 
  214.       (Self  : Gtk_Editable; 
  215.        Call  : Cb_GObject_Void; 
  216.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  217.        After : Boolean := False); 
  218.    --  The ::changed signal is emitted at the end of a single user-visible 
  219.    --  operation on the contents of the Gtk.Editable.Gtk_Editable. 
  220.    -- 
  221.    --  E.g., a paste operation that replaces the contents of the selection 
  222.    --  will cause only one signal emission (even though it is implemented by 
  223.    --  first deleting the selection, then inserting the new content, and may 
  224.    --  cause multiple ::notify::text signals to be emitted). 
  225.  
  226.    type Cb_Gtk_Editable_Gint_Gint_Void is not null access procedure 
  227.      (Self      : Gtk_Editable; 
  228.       Start_Pos : Gint; 
  229.       End_Pos   : Gint); 
  230.  
  231.    type Cb_GObject_Gint_Gint_Void is not null access procedure 
  232.      (Self      : access Glib.Object.GObject_Record'Class; 
  233.       Start_Pos : Gint; 
  234.       End_Pos   : Gint); 
  235.  
  236.    Signal_Delete_Text : constant Glib.Signal_Name := "delete-text"; 
  237.    procedure On_Delete_Text 
  238.       (Self  : Gtk_Editable; 
  239.        Call  : Cb_Gtk_Editable_Gint_Gint_Void; 
  240.        After : Boolean := False); 
  241.    procedure On_Delete_Text 
  242.       (Self  : Gtk_Editable; 
  243.        Call  : Cb_GObject_Gint_Gint_Void; 
  244.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  245.        After : Boolean := False); 
  246.    --  This signal is emitted when text is deleted from the widget by the 
  247.    --  user. The default handler for this signal will normally be responsible 
  248.    --  for deleting the text, so by connecting to this signal and then stopping 
  249.    --  the signal with g_signal_stop_emission, it is possible to modify the 
  250.    --  range of deleted text, or prevent it from being deleted entirely. The 
  251.    --  Start_Pos and End_Pos parameters are interpreted as for 
  252.    --  Gtk.Editable.Delete_Text. 
  253.    --  
  254.    --  Callback parameters: 
  255.    --    --  "start_pos": the starting position 
  256.    --    --  "end_pos": the end position 
  257.  
  258.    type Cb_Gtk_Editable_UTF8_String_Gint_Gint_Void is not null access procedure 
  259.      (Self            : Gtk_Editable; 
  260.       New_Text        : UTF8_String; 
  261.       New_Text_Length : Gint; 
  262.       Position        : access Gint); 
  263.  
  264.    type Cb_GObject_UTF8_String_Gint_Gint_Void is not null access procedure 
  265.      (Self            : access Glib.Object.GObject_Record'Class; 
  266.       New_Text        : UTF8_String; 
  267.       New_Text_Length : Gint; 
  268.       Position        : access Gint); 
  269.  
  270.    Signal_Insert_Text : constant Glib.Signal_Name := "insert-text"; 
  271.    procedure On_Insert_Text 
  272.       (Self  : Gtk_Editable; 
  273.        Call  : Cb_Gtk_Editable_UTF8_String_Gint_Gint_Void; 
  274.        After : Boolean := False); 
  275.    procedure On_Insert_Text 
  276.       (Self  : Gtk_Editable; 
  277.        Call  : Cb_GObject_UTF8_String_Gint_Gint_Void; 
  278.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  279.        After : Boolean := False); 
  280.    --  This signal is emitted when text is inserted into the widget by the 
  281.    --  user. The default handler for this signal will normally be responsible 
  282.    --  for inserting the text, so by connecting to this signal and then 
  283.    --  stopping the signal with g_signal_stop_emission, it is possible to 
  284.    --  modify the inserted text, or prevent it from being inserted entirely. 
  285.    --  
  286.    --  Callback parameters: 
  287.    --    --  "new_text": the new text to insert 
  288.    --    --  "new_text_length": the length of the new text, in bytes, or -1 if 
  289.    --    --  new_text is nul-terminated 
  290.    --    --  "position": the position, in characters, at which to insert the new 
  291.    --    --  text. this is an in-out parameter. After the signal emission is 
  292.    --    --  finished, it should point after the newly inserted text. 
  293.  
  294.    ---------------- 
  295.    -- Interfaces -- 
  296.    ---------------- 
  297.    --  This class implements several interfaces. See Glib.Types 
  298.    -- 
  299.    --  - "Gtk_Editable" 
  300.  
  301.    function "+" (W : Gtk_Editable) return Gtk_Editable; 
  302.    pragma Inline ("+"); 
  303.  
  304. private 
  305.  
  306. Null_Gtk_Editable : constant Gtk_Editable := 
  307.    Gtk_Editable (Glib.Types.Null_Interface); 
  308. end Gtk.Editable;