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