1. ------------------------------------------------------------------------------ 
  2. --                  GtkAda - Ada95 binding for Gtk+/Gnome                   -- 
  3. --                                                                          -- 
  4. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  5. --                     Copyright (C) 1998-2014, AdaCore                     -- 
  6. --                                                                          -- 
  7. -- This library is free software;  you can redistribute it and/or modify it -- 
  8. -- under terms of the  GNU General Public License  as published by the Free -- 
  9. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  10. -- version. This library is distributed in the hope that it will be useful, -- 
  11. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  12. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  13. --                                                                          -- 
  14. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  15. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  16. -- version 3.1, as published by the Free Software Foundation.               -- 
  17. --                                                                          -- 
  18. -- You should have received a copy of the GNU General Public License and    -- 
  19. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  20. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  21. -- <http://www.gnu.org/licenses/>.                                          -- 
  22. --                                                                          -- 
  23. ------------------------------------------------------------------------------ 
  24.  
  25. --  <description> 
  26. --  This package provides an interactive canvas, on which the user can put 
  27. --  items, move them with the mouse, etc. The items can be connected together, 
  28. --  and the connections remain active while the items are moved. 
  29. -- 
  30. --  It also supports scrolling if put in a Gtk_Scrolled_Window. 
  31. --  The canvas will be scrolled (and the selected items moved) if an item is 
  32. --  selected and the mouse is dragged on a small area on the side of the canvas 
  33. --  or even directly outside of the canvas. Scrolling will continue until the 
  34. --  mouse is either released or moved back inside the canvas. 
  35. -- 
  36. --  The scrolling speed will slightly increase over time if the mouse is kept 
  37. --  outside of the canvas. This makes the canvas much more comfortable to use 
  38. --  for the user. 
  39. -- 
  40. --  All items put in this canvas must inherit from the type Canvas_Item_Record. 
  41. --  However, it is your responsability, as a programmer, to provide drawing 
  42. --  routines. In fact, all these items should draw in a pixmap, which is then 
  43. --  copied automatically to the screen whenever the canvas needs to redraw 
  44. --  itself. 
  45. -- 
  46. --  The items can also react to mouse events: mouse clicks are transmitted to 
  47. --  the item if the mouse did not move more than a given amount of pixels. 
  48. --  To decide what their reaction should be, you should override the 
  49. --  On_Button_Click subprogram. 
  50. -- 
  51. --  This canvas is not intended for cases where you want to put hundreds of 
  52. --  items on the screen. For instance, it does not provide any smart 
  53. --  double-buffering other than the one provided by gtk+ itself, and thus you 
  54. --  would get some flicker if there are too many items. 
  55. -- 
  56. --  There are three coordinate systems used by widget. All the subprograms 
  57. --  expect a specific coordinate system as input or output. Here are the three 
  58. --  systems: 
  59. --    - World coordinates 
  60. --      The position of an item is reported in pixels, as if the canvas 
  61. --      currently had a zoom level of 100%. This is fully independent, at any 
  62. --      time, from the current zoom level of the canvas. 
  63. --      Since the canvas is considered to expand ad infinitum, the top-left 
  64. --      corner doesn't have any specific fixed coordinates. It can be known by 
  65. --      checking the current lower value of the adjustments (aka scrollbars). 
  66. -- 
  67. --    - Canvas coordinates 
  68. --      This is similar to world coordinates, except these depend on the 
  69. --      current zoom level of the canvas. This also affect the width and height 
  70. --      of the objects in the canvas. 
  71. --      The subprograms To_Canvas_Coordinates and To_World_Coordinates can be 
  72. --      used to convert lengths from world to canvas coordinates. 
  73. --      The same behavior as world coordinates applies for the top-left corner. 
  74. --      All drawing to the screen, in particular for Draw_Background, must be 
  75. --      done using this coordinate systems 
  76. -- 
  77. --    - Item coordinates 
  78. --      The position of a point is relative to the top-left corner of the 
  79. --      current item. This corner therefore has coordinates (0, 0). 
  80. --      This coordinate systems assumes a zoom-level of 100% 
  81. -- 
  82. --  Items are selected automatically when they are clicked. If Control is 
  83. --  pressed at the same time, multiple items can be selected. 
  84. --  If the background is clicked (and control is not pressed), then all items 
  85. --  are unselected. 
  86. --  Pressing and dragging the mouse in the backgroudn draws a virtual box on 
  87. --  the screen. All the items fully included in this box when it is released 
  88. --  will be selected (this will replace the current selection if Control was 
  89. --  not pressed). 
  90. -- 
  91. --  </description> 
  92. --  <group>Drawing</group> 
  93. --  <testgtk>create_canvas.adb</testgtk> 
  94. --  <screenshot>gtkada-canvas</screenshot> 
  95.  
  96. with Ada.Calendar; 
  97.  
  98. with Cairo; 
  99. with Cairo.Region; 
  100.  
  101. with Gdk.Color; 
  102. with Gdk.Device; 
  103. with Gdk.Event; 
  104. with Gdk.RGBA; 
  105.  
  106. with Glib; 
  107. with Glib.Graphs; 
  108. with Glib.Main; 
  109.  
  110. with Gtk.Adjustment; 
  111. with Gtk.Layout; 
  112.  
  113. with Pango.Font; 
  114. with Pango.Layout; 
  115.  
  116. package Gtkada.Canvas is 
  117.  
  118.    type Interactive_Canvas_Record is new 
  119.      Gtk.Layout.Gtk_Layout_Record with private; 
  120.    type Interactive_Canvas is access all Interactive_Canvas_Record'Class; 
  121.    --  A canvas on which items are put. 
  122.    --  Each item can be moved interactively by the user, and links can be 
  123.    --  drawn automatically from an item to another. 
  124.    --  This widget can be inserted directly in a scrolled window to provide 
  125.    --  support for scrolling. 
  126.  
  127.    type Canvas_Item_Record is abstract new Glib.Graphs.Vertex with private; 
  128.    type Canvas_Item is access all Canvas_Item_Record'Class; 
  129.    --  An item that can be put on the canvas. 
  130.    --  This is an abstract type, as it does not provide any default drawing 
  131.    --  routine. You must override the abstract Draw subprogram. 
  132.  
  133.    type Canvas_Link_Record is new Glib.Graphs.Edge with private; 
  134.    type Canvas_Link is access all Canvas_Link_Record'Class; 
  135.    type Canvas_Link_Access is access all Canvas_Link_Record; 
  136.    --  A link between two items in the canvas. 
  137.    --  The implementation provided in this package provides links that can 
  138.    --  be either straight links or curved links. 
  139.    --  This type is provided as a tagged type so that you can associated your 
  140.    --  own user data with it. 
  141.  
  142.    ------------------- 
  143.    -- Customization -- 
  144.    ------------------- 
  145.    --  These are the default configuration values for the canvas. All the 
  146.    --  values can be changed by the Configure subprogram. 
  147.  
  148.    Default_Annotation_Font  : constant String := "Helvetica 8"; 
  149.    --  Font used when displaying link annotation. See Pango.Font for the 
  150.    --  format. 
  151.  
  152.    Default_Grid_Size        : constant := 15; 
  153.    --  Number of pixels between two dots on the grid. 
  154.    --  This is used for both horizontal and vertical orientation. 
  155.  
  156.    Default_Arc_Link_Offset  : constant := 25; 
  157.    --  Distance between two parallel arcs for two links. This is not the exact 
  158.    --  distance, and it only used to compute the control points for the bezier 
  159.    --  curves. 
  160.  
  161.    Default_Arrow_Angle      : constant := 30; 
  162.    --  Half angle for the arrows in degres 
  163.  
  164.    Default_Arrow_Length     : constant := 6; 
  165.    --  Length of the arrows in pixels. 
  166.  
  167.    Default_Motion_Threshold : constant := 4.0; 
  168.    --  Mimimum motion the mouse must have before we start moving the selected 
  169.    --  item. If the mouse has moved less than that amount of pixels in any 
  170.    --  direction, then the mouse click is considered as being a selection 
  171.    --  only and is transfered to the item itself. 
  172.    --  This is in screen coordinates 
  173.  
  174.    ---------------- 
  175.    -- Enum types -- 
  176.    ---------------- 
  177.  
  178.    type Arrow_Type is 
  179.      (No_Arrow, 
  180.       --  the link does not have an arrow 
  181.  
  182.       Start_Arrow, 
  183.       --  the link has an arrow at its beginning 
  184.  
  185.       End_Arrow, 
  186.       --  the link has an arrow at the end 
  187.  
  188.       Both_Arrow 
  189.       --  the link has an arrow on both sides 
  190.      ); 
  191.    --  Indicate whether the links have an arrow or not. 
  192.  
  193.    ----------------------- 
  194.    -- Creating a canvas -- 
  195.    ----------------------- 
  196.  
  197.    procedure Gtk_New 
  198.      (Canvas : out Interactive_Canvas; Auto_Layout : Boolean := True); 
  199.    --  Create a new empty Canvas. 
  200.    --  If Auto_Layout is True, then the items are automatically positioned as 
  201.    --  they are put in the canvas, if no coordinates are specified. 
  202.  
  203.    procedure Initialize 
  204.      (Canvas      : access Interactive_Canvas_Record'Class; 
  205.       Auto_Layout : Boolean := True); 
  206.    --  Internal function used to initialize the canvas. 
  207.  
  208.    function Get_Type return Glib.GType; 
  209.    --  Return the internal type 
  210.  
  211.    procedure Configure 
  212.      (Canvas : access Interactive_Canvas_Record; 
  213.       Grid_Size        : Glib.Guint := Default_Grid_Size; 
  214.       Annotation_Font  : Pango.Font.Pango_Font_Description := 
  215.                            Pango.Font.From_String (Default_Annotation_Font); 
  216.       Arc_Link_Offset  : Glib.Gint := Default_Arc_Link_Offset; 
  217.       Arrow_Angle      : Glib.Gint := Default_Arrow_Angle; 
  218.       Arrow_Length     : Glib.Gint := Default_Arrow_Length; 
  219.       Motion_Threshold : Glib.Gdouble := Default_Motion_Threshold; 
  220.       Background       : Gdk.RGBA.Gdk_RGBA := Gdk.RGBA.White_RGBA); 
  221.    --  Change the parameters for the canvas. 
  222.    --  A Grid_Size of 0 means than no grid should be drawn in the background of 
  223.    --  canvas. Note that in that case you can never activate Align_On_Grid. 
  224.    --  This setting doesn't apply if you have redefined Draw_Background, which 
  225.    --  may not draw a grid. 
  226.  
  227.    function Get_Vadj 
  228.      (Canvas : access Interactive_Canvas_Record'Class) 
  229.       return Gtk.Adjustment.Gtk_Adjustment; 
  230.    --  Return the vertical adjustment associated with Canvas 
  231.  
  232.    function Get_Hadj 
  233.      (Canvas : access Interactive_Canvas_Record'Class) 
  234.       return Gtk.Adjustment.Gtk_Adjustment; 
  235.    --  Return the horizontal adjustment associated with Canva 
  236.  
  237.    procedure Get_Bounding_Box 
  238.      (Canvas : access Interactive_Canvas_Record'Class; 
  239.       Width  : out Glib.Gdouble; 
  240.       Height : out Glib.Gdouble); 
  241.    --  Return the size occupied by the items drawn on the canvas. 
  242.  
  243.    procedure Draw_Area 
  244.      (Canvas : access Interactive_Canvas_Record'Class; 
  245.       Rect   : Cairo.Region.Cairo_Rectangle_Int); 
  246.    --  Draw in Canvas the specified area. 
  247.  
  248.    procedure Draw_All 
  249.      (Canvas : access Interactive_Canvas_Record'Class; 
  250.       Cr     : Cairo.Cairo_Context); 
  251.    --  Draws the whole canvas in Cr. Useful to print the canvas on an SVG or 
  252.    --  PNG surface. 
  253.  
  254.    procedure Draw_Background 
  255.      (Canvas : access Interactive_Canvas_Record; 
  256.       Cr     : Cairo.Cairo_Context); 
  257.    --  Draw the background of the canvas. This procedure should be overriden if 
  258.    --  you want to draw something else on the background. It must first clear 
  259.    --  the area on the screen. 
  260.    -- 
  261.    --  The default implementation draws a grid. 
  262.    -- 
  263.    --  An example implementation that draws a background image is shown at the 
  264.    --  end of this file. 
  265.  
  266.    procedure Draw_Grid 
  267.      (Canvas : access Interactive_Canvas_Record; 
  268.       Cr     : Cairo.Cairo_Context); 
  269.    --  Helper function that can be called from Draw_Background. It cannot be 
  270.    --  used directly as Draw_Background, since it doesn't clear the area first. 
  271.  
  272.    procedure Set_Orthogonal_Links 
  273.      (Canvas : access Interactive_Canvas_Record; 
  274.       Orthogonal : Boolean); 
  275.    --  If Orthogonal is True, then all the links will be drawn only with 
  276.    --  vertical and horizontal lines. This is not applied for the second or 
  277.    --  more link between two items. 
  278.  
  279.    function Get_Orthogonal_Links 
  280.      (Canvas : access Interactive_Canvas_Record) return Boolean; 
  281.    --  Return True if the links are only drawn horizontally and vertically. 
  282.  
  283.    procedure Align_On_Grid 
  284.      (Canvas : access Interactive_Canvas_Record; 
  285.       Align  : Boolean := True); 
  286.    --  Choose whether the items should be aligned on the grid when moved. 
  287.    --  Existing items are not moved even if you set this parameter to True, 
  288.    --  this will only take effect the next time the items are moved. 
  289.  
  290.    function Get_Align_On_Grid 
  291.      (Canvas : access Interactive_Canvas_Record) return Boolean; 
  292.    --  Return True if items are currently aligned on grid. 
  293.  
  294.    procedure Move_To 
  295.      (Canvas : access Interactive_Canvas_Record; 
  296.       Item   : access Canvas_Item_Record'Class; 
  297.       X, Y   : Glib.Gint := Glib.Gint'First); 
  298.    --  Move the item in the canvas, to world coordinates (X, Y). 
  299.    --  Item is assumed to be already in the canvas. 
  300.    --  If you leave both coordinates X and Y to their default value, then the 
  301.    --  item's location will be automatically computed when you layout the 
  302.    --  canvas (it is your responsability to call Layout). 
  303.  
  304.    procedure Set_Items 
  305.      (Canvas : access Interactive_Canvas_Record; 
  306.       Items  : Glib.Graphs.Graph); 
  307.    --  Set the items and links to display in the canvas from Items. 
  308.    --  All items previously in the canvas are removed, and replaced by the 
  309.    --  vertices in Items. 
  310.    --  Note that the vertices in Items must be in Canvas_Item_Record'Class, and 
  311.    --  the links must be in Canvas_Link_Record'Class. 
  312.    --  If you do not have an automatic layout set up in Canvas, you need to set 
  313.    --  the coordinates of all the vertices by calling Move_To separately. 
  314.    -- 
  315.    --  You mustn't destroy items yourself, this is done automatically when the 
  316.    --  canvas is destroyed. 
  317.  
  318.    procedure Put 
  319.      (Canvas : access Interactive_Canvas_Record; 
  320.       Item   : access Canvas_Item_Record'Class; 
  321.       X, Y   : Glib.Gint := Glib.Gint'First); 
  322.    --  Add a new item to the canvas, at world coordinates (X, Y). 
  323.    --  The item is added at a specific location. 
  324.    --  If you leave both X and Y to their default value, the item's location 
  325.    --  will be computed automatically when you call Layout on the canvas, 
  326.    --  unless Auto_Layout has been set, in which case the position will be 
  327.    --  computed immediately. 
  328.  
  329.    function Item_At_Coordinates 
  330.      (Canvas : access Interactive_Canvas_Record; 
  331.       X, Y : Glib.Gint) return Canvas_Item; 
  332.    --  Return the item at world coordinates (X, Y) which is on top of all 
  333.    --  others. 
  334.    --  null is returned if there is no such item. 
  335.  
  336.    function Item_At_Coordinates 
  337.      (Canvas : access Interactive_Canvas_Record; Event : Gdk.Event.Gdk_Event) 
  338.       return Canvas_Item; 
  339.    --  Same as above, but using the canvas coordinates of the event, taking 
  340.    --  into account the current zoom level and current scrolling 
  341.  
  342.    procedure Item_At_Coordinates 
  343.      (Canvas : access Interactive_Canvas_Record; 
  344.       Event  : Gdk.Event.Gdk_Event; 
  345.       Item   : out Canvas_Item; 
  346.       X, Y   : out Glib.Gint); 
  347.    --  Same as above, but also returns the coordinates (X, Y) within the item. 
  348.    --  The coordinates are not set if Item is null on exit. 
  349.  
  350.    procedure Clear (Canvas : access Interactive_Canvas_Record); 
  351.    --  Remove all items from the canvas 
  352.  
  353.    procedure Remove 
  354.      (Canvas : access Interactive_Canvas_Record; 
  355.       Item   : access Canvas_Item_Record'Class); 
  356.    --  Remove an item and all the links to and from it from the canvas. 
  357.    --  The item itself is not freed, but the links are. 
  358.    --  Nothing is done if the item is not part of the canvas. 
  359.  
  360.    procedure Item_Updated 
  361.      (Canvas : access Interactive_Canvas_Record; 
  362.       Item   : access Canvas_Item_Record'Class); 
  363.    --  This should be called when Item has changed the contents of its 
  364.    --  pixmap, and thus the Canvas should be updated. 
  365.  
  366.    procedure Refresh_Canvas (Canvas : access Interactive_Canvas_Record); 
  367.    --  Redraw the whole canvas (both in the double buffer and on the screen). 
  368.  
  369.    procedure Refresh 
  370.      (Self : not null access Interactive_Canvas_Record; 
  371.       Item : access Canvas_Item_Record'Class := null); 
  372.    --  Refresh either the whole canvas, or just the area occupied by the item 
  373.    --  if it is specified. 
  374.  
  375.    procedure Raise_Item 
  376.      (Canvas : access Interactive_Canvas_Record; 
  377.       Item   : access Canvas_Item_Record'Class); 
  378.    --  Raise the item so that it is displayed on top of all the others 
  379.    --  The canvas is refreshed as needed to reflect the change. 
  380.    --  Nothing happens if Item is not part of the canvas. 
  381.  
  382.    procedure Lower_Item 
  383.      (Canvas : access Interactive_Canvas_Record; 
  384.       Item   : access Canvas_Item_Record'Class); 
  385.    --  Lower the item so that it is displayed below all the others. 
  386.    --  The canvas is refreshed as needed to reflect the change. 
  387.    --  Nothing happens if Item is not part of the canvas. 
  388.  
  389.    function Is_On_Top 
  390.      (Canvas : access Interactive_Canvas_Record; 
  391.       Item   : access Canvas_Item_Record'Class) return Boolean; 
  392.    --  Return True if Item is displayed on top of all the others in the canvas. 
  393.  
  394.    procedure Show_Item 
  395.      (Canvas : access Interactive_Canvas_Record; 
  396.       Item   : access Canvas_Item_Record'Class); 
  397.    --  Scroll the canvas so that Item is visible. Nothing is done if the item 
  398.    --  is already visible 
  399.  
  400.    procedure Align_Item 
  401.      (Canvas  : access Interactive_Canvas_Record; 
  402.       Item    : access Canvas_Item_Record'Class; 
  403.       X_Align : Float := 0.5; 
  404.       Y_Align : Float := 0.5); 
  405.    --  Scroll the canvas so that the Item appears at the given location in the 
  406.    --  canvas. If X_Align is 0.0, the item is align on the left. With 0.5, it 
  407.    --  is centered horizontally. If 1.0, it is aligned on the right. 
  408.  
  409.    function Get_Arrow_Angle 
  410.      (Canvas : access Interactive_Canvas_Record'Class) return Glib.Gdouble; 
  411.    --  Return the angle of arrows in the canvas. 
  412.  
  413.    function Get_Arrow_Length 
  414.      (Canvas : access Interactive_Canvas_Record'Class) return Glib.Gint; 
  415.    --  Return the length of arrows in the canvas. 
  416.  
  417.    -------------------------- 
  418.    -- Iterating over items -- 
  419.    -------------------------- 
  420.  
  421.    type Item_Processor is access function 
  422.      (Canvas : access Interactive_Canvas_Record'Class; 
  423.       Item   : access Canvas_Item_Record'Class) return Boolean; 
  424.  
  425.    procedure For_Each_Item 
  426.      (Canvas            : access Interactive_Canvas_Record; 
  427.       Execute           : Item_Processor; 
  428.       Linked_From_Or_To : Canvas_Item := null); 
  429.    --  Execute an action on each of the items contained in the canvas. 
  430.    --  If Execute returns False, we stop traversing the list of children. 
  431.    --  It is safe to remove the items in Item_Processor. 
  432.    -- 
  433.    --  If Linked_From_Or_To is not null, then only the items linked to this one 
  434.    --  will be processed. It is possible that a given item will be returned 
  435.    --  twice, if it is both linked to and from the item. 
  436.  
  437.    type Item_Iterator is private; 
  438.  
  439.    function Start 
  440.      (Canvas            : access Interactive_Canvas_Record; 
  441.       Linked_From_Or_To : Canvas_Item := null; 
  442.       Selected_Only     : Boolean := False) return Item_Iterator; 
  443.    --  Return the first item in the canvas. 
  444.    --  The same restriction as above applies if Linked_From_Or_To is not null. 
  445.  
  446.    procedure Next (Iter : in out Item_Iterator); 
  447.    function Next (Iter : Item_Iterator) return Item_Iterator; 
  448.    --  Move the iterator to the next item. 
  449.    --  All items will eventually be returned if you do not add new items during 
  450.    --  the iteration and none are removed. However, it is safe to remove items 
  451.    --  at any time, except the current item 
  452.  
  453.    function Get (Iter : Item_Iterator) return Canvas_Item; 
  454.    --  Return the item pointed to by the iterator. 
  455.    --  null is returned when there are no more item in the canvas. 
  456.  
  457.    function Is_Linked_From (Iter : Item_Iterator) return Boolean; 
  458.    --  Return True if there is a link from: 
  459.    --     Get (Iter) -> Linked_From_Or_To 
  460.    --  Linked_From_Or_To is the item passed to Start. False is returned if this 
  461.    --  item was null. 
  462.  
  463.    ------------- 
  464.    -- Zooming -- 
  465.    ------------- 
  466.  
  467.    procedure Zoom 
  468.      (Canvas  : access Interactive_Canvas_Record; 
  469.       Percent : Glib.Gdouble := 1.0; 
  470.       Length  : Duration := 0.0); 
  471.    --  Zoom in or out in the canvas. 
  472.    -- 
  473.    --  Length is the length of the zooming animation. 
  474.    -- 
  475.    --  Note that one possible use for this function is to refresh the canvas 
  476.    --  and emit the "zoomed" signal, which might redraw all the items. This can 
  477.    --  be accomplished by keeping the default 1.0 value for Percent. 
  478.  
  479.    function Get_Zoom 
  480.      (Canvas : access Interactive_Canvas_Record) return Glib.Gdouble; 
  481.    --  Return the current zoom level 
  482.  
  483.    procedure Get_World_Coordinates 
  484.      (Canvas : access Interactive_Canvas_Record'Class; 
  485.       X, Y   : out Glib.Gdouble; 
  486.       Width  : out Glib.Gdouble; 
  487.       Height : out Glib.Gdouble); 
  488.    --  Return the world coordinates of Canvas. 
  489.  
  490.    --------------------- 
  491.    -- Layout of items -- 
  492.    --------------------- 
  493.  
  494.    type Layout_Algorithm is access procedure 
  495.      (Canvas          : access Interactive_Canvas_Record'Class; 
  496.       Graph           : Glib.Graphs.Graph; 
  497.       Force           : Boolean; 
  498.       Vertical_Layout : Boolean); 
  499.    --  A general layout algorithm. It should compute the position of all the 
  500.    --  vertices of the graph, and set them directly in the graph itself. 
  501.    --  Note: all the vertices in the graph are of type Canvas_Item_Record'Class 
  502.    --  and you should use that to set the coordinates through a call to 
  503.    --  Move_To. 
  504.    -- 
  505.    --  Algorithms are encouraged to preserve the current layout as much as 
  506.    --  possible, taking into account items that have been moved manually by 
  507.    --  the user, so that the latter can preserver his mental map of the graph. 
  508.    --  However, if Force is set to True, then the whole layout should be 
  509.    --  recomputed as if all items had just been inserted. 
  510.    -- 
  511.    --  Items that have just been inserted in the graph, but whose position has 
  512.    --  never been computed, are set at coordinates (Gint'First, Gint'First). 
  513.    --  Check the result of Get_Coord. 
  514.    -- 
  515.    --  This function doesn't need to align items, this is done automatically by 
  516.    --  the canvas if necessary. 
  517.  
  518.    procedure Set_Layout_Algorithm 
  519.      (Canvas    : access Interactive_Canvas_Record; 
  520.       Algorithm : Layout_Algorithm); 
  521.    --  Set the layout algorithm to use to compute the position of the items. 
  522.    --  Algorithm mustn't be null. 
  523.  
  524.    procedure Default_Layout_Algorithm 
  525.      (Canvas          : access Interactive_Canvas_Record'Class; 
  526.       Graph           : Glib.Graphs.Graph; 
  527.       Force           : Boolean; 
  528.       Vertical_Layout : Boolean); 
  529.    --  The default algorithm used in the canvas. 
  530.    --  Basically, items are put next to each other, unless there is a link 
  531.    --  between two items. In that case, the second item is put below the first, 
  532.    --  as space allows. 
  533.  
  534.    procedure Set_Auto_Layout 
  535.      (Canvas      : access Interactive_Canvas_Record; 
  536.       Auto_Layout : Boolean); 
  537.    --  If Auto_Layout is true, then every time an item is inserted in the 
  538.    --  canvas, the layout algorithm is called. If set to False, it is the 
  539.    --  responsability of the caller to call Layout below to force a 
  540.    --  recomputation of the layout, preferably after inserting a number of 
  541.    --  items. 
  542.  
  543.    procedure Set_Layout_Orientation 
  544.      (Canvas          : access Interactive_Canvas_Record; 
  545.       Vertical_Layout : Boolean := False); 
  546.    --  Specify the layout orientation to use for this canvas. The setting is 
  547.    --  passed as a parameter to the layout algorithm 
  548.  
  549.    procedure Layout 
  550.      (Canvas : access Interactive_Canvas_Record; 
  551.       Force  : Boolean := False); 
  552.    --  Recompute the layout of the canvas. 
  553.    --  Force can be used to control the layout algorithm, as described above 
  554.    --  for Layout_Algorithm. 
  555.  
  556.    ----------- 
  557.    -- Links -- 
  558.    ----------- 
  559.  
  560.    procedure Configure 
  561.      (Link  : access Canvas_Link_Record; 
  562.       Arrow : Arrow_Type := End_Arrow; 
  563.       Descr : Glib.UTF8_String := ""); 
  564.    --  Configure a link. 
  565.    --  The link is an oriented bound between two items on the canvas. 
  566.    --  If Descr is not the empty string, it will be displayed in the middle 
  567.    --  of the link, and should indicate what the link means. 
  568.    --  Arrow indicates whether some arrows should be printed as well. 
  569.  
  570.    function Get_Descr 
  571.      (Link : access Canvas_Link_Record) return Glib.UTF8_String; 
  572.    --  Return the description for the link, or "" if there is none 
  573.  
  574.    function Get_Arrow_Type 
  575.      (Link : access Canvas_Link_Record) return Arrow_Type; 
  576.    --  Return the location of the arrows on Link 
  577.  
  578.    procedure Set_Src_Pos 
  579.      (Link : access Canvas_Link_Record; X_Pos, Y_Pos : Glib.Gfloat := 0.5); 
  580.    --  Set the position of the link's attachment in its source item. 
  581.    --  X_Pos and Y_Pos should be given between 0.0 and 1.0 (from left to right 
  582.    --  or top to bottom).. 
  583.    --  By default, all links are considered to be attached to the center of 
  584.    --  items. However, in some cases it is more convenient to attach it to a 
  585.    --  specific part of the item. For instance, you can force a link to always 
  586.    --  start from the top of the item by setting Y_Pos to 0.0. 
  587.  
  588.    procedure Set_Dest_Pos 
  589.      (Link : access Canvas_Link_Record; X_Pos, Y_Pos : Glib.Gfloat := 0.5); 
  590.    --  Same as Set_Src_Pos for the destination item 
  591.  
  592.    procedure Get_Src_Pos 
  593.      (Link : access Canvas_Link_Record; X, Y : out Glib.Gfloat); 
  594.    --  Return the attachment position of the link along its source item 
  595.  
  596.    procedure Get_Dest_Pos 
  597.      (Link : access Canvas_Link_Record; X, Y : out Glib.Gfloat); 
  598.    --  Return the attachment position of the link along its destination item 
  599.  
  600.    function Has_Link 
  601.      (Canvas   : access Interactive_Canvas_Record; 
  602.       From, To : access Canvas_Item_Record'Class; 
  603.       Name     : Glib.UTF8_String := "") return Boolean; 
  604.    --  Test whether there is a link from From to To, with the same name. 
  605.    --  If Name is the empty string "", then no check is done on the name, 
  606.    --  and True if returned if there is any link between the two items. 
  607.  
  608.    procedure Add_Link 
  609.      (Canvas : access Interactive_Canvas_Record; 
  610.       Link   : access Canvas_Link_Record'Class; 
  611.       Src    : access Canvas_Item_Record'Class; 
  612.       Dest   : access Canvas_Item_Record'Class; 
  613.       Arrow  : Arrow_Type := End_Arrow; 
  614.       Descr  : Glib.UTF8_String := ""); 
  615.    --  Add Link in the canvas. This connects the two items Src and Dest. 
  616.    --  Simpler procedure to add a standard link. 
  617.    --  This takes care of memory allocation, as well as adding the link to 
  618.    --  the canvas. 
  619.  
  620.    procedure Remove_Link 
  621.      (Canvas : access Interactive_Canvas_Record; 
  622.       Link   : access Canvas_Link_Record'Class); 
  623.    --  Remove a link from the canvas. 
  624.    --  It also destroys the link itself, and free the memory allocated to it. 
  625.    --  Nothing is done if Link does not belong to canvas. 
  626.  
  627.    type Link_Processor is access function 
  628.      (Canvas : access Interactive_Canvas_Record'Class; 
  629.       Link   : access Canvas_Link_Record'Class) return Boolean; 
  630.  
  631.    procedure For_Each_Link 
  632.      (Canvas   : access Interactive_Canvas_Record; 
  633.       Execute  : Link_Processor; 
  634.       From, To : Canvas_Item := null); 
  635.    --  Execute an action on each of the links contained in the canvas. 
  636.    --  If Execute returns False, we stop traversing the list of links. 
  637.    --  It is safe to remove the link from the list in Link_Processor. 
  638.    -- 
  639.    --  (From, To) can be used to limit what links are looked for. 
  640.    -- 
  641.    --  ??? Would be nicer to give direct access to the Graph iterators 
  642.  
  643.    procedure Destroy (Link : in out Canvas_Link_Record); 
  644.    --  Method called every time a link is destroyed. You should override this 
  645.    --  if you define your own link types. 
  646.    --  Note that the link might already have been removed from the canvas 
  647.    --  when this subprogram is called. 
  648.    --  This shouldn't free the link itself, only its fields. 
  649.  
  650.    ------------------- 
  651.    -- Drawing links -- 
  652.    ------------------- 
  653.    --  Drawing of links can be controlled at several levels: 
  654.    --    - Redefining Update_Links gives control at the canvas level. This can 
  655.    --      be used to implement routing algorithms for the links where the 
  656.    --      routes must be computed before any link is actually drawn (otherwise 
  657.    --      it is better to redefine Draw_Link). It can also be used to control 
  658.    --      in what order the links should be drawn. 
  659.    --    - Redefining Draw_Link gives the opportunity to draw links any way you 
  660.    --      need (several bends, ...). It can be used to control the routing of 
  661.    --      this specific link, for routing algorithms that only rely on the 
  662.    --      items layout and not on other links. Otherwise see Update_Links. 
  663.    --    - Redefining Draw_Straight_Line if slightly lower-level. This is 
  664.    --      called by the default Draw_Link procedure, once the ends of the 
  665.    --      links have been computed. 
  666.  
  667.    procedure Update_Links 
  668.      (Canvas         : access Interactive_Canvas_Record; 
  669.       Cr             : Cairo.Cairo_Context; 
  670.       Invert_Mode    : Boolean; 
  671.       From_Selection : Boolean); 
  672.    --  Redraw all the links in the canvas, after the items have been laid out. 
  673.    -- 
  674.    --  If From_Selection is true, then only the links to or from one of the 
  675.    --  selected items need to be drawn. 
  676.  
  677.    procedure Draw_Link 
  678.      (Canvas      : access Interactive_Canvas_Record'Class; 
  679.       Link        : access Canvas_Link_Record; 
  680.       Cr          : Cairo.Cairo_Context; 
  681.       Edge_Number : Glib.Gint; 
  682.       Show_Annotation : Boolean := True); 
  683.    --  Redraw the link on the canvas. 
  684.    --  Note that this is a primitive procedure of Link, not of Canvas, and thus 
  685.    --  can easily be overrided for specific links. The default version draws 
  686.    --  either straight or arc links (the latter when there are multiple links 
  687.    --  between two given items). 
  688.    --  This function shouldn't be called if one of the two ends of the link is 
  689.    --  invisible. 
  690.    -- 
  691.    --  Cr is the Cairo_Context that is used to draw the link. 
  692.    --  The link is drawn using the current cairo brush, so if you need to 
  693.    --  specify some particular color, you can do it directly in the 
  694.    --  Cairo_Context 
  695.    -- 
  696.    --  Edge_Number indicates the index of link in the list of links that join 
  697.    --  the same source to the same destination. It should be used so that two 
  698.    --  links do not overlap (for instance, the default is to draw the first 
  699.    --  link straight, and the others as arcs). 
  700.  
  701.    type Item_Side is (East, West, North, South); 
  702.    --  Each side of an item, along its rectangle bounding box 
  703.  
  704.    procedure Clip_Line 
  705.      (Src   : access Canvas_Item_Record; 
  706.       Canvas : access Interactive_Canvas_Record'Class; 
  707.       To_X  : Glib.Gint; 
  708.       To_Y  : Glib.Gint; 
  709.       X_Pos : Glib.Gfloat; 
  710.       Y_Pos : Glib.Gfloat; 
  711.       Side  : out Item_Side; 
  712.       X_Out : out Glib.Gint; 
  713.       Y_Out : out Glib.Gint); 
  714.    --  Clip the line that goes from Src at pos (X_Pos, Y_Pos) to (To_X, To_Y) 
  715.    --  in world coordinates. 
  716.    --  The intersection between that line and the border of Rect is returned 
  717.    --  in (X_Out, Y_Out). The result should be in world coordinates. 
  718.    --  X_Pos and Y_Pos have the same meaning as Src_X_Pos and Src_Y_Pos in the 
  719.    --  link record. 
  720.    --  This procedure is called when computing the position for the links 
  721.    --  within the default Draw_Link procedure. The default implementation only 
  722.    --  works with rectangular items. The computed coordinates are then passed 
  723.    --  on directly to Draw_Straight_Line. 
  724.  
  725.    procedure Draw_Straight_Line 
  726.      (Link      : access Canvas_Link_Record; 
  727.       Cr        : Cairo.Cairo_Context; 
  728.       Src_Side  : Item_Side; 
  729.       X1, Y1    : Glib.Gdouble; 
  730.       Dest_Side : Item_Side; 
  731.       X2, Y2    : Glib.Gdouble); 
  732.    --  Draw a straight link between two points. This could be overriden if you 
  733.    --  need to draw an something along the link. 
  734.    --  The links goes from (Src, X1, Y1) to (Dest, X2, Y2), in canvas 
  735.    --  coordinates. The coordinates have already been clipped so that they do 
  736.    --  not override the item. 
  737.  
  738.    --------------- 
  739.    -- Selection -- 
  740.    --------------- 
  741.  
  742.    procedure Clear_Selection (Canvas : access Interactive_Canvas_Record); 
  743.    --  Clear the list of currently selected items. 
  744.  
  745.    procedure Add_To_Selection 
  746.      (Canvas : access Interactive_Canvas_Record; 
  747.       Item   : access Canvas_Item_Record'Class); 
  748.    --  Add Item to the selection.  This is only meaningful during a drag 
  749.    --  operation (ie during a button press and the matching button 
  750.    --  release). Item will be moved at the same time that the selection is 
  751.    --  moved. 
  752.    --  Item is not added again if it is already in the selection. 
  753.    --  This function can be called from the Button_Click subprogram to force 
  754.    --  moving items. 
  755.    --  This emits the "item_selected" signal. 
  756.  
  757.    procedure Remove_From_Selection 
  758.      (Canvas : access Interactive_Canvas_Record; 
  759.       Item   : access Canvas_Item_Record'Class); 
  760.    --  Remove Item from the selection. 
  761.    --  This emits the "item_unselected" signal. 
  762.  
  763.    procedure Select_All (Canvas : access Interactive_Canvas_Record); 
  764.    --  Select all the Item in the canvas. 
  765.  
  766.    function Is_Selected 
  767.      (Canvas : access Interactive_Canvas_Record; 
  768.       Item   : access Canvas_Item_Record'Class) return Boolean; 
  769.    --  Return True if the item is currently selected 
  770.  
  771.    ------------------------ 
  772.    -- Items manipulation -- 
  773.    ------------------------ 
  774.  
  775.    function Canvas 
  776.      (Item : access Canvas_Item_Record) return Interactive_Canvas; 
  777.    --  Retrieve the canvas this item is attached to, or null if it does not 
  778.    --  belong to a canvas. 
  779.  
  780.    procedure Selected 
  781.      (Item        : access Canvas_Item_Record; 
  782.       Canvas      : access Interactive_Canvas_Record'Class; 
  783.       Is_Selected : Boolean); 
  784.    --  Called when the item is selected or unselected. 
  785.    --  The default is to do nothing. 
  786.  
  787.    function Point_In_Item 
  788.      (Item : access Canvas_Item_Record; 
  789.       X, Y : Glib.Gint) return Boolean; 
  790.    --  This function should return True if (X, Y) is inside the item. X and Y 
  791.    --  are in world coordinates. 
  792.    --  This function is meant to be overriden for non-rectangular items, since 
  793.    --  the default behavior works for rectangular items. 
  794.    --  This function is never called for invisible items 
  795.  
  796.    procedure Set_Screen_Size 
  797.      (Item   : access Canvas_Item_Record; 
  798.       Width  : Glib.Gint; 
  799.       Height : Glib.Gint); 
  800.    --  Set the size of bounding box for the item in world coordinates. 
  801.    --  The item itself needn't occupy the whole area of this bounding box, 
  802.    --  see Point_In_Item. 
  803.    --  You need to redraw the item, and call Item_Updated to force the canvas 
  804.    --  to refresh the screen. 
  805.  
  806.    procedure Draw_Selected 
  807.      (Item : access Canvas_Item_Record; 
  808.       Cr   : Cairo.Cairo_Context); 
  809.    --  Draws a selected item. By default, this adds a semi-transparent overlay 
  810.    --  above the item, drawn using the below call to Draw 
  811.  
  812.    procedure Draw 
  813.      (Item : access Canvas_Item_Record; 
  814.       Cr   : Cairo.Cairo_Context) is abstract; 
  815.    --  This subprogram, that must be overridden, should draw the item on 
  816.    --  Cr. The Item is drawn from coordinates (0,0), and does not need to take 
  817.    --  care of the zoom level. 
  818.    --  If you need to change the contents of the item, you should call 
  819.    --  Item_Updated after having done the drawing. 
  820.  
  821.    procedure Destroy (Item : in out Canvas_Item_Record); 
  822.    --  Free the memory occupied by the item (not the item itself). You should 
  823.    --  override this function if you define your own widget type, but always 
  824.    --  call the parent's Destroy subprogram. 
  825.  
  826.    function On_Button_Click 
  827.      (Item  : access Canvas_Item_Record; 
  828.       Event : Gdk.Event.Gdk_Event_Button) return Boolean; 
  829.    --  Function called whenever mouse events occured. 
  830.    --  The following mouse events may be received: 
  831.    --    Mouse_Press, 
  832.    --    Motion_Notify 
  833.    --      (only once the mouse is pressed, and On_Button_Click returned True), 
  834.    --    Mouse_Release 
  835.    --      (only once the mouse is pressed, and On_Button_Click returned True), 
  836.    --  Returns whether the event was handled or not. 
  837.    -- 
  838.    --  The coordinates (X, Y) in the Event are relative to the top-left corner 
  839.    --  of Item. 
  840.  
  841.    function Get_Coord 
  842.      (Item : access Canvas_Item_Record) 
  843.       return Cairo.Region.Cairo_Rectangle_Int; 
  844.    --  Return the coordinates and size of the bounding box for item, in world 
  845.    --  coordinates. 
  846.    --  If the item has never been resized, it initially has a width and height 
  847.    --  of 1. 
  848.  
  849.    procedure Set_Visibility 
  850.      (Item    : access Canvas_Item_Record; 
  851.       Visible : Boolean); 
  852.    --  Set the visibility status of the item. An invisible item will not be 
  853.    --  visible on the screen, and will not take part in the computation of the 
  854.    --  the scrollbars for the canvas. 
  855.    --  The canvas is not refreshed (this is your responsibility to do it after 
  856.    --  you have finished doing all the modifications). 
  857.  
  858.    function Is_Visible (Item : access Canvas_Item_Record) return Boolean; 
  859.    --  Return True if the item is currently visible 
  860.  
  861.    function Is_From_Auto_Layout 
  862.      (Item : access Canvas_Item_Record) return Boolean; 
  863.    --  Return True if the current location of the item is the result from the 
  864.    --  auto layout algorithm. 
  865.    --  False is returned if the item was moved manually by the user. 
  866.  
  867.    -------------------- 
  868.    -- Buffered items -- 
  869.    -------------------- 
  870.  
  871.    type Buffered_Item_Record is new Canvas_Item_Record with private; 
  872.    type Buffered_Item is access all Buffered_Item_Record'Class; 
  873.    --  A widget that has a double-buffer associated. You should use this one 
  874.    --  when drawing items can take a long time, or you do not want to handle 
  875.    --  the zoom yourself. 
  876.    --  You only need to update the contents of the double pixmap when the 
  877.    --  contents of the item changes, since all the drawing and zooming is 
  878.    --  taken care of automatically. Once the drawing is done, call Item_Updated 
  879.    --  to force the canvas to refresh the screen. 
  880.    --  This buffered_item is meant to handle rectangular items. However, it can 
  881.    --  be used for polygonal items by overriding Draw. The new version should 
  882.    --  set the clip mask for the GC, then call Draw for the buffered item, and 
  883.    --  finally reset the clip mask. The clip mask must take into account the 
  884.    --  current zoom level. 
  885.  
  886.    function Surface (Item : access Buffered_Item_Record) 
  887.       return Cairo.Cairo_Surface; 
  888.    --  Return the double-buffer. 
  889.  
  890.    ------------- 
  891.    -- Signals -- 
  892.    ------------- 
  893.  
  894.    --  <signals> 
  895.    --  The following new signals are defined for this widget: 
  896.    -- 
  897.    --  - "background_click" 
  898.    --  procedure Handler (Canvas : access Interactive_Canvas_Record'Class; 
  899.    --                     Event  : Gdk.Event.Gdk_Event); 
  900.    -- 
  901.    --  Called every time the user clicks in the background (ie not on an item, 
  902.    --  or On_Button_Click would be called). 
  903.    --  This is called both on Button_Release and Button_Press events. 
  904.    --  The coordinates (X, Y) in the Event are relative to the top-left corner 
  905.    --  of Canvas. 
  906.    -- 
  907.    --  - "item_selected" 
  908.    --  procedure Handler (Canvas : access Interactive_Canvas_Record'Class; 
  909.    --                     Item   : Canvas_Item); 
  910.    -- 
  911.    --  Emitted when the user has clicked on an item to select it, ie before any 
  912.    --  drag even has occured. This is a good time to add other items to the 
  913.    --  selection if you need. At thee same time, the primitive operation 
  914.    --  Selected is called for the item. 
  915.    -- 
  916.    --  - "item_unselected" 
  917.    --  procedure Handler (Canvas : access Interactive_Canvas_Record'Class; 
  918.    --                     Item   : Canvas_Item); 
  919.    -- 
  920.    --  Emitted when the Item was unselected. At the same time, the primitive 
  921.    --  operation Selected is called for the item. 
  922.    -- 
  923.    --  - "item_moved" 
  924.    --  procedure Handler (Canvas : access Interactive_Canvas_Record'Class; 
  925.    --                     Item   : Canvas_Item); 
  926.    -- 
  927.    --  Emitted when Item has been moved. New coordinates have been assigned to 
  928.    --  Item. However, the canvas hasn't been refreshed yet. This signal might 
  929.    --  be called multiple time when the user finishes a drag action, in case 
  930.    --  there were several selected items. 
  931.    -- 
  932.    --  - "zoomed" 
  933.    --  procedure Handler (Canvas : access Interactive_Canvas_Record'Class); 
  934.    -- 
  935.    --  Emitted when the canvas has been zoomed in or out. You do not need to 
  936.    --  redraw the items yourself, since this will be handled by calls to Draw 
  937.    -- 
  938.    --  - "set_scroll_adjustments" 
  939.    --  procedure Handler (Canvas : access Interactive_Canvas_Record'Class); 
  940.    -- 
  941.    --  Emitted when the canvas has scrolled. 
  942.    -- 
  943.    --  </signals> 
  944.  
  945.    Signal_Background_Click       : constant Glib.Signal_Name := 
  946.                                      "background_click"; 
  947.    Signal_Item_Selected          : constant Glib.Signal_Name := 
  948.                                      "item_selected"; 
  949.    Signal_Item_Unselected        : constant Glib.Signal_Name := 
  950.                                      "item_unselected"; 
  951.    Signal_Item_Moved             : constant Glib.Signal_Name := 
  952.                                      "item_moved"; 
  953.    Signal_Zoomed                 : constant Glib.Signal_Name := 
  954.                                      "zoomed"; 
  955.    Signal_Set_Scroll_Adjustments : constant Glib.Signal_Name := 
  956.                                      "set_scroll_adjustments"; 
  957.  
  958. private 
  959.  
  960.    type String_Access is access Glib.UTF8_String; 
  961.  
  962.    type Canvas_Link_Record is new Glib.Graphs.Edge with record 
  963.       Descr      : String_Access; 
  964.       Arrow      : Arrow_Type := End_Arrow; 
  965.  
  966.       Src_X_Pos  : Glib.Gfloat := 0.5; 
  967.       Src_Y_Pos  : Glib.Gfloat := 0.5; 
  968.       Dest_X_Pos : Glib.Gfloat := 0.5; 
  969.       Dest_Y_Pos : Glib.Gfloat := 0.5; 
  970.       --  Position of the link's attachment in each of the src and dest items. 
  971.    end record; 
  972.  
  973.    type Interactive_Canvas_Record is new 
  974.      Gtk.Layout.Gtk_Layout_Record 
  975.    with record 
  976.       Children          : Glib.Graphs.Graph; 
  977.       World_X, World_Y  : Glib.Gdouble; 
  978.       --  The World coordinates at canvas (0,0) 
  979.  
  980.       Background_Color  : Gdk.RGBA.Gdk_RGBA := Gdk.RGBA.White_RGBA; 
  981.  
  982.       Layout            : Layout_Algorithm := Default_Layout_Algorithm'Access; 
  983.       Auto_Layout       : Boolean := True; 
  984.       Vertical_Layout   : Boolean := False; 
  985.       --  The algorithm to use when laying out items on the canvas. 
  986.  
  987.       World_X_At_Click  : Glib.Gdouble := 0.0; 
  988.       World_Y_At_Click  : Glib.Gdouble := 0.0; 
  989.       --  Coordinates of the last button_press event in the canvas. 
  990.       --  These are world-coordinates, so that even if the canvas is scrolled 
  991.       --  they remain valid 
  992.  
  993.       Selected_Count    : Natural := 0; 
  994.       --  Number of selected items 
  995.  
  996.       Offset_X_World    : Glib.Gdouble := 0.0; 
  997.       Offset_Y_World    : Glib.Gdouble := 0.0; 
  998.       --  How much world-coordinates have we moved the mouse since the last 
  999.       --  button press event ? 
  1000.  
  1001.       Mouse_Has_Moved   : Boolean; 
  1002.       --  True if mouse has moved while the button was clicked. This is used 
  1003.       --  to distinguish between item motion and item selection. 
  1004.  
  1005.       Background_Press  : Boolean; 
  1006.       --  True if the mouse press event occured in the background 
  1007.  
  1008.       Item_Press        : Canvas_Item; 
  1009.       --  Points to the canvas item that received the press event 
  1010.  
  1011.       Show_Item                    : Canvas_Item; 
  1012.       Show_Canvas_X, Show_Canvas_Y : Glib.Gdouble; 
  1013.       --  The item that should be made visible when the canvas is resized. 
  1014.       --  This is required since the canvas doesn't necessarily have a size yet 
  1015.       --  when Show_Item() is called the first time. 
  1016.  
  1017.       Grid_Size         : Glib.Guint := Default_Grid_Size; 
  1018.       --  The current number of pixels between each dot of the grid. If this 
  1019.       --  is strictly below 2, the grid is not drawn. 
  1020.  
  1021.       Arc_Link_Offset   : Glib.Gint := Default_Arc_Link_Offset; 
  1022.       Arrow_Angle       : Glib.Gdouble; 
  1023.       Arrow_Length      : Glib.Gint := Default_Arrow_Length; 
  1024.       Motion_Threshold  : Glib.Gdouble := Default_Motion_Threshold; 
  1025.       Align_On_Grid     : Boolean := False; 
  1026.  
  1027.       Black_Color     : Gdk.Color.Gdk_Color := Gdk.Color.Null_Color; 
  1028.       Sel_Color       : Gdk.Color.Gdk_Color := Gdk.Color.Null_Color; 
  1029.  
  1030.       Annotation_Layout : Pango.Layout.Pango_Layout; 
  1031.       --  Layout used to draw the annotations 
  1032.  
  1033.       Scrolling_Timeout_Id : Glib.Main.G_Source_Id := 0; 
  1034.       Scrolling_Device     : Gdk.Device.Gdk_Device; 
  1035.  
  1036.       Orthogonal_Links : Boolean := False; 
  1037.       --  True if the links should be orthogonal 
  1038.  
  1039.       Surround_Box_Scroll : Glib.Gdouble; 
  1040.       --  Amount of scrolling for each step while the cursor is left in the 
  1041.       --  surrounding box. 
  1042.  
  1043.       Zoom                : Glib.Gdouble := 1.0; 
  1044.       --  Zoom level in percent (100% is normal size) 
  1045.  
  1046.       Initial_Zoom        : Glib.Gdouble := 1.0; 
  1047.       Target_Zoom         : Glib.Gdouble := 1.0; 
  1048.       Zoom_Duration       : Duration := 0.0; 
  1049.       Zoom_Start          : Ada.Calendar.Time; 
  1050.       Zoom_X              : Glib.Gdouble := 0.0; 
  1051.       Zoom_Y              : Glib.Gdouble := 0.0; 
  1052.       --  Variables used while smooth-scrolling the canvas 
  1053.  
  1054.       Freeze           : Boolean := False; 
  1055.    end record; 
  1056.  
  1057.    type Canvas_Item_Record is abstract new Glib.Graphs.Vertex with record 
  1058.       Canvas           : Interactive_Canvas := null; 
  1059.       Coord            : aliased Cairo.Region.Cairo_Rectangle_Int := 
  1060.         (0, 0, 0, 0); 
  1061.       --  This is the bounding box of the item 
  1062.  
  1063.       Visible          : Boolean := True; 
  1064.       Selected         : Boolean := False; 
  1065.  
  1066.       From_Auto_Layout : Boolean := True; 
  1067.       --  True if the item's current location is the result of the automatic 
  1068.       --  layout algorithm. 
  1069.    end record; 
  1070.  
  1071.    type Buffered_Item_Record is new Canvas_Item_Record with record 
  1072.       Pixmap : Cairo.Cairo_Surface := Cairo.Null_Surface; 
  1073.    end record; 
  1074.  
  1075.    procedure Set_Screen_Size 
  1076.      (Item   : access Buffered_Item_Record; 
  1077.       Width, Height  : Glib.Gint); 
  1078.    --  See documentation from inherited subprogram 
  1079.  
  1080.    procedure Draw 
  1081.      (Item : access Buffered_Item_Record; 
  1082.       Cr   : Cairo.Cairo_Context); 
  1083.    --  Draw the item's double-buffer onto Dest. 
  1084.  
  1085.    procedure Destroy (Item : in out Buffered_Item_Record); 
  1086.    --  Free the double-buffer allocated for the item 
  1087.  
  1088.    type Item_Iterator is record 
  1089.       Vertex            : Glib.Graphs.Vertex_Iterator; 
  1090.       Edge              : Glib.Graphs.Edge_Iterator; 
  1091.       Linked_From_Or_To : Canvas_Item; 
  1092.       Selected_Only     : Boolean; 
  1093.    end record; 
  1094.  
  1095.    pragma Inline (Get_Arrow_Type); 
  1096.  
  1097. end Gtkada.Canvas; 
  1098.  
  1099. --  <example> 
  1100. --  --  The following example shows a possible Draw_Background procedure, 
  1101. --  --  that draws a background image on the canvas's background. It fully 
  1102. --  --  handles zooming and tiling of the image. Note that drawing a large 
  1103. --  --  image will dramatically slow down the performances. 
  1104. -- 
  1105. --  Bg_Image : constant String := "my_background.png"; 
  1106. -- 
  1107. --  procedure Draw_Background 
  1108. --    (Canvas : access Image_Canvas_Record; 
  1109. --     Cr     : Cairo.Cairo_Context) 
  1110. --  is 
  1111. --     Surface    : Cairo.Cairo_Surface; 
  1112. --     Background : Cairo.Cairo_Pattern; 
  1113. --  begin 
  1114. --     Surface := Cairo.Png.Create_From_Png (Bg_Image); 
  1115. --     Background := Cairo.Pattern.Create_For_Surface (Surface); 
  1116. --     Cairo.Pattern.Set_Extend (Canvas.Background, Cairo_Extend_Repeat); 
  1117. --     Destroy (Surface); 
  1118.  
  1119. --     Cairo.Save (Cr); 
  1120. --     Cairo.Set_Source (Cr, Canvas.Background); 
  1121. --     Cairo.Paint (Cr); 
  1122. --     Cairo.Restore (Cr); 
  1123. --  end Draw_Background; 
  1124. --  </example>