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. --  Gtk.Tree_Sortable.Gtk_Tree_Sortable is an interface to be implemented by 
  26. --  tree models which support sorting. The Gtk.Tree_View.Gtk_Tree_View uses the 
  27. --  methods provided by this interface to sort the model. 
  28. -- 
  29. --  </description> 
  30. pragma Ada_2005; 
  31.  
  32. pragma Warnings (Off, "*is already use-visible*"); 
  33. with Glib;           use Glib; 
  34. with Glib.Object;    use Glib.Object; 
  35. with Glib.Types;     use Glib.Types; 
  36. with Gtk.Enums;      use Gtk.Enums; 
  37. with Gtk.Tree_Model; use Gtk.Tree_Model; 
  38.  
  39. package Gtk.Tree_Sortable is 
  40.  
  41.    type Gtk_Tree_Sortable is new Glib.Types.GType_Interface; 
  42.    Null_Gtk_Tree_Sortable : constant Gtk_Tree_Sortable; 
  43.  
  44.    --------------- 
  45.    -- Callbacks -- 
  46.    --------------- 
  47.  
  48.    type Gtk_Tree_Iter_Compare_Func is access function 
  49.      (Model : Gtk.Tree_Model.Gtk_Tree_Model; 
  50.       A     : Gtk.Tree_Model.Gtk_Tree_Iter; 
  51.       B     : Gtk.Tree_Model.Gtk_Tree_Iter) return Gint; 
  52.    --  A GtkTreeIterCompareFunc should return a negative integer, zero, or a 
  53.    --  positive integer if A sorts before B, A sorts with B, or A sorts after B 
  54.    --  respectively. If two iters compare as equal, their order in the sorted 
  55.    --  model is undefined. In order to ensure that the 
  56.    --  Gtk.Tree_Sortable.Gtk_Tree_Sortable behaves as expected, the 
  57.    --  GtkTreeIterCompareFunc must define a partial order on the model, i.e. it 
  58.    --  must be reflexive, antisymmetric and transitive. 
  59.    --  For example, if Model is a product catalogue, then a compare function 
  60.    --  for the "price" column could be one which returns 'price_of(A) - 
  61.    --  price_of(B)'. 
  62.    --  "model": The Gtk.Tree_Model.Gtk_Tree_Model the comparison is within 
  63.    --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  64.    --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  65.  
  66.    ------------------ 
  67.    -- Constructors -- 
  68.    ------------------ 
  69.  
  70.    function Get_Type return Glib.GType; 
  71.    pragma Import (C, Get_Type, "gtk_tree_sortable_get_type"); 
  72.  
  73.    ------------- 
  74.    -- Methods -- 
  75.    ------------- 
  76.  
  77.    procedure Get_Sort_Column_Id 
  78.       (Sortable       : Gtk_Tree_Sortable; 
  79.        Sort_Column_Id : out Gint; 
  80.        Order          : out Gtk.Enums.Gtk_Sort_Type); 
  81.    pragma Import (C, Get_Sort_Column_Id, "gtk_tree_sortable_get_sort_column_id"); 
  82.    --  Fills in Sort_Column_Id and Order with the current sort column and the 
  83.    --  order. It returns True unless the Sort_Column_Id is 
  84.    --  GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID or 
  85.    --  GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID. 
  86.    --  "sort_column_id": The sort column id to be filled in 
  87.    --  "order": The Gtk.Enums.Gtk_Sort_Type to be filled in 
  88.  
  89.    procedure Set_Sort_Column_Id 
  90.       (Sortable       : Gtk_Tree_Sortable; 
  91.        Sort_Column_Id : Gint; 
  92.        Order          : Gtk.Enums.Gtk_Sort_Type); 
  93.    pragma Import (C, Set_Sort_Column_Id, "gtk_tree_sortable_set_sort_column_id"); 
  94.    --  Sets the current sort column to be Sort_Column_Id. The Sortable will 
  95.    --  resort itself to reflect this change, after emitting a 
  96.    --  Gtk.Tree_Sortable.Gtk_Tree_Sortable::sort-column-changed signal. 
  97.    --  Sort_Column_Id may either be a regular column id, or one of the 
  98.    --  following special values: 
  99.    --  'GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID' 
  100.    --     * the default sort function will be used, if it is set 
  101.    --  'GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID' 
  102.    --     * no sorting will occur 
  103.    --  "sort_column_id": the sort column id to set 
  104.    --  "order": The sort order of the column 
  105.  
  106.    function Has_Default_Sort_Func 
  107.       (Sortable : Gtk_Tree_Sortable) return Boolean; 
  108.    --  Returns True if the model has a default sort function. This is used 
  109.    --  primarily by GtkTreeViewColumns in order to determine if a model can go 
  110.    --  back to the default state, or not. 
  111.  
  112.    procedure Set_Default_Sort_Func 
  113.       (Sortable  : Gtk_Tree_Sortable; 
  114.        Sort_Func : Gtk_Tree_Iter_Compare_Func); 
  115.    --  Sets the default comparison function used when sorting to be Sort_Func. 
  116.    --  If the current sort column id of Sortable is 
  117.    --  GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using 
  118.    --  this function. 
  119.    --  If Sort_Func is null, then there will be no default comparison 
  120.    --  function. This means that once the model has been sorted, it can't go 
  121.    --  back to the default state. In this case, when the current sort column id 
  122.    --  of Sortable is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will 
  123.    --  be unsorted. 
  124.    --  "sort_func": The comparison function 
  125.  
  126.    generic 
  127.       type User_Data_Type (<>) is private; 
  128.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  129.    package Set_Default_Sort_Func_User_Data is 
  130.  
  131.       type Gtk_Tree_Iter_Compare_Func is access function 
  132.         (Model     : Gtk.Tree_Model.Gtk_Tree_Model; 
  133.          A         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  134.          B         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  135.          User_Data : User_Data_Type) return Gint; 
  136.       --  A GtkTreeIterCompareFunc should return a negative integer, zero, or a 
  137.       --  positive integer if A sorts before B, A sorts with B, or A sorts after B 
  138.       --  respectively. If two iters compare as equal, their order in the sorted 
  139.       --  model is undefined. In order to ensure that the 
  140.       --  Gtk.Tree_Sortable.Gtk_Tree_Sortable behaves as expected, the 
  141.       --  GtkTreeIterCompareFunc must define a partial order on the model, i.e. it 
  142.       --  must be reflexive, antisymmetric and transitive. 
  143.       --  For example, if Model is a product catalogue, then a compare function 
  144.       --  for the "price" column could be one which returns 'price_of(A) - 
  145.       --  price_of(B)'. 
  146.       --  "model": The Gtk.Tree_Model.Gtk_Tree_Model the comparison is within 
  147.       --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  148.       --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  149.       --  "user_data": Data passed when the compare func is assigned e.g. by 
  150.       --  gtk_tree_sortable_set_sort_func 
  151.  
  152.       procedure Set_Default_Sort_Func 
  153.          (Sortable  : Gtk.Tree_Sortable.Gtk_Tree_Sortable; 
  154.           Sort_Func : Gtk_Tree_Iter_Compare_Func; 
  155.           User_Data : User_Data_Type); 
  156.       --  Sets the default comparison function used when sorting to be 
  157.       --  Sort_Func. If the current sort column id of Sortable is 
  158.       --  GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort 
  159.       --  using this function. 
  160.       --  If Sort_Func is null, then there will be no default comparison 
  161.       --  function. This means that once the model has been sorted, it can't go 
  162.       --  back to the default state. In this case, when the current sort column 
  163.       --  id of Sortable is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model 
  164.       --  will be unsorted. 
  165.       --  "sort_func": The comparison function 
  166.       --  "user_data": User data to pass to Sort_Func, or null 
  167.  
  168.    end Set_Default_Sort_Func_User_Data; 
  169.  
  170.    procedure Set_Sort_Func 
  171.       (Sortable       : Gtk_Tree_Sortable; 
  172.        Sort_Column_Id : Gint; 
  173.        Sort_Func      : Gtk_Tree_Iter_Compare_Func); 
  174.    --  Sets the comparison function used when sorting to be Sort_Func. If the 
  175.    --  current sort column id of Sortable is the same as Sort_Column_Id, then 
  176.    --  the model will sort using this function. 
  177.    --  "sort_column_id": the sort column id to set the function for 
  178.    --  "sort_func": The comparison function 
  179.  
  180.    generic 
  181.       type User_Data_Type (<>) is private; 
  182.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  183.    package Set_Sort_Func_User_Data is 
  184.  
  185.       type Gtk_Tree_Iter_Compare_Func is access function 
  186.         (Model     : Gtk.Tree_Model.Gtk_Tree_Model; 
  187.          A         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  188.          B         : Gtk.Tree_Model.Gtk_Tree_Iter; 
  189.          User_Data : User_Data_Type) return Gint; 
  190.       --  A GtkTreeIterCompareFunc should return a negative integer, zero, or a 
  191.       --  positive integer if A sorts before B, A sorts with B, or A sorts after B 
  192.       --  respectively. If two iters compare as equal, their order in the sorted 
  193.       --  model is undefined. In order to ensure that the 
  194.       --  Gtk.Tree_Sortable.Gtk_Tree_Sortable behaves as expected, the 
  195.       --  GtkTreeIterCompareFunc must define a partial order on the model, i.e. it 
  196.       --  must be reflexive, antisymmetric and transitive. 
  197.       --  For example, if Model is a product catalogue, then a compare function 
  198.       --  for the "price" column could be one which returns 'price_of(A) - 
  199.       --  price_of(B)'. 
  200.       --  "model": The Gtk.Tree_Model.Gtk_Tree_Model the comparison is within 
  201.       --  "a": A Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  202.       --  "b": Another Gtk.Tree_Model.Gtk_Tree_Iter in Model 
  203.       --  "user_data": Data passed when the compare func is assigned e.g. by 
  204.       --  Gtk.Tree_Sortable.Set_Sort_Func 
  205.  
  206.       procedure Set_Sort_Func 
  207.          (Sortable       : Gtk.Tree_Sortable.Gtk_Tree_Sortable; 
  208.           Sort_Column_Id : Gint; 
  209.           Sort_Func      : Gtk_Tree_Iter_Compare_Func; 
  210.           User_Data      : User_Data_Type); 
  211.       --  Sets the comparison function used when sorting to be Sort_Func. If 
  212.       --  the current sort column id of Sortable is the same as Sort_Column_Id, 
  213.       --  then the model will sort using this function. 
  214.       --  "sort_column_id": the sort column id to set the function for 
  215.       --  "sort_func": The comparison function 
  216.       --  "user_data": User data to pass to Sort_Func, or null 
  217.  
  218.    end Set_Sort_Func_User_Data; 
  219.  
  220.    procedure Sort_Column_Changed (Sortable : Gtk_Tree_Sortable); 
  221.    pragma Import (C, Sort_Column_Changed, "gtk_tree_sortable_sort_column_changed"); 
  222.    --  Emits a Gtk.Tree_Sortable.Gtk_Tree_Sortable::sort-column-changed signal 
  223.    --  on Sortable. 
  224.  
  225.    ---------------------- 
  226.    -- GtkAda additions -- 
  227.    ---------------------- 
  228.  
  229.    Default_Sort_Column_Id  : constant Gint := -1; 
  230.    Unsorted_Sort_Column_Id : constant Gint := -2; 
  231.    --  Two special values for the sort column 
  232.  
  233.    ------------- 
  234.    -- Signals -- 
  235.    ------------- 
  236.  
  237.    type Cb_Gtk_Tree_Sortable_Void is not null access procedure (Self : Gtk_Tree_Sortable); 
  238.  
  239.    type Cb_GObject_Void is not null access procedure 
  240.      (Self : access Glib.Object.GObject_Record'Class); 
  241.  
  242.    Signal_Sort_Column_Changed : constant Glib.Signal_Name := "sort-column-changed"; 
  243.    procedure On_Sort_Column_Changed 
  244.       (Self  : Gtk_Tree_Sortable; 
  245.        Call  : Cb_Gtk_Tree_Sortable_Void; 
  246.        After : Boolean := False); 
  247.    procedure On_Sort_Column_Changed 
  248.       (Self  : Gtk_Tree_Sortable; 
  249.        Call  : Cb_GObject_Void; 
  250.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  251.        After : Boolean := False); 
  252.    --  The ::sort-column-changed signal is emitted when the sort column or 
  253.    --  sort order of Sortable is changed. The signal is emitted before the 
  254.    --  contents of Sortable are resorted. 
  255.  
  256.    ---------------- 
  257.    -- Interfaces -- 
  258.    ---------------- 
  259.    --  This class implements several interfaces. See Glib.Types 
  260.    -- 
  261.    --  - "Gtk_Tree_Sortable" 
  262.  
  263.    function "+" (W : Gtk_Tree_Sortable) return Gtk_Tree_Sortable; 
  264.    pragma Inline ("+"); 
  265.  
  266. private 
  267.  
  268. Null_Gtk_Tree_Sortable : constant Gtk_Tree_Sortable := 
  269.    Gtk_Tree_Sortable (Glib.Types.Null_Interface); 
  270. end Gtk.Tree_Sortable;