1. ------------------------------------------------------------------------------ 
  2. --               GtkAda - Ada95 binding for the Gimp Toolkit                -- 
  3. --                                                                          -- 
  4. --                     Copyright (C) 2008-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. with Glib.Values; 
  25. with Gtk.Tree_Model; 
  26. with Glib.Types; 
  27.  
  28. package Gtkada.Abstract_Tree_Model is 
  29.  
  30.    type Gtk_Abstract_Tree_Model_Record is 
  31.       new Gtk.Tree_Model.Gtk_Root_Tree_Model_Record with null record; 
  32.    --  Conceptually, this is an abstract type, but this prevents the 
  33.    --  instantiation of Glib.Types.Implements 
  34.  
  35.    type Gtk_Abstract_Tree_Model is 
  36.       access all Gtk_Abstract_Tree_Model_Record'Class; 
  37.  
  38.    procedure Initialize (Self : access Gtk_Abstract_Tree_Model_Record'Class); 
  39.    function Get_Type return Glib.GType; 
  40.  
  41.    ------------------------------ 
  42.    -- Interface implementation -- 
  43.    ------------------------------ 
  44.  
  45.    --  The following subprograms can be overridden to implement the custom 
  46.    --  tree model. 
  47.    --  Note that they are called from C (wrapped through calls to the 
  48.    --  Dispatch_* functions defined in the body of this package) so it is 
  49.    --  advised to add exception handlers in these subprograms, just like in 
  50.    --  regular GtkAda callbacks. 
  51.  
  52.    function Get_Flags 
  53.      (Self : access Gtk_Abstract_Tree_Model_Record) 
  54.       return Gtk.Tree_Model.Tree_Model_Flags; 
  55.    --  Override this to return a set of flags supported by this interface. 
  56.    --  The flags supported should not change during the lifecycle of the 
  57.    --  tree_model. 
  58.  
  59.    function Get_N_Columns 
  60.      (Self : access Gtk_Abstract_Tree_Model_Record) 
  61.       return Glib.Gint; 
  62.    --  Override this to return the number of columns supported by Tree_Model. 
  63.  
  64.    function Get_Column_Type 
  65.      (Self  : access Gtk_Abstract_Tree_Model_Record; 
  66.       Index : Glib.Gint) return Glib.GType; 
  67.    --  Override this to return the type of the Index-th column in the model. 
  68.  
  69.    function Get_Iter 
  70.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  71.       Path : Gtk.Tree_Model.Gtk_Tree_Path) 
  72.       return Gtk.Tree_Model.Gtk_Tree_Iter; 
  73.    --  Override this return an iterator pointing to Path. 
  74.    --  Null_Iter is returned if Path was invalid or no iterator could be set. 
  75.  
  76.    function Get_Path 
  77.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  78.       Iter : Gtk.Tree_Model.Gtk_Tree_Iter) 
  79.       return Gtk.Tree_Model.Gtk_Tree_Path; 
  80.    --  Override this to return a newly created Gtk_Tree_Path referenced by 
  81.    --  Iter. This path will be freed with Path_Free by the caller. 
  82.  
  83.    procedure Get_Value 
  84.      (Self   : access Gtk_Abstract_Tree_Model_Record; 
  85.       Iter   : Gtk.Tree_Model.Gtk_Tree_Iter; 
  86.       Column : Glib.Gint; 
  87.       Value  : out Glib.Values.GValue); 
  88.    --  Override this get a value from the model, at column Column and line 
  89.    --  Iter. Value must be freed by the caller. 
  90.  
  91.    procedure Next 
  92.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  93.       Iter : in out Gtk.Tree_Model.Gtk_Tree_Iter); 
  94.    --  Override this to set Iter to point to the node following it at the 
  95.    --  current level. If there is none, Iter is set to Null_Iter. 
  96.  
  97.    function Children 
  98.      (Self   : access Gtk_Abstract_Tree_Model_Record; 
  99.       Parent : Gtk.Tree_Model.Gtk_Tree_Iter) 
  100.       return Gtk.Tree_Model.Gtk_Tree_Iter; 
  101.    --  Override this to return the first child of Parent. If Parent has no 
  102.    --  children, return Null_Iter. Parent will remain a valid node after this 
  103.    --  function has been called. 
  104.  
  105.    function Has_Child 
  106.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  107.       Iter : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean; 
  108.    --  Override this to return True if Iter has children, False otherwise. 
  109.  
  110.    function N_Children 
  111.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  112.       Iter : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Null_Iter) 
  113.       return Glib.Gint; 
  114.    --  Override this to return the number of children that Iter has. 
  115.    --  As a special case, if Iter is Null_Iter, then the number of toplevel 
  116.    --  nodes is returned. 
  117.  
  118.    function Nth_Child 
  119.      (Self   : access Gtk_Abstract_Tree_Model_Record; 
  120.       Parent : Gtk.Tree_Model.Gtk_Tree_Iter; 
  121.       N      : Glib.Gint) return Gtk.Tree_Model.Gtk_Tree_Iter; 
  122.    --  Override this to return the child of Parent, using the given index. 
  123.    --  The First index is 0. If Index is too big, or Parent has no children, 
  124.    --  return Null_Iter. If Parent is Null_Iter, then the nth root node is set. 
  125.  
  126.    function Parent 
  127.      (Self  : access Gtk_Abstract_Tree_Model_Record; 
  128.       Child : Gtk.Tree_Model.Gtk_Tree_Iter) 
  129.       return Gtk.Tree_Model.Gtk_Tree_Iter; 
  130.    --  Override this to return the parent of Child. If Child is at the 
  131.    --  toplevel, and doesn't have a parent, then Null_Iter is returned. 
  132.  
  133.    procedure Ref_Node 
  134.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  135.       Iter : Gtk.Tree_Model.Gtk_Tree_Iter); 
  136.    --  Let the tree reference the node. 
  137.    --  This is an optional method for models to implement. 
  138.    --  To be more specific, models may ignore this call as it exists primarily 
  139.    --  for performance reasons. This function is primarily meant as a way for 
  140.    --  views to let caching model know when nodes are being displayed (and 
  141.    --  hence, whether or not to cache that node). For example, a file-system 
  142.    --  based model would not want to keep the entire file-hierarchy in memory, 
  143.    --  just the sections that are currently being displayed by every current 
  144.    --  view. 
  145.    --  Technically, the idea is to increase the refcount for the node itself, 
  146.    --  not for any data associated with it (should you want to associate a 
  147.    --  reference counted type with the rows). Most of the time you will not 
  148.    --  need to do anything here. 
  149.    --  Every time the view makes a row visible (for instance when you expand 
  150.    --  a node), it calls Ref_Node for that row. When the row is hidden again, 
  151.    --  it calls Unref_Node. 
  152.  
  153.    procedure Unref_Node 
  154.      (Self : access Gtk_Abstract_Tree_Model_Record; 
  155.       Iter : Gtk.Tree_Model.Gtk_Tree_Iter); 
  156.    --  Let the tree unref the node. 
  157.    --  This is an optional method for models to implement. To be more specific, 
  158.    --  models may ignore this call as it exists primarily for performance 
  159.    --  reasons. For more information on what this means, please see 
  160.    --  Tree_Model_Ref_Node. Please note that nodes that are deleted are not 
  161.    --  unreferenced. 
  162.    --  Technically, your model is the one deleting a row (and it should do so 
  163.    --  only if the refcount for the row is not 1, see Ref_Node). Thus gtk+ 
  164.    --  avoids a potential callback to your application by not emitting 
  165.    --  Unref_Node in such a case. 
  166.  
  167.    ---------------- 
  168.    -- Interfaces -- 
  169.    ---------------- 
  170.  
  171.    package Implements_Gtk_Tree_Model is new Glib.Types.Implements 
  172.       (Gtk.Tree_Model.Gtk_Tree_Model, Gtk_Abstract_Tree_Model_Record, 
  173.        Gtk_Abstract_Tree_Model); 
  174.    function "+" 
  175.       (Widget : access Gtk_Abstract_Tree_Model_Record'Class) 
  176.        return Gtk.Tree_Model.Gtk_Tree_Model 
  177.        renames Implements_Gtk_Tree_Model.To_Interface; 
  178.    function "-" 
  179.       (Interf : Gtk.Tree_Model.Gtk_Tree_Model) 
  180.        return Gtk_Abstract_Tree_Model 
  181.        renames Implements_Gtk_Tree_Model.To_Object; 
  182. end Gtkada.Abstract_Tree_Model;