1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  The Gdk.Device.Gdk_Device object represents a single input device, such as 
  26. --  a keyboard, a mouse, a touchpad, etc. 
  27. -- 
  28. --  See the Gdk.Device_Manager.Gdk_Device_Manager documentation for more 
  29. --  information about the various kinds of master and slave devices, and their 
  30. --  relationships. 
  31. -- 
  32. --  </description> 
  33. pragma Ada_2005; 
  34.  
  35. pragma Warnings (Off, "*is already use-visible*"); 
  36. with Gdk;                     use Gdk; 
  37. with Gdk.Display;             use Gdk.Display; 
  38. with Gdk.Event;               use Gdk.Event; 
  39. with Gdk.Screen;              use Gdk.Screen; 
  40. with Gdk.Types;               use Gdk.Types; 
  41. with Glib;                    use Glib; 
  42. with Glib.Generic_Properties; use Glib.Generic_Properties; 
  43. with Glib.Glist;              use Glib.Glist; 
  44. with Glib.Object;             use Glib.Object; 
  45. with Glib.Properties;         use Glib.Properties; 
  46.  
  47. package Gdk.Device is 
  48.  
  49.    type Gdk_Device_Record is new GObject_Record with null record; 
  50.    type Gdk_Device is access all Gdk_Device_Record'Class; 
  51.  
  52.    type Gdk_Device_Type is ( 
  53.       Gdk_Device_Type_Master, 
  54.       Gdk_Device_Type_Slave, 
  55.       Gdk_Device_Type_Floating); 
  56.    pragma Convention (C, Gdk_Device_Type); 
  57.    --  Indicates the device type. See <link 
  58.    --  linkend="GdkDeviceManager.description">above</link> for more information 
  59.    --  about the meaning of these device types. 
  60.  
  61.    function Convert (R : Gdk.Device.Gdk_Device) return System.Address; 
  62.    function Convert (R : System.Address) return Gdk.Device.Gdk_Device; 
  63.    package Device_List is new Generic_List (Gdk.Device.Gdk_Device); 
  64.  
  65.    ---------------------------- 
  66.    -- Enumeration Properties -- 
  67.    ---------------------------- 
  68.  
  69.    package Gdk_Device_Type_Properties is 
  70.       new Generic_Internal_Discrete_Property (Gdk_Device_Type); 
  71.    type Property_Gdk_Device_Type is new Gdk_Device_Type_Properties.Property; 
  72.  
  73.    ------------------ 
  74.    -- Constructors -- 
  75.    ------------------ 
  76.  
  77.    function Get_Type return Glib.GType; 
  78.    pragma Import (C, Get_Type, "gdk_device_get_type"); 
  79.  
  80.    ------------- 
  81.    -- Methods -- 
  82.    ------------- 
  83.  
  84.    function Get_Associated_Device 
  85.       (Self : not null access Gdk_Device_Record) return Gdk_Device; 
  86.    --  Returns the associated device to Device, if Device is of type 
  87.    --  Gdk.Device.Gdk_Device_Type_Master, it will return the paired pointer or 
  88.    --  keyboard. 
  89.    --  If Device is of type Gdk.Device.Gdk_Device_Type_Slave, it will return 
  90.    --  the master device to which Device is attached to. 
  91.    --  If Device is of type Gdk.Device.Gdk_Device_Type_Floating, null will be 
  92.    --  returned, as there is no associated device. 
  93.    --  Since: gtk+ 3.0 
  94.  
  95.    function Get_Axis_Use 
  96.       (Self  : not null access Gdk_Device_Record; 
  97.        Index : Guint) return Gdk_Axis_Use; 
  98.    --  Returns the axis use for Index_. 
  99.    --  Since: gtk+ 2.20 
  100.    --  "index_": the index of the axis. 
  101.  
  102.    procedure Set_Axis_Use 
  103.       (Self  : not null access Gdk_Device_Record; 
  104.        Index : Guint; 
  105.        GUse  : Gdk_Axis_Use); 
  106.    --  Specifies how an axis of a device is used. 
  107.    --  "index_": the index of the axis 
  108.    --  "use": specifies how the axis is used 
  109.  
  110.    function Get_Device_Type 
  111.       (Self : not null access Gdk_Device_Record) return Gdk_Device_Type; 
  112.    --  Returns the device type for Device. 
  113.    --  Since: gtk+ 3.0 
  114.  
  115.    function Get_Display 
  116.       (Self : not null access Gdk_Device_Record) 
  117.        return Gdk.Display.Gdk_Display; 
  118.    --  Returns the Gdk.Display.Gdk_Display to which Device pertains. 
  119.    --  Since: gtk+ 3.0 
  120.  
  121.    function Get_Has_Cursor 
  122.       (Self : not null access Gdk_Device_Record) return Boolean; 
  123.    --  Determines whether the pointer follows device motion. 
  124.    --  Since: gtk+ 2.20 
  125.  
  126.    function Get_Mode 
  127.       (Self : not null access Gdk_Device_Record) return Gdk_Input_Mode; 
  128.    --  Determines the mode of the device. 
  129.    --  Since: gtk+ 2.20 
  130.  
  131.    function Set_Mode 
  132.       (Self : not null access Gdk_Device_Record; 
  133.        Mode : Gdk_Input_Mode) return Boolean; 
  134.    --  Sets a the mode of an input device. The mode controls if the device is 
  135.    --  active and whether the device's range is mapped to the entire screen or 
  136.    --  to a single window. 
  137.    --  "mode": the input mode. 
  138.  
  139.    function Get_N_Axes 
  140.       (Self : not null access Gdk_Device_Record) return Gint; 
  141.    --  Returns the number of axes the device currently has. 
  142.    --  Since: gtk+ 3.0 
  143.  
  144.    function Get_N_Keys 
  145.       (Self : not null access Gdk_Device_Record) return Gint; 
  146.    --  Returns the number of keys the device currently has. 
  147.    --  Since: gtk+ 2.24 
  148.  
  149.    function Get_Name 
  150.       (Self : not null access Gdk_Device_Record) return UTF8_String; 
  151.    --  Determines the name of the device. 
  152.    --  Since: gtk+ 2.20 
  153.  
  154.    function Get_Source 
  155.       (Self : not null access Gdk_Device_Record) return Gdk_Input_Source; 
  156.    --  Determines the type of the device. 
  157.    --  Since: gtk+ 2.20 
  158.  
  159.    procedure Get_State 
  160.       (Self   : not null access Gdk_Device_Record; 
  161.        Window : Gdk.Gdk_Window; 
  162.        Axes   : in out Gdouble; 
  163.        Mask   : in out Gdk.Types.Gdk_Modifier_Type); 
  164.    --  Gets the current state of a pointer device relative to Window. As a 
  165.    --  slave device coordinates are those of its master pointer, This function 
  166.    --  may not be called on devices of type Gdk.Device.Gdk_Device_Type_Slave, 
  167.    --  unless there is an ongoing grab on them, see Gdk.Device.Grab. 
  168.    --  "window": a Gdk.Gdk_Window. 
  169.    --  "axes": an array of doubles to store the values of the axes of Device 
  170.    --  in, or null. 
  171.    --  "mask": location to store the modifiers, or null. 
  172.  
  173.    function Grab 
  174.       (Self           : not null access Gdk_Device_Record; 
  175.        Window         : Gdk.Gdk_Window; 
  176.        Grab_Ownership : Gdk_Grab_Ownership; 
  177.        Owner_Events   : Boolean; 
  178.        Event_Mask     : Gdk.Event.Gdk_Event_Mask; 
  179.        Cursor         : Gdk.Gdk_Cursor; 
  180.        Time           : Guint32) return Gdk_Grab_Status; 
  181.    --  Grabs the device so that all events coming from this device are passed 
  182.    --  to this application until the device is ungrabbed with 
  183.    --  Gdk.Device.Ungrab, or the window becomes unviewable. This overrides any 
  184.    --  previous grab on the device by this client. 
  185.    --  Device grabs are used for operations which need complete control over 
  186.    --  the given device events (either pointer or keyboard). For example in 
  187.    --  GTK+ this is used for Drag and Drop operations, popup menus and such. 
  188.    --  Note that if the event mask of an X window has selected both button 
  189.    --  press and button release events, then a button press event will cause an 
  190.    --  automatic pointer grab until the button is released. X does this 
  191.    --  automatically since most applications expect to receive button press and 
  192.    --  release events in pairs. It is equivalent to a pointer grab on the 
  193.    --  window with Owner_Events set to True. 
  194.    --  If you set up anything at the time you take the grab that needs to be 
  195.    --  cleaned up when the grab ends, you should handle the 
  196.    --  Gdk.Event.Gdk_Event_Grab_Broken events that are emitted when the grab 
  197.    --  ends unvoluntarily. 
  198.    --  Since: gtk+ 3.0 
  199.    --  "window": the Gdk.Gdk_Window which will own the grab (the grab window) 
  200.    --  "grab_ownership": specifies the grab ownership. 
  201.    --  "owner_events": if False then all device events are reported with 
  202.    --  respect to Window and are only reported if selected by Event_Mask. If 
  203.    --  True then pointer events for this application are reported as normal, 
  204.    --  but pointer events outside this application are reported with respect to 
  205.    --  Window and only if selected by Event_Mask. In either mode, unreported 
  206.    --  events are discarded. 
  207.    --  "event_mask": specifies the event mask, which is used in accordance 
  208.    --  with Owner_Events. 
  209.    --  "cursor": the cursor to display while the grab is active if the device 
  210.    --  is a pointer. If this is null then the normal cursors are used for 
  211.    --  Window and its descendants, and the cursor for Window is used elsewhere. 
  212.    --  "time_": the timestamp of the event which led to this pointer grab. 
  213.    --  This usually comes from the Gdk.Event.Gdk_Event struct, though 
  214.    --  GDK_CURRENT_TIME can be used if the time isn't known. 
  215.  
  216.    procedure Set_Key 
  217.       (Self      : not null access Gdk_Device_Record; 
  218.        Index     : Guint; 
  219.        Keyval    : Guint; 
  220.        Modifiers : Gdk.Types.Gdk_Modifier_Type); 
  221.    --  Specifies the X key event to generate when a macro button of a device 
  222.    --  is pressed. 
  223.    --  "index_": the index of the macro button to set 
  224.    --  "keyval": the keyval to generate 
  225.    --  "modifiers": the modifiers to set 
  226.  
  227.    procedure Ungrab 
  228.       (Self : not null access Gdk_Device_Record; 
  229.        Time : Guint32); 
  230.    --  Release any grab on Device. 
  231.    --  Since: gtk+ 3.0 
  232.    --  "time_": a timestap (e.g. GDK_CURRENT_TIME). 
  233.  
  234.    procedure Warp 
  235.       (Self   : not null access Gdk_Device_Record; 
  236.        Screen : not null access Gdk.Screen.Gdk_Screen_Record'Class; 
  237.        X      : Gint; 
  238.        Y      : Gint); 
  239.    --  Warps Device in Display to the point X,Y on the screen Screen, unless 
  240.    --  the device is confined to a window by a grab, in which case it will be 
  241.    --  moved as far as allowed by the grab. Warping the pointer creates events 
  242.    --  as if the user had moved the mouse instantaneously to the destination. 
  243.    --  Note that the pointer should normally be under the control of the user. 
  244.    --  This function was added to cover some rare use cases like keyboard 
  245.    --  navigation support for the color picker in the 
  246.    --  Gtk.Color_Selection_Dialog.Gtk_Color_Selection_Dialog. 
  247.    --  Since: gtk+ 3.0 
  248.    --  "screen": the screen to warp Device to. 
  249.    --  "x": the X coordinate of the destination. 
  250.    --  "y": the Y coordinate of the destination. 
  251.  
  252.    ---------------------- 
  253.    -- GtkAda additions -- 
  254.    ---------------------- 
  255.  
  256.    procedure Get_Window_At_Position 
  257.      (Self   : not null access Gdk_Device_Record; 
  258.       Win_X  : out Gint; 
  259.       Win_Y  : out Gint; 
  260.       Window : out Gdk.Gdk_Window); 
  261.    --  Obtains the window underneath Device, returning the location of the 
  262.    --  device in Win_X and Win_Y. Returns null if the window tree under Device 
  263.    --  is not known to GDK (for example, belongs to another application). 
  264.    --  As a slave device coordinates are those of its master pointer, This 
  265.    --  function may not be called on devices of type 
  266.    --  Gdk.Device.Gdk_Device_Type_Slave, unless there is an ongoing grab on 
  267.    --  them, see Gdk.Device.Grab. 
  268.    --  Since: gtk+ 3.0 
  269.    --  "win_x": return location for the X coordinate of the device location, 
  270.    --  relative to the window origin, or null. 
  271.    --  "win_y": return location for the Y coordinate of the device location, 
  272.    --  relative to the window origin, or null. 
  273.  
  274.    procedure Set_Device 
  275.      (Event   : Gdk.Event.Gdk_Event; 
  276.       Device  : not null access Gdk_Device_Record); 
  277.    --  Sets the device for Event to Device. The event must 
  278.    --  have been allocated by GTK+, for instance, by gdk_event_copy(). 
  279.  
  280.    procedure Set_Source_Device 
  281.      (Event   : Gdk.Event.Gdk_Event; 
  282.       Device  : not null access Gdk_Device_Record); 
  283.    --  Sets the slave device for Event to Device. 
  284.    --  The event must have been allocated by GTK+, 
  285.    --  for instance by gdk_event_copy(). 
  286.  
  287.    ---------------- 
  288.    -- Properties -- 
  289.    ---------------- 
  290.    --  The following properties are defined for this widget. See 
  291.    --  Glib.Properties for more information on properties) 
  292.  
  293.    Associated_Device_Property : constant Glib.Properties.Property_Boxed; 
  294.    --  Type: Device 
  295.    --  Associated pointer or keyboard with this device, if any. Devices of 
  296.    --  type GDK_DEVICE_TYPE_MASTER always come in keyboard/pointer pairs. Other 
  297.    --  device types will have a null associated device. 
  298.  
  299.    Device_Manager_Property : constant Glib.Properties.Property_Boxed; 
  300.    --  Type: Device_Manager 
  301.    --  The Gdk.Device_Manager.Gdk_Device_Manager the Gdk.Device.Gdk_Device 
  302.    --  pertains to. 
  303.  
  304.    Display_Property : constant Glib.Properties.Property_Boxed; 
  305.    --  Type: Display 
  306.    --  The Gdk.Display.Gdk_Display the Gdk.Device.Gdk_Device pertains to. 
  307.  
  308.    Has_Cursor_Property : constant Glib.Properties.Property_Boolean; 
  309.    --  Whether the device is represented by a cursor on the screen. Devices of 
  310.    --  type Gdk.Device.Gdk_Device_Type_Master will have True here. 
  311.  
  312.    Input_Mode_Property : constant Glib.Properties.Property_Boxed; 
  313.    --  Type: Input_Mode 
  314.    --  Input mode for the device. 
  315.  
  316.    Input_Source_Property : constant Glib.Properties.Property_Boxed; 
  317.    --  Type: Input_Source 
  318.    --  Source type for the device. 
  319.  
  320.    N_Axes_Property : constant Glib.Properties.Property_Uint; 
  321.    --  Number of axes in the device. 
  322.  
  323.    Name_Property : constant Glib.Properties.Property_String; 
  324.    --  The device name. 
  325.  
  326.    The_Type_Property : constant Glib.Properties.Property_Boxed; 
  327.    --  Type: Device_Type 
  328.    --  Device role in the device manager. 
  329.  
  330.    ------------- 
  331.    -- Signals -- 
  332.    ------------- 
  333.  
  334.    Signal_Changed : constant Glib.Signal_Name := "changed"; 
  335.    --  The ::changed signal is emitted either when the Gdk.Device.Gdk_Device 
  336.    --  has changed the number of either axes or keys. For example In X this 
  337.    --  will normally happen when the slave device routing events through the 
  338.    --  master device changes (for example, user switches from the USB mouse to 
  339.    --  a tablet), in that case the master device will change to reflect the new 
  340.    --  slave device axes and keys. 
  341.    --    procedure Handler (Self : access Gdk_Device_Record'Class) 
  342.  
  343. private 
  344.    The_Type_Property : constant Glib.Properties.Property_Boxed := 
  345.      Glib.Properties.Build ("type"); 
  346.    Name_Property : constant Glib.Properties.Property_String := 
  347.      Glib.Properties.Build ("name"); 
  348.    N_Axes_Property : constant Glib.Properties.Property_Uint := 
  349.      Glib.Properties.Build ("n-axes"); 
  350.    Input_Source_Property : constant Glib.Properties.Property_Boxed := 
  351.      Glib.Properties.Build ("input-source"); 
  352.    Input_Mode_Property : constant Glib.Properties.Property_Boxed := 
  353.      Glib.Properties.Build ("input-mode"); 
  354.    Has_Cursor_Property : constant Glib.Properties.Property_Boolean := 
  355.      Glib.Properties.Build ("has-cursor"); 
  356.    Display_Property : constant Glib.Properties.Property_Boxed := 
  357.      Glib.Properties.Build ("display"); 
  358.    Device_Manager_Property : constant Glib.Properties.Property_Boxed := 
  359.      Glib.Properties.Build ("device-manager"); 
  360.    Associated_Device_Property : constant Glib.Properties.Property_Boxed := 
  361.      Glib.Properties.Build ("associated-device"); 
  362. end Gdk.Device;