1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006 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. --  <description> 
  25. --  Gtk_Cell_Layout is an interface to be implemented by all objects which want 
  26. --  to provide a Gtk_Tree_View_Column like API for packing cells, setting 
  27. --  attributes and data funcs. 
  28. --  The rendering of the widget is done through various Gtk_Cell_Renderer, and 
  29. --  by reading data from a Gtk_Tree_Model. 
  30. --  </description> 
  31. --  <c_version>2.8.17</c_version> 
  32. --  <group>Trees and Lists</group> 
  33. --  <testgtk>create_cell_view.adb</testgtk> 
  34.  
  35. with Glib.Types; 
  36. with Gtk.Cell_Renderer; 
  37. with Gtk.Tree_Model; 
  38.  
  39. package Gtk.Cell_Layout is 
  40.  
  41.    type Gtk_Cell_Layout is new Glib.Types.GType_Interface; 
  42.    --  An interface (similar to Java's interfaces) that can be implemented by 
  43.    --  tagged types derived from Glib.Object.GObject. 
  44.  
  45.    function Get_Type return Glib.GType; 
  46.    --  Returns the internal type used for a Gtk_Cell_Layout interface 
  47.  
  48.    procedure Pack_Start 
  49.      (Cell_Layout : Gtk_Cell_Layout; 
  50.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  51.       Expand      : Boolean); 
  52.    procedure Pack_End 
  53.      (Cell_Layout : Gtk_Cell_Layout; 
  54.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  55.       Expand      : Boolean); 
  56.    --  Adds Cell to the beginning or end of Cell_Layout. If Expand is False, 
  57.    --  then the Cell is allocated no more space than it needs. Any unused space 
  58.    --  is divided evenly between cells for which Expand is True. Note that 
  59.    --  reusing the same cell renderer is not supported. 
  60.  
  61.    procedure Add_Attribute 
  62.      (Cell_Layout : Gtk_Cell_Layout; 
  63.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  64.       Attribute   : String; 
  65.       Column      : Gint); 
  66.    --  Adds an attribute mapping to the list in Cell_Layout. Column is the 
  67.    --  column of the model to get a value from, and Attribute is the parameter 
  68.    --  on Cell to be set from the value. So for example if column of the model 
  69.    --  contains strings, you could have the "text" attribute of 
  70.    --  Gtk_Cell_Renderer_Text get its values from column 2. 
  71.  
  72.    procedure Clear (Cell_Layout : Gtk_Cell_Layout); 
  73.    --  Unsets all the mappings on all renderers on Cell_Layout and 
  74.    --  removes all renderers from Cell_Layout. 
  75.  
  76.    procedure Clear_Attributes 
  77.      (Cell_Layout : Gtk_Cell_Layout; 
  78.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class); 
  79.    --  Clears all existing attributes previously set with Add_Attribute. 
  80.  
  81.    procedure Reorder 
  82.      (Cell_Layout : Gtk_Cell_Layout; 
  83.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  84.       Position    : Gint); 
  85.    --  Re-inserts Cell at Position. Note that Cell has already to be packed 
  86.    --  into Cell_layout for this to function properly. 
  87.  
  88.    type Cell_Data_Func is access procedure 
  89.      (Cell_Layout : Gtk_Cell_Layout; 
  90.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  91.       Model       : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; 
  92.       Iter        : Gtk.Tree_Model.Gtk_Tree_Iter); 
  93.    --  This subprogram can be used to globally modify an attribute of the 
  94.    --  Cell renderer. 
  95.    --  It should set the attributes of Cell as appropriate for this tree iter. 
  96.  
  97.    procedure Set_Cell_Data_Func 
  98.      (Cell_Layout : Gtk_Cell_Layout; 
  99.       Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  100.       Func        : Cell_Data_Func); 
  101.    --  Sets the Cell_Data_Func to use for Cell_Layout. This function is used 
  102.    --  instead of the standard attributes mapping for setting the column value, 
  103.    --  and should set the value of Cell_layout's cell renderer(s) as 
  104.    --  appropriate. Func may be null to remove and older one. 
  105.    --  This allows you to compute the attributes dynamically from several 
  106.    --  columns of the model for instance 
  107.  
  108.    generic 
  109.       type Data_Type (<>) is private; 
  110.    package Cell_Data_Functions is 
  111.       type Cell_Data_Func is access procedure 
  112.         (Cell_Layout : Gtk_Cell_Layout; 
  113.          Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  114.          Model       : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; 
  115.          Iter        : Gtk.Tree_Model.Gtk_Tree_Iter; 
  116.          Data        : Data_Type); 
  117.  
  118.       type Destroy_Notify is access procedure (Data : in out Data_Type); 
  119.       --  Free the memory used by Data 
  120.  
  121.       procedure Set_Cell_Data_Func 
  122.         (Cell_Layout : Gtk_Cell_Layout; 
  123.          Cell        : access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  124.          Func        : Cell_Data_Func; 
  125.          Data        : Data_Type; 
  126.          Destroy     : Destroy_Notify := null); 
  127.       --  Same as the other Set_Cell_Data_Func, but passes an addition user 
  128.       --  data to the callback. 
  129.  
  130.    private 
  131.       --  <doc_ignore> 
  132.       type Data_Type_Access is access Data_Type; 
  133.  
  134.       type Data_Type_Record is record 
  135.          Func    : Cell_Data_Func; 
  136.          Destroy : Destroy_Notify; 
  137.          Data    : Data_Type_Access; 
  138.       end record; 
  139.       type Data_Type_Record_Access is access Data_Type_Record; 
  140.       pragma Convention (C, Data_Type_Record_Access); 
  141.  
  142.       procedure Internal_Destroy_Notify (Data : Data_Type_Record_Access); 
  143.       pragma Convention (C, Internal_Destroy_Notify); 
  144.  
  145.       procedure Internal_Data_Cell_Data_Func 
  146.         (Cell_Layout       : Gtk_Cell_Layout; 
  147.          Cell, Model, Iter : System.Address; 
  148.          Data              : Data_Type_Record_Access); 
  149.       pragma Convention (C, Internal_Data_Cell_Data_Func); 
  150.       --  </doc_ignore> 
  151.    end Cell_Data_Functions; 
  152.  
  153. private 
  154.    pragma Import (C, Get_Type, "gtk_cell_layout_get_type"); 
  155.    pragma Import (C, Clear, "gtk_cell_layout_clear"); 
  156. end Gtk.Cell_Layout; 
  157.  
  158. --  No binding: gtk_cell_layout_set_attributes