Re: cancelling a drag from a widget




Elliott Hughes <Elliott.Hughes@genedata.com> writes:

> i've written a widget where, if the user uses gtk_drag_source_set,
> i only want a drag to start from certain `active' areas within the
> widget. how can i do this? basically, i want to check the x and
> y start coordinates of the drag from within drag_start, and tell
> gtk not to initiate a drag if it doesn't make sense from that part
> of the component.
> 
> i can get the relevant x and y coordinates from the button_press
> that comes before drag_start, but what i don't know how to do is
> prevent the drag. certainly, it seems that calling gtk_drag_finish
> from within drag_start causes trouble.
> 
> does this need drag_start to return gboolean, and have the code
> in gtkdnd.c check whether or not to continue, or is it possible in
> the system as it stands?

Once the drag starts from the source widget, GTK+ is completely
in control, and there are only two ways that the drag will
end:

 - the user releases the mouse, dropping the dragged item
 - the user presses Escape, cancelling the drag.

So, if you want to only allow drags from some places, you need
to keep the drag from being started in the first place. (Note
that it wouldn't look good to the user if they saw a drag
beginning, and then it immediately snapped back.)

The way to do this is to avoid gtk_drag_source_set() and call

 GdkDragContext *gtk_drag_begin (GtkWidget         *widget,
	  			 GtkTargetList     *targets,
				 GdkDragAction      actions,
				 gint               button,
				 GdkEvent          *event);

yourself when you want to trigger the drag. 

There is some information on this function and GtkTargetList
at:

 http://developer.gnome.og/doc/API/gtk/gtk-drag-and-drop.html
 http://developer.gnome.og/doc/API/gtk/gtk-selections.html

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]