1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2013, AdaCore                   -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- As a special exception, if other files instantiate generics from  -- 
  22. -- this unit, or you link this unit with other files to produce an   -- 
  23. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  24. -- executable to be covered by the GNU General Public License. This  -- 
  25. -- exception does not however invalidate any other reasons why the   -- 
  26. -- executable file  might be covered by the  GNU Public License.     -- 
  27. ----------------------------------------------------------------------- 
  28.  
  29. --  <description> 
  30. --  A Gtk_Combo_Box is a widget that allows the user to choose from a list of 
  31. --  valid choices. The Gtk_Combo_Box displays the selected choice. When 
  32. --  activated, the Gtk_Combo_Box displays a popup which allows the user to make 
  33. --  new choice. The style in which the selected value is displayed, and the 
  34. --  style of the popup is determined by the current theme. It may be similar to 
  35. --  a Gtk_Option_Menu, or similar to a Windows-style combo box. 
  36. -- 
  37. --  Unlike its predecessors Gtk.Combo.Gtk_Combo and 
  38. --  Gtk.Option_Menu.Gtk_Option_Menu, the Gtk_Combo_Box uses the model-view 
  39. --  pattern; the list of valid choices is specified in the form of a tree 
  40. --  model, and the display of the choices can be adapted to the data in the 
  41. --  model by using cell renderers, as you would in a tree view. This is 
  42. --  possible since Gtk_Combo_Box implements the Gtk_Cell_Layout interface. The 
  43. --  tree model holding the valid choices is not restricted to a flat list, it 
  44. --  can be a real tree, and the popup will reflect the tree structure. 
  45. -- 
  46. --  In addition to the model-view API, Gtk_Combo_Box offers a simple API which 
  47. --  is suitable for text-only combo boxes, and hides the complexity of managing 
  48. --  the data in a model. 
  49. --  </description> 
  50. --  <c_version>2.16.6</c_version> 
  51. --  <group>Trees and Lists</group> 
  52. --  <see>Gtk.Combo_Box_Entry</see> 
  53. --  <screenshot>gtk-combo_box</screenshot> 
  54.  
  55. with Glib.Properties; 
  56. with Gtk.Bin; 
  57. with Gtk.Cell_Editable; 
  58. with Gtk.Cell_Layout; 
  59. with Gtk.Enums; 
  60. with Gtk.Tree_Model; 
  61. with Gtk.Tree_View; 
  62. with Glib.Types; 
  63.  
  64. package Gtk.Combo_Box is 
  65.    type Gtk_Combo_Box_Record is new Gtk.Bin.Gtk_Bin_Record with null record; 
  66.    type Gtk_Combo_Box is access all Gtk_Combo_Box_Record'Class; 
  67.  
  68.    procedure Gtk_New    (Combo : out Gtk_Combo_Box); 
  69.    procedure Initialize (Combo : access Gtk_Combo_Box_Record'Class); 
  70.    --  Creates or initializes a new empty combo 
  71.  
  72.    procedure Gtk_New_With_Model 
  73.      (Combo : out Gtk_Combo_Box; 
  74.       Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class); 
  75.    procedure Initialize_With_Model 
  76.      (Combo : access Gtk_Combo_Box_Record'Class; 
  77.       Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class); 
  78.    --  Creates or initializes a new combo initializes to Model. 
  79.  
  80.    procedure Gtk_New_With_Entry (Combo : out Gtk_Combo_Box); 
  81.    procedure Initialize_With_Entry (Combo : access Gtk_Combo_Box_Record'Class); 
  82.    --  Creates or initializes a new combo with entry 
  83.  
  84.    procedure Gtk_New_With_Model_And_Entry 
  85.      (Combo : out Gtk_Combo_Box; 
  86.       Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class); 
  87.    procedure Initialize_With_Model_And_Entry 
  88.      (Combo : access Gtk_Combo_Box_Record'Class; 
  89.       Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class); 
  90.    --  Creates or initializes a new combo with entry, initialized with Model 
  91.  
  92.    function Get_Type return Glib.GType; 
  93.    --  Returns the internal value used for Gtk_Combo_Box widgets 
  94.  
  95.    procedure Set_Model 
  96.      (Combo_Box : access Gtk_Combo_Box_Record; 
  97.       Model     : Gtk.Tree_Model.Gtk_Tree_Model := null); 
  98.    function Get_Model 
  99.      (Combo_Box : access Gtk_Combo_Box_Record) 
  100.       return Gtk.Tree_Model.Gtk_Tree_Model; 
  101.    --  Sets the model used by Combo_Box to be Model. Will unset a previously 
  102.    --  set model (if applicable). If model is null, then it will unset the 
  103.    --  model. Note that this function does not clear the cell renderers, you 
  104.    --  have to call Gtk.Cell_Layout.Clear yourself if you need to set up 
  105.    --  different cell renderers for the new model. 
  106.  
  107.    procedure Set_Active 
  108.      (Combo_Box : access Gtk_Combo_Box_Record; Index : Gint); 
  109.    function Get_Active 
  110.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  111.    --  Returns the index of the currently active item, or -1 if there's no 
  112.    --  active item. If the model is a non-flat treemodel, and the active item 
  113.    --  is not an immediate child of the root of the tree, this function returns 
  114.    --  Gtk.Tree_Model.Get_Indices (Path)[0], where Path is the Gtk_Tree_Path of 
  115.    --  the active model. 
  116.  
  117.    procedure Set_Active_Iter 
  118.      (Combo_Box : access Gtk_Combo_Box_Record; 
  119.       Iter      : Gtk.Tree_Model.Gtk_Tree_Iter); 
  120.    function Get_Active_Iter 
  121.      (Combo_Box : access Gtk_Combo_Box_Record) 
  122.       return Gtk.Tree_Model.Gtk_Tree_Iter; 
  123.    --  Sets the current active item to be the one referenced by Iter. 
  124.    --  Iter must correspond to a path of depth one. 
  125.  
  126.    procedure Set_Wrap_Width 
  127.      (Combo_Box : access Gtk_Combo_Box_Record; Width : Gint); 
  128.    function Get_Wrap_Width 
  129.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  130.    --  Returns the wrap width which is used to determine the number 
  131.    --  of columns for the popup menu. If the wrap width is larger than 
  132.    --  1, the combo box is in table mode. This can be used for instance to 
  133.    --  display a matrix of color (a color palette to choose from). 
  134.    --  See also Set_Column_Span_Column 
  135.  
  136.    procedure Set_Add_Tearoffs 
  137.      (Combo_Box : access Gtk_Combo_Box_Record; Add_Tearoffs : Boolean); 
  138.    function Get_Add_Tearoffs 
  139.      (Combo_Box : access Gtk_Combo_Box_Record) return Boolean; 
  140.    --  Sets whether the popup menu should have a tearoff menu item. 
  141.    --  Clicking on this menu will detach the combo into a floating window that 
  142.    --  the user can put anywhere on the screen. 
  143.  
  144.    procedure Set_Button_Sensitivity 
  145.      (Combo_Box   : access Gtk_Combo_Box_Record; 
  146.       Sensitivity : Gtk.Enums.Gtk_Sensitivity_Type); 
  147.    function Get_Button_Sensitivity 
  148.      (Combo_Box : access Gtk_Combo_Box_Record) 
  149.       return Gtk.Enums.Gtk_Sensitivity_Type; 
  150.    --  Sets whether the dropdown button of the combo box should be always 
  151.    --  sensitive (Gtk_Sensitivity_On), never sensitive (Gtk_Sensitivity_Off) 
  152.    --  or only if there is at least one item to display (Gtk_Sensitivity_Auto). 
  153.  
  154.    function Get_Has_Entry 
  155.      (Combo_Box : access Gtk_Combo_Box_Record) return Boolean; 
  156.    --  Returns whether the combo box has an entry 
  157.  
  158.    procedure Set_Entry_Text_Column 
  159.      (Combo_Box   : access Gtk_Combo_Box_Record; 
  160.       Text_Column : Gint); 
  161.    --  Sets the model column which combo_box should use to get strings from to 
  162.    --  be Text_Column. The column Text_Column in the model of Combo_Box must be 
  163.    --  of type G_TYPE_STRING. 
  164.  
  165.    function Get_Entry_Text_Column 
  166.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  167.    --  Returns the column which combo_box is using to get the strings from to 
  168.    --  display in the internal entry. 
  169.  
  170.    procedure Set_Column_Span_Column 
  171.      (Combo_Box : access Gtk_Combo_Box_Record; Column_Span : Gint); 
  172.    function Get_Column_Span_Column 
  173.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  174.    --  Sets the column with column span information for Combo_Box to be 
  175.    --  Column_Span. The column span column contains integers which indicate 
  176.    --  how many columns an item should span. This applies to grid combos, see 
  177.    --  also Set_Wrap_Width. 
  178.  
  179.    procedure Set_Row_Span_Column 
  180.      (Combo_Box : access Gtk_Combo_Box_Record; Row_Span : Gint); 
  181.    function Get_Row_Span_Column 
  182.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  183.    --  Sets the column with row span information for Combo_Box to be Row_Span. 
  184.    --  The row span column contains integers which indicate how many rows 
  185.    --  an item should span. 
  186.  
  187.    procedure Set_Focus_On_Click 
  188.      (Combo          : access Gtk_Combo_Box_Record; 
  189.       Focus_On_Click : Boolean); 
  190.    function Get_Focus_On_Click 
  191.      (Combo : access Gtk_Combo_Box_Record) return Boolean; 
  192.    --  Sets whether the combo box will grab focus when it is clicked with 
  193.    --  the mouse. Making mouse clicks not grab focus is useful in places 
  194.    --  like toolbars where you don't want the keyboard focus removed from 
  195.    --  the main area of the application. 
  196.  
  197.    procedure Set_Row_Separator_Func 
  198.      (Combo_Box : access Gtk_Combo_Box_Record; 
  199.       Func      : Gtk.Tree_View.Gtk_Tree_View_Row_Separator_Func; 
  200.       Data      : System.Address; 
  201.       Destroy   : Glib.G_Destroy_Notify_Address := null); 
  202.    function Get_Row_Separator_Func 
  203.      (Combo_Box : access Gtk_Combo_Box_Record) 
  204.       return Gtk.Tree_View.Gtk_Tree_View_Row_Separator_Func; 
  205.    --  Sets the row separator function, which is used to determine 
  206.    --  whether a row should be drawn as a separator. If the row separator 
  207.    --  function is null, no separators are drawn. This is the default value. 
  208.  
  209.    procedure Set_Title 
  210.      (Combo_Box : access Gtk_Combo_Box_Record; 
  211.       Title     : String); 
  212.    function Get_Title 
  213.      (Combo_Box : access Gtk_Combo_Box_Record) 
  214.       return String; 
  215.    --  Sets or Gets the menu's title in tearoff mode. 
  216.  
  217.    --------------------------- 
  218.    -- Text-only combo boxes -- 
  219.    --------------------------- 
  220.    --  If your combo box only contains text, you do not necessarily have to go 
  221.    --  through the more complex use of a Gtk_Tree_Model. 
  222.  
  223.    procedure Gtk_New_Text    (Combo : out Gtk_Combo_Box); 
  224.    procedure Initialize_Text (Combo : access Gtk_Combo_Box_Record'Class); 
  225.    --  Convenience function which constructs a new text combo box, which is 
  226.    --  Gtk_Combo_Box just displaying strings. If you use this function to 
  227.    --  create a text combo box, you should only manipulate its data source with 
  228.    --  the following convenience functions: Append_Text, Insert_Text, 
  229.    --  Prepend_Text and Remove_Text 
  230.  
  231.    procedure Append_Text 
  232.      (Combo_Box : access Gtk_Combo_Box_Record; Text : String); 
  233.    procedure Prepend_Text 
  234.      (Combo_Box : access Gtk_Combo_Box_Record; Text : String); 
  235.    procedure Insert_Text 
  236.      (Combo_Box : access Gtk_Combo_Box_Record; 
  237.       Position  : Gint; 
  238.       Text      : String); 
  239.    --  Adds Text to the list of strings stored in Combo_Box. Note that 
  240.    --  you can only use this function with combo boxes constructed with 
  241.    --  Gtk_New_Text. 
  242.  
  243.    procedure Remove_Text 
  244.      (Combo_Box : access Gtk_Combo_Box_Record; Position : Gint); 
  245.    --  Removes the string at Position from Combo_Box. Note that you can only 
  246.    --  use this function with combo boxes constructed with Gtk_New_Text. 
  247.  
  248.    function Get_Active_Text 
  249.      (Combo_Box : access Gtk_Combo_Box_Record) return String; 
  250.    --  Returns the currently active string in Combo_Box or "" if none 
  251.    --  is selected.  Note that you can only use this function with combo 
  252.    --  boxes constructed with Gtk_New_Text. 
  253.  
  254.    -------------------------- 
  255.    -- Programmatic Control -- 
  256.    -------------------------- 
  257.  
  258.    procedure Popdown (Combo_Box : access Gtk_Combo_Box_Record); 
  259.    procedure Popup   (Combo_Box : access Gtk_Combo_Box_Record); 
  260.    --  Hides or pops up the menu or dropdown list of Combo_Box. 
  261.    --  This function is mostly intended for use by accessibility technologies; 
  262.    --  applications should have little use for it. 
  263.  
  264.    ---------------- 
  265.    -- Interfaces -- 
  266.    ---------------- 
  267.    --  This class implements several interfaces. See Glib.Types 
  268.    -- 
  269.    --  - "Gtk_Cell_Layout" 
  270.    --    This interface should be used to add new renderers to the view, to 
  271.    --    render various columns of the model 
  272.    --  - "Gtk_Cell_Editable" 
  273.    --    This interface should be used to edit the contents of a tree model 
  274.    --    cell 
  275.  
  276.    package Implements_Cell_Layout is new Glib.Types.Implements 
  277.      (Gtk.Cell_Layout.Gtk_Cell_Layout, Gtk_Combo_Box_Record, Gtk_Combo_Box); 
  278.    function "+" 
  279.      (Box : access Gtk_Combo_Box_Record'Class) 
  280.       return Gtk.Cell_Layout.Gtk_Cell_Layout 
  281.       renames Implements_Cell_Layout.To_Interface; 
  282.    function "-" 
  283.      (Layout : Gtk.Cell_Layout.Gtk_Cell_Layout) 
  284.       return Gtk_Combo_Box 
  285.       renames Implements_Cell_Layout.To_Object; 
  286.    --  Converts to and from the Gtk_Cell_Layout interface 
  287.  
  288.    package Implements_Cell_Editable is new Glib.Types.Implements 
  289.      (Gtk.Cell_Editable.Gtk_Cell_Editable, 
  290.       Gtk_Combo_Box_Record, Gtk_Combo_Box); 
  291.    function "+" 
  292.      (Box : access Gtk_Combo_Box_Record'Class) 
  293.       return Gtk.Cell_Editable.Gtk_Cell_Editable 
  294.       renames Implements_Cell_Editable.To_Interface; 
  295.    function "-" 
  296.      (Editable : Gtk.Cell_Editable.Gtk_Cell_Editable) 
  297.       return Gtk_Combo_Box 
  298.       renames Implements_Cell_Editable.To_Object; 
  299.    --  Converts to and from the Gtk_Cell_Editable interface 
  300.  
  301.    ---------------- 
  302.    -- Properties -- 
  303.    ---------------- 
  304.    --  The following properties are defined for this widget. See 
  305.    --  Glib.Properties for more information on properties. 
  306.  
  307.    --  <properties> 
  308.    --  Name:  Active_Property 
  309.    --  Type:  Int 
  310.    --  Descr: The item which is currently active 
  311.    -- 
  312.    --  Name:  Add_Tearoffs_Property 
  313.    --  Type:  Boolean 
  314.    --  Descr: Whether dropdowns should have a tearoff menu item 
  315.    -- 
  316.    --  Name:  Button_Sensitivity_Property 
  317.    --  Type:  Enum 
  318.    --  Descr: Whether the dropdown button is sensitive when the model is empty 
  319.    -- 
  320.    --  Name:  Column_Span_Column_Property 
  321.    --  Type:  Int 
  322.    --  Descr: TreeModel column containing the column span values 
  323.    -- 
  324.    --  Name:  Focus_On_Click_Property 
  325.    --  Type:  Boolean 
  326.    --  Descr: Whether the combo box grabs focus when it is clicked with the 
  327.    --         mouse 
  328.    -- 
  329.    --  Name:  Has_Frame_Property 
  330.    --  Type:  Boolean 
  331.    --  Descr: Whether the combo box draws a frame around the child 
  332.    -- 
  333.    --  Name:  Model_Property 
  334.    --  Type:  Object 
  335.    --  Descr: The model for the combo box 
  336.    -- 
  337.    --  Name:  Popup_Shown_Property 
  338.    --  Type:  Boolean 
  339.    --  Descr: Whether the combo's dropdown is shown 
  340.    -- 
  341.    --  Name:  Row_Span_Column_Property 
  342.    --  Type:  Int 
  343.    --  Descr: TreeModel column containing the row span values 
  344.    -- 
  345.    --  Name:  Tearoff_Title_Property 
  346.    --  Type:  String 
  347.    --  Descr: A title that may be displayed by the window manager when the 
  348.    --         popup is torn-off 
  349.    -- 
  350.    --  Name:  Wrap_Width_Property 
  351.    --  Type:  Int 
  352.    --  Descr: Wrap width for layouting the items in a grid 
  353.    --  </properties> 
  354.  
  355.    Active_Property             : constant Glib.Properties.Property_Int; 
  356.    Add_Tearoffs_Property       : constant Glib.Properties.Property_Boolean; 
  357.    Button_Sensitivity_Property : constant Glib.Properties.Property_Enum; 
  358.    Column_Span_Column_Property : constant Glib.Properties.Property_Int; 
  359.    Focus_On_Click_Property     : constant Glib.Properties.Property_Boolean; 
  360.    Has_Frame_Property          : constant Glib.Properties.Property_Boolean; 
  361.    Model_Property              : constant Glib.Properties.Property_Object; 
  362.    Popup_Shown_Property        : constant Glib.Properties.Property_Boolean; 
  363.    Row_Span_Column_Property    : constant Glib.Properties.Property_Int; 
  364.    Tearoff_Title_Property      : constant Glib.Properties.Property_String; 
  365.    Wrap_Width_Property         : constant Glib.Properties.Property_Int; 
  366.  
  367.    ---------------------- 
  368.    -- Style Properties -- 
  369.    ---------------------- 
  370.    --  The following properties can be changed through the gtk theme and 
  371.    --  configuration files, and retrieved through Gtk.Widget.Style_Get_Property 
  372.  
  373.    --  <style_properties> 
  374.    --  Name:  Appears_As_List_Property 
  375.    --  Type:  Boolean 
  376.    --  Descr: Whether dropdowns should look like lists rather than menus 
  377.    -- 
  378.    --  Name:  Arrow_Size_Property 
  379.    --  Type:  Int 
  380.    --  Descr: The minimum size of the arrow in the combo box 
  381.    -- 
  382.    --  Name:  Shadow_Type_Property 
  383.    --  Type:  Enum 
  384.    --  Descr: Which kind of shadow to draw around the combo box 
  385.    --  </style_properties> 
  386.  
  387.    Appears_As_List_Property : constant Glib.Properties.Property_Boolean; 
  388.    Arrow_Size_Property      : constant Glib.Properties.Property_Int; 
  389.    Shadow_Type_Property     : constant Glib.Properties.Property_Enum; 
  390.  
  391.    ------------- 
  392.    -- Signals -- 
  393.    ------------- 
  394.    --  The following new signals are defined for this widget 
  395.  
  396.    --  <signals> 
  397.    --  - "changed" 
  398.    --    procedure Handler (Combo : access Gtk_Combo_Box_Record'Class); 
  399.    --    Emitted when the active item is changed. The can be due to the user 
  400.    --    selecting a different item from the list, or due to a call to 
  401.    --    Set_Active_Iter. It will also be emitted while typing into a 
  402.    --    Gtk_Combo_Box_Entry, as well as when selecting an item from the 
  403.    --    Gtk_Combo_Box_Entry's list. 
  404.    --  </signals> 
  405.  
  406.    Signal_Changed : constant Glib.Signal_Name := "changed"; 
  407.  
  408. private 
  409.    pragma Import (C, Get_Type, "gtk_combo_box_get_type"); 
  410.  
  411.    Active_Property : constant Glib.Properties.Property_Int := 
  412.      Glib.Properties.Build ("active"); 
  413.    Add_Tearoffs_Property : constant Glib.Properties.Property_Boolean := 
  414.      Glib.Properties.Build ("add-tearoffs"); 
  415.    Arrow_Size_Property : constant Glib.Properties.Property_Int := 
  416.      Glib.Properties.Build ("arrow-size"); 
  417.    Button_Sensitivity_Property : constant Glib.Properties.Property_Enum := 
  418.      Glib.Properties.Build ("button-sensitivity"); 
  419.    Column_Span_Column_Property : constant Glib.Properties.Property_Int := 
  420.      Glib.Properties.Build ("column-span-column"); 
  421.    Focus_On_Click_Property : constant Glib.Properties.Property_Boolean := 
  422.      Glib.Properties.Build ("focus-on-click"); 
  423.    Has_Frame_Property : constant Glib.Properties.Property_Boolean := 
  424.      Glib.Properties.Build ("has-frame"); 
  425.    Model_Property : constant Glib.Properties.Property_Object := 
  426.      Glib.Properties.Build ("model"); 
  427.    Popup_Shown_Property : constant Glib.Properties.Property_Boolean := 
  428.      Glib.Properties.Build ("popup-shown"); 
  429.    Row_Span_Column_Property : constant Glib.Properties.Property_Int := 
  430.      Glib.Properties.Build ("row-span-column"); 
  431.    Shadow_Type_Property : constant Glib.Properties.Property_Enum := 
  432.      Glib.Properties.Build ("shadow-type"); 
  433.    Tearoff_Title_Property : constant Glib.Properties.Property_String := 
  434.      Glib.Properties.Build ("tearoff-title"); 
  435.    Wrap_Width_Property : constant Glib.Properties.Property_Int := 
  436.      Glib.Properties.Build ("wrap-width"); 
  437.  
  438.    Appears_As_List_Property : constant Glib.Properties.Property_Boolean := 
  439.      Glib.Properties.Build ("appears-as-list"); 
  440. end Gtk.Combo_Box; 
  441.  
  442. --  No binding: gtk_combo_box_get_popup_accessible