1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2001-2007 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. --  The Gtk_Tree_Selection object is a helper object to manage the selection 
  31. --  for a Gtk_Tree_View widget. The Gtk_Tree_Selection object is automatically 
  32. --  created when a new Gtk_Tree_View widget is created, and cannot exist 
  33. --  independentally of this widget. The primary reason the Gtk_Tree_Selection 
  34. --  objects exists is for cleanliness of code and API. That is, there is no 
  35. --  conceptual reason all these functions could not be methods on the 
  36. --  Gtk_Tree_View widget instead of separate function. 
  37. -- 
  38. --  The Gtk_Tree_Selection object is gotten from a Gtk_Tree_View by calling 
  39. --  Gtk.Tree_View.Get_Selection. It can be manipulated to check the selection 
  40. --  status of the tree, as well as select and deselect individual rows. 
  41. --  Selection is done completely view side. As a result, multiple views of the 
  42. --  same model can have completely different selections. Additionally, you 
  43. --  cannot change the selection of a row on the model that is not currently 
  44. --  displayed by the view without expanding its parents first. 
  45. -- 
  46. --  One of the important things to remember when monitoring the selection of a 
  47. --  view is that the "changed" signal is mostly a hint. That is, it may only 
  48. --  emit one signal when a range of rows is selected. Additionally, it may on 
  49. --  occasion emit a "changed" signal when nothing has happened (mostly as a 
  50. --  result of programmers calling select_row on an already selected row). 
  51. --  </description> 
  52. --  <c_version>2.8.17</c_version> 
  53. --  <group>Trees and Lists</group> 
  54.  
  55. with Glib.Object; 
  56. with Gtk; 
  57. with Gtk.Enums;      use Gtk.Enums; 
  58. with Gtk.Tree_Model; 
  59. with Gtk.Widget;     use Gtk.Widget; 
  60.  
  61. package Gtk.Tree_Selection is 
  62.  
  63.    type Gtk_Tree_Selection_Record is 
  64.      new Glib.Object.GObject_Record with private; 
  65.    type Gtk_Tree_Selection is access all Gtk_Tree_Selection_Record'Class; 
  66.  
  67.    function Get_Type return Glib.GType; 
  68.    --  Return the internal type associated with Gtk_Tree_Selection. 
  69.  
  70.    procedure Set_Mode 
  71.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  72.       The_Type  : Gtk_Selection_Mode); 
  73.    function Get_Mode 
  74.      (Selection : access Gtk_Tree_Selection_Record'Class) 
  75.       return Gtk_Selection_Mode; 
  76.    --  Set the selection mode of the Selection. 
  77.    --  If the previous type was Gtk_Selection_Multiple, 
  78.    --  then the anchor is kept selected, if it was  previously selected. 
  79.  
  80.    function Get_Tree_View 
  81.      (Selection : access Gtk_Tree_Selection_Record'Class) 
  82.       return Gtk.Widget.Gtk_Widget; 
  83.    --  Return the tree view associated with Selection. 
  84.  
  85.    function Count_Selected_Rows 
  86.      (Selection : access Gtk_Tree_Selection_Record) return Gint; 
  87.    --  Returns the number of rows that have been selected. 
  88.  
  89.    procedure Get_Selected 
  90.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  91.       Model     : out Gtk.Tree_Model.Gtk_Tree_Model; 
  92.       Iter      : out Gtk.Tree_Model.Gtk_Tree_Iter); 
  93.    --  Set Iter to the currently selected node if Selection 
  94.    --  is set to Gtk_Selection_Single or Gtk_Selection_Browse. 
  95.    --  Iter is set to Null_Iter if no node is currently selected. 
  96.    --  Model is filled with the current model as a convenience. This function 
  97.    --  will not work if Selection is set to Gtk_Selection_Multiple. 
  98.  
  99.    procedure Get_Selected_Rows 
  100.      (Selection : access Gtk_Tree_Selection_Record; 
  101.       Model     : out Gtk.Tree_Model.Gtk_Tree_Model; 
  102.       Path_List : out Gtk.Tree_Model.Gtk_Tree_Path_List.Glist); 
  103.    --  Creates a list of path of all selected rows. Additionally, if you are 
  104.    --  planning on modifying the model after calling this function, you may 
  105.    --  want to convert the returned list into a list of Gtk_Tree_Row_Reference. 
  106.    -- 
  107.    --  You must free the resulting list by calling Path_Free on each item, and 
  108.    --  then freeing the list itself. 
  109.  
  110.    generic 
  111.       type Data_Type is private; 
  112.    package Selection_Foreach is 
  113.  
  114.       type Data_Type_Access is access all Data_Type; 
  115.  
  116.       type Foreach_Func is access procedure 
  117.         (Model : Gtk.Tree_Model.Gtk_Tree_Model; 
  118.          Path  : Gtk.Tree_Model.Gtk_Tree_Path; 
  119.          Iter  : Gtk.Tree_Model.Gtk_Tree_Iter; 
  120.          Data  : Data_Type_Access); 
  121.  
  122.       procedure Selected_Foreach 
  123.         (Selection : access Gtk_Tree_Selection_Record'Class; 
  124.          Func      : Foreach_Func; 
  125.          Data      : Data_Type_Access); 
  126.       --  Call Func for each selected node. 
  127.  
  128.    end Selection_Foreach; 
  129.  
  130.    procedure Select_Path 
  131.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  132.       Path      : Gtk.Tree_Model.Gtk_Tree_Path); 
  133.    procedure Unselect_Path 
  134.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  135.       Path      : Gtk.Tree_Model.Gtk_Tree_Path); 
  136.    --  Selects or unselects the row at path. 
  137.  
  138.    function Path_Is_Selected 
  139.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  140.       Path      : Gtk.Tree_Model.Gtk_Tree_Path) 
  141.       return Boolean; 
  142.    --  Return True if the row pointed to by path is currently selected. 
  143.    --  If path does not point to a valid location, False is returned 
  144.  
  145.    procedure Select_Iter 
  146.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  147.       Iter      : Gtk.Tree_Model.Gtk_Tree_Iter); 
  148.    procedure Unselect_Iter 
  149.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  150.       Iter      : Gtk.Tree_Model.Gtk_Tree_Iter); 
  151.    --  Selects or unselects the row pointed to by the specified iterator. 
  152.  
  153.    function Iter_Is_Selected 
  154.      (Selection : access Gtk_Tree_Selection_Record'Class; 
  155.       Iter      : Gtk.Tree_Model.Gtk_Tree_Iter) 
  156.       return Boolean; 
  157.    --  Return True if the row pointed to by path is currently selected. 
  158.  
  159.    procedure Select_All (Selection : access Gtk_Tree_Selection_Record'Class); 
  160.    procedure Unselect_All (Selection : access Gtk_Tree_Selection_Record'Class); 
  161.    --  Selects or unselects all the nodes. 
  162.    --  Selection must be set to Gtk_Selection_Multiple mode. 
  163.  
  164.    procedure Select_Range 
  165.      (Selection  : access Gtk_Tree_Selection_Record'Class; 
  166.       Start_Path : Gtk.Tree_Model.Gtk_Tree_Path; 
  167.       End_Path   : Gtk.Tree_Model.Gtk_Tree_Path); 
  168.    procedure Unselect_Range 
  169.      (Selection  : access Gtk_Tree_Selection_Record; 
  170.       Start_Path : Gtk.Tree_Model.Gtk_Tree_Path; 
  171.       End_Path   : Gtk.Tree_Model.Gtk_Tree_Path); 
  172.    --  Selects or unselects a range of nodes, determined by Start_Path and 
  173.    --  End_Path inclusive 
  174.  
  175.    ------------- 
  176.    -- Signals -- 
  177.    ------------- 
  178.  
  179.    --  <signals> 
  180.    --  The following new signals are defined for this widget: 
  181.    -- 
  182.    --  - "changed" 
  183.    --    procedure Handler 
  184.    --      (Widget : access Gtk_Tree_Selection_Record'Class'Class); 
  185.    --    Emitted whenever the selection has (possibly) changed. Please note 
  186.    --    that this signal is mostly a hint. It may only be emitted once when a 
  187.    --    range of rows are selected, and it may occasionally be emitted when 
  188.    --    nothing has happened. 
  189.    -- 
  190.    --  </signals> 
  191.  
  192.    Signal_Changed : constant Glib.Signal_Name := "changed"; 
  193.  
  194. private 
  195.    type Gtk_Tree_Selection_Record is 
  196.      new Glib.Object.GObject_Record with null record; 
  197.  
  198.    pragma Import (C, Get_Type, "gtk_tree_selection_get_type"); 
  199.  
  200. end Gtk.Tree_Selection; 
  201.  
  202. --   missing: 
  203. -- 
  204. --    procedure Set_Select_Function 
  205. --      (Selection : access Gtk_Tree_Selection_Record'Class; 
  206. --       Func      : Gtk_Tree_Selection_Func; 
  207. --       Data      : gpointer; 
  208. --       Destroy   : Gtk_Destroy_Notify); 
  209. -- 
  210. --    function Get_User_Data 
  211. --      (Selection : access Gtk_Tree_Selection_Record'Class) return gpointer;