/src/wrappers/gtk/library/gtk_tree_drag_dest.e

http://github.com/tybor/Liberty · Specman e · 183 lines · 54 code · 41 blank · 88 comment · 3 complexity · ebb5e0c3b1b87c5e27381e58f473ab2f MD5 · raw file

  1. indexing
  2. description: "Destionation of a drag'n'drop: GtkTreeView drag-and-drop Interface for drag-and-drop support in GtkTreeView"
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. deferred class GTK_TREE_DRAG_DEST
  19. -- GTK+ supports Drag-and-Drop in tree views with a high-level and
  20. -- a low-level API.
  21. -- The low-level API consists of the GTK+ DND API, augmented by
  22. -- some treeview utility functions: GTK_TREE_VIEW's
  23. -- set_drag_dest_row, get_drag_dest_row, get_dest_row_at_pos,
  24. -- create_row_drag_icon, set_row_drag_data and
  25. -- get_row_drag_data. This API leaves a lot of flexibility, but
  26. -- nothing is done automatically, and implementing advanced
  27. -- features like hover-to-open-rows or autoscrolling on top of this
  28. -- API is a lot of work.
  29. -- On the other hand, if you write to the high-level API, then all
  30. -- the bookkeeping of rows is done for you, as well as things like
  31. -- hover-to-open and auto-scroll, but your models have to implement
  32. -- the GtkTreeDragSource and GtkTreeDragDest interfaces.
  33. inherit G_OBJECT
  34. -- Object Hierarchy: inherits from GInterface
  35. -- Known Implementations: GtkTreeDragSource is implemented by
  36. -- GtkTreeModelSort, GtkTreeStore, GtkListStore and
  37. -- GtkTreeModelFilter.
  38. -- GtkTreeDragDest is implemented by GtkTreeStore and GtkListStore.
  39. feature --
  40. is_last_action_successful: BOOLEAN
  41. receive_data (a_path: GTK_TREE_PATH; a_selection_data: GTK_SELECTION_DATA) is
  42. -- Try to insert a row before `a_path', deriving the contents
  43. -- of the row from
  44. -- `a_selection_data'. `is_last_action_successful' will be
  45. -- False if `a_path' is outside the tree so that inserting
  46. -- before it is impossible; it will also be False if the new
  47. -- row is not created for some model-specific reason. Should
  48. -- robustly handle a dest no longer found in the model!
  49. require
  50. valid_path: a_path /= Void
  51. valid_data: a_selection_data /= Void
  52. do
  53. is_last_action_successful :=
  54. (gtk_tree_drag_dest_drag_data_received
  55. (handle, a_path.handle, a_selection_data.handle)).to_boolean
  56. end
  57. is_row_drop_possible (a_path: GTK_TREE_PATH; a_selection_data: GTK_SELECTION_DATA): BOOLEAN is
  58. -- Determines whether a drop is possible before the given
  59. -- dest_path, at the same depth as dest_path. i.e., can we
  60. -- drop the data in selection_data at that
  61. -- location. dest_path does not have to exist; the return
  62. -- value will almost certainly be FALSE if the parent of
  63. -- dest_path doesn't exist, though.
  64. -- drag_dest : a GtkTreeDragDest
  65. -- dest_path : destination row
  66. -- selection_data : the data being dragged
  67. -- Returns : TRUE if a drop is possible before dest_path
  68. require
  69. valid_path: a_path /= Void
  70. valid_data: a_selection_data /= Void
  71. do
  72. Result := (gtk_tree_drag_dest_row_drop_possible
  73. (handle, a_path.handle, a_selection_data.handle)).to_boolean
  74. end
  75. feature -- TODO: GtkTreeDragDestIface
  76. -- typedef struct {
  77. -- GTypeInterface g_iface;
  78. -- /* VTable - not signals */
  79. -- gboolean (* drag_data_received) (GtkTreeDragDest *drag_dest,
  80. -- GtkTreePath *dest,
  81. -- GtkSelectionData *selection_data);
  82. -- gboolean (* row_drop_possible) (GtkTreeDragDest *drag_dest,
  83. -- GtkTreePath *dest_path,
  84. -- GtkSelectionData *selection_data);
  85. -- } GtkTreeDragDestIface;
  86. -- gtk_tree_set_row_drag_data ()
  87. -- gboolean gtk_tree_set_row_drag_data (GtkSelectionData *selection_data,
  88. -- GtkTreeModel *tree_model,
  89. -- GtkTreePath *path);
  90. -- Sets selection data of target type GTK_TREE_MODEL_ROW. Normally used in a drag_data_get handler.
  91. -- selection_data : some GtkSelectionData
  92. -- tree_model : a GtkTreeModel
  93. -- path : a row in tree_model
  94. -- Returns : TRUE if the GtkSelectionData had the proper target type to allow us to set a tree row
  95. -- gtk_tree_get_row_drag_data ()
  96. -- gboolean gtk_tree_get_row_drag_data (GtkSelectionData *selection_data,
  97. -- GtkTreeModel **tree_model,
  98. -- GtkTreePath **path);
  99. -- Obtains a tree_model and path from selection data of target type GTK_TREE_MODEL_ROW. Normally called from a drag_data_received handler. This function can only be used if selection_data originates from the same process that's calling this function, because a pointer to the tree model is being passed around. If you aren't in the same process, then you'll get memory corruption. In the GtkTreeDragDest drag_data_received handler, you can assume that selection data of type GTK_TREE_MODEL_ROW is in from the current process. The returned path must be freed with gtk_tree_path_free().
  100. -- selection_data : a GtkSelectionData
  101. -- tree_model : a GtkTreeModel
  102. -- path : row in tree_model
  103. -- Returns : TRUE if selection_data had target type GTK_TREE_MODEL_ROW and is otherwise valid
  104. feature {} -- External calls
  105. gtk_tree_drag_dest_drag_data_received (a_drag_dest: POINTER; -- GtkTreeDragDest*
  106. a_dest: POINTER; -- GtkTreePath*
  107. a_selection_data: POINTER -- GtkSelectionData*
  108. ): INTEGER is -- gboolean
  109. external "C use <gtk/gtk.h>"
  110. end
  111. gtk_tree_drag_dest_row_drop_possible (a_drag_dest: POINTER; -- GtkTreeDragDest*
  112. a_dest_path: POINTER; -- GtkTreePath *
  113. a_selection_data: POINTER -- GtkSelectionData
  114. ): INTEGER is -- gboolean
  115. external "C use <gtk/gtk.h>"
  116. end
  117. -- gtk_tree_set_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData*
  118. -- a_tree_model: POINTER; -- GtkTreeModel*
  119. -- a_path: POINTER; -- GtkTreePath*
  120. -- ): INTEGER is -- gboolean
  121. -- external "C use <gtk/gtk.h>"
  122. -- end
  123. -- gtk_tree_get_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData
  124. -- a_tree_model_handle: POINTER -- GtkTreeModel **
  125. -- a_path_handle: POINTER -- GtkTreePath **path
  126. -- ): INTEGER is -- gboolean
  127. -- external "C use <gtk/gtk.h>"
  128. -- end
  129. feature {} -- TODO: wrap - if necessary - GtkTreeDragSourceIface
  130. -- typedef struct _GtkTreeDragSource GtkTreeDragSource;
  131. -- typedef struct {
  132. -- GTypeInterface g_iface;
  133. -- /* VTable - not signals */
  134. -- gboolean (* row_draggable) (GtkTreeDragSource *drag_source,
  135. -- GtkTreePath *path);
  136. -- gboolean (* drag_data_get) (GtkTreeDragSource *drag_source,
  137. -- GtkTreePath *path,
  138. -- GtkSelectionData *selection_data);
  139. -- gboolean (* drag_data_delete) (GtkTreeDragSource *drag_source,
  140. -- GtkTreePath *path);
  141. -- } GtkTreeDragSourceIface;
  142. end