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.Cell_Layout.Gtk_Cell_Layout is an interface to be implemented by all 
  26. --  objects which want to provide a 
  27. --  Gtk.Tree_View_Column.Gtk_Tree_View_Column<!-- -->-like API for packing 
  28. --  cells, setting attributes and data funcs. 
  29. -- 
  30. --  One of the notable features provided by implementations of GtkCellLayout 
  31. --  are *attributes*. Attributes let you set the properties in flexible ways. 
  32. --  They can just be set to constant values like regular properties. But they 
  33. --  can also be mapped to a column of the underlying tree model with 
  34. --  gtk_cell_layout_set_attributes, which means that the value of the attribute 
  35. --  can change from cell to cell as they are rendered by the cell renderer. 
  36. --  Finally, it is possible to specify a function with 
  37. --  Gtk.Cell_Layout.Set_Cell_Data_Func that is called to determine the value of 
  38. --  the attribute for each cell that is rendered. 
  39. -- 
  40. --  == GtkCellLayouts as GtkBuildable == 
  41. -- 
  42. --  Implementations of GtkCellLayout which also implement the GtkBuildable 
  43. --  interface (Gtk.Cell_View.Gtk_Cell_View, Gtk.Icon_View.Gtk_Icon_View, 
  44. --  Gtk.Combo_Box.Gtk_Combo_Box, Gtk.Entry_Completion.Gtk_Entry_Completion, 
  45. --  Gtk.Tree_View_Column.Gtk_Tree_View_Column) accept GtkCellRenderer objects 
  46. --  as <child> elements in UI definitions. They support a custom <attributes> 
  47. --  element for their children, which can contain multiple <attribute> 
  48. --  elements. Each <attribute> element has a name attribute which specifies a 
  49. --  property of the cell renderer; the content of the element is the attribute 
  50. --  value. 
  51. -- 
  52. --  == A UI definition fragment specifying attributes == 
  53. -- 
  54. --    <object class="GtkCellView"> 
  55. --    <child> 
  56. --    <object class="GtkCellRendererText"/> 
  57. --    <attributes> 
  58. --    <attribute name="text">0</attribute> 
  59. --    </attributes> 
  60. --    </child>" 
  61. --    </object> 
  62. --  Furthermore for implementations of GtkCellLayout that use a 
  63. --  Gtk.Cell_Area.Gtk_Cell_Area to lay out cells (all GtkCellLayouts in GTK+ 
  64. --  use a GtkCellArea) <link linkend="cell-properties">cell properties</link> 
  65. --  can also be defined in the format by specifying the custom <cell-packing> 
  66. --  attribute which can contain multiple <property> elements defined in the 
  67. --  normal way. 
  68. -- 
  69. --  == A UI definition fragment specifying cell properties == 
  70. -- 
  71. --    <object class="GtkTreeViewColumn"> 
  72. --    <child> 
  73. --    <object class="GtkCellRendererText"/> 
  74. --    <cell-packing> 
  75. --    <property name="align">True</property> 
  76. --    <property name="expand">False</property> 
  77. --    </cell-packing> 
  78. --    </child>" 
  79. --    </object> 
  80. --  == Subclassing GtkCellLayout implementations == 
  81. -- 
  82. --  When subclassing a widget that implements Gtk.Cell_Layout.Gtk_Cell_Layout 
  83. --  like Gtk.Icon_View.Gtk_Icon_View or Gtk.Combo_Box.Gtk_Combo_Box, there are 
  84. --  some considerations related to the fact that these widgets internally use a 
  85. --  Gtk.Cell_Area.Gtk_Cell_Area. The cell area is exposed as a construct-only 
  86. --  property by these widgets. This means that it is possible to e.g. do 
  87. -- 
  88. --    combo = g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL); 
  89. -- 
  90. --  to use a custom cell area with a combo box. But construct properties are 
  91. --  only initialized *after* instance init functions have run, which means that 
  92. --  using functions which rely on the existence of the cell area in your 
  93. --  subclass' init function will cause the default cell area to be 
  94. --  instantiated. In this case, a provided construct property value will be 
  95. --  ignored (with a warning, to alert you to the problem). 
  96. -- 
  97. --    static void 
  98. --    my_combo_box_init (MyComboBox *b) 
  99. --    { 
  100. --       GtkCellRenderer *cell; 
  101. --       cell = gtk_cell_renderer_pixbuf_new (); 
  102. --       /* The following call causes the default cell area for combo boxes, 
  103. --       * a GtkCellAreaBox, to be instantiated 
  104. --       */ 
  105. --       gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE); 
  106. --       ... 
  107. --    } 
  108. --    GtkWidget * 
  109. --    my_combo_box_new (GtkCellArea *area) 
  110. --    { 
  111. --       /* This call is going to cause a warning 
  112. --       * about area being ignored 
  113. --       */ 
  114. --       return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL); 
  115. --    } 
  116. -- 
  117. --  If supporting alternative cell areas with your derived widget is not 
  118. --  important, then this does not have to concern you. If you want to support 
  119. --  alternative cell areas, you can do so by moving the problematic calls out 
  120. --  of init and into a constructor for your class. 
  121. -- 
  122. -- 
  123. --  </description> 
  124. --  <group>Trees and Lists</group> 
  125. --  <testgtk>create_cell_view.adb</testgtk> 
  126. pragma Ada_2005; 
  127.  
  128. pragma Warnings (Off, "*is already use-visible*"); 
  129. with Glib;              use Glib; 
  130. with Glib.Object;       use Glib.Object; 
  131. with Glib.Types;        use Glib.Types; 
  132. with Gtk.Cell_Renderer; use Gtk.Cell_Renderer; 
  133. with Gtk.Tree_Model;    use Gtk.Tree_Model; 
  134.  
  135. package Gtk.Cell_Layout is 
  136.  
  137.    type Gtk_Cell_Layout is new Glib.Types.GType_Interface; 
  138.    Null_Gtk_Cell_Layout : constant Gtk_Cell_Layout; 
  139.  
  140.    --------------- 
  141.    -- Callbacks -- 
  142.    --------------- 
  143.  
  144.    type Gtk_Cell_Layout_Data_Func is access procedure 
  145.      (Cell_Layout : Gtk_Cell_Layout; 
  146.       Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  147.       Tree_Model  : Gtk.Tree_Model.Gtk_Tree_Model; 
  148.       Iter        : Gtk.Tree_Model.Gtk_Tree_Iter); 
  149.    --  A function which should set the value of Cell_Layout's cell renderer(s) 
  150.    --  as appropriate. 
  151.    --  "cell_layout": a Gtk.Cell_Layout.Gtk_Cell_Layout 
  152.    --  "cell": the cell renderer whose value is to be set 
  153.    --  "tree_model": the model 
  154.    --  "iter": a Gtk.Tree_Model.Gtk_Tree_Iter indicating the row to set the 
  155.    --  value for 
  156.  
  157.    ------------------ 
  158.    -- Constructors -- 
  159.    ------------------ 
  160.  
  161.    function Get_Type return Glib.GType; 
  162.    pragma Import (C, Get_Type, "gtk_cell_layout_get_type"); 
  163.  
  164.    ------------- 
  165.    -- Methods -- 
  166.    ------------- 
  167.  
  168.    procedure Add_Attribute 
  169.       (Cell_Layout : Gtk_Cell_Layout; 
  170.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  171.        Attribute   : UTF8_String; 
  172.        Column      : Gint); 
  173.    --  Adds an attribute mapping to the list in Cell_Layout. 
  174.    --  The Column is the column of the model to get a value from, and the 
  175.    --  Attribute is the parameter on Cell to be set from the value. So for 
  176.    --  example if column 2 of the model contains strings, you could have the 
  177.    --  "text" attribute of a Gtk.Cell_Renderer_Text.Gtk_Cell_Renderer_Text get 
  178.    --  its values from column 2. 
  179.    --  Since: gtk+ 2.4 
  180.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  181.    --  "attribute": an attribute on the renderer 
  182.    --  "column": the column position on the model to get the attribute from 
  183.  
  184.    procedure Clear (Cell_Layout : Gtk_Cell_Layout); 
  185.    pragma Import (C, Clear, "gtk_cell_layout_clear"); 
  186.    --  Unsets all the mappings on all renderers on Cell_Layout and removes all 
  187.    --  renderers from Cell_Layout. 
  188.    --  Since: gtk+ 2.4 
  189.  
  190.    procedure Clear_Attributes 
  191.       (Cell_Layout : Gtk_Cell_Layout; 
  192.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class); 
  193.    --  Clears all existing attributes previously set with 
  194.    --  gtk_cell_layout_set_attributes. 
  195.    --  Since: gtk+ 2.4 
  196.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer to clear the attribute 
  197.    --  mapping on 
  198.  
  199.    function Get_Cells 
  200.       (Cell_Layout : Gtk_Cell_Layout) 
  201.        return Glib.Object.Object_Simple_List.Glist; 
  202.    --  Returns the cell renderers which have been added to Cell_Layout. 
  203.    --  Since: gtk+ 2.12 
  204.  
  205.    procedure Pack_End 
  206.       (Cell_Layout : Gtk_Cell_Layout; 
  207.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  208.        Expand      : Boolean); 
  209.    --  Adds the Cell to the end of Cell_Layout. If Expand is False, then the 
  210.    --  Cell is allocated no more space than it needs. Any unused space is 
  211.    --  divided evenly between cells for which Expand is True. 
  212.    --  Note that reusing the same cell renderer is not supported. 
  213.    --  Since: gtk+ 2.4 
  214.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  215.    --  "expand": True if Cell is to be given extra space allocated to 
  216.    --  Cell_Layout 
  217.  
  218.    procedure Pack_Start 
  219.       (Cell_Layout : Gtk_Cell_Layout; 
  220.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  221.        Expand      : Boolean); 
  222.    --  Packs the Cell into the beginning of Cell_Layout. If Expand is False, 
  223.    --  then the Cell is allocated no more space than it needs. Any unused space 
  224.    --  is divided evenly between cells for which Expand is True. 
  225.    --  Note that reusing the same cell renderer is not supported. 
  226.    --  Since: gtk+ 2.4 
  227.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  228.    --  "expand": True if Cell is to be given extra space allocated to 
  229.    --  Cell_Layout 
  230.  
  231.    procedure Reorder 
  232.       (Cell_Layout : Gtk_Cell_Layout; 
  233.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  234.        Position    : Gint); 
  235.    --  Re-inserts Cell at Position. 
  236.    --  Note that Cell has already to be packed into Cell_Layout for this to 
  237.    --  function properly. 
  238.    --  Since: gtk+ 2.4 
  239.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer to reorder 
  240.    --  "position": new position to insert Cell at 
  241.  
  242.    procedure Set_Cell_Data_Func 
  243.       (Cell_Layout : Gtk_Cell_Layout; 
  244.        Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  245.        Func        : Gtk_Cell_Layout_Data_Func); 
  246.    --  Sets the Gtk_Cell_Layout_Data_Func to use for Cell_Layout. 
  247.    --  This function is used instead of the standard attributes mapping for 
  248.    --  setting the column value, and should set the value of Cell_Layout's cell 
  249.    --  renderer(s) as appropriate. 
  250.    --  Func may be null to remove a previously set function. 
  251.    --  Since: gtk+ 2.4 
  252.    --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  253.    --  "func": the Gtk_Cell_Layout_Data_Func to use, or null 
  254.  
  255.    generic 
  256.       type User_Data_Type (<>) is private; 
  257.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  258.    package Set_Cell_Data_Func_User_Data is 
  259.  
  260.       type Gtk_Cell_Layout_Data_Func is access procedure 
  261.         (Cell_Layout : Gtk.Cell_Layout.Gtk_Cell_Layout; 
  262.          Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  263.          Tree_Model  : Gtk.Tree_Model.Gtk_Tree_Model; 
  264.          Iter        : Gtk.Tree_Model.Gtk_Tree_Iter; 
  265.          Data        : User_Data_Type); 
  266.       --  A function which should set the value of Cell_Layout's cell renderer(s) 
  267.       --  as appropriate. 
  268.       --  "cell_layout": a Gtk.Cell_Layout.Gtk_Cell_Layout 
  269.       --  "cell": the cell renderer whose value is to be set 
  270.       --  "tree_model": the model 
  271.       --  "iter": a Gtk.Tree_Model.Gtk_Tree_Iter indicating the row to set the 
  272.       --  value for 
  273.       --  "data": user data passed to Gtk.Cell_Layout.Set_Cell_Data_Func 
  274.  
  275.       procedure Set_Cell_Data_Func 
  276.          (Cell_Layout : Gtk.Cell_Layout.Gtk_Cell_Layout; 
  277.           Cell        : not null access Gtk.Cell_Renderer.Gtk_Cell_Renderer_Record'Class; 
  278.           Func        : Gtk_Cell_Layout_Data_Func; 
  279.           Func_Data   : User_Data_Type); 
  280.       --  Sets the Gtk_Cell_Layout_Data_Func to use for Cell_Layout. 
  281.       --  This function is used instead of the standard attributes mapping for 
  282.       --  setting the column value, and should set the value of Cell_Layout's 
  283.       --  cell renderer(s) as appropriate. 
  284.       --  Func may be null to remove a previously set function. 
  285.       --  Since: gtk+ 2.4 
  286.       --  "cell": a Gtk.Cell_Renderer.Gtk_Cell_Renderer 
  287.       --  "func": the Gtk_Cell_Layout_Data_Func to use, or null 
  288.       --  "func_data": user data for Func 
  289.  
  290.    end Set_Cell_Data_Func_User_Data; 
  291.  
  292.    ---------------- 
  293.    -- Interfaces -- 
  294.    ---------------- 
  295.    --  This class implements several interfaces. See Glib.Types 
  296.    -- 
  297.    --  - "Gtk_Cell_Layout" 
  298.  
  299.    function "+" (W : Gtk_Cell_Layout) return Gtk_Cell_Layout; 
  300.    pragma Inline ("+"); 
  301.  
  302. private 
  303.  
  304. Null_Gtk_Cell_Layout : constant Gtk_Cell_Layout := 
  305.    Gtk_Cell_Layout (Glib.Types.Null_Interface); 
  306. end Gtk.Cell_Layout;