/src/wrappers/gtk/library/gtk_tree_drag_source.e

http://github.com/tybor/Liberty · Specman e · 185 lines · 55 code · 40 blank · 90 comment · 3 complexity · 3839100e9b8c91ae6bcd70cbab5bfd3b MD5 · raw file

  1. indexing
  2. description: "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_SOURCE
  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, wrapped into GTK_TREE_VIEW:
  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. -- gtk_tree_get_row_drag_data(). This API leaves a lot of
  26. -- flexibility, but nothing is done automatically, and implementing
  27. -- advanced features like hover-to-open-rows or autoscrolling on
  28. -- top of this 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
  34. G_OBJECT
  35. -- Note: GtkTreeDragSource inherits from GInterface, but GInterface
  36. -- doesn't have an Eiffel wrapper now, at I suspect that the
  37. -- generic GInterface wouldn't even need one. Paolo 2006-05-06
  38. -- GtkTreeDragSource is implemented by GtkTreeModelSort,
  39. -- GtkTreeStore, GtkListStore and GtkTreeModelFilter.
  40. feature
  41. is_action_successful: BOOLEAN
  42. delete_data (a_path: GTK_TREE_PATH) is
  43. -- Try to delete the row at `a_path', because it was moved
  44. -- somewhere else via drag-and-drop.
  45. -- `is_action_successful' will be False if the deletion
  46. -- fails because path no longer exists, or for some
  47. -- model-specific reason. Should robustly handle a path no
  48. -- longer found in the model!
  49. require valid_path: a_path /= Void
  50. do
  51. is_action_successful := (gtk_tree_drag_source_drag_data_delete (handle, a_path.handle)).to_boolean
  52. end
  53. data (a_path: GTK_TREE_PATH): GTK_SELECTION_DATA is
  54. -- Try to fill in `a_selection_data' with a representation of
  55. -- the row at path. `is_action_successful' will be True
  56. -- if data of the required type was provided.
  57. -- a_selection_data.target (Note: currently unimplemented;
  58. -- Paolo 2006-05-05) gives the required type of the
  59. -- data. Should robustly handle a path no longer found in the
  60. -- model!
  61. -- `a_path' : row that was dragged
  62. -- `a_selection_data' : a GtkSelectionData to fill with data from the dragged row
  63. do
  64. create Result.make
  65. is_action_successful := (gtk_tree_drag_source_drag_data_get (handle, a_path.handle, Result.handle)).to_boolean
  66. end
  67. is_row_draggable (a_path: GTK_TREE_PATH): BOOLEAN is
  68. -- Can `a_path' (i.e.: a particular row) be used as the
  69. -- source of a DND operation? If the source doesn't implement
  70. -- this interface, the row is assumed draggable. Note: This
  71. -- is a feature of GtkTreeDragSource
  72. do
  73. Result := (gtk_tree_drag_source_row_draggable (handle, a_path.handle)).to_boolean
  74. end
  75. -- TODO: understand usage and then wrap gtk_tree_set_row_drag_data ()
  76. -- gboolean gtk_tree_set_row_drag_data (GtkSelectionData
  77. -- *selection_data, GtkTreeModel *tree_model, GtkTreePath *path);
  78. -- Sets selection data of target type GTK_TREE_MODEL_ROW. Normally
  79. -- used in a drag_data_get handler.
  80. -- selection_data : some GtkSelectionData
  81. -- tree_model : a GtkTreeModel
  82. -- path : a row in tree_model
  83. -- Returns : TRUE if the GtkSelectionData had the proper target
  84. -- type to allow us to set a tree row
  85. -- TODO: understand usage and wrap gtk_tree_get_row_drag_data ()
  86. -- gboolean gtk_tree_get_row_drag_data (GtkSelectionData
  87. -- *selection_data, GtkTreeModel **tree_model, GtkTreePath **path);
  88. -- Obtains a tree_model and path from selection data of target type
  89. -- GTK_TREE_MODEL_ROW. Normally called from a drag_data_received
  90. -- handler. This function can only be used if selection_data
  91. -- originates from the same process that's calling this function,
  92. -- because a pointer to the tree model is being passed around. If
  93. -- you aren't in the same process, then you'll get memory
  94. -- corruption. In the GtkTreeDragDest drag_data_received handler,
  95. -- you can assume that selection data of type GTK_TREE_MODEL_ROW is
  96. -- in from the current process. The returned path must be freed
  97. -- with gtk_tree_path_free().
  98. -- selection_data : a GtkSelectionData
  99. -- tree_model : a GtkTreeModel
  100. -- path : row in tree_model
  101. -- Returns : TRUE if selection_data had target type GTK_TREE_MODEL_ROW and is
  102. -- otherwise valid
  103. feature {} -- External calls
  104. gtk_tree_drag_source_drag_data_delete (a_drag_source: POINTER; -- GtkTreeDragSource*
  105. a_path: POINTER -- GtkTreePath*
  106. ): INTEGER is -- gboolean
  107. external "C use <gtk/gtk.h>"
  108. end
  109. gtk_tree_drag_source_drag_data_get (a_drag_source: POINTER -- GtkTreeDragSource*
  110. a_path: POINTER; -- GtkTreePath*
  111. a_selection_data: POINTER -- GtkSelectionData*
  112. ): INTEGER is -- gboolean
  113. external "C use <gtk/gtk.h>"
  114. end
  115. gtk_tree_drag_source_row_draggable (a_drag_source: POINTER; -- GtkTreeDragSource*
  116. a_path: POINTER -- GtkTreePath*
  117. ): INTEGER is -- gboolean
  118. external "C use <gtk/gtk.h>"
  119. end
  120. -- gtk_tree_set_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData*
  121. -- a_tree_model: POINTER; -- GtkTreeModel*
  122. -- a_path: POINTER; -- GtkTreePath*
  123. -- ): INTEGER is -- gboolean
  124. -- external "C use <gtk/gtk.h>"
  125. -- end
  126. -- gtk_tree_get_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData
  127. -- a_tree_model_handle: POINTER -- GtkTreeModel **
  128. -- a_path_handle: POINTER -- GtkTreePath **path
  129. -- ): INTEGER is -- gboolean
  130. -- external "C use <gtk/gtk.h>"
  131. -- end
  132. feature {} -- TODO: wrap - if necessary - GtkTreeDragSourceIface
  133. -- typedef struct _GtkTreeDragSource GtkTreeDragSource;
  134. -- typedef struct {
  135. -- GTypeInterface g_iface;
  136. -- /* VTable - not signals */
  137. -- gboolean (* row_draggable) (GtkTreeDragSource *drag_source,
  138. -- GtkTreePath *path);
  139. -- gboolean (* drag_data_get) (GtkTreeDragSource *drag_source,
  140. -- GtkTreePath *path,
  141. -- GtkSelectionData *selection_data);
  142. -- gboolean (* drag_data_delete) (GtkTreeDragSource *drag_source,
  143. -- GtkTreePath *path);
  144. -- } GtkTreeDragSourceIface;
  145. end