1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2001-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. --  <description> 
  25. --  The Gtk_Cell_Renderer is a base class of a set of objects used for 
  26. --  rendering a cell to a Gdk_Drawable. These objects are used primarily by the 
  27. --  Gtk_Tree_View widget, though they aren't tied to them in any specific way. 
  28. --  It is worth noting that Gtk_Cell_Renderer is not a Gtk_Widget and cannot be 
  29. --  treated as such. 
  30. -- 
  31. --  The primary use of a Gtk_Cell_Renderer is for drawing a certain graphical 
  32. --  elements on a Gdk_Drawable. Typically, one cell renderer is used to draw 
  33. --  many cells on the screen. To this extent, it isn't expected that 
  34. --  Cell_Renderer keep any permanent state around. Instead, any state is set 
  35. --  just prior to use using GObjects property system. Then, the cell is 
  36. --  measured using Get_Size(). Finally, the cell is rendered in the correct 
  37. --  location using Render(). 
  38. -- 
  39. --  There are a number of rules that must be followed when writing a new 
  40. --  Gtk_Cell_Renderer. First and formost, it's important that a certain set of 
  41. --  properties will always yield a cell renderer of the same size, barring 
  42. --  GtkStyle change. The Gtk_Cell_Renderer also has a number of generic 
  43. --  properties that are expected to be honored by all children. 
  44. -- 
  45. --  Beyond merely rendering a cell, cell renderers can optionally provide 
  46. --  active user interface elements. A cell renderer can be activatable like 
  47. --  Gtk_Cell_Renderer_Toggle, which toggles when it gets activated by a mouse 
  48. --  click, or it can be editable like Gtk_Cell_Renderer_Text, which allows the 
  49. --  user to edit the text using a Gtk_Entry. To make a cell renderer 
  50. --  activatable or editable, you have to implement the activate or 
  51. --  start_editing virtual functions, respectively. 
  52. --  </description> 
  53. --  <c_version>2.14</c_version> 
  54. --  <group>Trees and Lists</group> 
  55.  
  56. with Gdk.Event; 
  57. with Gdk.Rectangle; 
  58. with Gdk.Window; 
  59. with Gtk; 
  60. with Gtk.Cell_Editable; 
  61. with Gtk.Object; 
  62. with Gtk.Widget; 
  63. with Glib.Properties; 
  64. with Glib.Generic_Properties; 
  65. with Glib.Glist; 
  66. pragma Elaborate_All (Glib.Glist); 
  67.  
  68. package Gtk.Cell_Renderer is 
  69.  
  70.    type Gtk_Cell_Renderer_Record is 
  71.      new Gtk.Object.Gtk_Object_Record with private; 
  72.    type Gtk_Cell_Renderer is access all Gtk_Cell_Renderer_Record'Class; 
  73.  
  74.    function Convert (R : Gtk_Cell_Renderer) return System.Address; 
  75.    function Convert (R : System.Address) return Gtk_Cell_Renderer; 
  76.    package Cell_Renderer_List is 
  77.       new Glib.Glist.Generic_List (Gtk_Cell_Renderer); 
  78.  
  79.    type Gtk_Cell_Renderer_State is mod 2 ** 32; 
  80.    Cell_Renderer_Selected    : constant Gtk_Cell_Renderer_State; 
  81.    Cell_Renderer_Prelit      : constant Gtk_Cell_Renderer_State; 
  82.    Cell_Renderer_Insensitive : constant Gtk_Cell_Renderer_State; 
  83.    Cell_Renderer_Sorted      : constant Gtk_Cell_Renderer_State; 
  84.    Cell_Renderer_Focused     : constant Gtk_Cell_Renderer_State; 
  85.    --  Identifies how a cell should be renderer. Prelit is used when the mouse 
  86.    --  is hovering over a particular cell. Sorted is used when the cell is in 
  87.    --  a sort row. 
  88.  
  89.    type Gtk_Cell_Renderer_Mode is 
  90.      (Cell_Renderer_Mode_Inert, 
  91.       Cell_Renderer_Mode_Activatable, 
  92.       Cell_Renderer_Mode_Editable); 
  93.    for Gtk_Cell_Renderer_Mode'Size use Glib.Gint'Size; 
  94.    --  Identifies how the user can interact with a particular cell. If 
  95.    --  Activatable, the cell can be clicked. If Editable, the cell can be 
  96.    --  modified 
  97.  
  98.    function Get_Type return GType; 
  99.    --  Return the internal value associated with Gtk_Cell_Renderer 
  100.  
  101.    procedure Get_Size 
  102.      (Cell      : access Gtk_Cell_Renderer_Record; 
  103.       Widget    : access Gtk.Widget.Gtk_Widget_Record'Class; 
  104.       Cell_Area : out Gdk.Rectangle.Gdk_Rectangle; 
  105.       X_Offset  : out Gint; 
  106.       Y_Offset  : out Gint; 
  107.       Width     : out Gint; 
  108.       Height    : out Gint); 
  109.    --  Obtain the width and height needed to render the cell. 
  110.    --  Used by view widgets to determine the appropriate size for the Cell_Area 
  111.    --  passed to Render. Fill in the x and y offsets (if set) of the cell 
  112.    --  relative to this location. Please note that the values set in Width and 
  113.    --  Height, as well as those in X_Offset and Y_Offset are inclusive of the 
  114.    --  Xpad and Ypad properties. 
  115.    --  Widget: the widget the renderer is rendering to. 
  116.    --  Cell_Area: The area a cell will be allocated. 
  117.    --  X_Offset: X offset of cell relative to Cell_Area. 
  118.    --  Y_Offset: Y offset of cell relative to Cell_Area. 
  119.    --  Width: Width needed to render a cell. 
  120.    --  Height: Height needed to render a cell. 
  121.  
  122.    procedure Render 
  123.      (Cell            : access Gtk_Cell_Renderer_Record; 
  124.       Window          : Gdk.Window.Gdk_Window; 
  125.       Widget          : access Gtk.Widget.Gtk_Widget_Record'Class; 
  126.       Background_Area : Gdk.Rectangle.Gdk_Rectangle; 
  127.       Cell_Area       : Gdk.Rectangle.Gdk_Rectangle; 
  128.       Expose_Area     : Gdk.Rectangle.Gdk_Rectangle; 
  129.       Flags           : Gtk_Cell_Renderer_State); 
  130.    --  Invokes the virtual render function of the Gtk_Cell_Renderer. The three 
  131.    --  passed-in rectangles are areas of Window. Most renderers will draw 
  132.    --  within Cell_Area; the Xalign, Yalign, Xpad, and Ypad fields of the 
  133.    --  GtkCellRenderer should be honored with respect to Cell_Area. 
  134.    --  Background_Area includes the blank space around the cell, and also the 
  135.    --  area containing the tree expander; so the Background_Area rectangles 
  136.    --  for all cells tile to cover the entire Window.  Expose_Area is a clip 
  137.    --  rectangle. 
  138.  
  139.    function Activate 
  140.      (Cell            : access Gtk_Cell_Renderer_Record; 
  141.       Event           : Gdk.Event.Gdk_Event; 
  142.       Widget          : access Gtk.Widget.Gtk_Widget_Record'Class; 
  143.       Path            : UTF8_String; 
  144.       Background_Area : Gdk.Rectangle.Gdk_Rectangle; 
  145.       Cell_Area       : Gdk.Rectangle.Gdk_Rectangle; 
  146.       Flags           : Gtk_Cell_Renderer_State) return Boolean; 
  147.    --  Passes an activate event to the cell renderer for possible processing. 
  148.    --  Some cell renderers may use events; 
  149.    --  for example, Gtk_Cell_Renderer_Toggle toggles when it gets a 
  150.    --  mouse click. 
  151.  
  152.    function Start_Editing 
  153.      (Cell            : access Gtk_Cell_Renderer_Record; 
  154.       Event           : Gdk.Event.Gdk_Event; 
  155.       Widget          : access Gtk.Widget.Gtk_Widget_Record'Class; 
  156.       Path            : UTF8_String; 
  157.       Background_Area : Gdk.Rectangle.Gdk_Rectangle; 
  158.       Cell_Area       : Gdk.Rectangle.Gdk_Rectangle; 
  159.       Flags           : Gtk_Cell_Renderer_State) 
  160.       return Gtk.Cell_Editable.Gtk_Cell_Editable; 
  161.    --  Passes an activate event to the cell renderer for possible processing. 
  162.    --  Cell: a Gtk_Cell_Renderer 
  163.    --  Event: a Gdk_Event 
  164.    --  Widget: widget that received the event 
  165.    --  Path: widget-dependent string representation of the event location; 
  166.    --  e.g. for Gtk_Tree_View, a string representation of Gtk_Tree_Path 
  167.    --  Background_Area: background area as passed to Render 
  168.    --  Cell_Area: cell area as passed to Render 
  169.  
  170.    procedure Set_Fixed_Size 
  171.      (Cell   : access Gtk_Cell_Renderer_Record; 
  172.       Width  : Gint; 
  173.       Height : Gint); 
  174.    procedure Get_Fixed_Size 
  175.      (Cell   : access Gtk_Cell_Renderer_Record; 
  176.       Width  : out Gint; 
  177.       Height : out Gint); 
  178.    --  Sets the renderer size to be explicit, independent of the 
  179.    --  properties set. 
  180.  
  181.    ------------- 
  182.    -- Signals -- 
  183.    ------------- 
  184.  
  185.    --  <signals> 
  186.    --  The following new signals are defined for this widget: 
  187.    -- 
  188.    --  - "editing-canceled" 
  189.    --    procedure Handler (Cell : access Gtk_Cell_Renderer_Record'Class); 
  190.    --    This signal gets emitted when the user cancels the process of editing 
  191.    --    cell. For example, an editable cell renderer could be written to 
  192.    --    cancel editing when the user presses Escape. 
  193.    -- 
  194.    --  - "editing-started" 
  195.    --    procedure Handler 
  196.    --       (Cell     : access Gtk_Cell_Renderer_Record'Class; 
  197.    --        Editable : Gtk_Cell_Editable 
  198.    --        Path     : String) 
  199.    --    This signal gets emitted when a cell starts to be edited. The indended 
  200.    --    use of this signal is to do special setup on editable, e.g. adding a 
  201.    --    GtkEntryCompletion or setting up additional columns in a GtkComboBox. 
  202.    --    Note that GTK+ doesn't guarantee that cell renderers will continue to 
  203.    --    use the same kind of widget for editing in future releases, therefore 
  204.    --    you should check the type of editable before doing any specific setup, 
  205.    --    as in the following example: 
  206.    --  </signals> 
  207.  
  208.    Signal_Editing_Canceled : constant Glib.Signal_Name := "editing-canceled"; 
  209.    Signal_Editing_Started  : constant Glib.Signal_Name := "editing-started"; 
  210.  
  211.    ---------------- 
  212.    -- Properties -- 
  213.    ---------------- 
  214.  
  215.    --  The following properties are defined for this cell_renderer and its 
  216.    --  children: 
  217.    --  <properties> 
  218.    -- 
  219.    --   Attribute             Type in Model             Mode 
  220.    --   =========             =============             ==== 
  221.    -- 
  222.    --   "mode"                Gtk_Cell_Renderer_Mode    Read / Write 
  223.    --   "visible"             Boolean                   Read / Write 
  224.    --   "xalign"              Gfloat                    Read / Write 
  225.    --   "yalign"              Gfloat                    Read / Write 
  226.    --   "xpad"                Guint                     Read / Write 
  227.    --   "ypad"                Guint                     Read / Write 
  228.    --   "width"               Gint                      Read / Write 
  229.    --   "height"              Gint                      Read / Write 
  230.    --   "is_expander"         Boolean                   Read / Write 
  231.    --   "is_expanded"         Boolean                   Read / Write 
  232.    --   "cell_background_gdk" Gdk_Color                 Read / Write 
  233.    --   "cell_background"     String                    Write 
  234.    -- 
  235.    --  Name:  Cell_Background_Property 
  236.    --  Type:  String 
  237.    --  Descr: Cell background color as a string 
  238.    -- 
  239.    --  Name:  Cell_Background_Gdk_Property 
  240.    --  Type:  Boxed 
  241.    --  Descr: Cell background color as a GdkColor 
  242.    -- 
  243.    --  Name:  Editing_Property 
  244.    --  Type:  Boolean 
  245.    --  Descr: Whether the cell renderer is currently in editing mode 
  246.    -- 
  247.    --  Name:  Height_Property 
  248.    --  Type:  Int 
  249.    --  Descr: The fixed height 
  250.    -- 
  251.    --  Name:  Is_Expanded_Property 
  252.    --  Type:  Boolean 
  253.    --  Descr: Row is an expander row, and is expanded 
  254.    -- 
  255.    --  Name:  Is_Expander_Property 
  256.    --  Type:  Boolean 
  257.    --  Descr: Row has children 
  258.    -- 
  259.    --  Name:  Mode_Property 
  260.    --  Type:  Enum 
  261.    --  Descr: Editable mode of the CellRenderer 
  262.    -- 
  263.    --  Name:  Sensitive_Property 
  264.    --  Type:  Boolean 
  265.    --  Descr: Display the cell sensitive 
  266.    -- 
  267.    --  Name:  Visible_Property 
  268.    --  Type:  Boolean 
  269.    --  Descr: Display the cell 
  270.    -- 
  271.    --  Name:  Width_Property 
  272.    --  Type:  Int 
  273.    --  Descr: The fixed width 
  274.    -- 
  275.    --  Name:  Xalign_Property 
  276.    --  Type:  Float 
  277.    --  Descr: The x-align 
  278.    -- 
  279.    --  Name:  Xpad_Property 
  280.    --  Type:  Uint 
  281.    --  Descr: The xpad 
  282.    -- 
  283.    --  Name:  Yalign_Property 
  284.    --  Type:  Float 
  285.    --  Descr: The y-align 
  286.    -- 
  287.    --  Name:  Ypad_Property 
  288.    --  Type:  Uint 
  289.    --  Descr: The ypad 
  290.  
  291.    --   </properties> 
  292.  
  293.    package Cell_Renderer_Mode_Properties is new 
  294.      Glib.Generic_Properties.Generic_Internal_Discrete_Property 
  295.        (Gtk_Cell_Renderer_Mode); 
  296.    type Property_Cell_Renderer_Mode is 
  297.      new Cell_Renderer_Mode_Properties.Property; 
  298.  
  299.    Cell_Background_Property     : constant Glib.Properties.Property_String; 
  300.    --  Cell_Background_Gdk_Property : constant Glib.Properties.Property_Boxed; 
  301.    Editing_Property             : constant Glib.Properties.Property_Boolean; 
  302.    Height_Property              : constant Glib.Properties.Property_Int; 
  303.    Is_Expanded_Property         : constant Glib.Properties.Property_Boolean; 
  304.    Is_Expander_Property         : constant Glib.Properties.Property_Boolean; 
  305.    Mode_Property                : constant Property_Cell_Renderer_Mode; 
  306.    Sensitive_Property           : constant Glib.Properties.Property_Boolean; 
  307.    Visible_Property             : constant Glib.Properties.Property_Boolean; 
  308.    Width_Property               : constant Glib.Properties.Property_Int; 
  309.    Xalign_Property              : constant Glib.Properties.Property_Float; 
  310.    Xpad_Property                : constant Glib.Properties.Property_Uint; 
  311.    Yalign_Property              : constant Glib.Properties.Property_Float; 
  312.    Ypad_Property                : constant Glib.Properties.Property_Uint; 
  313.  
  314. private 
  315.    type Gtk_Cell_Renderer_Record is 
  316.      new Gtk.Object.Gtk_Object_Record with null record; 
  317.  
  318.    pragma Import (C, Get_Type, "gtk_cell_renderer_get_type"); 
  319.  
  320.    Cell_Background_Property : constant Glib.Properties.Property_String := 
  321.      Glib.Properties.Build ("cell-background"); 
  322.    --  Cell_Background_Gdk_Property : constant Glib.Properties.Property_Boxed 
  323.    --    := Glib.Properties.Build ("cell-background-gdk"); 
  324.    Editing_Property : constant Glib.Properties.Property_Boolean := 
  325.      Glib.Properties.Build ("editing"); 
  326.    Height_Property : constant Glib.Properties.Property_Int := 
  327.      Glib.Properties.Build ("height"); 
  328.    Is_Expanded_Property : constant Glib.Properties.Property_Boolean := 
  329.      Glib.Properties.Build ("is-expanded"); 
  330.    Is_Expander_Property : constant Glib.Properties.Property_Boolean := 
  331.      Glib.Properties.Build ("is-expander"); 
  332.    Mode_Property : constant Property_Cell_Renderer_Mode := 
  333.      Build ("mode"); 
  334.    Sensitive_Property : constant Glib.Properties.Property_Boolean := 
  335.      Glib.Properties.Build ("sensitive"); 
  336.    Visible_Property : constant Glib.Properties.Property_Boolean := 
  337.      Glib.Properties.Build ("visible"); 
  338.    Width_Property : constant Glib.Properties.Property_Int := 
  339.      Glib.Properties.Build ("width"); 
  340.    Xalign_Property : constant Glib.Properties.Property_Float := 
  341.      Glib.Properties.Build ("xalign"); 
  342.    Xpad_Property : constant Glib.Properties.Property_Uint := 
  343.      Glib.Properties.Build ("xpad"); 
  344.    Yalign_Property : constant Glib.Properties.Property_Float := 
  345.      Glib.Properties.Build ("yalign"); 
  346.    Ypad_Property : constant Glib.Properties.Property_Uint := 
  347.      Glib.Properties.Build ("ypad"); 
  348.  
  349.    Cell_Renderer_Selected    : constant Gtk_Cell_Renderer_State := 2 ** 0; 
  350.    Cell_Renderer_Prelit      : constant Gtk_Cell_Renderer_State := 2 ** 1; 
  351.    Cell_Renderer_Insensitive : constant Gtk_Cell_Renderer_State := 2 ** 2; 
  352.    Cell_Renderer_Sorted      : constant Gtk_Cell_Renderer_State := 2 ** 3; 
  353.    Cell_Renderer_Focused     : constant Gtk_Cell_Renderer_State := 2 ** 4; 
  354. end Gtk.Cell_Renderer; 
  355.  
  356. --  The following subprograms never had a binding, are now obsolescent 
  357. --  No binding: gtk_cell_renderer_editing_canceled 
  358. --  No binding: gtk_cell_renderer_stop_editing