Implementing TreeDragDest interface with a TreeModelSort model



Hello,

I'd like to enable drag and drop on a Gtk2::TreeView that contains a
Gtk2::TreeModelSort as its model (actually this one contains also a
Gtk2::TreeModelFilter which contains a Gtk2::TreeStore, but this has no impact
here).

But when I try to use drag and drop, I get an error message:


Gtk-WARNING **: You must override the default 'drag_drop' handler on
GtkTreeView when using models that don't support the GtkTreeDragDest
interface and enabling drag-and-drop. The simplest way to do this is to
connect to 'drag_drop' and call g_signal_stop_emission_by_name() in your
signal handler to prevent the default handler from running. Look at the
source code for the default handler in gtktreeview.c to get an idea what
your handler should do. (gtktreeview.c is in the GTK source code.) If you're
using GTK from a language other than C, there may be a more natural way to
override default handlers, e.g. via derivation.


So I tried to add the interface to the TreeModelSort by implementing my own
class and planned to call the method from the underlying real model. But I
have the same error then, just as if the interface I added is ignored. I tried
to do as I found in documentation without any success.

I created a little program that reproduces this problem. I certainly did
something wrong with subclassing as it is the first time I used that. But I
don't know what as it seems to conform to the examples I saw and the print
shows correct list of interfaces. Find below the small program that shows my
problem. The error message is displayed when trying to drag and drop a row
anywhere else in the list.

Thank you for any help.

Christian Jodar.

#!/bin/perl

use strict;
use warnings;
use Data::Dumper;
use Gtk2;
Gtk2->init;

my $window = new Gtk2::Window('toplevel');

{
    package MyTreeModelSort;
    use Glib::Object::Subclass
        Gtk2::TreeModelSort::,
        interfaces => [ Gtk2::TreeDragDest:: ],
        ;

    sub new
    {
        my ($proto, $childModel) = @_;
        my $class = ref($proto) || $proto;
        my $self = Gtk2::TreeModelSort->new($childModel);
        bless ($self, $class);
        return $self;
    }
    sub DRAG_DATA_RECEIVED
    {
        print "DRAG_DATA_RECEIVED\n";
    }
    sub ROW_DROP_POSSIBLE
    {
        print "ROW_DROP_POSSIBLE\n";
    }
}

print "Interfaces :
\n",Dumper(Glib::Type->list_interfaces('MyTreeModelSort')),"\n"; my $model =
new Gtk2::TreeStore('Glib::String'); my $sorter = new MyTreeModelSort($model);
my $list = Gtk2::TreeView->new_with_model($sorter);
my $column = Gtk2::TreeViewColumn->new_with_attributes('Title',
Gtk2::CellRendererText->new, 'text' => 0); $list->append_column($column);

foreach ('a'..'z')
{
    my $iter = $model->append(undef);
    $model->set($iter, 0 => 'line'.$_);
}

my $targetEntryMove = {
    target => 'MY_ROW_TARGET',
    flags => ['same-widget'],
    info => 42,
};
$list->enable_model_drag_source('button1-mask','move', $targetEntryMove);
$list->enable_model_drag_dest('move', $targetEntryMove);

$window->add($list);
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->show_all;
Gtk2->main;




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