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