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. --  The Gtk.Tree_Store.Gtk_Tree_Store object is a list model for use with a 
  26. --  Gtk.Tree_View.Gtk_Tree_View widget. It implements the 
  27. --  Gtk.Tree_Model.Gtk_Tree_Model interface, and consequentialy, can use all of 
  28. --  the methods available there. It also implements the 
  29. --  Gtk.Tree_Sortable.Gtk_Tree_Sortable interface so it can be sorted by the 
  30. --  view. Finally, it also implements the tree <link linkend="gtktreednd">drag 
  31. --  and drop</link> interfaces. 
  32. -- 
  33. --  == GtkTreeStore as GtkBuildable == 
  34. -- 
  35. --  The GtkTreeStore implementation of the Gtk.Buildable.Gtk_Buildable 
  36. --  interface allows to specify the model columns with a <columns> element that 
  37. --  may contain multiple <column> elements, each specifying one model column. 
  38. --  The "type" attribute specifies the data type for the column. 
  39. -- 
  40. --  == A UI Definition fragment for a tree store == 
  41. -- 
  42. --    <object class="GtkTreeStore"> 
  43. --    <columns> 
  44. --    <column type="gchararray"/> 
  45. --    <column type="gchararray"/> 
  46. --    <column type="gint"/> 
  47. --    </columns> 
  48. --    </object> 
  49. --  </description> 
  50. pragma Ada_2005; 
  51.  
  52. pragma Warnings (Off, "*is already use-visible*"); 
  53. with Glib;                 use Glib; 
  54. with Glib.Types;           use Glib.Types; 
  55. with Glib.Values;          use Glib.Values; 
  56. with Gtk.Buildable;        use Gtk.Buildable; 
  57. with Gtk.Enums;            use Gtk.Enums; 
  58. with Gtk.Selection_Data;   use Gtk.Selection_Data; 
  59. with Gtk.Tree_Drag_Dest;   use Gtk.Tree_Drag_Dest; 
  60. with Gtk.Tree_Drag_Source; use Gtk.Tree_Drag_Source; 
  61. with Gtk.Tree_Model;       use Gtk.Tree_Model; 
  62. with Gtk.Tree_Sortable;    use Gtk.Tree_Sortable; 
  63.  
  64. package Gtk.Tree_Store is 
  65.  
  66.    type Gtk_Tree_Store_Record is new Gtk_Root_Tree_Model_Record with null record; 
  67.    type Gtk_Tree_Store is access all Gtk_Tree_Store_Record'Class; 
  68.  
  69.    --------------- 
  70.    -- Callbacks -- 
  71.    --------------- 
  72.  
  73.    type Gtk_Tree_Model_Foreach_Func is access function 
  74.      (Model : Gtk.Tree_Model.Gtk_Tree_Model; 
  75.       Path  : Gtk.Tree_Model.Gtk_Tree_Path; 
  76.       Iter  : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean; 
  77.    --  Type of the callback passed to Gtk.Tree_Model.Foreach to iterate over 
  78.    --  the rows in a tree model. 
  79.    --  "model": the Gtk.Tree_Model.Gtk_Tree_Model being iterated 
  80.    --  "path": the current Gtk.Tree_Model.Gtk_Tree_Path 
  81.    --  "iter": the current Gtk.Tree_Model.Gtk_Tree_Iter 
  82.  
  83.    type Gtk_Tree_Iter_Compare_Func is access function 
  84.      (Model : Gtk.Tree_Model.Gtk_Tree_Model; 
  85.       A     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  86.       B     : Gtk.Tree_Model.Gtk_Tree_Iter) return Gint; 
  87.    --  A GtkTreeIterCompareFunc should return a negative integer, zero, or a 
  88.    --  positive integer if A sorts before B, A sorts with B, or A sorts after B 
  89.    --  respectively. If two iters compare as equal, their order in the sorted 
  90.    --  model is undefined. In order to ensure that the 
  91.    --  Gtk.Tree_Sortable.Gtk_Tree_Sortable behaves as expected, the 
  92.    --  GtkTreeIterCompareFunc must define a partial order on the model, i.e. it 
  93.    --  must be reflexive, antisymmetric and transitive. 
  94.    --  For example, if Model is a product catalogue, then a compare function 
  95.    --  for the "price" column could be one which returns 'price_of(A) - 
  96.    --  price_of(B)'. 
  97.    --  "model": The Gtk.Tree_Model.Gtk_Tree_Model the comparison is within 
  98.    --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  99.    --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  100.  
  101.    ------------------ 
  102.    -- Constructors -- 
  103.    ------------------ 
  104.  
  105.    procedure Gtk_New (Tree_Store : out Gtk_Tree_Store; Types : GType_Array); 
  106.    procedure Initialize 
  107.       (Tree_Store : not null access Gtk_Tree_Store_Record'Class; 
  108.        Types      : GType_Array); 
  109.    --  Non vararg creation function. Used primarily by language bindings. 
  110.    --  "types": an array of GType types for the columns, from first to last 
  111.  
  112.    function Gtk_Tree_Store_Newv (Types : GType_Array) return Gtk_Tree_Store; 
  113.    --  Non vararg creation function. Used primarily by language bindings. 
  114.    --  "types": an array of GType types for the columns, from first to last 
  115.  
  116.    function Get_Type return Glib.GType; 
  117.    pragma Import (C, Get_Type, "gtk_tree_store_get_type"); 
  118.  
  119.    ------------- 
  120.    -- Methods -- 
  121.    ------------- 
  122.  
  123.    procedure Append 
  124.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  125.        Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter; 
  126.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter); 
  127.    --  Appends a new row to Tree_Store. If Parent is non-null, then it will 
  128.    --  append the new row after the last child of Parent, otherwise it will 
  129.    --  append a row to the top level. Iter will be changed to point to this new 
  130.    --  row. The row will be empty after this function is called. To fill in 
  131.    --  values, you need to call gtk_tree_store_set or Gtk.Tree_Store.Set_Value. 
  132.    --  "iter": An unset Gtk.Tree_Model.Gtk_Tree_Iter to set to the appended 
  133.    --  row 
  134.    --  "parent": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  135.  
  136.    procedure Clear (Tree_Store : not null access Gtk_Tree_Store_Record); 
  137.    --  Removes all rows from Tree_Store 
  138.  
  139.    procedure Insert 
  140.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  141.        Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter; 
  142.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  143.        Position   : Gint); 
  144.    --  Creates a new row at Position. If parent is non-null, then the row will 
  145.    --  be made a child of Parent. Otherwise, the row will be created at the 
  146.    --  toplevel. If Position is -1 or is larger than the number of rows at that 
  147.    --  level, then the new row will be inserted to the end of the list. Iter 
  148.    --  will be changed to point to this new row. The row will be empty after 
  149.    --  this function is called. To fill in values, you need to call 
  150.    --  gtk_tree_store_set or Gtk.Tree_Store.Set_Value. 
  151.    --  "iter": An unset Gtk.Tree_Model.Gtk_Tree_Iter to set to the new row 
  152.    --  "parent": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  153.    --  "position": position to insert the new row, or -1 for last 
  154.  
  155.    procedure Insert_After 
  156.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  157.        Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter; 
  158.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  159.        Sibling    : Gtk.Tree_Model.Gtk_Tree_Iter); 
  160.    --  Inserts a new row after Sibling. If Sibling is null, then the row will 
  161.    --  be prepended to Parent 's children. If Parent and Sibling are null, then 
  162.    --  the row will be prepended to the toplevel. If both Sibling and Parent 
  163.    --  are set, then Parent must be the parent of Sibling. When Sibling is set, 
  164.    --  Parent is optional. 
  165.    --  Iter will be changed to point to this new row. The row will be empty 
  166.    --  after this function is called. To fill in values, you need to call 
  167.    --  gtk_tree_store_set or Gtk.Tree_Store.Set_Value. 
  168.    --  "iter": An unset Gtk.Tree_Model.Gtk_Tree_Iter to set to the new row 
  169.    --  "parent": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  170.    --  "sibling": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  171.  
  172.    procedure Insert_Before 
  173.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  174.        Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter; 
  175.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  176.        Sibling    : Gtk.Tree_Model.Gtk_Tree_Iter); 
  177.    --  Inserts a new row before Sibling. If Sibling is null, then the row will 
  178.    --  be appended to Parent 's children. If Parent and Sibling are null, then 
  179.    --  the row will be appended to the toplevel. If both Sibling and Parent are 
  180.    --  set, then Parent must be the parent of Sibling. When Sibling is set, 
  181.    --  Parent is optional. 
  182.    --  Iter will be changed to point to this new row. The row will be empty 
  183.    --  after this function is called. To fill in values, you need to call 
  184.    --  gtk_tree_store_set or Gtk.Tree_Store.Set_Value. 
  185.    --  "iter": An unset Gtk.Tree_Model.Gtk_Tree_Iter to set to the new row 
  186.    --  "parent": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  187.    --  "sibling": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  188.  
  189.    function Is_Ancestor 
  190.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  191.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  192.        Descendant : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean; 
  193.    --  Returns True if Iter is an ancestor of Descendant. That is, Iter is the 
  194.    --  parent (or grandparent or great-grandparent) of Descendant. 
  195.    --  "iter": A valid Gtk.Tree_Model.Gtk_Tree_Iter 
  196.    --  "descendant": A valid Gtk.Tree_Model.Gtk_Tree_Iter 
  197.  
  198.    function Iter_Depth 
  199.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  200.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter) return Gint; 
  201.    --  Returns the depth of Iter. This will be 0 for anything on the root 
  202.    --  level, 1 for anything down a level, etc. 
  203.    --  "iter": A valid Gtk.Tree_Model.Gtk_Tree_Iter 
  204.  
  205.    function Iter_Is_Valid 
  206.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  207.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean; 
  208.    --  WARNING: This function is slow. Only use it for debugging and/or 
  209.    --  testing purposes. 
  210.    --  Checks if the given iter is a valid iter for this 
  211.    --  Gtk.Tree_Store.Gtk_Tree_Store. 
  212.    --  Since: gtk+ 2.2 
  213.    --  "iter": A Gtk.Tree_Model.Gtk_Tree_Iter. 
  214.  
  215.    procedure Move_After 
  216.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  217.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  218.        Position   : Gtk.Tree_Model.Gtk_Tree_Iter); 
  219.    --  Moves Iter in Tree_Store to the position after Position. Iter and 
  220.    --  Position should be in the same level. Note that this function only works 
  221.    --  with unsorted stores. If Position is null, Iter will be moved to the 
  222.    --  start of the level. 
  223.    --  Since: gtk+ 2.2 
  224.    --  "iter": A Gtk.Tree_Model.Gtk_Tree_Iter. 
  225.    --  "position": A Gtk.Tree_Model.Gtk_Tree_Iter. 
  226.  
  227.    procedure Move_Before 
  228.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  229.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  230.        Position   : Gtk.Tree_Model.Gtk_Tree_Iter); 
  231.    --  Moves Iter in Tree_Store to the position before Position. Iter and 
  232.    --  Position should be in the same level. Note that this function only works 
  233.    --  with unsorted stores. If Position is null, Iter will be moved to the end 
  234.    --  of the level. 
  235.    --  Since: gtk+ 2.2 
  236.    --  "iter": A Gtk.Tree_Model.Gtk_Tree_Iter. 
  237.    --  "position": A Gtk.Tree_Model.Gtk_Tree_Iter or null. 
  238.  
  239.    procedure Prepend 
  240.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  241.        Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter; 
  242.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter); 
  243.    --  Prepends a new row to Tree_Store. If Parent is non-null, then it will 
  244.    --  prepend the new row before the first child of Parent, otherwise it will 
  245.    --  prepend a row to the top level. Iter will be changed to point to this 
  246.    --  new row. The row will be empty after this function is called. To fill in 
  247.    --  values, you need to call gtk_tree_store_set or Gtk.Tree_Store.Set_Value. 
  248.    --  "iter": An unset Gtk.Tree_Model.Gtk_Tree_Iter to set to the prepended 
  249.    --  row 
  250.    --  "parent": A valid Gtk.Tree_Model.Gtk_Tree_Iter, or null 
  251.  
  252.    procedure Remove 
  253.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  254.        Iter       : in out Gtk.Tree_Model.Gtk_Tree_Iter); 
  255.    --  Removes Iter from Tree_Store. After being removed, Iter is set to the 
  256.    --  next valid row at that level, or invalidated if it previously pointed to 
  257.    --  the last one. 
  258.    --  "iter": A valid Gtk.Tree_Model.Gtk_Tree_Iter 
  259.  
  260.    procedure Reorder 
  261.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  262.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  263.        New_Order  : Gint_Array); 
  264.    --  Reorders the children of Parent in Tree_Store to follow the order 
  265.    --  indicated by New_Order. Note that this function only works with unsorted 
  266.    --  stores. 
  267.    --  Since: gtk+ 2.2 
  268.    --  "parent": A Gtk.Tree_Model.Gtk_Tree_Iter. 
  269.    --  "new_order": an array of integers mapping the new position of each 
  270.    --  child to its old position before the re-ordering, i.e. 
  271.    --  New_Order'[newpos] = oldpos'. 
  272.  
  273.    procedure Set_Column_Types 
  274.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  275.        Types      : GType_Array); 
  276.    --  This function is meant primarily for GObjects that inherit from 
  277.    --  Gtk.Tree_Store.Gtk_Tree_Store, and should only be used when constructing 
  278.    --  a new Gtk.Tree_Store.Gtk_Tree_Store. It will not function after a row 
  279.    --  has been added, or a method on the Gtk.Tree_Model.Gtk_Tree_Model 
  280.    --  interface is called. 
  281.    --  "types": An array of GType types, one for each column 
  282.  
  283.    procedure Set_Value 
  284.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  285.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  286.        Column     : Gint; 
  287.        Value      : Glib.Values.GValue); 
  288.    --  Sets the data in the cell specified by Iter and Column. The type of 
  289.    --  Value must be convertible to the type of the column. 
  290.    --  "iter": A valid Gtk.Tree_Model.Gtk_Tree_Iter for the row being modified 
  291.    --  "column": column number to modify 
  292.    --  "value": new value for the cell 
  293.  
  294.    procedure Swap 
  295.       (Tree_Store : not null access Gtk_Tree_Store_Record; 
  296.        A          : Gtk.Tree_Model.Gtk_Tree_Iter; 
  297.        B          : Gtk.Tree_Model.Gtk_Tree_Iter); 
  298.    --  Swaps A and B in the same level of Tree_Store. Note that this function 
  299.    --  only works with unsorted stores. 
  300.    --  Since: gtk+ 2.2 
  301.    --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter. 
  302.    --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter. 
  303.  
  304.    procedure Foreach 
  305.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  306.        Func       : Gtk_Tree_Model_Foreach_Func); 
  307.    --  Calls func on each node in model in a depth-first fashion. 
  308.    --  If Func returns True, then the tree ceases to be walked, and 
  309.    --  Gtk.Tree_Model.Foreach returns. 
  310.    --  "func": a function to be called on each row 
  311.  
  312.    generic 
  313.       type User_Data_Type (<>) is private; 
  314.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  315.    package Foreach_User_Data is 
  316.  
  317.       type Gtk_Tree_Model_Foreach_Func is access function 
  318.         (Model : Gtk.Tree_Model.Gtk_Tree_Model; 
  319.          Path  : Gtk.Tree_Model.Gtk_Tree_Path; 
  320.          Iter  : Gtk.Tree_Model.Gtk_Tree_Iter; 
  321.          Data  : User_Data_Type) return Boolean; 
  322.       --  Type of the callback passed to Gtk.Tree_Model.Foreach to iterate over 
  323.       --  the rows in a tree model. 
  324.       --  "model": the Gtk.Tree_Model.Gtk_Tree_Model being iterated 
  325.       --  "path": the current Gtk.Tree_Model.Gtk_Tree_Path 
  326.       --  "iter": the current Gtk.Tree_Model.Gtk_Tree_Iter 
  327.       --  "data": The user data passed to Gtk.Tree_Model.Foreach 
  328.  
  329.       procedure Foreach 
  330.          (Tree_Model : not null access Gtk.Tree_Store.Gtk_Tree_Store_Record'Class; 
  331.           Func       : Gtk_Tree_Model_Foreach_Func; 
  332.           User_Data  : User_Data_Type); 
  333.       --  Calls func on each node in model in a depth-first fashion. 
  334.       --  If Func returns True, then the tree ceases to be walked, and 
  335.       --  Gtk.Tree_Model.Foreach returns. 
  336.       --  "func": a function to be called on each row 
  337.       --  "user_data": user data to passed to Func 
  338.  
  339.    end Foreach_User_Data; 
  340.  
  341.    procedure Set_Default_Sort_Func 
  342.       (Sortable  : not null access Gtk_Tree_Store_Record; 
  343.        Sort_Func : Gtk_Tree_Iter_Compare_Func); 
  344.    --  Sets the default comparison function used when sorting to be Sort_Func. 
  345.    --  If the current sort column id of Sortable is 
  346.    --  GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using 
  347.    --  this function. 
  348.    --  If Sort_Func is null, then there will be no default comparison 
  349.    --  function. This means that once the model has been sorted, it can't go 
  350.    --  back to the default state. In this case, when the current sort column id 
  351.    --  of Sortable is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will 
  352.    --  be unsorted. 
  353.    --  "sort_func": The comparison function 
  354.  
  355.    generic 
  356.       type User_Data_Type (<>) is private; 
  357.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  358.    package Set_Default_Sort_Func_User_Data is 
  359.  
  360.       type Gtk_Tree_Iter_Compare_Func is access function 
  361.         (Model     : Gtk.Tree_Model.Gtk_Tree_Model; 
  362.          A         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  363.          B         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  364.          User_Data : User_Data_Type) return Gint; 
  365.       --  A GtkTreeIterCompareFunc should return a negative integer, zero, or a 
  366.       --  positive integer if A sorts before B, A sorts with B, or A sorts after B 
  367.       --  respectively. If two iters compare as equal, their order in the sorted 
  368.       --  model is undefined. In order to ensure that the 
  369.       --  Gtk.Tree_Sortable.Gtk_Tree_Sortable behaves as expected, the 
  370.       --  GtkTreeIterCompareFunc must define a partial order on the model, i.e. it 
  371.       --  must be reflexive, antisymmetric and transitive. 
  372.       --  For example, if Model is a product catalogue, then a compare function 
  373.       --  for the "price" column could be one which returns 'price_of(A) - 
  374.       --  price_of(B)'. 
  375.       --  "model": The Gtk.Tree_Model.Gtk_Tree_Model the comparison is within 
  376.       --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  377.       --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  378.       --  "user_data": Data passed when the compare func is assigned e.g. by 
  379.       --  Gtk.Tree_Sortable.Set_Sort_Func 
  380.  
  381.       procedure Set_Default_Sort_Func 
  382.          (Sortable  : not null access Gtk.Tree_Store.Gtk_Tree_Store_Record'Class; 
  383.           Sort_Func : Gtk_Tree_Iter_Compare_Func; 
  384.           User_Data : User_Data_Type); 
  385.       --  Sets the default comparison function used when sorting to be 
  386.       --  Sort_Func. If the current sort column id of Sortable is 
  387.       --  GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort 
  388.       --  using this function. 
  389.       --  If Sort_Func is null, then there will be no default comparison 
  390.       --  function. This means that once the model has been sorted, it can't go 
  391.       --  back to the default state. In this case, when the current sort column 
  392.       --  id of Sortable is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model 
  393.       --  will be unsorted. 
  394.       --  "sort_func": The comparison function 
  395.       --  "user_data": User data to pass to Sort_Func, or null 
  396.  
  397.    end Set_Default_Sort_Func_User_Data; 
  398.  
  399.    procedure Set_Sort_Func 
  400.       (Sortable       : not null access Gtk_Tree_Store_Record; 
  401.        Sort_Column_Id : Gint; 
  402.        Sort_Func      : Gtk_Tree_Iter_Compare_Func); 
  403.    --  Sets the comparison function used when sorting to be Sort_Func. If the 
  404.    --  current sort column id of Sortable is the same as Sort_Column_Id, then 
  405.    --  the model will sort using this function. 
  406.    --  "sort_column_id": the sort column id to set the function for 
  407.    --  "sort_func": The comparison function 
  408.  
  409.    generic 
  410.       type User_Data_Type (<>) is private; 
  411.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  412.    package Set_Sort_Func_User_Data is 
  413.  
  414.       type Gtk_Tree_Iter_Compare_Func is access function 
  415.         (Model     : Gtk.Tree_Model.Gtk_Tree_Model; 
  416.          A         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  417.          B         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  418.          User_Data : User_Data_Type) return Gint; 
  419.       --  A GtkTreeIterCompareFunc should return a negative integer, zero, or a 
  420.       --  positive integer if A sorts before B, A sorts with B, or A sorts after B 
  421.       --  respectively. If two iters compare as equal, their order in the sorted 
  422.       --  model is undefined. In order to ensure that the 
  423.       --  Gtk.Tree_Sortable.Gtk_Tree_Sortable behaves as expected, the 
  424.       --  GtkTreeIterCompareFunc must define a partial order on the model, i.e. it 
  425.       --  must be reflexive, antisymmetric and transitive. 
  426.       --  For example, if Model is a product catalogue, then a compare function 
  427.       --  for the "price" column could be one which returns 'price_of(A) - 
  428.       --  price_of(B)'. 
  429.       --  "model": The Gtk.Tree_Model.Gtk_Tree_Model the comparison is within 
  430.       --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  431.       --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  432.       --  "user_data": Data passed when the compare func is assigned e.g. by 
  433.       --  Gtk.Tree_Sortable.Set_Sort_Func 
  434.  
  435.       procedure Set_Sort_Func 
  436.          (Sortable       : not null access Gtk.Tree_Store.Gtk_Tree_Store_Record'Class; 
  437.           Sort_Column_Id : Gint; 
  438.           Sort_Func      : Gtk_Tree_Iter_Compare_Func; 
  439.           User_Data      : User_Data_Type); 
  440.       --  Sets the comparison function used when sorting to be Sort_Func. If 
  441.       --  the current sort column id of Sortable is the same as Sort_Column_Id, 
  442.       --  then the model will sort using this function. 
  443.       --  "sort_column_id": the sort column id to set the function for 
  444.       --  "sort_func": The comparison function 
  445.       --  "user_data": User data to pass to Sort_Func, or null 
  446.  
  447.    end Set_Sort_Func_User_Data; 
  448.  
  449.    ---------------------- 
  450.    -- GtkAda additions -- 
  451.    ---------------------- 
  452.  
  453.    generic 
  454.    type Data_Type is private; 
  455.    package Generic_Set is 
  456.       type Data_Type_Access is access all Data_Type; 
  457.  
  458.       procedure Set 
  459.         (Tree_Store : access Gtk_Tree_Store_Record'Class; 
  460.          Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  461.          Column     : Gint; 
  462.          Value      : Data_Type_Access); 
  463.       --  Generic procedure used to store access objects in the model. 
  464.       --  For GObject and all of its descendents (including all widgets), 
  465.       --  you should use the Set procedure below that takes a GObject as 
  466.       --  parameter. 
  467.       -- 
  468.       --  Please see the example at the end for more information on how to 
  469.       --  create your own Set procedures adapted to your model. Also consider 
  470.       --  using Set_Value for complex cases 
  471.  
  472.       function Get 
  473.         (Tree_Store : access Gtk_Tree_Store_Record'Class; 
  474.          Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  475.          Column     : Gint) return Data_Type_Access; 
  476.       --  Generic procedure used to get access objects back from the model. 
  477.       --  For GObject and all of its descendents (including all widgets), 
  478.       --  you should use the Get_Object function defined in Gtk-Tree_Model 
  479.       --  that returns a GObject. 
  480.  
  481.    end Generic_Set; 
  482.  
  483.    procedure Set 
  484.      (Tree_Store : access Gtk_Tree_Store_Record; 
  485.       Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  486.       Column     : Gint; 
  487.       Value      : UTF8_String); 
  488.    procedure Set 
  489.      (Tree_Store : access Gtk_Tree_Store_Record; 
  490.       Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  491.       Column     : Gint; 
  492.       Value      : Boolean); 
  493.    procedure Set 
  494.      (Tree_Store : access Gtk_Tree_Store_Record; 
  495.       Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  496.       Column     : Gint; 
  497.       Value      : Gint); 
  498.    procedure Set 
  499.      (Tree_Store : access Gtk_Tree_Store_Record; 
  500.       Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  501.       Column     : Gint; 
  502.       Value      : Glib.C_Proxy); 
  503.    procedure Set 
  504.      (Tree_Store : access Gtk_Tree_Store_Record; 
  505.       Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  506.       Column     : Gint; 
  507.       Address    : System.Address); 
  508.    procedure Set 
  509.      (Tree_Store : access Gtk_Tree_Store_Record; 
  510.       Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  511.       Column     : Gint; 
  512.       Value      : Glib.Object.GObject); 
  513.  
  514.    function Freeze_Sort 
  515.      (Tree : access Gtk.Tree_Store.Gtk_Tree_Store_Record'Class) 
  516.    return Gint; 
  517.    --  Freeze the sorting in the tree view, and returns the current 
  518.    --  sort_column_id, which should be used when thawing. (See Thaw_Sort) 
  519.  
  520.    procedure Thaw_Sort 
  521.      (Tree      : access Gtk.Tree_Store.Gtk_Tree_Store_Record'Class; 
  522.       Column_Id : Gint); 
  523.    --  Thaw a frozen tree_view. Column_Id should be the value returned by 
  524.    --  the corresponding call to Freeze_Sort. 
  525.  
  526.    --------------------------------------------- 
  527.    -- Inherited subprograms (from interfaces) -- 
  528.    --------------------------------------------- 
  529.    --  Methods inherited from the Buildable interface are not duplicated here 
  530.    --  since they are meant to be used by tools, mostly. If you need to call 
  531.    --  them, use an explicit cast through the "-" operator below. 
  532.  
  533.    function Drag_Data_Received 
  534.       (Self           : not null access Gtk_Tree_Store_Record; 
  535.        Dest           : Gtk.Tree_Model.Gtk_Tree_Path; 
  536.        Selection_Data : Gtk.Selection_Data.Gtk_Selection_Data) 
  537.        return Boolean; 
  538.  
  539.    function Row_Drop_Possible 
  540.       (Self           : not null access Gtk_Tree_Store_Record; 
  541.        Dest_Path      : Gtk.Tree_Model.Gtk_Tree_Path; 
  542.        Selection_Data : Gtk.Selection_Data.Gtk_Selection_Data) 
  543.        return Boolean; 
  544.  
  545.    function Drag_Data_Delete 
  546.       (Self : not null access Gtk_Tree_Store_Record; 
  547.        Path : Gtk.Tree_Model.Gtk_Tree_Path) return Boolean; 
  548.  
  549.    function Drag_Data_Get 
  550.       (Self           : not null access Gtk_Tree_Store_Record; 
  551.        Path           : Gtk.Tree_Model.Gtk_Tree_Path; 
  552.        Selection_Data : Gtk.Selection_Data.Gtk_Selection_Data) 
  553.        return Boolean; 
  554.  
  555.    function Row_Draggable 
  556.       (Self : not null access Gtk_Tree_Store_Record; 
  557.        Path : Gtk.Tree_Model.Gtk_Tree_Path) return Boolean; 
  558.  
  559.    function Get_Column_Type 
  560.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  561.        Index      : Gint) return GType; 
  562.  
  563.    function Get_Flags 
  564.       (Tree_Model : not null access Gtk_Tree_Store_Record) 
  565.        return Gtk.Tree_Model.Tree_Model_Flags; 
  566.  
  567.    function Get_Iter 
  568.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  569.        Path       : Gtk.Tree_Model.Gtk_Tree_Path) 
  570.        return Gtk.Tree_Model.Gtk_Tree_Iter; 
  571.  
  572.    function Get_Iter_First 
  573.       (Tree_Model : not null access Gtk_Tree_Store_Record) 
  574.        return Gtk.Tree_Model.Gtk_Tree_Iter; 
  575.  
  576.    function Get_Iter_From_String 
  577.       (Tree_Model  : not null access Gtk_Tree_Store_Record; 
  578.        Path_String : UTF8_String) return Gtk.Tree_Model.Gtk_Tree_Iter; 
  579.  
  580.    function Get_N_Columns 
  581.       (Tree_Model : not null access Gtk_Tree_Store_Record) return Gint; 
  582.  
  583.    function Get_Path 
  584.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  585.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter) 
  586.        return Gtk.Tree_Model.Gtk_Tree_Path; 
  587.  
  588.    function Get_String_From_Iter 
  589.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  590.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter) return UTF8_String; 
  591.  
  592.    procedure Get_Value 
  593.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  594.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  595.        Column     : Gint; 
  596.        Value      : out Glib.Values.GValue); 
  597.  
  598.    function Children 
  599.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  600.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter) 
  601.        return Gtk.Tree_Model.Gtk_Tree_Iter; 
  602.  
  603.    function Has_Child 
  604.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  605.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean; 
  606.  
  607.    function N_Children 
  608.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  609.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Null_Iter) 
  610.        return Gint; 
  611.  
  612.    procedure Next 
  613.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  614.        Iter       : in out Gtk.Tree_Model.Gtk_Tree_Iter); 
  615.  
  616.    function Nth_Child 
  617.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  618.        Parent     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  619.        N          : Gint) return Gtk.Tree_Model.Gtk_Tree_Iter; 
  620.  
  621.    function Parent 
  622.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  623.        Child      : Gtk.Tree_Model.Gtk_Tree_Iter) 
  624.        return Gtk.Tree_Model.Gtk_Tree_Iter; 
  625.  
  626.    procedure Previous 
  627.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  628.        Iter       : in out Gtk.Tree_Model.Gtk_Tree_Iter); 
  629.  
  630.    procedure Ref_Node 
  631.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  632.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter); 
  633.  
  634.    procedure Row_Changed 
  635.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  636.        Path       : Gtk.Tree_Model.Gtk_Tree_Path; 
  637.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter); 
  638.  
  639.    procedure Row_Deleted 
  640.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  641.        Path       : Gtk.Tree_Model.Gtk_Tree_Path); 
  642.  
  643.    procedure Row_Has_Child_Toggled 
  644.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  645.        Path       : Gtk.Tree_Model.Gtk_Tree_Path; 
  646.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter); 
  647.  
  648.    procedure Row_Inserted 
  649.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  650.        Path       : Gtk.Tree_Model.Gtk_Tree_Path; 
  651.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter); 
  652.  
  653.    procedure Rows_Reordered 
  654.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  655.        Path       : Gtk.Tree_Model.Gtk_Tree_Path; 
  656.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter; 
  657.        New_Order  : Gint_Array); 
  658.  
  659.    procedure Unref_Node 
  660.       (Tree_Model : not null access Gtk_Tree_Store_Record; 
  661.        Iter       : Gtk.Tree_Model.Gtk_Tree_Iter); 
  662.  
  663.    procedure Get_Sort_Column_Id 
  664.       (Sortable       : not null access Gtk_Tree_Store_Record; 
  665.        Sort_Column_Id : out Gint; 
  666.        Order          : out Gtk.Enums.Gtk_Sort_Type); 
  667.  
  668.    procedure Set_Sort_Column_Id 
  669.       (Sortable       : not null access Gtk_Tree_Store_Record; 
  670.        Sort_Column_Id : Gint; 
  671.        Order          : Gtk.Enums.Gtk_Sort_Type); 
  672.  
  673.    function Has_Default_Sort_Func 
  674.       (Sortable : not null access Gtk_Tree_Store_Record) return Boolean; 
  675.  
  676.    procedure Sort_Column_Changed 
  677.       (Sortable : not null access Gtk_Tree_Store_Record); 
  678.  
  679.    ---------------- 
  680.    -- Interfaces -- 
  681.    ---------------- 
  682.    --  This class implements several interfaces. See Glib.Types 
  683.    -- 
  684.    --  - "Buildable" 
  685.    -- 
  686.    --  - "TreeDragDest" 
  687.    -- 
  688.    --  - "TreeDragSource" 
  689.    -- 
  690.    --  - "TreeModel" 
  691.    -- 
  692.    --  - "TreeSortable" 
  693.  
  694.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  695.      (Gtk.Buildable.Gtk_Buildable, Gtk_Tree_Store_Record, Gtk_Tree_Store); 
  696.    function "+" 
  697.      (Widget : access Gtk_Tree_Store_Record'Class) 
  698.    return Gtk.Buildable.Gtk_Buildable 
  699.    renames Implements_Gtk_Buildable.To_Interface; 
  700.    function "-" 
  701.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  702.    return Gtk_Tree_Store 
  703.    renames Implements_Gtk_Buildable.To_Object; 
  704.  
  705.    package Implements_Gtk_Tree_Drag_Dest is new Glib.Types.Implements 
  706.      (Gtk.Tree_Drag_Dest.Gtk_Tree_Drag_Dest, Gtk_Tree_Store_Record, Gtk_Tree_Store); 
  707.    function "+" 
  708.      (Widget : access Gtk_Tree_Store_Record'Class) 
  709.    return Gtk.Tree_Drag_Dest.Gtk_Tree_Drag_Dest 
  710.    renames Implements_Gtk_Tree_Drag_Dest.To_Interface; 
  711.    function "-" 
  712.      (Interf : Gtk.Tree_Drag_Dest.Gtk_Tree_Drag_Dest) 
  713.    return Gtk_Tree_Store 
  714.    renames Implements_Gtk_Tree_Drag_Dest.To_Object; 
  715.  
  716.    package Implements_Gtk_Tree_Drag_Source is new Glib.Types.Implements 
  717.      (Gtk.Tree_Drag_Source.Gtk_Tree_Drag_Source, Gtk_Tree_Store_Record, Gtk_Tree_Store); 
  718.    function "+" 
  719.      (Widget : access Gtk_Tree_Store_Record'Class) 
  720.    return Gtk.Tree_Drag_Source.Gtk_Tree_Drag_Source 
  721.    renames Implements_Gtk_Tree_Drag_Source.To_Interface; 
  722.    function "-" 
  723.      (Interf : Gtk.Tree_Drag_Source.Gtk_Tree_Drag_Source) 
  724.    return Gtk_Tree_Store 
  725.    renames Implements_Gtk_Tree_Drag_Source.To_Object; 
  726.  
  727.    package Implements_Gtk_Tree_Model is new Glib.Types.Implements 
  728.      (Gtk.Tree_Model.Gtk_Tree_Model, Gtk_Tree_Store_Record, Gtk_Tree_Store); 
  729.    function "+" 
  730.      (Widget : access Gtk_Tree_Store_Record'Class) 
  731.    return Gtk.Tree_Model.Gtk_Tree_Model 
  732.    renames Implements_Gtk_Tree_Model.To_Interface; 
  733.    function "-" 
  734.      (Interf : Gtk.Tree_Model.Gtk_Tree_Model) 
  735.    return Gtk_Tree_Store 
  736.    renames Implements_Gtk_Tree_Model.To_Object; 
  737.  
  738.    package Implements_Gtk_Tree_Sortable is new Glib.Types.Implements 
  739.      (Gtk.Tree_Sortable.Gtk_Tree_Sortable, Gtk_Tree_Store_Record, Gtk_Tree_Store); 
  740.    function "+" 
  741.      (Widget : access Gtk_Tree_Store_Record'Class) 
  742.    return Gtk.Tree_Sortable.Gtk_Tree_Sortable 
  743.    renames Implements_Gtk_Tree_Sortable.To_Interface; 
  744.    function "-" 
  745.      (Interf : Gtk.Tree_Sortable.Gtk_Tree_Sortable) 
  746.    return Gtk_Tree_Store 
  747.    renames Implements_Gtk_Tree_Sortable.To_Object; 
  748.  
  749. end Gtk.Tree_Store;