1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2013, AdaCore                   -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- As a special exception, if other files instantiate generics from  -- 
  22. -- this unit, or you link this unit with other files to produce an   -- 
  23. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  24. -- executable to be covered by the GNU General Public License. This  -- 
  25. -- exception does not however invalidate any other reasons why the   -- 
  26. -- executable file  might be covered by the  GNU Public License.     -- 
  27. ----------------------------------------------------------------------- 
  28.  
  29. --  <description> 
  30. --  GTK+ supports Drag-and-Drop in tree views with a high-level and a low-level 
  31. --  API. 
  32. -- 
  33. --  The low-level API consists of the GTK+ DND API, augmented by some treeview 
  34. --  utility functions: Gtk.Tree_View.Set_Drag_Dest_Row, 
  35. --  Gtk.Tree_View.Get_Drag_Dest_Row, Gtk.Tree_View.Get_Dest_Row_At_Pos, 
  36. --  Gtk.Tree_View.Create_Row_Drag_Icon, Set_Row_Drag_Data and 
  37. --  Get_Row_Drag_Data. This API leaves a lot of flexibility, but 
  38. --  nothing is done automatically, and implementing advanced features like 
  39. --  hover-to-open-rows or autoscrolling on top of this API is a lot of work. 
  40. -- 
  41. --  On the other hand, if you write to the high-level API, then all the 
  42. --  bookkeeping of rows is done for you, as well as things like hover-to-open 
  43. --  and auto-scroll, but your models have to implement the Gtk_Tree_Drag_Source 
  44. --  and Gtk_Tree_Drag_Dest interfaces. 
  45. --  </description> 
  46. --  <c_version>2.8.17</c_version> 
  47. --  <group>Trees and Lists</group> 
  48.  
  49. with Glib.Types; 
  50. with Gtk.Selection; 
  51. with Gtk.Tree_Model; 
  52.  
  53. package Gtk.Tree_Dnd is 
  54.    type Gtk_Tree_Drag_Source is new Glib.Types.GType_Interface; 
  55.    type Gtk_Tree_Drag_Dest   is new Glib.Types.GType_Interface; 
  56.  
  57.    function Drag_Dest_Get_Type   return GType; 
  58.    function Drag_Source_Get_Type return GType; 
  59.    --  Return the low-level types associated with the interfaces 
  60.  
  61.    function Drag_Dest_Drag_Data_Received 
  62.      (Drag_Dest      : Gtk_Tree_Drag_Dest; 
  63.       Dest           : Gtk.Tree_Model.Gtk_Tree_Path; 
  64.       Selection_Data : Gtk.Selection.Selection_Data) 
  65.       return Boolean; 
  66.    --  Asks the Drag_Dest to insert a row before the path Dest, 
  67.    --  deriving the contents of the row from Selection_Data. If Dest is 
  68.    --  outside the tree so that inserting before it is impossible, False 
  69.    --  will be returned. Also, False may be returned if the new row is 
  70.    --  not created for some model-specific reason.  Should robustly handle 
  71.    --  a Dest no longer found in the model! 
  72.  
  73.    function Drag_Dest_Row_Drop_Possible 
  74.      (Drag_Dest      : Gtk_Tree_Drag_Dest; 
  75.       Dest_Path      : Gtk.Tree_Model.Gtk_Tree_Path; 
  76.       Selection_Data : Gtk.Selection.Selection_Data) 
  77.       return Boolean; 
  78.    --  Determines whether a drop is possible before the given Dest_Path, 
  79.    --  at the same depth as Dest_Path. i.e., can we drop the data in 
  80.    --  Selection_Data at that location. Dest_Path does not have to 
  81.    --  exist; the return value will almost certainly be False if the 
  82.    --  parent of Dest_Path doesn't exist, though. 
  83.  
  84.    function Drag_Source_Drag_Data_Delete 
  85.      (Drag_Source : Gtk_Tree_Drag_Source; 
  86.       Path        : Gtk.Tree_Model.Gtk_Tree_Path) 
  87.       return Boolean; 
  88.    --  Asks the Drag_Source to delete the row at Path, because 
  89.    --  it was moved somewhere else via drag-and-drop. Returns False 
  90.    --  if the deletion fails because Path no longer exists, or for 
  91.    --  some model-specific reason. Should robustly handle a Path no 
  92.    --  longer found in the model! 
  93.  
  94.    function Drag_Source_Drag_Data_Get 
  95.      (Drag_Source    : Gtk_Tree_Drag_Source; 
  96.       Path           : Gtk.Tree_Model.Gtk_Tree_Path; 
  97.       Selection_Data : Gtk.Selection.Selection_Data) 
  98.       return Boolean; 
  99.    --  Asks the Drag_Source to fill in Selection_Data with a 
  100.    --  representation of the row at Path. Get_Target (Selection_Data) gives 
  101.    --  the required type of the data.  Should robustly handle a Path no 
  102.    --  longer found in the model! 
  103.  
  104.    function Drag_Source_Row_Draggable 
  105.      (Drag_Source : Gtk_Tree_Drag_Source; 
  106.       Path        : Gtk.Tree_Model.Gtk_Tree_Path) 
  107.       return Boolean; 
  108.    --  Asks the Drag_Source whether a particular row can be used as 
  109.    --  the source of a DND operation. If the source doesn't implement 
  110.    --  this interface, the row is assumed draggable. 
  111.  
  112.    procedure Get_Row_Drag_Data 
  113.      (Selection_Data : Gtk.Selection.Selection_Data; 
  114.       Tree_Model     : out Gtk.Tree_Model.Gtk_Tree_Model; 
  115.       Path           : out Gtk.Tree_Model.Gtk_Tree_Path; 
  116.       Success        : out Boolean); 
  117.    --  Obtains a Tree_Model and Path from selection data of target type 
  118.    --  GTK_TREE_MODEL_ROW. Normally called from a drag_data_received handler. 
  119.    -- 
  120.    --  This function can only be used if Selection_Data originates from the 
  121.    --  same process that's calling this function, because a pointer to the tree 
  122.    --  model is being passed around. If you aren't in the same process, then 
  123.    --  you'll get memory corruption. In the Gtk_Tree_Drag_Dest 
  124.    --  drag_data_received handler, you can assume that selection data of type 
  125.    --  GTK_TREE_MODEL_ROW is in from the current process. 
  126.    -- 
  127.    --  The returned path must be freed with 
  128.  
  129.    function Set_Row_Drag_Data 
  130.      (Selection_Data : Gtk.Selection.Selection_Data; 
  131.       Tree_Model     : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; 
  132.       Path           : Gtk.Tree_Model.Gtk_Tree_Path) 
  133.       return Boolean; 
  134.    --  Sets selection data of target type GTK_TREE_MODEL_ROW. Normally used 
  135.    --  in a drag_data_get handler. 
  136.  
  137. private 
  138.    pragma Import (C, Drag_Dest_Get_Type, "gtk_tree_drag_dest_get_type"); 
  139.    pragma Import (C, Drag_Source_Get_Type, "gtk_tree_drag_source_get_type"); 
  140.  
  141. end Gtk.Tree_Dnd; 
  142.  
  143.  
  144.