1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2010 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.    function Get_Type return Glib.GType; 
  81.    --  Returns the internal value used for Gtk_Combo_Box widgets 
  82.  
  83.    procedure Set_Model 
  84.      (Combo_Box : access Gtk_Combo_Box_Record; 
  85.       Model     : Gtk.Tree_Model.Gtk_Tree_Model := null); 
  86.    function Get_Model 
  87.      (Combo_Box : access Gtk_Combo_Box_Record) 
  88.       return Gtk.Tree_Model.Gtk_Tree_Model; 
  89.    --  Sets the model used by Combo_Box to be Model. Will unset a previously 
  90.    --  set model (if applicable). If model is null, then it will unset the 
  91.    --  model. Note that this function does not clear the cell renderers, you 
  92.    --  have to call Gtk.Cell_Layout.Clear yourself if you need to set up 
  93.    --  different cell renderers for the new model. 
  94.  
  95.    procedure Set_Active 
  96.      (Combo_Box : access Gtk_Combo_Box_Record; Index : Gint); 
  97.    function Get_Active 
  98.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  99.    --  Returns the index of the currently active item, or -1 if there's no 
  100.    --  active item. If the model is a non-flat treemodel, and the active item 
  101.    --  is not an immediate child of the root of the tree, this function returns 
  102.    --  Gtk.Tree_Model.Get_Indices (Path)[0], where Path is the Gtk_Tree_Path of 
  103.    --  the active model. 
  104.  
  105.    procedure Set_Active_Iter 
  106.      (Combo_Box : access Gtk_Combo_Box_Record; 
  107.       Iter      : Gtk.Tree_Model.Gtk_Tree_Iter); 
  108.    function Get_Active_Iter 
  109.      (Combo_Box : access Gtk_Combo_Box_Record) 
  110.       return Gtk.Tree_Model.Gtk_Tree_Iter; 
  111.    --  Sets the current active item to be the one referenced by Iter. 
  112.    --  Iter must correspond to a path of depth one. 
  113.  
  114.    procedure Set_Wrap_Width 
  115.      (Combo_Box : access Gtk_Combo_Box_Record; Width : Gint); 
  116.    function Get_Wrap_Width 
  117.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  118.    --  Returns the wrap width which is used to determine the number 
  119.    --  of columns for the popup menu. If the wrap width is larger than 
  120.    --  1, the combo box is in table mode. This can be used for instance to 
  121.    --  display a matrix of color (a color palette to choose from). 
  122.    --  See also Set_Column_Span_Column 
  123.  
  124.    procedure Set_Add_Tearoffs 
  125.      (Combo_Box : access Gtk_Combo_Box_Record; Add_Tearoffs : Boolean); 
  126.    function Get_Add_Tearoffs 
  127.      (Combo_Box : access Gtk_Combo_Box_Record) return Boolean; 
  128.    --  Sets whether the popup menu should have a tearoff menu item. 
  129.    --  Clicking on this menu will detach the combo into a floating window that 
  130.    --  the user can put anywhere on the screen. 
  131.  
  132.    procedure Set_Button_Sensitivity 
  133.      (Combo_Box   : access Gtk_Combo_Box_Record; 
  134.       Sensitivity : Gtk.Enums.Gtk_Sensitivity_Type); 
  135.    function Get_Button_Sensitivity 
  136.      (Combo_Box : access Gtk_Combo_Box_Record) 
  137.       return Gtk.Enums.Gtk_Sensitivity_Type; 
  138.    --  Sets whether the dropdown button of the combo box should be always 
  139.    --  sensitive (Gtk_Sensitivity_On), never sensitive (Gtk_Sensitivity_Off) 
  140.    --  or only if there is at least one item to display (Gtk_Sensitivity_Auto). 
  141.  
  142.    procedure Set_Column_Span_Column 
  143.      (Combo_Box : access Gtk_Combo_Box_Record; Column_Span : Gint); 
  144.    function Get_Column_Span_Column 
  145.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  146.    --  Sets the column with column span information for Combo_Box to be 
  147.    --  Column_Span. The column span column contains integers which indicate 
  148.    --  how many columns an item should span. This applies to grid combos, see 
  149.    --  also Set_Wrap_Width. 
  150.  
  151.    procedure Set_Row_Span_Column 
  152.      (Combo_Box : access Gtk_Combo_Box_Record; Row_Span : Gint); 
  153.    function Get_Row_Span_Column 
  154.      (Combo_Box : access Gtk_Combo_Box_Record) return Gint; 
  155.    --  Sets the column with row span information for Combo_Box to be Row_Span. 
  156.    --  The row span column contains integers which indicate how many rows 
  157.    --  an item should span. 
  158.  
  159.    procedure Set_Focus_On_Click 
  160.      (Combo          : access Gtk_Combo_Box_Record; 
  161.       Focus_On_Click : Boolean); 
  162.    function Get_Focus_On_Click 
  163.      (Combo : access Gtk_Combo_Box_Record) return Boolean; 
  164.    --  Sets whether the combo box will grab focus when it is clicked with 
  165.    --  the mouse. Making mouse clicks not grab focus is useful in places 
  166.    --  like toolbars where you don't want the keyboard focus removed from 
  167.    --  the main area of the application. 
  168.  
  169.    procedure Set_Row_Separator_Func 
  170.      (Combo_Box : access Gtk_Combo_Box_Record; 
  171.       Func      : Gtk.Tree_View.Gtk_Tree_View_Row_Separator_Func; 
  172.       Data      : System.Address; 
  173.       Destroy   : Glib.G_Destroy_Notify_Address := null); 
  174.    function Get_Row_Separator_Func 
  175.      (Combo_Box : access Gtk_Combo_Box_Record) 
  176.       return Gtk.Tree_View.Gtk_Tree_View_Row_Separator_Func; 
  177.    --  Sets the row separator function, which is used to determine 
  178.    --  whether a row should be drawn as a separator. If the row separator 
  179.    --  function is null, no separators are drawn. This is the default value. 
  180.  
  181.    procedure Set_Title 
  182.      (Combo_Box : access Gtk_Combo_Box_Record; 
  183.       Title     : String); 
  184.    function Get_Title 
  185.      (Combo_Box : access Gtk_Combo_Box_Record) 
  186.       return String; 
  187.    --  Sets or Gets the menu's title in tearoff mode. 
  188.  
  189.    --------------------------- 
  190.    -- Text-only combo boxes -- 
  191.    --------------------------- 
  192.    --  If your combo box only contains text, you do not necessarily have to go 
  193.    --  through the more complex use of a Gtk_Tree_Model. 
  194.  
  195.    procedure Gtk_New_Text    (Combo : out Gtk_Combo_Box); 
  196.    procedure Initialize_Text (Combo : access Gtk_Combo_Box_Record'Class); 
  197.    --  Convenience function which constructs a new text combo box, which is 
  198.    --  Gtk_Combo_Box just displaying strings. If you use this function to 
  199.    --  create a text combo box, you should only manipulate its data source with 
  200.    --  the following convenience functions: Append_Text, Insert_Text, 
  201.    --  Prepend_Text and Remove_Text 
  202.  
  203.    procedure Append_Text 
  204.      (Combo_Box : access Gtk_Combo_Box_Record; Text : String); 
  205.    procedure Prepend_Text 
  206.      (Combo_Box : access Gtk_Combo_Box_Record; Text : String); 
  207.    procedure Insert_Text 
  208.      (Combo_Box : access Gtk_Combo_Box_Record; 
  209.       Position  : Gint; 
  210.       Text      : String); 
  211.    --  Adds Text to the list of strings stored in Combo_Box. Note that 
  212.    --  you can only use this function with combo boxes constructed with 
  213.    --  Gtk_New_Text. 
  214.  
  215.    procedure Remove_Text 
  216.      (Combo_Box : access Gtk_Combo_Box_Record; Position : Gint); 
  217.    --  Removes the string at Position from Combo_Box. Note that you can only 
  218.    --  use this function with combo boxes constructed with Gtk_New_Text. 
  219.  
  220.    function Get_Active_Text 
  221.      (Combo_Box : access Gtk_Combo_Box_Record) return String; 
  222.    --  Returns the currently active string in Combo_Box or "" if none 
  223.    --  is selected.  Note that you can only use this function with combo 
  224.    --  boxes constructed with Gtk_New_Text. 
  225.  
  226.    -------------------------- 
  227.    -- Programmatic Control -- 
  228.    -------------------------- 
  229.  
  230.    procedure Popdown (Combo_Box : access Gtk_Combo_Box_Record); 
  231.    procedure Popup   (Combo_Box : access Gtk_Combo_Box_Record); 
  232.    --  Hides or pops up the menu or dropdown list of Combo_Box. 
  233.    --  This function is mostly intended for use by accessibility technologies; 
  234.    --  applications should have little use for it. 
  235.  
  236.    ---------------- 
  237.    -- Interfaces -- 
  238.    ---------------- 
  239.    --  This class implements several interfaces. See Glib.Types 
  240.    -- 
  241.    --  - "Gtk_Cell_Layout" 
  242.    --    This interface should be used to add new renderers to the view, to 
  243.    --    render various columns of the model 
  244.    --  - "Gtk_Cell_Editable" 
  245.    --    This interface should be used to edit the contents of a tree model 
  246.    --    cell 
  247.  
  248.    package Implements_Cell_Layout is new Glib.Types.Implements 
  249.      (Gtk.Cell_Layout.Gtk_Cell_Layout, Gtk_Combo_Box_Record, Gtk_Combo_Box); 
  250.    function "+" 
  251.      (Box : access Gtk_Combo_Box_Record'Class) 
  252.       return Gtk.Cell_Layout.Gtk_Cell_Layout 
  253.       renames Implements_Cell_Layout.To_Interface; 
  254.    function "-" 
  255.      (Layout : Gtk.Cell_Layout.Gtk_Cell_Layout) 
  256.       return Gtk_Combo_Box 
  257.       renames Implements_Cell_Layout.To_Object; 
  258.    --  Converts to and from the Gtk_Cell_Layout interface 
  259.  
  260.    package Implements_Cell_Editable is new Glib.Types.Implements 
  261.      (Gtk.Cell_Editable.Gtk_Cell_Editable, 
  262.       Gtk_Combo_Box_Record, Gtk_Combo_Box); 
  263.    function "+" 
  264.      (Box : access Gtk_Combo_Box_Record'Class) 
  265.       return Gtk.Cell_Editable.Gtk_Cell_Editable 
  266.       renames Implements_Cell_Editable.To_Interface; 
  267.    function "-" 
  268.      (Editable : Gtk.Cell_Editable.Gtk_Cell_Editable) 
  269.       return Gtk_Combo_Box 
  270.       renames Implements_Cell_Editable.To_Object; 
  271.    --  Converts to and from the Gtk_Cell_Editable interface 
  272.  
  273.    ---------------- 
  274.    -- Properties -- 
  275.    ---------------- 
  276.    --  The following properties are defined for this widget. See 
  277.    --  Glib.Properties for more information on properties. 
  278.  
  279.    --  <properties> 
  280.    --  Name:  Active_Property 
  281.    --  Type:  Int 
  282.    --  Descr: The item which is currently active 
  283.    -- 
  284.    --  Name:  Add_Tearoffs_Property 
  285.    --  Type:  Boolean 
  286.    --  Descr: Whether dropdowns should have a tearoff menu item 
  287.    -- 
  288.    --  Name:  Button_Sensitivity_Property 
  289.    --  Type:  Enum 
  290.    --  Descr: Whether the dropdown button is sensitive when the model is empty 
  291.    -- 
  292.    --  Name:  Column_Span_Column_Property 
  293.    --  Type:  Int 
  294.    --  Descr: TreeModel column containing the column span values 
  295.    -- 
  296.    --  Name:  Focus_On_Click_Property 
  297.    --  Type:  Boolean 
  298.    --  Descr: Whether the combo box grabs focus when it is clicked with the 
  299.    --         mouse 
  300.    -- 
  301.    --  Name:  Has_Frame_Property 
  302.    --  Type:  Boolean 
  303.    --  Descr: Whether the combo box draws a frame around the child 
  304.    -- 
  305.    --  Name:  Model_Property 
  306.    --  Type:  Object 
  307.    --  Descr: The model for the combo box 
  308.    -- 
  309.    --  Name:  Popup_Shown_Property 
  310.    --  Type:  Boolean 
  311.    --  Descr: Whether the combo's dropdown is shown 
  312.    -- 
  313.    --  Name:  Row_Span_Column_Property 
  314.    --  Type:  Int 
  315.    --  Descr: TreeModel column containing the row span values 
  316.    -- 
  317.    --  Name:  Tearoff_Title_Property 
  318.    --  Type:  String 
  319.    --  Descr: A title that may be displayed by the window manager when the 
  320.    --         popup is torn-off 
  321.    -- 
  322.    --  Name:  Wrap_Width_Property 
  323.    --  Type:  Int 
  324.    --  Descr: Wrap width for layouting the items in a grid 
  325.    --  </properties> 
  326.  
  327.    Active_Property             : constant Glib.Properties.Property_Int; 
  328.    Add_Tearoffs_Property       : constant Glib.Properties.Property_Boolean; 
  329.    Button_Sensitivity_Property : constant Glib.Properties.Property_Enum; 
  330.    Column_Span_Column_Property : constant Glib.Properties.Property_Int; 
  331.    Focus_On_Click_Property     : constant Glib.Properties.Property_Boolean; 
  332.    Has_Frame_Property          : constant Glib.Properties.Property_Boolean; 
  333.    Model_Property              : constant Glib.Properties.Property_Object; 
  334.    Popup_Shown_Property        : constant Glib.Properties.Property_Boolean; 
  335.    Row_Span_Column_Property    : constant Glib.Properties.Property_Int; 
  336.    Tearoff_Title_Property      : constant Glib.Properties.Property_String; 
  337.    Wrap_Width_Property         : constant Glib.Properties.Property_Int; 
  338.  
  339.    ---------------------- 
  340.    -- Style Properties -- 
  341.    ---------------------- 
  342.    --  The following properties can be changed through the gtk theme and 
  343.    --  configuration files, and retrieved through Gtk.Widget.Style_Get_Property 
  344.  
  345.    --  <style_properties> 
  346.    --  Name:  Appears_As_List_Property 
  347.    --  Type:  Boolean 
  348.    --  Descr: Whether dropdowns should look like lists rather than menus 
  349.    -- 
  350.    --  Name:  Arrow_Size_Property 
  351.    --  Type:  Int 
  352.    --  Descr: The minimum size of the arrow in the combo box 
  353.    -- 
  354.    --  Name:  Shadow_Type_Property 
  355.    --  Type:  Enum 
  356.    --  Descr: Which kind of shadow to draw around the combo box 
  357.    --  </style_properties> 
  358.  
  359.    Appears_As_List_Property : constant Glib.Properties.Property_Boolean; 
  360.    Arrow_Size_Property      : constant Glib.Properties.Property_Int; 
  361.    Shadow_Type_Property     : constant Glib.Properties.Property_Enum; 
  362.  
  363.    ------------- 
  364.    -- Signals -- 
  365.    ------------- 
  366.    --  The following new signals are defined for this widget 
  367.  
  368.    --  <signals> 
  369.    --  - "changed" 
  370.    --    procedure Handler (Combo : access Gtk_Combo_Box_Record'Class); 
  371.    --    Emitted when the active item is changed. The can be due to the user 
  372.    --    selecting a different item from the list, or due to a call to 
  373.    --    Set_Active_Iter. It will also be emitted while typing into a 
  374.    --    Gtk_Combo_Box_Entry, as well as when selecting an item from the 
  375.    --    Gtk_Combo_Box_Entry's list. 
  376.    --  </signals> 
  377.  
  378.    Signal_Changed : constant Glib.Signal_Name := "changed"; 
  379.  
  380. private 
  381.    pragma Import (C, Get_Type, "gtk_combo_box_get_type"); 
  382.  
  383.    Active_Property : constant Glib.Properties.Property_Int := 
  384.      Glib.Properties.Build ("active"); 
  385.    Add_Tearoffs_Property : constant Glib.Properties.Property_Boolean := 
  386.      Glib.Properties.Build ("add-tearoffs"); 
  387.    Arrow_Size_Property : constant Glib.Properties.Property_Int := 
  388.      Glib.Properties.Build ("arrow-size"); 
  389.    Button_Sensitivity_Property : constant Glib.Properties.Property_Enum := 
  390.      Glib.Properties.Build ("button-sensitivity"); 
  391.    Column_Span_Column_Property : constant Glib.Properties.Property_Int := 
  392.      Glib.Properties.Build ("column-span-column"); 
  393.    Focus_On_Click_Property : constant Glib.Properties.Property_Boolean := 
  394.      Glib.Properties.Build ("focus-on-click"); 
  395.    Has_Frame_Property : constant Glib.Properties.Property_Boolean := 
  396.      Glib.Properties.Build ("has-frame"); 
  397.    Model_Property : constant Glib.Properties.Property_Object := 
  398.      Glib.Properties.Build ("model"); 
  399.    Popup_Shown_Property : constant Glib.Properties.Property_Boolean := 
  400.      Glib.Properties.Build ("popup-shown"); 
  401.    Row_Span_Column_Property : constant Glib.Properties.Property_Int := 
  402.      Glib.Properties.Build ("row-span-column"); 
  403.    Shadow_Type_Property : constant Glib.Properties.Property_Enum := 
  404.      Glib.Properties.Build ("shadow-type"); 
  405.    Tearoff_Title_Property : constant Glib.Properties.Property_String := 
  406.      Glib.Properties.Build ("tearoff-title"); 
  407.    Wrap_Width_Property : constant Glib.Properties.Property_Int := 
  408.      Glib.Properties.Build ("wrap-width"); 
  409.  
  410.    Appears_As_List_Property : constant Glib.Properties.Property_Boolean := 
  411.      Glib.Properties.Build ("appears-as-list"); 
  412. end Gtk.Combo_Box; 
  413.  
  414. --  No binding: gtk_combo_box_get_popup_accessible