ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/DragHelper.pm
Revision: 1.1
Committed: Mon Mar 27 15:59:46 2006 UTC (20 years, 7 months ago) by elmex
Branch: MAIN
CVS Tags: rel-2_2, rel-2_0, rel-2_1
Log Message:
forgot draghelper

File Contents

# User Rev Content
1 elmex 1.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 Crossfire;
14     use Crossfire::Map;
15     use Crossfire::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;