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