1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2009, 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. --  Gtk_Tree_Sortable is an interface to be implemented by tree models which 
  26. --  support sorting. The Gtk_Tree_View uses the methods provided by this 
  27. --  interface to sort the model. 
  28. --  </description> 
  29. --  <c_version>2.8.17</c_version> 
  30. --  <group>Trees and Lists</group> 
  31.  
  32. with Glib.Types; 
  33. with Gtk.Enums; 
  34. with Gtk.Tree_Model; 
  35.  
  36. package Gtk.Tree_Sortable is 
  37.    type Gtk_Tree_Sortable is new Glib.Types.GType_Interface; 
  38.  
  39.    Default_Sort_Column_Id  : constant Gint := -1; 
  40.    Unsorted_Sort_Column_Id : constant Gint := -2; 
  41.    --  Two special values for the sort column 
  42.  
  43.    function Get_Type return Glib.GType; 
  44.    --  Returns the internal type used for a Gtk_Tree_Sortable 
  45.  
  46.    procedure Set_Sort_Column_Id 
  47.      (Sortable       : Gtk_Tree_Sortable; 
  48.       Sort_Column_Id : Gint; 
  49.       Order          : Gtk.Enums.Gtk_Sort_Type); 
  50.    procedure Get_Sort_Column_Id 
  51.      (Sortable       : Gtk_Tree_Sortable; 
  52.       Sort_Column_Id : out Gint; 
  53.       Order          : out Gtk.Enums.Gtk_Sort_Type); 
  54.    --  Sets the current sort column to be Sort_Column_Id. The Sortable will 
  55.    --  resort itself to reflect this change, after emitting sort_column_changed 
  56.    --  signal. If Sort_Column_Id is Default_Sort_Column_Id, then the default 
  57.    --  sort function will be used, if it is set. 
  58.  
  59.    type Gtk_Tree_Iter_Compare_Func is access function 
  60.      (Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; 
  61.       A     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  62.       B     : Gtk.Tree_Model.Gtk_Tree_Iter) return Gint; 
  63.    --  A Gtk_Tree_Iter_Compare_Func should return a negative integer, zero, or 
  64.    --  a positive integer if a sorts before b, a sorts with b, or a sorts after 
  65.    --  b respectively. If two iters compare as equal, their order in the sorted 
  66.    --  model is undefined. In order to ensure that the Gtk_Tree_Sortable 
  67.    --  behaves as expected, the Gtk_Tree_Iter_Compare_Func must define a 
  68.    --  partial order on the model, i.e. it must be reflexive, antisymmetric and 
  69.    --  transitive. 
  70.    --  For example, if model is a product catalogue, then a compare function 
  71.    --  for the "price" column could be one which returns price_of(a) - 
  72.    --  price_of(b). 
  73.  
  74.    procedure Set_Default_Sort_Func 
  75.      (Sortable  : Gtk_Tree_Sortable; 
  76.       Sort_Func : Gtk_Tree_Iter_Compare_Func); 
  77.    function Has_Default_Sort_Func 
  78.      (Sortable : Gtk_Tree_Sortable) return Boolean; 
  79.    --  Sets the default comparison function used when sorting to be Sort_Func. 
  80.    --  If the current sort column id of Sortable is Default_Sort_Column_Id, 
  81.    --  then the model will sort using this function. 
  82.    --  If Sort_Func is null, then there will be no default comparison function. 
  83.    --  This means that once the model has been sorted, it can't go back to the 
  84.    --  default state. In this case, when the current sort column id of Sortable 
  85.    --  is Default_Sort_Column_Id, the model will be unsorted. 
  86.  
  87.    procedure Set_Sort_Func 
  88.      (Sortable       : Gtk_Tree_Sortable; 
  89.       Sort_Column_Id : Gint; 
  90.       Sort_Func      : Gtk_Tree_Iter_Compare_Func); 
  91.    --  Sets the comparison function used when sorting to be Sort_Func. If the 
  92.    --  current sort column id of Sortable is the same as Sort_Column_Id, then 
  93.    --  the model will sort using this function. 
  94.  
  95.    generic 
  96.       type Data_Type (<>) is private; 
  97.    package Compare_Funcs is 
  98.       type Gtk_Tree_Iter_Compare_Func is access function 
  99.         (Model     : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; 
  100.          A         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  101.          B         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  102.          User_Data : Data_Type) return Gint; 
  103.  
  104.       type Destroy_Notify is access procedure (Data : in out Data_Type); 
  105.       --  Free the memory used by Data 
  106.  
  107.       procedure Set_Default_Sort_Func 
  108.         (Sortable  : Gtk_Tree_Sortable; 
  109.          Sort_Func : Gtk_Tree_Iter_Compare_Func; 
  110.          User_Data : Data_Type; 
  111.          Destroy   : Destroy_Notify := null); 
  112.       procedure Set_Sort_Func 
  113.         (Sortable       : Gtk_Tree_Sortable; 
  114.          Sort_Column_Id : Gint; 
  115.          Sort_Func      : Gtk_Tree_Iter_Compare_Func; 
  116.          User_Data      : Data_Type; 
  117.          Destroy        : Destroy_Notify := null); 
  118.       --  Same as above, but an additional user data can be passed to the sort 
  119.       --  function. 
  120.    private 
  121.       --  <doc_ignore> 
  122.       type Data_Type_Access is access Data_Type; 
  123.       type Data_Type_Record is record 
  124.          Func    : Gtk_Tree_Iter_Compare_Func; 
  125.          Destroy : Destroy_Notify; 
  126.          Data    : Data_Type_Access; 
  127.       end record; 
  128.       type Data_Type_Record_Access is access Data_Type_Record; 
  129.       pragma Convention (C, Data_Type_Record_Access); 
  130.  
  131.       procedure Internal_Destroy_Notify (Data : Data_Type_Record_Access); 
  132.       pragma Convention (C, Internal_Destroy_Notify); 
  133.  
  134.       function Internal_Compare_Func 
  135.         (Model : System.Address; 
  136.          A, B  : System.Address; 
  137.          Data  : Data_Type_Record_Access) return Gint; 
  138.       pragma Convention (C, Internal_Compare_Func); 
  139.       --  </doc_ignore> 
  140.    end Compare_Funcs; 
  141.    --  </doc_ignore> 
  142.  
  143.    ------------- 
  144.    -- Signals -- 
  145.    ------------- 
  146.    --  The following new signals are defined for this widget: 
  147.  
  148.    --  <signals> 
  149.    --  - "sort_column_changed" 
  150.    --    procedure Handler (Sortable : Gtk_Tree_Sortable); 
  151.    --    Emitted when the sort column is changed through Set_Sort_Column_Id 
  152.    --  </signals> 
  153.  
  154.    Signal_Sort_Column_Changed : constant Glib.Signal_Name := 
  155.                                   "sort_column_changed"; 
  156.  
  157.    procedure Sort_Column_Changed (Sortable : Gtk_Tree_Sortable); 
  158.    --  Emits sort_column_changed signal 
  159.  
  160. private 
  161.    pragma Import (C, Get_Type, "gtk_tree_sortable_get_type"); 
  162.    pragma Import 
  163.      (C, Set_Sort_Column_Id, "gtk_tree_sortable_set_sort_column_id"); 
  164.    pragma Import 
  165.      (C, Sort_Column_Changed, "gtk_tree_sortable_sort_column_changed"); 
  166. end Gtk.Tree_Sortable;