1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --      Copyright (C) 2000 E. Briot, J. Brobecker and A. Charlet     -- 
  5. --                Copyright (C) 2000-2006 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. --  A Gtk_Plot_Canvas is a special kind of drawing area used with Gtk_Plot 
  27. --  widgets. 
  28. --  It provides drag-and-drop capabilities for the texts, legends, points... 
  29. --  available in a Gtk_Plot. 
  30. --  Note that this widget is specifically designed for Gtk_Plot widgets, and 
  31. --  won't provide any other capability for other kinds of widgets. 
  32. -- 
  33. --  Like any child of Gtk_Layout, this widget can have an almost unlimited 
  34. --  size for its children, and provides scrolling. 
  35. --  </description> 
  36. --  <c_version>gtkextra 2.1.1</c_version> 
  37. --  <group>Plotting Data</group> 
  38.  
  39. with Gdk; 
  40. with Gtk.Extra.Plot_Data; 
  41. with Gtk.Fixed; 
  42. with Gtk.Object; 
  43. with Gdk.Color; 
  44.  
  45. package Gtk.Extra.Plot_Canvas is 
  46.  
  47.    type Gtk_Plot_Canvas_Record is new Gtk.Fixed.Gtk_Fixed_Record with private; 
  48.    type Gtk_Plot_Canvas is access all Gtk_Plot_Canvas_Record'Class; 
  49.  
  50.    type Gtk_Plot_Canvas_Child_Record is 
  51.      new Gtk.Object.Gtk_Object_Record with private; 
  52.    type Gtk_Plot_Canvas_Child is access all Gtk_Plot_Canvas_Child_Record'Class; 
  53.  
  54.    ---------------- 
  55.    -- Enum types -- 
  56.    ---------------- 
  57.  
  58.    type Plot_Canvas_Action is 
  59.      (Action_Inactive, 
  60.       Action_Selection, 
  61.       Action_Drag, 
  62.       Action_Resize); 
  63.    --  The action being performed on the canvas. 
  64.    pragma Convention (C, Plot_Canvas_Action); 
  65.  
  66.    type Plot_Canvas_Flag is new Gint; 
  67.    Frozen     : constant Plot_Canvas_Flag; 
  68.    Can_Move   : constant Plot_Canvas_Flag; 
  69.    Can_Resize : constant Plot_Canvas_Flag; 
  70.  
  71.    type Plot_Canvas_Selection is 
  72.      (Select_None, 
  73.       Select_Markers, 
  74.       Select_Target); 
  75.    pragma Convention (C, Plot_Canvas_Selection); 
  76.  
  77.    type Plot_Canvas_Pos is 
  78.      (Canvas_Out, 
  79.       Canvas_In, 
  80.       Canvas_Left, 
  81.       Canvas_Right, 
  82.       Canvas_Top, 
  83.       Canvas_Bottom, 
  84.       Canvas_Top_Left, 
  85.       Canvas_Top_Right, 
  86.       Canvas_Bottom_Left, 
  87.       Canvas_Bottom_Right); 
  88.    --  The position of the items in the canvas. 
  89.    pragma Convention (C, Plot_Canvas_Pos); 
  90.  
  91.    type Plot_Canvas_Selection_Mode is 
  92.      (Select_Click_1, 
  93.       Select_Click_2); 
  94.    pragma Convention (C, Plot_Canvas_Selection_Mode); 
  95.  
  96.    ------------------------------------------ 
  97.    -- Creating and manipulating the canvas -- 
  98.    ------------------------------------------ 
  99.  
  100.    procedure Gtk_New 
  101.      (Widget        : out Gtk_Plot_Canvas; 
  102.       Width         : Gint; 
  103.       Height        : Gint; 
  104.       Magnification : Gdouble := 1.0); 
  105.    --  Create a new Gtk_Plot_Canvas, with a specific screen size. 
  106.    --  Since the widget can have an unlimited internal size, it does not try 
  107.    --  to set its size to accommodate all of its children. 
  108.  
  109.    procedure Initialize 
  110.      (Widget        : access Gtk_Plot_Canvas_Record'Class; 
  111.       Width         : Gint; 
  112.       Height        : Gint; 
  113.       Magnification : Gdouble := 1.0); 
  114.    --  Internal initialization function. 
  115.    --  See the section "Creating your own widgets" in the documentation. 
  116.  
  117.    function Get_Type return Gtk.Gtk_Type; 
  118.    --  Return the internal value associated with a Gtk_Plot_Canvas. 
  119.  
  120.    function Child_Get_Type return Gtk.Gtk_Type; 
  121.    --  Return the internal value associated with a Gtk_Plot_Canvas_Child. 
  122.  
  123.    procedure Refresh (Canvas : access Gtk_Plot_Canvas_Record); 
  124.    --  Force a refresh of the canvas on the screen. The screen is updated from 
  125.    --  the contents of the double-buffer. 
  126.  
  127.    procedure Paint (Canvas : access Gtk_Plot_Canvas_Record); 
  128.    --  Redraw each of the items included in the canvas. The painting is done 
  129.    --  in the double-buffer, and must be drawn on the screen with Refresh. 
  130.  
  131.    procedure Freeze (Canvas : access Gtk_Plot_Canvas_Record); 
  132.    --  Freeze all graphical updates to the screen. This significanly speeds up 
  133.    --  the updates to the plot 
  134.  
  135.    procedure Thaw (Canvas : access Gtk_Plot_Canvas_Record); 
  136.    --  Reactivate all graphical updates to the screen 
  137.  
  138.    procedure Grid_Set_Visible 
  139.      (Canvas  : access Gtk_Plot_Canvas_Record; 
  140.       Visible : Boolean); 
  141.    --  Indicate whether the grid should be visible or not. 
  142.  
  143.    procedure Grid_Set_Step 
  144.      (Canvas : access Gtk_Plot_Canvas_Record; 
  145.       Step   : Gdouble); 
  146.    --  Set the space between two lines of the grid. 
  147.  
  148.    procedure Grid_Set_Attributes 
  149.      (Canvas : access Gtk_Plot_Canvas_Record; 
  150.       Style  : Gtk.Extra.Plot_Data.Plot_Line_Style; 
  151.       Width  : Gint; 
  152.       Color  : Gdk.Color.Gdk_Color); 
  153.    --  Set the attributes of the grid. 
  154.  
  155.    procedure Cancel_Action (Plot_Canvas : access Gtk_Plot_Canvas_Record); 
  156.    --  Cancel the current action. 
  157.    --  This can be called in the user callbacks to ignore temporarily some of 
  158.    --  the signals below. 
  159.  
  160.    procedure Unselect (Canvas : access Gtk_Plot_Canvas_Record); 
  161.    --  Unselect the currently selected item. 
  162.  
  163.    function Get_Active_Item 
  164.      (Canvas  : access Gtk_Plot_Canvas_Record) 
  165.      return Gtk_Plot_Canvas_Child; 
  166.    --  Return the currently selected item. 
  167.  
  168.    procedure Set_Size 
  169.      (Canvas  : access Gtk_Plot_Canvas_Record; 
  170.       Width   : Gint; 
  171.       Height  : Gint); 
  172.    --  Modify the size allocated for the canvas, and the size of the pixmap 
  173.    --  the plots are displayed on. 
  174.  
  175.    procedure Set_Magnification 
  176.      (Canvas        : access Gtk_Plot_Canvas_Record; 
  177.       Magnification : Gdouble := 1.0); 
  178.    --  Changes the magnification for the canvas. 
  179.    --  1.0 is the default value. Higher values will zoom in, while lower values 
  180.    --  will zoom out. 
  181.  
  182.    procedure Set_Transparent 
  183.      (Canvas : access Gtk_Plot_Canvas_Record; Transparent : Boolean); 
  184.    --  Whether the canvas should be transparent. If Transparent is True, all 
  185.    --  background attributes are ignored 
  186.  
  187.    function Transparent 
  188.      (Canvas : access Gtk_Plot_Canvas_Record) return Boolean; 
  189.    --  Whether the canvas is currently transparent 
  190.  
  191.    procedure Set_Background 
  192.      (Canvas     : access Gtk_Plot_Canvas_Record; 
  193.       Background : Gdk.Color.Gdk_Color); 
  194.    --  Set the background color for the canvas. 
  195.  
  196.    procedure Get_Pixel 
  197.      (Canvas : access Gtk_Plot_Canvas_Record; 
  198.       Px     : Gdouble; 
  199.       Py     : Gdouble; 
  200.       X      : out Gint; 
  201.       Y      : out Gint); 
  202.    --  Convert from relative coordinates to absolute ones. 
  203.  
  204.    procedure Get_Position 
  205.      (Canvas : access Gtk_Plot_Canvas_Record; 
  206.       X      : Gint; 
  207.       Y      : Gint; 
  208.       Px     : out Gdouble; 
  209.       Py     : out Gdouble); 
  210.    --  Convert from absolute coordinates to relative ones. 
  211.  
  212.    procedure Put_Child 
  213.      (Canvas : access Gtk_Plot_Canvas_Record; 
  214.       Child  : access Gtk_Plot_Canvas_Child_Record'Class; 
  215.       X1     : Gdouble; 
  216.       Y1     : Gdouble; 
  217.       X2     : Gdouble := 0.0; 
  218.       Y2     : Gdouble := 0.0); 
  219.    --  Insert a new item in the canvas. It will occupy the area defined by 
  220.    --  the four coordinates. 
  221.    --  See the various packages Gtk.Extra.Plot_Canvas.* on how to create 
  222.    --  such children. 
  223.    --  Leaving X2 and Y2 to their default value will ensure that the child uses 
  224.    --  as much space as it needs 
  225.  
  226.    procedure Remove_Child 
  227.      (Canvas : access Gtk_Plot_Canvas_Record; 
  228.       Child  : access Gtk_Plot_Canvas_Child_Record'Class); 
  229.    --  Remove a child from the canvas 
  230.  
  231.    procedure Child_Move 
  232.      (Canvas : access Gtk_Plot_Canvas_Record; 
  233.       Child  : access Gtk_Plot_Canvas_Child_Record'Class; 
  234.       X1     : Gdouble; 
  235.       Y1     : Gdouble); 
  236.    --  Move an item, but does not change its size. 
  237.  
  238.    procedure Child_Move_Resize 
  239.      (Canvas : access Gtk_Plot_Canvas_Record; 
  240.       Child  : access Gtk_Plot_Canvas_Child_Record'Class; 
  241.       X1     : Gdouble; 
  242.       Y1     : Gdouble; 
  243.       X2     : Gdouble; 
  244.       Y2     : Gdouble); 
  245.    --  Move an resize an item in the canvas. 
  246.  
  247.    procedure Set_Selection 
  248.      (Child     : access Gtk_Plot_Canvas_Child_Record; 
  249.       Selection : Plot_Canvas_Selection); 
  250.  
  251.    procedure Set_Selection_Mode 
  252.      (Child     : access Gtk_Plot_Canvas_Child_Record; 
  253.       Mode      : Plot_Canvas_Selection_Mode); 
  254.  
  255.    procedure Get_Position 
  256.      (Canvas    : access Gtk_Plot_Canvas_Record; 
  257.       Child     : access Gtk_Plot_Canvas_Child_Record'Class; 
  258.       X1, Y1    : out Gdouble; 
  259.       X2, Y2    : out Gdouble); 
  260.  
  261.    --------------------- 
  262.    -- Custom children -- 
  263.    --------------------- 
  264.    --  You can insert your own items in a canvas. 
  265.    --  While the canvas will take care of moving the item, it is your 
  266.    --  responsability to provide a visual rendering for it. 
  267.  
  268.    ----------- 
  269.    -- Flags -- 
  270.    ----------- 
  271.    --  Some flags are defined for this widget. You can not access them through 
  272.    --  the usual interface in Gtk.Object.Flag_Is_Set since this widget is not 
  273.    --  part of the standard gtk+ packages. Instead, use the functions below. 
  274.    -- 
  275.    --  - "can_select" 
  276.    --    True if it is possible to select a region of the canvas 
  277.    -- 
  278.    --  - "can_select_item" 
  279.    --    True if it is possible to select any of the item on the canvas. 
  280.    -- 
  281.    --  - "can_dnd" 
  282.    --    True if it is possible to drag an item on the canvas. 
  283.    -- 
  284.  
  285.    Can_Select       : constant := 2 ** 0; 
  286.    Can_Select_Item  : constant := 2 ** 1; 
  287.    Can_Dnd          : constant := 2 ** 2; 
  288.    Dnd_Flags        : constant := Can_Select_Item + Can_Dnd; 
  289.  
  290.    function Plot_Canvas_Flag_Is_Set 
  291.      (Plot_Canvas : access Gtk_Plot_Canvas_Record; 
  292.       Flag        : in Guint16) 
  293.      return Boolean; 
  294.    --  Test whether one of the flags for a Gtk_Plot_Canvas widget or its 
  295.    --  children is set. 
  296.  
  297.    procedure Plot_Canvas_Set_Flags 
  298.      (Plot_Canvas  : access Gtk_Plot_Canvas_Record; 
  299.       Flags        : in Guint16); 
  300.    --  Set the flags for a Gtk_Plot_Canvas widget or its children. 
  301.    --  Note that the flags currently set are not touched by this function. 
  302.    --  This can only be used for the flags defined in the 
  303.    --  Gtk.Extra.Gtk_Plot_Canvas package. 
  304.  
  305.    procedure Plot_Canvas_Unset_Flags 
  306.      (Plot_Canvas  : access Gtk_Plot_Canvas_Record; 
  307.       Flags        : in Guint16); 
  308.    --  Unset the flags for a Gtk_Plot_Canvas. 
  309.  
  310.    ------------- 
  311.    -- Signals -- 
  312.    ------------- 
  313.  
  314.    --  <signals> 
  315.    --  The following new signals are defined for this widget: 
  316.    -- 
  317.    --  - "select_item" 
  318.    --    function Handler (Canvas : access Gtk_Plot_Canvas_Record'Class; 
  319.    --                      Event  : Gdk_Button_Event; 
  320.    --                      Item   : Gtk_Plot_Canvas_Child) 
  321.    --                     return Boolean; 
  322.    -- 
  323.    --    Called when an item was selected. 
  324.    --    An item can be anything, from a text to a plot 
  325.    --    When this signal is called, the item was simply selected, but not 
  326.    --    dragged. 
  327.    --    The handler should return False if the item can not be selected. 
  328.    -- 
  329.    --  - "move_item" 
  330.    --    function Handler (Canvas : access Gtk_Plot_Canvas_Record'Class; 
  331.    --                      Item   : Gtk_Plot_Canvas_Child; 
  332.    --                      New_X  : Gdouble; 
  333.    --                      New_Y  : Gdouble) 
  334.    --                     return Boolean; 
  335.    -- 
  336.    --    An item was moved on the canvas. 
  337.    --    Its coordinates have not changed yet, but if the handler returns True 
  338.    --    they will become (New_X, New_Y). If the handler returns False, 
  339.    --    nothing happens. 
  340.    -- 
  341.    --  - "resize_item" 
  342.    --    function Handler (Canvas     : access Gtk_Plot_Canvas_Record'Class; 
  343.    --                      Item       : Gtk_Plot_Canvas_Child; 
  344.    --                      New_Width  : Gdouble; 
  345.    --                      New_Height : Gdouble) 
  346.    --                     return Boolean; 
  347.    -- 
  348.    --    An item is being resized. 
  349.    --    Its size has not changed yet, but if the handler returns True 
  350.    --    it will become (New_Width, New_Height). If the handler returns False, 
  351.    --    nothing happens. 
  352.    -- 
  353.    --  - "add_item" 
  354.    --    procedure Handler (Canvas : access Gtk_Plot_Canvas_Record'Class; 
  355.    --                       Item   : Gtk_Plot_Canvas_Child); 
  356.    --    Called when a new child is added into the canvas 
  357.    -- 
  358.    --  - "delete_item" 
  359.    --    function Handler (Canvas : access Gtk_Plot_Canvas_Record'Class; 
  360.    --                      Item   : Gtk_Plot_Canvas_Child) return GBoolean; 
  361.    --    Called when an item is being removed from the canvas 
  362.    -- 
  363.    --  - "select_region" 
  364.    --    procedure Handler (Canvas : access Gtk_Plot_Canvas_Record'Class; 
  365.    --                       X_Min  : Gdouble; 
  366.    --                       Y_Min  : Gdouble; 
  367.    --                       X_Max  : Gdouble; 
  368.    --                       Y_Max  : Gdouble); 
  369.    --    A region of the canvas was selected by the user. 
  370.    -- 
  371.    --  - "changed" 
  372.    --    procedure Handler (Canvas : access Gtk_Plot_Canvas_Record'Class); 
  373.    --    Called when the contents of the canvas has changed (an item was 
  374.    --    moved interactively by the user). 
  375.    --  </signals> 
  376.  
  377. private 
  378.    type Gtk_Plot_Canvas_Record is new Gtk.Fixed.Gtk_Fixed_Record 
  379.      with null record; 
  380.    type Gtk_Plot_Canvas_Child_Record is 
  381.      new Gtk.Object.Gtk_Object_Record with null record; 
  382.    pragma Import (C, Get_Type, "gtk_plot_canvas_get_type"); 
  383.    pragma Import (C, Child_Get_Type, "gtk_plot_canvas_child_get_type"); 
  384.  
  385.    Frozen     : constant Plot_Canvas_Flag := 0; 
  386.    Can_Move   : constant Plot_Canvas_Flag := 1; 
  387.    Can_Resize : constant Plot_Canvas_Flag := 2; 
  388.  
  389. end Gtk.Extra.Plot_Canvas; 
  390.  
  391. --  Unbound 
  392. --    gtk_plot_canvas_set_pc 
  393. --    gtk_plot_canvas_set_line_attributes