PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1indexing
  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					
  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_DEST
 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: GTK_TREE_VIEW's
 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	-- get_row_drag_data. This API leaves a lot of flexibility, but
 31	-- nothing is done automatically, and implementing advanced
 32	-- features like hover-to-open-rows or autoscrolling on top of this
 33	-- 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 G_OBJECT
 41	
 42	-- Object Hierarchy: inherits from GInterface
 43
 44	-- Known Implementations: GtkTreeDragSource is implemented by
 45	-- GtkTreeModelSort, GtkTreeStore, GtkListStore and
 46	-- GtkTreeModelFilter.
 47
 48	-- GtkTreeDragDest is implemented by GtkTreeStore and GtkListStore.
 49feature -- 
 50	is_last_action_successful: BOOLEAN
 51		
 52	receive_data (a_path: GTK_TREE_PATH; a_selection_data: GTK_SELECTION_DATA) is
 53			-- Try to insert a row before `a_path', deriving the contents
 54			-- of the row from
 55			-- `a_selection_data'. `is_last_action_successful' will be
 56			-- False if `a_path' is outside the tree so that inserting
 57			-- before it is impossible; it will also be False if the new
 58			-- row is not created for some model-specific reason. Should
 59			-- robustly handle a dest no longer found in the model!
 60		require 
 61			valid_path: a_path /= Void
 62			valid_data: a_selection_data /= Void
 63		do
 64			is_last_action_successful :=
 65				(gtk_tree_drag_dest_drag_data_received
 66				 (handle, a_path.handle, a_selection_data.handle)).to_boolean
 67		end
 68	
 69	is_row_drop_possible (a_path: GTK_TREE_PATH; a_selection_data: GTK_SELECTION_DATA): BOOLEAN is
 70			-- Determines whether a drop is possible before the given
 71			-- dest_path, at the same depth as dest_path. i.e., can we
 72			-- drop the data in selection_data at that
 73			-- location. dest_path does not have to exist; the return
 74			-- value will almost certainly be FALSE if the parent of
 75			-- dest_path doesn't exist, though.
 76		
 77			-- drag_dest : 	a GtkTreeDragDest
 78			-- dest_path : 	destination row
 79			-- selection_data : 	the data being dragged
 80			-- Returns : 	TRUE if a drop is possible before dest_path
 81		require 
 82			valid_path: a_path /= Void
 83			valid_data: a_selection_data /= Void
 84		do
 85			Result := (gtk_tree_drag_dest_row_drop_possible
 86						  (handle, a_path.handle, a_selection_data.handle)).to_boolean
 87		end
 88
 89
 90
 91feature -- TODO: GtkTreeDragDestIface
 92
 93	-- typedef struct {
 94	--   GTypeInterface g_iface;
 95	
 96	--   /* VTable - not signals */
 97	
 98	--   gboolean     (* drag_data_received) (GtkTreeDragDest   *drag_dest,
 99	-- 													GtkTreePath       *dest,
100	-- 													GtkSelectionData  *selection_data);
101	
102	--   gboolean     (* row_drop_possible)  (GtkTreeDragDest   *drag_dest,
103	-- 													GtkTreePath       *dest_path,
104	-- 						                     GtkSelectionData  *selection_data);
105	-- } GtkTreeDragDestIface;
106
107
108	-- gtk_tree_set_row_drag_data ()
109	
110	-- gboolean    gtk_tree_set_row_drag_data      (GtkSelectionData *selection_data,
111	-- 															GtkTreeModel *tree_model,
112	-- 															GtkTreePath *path);
113
114	-- Sets selection data of target type GTK_TREE_MODEL_ROW. Normally used in a drag_data_get handler.
115
116	-- selection_data : 	some GtkSelectionData
117	-- tree_model : 	a GtkTreeModel
118	-- path : 	a row in tree_model
119	-- Returns : 	TRUE if the GtkSelectionData had the proper target type to allow us to set a tree row
120	-- gtk_tree_get_row_drag_data ()
121
122	-- gboolean    gtk_tree_get_row_drag_data      (GtkSelectionData *selection_data,
123	-- 															GtkTreeModel **tree_model,
124	-- 															GtkTreePath **path);
125
126	-- 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().
127
128	-- selection_data : 	a GtkSelectionData
129	-- tree_model : 	a GtkTreeModel
130	-- path : 	row in tree_model
131	-- Returns : 	TRUE if selection_data had target type GTK_TREE_MODEL_ROW and is otherwise valid
132feature {} -- External calls
133	gtk_tree_drag_dest_drag_data_received (a_drag_dest: POINTER; -- GtkTreeDragDest*
134														a_dest: POINTER; -- GtkTreePath*
135														a_selection_data: POINTER -- GtkSelectionData*
136														): INTEGER is -- gboolean
137		external "C use <gtk/gtk.h>"
138		end
139	
140	gtk_tree_drag_dest_row_drop_possible (a_drag_dest: POINTER; -- GtkTreeDragDest*
141													  a_dest_path: POINTER; -- GtkTreePath *
142													  a_selection_data: POINTER -- GtkSelectionData
143													  ): INTEGER is -- gboolean
144		external "C use <gtk/gtk.h>"
145		end
146
147-- 	gtk_tree_set_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData*
148-- 										 a_tree_model: POINTER; -- GtkTreeModel*
149-- 										 a_path: POINTER; -- GtkTreePath*
150-- 										 ): INTEGER is -- gboolean
151-- 		external "C use <gtk/gtk.h>"
152-- 		end
153	
154-- 	gtk_tree_get_row_drag_data (a_selection_data: POINTER; -- GtkSelectionData
155-- 										 a_tree_model_handle: POINTER -- GtkTreeModel **
156-- 										 a_path_handle: POINTER -- GtkTreePath **path
157-- 										 ): INTEGER is -- gboolean
158-- 		external "C use <gtk/gtk.h>"
159-- 		end
160
161feature {}	-- TODO: wrap - if necessary - GtkTreeDragSourceIface
162	
163	-- typedef struct _GtkTreeDragSource GtkTreeDragSource;
164
165
166
167	-- typedef struct {
168	--   GTypeInterface g_iface;
169
170	--   /* VTable - not signals */
171
172	--   gboolean     (* row_draggable)        (GtkTreeDragSource   *drag_source,
173	-- 													  GtkTreePath         *path);
174
175	--   gboolean     (* drag_data_get)        (GtkTreeDragSource   *drag_source,
176	-- 													  GtkTreePath         *path,
177	-- 													  GtkSelectionData    *selection_data);
178
179	--   gboolean     (* drag_data_delete)     (GtkTreeDragSource *drag_source,
180	-- 													  GtkTreePath       *path);
181	-- } GtkTreeDragSourceIface;
182
183end