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