ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/DragHelper.pm
Revision: 1.2
Committed: Thu Dec 27 22:28:01 2007 UTC (16 years, 4 months ago) by root
Branch: MAIN
CVS Tags: pre_cursor_branch, HEAD
Branch point for: cursor
Changes since 1.1: +3 -3 lines
Log Message:
upgrade Crossfire to Deliantra

File Contents

# Content
1 package GCE::DragHelper;
2
3 =head1 NAME
4
5 GCE::MapEditor - the map editing widget
6
7 =cut
8
9 use Gtk2;
10 use Gtk2::Gdk::Keysyms;
11 use Gtk2::SimpleMenu;
12
13 use Deliantra;
14 use Deliantra::Map;
15 use Deliantra::MapWidget;
16
17 use GCE::AttrEdit;
18 use GCE::Util;
19
20 use strict;
21
22 our $DRAGDATA = {};
23
24 sub set_drag_source {
25 my ($widget, $key, $value_cb) = @_;
26
27 $widget->drag_source_set (['button1_mask'], ['move'],
28 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
29 );
30 $widget->signal_connect (drag_data_get => sub {
31 my ($widget, $context, $data, $info, $time) = @_;
32 $data->set ($data->target, 8, $key);
33 $DRAGDATA->{$key} = $value_cb->();
34 });
35 }
36
37 sub set_drag_sink {
38 my ($widget, $key, $get_cb) = @_;
39
40 $widget->drag_dest_set (all => ['move'],
41 { target => 'STRING', flags => [], info => 'TARGET_STRING' }
42 );
43 # XXX: I'm unsure here, do i have to issue a get request?
44 # And what if i get the data twice? Wait for transaction end?
45 $widget->signal_connect (drag_data_received => sub {
46 my ($widget, $context, $wx, $wy, $data, $info, $time) = @_;
47
48 if (($data->length >= 0) && ($data->format == 8)) {
49
50 $context->finish (1, 0, $time);
51
52 if ($data->data eq $key) {
53 my $v = $DRAGDATA->{$data->data};
54 $get_cb->($v);
55 }
56
57 return;
58 }
59 $context->finish (0, 0, $time);
60 });
61
62 }
63
64 =head1 AUTHOR
65
66 Marc Lehmann <schmorp@schmorp.de>
67 http://home.schmorp.de/
68
69 Robin Redeker <elmex@ta-sa.org>
70 http://www.ta-sa.org/
71
72 =cut
73 1;