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.Pixbuf;   use Gdk.Pixbuf; 
  30. with Gdk.Types;    use Gdk.Types; 
  31. with Glib;         use Glib; 
  32.  
  33. package Gtk.Selection_Data is 
  34.  
  35.    type Gtk_Selection_Data is new Glib.C_Boxed with null record; 
  36.    Null_Gtk_Selection_Data : constant Gtk_Selection_Data; 
  37.  
  38.    function From_Object (Object : System.Address) return Gtk_Selection_Data; 
  39.    function From_Object_Free (B : access Gtk_Selection_Data'Class) return Gtk_Selection_Data; 
  40.    pragma Inline (From_Object_Free, From_Object); 
  41.  
  42.    ------------------ 
  43.    -- Constructors -- 
  44.    ------------------ 
  45.  
  46.    function Get_Type return Glib.GType; 
  47.    pragma Import (C, Get_Type, "gtk_selection_data_get_type"); 
  48.  
  49.    ------------- 
  50.    -- Methods -- 
  51.    ------------- 
  52.  
  53.    function Copy (Selection : Gtk_Selection_Data) return Gtk_Selection_Data; 
  54.    --  Makes a copy of a Gtk.Selection_Data.Gtk_Selection_Data structure and 
  55.    --  its data. 
  56.  
  57.    procedure Free (Selection : Gtk_Selection_Data); 
  58.    --  Frees a Gtk.Selection_Data.Gtk_Selection_Data structure returned from 
  59.    --  Gtk.Selection_Data.Copy. 
  60.  
  61.    function Get_Data (Selection : Gtk_Selection_Data) return System.Address; 
  62.    --  Retrieves the raw data of the selection. 
  63.    --  Since: gtk+ 2.14 
  64.  
  65.    function Get_Data_Type 
  66.       (Selection : Gtk_Selection_Data) return Gdk.Types.Gdk_Atom; 
  67.    --  Retrieves the data type of the selection. 
  68.    --  Since: gtk+ 2.14 
  69.  
  70.    function Get_Display 
  71.       (Selection : Gtk_Selection_Data) return Gdk.Display.Gdk_Display; 
  72.    --  Retrieves the display of the selection. 
  73.    --  Since: gtk+ 2.14 
  74.  
  75.    function Get_Format (Selection : Gtk_Selection_Data) return Gint; 
  76.    --  Retrieves the format of the selection. 
  77.    --  Since: gtk+ 2.14 
  78.  
  79.    function Get_Length (Selection : Gtk_Selection_Data) return Gint; 
  80.    --  Retrieves the length of the raw data of the selection. 
  81.    --  Since: gtk+ 2.14 
  82.  
  83.    function Get_Pixbuf 
  84.       (Selection : Gtk_Selection_Data) return Gdk.Pixbuf.Gdk_Pixbuf; 
  85.    --  Gets the contents of the selection data as a Gdk.Pixbuf.Gdk_Pixbuf. 
  86.    --  Since: gtk+ 2.6 
  87.  
  88.    function Set_Pixbuf 
  89.       (Selection : Gtk_Selection_Data; 
  90.        Pixbuf    : not null access Gdk.Pixbuf.Gdk_Pixbuf_Record'Class) 
  91.        return Boolean; 
  92.    --  Sets the contents of the selection from a Gdk.Pixbuf.Gdk_Pixbuf The 
  93.    --  pixbuf is converted to the form determined by Selection_Data->target. 
  94.    --  Since: gtk+ 2.6 
  95.    --  "pixbuf": a Gdk.Pixbuf.Gdk_Pixbuf 
  96.  
  97.    function Get_Selection 
  98.       (Selection : Gtk_Selection_Data) return Gdk.Types.Gdk_Atom; 
  99.    --  Retrieves the selection Gdk.Types.Gdk_Atom of the selection data. 
  100.    --  Since: gtk+ 2.16 
  101.  
  102.    function Get_Target 
  103.       (Selection : Gtk_Selection_Data) return Gdk.Types.Gdk_Atom; 
  104.    --  Retrieves the target of the selection. 
  105.    --  Since: gtk+ 2.14 
  106.  
  107.    function Get_Text (Selection : Gtk_Selection_Data) return UTF8_String; 
  108.    --  Gets the contents of the selection data as a UTF-8 string. 
  109.  
  110.    function Set_Text 
  111.       (Selection : Gtk_Selection_Data; 
  112.        Str       : UTF8_String; 
  113.        Len       : Gint) return Boolean; 
  114.    --  Sets the contents of the selection from a UTF-8 encoded string. The 
  115.    --  string is converted to the form determined by Selection_Data->target. 
  116.    --  "str": a UTF-8 string 
  117.    --  "len": the length of Str, or -1 if Str is nul-terminated. 
  118.  
  119.    function Get_Uris 
  120.       (Selection : Gtk_Selection_Data) return GNAT.Strings.String_List; 
  121.    --  Gets the contents of the selection data as array of URIs. 
  122.    --  Since: gtk+ 2.6 
  123.  
  124.    function Set_Uris 
  125.       (Selection : Gtk_Selection_Data; 
  126.        Uris      : GNAT.Strings.String_List) return Boolean; 
  127.    --  Sets the contents of the selection from a list of URIs. The string is 
  128.    --  converted to the form determined by Selection_Data->target. 
  129.    --  Since: gtk+ 2.6 
  130.    --  "uris": a null-terminated array of strings holding URIs 
  131.  
  132.    function Targets_Include_Image 
  133.       (Selection : Gtk_Selection_Data; 
  134.        Writable  : Boolean) return Boolean; 
  135.    --  Given a Gtk.Selection_Data.Gtk_Selection_Data object holding a list of 
  136.    --  targets, determines if any of the targets in Targets can be used to 
  137.    --  provide a Gdk.Pixbuf.Gdk_Pixbuf. 
  138.    --  Since: gtk+ 2.6 
  139.    --  "writable": whether to accept only targets for which GTK+ knows how to 
  140.    --  convert a pixbuf into the format 
  141.  
  142.    function Targets_Include_Text 
  143.       (Selection : Gtk_Selection_Data) return Boolean; 
  144.    --  Given a Gtk.Selection_Data.Gtk_Selection_Data object holding a list of 
  145.    --  targets, determines if any of the targets in Targets can be used to 
  146.    --  provide text. 
  147.  
  148.    function Targets_Include_Uri 
  149.       (Selection : Gtk_Selection_Data) return Boolean; 
  150.    --  Given a Gtk.Selection_Data.Gtk_Selection_Data object holding a list of 
  151.    --  targets, determines if any of the targets in Targets can be used to 
  152.    --  provide a list or URIs. 
  153.    --  Since: gtk+ 2.10 
  154.  
  155.    ---------------------- 
  156.    -- GtkAda additions -- 
  157.    ---------------------- 
  158.  
  159.    --------------- 
  160.    -- Selection -- 
  161.    --------------- 
  162.  
  163.    function Make_Atom (Num : Gulong) return Gdk.Types.Gdk_Atom; 
  164.    pragma Import (C, Make_Atom, "ada_make_atom"); 
  165.    --  Auxiliary subprogram 
  166.  
  167.    subtype Gdk_Selection is Gdk.Types.Gdk_Atom; 
  168.    --  These are predefined atom values for several common selections. 
  169.    --  You are of course free to create new ones, but most of the time you 
  170.    --  should simply use Selection_Primary unless you foresee the need for 
  171.    --  multiple simultaneous selections. 
  172.    --  To access the clipboard on windows machines, you might need to create 
  173.    --  a new selection with Gdk.Property.Atom_Intern ("CLIPBOARD"); 
  174.  
  175.    Selection_Primary   : constant Gdk_Selection := Make_Atom (1); 
  176.    Selection_Secondary : constant Gdk_Selection := Make_Atom (2); 
  177.  
  178.    procedure Selection_Data_Set 
  179.      (Selection : Gtk_Selection_Data; 
  180.       The_Type  : Gdk.Types.Gdk_Atom; 
  181.       Format    : Gint; 
  182.       Data      : System.Address; 
  183.       Length    : Gint); 
  184.    --  General form of Selection_Data_Set. 
  185.    --  Any data can be transmitted. Length is the number of bytes in Data. 
  186.  
  187.    procedure Selection_Data_Set 
  188.      (Selection : Gtk_Selection_Data; 
  189.       The_Type  : Gdk.Types.Gdk_Atom; 
  190.       Format    : Gint; 
  191.       Data      : String); 
  192.    --  Set the data for a selection (special case for strings) 
  193.    --  This function is generally called when a drag-and-drop operation 
  194.    --  ask the source widget for the data to be transmitted. In that case, 
  195.    --  a Selection_Data was already transmitted and is given as a handler 
  196.    --  parameter for the signal "drag_data_get". The_Type can simply be 
  197.    --  extracted from the Selection_Data. 
  198.  
  199.    function Get_Targets 
  200.      (Selection : Gtk_Selection_Data) return Gdk.Types.Gdk_Atom_Array; 
  201.    --  Gets the contents of Selection_Data as an array of targets. 
  202.    --  This can be used to interpret the results of getting 
  203.    --  the standard TARGETS target that is always supplied for 
  204.    --  any selection. 
  205.    --  This is different from Get_Target, which indicate the current format 
  206.    --  that the selection contains. Get_Targets only applies when Get_Target 
  207.    --  is "TARGETS". 
  208.  
  209.    function Get_Data_As_String (Selection : Gtk_Selection_Data) return String; 
  210.    --  Return the data as a string. 
  211.    --  This is only a convenience function, since it simply creates a string 
  212.    --  from the return of Get_Data. 
  213.  
  214. private 
  215.  
  216.    Null_Gtk_Selection_Data : constant Gtk_Selection_Data := (Glib.C_Boxed with null record); 
  217.  
  218. end Gtk.Selection_Data;