~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Samples/Samples/DragDrop.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using Xwt;
 
3
using Xwt.Drawing;
 
4
 
 
5
namespace Samples
 
6
{
 
7
        public class DragDrop: VBox
 
8
        {
 
9
                Button b2;
 
10
                public DragDrop ()
 
11
                {
 
12
                        HBox box = new HBox ();
 
13
                        
 
14
                        SimpleBox b1 = new SimpleBox (30);
 
15
                        box.PackStart (b1, BoxMode.None);
 
16
                        
 
17
                        b2 = new Button ("Drop here");
 
18
                        box.PackEnd (b2, BoxMode.None);
 
19
                        
 
20
                        b1.ButtonPressed += delegate {
 
21
                                var d = b1.CreateDragOperation ();
 
22
                                d.Data.AddValue ("Hola");
 
23
                                var img = Image.FromResource (GetType(), "class.png");
 
24
                                d.SetDragImage (img, (int)img.Size.Width, (int)img.Size.Height);
 
25
                                d.AllowedActions = DragDropAction.All;
 
26
                                d.Start ();
 
27
                        };
 
28
                        
 
29
                        b2.SetDragDropTarget (TransferDataType.Text, TransferDataType.Uri);
 
30
                        PackStart (box);
 
31
                        
 
32
                        b2.DragDrop += HandleB2DragDrop;
 
33
                        b2.DragOver += HandleB2DragOver;
 
34
                }
 
35
 
 
36
                void HandleB2DragOver (object sender, DragOverEventArgs e)
 
37
                {
 
38
                        if (e.Action == DragDropAction.All)
 
39
                                e.AllowedAction = DragDropAction.Move;
 
40
                        else
 
41
                                e.AllowedAction = e.Action;
 
42
                }
 
43
 
 
44
                void HandleB2DragDrop (object sender, DragEventArgs e)
 
45
                {
 
46
                        Console.WriteLine ("Dropped! " + e.Action);
 
47
                        Console.WriteLine ("Text: " + e.Data.GetValue (TransferDataType.Text));
 
48
                        Console.WriteLine ("Uris:");
 
49
                        foreach (var u in e.Data.Uris)
 
50
                                Console.WriteLine ("u:" + u);
 
51
                        e.Success = true;
 
52
                        b2.Label = "Dropped!";
 
53
                }
 
54
        }
 
55
}
 
56