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