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