Re: multiple-item drag-and-drop



After some further investigation, it seems that the code I posted in
the previous message works for windows taller than a certain height.
I've simplified it below to concentrate on the
scrolling-whilst-dragging problem.

For short windows where, for instance, only a couple of lines of the
Simple::List are visible, although it scrolls OK in both directions,
scrolling up seems to be automatic; "going up" is never printed. So:

1. What is doing this automatic scrolling?
2. Why is it getting turned off in the original example?
3. What is the best way of determining the height of a row of a
Simple::List to improve the logic of the if-statement in the
'drag-motion' callback?

Jeff

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw(TRUE FALSE);             # To get TRUE and FALSE
use Gtk2 -init;
use Gtk2::Ex::Simple::List;
use Storable qw(freeze thaw);

my $win = Gtk2::Window->new;
$win->signal_connect (delete_event => sub { Gtk2->main_quit; });

my $scwin = Gtk2::ScrolledWindow -> new;
$win->add ($scwin);
$scwin -> set_policy ('automatic', 'automatic');

my $slist = Gtk2::Ex::Simple::List->new ( 'Int' => 'int' );
for (my $i = 1; $i < 21; $i++) {
  push @{$slist->{data}}, $i;
}
$slist -> set_reorderable( TRUE );
$slist -> get_selection -> set_mode ('multiple');


# If dragged below the bottom of the window, scroll it.
$slist->signal_connect('drag-motion' => sub {
  my ($tree, $dnd, $x, $y, $t) = @_;
 my ($path, $how) = $tree->get_dest_row_at_pos($x, $y) or return;
 my $scroll = $tree->parent;
 $tree->set_drag_dest_row($path, $how);

 my $adj = $scroll->get_vadjustment;
 my ($value, $step) = ($adj->value, $adj->step_increment);

print "y $y, step $step\n";

 if ($y > $adj->page_size - $step/2) {
print "going down\n";
  my $v = $value + $step;
  my $m = $adj->upper - $adj->page_size;
  $adj->set_value($v > $m ? $m : $v);
 }
  elsif ($y < ($tree->get_headers_visible ? $step : $step/2)) {
print "going up\n";
  my $v = $value - $step;
  my $m = $adj->lower;
  $adj->set_value($v < $m ? $m : $v);
 }

 return FALSE;
});

$scwin -> add($slist);

$win->show_all;
Gtk2->main;



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