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