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