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