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. pragma Ada_2005; 
  25.  
  26. pragma Warnings (Off, "*is already use-visible*"); 
  27. with GNAT.Strings;       use GNAT.Strings; 
  28. with Gdk.Display;        use Gdk.Display; 
  29. with Gdk.Event;          use Gdk.Event; 
  30. with Gdk.Pixbuf;         use Gdk.Pixbuf; 
  31. with Gdk.Types;          use Gdk.Types; 
  32. with Glib;               use Glib; 
  33. with Glib.Object;        use Glib.Object; 
  34. with Gtk.Selection_Data; use Gtk.Selection_Data; 
  35. with Gtk.Target_List;    use Gtk.Target_List; 
  36.  
  37. package Gtk.Clipboard is 
  38.  
  39.    type Gtk_Clipboard_Record is new GObject_Record with null record; 
  40.    type Gtk_Clipboard is access all Gtk_Clipboard_Record'Class; 
  41.  
  42.    --------------- 
  43.    -- Callbacks -- 
  44.    --------------- 
  45.  
  46.    type Gtk_Clipboard_Received_Func is access procedure 
  47.      (Clipboard      : not null access Gtk_Clipboard_Record'Class; 
  48.       Selection_Data : Gtk.Selection_Data.Gtk_Selection_Data); 
  49.    --  A function to be called when the results of 
  50.    --  Gtk.Clipboard.Request_Contents are received, or when the request fails. 
  51.    --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  52.    --  "selection_data": a Gtk.Selection_Data.Gtk_Selection_Data containing 
  53.    --  the data was received. If retrieving the data failed, then then length 
  54.    --  field of Selection_Data will be negative. 
  55.  
  56.    type Gtk_Clipboard_Image_Received_Func is access procedure 
  57.      (Clipboard : not null access Gtk_Clipboard_Record'Class; 
  58.       Pixbuf    : not null access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class); 
  59.    --  A function to be called when the results of Gtk.Clipboard.Request_Image 
  60.    --  are received, or when the request fails. 
  61.    --  Since: gtk+ 2.6 
  62.    --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  63.    --  "pixbuf": the received image 
  64.  
  65.    type Gtk_Clipboard_Rich_Text_Received_Func is access procedure 
  66.      (Clipboard : not null access Gtk_Clipboard_Record'Class; 
  67.       Format    : Gdk.Types.Gdk_Atom; 
  68.       Text      : in out Guint8; 
  69.       Length    : Gsize); 
  70.  
  71.    type Gtk_Clipboard_Targets_Received_Func is access procedure 
  72.      (Clipboard : not null access Gtk_Clipboard_Record'Class; 
  73.       Atoms     : in out Gdk.Types.Gdk_Atom; 
  74.       N_Atoms   : Gint); 
  75.    --  A function to be called when the results of 
  76.    --  Gtk.Clipboard.Request_Targets are received, or when the request fails. 
  77.    --  Since: gtk+ 2.4 
  78.    --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  79.    --  "atoms": the supported targets, as array of Gdk.Types.Gdk_Atom, or null 
  80.    --  if retrieving the data failed. 
  81.    --  "n_atoms": the length of the Atoms array. 
  82.  
  83.    type Gtk_Clipboard_Text_Received_Func is access procedure 
  84.      (Clipboard : not null access Gtk_Clipboard_Record'Class; 
  85.       Text      : UTF8_String); 
  86.    --  A function to be called when the results of Gtk.Clipboard.Request_Text 
  87.    --  are received, or when the request fails. 
  88.    --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  89.    --  "text": the text received, as a UTF-8 encoded string, or null if 
  90.    --  retrieving the data failed. 
  91.  
  92.    type Gtk_Clipboard_Urireceived_Func is access procedure 
  93.      (Clipboard : not null access Gtk_Clipboard_Record'Class; 
  94.       Uris      : GNAT.Strings.String_List); 
  95.  
  96.    ------------------ 
  97.    -- Constructors -- 
  98.    ------------------ 
  99.  
  100.    function Get_Type return Glib.GType; 
  101.    pragma Import (C, Get_Type, "gtk_clipboard_get_type"); 
  102.  
  103.    ------------- 
  104.    -- Methods -- 
  105.    ------------- 
  106.  
  107.    procedure Clear (Clipboard : not null access Gtk_Clipboard_Record); 
  108.  
  109.    function Get_Display 
  110.       (Clipboard : not null access Gtk_Clipboard_Record) 
  111.        return Gdk.Display.Gdk_Display; 
  112.  
  113.    function Get_Owner 
  114.       (Clipboard : not null access Gtk_Clipboard_Record) 
  115.        return Glib.Object.GObject; 
  116.  
  117.    procedure Request_Contents 
  118.       (Clipboard : not null access Gtk_Clipboard_Record; 
  119.        Target    : Gdk.Types.Gdk_Atom; 
  120.        Callback  : Gtk_Clipboard_Received_Func); 
  121.  
  122.    generic 
  123.       type User_Data_Type (<>) is private; 
  124.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  125.    package Request_Contents_User_Data is 
  126.  
  127.       type Gtk_Clipboard_Received_Func is access procedure 
  128.         (Clipboard      : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  129.          Selection_Data : Gtk.Selection_Data.Gtk_Selection_Data; 
  130.          Data           : User_Data_Type); 
  131.       --  A function to be called when the results of 
  132.       --  Gtk.Clipboard.Request_Contents are received, or when the request fails. 
  133.       --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  134.       --  "selection_data": a Gtk.Selection_Data.Gtk_Selection_Data containing 
  135.       --  the data was received. If retrieving the data failed, then then length 
  136.       --  field of Selection_Data will be negative. 
  137.       --  "data": the User_Data supplied to Gtk.Clipboard.Request_Contents. 
  138.  
  139.       procedure Request_Contents 
  140.          (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  141.           Target    : Gdk.Types.Gdk_Atom; 
  142.           Callback  : Gtk_Clipboard_Received_Func; 
  143.           User_Data : User_Data_Type); 
  144.  
  145.    end Request_Contents_User_Data; 
  146.  
  147.    procedure Request_Image 
  148.       (Clipboard : not null access Gtk_Clipboard_Record; 
  149.        Callback  : Gtk_Clipboard_Image_Received_Func); 
  150.  
  151.    generic 
  152.       type User_Data_Type (<>) is private; 
  153.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  154.    package Request_Image_User_Data is 
  155.  
  156.       type Gtk_Clipboard_Image_Received_Func is access procedure 
  157.         (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  158.          Pixbuf    : not null access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class; 
  159.          Data      : User_Data_Type); 
  160.       --  A function to be called when the results of Gtk.Clipboard.Request_Image 
  161.       --  are received, or when the request fails. 
  162.       --  Since: gtk+ 2.6 
  163.       --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  164.       --  "pixbuf": the received image 
  165.       --  "data": the User_Data supplied to Gtk.Clipboard.Request_Image. 
  166.  
  167.       procedure Request_Image 
  168.          (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  169.           Callback  : Gtk_Clipboard_Image_Received_Func; 
  170.           User_Data : User_Data_Type); 
  171.  
  172.    end Request_Image_User_Data; 
  173.  
  174.    procedure Request_Rich_Text 
  175.       (Clipboard : not null access Gtk_Clipboard_Record; 
  176.        Buffer    : not null access Glib.Object.GObject_Record'Class; 
  177.        Callback  : Gtk_Clipboard_Rich_Text_Received_Func); 
  178.  
  179.    generic 
  180.       type User_Data_Type (<>) is private; 
  181.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  182.    package Request_Rich_Text_User_Data is 
  183.  
  184.       type Gtk_Clipboard_Rich_Text_Received_Func is access procedure 
  185.         (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  186.          Format    : Gdk.Types.Gdk_Atom; 
  187.          Text      : in out Guint8; 
  188.          Length    : Gsize; 
  189.          Data      : User_Data_Type); 
  190.  
  191.       procedure Request_Rich_Text 
  192.          (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  193.           Buffer    : not null access Glib.Object.GObject_Record'Class; 
  194.           Callback  : Gtk_Clipboard_Rich_Text_Received_Func; 
  195.           User_Data : User_Data_Type); 
  196.  
  197.    end Request_Rich_Text_User_Data; 
  198.  
  199.    procedure Request_Targets 
  200.       (Clipboard : not null access Gtk_Clipboard_Record; 
  201.        Callback  : Gtk_Clipboard_Targets_Received_Func); 
  202.  
  203.    generic 
  204.       type User_Data_Type (<>) is private; 
  205.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  206.    package Request_Targets_User_Data is 
  207.  
  208.       type Gtk_Clipboard_Targets_Received_Func is access procedure 
  209.         (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  210.          Atoms     : in out Gdk.Types.Gdk_Atom; 
  211.          N_Atoms   : Gint; 
  212.          Data      : User_Data_Type); 
  213.       --  A function to be called when the results of 
  214.       --  Gtk.Clipboard.Request_Targets are received, or when the request fails. 
  215.       --  Since: gtk+ 2.4 
  216.       --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  217.       --  "atoms": the supported targets, as array of Gdk.Types.Gdk_Atom, or null 
  218.       --  if retrieving the data failed. 
  219.       --  "n_atoms": the length of the Atoms array. 
  220.       --  "data": the User_Data supplied to Gtk.Clipboard.Request_Targets. 
  221.  
  222.       procedure Request_Targets 
  223.          (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  224.           Callback  : Gtk_Clipboard_Targets_Received_Func; 
  225.           User_Data : User_Data_Type); 
  226.  
  227.    end Request_Targets_User_Data; 
  228.  
  229.    procedure Request_Text 
  230.       (Clipboard : not null access Gtk_Clipboard_Record; 
  231.        Callback  : Gtk_Clipboard_Text_Received_Func); 
  232.  
  233.    generic 
  234.       type User_Data_Type (<>) is private; 
  235.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  236.    package Request_Text_User_Data is 
  237.  
  238.       type Gtk_Clipboard_Text_Received_Func is access procedure 
  239.         (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  240.          Text      : UTF8_String; 
  241.          Data      : User_Data_Type); 
  242.       --  A function to be called when the results of Gtk.Clipboard.Request_Text 
  243.       --  are received, or when the request fails. 
  244.       --  "clipboard": the Gtk.Clipboard.Gtk_Clipboard 
  245.       --  "text": the text received, as a UTF-8 encoded string, or null if 
  246.       --  retrieving the data failed. 
  247.       --  "data": the User_Data supplied to Gtk.Clipboard.Request_Text. 
  248.  
  249.       procedure Request_Text 
  250.          (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  251.           Callback  : Gtk_Clipboard_Text_Received_Func; 
  252.           User_Data : User_Data_Type); 
  253.  
  254.    end Request_Text_User_Data; 
  255.  
  256.    procedure Request_Uris 
  257.       (Clipboard : not null access Gtk_Clipboard_Record; 
  258.        Callback  : Gtk_Clipboard_Urireceived_Func); 
  259.  
  260.    generic 
  261.       type User_Data_Type (<>) is private; 
  262.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  263.    package Request_Uris_User_Data is 
  264.  
  265.       type Gtk_Clipboard_Urireceived_Func is access procedure 
  266.         (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  267.          Uris      : GNAT.Strings.String_List; 
  268.          Data      : User_Data_Type); 
  269.  
  270.       procedure Request_Uris 
  271.          (Clipboard : not null access Gtk.Clipboard.Gtk_Clipboard_Record'Class; 
  272.           Callback  : Gtk_Clipboard_Urireceived_Func; 
  273.           User_Data : User_Data_Type); 
  274.  
  275.    end Request_Uris_User_Data; 
  276.  
  277.    procedure Set_Can_Store 
  278.       (Clipboard : not null access Gtk_Clipboard_Record; 
  279.        Targets   : Gtk.Target_List.Target_Entry_Array; 
  280.        N_Targets : Gint); 
  281.  
  282.    procedure Set_Image 
  283.       (Clipboard : not null access Gtk_Clipboard_Record; 
  284.        Pixbuf    : not null access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class); 
  285.  
  286.    procedure Set_Text 
  287.       (Clipboard : not null access Gtk_Clipboard_Record; 
  288.        Text      : UTF8_String); 
  289.  
  290.    procedure Store (Clipboard : not null access Gtk_Clipboard_Record); 
  291.  
  292.    function Wait_For_Contents 
  293.       (Clipboard : not null access Gtk_Clipboard_Record; 
  294.        Target    : Gdk.Types.Gdk_Atom) 
  295.        return Gtk.Selection_Data.Gtk_Selection_Data; 
  296.  
  297.    function Wait_For_Image 
  298.       (Clipboard : not null access Gtk_Clipboard_Record) 
  299.        return Gdk.Pixbuf.Gdk_Pixbuf; 
  300.  
  301.    function Wait_For_Text 
  302.       (Clipboard : not null access Gtk_Clipboard_Record) return UTF8_String; 
  303.  
  304.    function Wait_For_Uris 
  305.       (Clipboard : not null access Gtk_Clipboard_Record) 
  306.        return GNAT.Strings.String_List; 
  307.  
  308.    function Wait_Is_Image_Available 
  309.       (Clipboard : not null access Gtk_Clipboard_Record) return Boolean; 
  310.  
  311.    function Wait_Is_Rich_Text_Available 
  312.       (Clipboard : not null access Gtk_Clipboard_Record; 
  313.        Buffer    : not null access Glib.Object.GObject_Record'Class) 
  314.        return Boolean; 
  315.  
  316.    function Wait_Is_Target_Available 
  317.       (Clipboard : not null access Gtk_Clipboard_Record; 
  318.        Target    : Gdk.Types.Gdk_Atom) return Boolean; 
  319.  
  320.    function Wait_Is_Text_Available 
  321.       (Clipboard : not null access Gtk_Clipboard_Record) return Boolean; 
  322.  
  323.    function Wait_Is_Uris_Available 
  324.       (Clipboard : not null access Gtk_Clipboard_Record) return Boolean; 
  325.  
  326.    ---------------------- 
  327.    -- GtkAda additions -- 
  328.    ---------------------- 
  329.  
  330.    function Wait_For_Targets 
  331.      (Clipboard : not null access Gtk_Clipboard_Record) 
  332.    return Gdk.Types.Gdk_Atom_Array; 
  333.    --  Returns a list of targets that are present on the clipboard, or an empty 
  334.    --  array if there aren't any targets available. 
  335.    --  This function waits for the data to be received using the main 
  336.    --  loop, so events, timeouts, etc, may be dispatched during the wait. 
  337.  
  338.    --------------- 
  339.    -- Functions -- 
  340.    --------------- 
  341.  
  342.    function Get 
  343.       (Selection : Gdk.Types.Gdk_Atom := Gdk.Types.Gdk_None) 
  344.        return Gtk_Clipboard; 
  345.  
  346.    function Get_For_Display 
  347.       (Display   : not null access Gdk.Display.Gdk_Display_Record'Class; 
  348.        Selection : Gdk.Types.Gdk_Atom := Gdk.Types.Gdk_None) 
  349.        return Gtk_Clipboard; 
  350.  
  351.    ------------- 
  352.    -- Signals -- 
  353.    ------------- 
  354.  
  355.    type Cb_Gtk_Clipboard_Gdk_Event_Void is not null access procedure 
  356.      (Self   : access Gtk_Clipboard_Record'Class; 
  357.       Object : Gdk.Event.Gdk_Event); 
  358.  
  359.    type Cb_GObject_Gdk_Event_Void is not null access procedure 
  360.      (Self   : access Glib.Object.GObject_Record'Class; 
  361.       Object : Gdk.Event.Gdk_Event); 
  362.  
  363.    Signal_Owner_Change : constant Glib.Signal_Name := "owner-change"; 
  364.    procedure On_Owner_Change 
  365.       (Self  : not null access Gtk_Clipboard_Record; 
  366.        Call  : Cb_Gtk_Clipboard_Gdk_Event_Void; 
  367.        After : Boolean := False); 
  368.    procedure On_Owner_Change 
  369.       (Self  : not null access Gtk_Clipboard_Record; 
  370.        Call  : Cb_GObject_Gdk_Event_Void; 
  371.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  372.        After : Boolean := False); 
  373.  
  374. end Gtk.Clipboard;