Gtk2
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
examples/testdnd.pl view on Meta::CPAN
$context->finish (0, 0, $time);
}
sub source_drag_data_get {
my ($widget, $context, $data, $info, $time) = @_;
if ($info == TARGET_ROOTWIN) {
print ("I was dropped on the rootwin\n");
} else {
print "\$data is $data\n";
$data->set ($data->target, 8, "I'm Data!");
}
}
#/* The following is a rather elaborate example demonstrating/testing
# * changing of the window heirarchy during a drag - in this case,
# * via a "spring-loaded" popup window.
# */
$popup_window = undef;
$popped_up = 0;
$in_popup = 0;
$popdown_timer = 0;
$popup_timer = 0;
sub popdown_cb
{
$popdown_timer = 0;
$popup_window->hide();
$popped_up = 0;
return 0;
}
sub popup_motion
{
my ($widget, $context, $x, $y, $time) = @_;
if (!$in_popup)
{
$in_popup = 1;
if ($popdown_timer)
{
print ("removed popdown\n");
Glib::Source->remove ($popdown_timer);
$popdown_timer = 0;
}
}
return 1;
}
sub popup_leave {
my ($widget, $context, $time) = @_;
if ($in_popup)
{
$in_popup = 0;
if ($popdown_timer)
{
print ("added popdown\n");
$popdown_timer = Gtk2::Timeout->add (500, \&popdown_cb);
}
}
}
sub popup_cb {
if (!$popped_up)
{
if (!$popup_window)
{
my ($button, $table, $i, $j);
$popup_window = Gtk2::Window->new ('popup');
$popup_window->set_position('mouse');
$table = Gtk2::Table->new (3, 3, 0);
for ($i=0; $i<3; $i++) {
for ($j=0; $j<3; $j++)
{
$button = new Gtk2::Button ("$i,$j");
$table->attach ($button, $i, $i+1, $j, $j+1,
['expand','fill'],['expand','fill'], 0, 0);
$button->drag_dest_set ('all', ['copy', 'move'],
@target_table[0..1]); # no rootwin
$button->signal_connect ("drag_motion", \&popup_motion);
$button->signal_connect ("drag_leave", \&popup_leave);
}
}
$table->show_all ();
$popup_window->add($table);
}
$popup_window->show;
$popped_up = 1;
}
$popdown_timer = Glib::Timeout->add (500, \&popdown_cb);
print ("added popdown\n");
$popup_timer = 0;
return 0;
}
sub popsite_motion {
my ($widget, $context, $x, $y, $time) = @_;
if (!$popup_timer) {
$popup_timer = Glib::Timeout->add (500, \&popup_cb);
}
return 1;
}
sub popsite_leave {
my ($widget, $context, $time) = @_;
if ($popup_timer)
{
Glib::Source->remove ($popup_timer);
$popup_timer = 0;
}
}
sub source_drag_data_delete {
my ($widget, $context, $data) = @_;
print ("Delete the data!\n");
}
init Gtk2;
$window = new Gtk2::Window;
$window->signal_connect('destroy', sub {Gtk2->main_quit});
$table = new Gtk2::Table(2, 2, 0);
$window->add($table);
($drag_icon, $drag_mask) = Gtk2::Gdk::Pixmap->colormap_create_from_xpm_d (
undef, $window->get_colormap(), undef, @drag_icon_xpm);
($trashcan_open, $trashcan_open_mask) = Gtk2::Gdk::Pixmap->colormap_create_from_xpm_d (
undef, $window->get_colormap(), undef, @trashcan_open_xpm);
($trashcan_closed, $trashcan_closed_mask) = Gtk2::Gdk::Pixmap->colormap_create_from_xpm_d (
undef, $window->get_colormap(), undef, @trashcan_closed_xpm);
$label = new Gtk2::Label("Drop Here\n");
$label->drag_dest_set('all', ['copy', 'move'], @target_table[0..1]); # no rootwin
$label->signal_connect("drag_data_received", \&label_drag_data_received);
$table->attach ($label, 0, 1, 0, 1, ['expand', 'fill'], ['expand', 'fill'], 0, 0);
$label = new Gtk2::Label("Popup\n");
$label->drag_dest_set('all', ['copy', 'move'], @target_table[0..1]); # no rootwin
$table->attach ($label, 1, 2, 1, 2, ['expand', 'fill'], ['expand', 'fill'], 0, 0);
$label->signal_connect ("drag_motion", \&popsite_motion);
$label->signal_connect ("drag_leave", \&popsite_leave);
$pixmap = Gtk2::Image->new_from_pixmap ($trashcan_closed, $trashcan_closed_mask);
$pixmap->drag_dest_set ([], []);
$table->attach ($pixmap, 1, 2, 0, 1, ['expand', 'fill'], ['expand', 'fill'], 0, 0);
$pixmap->signal_connect ("drag_leave", \&target_drag_leave);
$pixmap->signal_connect ("drag_motion", \&target_drag_motion);
$pixmap->signal_connect ("drag_drop", \&target_drag_drop);
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.437 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )