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. --  A GtkComboBoxText is a simple variant of Gtk.Combo_Box.Gtk_Combo_Box that 
  26. --  hides the model-view complexity for simple text-only use cases. 
  27. -- 
  28. --  To create a GtkComboBoxText, use Gtk.Combo_Box_Text.Gtk_New or 
  29. --  Gtk.Combo_Box_Text.Gtk_New_With_Entry. 
  30. -- 
  31. --  You can add items to a GtkComboBoxText with 
  32. --  Gtk.Combo_Box_Text.Append_Text, Gtk.Combo_Box_Text.Insert_Text or 
  33. --  Gtk.Combo_Box_Text.Prepend_Text and remove options with 
  34. --  Gtk.Combo_Box_Text.Remove. 
  35. -- 
  36. --  If the GtkComboBoxText contains an entry (via the 'has-entry' property), 
  37. --  its contents can be retrieved using Gtk.Combo_Box_Text.Get_Active_Text. The 
  38. --  entry itself can be accessed by calling Gtk.Bin.Get_Child on the combo box. 
  39. -- 
  40. --  You should not call Gtk.Combo_Box.Set_Model or attempt to pack more cells 
  41. --  into this combo box via its GtkCellLayout interface. 
  42. -- 
  43. --  == GtkComboBoxText as GtkBuildable == 
  44. -- 
  45. --  The GtkComboBoxText implementation of the GtkBuildable interface supports 
  46. --  adding items directly using the <items> element and specifying <item> 
  47. --  elements for each item. Each <item> element supports the regular 
  48. --  translation attributes "translatable", "context" and "comments". 
  49. -- 
  50. --  == A UI definition fragment specifying GtkComboBoxText items == 
  51. -- 
  52. --    <object class="GtkComboBoxText"> 
  53. --    <items> 
  54. --    <item translatable="yes">Factory</item> 
  55. --    <item translatable="yes">Home</item> 
  56. --    <item translatable="yes">Subway</item> 
  57. --    </items> 
  58. --    </object> 
  59. --  </description> 
  60. --  <group>Numeric/Text Data Entry</group> 
  61. pragma Ada_2005; 
  62.  
  63. pragma Warnings (Off, "*is already use-visible*"); 
  64. with Gdk.Event;         use Gdk.Event; 
  65. with Glib;              use Glib; 
  66. with Glib.Object;       use Glib.Object; 
  67. with Glib.Types;        use Glib.Types; 
  68. with Gtk.Buildable;     use Gtk.Buildable; 
  69. with Gtk.Cell_Editable; use Gtk.Cell_Editable; 
  70. with Gtk.Cell_Layout;   use Gtk.Cell_Layout; 
  71. with Gtk.Cell_Renderer; use Gtk.Cell_Renderer; 
  72. with Gtk.Combo_Box;     use Gtk.Combo_Box; 
  73. with Gtk.Tree_Model;    use Gtk.Tree_Model; 
  74.  
  75. package Gtk.Combo_Box_Text is 
  76.  
  77.    type Gtk_Combo_Box_Text_Record is new Gtk_Combo_Box_Record with null record; 
  78.    type Gtk_Combo_Box_Text is access all Gtk_Combo_Box_Text_Record'Class; 
  79.  
  80.    --------------- 
  81.    -- Callbacks -- 
  82.    --------------- 
  83.  
  84.    type Gtk_Cell_Layout_Data_Func is access procedure 
  85.      (Cell_Layout : Gtk.Cell_Layout.Gtk_Cell_Layout; 
  86.       Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  87.       Tree_Model  : Gtk.Tree_Model.Gtk_Tree_Model; 
  88.       Iter        : Gtk.Tree_Model.Gtk_Tree_Iter); 
  89.    --  A function which should set the value of Cell_Layout's cell renderer(s) 
  90.    --  as appropriate. 
  91.    --  "cell_layout": a Gtk.Cell_Layout.Gtk_Cell_Layout 
  92.    --  "cell": the cell renderer whose value is to be set 
  93.    --  "tree_model": the model 
  94.    --  "iter": a Gtk.Tree_Model.Gtk_Tree_Iter indicating the row to set the 
  95.    --  value for 
  96.  
  97.    ------------------ 
  98.    -- Constructors -- 
  99.    ------------------ 
  100.  
  101.    procedure Gtk_New (Self : out Gtk_Combo_Box_Text); 
  102.    procedure Initialize 
  103.       (Self : not null access Gtk_Combo_Box_Text_Record'Class); 
  104.    --  Creates a new Gtk.Combo_Box_Text.Gtk_Combo_Box_Text, which is a 
  105.    --  Gtk.Combo_Box.Gtk_Combo_Box just displaying strings. 
  106.    --  Since: gtk+ 2.24 
  107.  
  108.    function Gtk_Combo_Box_Text_New return Gtk_Combo_Box_Text; 
  109.    --  Creates a new Gtk.Combo_Box_Text.Gtk_Combo_Box_Text, which is a 
  110.    --  Gtk.Combo_Box.Gtk_Combo_Box just displaying strings. 
  111.    --  Since: gtk+ 2.24 
  112.  
  113.    procedure Gtk_New_With_Entry (Self : out Gtk_Combo_Box_Text); 
  114.    procedure Initialize_With_Entry 
  115.       (Self : not null access Gtk_Combo_Box_Text_Record'Class); 
  116.    --  Creates a new Gtk.Combo_Box_Text.Gtk_Combo_Box_Text, which is a 
  117.    --  Gtk.Combo_Box.Gtk_Combo_Box just displaying strings. The combo box 
  118.    --  created by this function has an entry. 
  119.    --  Since: gtk+ 2.24 
  120.  
  121.    function Gtk_Combo_Box_Text_New_With_Entry return Gtk_Combo_Box_Text; 
  122.    --  Creates a new Gtk.Combo_Box_Text.Gtk_Combo_Box_Text, which is a 
  123.    --  Gtk.Combo_Box.Gtk_Combo_Box just displaying strings. The combo box 
  124.    --  created by this function has an entry. 
  125.    --  Since: gtk+ 2.24 
  126.  
  127.    function Get_Type return Glib.GType; 
  128.    pragma Import (C, Get_Type, "gtk_combo_box_text_get_type"); 
  129.  
  130.    ------------- 
  131.    -- Methods -- 
  132.    ------------- 
  133.  
  134.    procedure Append 
  135.       (Self : not null access Gtk_Combo_Box_Text_Record; 
  136.        Id   : UTF8_String := ""; 
  137.        Text : UTF8_String); 
  138.    --  Appends Text to the list of strings stored in Combo_Box. If Id is 
  139.    --  non-null then it is used as the ID of the row. 
  140.    --  This is the same as calling Gtk.Combo_Box_Text.Insert with a position 
  141.    --  of -1. 
  142.    --  Since: gtk+ 2.24 
  143.    --  "id": a string ID for this value, or null 
  144.    --  "text": A string 
  145.  
  146.    procedure Append_Text 
  147.       (Self : not null access Gtk_Combo_Box_Text_Record; 
  148.        Text : UTF8_String); 
  149.    --  Appends Text to the list of strings stored in Combo_Box. 
  150.    --  This is the same as calling Gtk.Combo_Box_Text.Insert_Text with a 
  151.    --  position of -1. 
  152.    --  Since: gtk+ 2.24 
  153.    --  "text": A string 
  154.  
  155.    function Get_Active_Text 
  156.       (Self : not null access Gtk_Combo_Box_Text_Record) return UTF8_String; 
  157.    --  Returns the currently active string in Combo_Box, or null if none is 
  158.    --  selected. If Combo_Box contains an entry, this function will return its 
  159.    --  contents (which will not necessarily be an item from the list). 
  160.    --  Since: gtk+ 2.24 
  161.  
  162.    procedure Insert 
  163.       (Self     : not null access Gtk_Combo_Box_Text_Record; 
  164.        Position : Gint; 
  165.        Id       : UTF8_String := ""; 
  166.        Text     : UTF8_String); 
  167.    --  Inserts Text at Position in the list of strings stored in Combo_Box. If 
  168.    --  Id is non-null then it is used as the ID of the row. See 
  169.    --  Gtk.Combo_Box.Gtk_Combo_Box:id-column. 
  170.    --  If Position is negative then Text is appended. 
  171.    --  Since: gtk+ 3.0 
  172.    --  "position": An index to insert Text 
  173.    --  "id": a string ID for this value, or null 
  174.    --  "text": A string to display 
  175.  
  176.    procedure Insert_Text 
  177.       (Self     : not null access Gtk_Combo_Box_Text_Record; 
  178.        Position : Gint; 
  179.        Text     : UTF8_String); 
  180.    --  Inserts Text at Position in the list of strings stored in Combo_Box. 
  181.    --  If Position is negative then Text is appended. 
  182.    --  This is the same as calling Gtk.Combo_Box_Text.Insert with a null ID 
  183.    --  string. 
  184.    --  Since: gtk+ 2.24 
  185.    --  "position": An index to insert Text 
  186.    --  "text": A string 
  187.  
  188.    procedure Prepend 
  189.       (Self : not null access Gtk_Combo_Box_Text_Record; 
  190.        Id   : UTF8_String := ""; 
  191.        Text : UTF8_String); 
  192.    --  Prepends Text to the list of strings stored in Combo_Box. If Id is 
  193.    --  non-null then it is used as the ID of the row. 
  194.    --  This is the same as calling Gtk.Combo_Box_Text.Insert with a position 
  195.    --  of 0. 
  196.    --  Since: gtk+ 2.24 
  197.    --  "id": a string ID for this value, or null 
  198.    --  "text": a string 
  199.  
  200.    procedure Prepend_Text 
  201.       (Self : not null access Gtk_Combo_Box_Text_Record; 
  202.        Text : UTF8_String); 
  203.    --  Prepends Text to the list of strings stored in Combo_Box. 
  204.    --  This is the same as calling Gtk.Combo_Box_Text.Insert_Text with a 
  205.    --  position of 0. 
  206.    --  Since: gtk+ 2.24 
  207.    --  "text": A string 
  208.  
  209.    procedure Remove 
  210.       (Self     : not null access Gtk_Combo_Box_Text_Record; 
  211.        Position : Gint); 
  212.    --  Removes the string at Position from Combo_Box. 
  213.    --  Since: gtk+ 2.24 
  214.    --  "position": Index of the item to remove 
  215.  
  216.    procedure Remove_All (Self : not null access Gtk_Combo_Box_Text_Record); 
  217.    --  Removes all the text entries from the combo box. 
  218.    --  Since: gtk+ 3.0 
  219.  
  220.    procedure Set_Cell_Data_Func 
  221.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record; 
  222.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  223.        Func        : Gtk_Cell_Layout_Data_Func); 
  224.    --  Sets the Gtk_Cell_Layout_Data_Func to use for Cell_Layout. 
  225.    --  This function is used instead of the standard attributes mapping for 
  226.    --  setting the column value, and should set the value of Cell_Layout's cell 
  227.    --  renderer(s) as appropriate. 
  228.    --  Func may be null to remove a previously set function. 
  229.    --  Since: gtk+ 2.4 
  230.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  231.    --  "func": the Gtk_Cell_Layout_Data_Func to use, or null 
  232.  
  233.    generic 
  234.       type User_Data_Type (<>) is private; 
  235.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  236.    package Set_Cell_Data_Func_User_Data is 
  237.  
  238.       type Gtk_Cell_Layout_Data_Func is access procedure 
  239.         (Cell_Layout : Gtk.Cell_Layout.Gtk_Cell_Layout; 
  240.          Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  241.          Tree_Model  : Gtk.Tree_Model.Gtk_Tree_Model; 
  242.          Iter        : Gtk.Tree_Model.Gtk_Tree_Iter; 
  243.          Data        : User_Data_Type); 
  244.       --  A function which should set the value of Cell_Layout's cell renderer(s) 
  245.       --  as appropriate. 
  246.       --  "cell_layout": a Gtk.Cell_Layout.Gtk_Cell_Layout 
  247.       --  "cell": the cell renderer whose value is to be set 
  248.       --  "tree_model": the model 
  249.       --  "iter": a Gtk.Tree_Model.Gtk_Tree_Iter indicating the row to set the 
  250.       --  value for 
  251.       --  "data": user data passed to Gtk.Cell_Layout.Set_Cell_Data_Func 
  252.  
  253.       procedure Set_Cell_Data_Func 
  254.          (Cell_Layout : not null access Gtk.Combo_Box_Text.Gtk_Combo_Box_Text_Record'Class; 
  255.           Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  256.           Func        : Gtk_Cell_Layout_Data_Func; 
  257.           Func_Data   : User_Data_Type); 
  258.       --  Sets the Gtk_Cell_Layout_Data_Func to use for Cell_Layout. 
  259.       --  This function is used instead of the standard attributes mapping for 
  260.       --  setting the column value, and should set the value of Cell_Layout's 
  261.       --  cell renderer(s) as appropriate. 
  262.       --  Func may be null to remove a previously set function. 
  263.       --  Since: gtk+ 2.4 
  264.       --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  265.       --  "func": the Gtk_Cell_Layout_Data_Func to use, or null 
  266.       --  "func_data": user data for Func 
  267.  
  268.    end Set_Cell_Data_Func_User_Data; 
  269.  
  270.    --------------------------------------------- 
  271.    -- Inherited subprograms (from interfaces) -- 
  272.    --------------------------------------------- 
  273.    --  Methods inherited from the Buildable interface are not duplicated here 
  274.    --  since they are meant to be used by tools, mostly. If you need to call 
  275.    --  them, use an explicit cast through the "-" operator below. 
  276.  
  277.    procedure Editing_Done 
  278.       (Cell_Editable : not null access Gtk_Combo_Box_Text_Record); 
  279.  
  280.    procedure Remove_Widget 
  281.       (Cell_Editable : not null access Gtk_Combo_Box_Text_Record); 
  282.  
  283.    procedure Start_Editing 
  284.       (Cell_Editable : not null access Gtk_Combo_Box_Text_Record; 
  285.        Event         : Gdk.Event.Gdk_Event); 
  286.  
  287.    procedure Add_Attribute 
  288.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record; 
  289.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  290.        Attribute   : UTF8_String; 
  291.        Column      : Gint); 
  292.  
  293.    procedure Clear (Cell_Layout : not null access Gtk_Combo_Box_Text_Record); 
  294.  
  295.    procedure Clear_Attributes 
  296.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record; 
  297.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class); 
  298.  
  299.    function Get_Cells 
  300.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record) 
  301.        return Glib.Object.Object_Simple_List.Glist; 
  302.  
  303.    procedure Pack_End 
  304.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record; 
  305.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  306.        Expand      : Boolean); 
  307.  
  308.    procedure Pack_Start 
  309.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record; 
  310.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  311.        Expand      : Boolean); 
  312.  
  313.    procedure Reorder 
  314.       (Cell_Layout : not null access Gtk_Combo_Box_Text_Record; 
  315.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  316.        Position    : Gint); 
  317.  
  318.    ---------------- 
  319.    -- Interfaces -- 
  320.    ---------------- 
  321.    --  This class implements several interfaces. See Glib.Types 
  322.    -- 
  323.    --  - "Buildable" 
  324.    -- 
  325.    --  - "CellEditable" 
  326.    -- 
  327.    --  - "CellLayout" 
  328.  
  329.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  330.      (Gtk.Buildable.Gtk_Buildable, Gtk_Combo_Box_Text_Record, Gtk_Combo_Box_Text); 
  331.    function "+" 
  332.      (Widget : access Gtk_Combo_Box_Text_Record'Class) 
  333.    return Gtk.Buildable.Gtk_Buildable 
  334.    renames Implements_Gtk_Buildable.To_Interface; 
  335.    function "-" 
  336.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  337.    return Gtk_Combo_Box_Text 
  338.    renames Implements_Gtk_Buildable.To_Object; 
  339.  
  340.    package Implements_Gtk_Cell_Editable is new Glib.Types.Implements 
  341.      (Gtk.Cell_Editable.Gtk_Cell_Editable, Gtk_Combo_Box_Text_Record, Gtk_Combo_Box_Text); 
  342.    function "+" 
  343.      (Widget : access Gtk_Combo_Box_Text_Record'Class) 
  344.    return Gtk.Cell_Editable.Gtk_Cell_Editable 
  345.    renames Implements_Gtk_Cell_Editable.To_Interface; 
  346.    function "-" 
  347.      (Interf : Gtk.Cell_Editable.Gtk_Cell_Editable) 
  348.    return Gtk_Combo_Box_Text 
  349.    renames Implements_Gtk_Cell_Editable.To_Object; 
  350.  
  351.    package Implements_Gtk_Cell_Layout is new Glib.Types.Implements 
  352.      (Gtk.Cell_Layout.Gtk_Cell_Layout, Gtk_Combo_Box_Text_Record, Gtk_Combo_Box_Text); 
  353.    function "+" 
  354.      (Widget : access Gtk_Combo_Box_Text_Record'Class) 
  355.    return Gtk.Cell_Layout.Gtk_Cell_Layout 
  356.    renames Implements_Gtk_Cell_Layout.To_Interface; 
  357.    function "-" 
  358.      (Interf : Gtk.Cell_Layout.Gtk_Cell_Layout) 
  359.    return Gtk_Combo_Box_Text 
  360.    renames Implements_Gtk_Cell_Layout.To_Object; 
  361.  
  362. end Gtk.Combo_Box_Text;