Chris Morrison wrote:
> On Wed, 2007-06-27 at 10:43 +0100, Dave Howorth wrote:
>> I wrote:
>>> In particular, I believe you will also need to call
>>> gtk_tree_view_enable_model_drag_dest and/or
>>> gtk_tree_view_enable_model_drag_dest on the tree_view.
>> Oops. Second one should be gtk_tree_view_enable_model_drag_source of course.
>>
> I tried using gtk_tree_view_enable_model_drag_dest() on my tree view and
> it caused some really strange stuff to happen:

Odd, I've just had a good experience with it. I looked at the code that
implements gtk_tree_view_set_reorderable and saw that it calls the two
functions I mentioned. So it's a layered API but that's helpfully not
mentioned in the doc. Anyway, once I realized that, it was obvious that
I needed to replace my call to set_reorderable with my calls to
enable_model_drag_dest and enable_model_drag_source, rather than call
them in addition to it. It was also obvious that I needed to make sure
that I used the same arguments that it did so that the whole built-in
drag'n'drop mechanism kept working. Except I needed to change the one
argument that I wanted different behaviour for.

Now I can drag nodes from one view of the tree and drop them on another
view. Eliminates dragging/scrolling across thousands of nodes.

I'm using the Perl bindings, so my actual working code looks like this:

    # The target entry must match that used by
    # gtk_tree_view_set_reorderable in order for the built-in
    # drag'n'drop support to keep working
    # Except I use 'same-app' instead of 'same-widget'
    #
    my $target_entry = {
        target  => 'GTK_TREE_MODEL_ROW',
        flags   => ['same-app'],# Gtk2::TargetFlags
        info    => 0,
        };

# Alternatively:
#    my $target_entry = [ 'GTK_TREE_MODEL_ROW', 'same-app', 0 ];

    $tree_view->enable_model_drag_dest(
                        ['move'],
                        $target_entry,
                );

    $tree_view->enable_model_drag_source(
                        'button1-mask', # $start_button_mask,
                        ['move'],
                        $target_entry,
                );

> I got a segmentation fault when ever I tried to access the GList of
> targets in drag_context->targets in my drag_drop handler.
> 
> If I returned FALSE from my drag_drop handler (i.e. to indicate the drop
> was not over a valid area of the widget) the drag-data-received signal
> was emitted but then I got a GTK critical assertion failed error.
> 
> I think I might give up on the GtkTreeView and use a GtkIconView widget
> instead.

Not an option for me, since I'm playing with trees. I'd have to abandon
gtk altogether and move to another widget set, and probably language.
Swing, anybody? :)

Cheers, Dave
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to