PageRenderTime 14ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1indexing
  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					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20				]"
 21
 22deferred class GTK_TREE_DRAG_SOURCE
 23	-- GTK+ supports Drag-and-Drop in tree views with a high-level and
 24	-- a low-level API.
 25	
 26	-- The low-level API consists of the GTK+ DND API, augmented by
 27	-- some treeview utility functions, wrapped into GTK_TREE_VIEW:
 28	-- set_drag_dest_row, get_drag_dest_row, get_dest_row_at_pos,
 29	-- create_row_drag_icon, _set_row_drag_data() and
 30	-- gtk_tree_get_row_drag_data(). This API leaves a lot of
 31	-- flexibility, but nothing is done automatically, and implementing
 32	-- advanced features like hover-to-open-rows or autoscrolling on
 33	-- top of this API is a lot of work.
 34	
 35	-- On the other hand, if you write to the high-level API, then all
 36	-- the bookkeeping of rows is done for you, as well as things like
 37	-- hover-to-open and auto-scroll, but your models have to implement
 38	-- the GtkTreeDragSource and GtkTreeDragDest interfaces.
 39	
 40inherit
 41	G_OBJECT
 42	
 43		-- Note: GtkTreeDragSource inherits from GInterface, but GInterface
 44		-- doesn't have an Eiffel wrapper now, at I suspect that the
 45	-- generic GInterface wouldn't even need one. Paolo 2006-05-06
 46
 47	-- GtkTreeDragSource is implemented by GtkTreeModelSort,
 48	-- GtkTreeStore, GtkListStore and GtkTreeModelFilter.
 49
 50feature
 51
 52	is_action_successful: BOOLEAN
 53
 54	delete_data (a_path: GTK_TREE_PATH) is
 55			-- Try to delete the row at `a_path', because it was moved
 56			-- somewhere else via drag-and-drop.
 57			-- `is_action_successful' will be False if the deletion
 58			-- fails because path no longer exists, or for some
 59			-- model-specific reason. Should robustly handle a path no
 60			-- longer found in the model!
 61		require valid_path: a_path /= Void
 62		do
 63			is_action_successful := (gtk_tree_drag_source_drag_data_delete (handle, a_path.handle)).to_boolean
 64		end
 65
 66	data (a_path: GTK_TREE_PATH): GTK_SELECTION_DATA is
 67			-- Try to fill in `a_selection_data' with a representation of
 68			-- the row at path. `is_action_successful' will be True
 69			-- if data of the required type was provided.
 70			-- a_selection_data.target (Note: currently unimplemented;
 71			-- Paolo 2006-05-05) gives the required type of the
 72			-- data. Should robustly handle a path no longer found in the
 73			-- model!
 74
 75			-- `a_path' : 	row that was dragged
 76
 77			-- `a_selection_data' : 	a GtkSelectionData to fill with data from the dragged row
 78		do
 79			create Result.make
 80			is_action_successful := (gtk_tree_drag_source_drag_data_get (handle, a_path.handle, Result.handle)).to_boolean
 81		end
 82
 83	is_row_draggable (a_path: GTK_TREE_PATH): BOOLEAN is
 84			-- Can `a_path' (i.e.: a particular row) be used as the
 85			-- source of a DND operation? If the source doesn't implement
 86			-- this interface, the row is assumed draggable. Note: This
 87			-- is a feature of GtkTreeDragSource
 88		do
 89			Result := (gtk_tree_drag_source_row_draggable (handle, a_path.handle)).to_boolean
 90		end
 91
 92	-- TODO: understand usage and then wrap gtk_tree_set_row_drag_data ()
 93
 94	-- gboolean gtk_tree_set_row_drag_data (GtkSelectionData
 95	-- *selection_data, GtkTreeModel *tree_model, GtkTreePath *path);
 96	
 97	-- Sets selection data of target type GTK_TREE_MODEL_ROW. Normally
 98	-- used in a drag_data_get handler.
 99	
100	-- selection_data : 	some GtkSelectionData
101	-- tree_model : 	a GtkTreeModel
102	-- path : 	a row in tree_model
103	-- Returns : 	TRUE if the GtkSelectionData had the proper target
104	-- type to allow us to set a tree row
105
106	-- TODO: understand usage and wrap gtk_tree_get_row_drag_data ()
107	
108	-- gboolean gtk_tree_get_row_drag_data (GtkSelectionData
109	-- *selection_data, GtkTreeModel **tree_model, GtkTreePath **path);
110
111	-- Obtains a tree_model and path from selection data of target type
112	-- GTK_TREE_MODEL_ROW. Normally called from a drag_data_received
113	-- handler. This function can only be used if selection_data
114	-- originates from the same process that's calling this function,
115	-- because a pointer to the tree model is being passed around. If
116	-- you aren't in the same process, then you'll get memory
117	-- corruption. In the GtkTreeDragDest drag_data_received handler,
118	-- you can assume that selection data of type GTK_TREE_MODEL_ROW is
119	-- in from the current process. The returned path must be freed
120	-- with gtk_tree_path_free().
121
122	-- selection_data : 	a GtkSelectionData
123	-- tree_model : 	a GtkTreeModel
124	-- path : 	row in tree_model
125	-- Returns : 	TRUE if selection_data had target type GTK_TREE_MODEL_ROW and is
126	-- 		otherwise valid
127
128feature {} -- External calls
129	
130	gtk_tree_drag_source_drag_data_delete (a_drag_source: POINTER; -- GtkTreeDragSource*
131														a_path: POINTER -- GtkTreePath*
132														): INTEGER is -- gboolean
133		external "C use <gtk/gtk.h>"
134		end
135
136	gtk_tree_drag_source_drag_data_get (a_drag_source: POINTER -- GtkTreeDragSource*
137													a_path: POINTER; -- GtkTreePath*
138													a_selection_data: POINTER -- GtkSelectionData*
139													): INTEGER is -- gboolean
140		external "C use <gtk/gtk.h>"
141		end
142
143	gtk_tree_drag_source_row_draggable (a_drag_source: POINTER; -- GtkTreeDragSource*
144													a_path: POINTER -- GtkTreePath*
145													): INTEGER is -- gboolean
146		external "C use <gtk/gtk.h>"
147		end
148
149-- 	gtk_tree_set_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData*
150-- 										 a_tree_model: POINTER; -- GtkTreeModel*
151-- 										 a_path: POINTER; -- GtkTreePath*
152-- 										 ): INTEGER is -- gboolean
153-- 		external "C use <gtk/gtk.h>"
154-- 		end
155	
156-- 	gtk_tree_get_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData
157-- 										 a_tree_model_handle: POINTER -- GtkTreeModel **
158-- 										 a_path_handle: POINTER -- GtkTreePath **path
159-- 										 ): INTEGER is -- gboolean
160-- 		external "C use <gtk/gtk.h>"
161-- 		end
162
163feature {}	-- TODO: wrap - if necessary - GtkTreeDragSourceIface
164	
165	-- typedef struct _GtkTreeDragSource GtkTreeDragSource;
166
167
168
169	-- typedef struct {
170	--   GTypeInterface g_iface;
171
172	--   /* VTable - not signals */
173
174	--   gboolean     (* row_draggable)        (GtkTreeDragSource   *drag_source,
175	-- 													  GtkTreePath         *path);
176
177	--   gboolean     (* drag_data_get)        (GtkTreeDragSource   *drag_source,
178	-- 													  GtkTreePath         *path,
179	-- 													  GtkSelectionData    *selection_data);
180
181	--   gboolean     (* drag_data_delete)     (GtkTreeDragSource *drag_source,
182	-- 													  GtkTreePath       *path);
183	-- } GtkTreeDragSourceIface;
184
185end