4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.WindowSystem;
6 using System.Collections.Generic;
8 namespace NUIWindowKVMSample
10 class Program : NUIApplication
12 protected override void OnCreate()
20 Window win = Window.Instance;
21 dnd = DragAndDrop.Instance;
23 win.WindowSize = new Size2D(500, 500);
24 win.KeyEvent += OnKeyEvent;
25 win.BackgroundColor = Color.White;
27 View windowView = new View();
28 windowView.Size2D = new Size2D(500, 500);
29 windowView.BackgroundColor = Color.White;
30 windowView.TouchEvent += OnTouchEvent;
33 TextLabel text = new TextLabel("Start drag here");
34 text.HorizontalAlignment = HorizontalAlignment.Center;
35 text.VerticalAlignment = VerticalAlignment.Center;
36 text.TextColor = Color.Black;
37 text.PointSize = 12.0f;
38 text.HeightResizePolicy = ResizePolicyType.FillToParent;
39 text.WidthResizePolicy = ResizePolicyType.FillToParent;
42 KVMServiceWindow kvmServiceWindow = new KVMServiceWindow(new Rectangle(2500, 0, 60, 1440));
43 kvmServiceWindow.Show();
46 private void OnKeyEvent(object sender, Window.KeyEventArgs e)
48 if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
54 private bool OnTouchEvent(object sender, View.TouchEventArgs e)
56 if (e.Touch.GetState(0) == PointStateType.Down)
58 View shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "NUIWindowKVMSample.png");
59 shadowView.Size = new Size(100, 100);
62 dragData.MimeType = "text/plain";
63 dragData.Data = "Hello World";
64 dnd.StartDragAndDrop((View)sender, shadowView, dragData, OnSourceEventHandler);
72 private void OnSourceEventHandler(DragSourceEventType e)
74 if (e == DragSourceEventType.Start)
76 Log.Debug("KVMSample", "Source App SourceEvnetType: Start");
78 else if (e == DragSourceEventType.Cancel)
80 Log.Debug("KVMSample", "Source App SourceEvnetType: Cancel");
82 else if (e == DragSourceEventType.Accept)
84 Log.Debug("KVMSample", "Source App SourceEvnetType: Accept");
86 else if (e == DragSourceEventType.Finish)
88 Log.Debug("KVMSample", "Source App SourceEvnetType: Finish");
92 static void Main(string[] args)
94 var app = new Program();
98 private DragAndDrop dnd;
101 class KVMServiceWindow : Window
103 public KVMServiceWindow(Rectangle winGeometry) :
104 base("KVM service Window", new Rectangle(winGeometry.X, winGeometry.Y, winGeometry.Width, winGeometry.Height))
106 dnd = DragAndDrop.Instance;
107 this.WindowSize = new Size2D(winGeometry.Width, winGeometry.Height);
108 this.BackgroundColor = Color.Yellow;
110 View windowView = new View();
111 windowView.Size2D = new Size2D(winGeometry.Width, winGeometry.Height);
112 windowView.BackgroundColor = Color.Yellow;
113 this.Add(windowView);
115 // The First argument of listener should be window, not view.
116 // The listener of view couldn't catch receive data from ReceiveDragData of KVMService
117 dnd.AddListener(this, OnDnDEvent);
119 tzShell = new Tizen.NUI.WindowSystem.Shell.TizenShell();
120 kvmService = new Tizen.NUI.WindowSystem.Shell.KVMService(tzShell, this);
121 kvmService.SetSecondarySelction();
122 kvmService.DragStarted += OnDragStarted;
123 kvmService.DragEnded += OnDragEnded;
126 private void OnDnDEvent(object sender, DragEvent e)
128 if (e.DragType == DragType.Enter)
130 Log.Debug("KVMSample", "Target(KVM) App DRagEvnetType: Enter");
131 // PerformDrop is drop into the KVM window and finish the current drag.
132 // If you want to get the current drag data without end the drag,
133 // use ReceiveDragData(mimetype) instead of PerformDrop().
134 //kvmService.PerformDrop();
136 // The drag data will be received by ReceiveDragData of OnDragStarted callback and DragEvent of the OnDnDEvent callback.
137 // and the drag will be ended by enter the KVM window as UX of the app.
138 // If you want to end the drag without receive drag data, use CancelDrag().
139 kvmService.CancelDrag();
141 if (e.DragType == DragType.Drop)
143 Log.Debug("KVMSample", "Target(KVM) App DRagEvnetType: Drop, Data: " + e.Data);
147 private void OnDragStarted(object sender, EventArgs e)
149 Log.Debug("KVMSample", "Tizen KVM: Drag started");
151 // Request the drag data to the Display server.
152 // The drag data can get at DnD Listener (OnDnDEvent function)
153 kvmService.ReceiveDragData("text/plain");
156 private void OnDragEnded(object sender, EventArgs e)
158 Log.Debug("KVMSample", "Tizen KVM: Drag ended");
161 private DragAndDrop dnd;
162 private Tizen.NUI.WindowSystem.Shell.TizenShell tzShell;
163 private Tizen.NUI.WindowSystem.Shell.KVMService kvmService;