1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006, 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. -- -- -- -- -- -- -- -- -- -- -- --
  22. ----------------------------------------------------------------------- 
  23.  
  24. --  <description> 
  25. --  GTK+ supports Drag-and-Drop in tree views with a high-level and a low-level 
  26. --  API. 
  27. -- 
  28. --  The low-level API consists of the GTK+ DND API, augmented by some treeview 
  29. --  utility functions: Gtk.Tree_View.Set_Drag_Dest_Row, 
  30. --  Gtk.Tree_View.Get_Drag_Dest_Row, Gtk.Tree_View.Get_Dest_Row_At_Pos, 
  31. --  Gtk.Tree_View.Create_Row_Drag_Icon, Set_Row_Drag_Data and 
  32. --  Get_Row_Drag_Data. This API leaves a lot of flexibility, but 
  33. --  nothing is done automatically, and implementing advanced features like 
  34. --  hover-to-open-rows or autoscrolling on top of this API is a lot of work. 
  35. -- 
  36. --  On the other hand, if you write to the high-level API, then all the 
  37. --  bookkeeping of rows is done for you, as well as things like hover-to-open 
  38. --  and auto-scroll, but your models have to implement the Gtk_Tree_Drag_Source 
  39. --  and Gtk_Tree_Drag_Dest interfaces. 
  40. --  </description> 
  41. --  <c_version>2.8.17</c_version> 
  42. --  <group>Trees and Lists</group> 
  43.  
  44. with Glib.Types; 
  45. with Gtk.Selection; 
  46. with Gtk.Tree_Model; 
  47.  
  48. package Gtk.Tree_Dnd is 
  49.    type Gtk_Tree_Drag_Source is new Glib.Types.GType_Interface; 
  50.    type Gtk_Tree_Drag_Dest   is new Glib.Types.GType_Interface; 
  51.  
  52.    function Drag_Dest_Get_Type   return GType; 
  53.    function Drag_Source_Get_Type return GType; 
  54.    --  Return the low-level types associated with the interfaces 
  55.  
  56.    function Drag_Dest_Drag_Data_Received 
  57.      (Drag_Dest      : Gtk_Tree_Drag_Dest; 
  58.       Dest           : Gtk.Tree_Model.Gtk_Tree_Path; 
  59.       Selection_Data : Gtk.Selection.Selection_Data) 
  60.       return Boolean; 
  61.    --  Asks the Drag_Dest to insert a row before the path Dest, 
  62.    --  deriving the contents of the row from Selection_Data. If Dest is 
  63.    --  outside the tree so that inserting before it is impossible, False 
  64.    --  will be returned. Also, False may be returned if the new row is 
  65.    --  not created for some model-specific reason.  Should robustly handle 
  66.    --  a Dest no longer found in the model! 
  67.  
  68.    function Drag_Dest_Row_Drop_Possible 
  69.      (Drag_Dest      : Gtk_Tree_Drag_Dest; 
  70.       Dest_Path      : Gtk.Tree_Model.Gtk_Tree_Path; 
  71.       Selection_Data : Gtk.Selection.Selection_Data) 
  72.       return Boolean; 
  73.    --  Determines whether a drop is possible before the given Dest_Path, 
  74.    --  at the same depth as Dest_Path. i.e., can we drop the data in 
  75.    --  Selection_Data at that location. Dest_Path does not have to 
  76.    --  exist; the return value will almost certainly be False if the 
  77.    --  parent of Dest_Path doesn't exist, though. 
  78.  
  79.    function Drag_Source_Drag_Data_Delete 
  80.      (Drag_Source : Gtk_Tree_Drag_Source; 
  81.       Path        : Gtk.Tree_Model.Gtk_Tree_Path) 
  82.       return Boolean; 
  83.    --  Asks the Drag_Source to delete the row at Path, because 
  84.    --  it was moved somewhere else via drag-and-drop. Returns False 
  85.    --  if the deletion fails because Path no longer exists, or for 
  86.    --  some model-specific reason. Should robustly handle a Path no 
  87.    --  longer found in the model! 
  88.  
  89.    function Drag_Source_Drag_Data_Get 
  90.      (Drag_Source    : Gtk_Tree_Drag_Source; 
  91.       Path           : Gtk.Tree_Model.Gtk_Tree_Path; 
  92.       Selection_Data : Gtk.Selection.Selection_Data) 
  93.       return Boolean; 
  94.    --  Asks the Drag_Source to fill in Selection_Data with a 
  95.    --  representation of the row at Path. Get_Target (Selection_Data) gives 
  96.    --  the required type of the data.  Should robustly handle a Path no 
  97.    --  longer found in the model! 
  98.  
  99.    function Drag_Source_Row_Draggable 
  100.      (Drag_Source : Gtk_Tree_Drag_Source; 
  101.       Path        : Gtk.Tree_Model.Gtk_Tree_Path) 
  102.       return Boolean; 
  103.    --  Asks the Drag_Source whether a particular row can be used as 
  104.    --  the source of a DND operation. If the source doesn't implement 
  105.    --  this interface, the row is assumed draggable. 
  106.  
  107.    procedure Get_Row_Drag_Data 
  108.      (Selection_Data : Gtk.Selection.Selection_Data; 
  109.       Tree_Model     : out Gtk.Tree_Model.Gtk_Tree_Model; 
  110.       Path           : out Gtk.Tree_Model.Gtk_Tree_Path; 
  111.       Success        : out Boolean); 
  112.    --  Obtains a Tree_Model and Path from selection data of target type 
  113.    --  GTK_TREE_MODEL_ROW. Normally called from a drag_data_received handler. 
  114.    -- 
  115.    --  This function can only be used if Selection_Data originates from the 
  116.    --  same process that's calling this function, because a pointer to the tree 
  117.    --  model is being passed around. If you aren't in the same process, then 
  118.    --  you'll get memory corruption. In the Gtk_Tree_Drag_Dest 
  119.    --  drag_data_received handler, you can assume that selection data of type 
  120.    --  GTK_TREE_MODEL_ROW is in from the current process. 
  121.    -- 
  122.    --  The returned path must be freed with 
  123.  
  124.    function Set_Row_Drag_Data 
  125.      (Selection_Data : Gtk.Selection.Selection_Data; 
  126.       Tree_Model     : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; 
  127.       Path           : Gtk.Tree_Model.Gtk_Tree_Path) 
  128.       return Boolean; 
  129.    --  Sets selection data of target type GTK_TREE_MODEL_ROW. Normally used 
  130.    --  in a drag_data_get handler. 
  131.  
  132. private 
  133.    pragma Import (C, Drag_Dest_Get_Type, "gtk_tree_drag_dest_get_type"); 
  134.    pragma Import (C, Drag_Source_Get_Type, "gtk_tree_drag_source_get_type"); 
  135.  
  136. end Gtk.Tree_Dnd; 
  137.  
  138.  
  139.