On Mon, 2007-10-29 at 11:29 +0000, Dave Howorth wrote:
Firstly, my tree has more than one column and as soon as I change the call to MyTreeStore->new to have more than one column, I get the error again e.g.: my $tree_store = MyTreeStore->new(qw/Glib::String Glib::Int/); type MyTreeStore does not support property 'Glib::String' At least I now know that the error is caused by multiple args. Any idea on how to make the constructor work for trees with multiple columns? I'll keep experimenting.
Ah. This happens because you get Glib::Object::new by default for custom subclasses. This would be fixable by using Gtk2::TreeStore::set_column_types in a custom new(), but see below.
I don't think my code is where I need it to be overridden. I don't have any plans to call drag_data_received. It's called automatically by gtk+ as part of the treeview drag'n'drop mechanism. What I do want to do is influence what it does. From what you say, I suspect I can't to this.
I see. Unfortunately, it doesn't seem to be possible to override just one interface method of some class (like row-drop-possible). You have to implement the whole interface, and that means implementing a completely custom tree model. But I think you can achieve what you want by using Gtk2::Widget's d'n'd stuff. For example: $view->signal_connect(drag_data_received => sub { my ($view, $context, $x, $y, $data, $info, $time) = @_; my ($model, $src) = $data->get_row_drag_data; my ($dest, $pos) = $view->get_drag_dest_row; return unless defined $dest; # If src and dest aren't on the same level or the user tries to move a # child into another ... if ($src->get_depth != $dest->get_depth || ($pos ne 'after' && $pos ne 'before')) { # ... inhibit the drop by giving the context an empty status, ... $context->status ([], $time); # ... and tell the tree view to not draw drop thingies. $view->set_drag_dest_row (undef, 'before'); return; } }); (Complete program attached.) -- Bye, -Torsten
Attachment:
inhibit-dnd.pl
Description: Perl program