Re: TreeModelFilter + drag and drop
- From: Yann Leboulanger <asterix lagaule org>
- To: gtk-list gnome org
- Subject: Re: TreeModelFilter + drag and drop
- Date: Tue, 20 Nov 2007 11:06:41 +0100
Kristian Rietveld wrote:
> On Sat, Nov 17, 2007 at 10:54:45PM +0100, Yann Leboulanger wrote:
>> I'd like to use Drag and drop on a treeview that gets data in a
>> TreeModelFilter. Of course at the begining I got this error:
>>
>> [snip]
>>
>> So what I understood is that I had to write a drag_drop handler and put
>> my code there instead of in the drag_data_received handler and finish by
>> stopping the propagation of the event. Am I right?
>
> You could indeed go that way and write a drag_drop handler. Since you
> will have to use gtk_drag_get_data() to retrieve the actual data that
> was dropped, you will probably end up implementing your own handler for
> drag_data_received as well (because gtk_drag_get_data() will trigger
> drag_data_received). Note that the default implementations of both of
> those handlers in GtkTreeView are not trivial at all; they contain logic
> to handle several special corner cases (drops on empty views, etc).
>
>> If so, the problem is that drag_drop handler don't get selection_data
>> and info parameters. Is there a way to get them? For selection_data this
>> can be a global variable, but for info, I don't see how to know if the
>> drop happend on a row, between 2 rows ...
>
> GtkTreeView just uses the (x, y) coordinates to figure out where you
> dropped. To determine if the user dropped in between or on a row, it
> just calculates where on the row the user dropped (vertically of
> course). If it was close to the row's edge, it will drop before or
> after; if the drop was closer to the middle of the row it will drop
> into. See gtk_tree_view_get_dest_row_at_pos().
>
> Instead of replicating this tree view code, it might be well easier to
> derive a new class from GtkTreeModelFilter and implement the
> GtkTreeDragDest here. See GtkTreeModelSort for an example how the
> GtkTreeDragDest implementation would look like, it should be very
> similar.
I just had a look at gtktreemodelfilter.c in gtk+-2.10.14, and I don't
see what has to be done. gtk_tree_model_filter_row_draggable,
gtk_tree_model_filter_drag_data_get,
gtk_tree_model_filter_drag_data_delete functions have code, and there is
no more function in tree gtktreemodelsort.c about TreeDragSource interface.
What did I miss?
> At some point in the future the GtkTreeModelFilter might
> implement the GtkTreeDragDest interface by default, but all kinds of
> interesting problems turn up, such as:
>
> ROW 1
> [row 2]
> [row 3]
> ROW 4
>
> say rows 2 and 3 are hidden. The tree view will only display row 1 and
> 4. Say the user drops a row in between row 1 and 4, where would you
> insert it in the original model, where row 2 and 3 do exist and are
> "visible"?
My "root" model has a sort function, so that should handle this case.
>
>
> I hope this clears things up a bit.
>
>
> regards,
>
> -kris.
>
--
Yann
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]