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