0c266d39d7e47e141145234c532ec214e16b29c5
[platform/core/csapi/tizenfx.git] / test / NUIWindowKVMSample / NUIWindowKVMSample.cs
1 using System;
2 using Tizen;
3 using Tizen.NUI;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.WindowSystem;
6 using System.Collections.Generic;
7
8 namespace NUIWindowKVMSample
9 {
10     class Program : NUIApplication
11     {
12         protected override void OnCreate()
13         {
14             base.OnCreate();
15             Initialize();
16         }
17
18         void Initialize()
19         {
20             Window win = Window.Instance;
21             dnd = DragAndDrop.Instance;
22
23             win.WindowSize = new Size2D(500, 500);
24             win.KeyEvent += OnKeyEvent;
25             win.BackgroundColor = Color.White;
26
27             View windowView = new View();
28             windowView.Size2D = new Size2D(500, 500);
29             windowView.BackgroundColor = Color.White;
30             windowView.TouchEvent += OnTouchEvent;
31             win.Add(windowView);
32
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;
40             windowView.Add(text);
41
42             KVMServiceWindow kvmServiceWindow = new KVMServiceWindow(new Rectangle(2500, 0, 60, 1440));
43             kvmServiceWindow.Show();
44         }
45
46         private void OnKeyEvent(object sender, Window.KeyEventArgs e)
47         {
48             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
49             {
50                 Exit();
51             }
52         }
53
54         private bool OnTouchEvent(object sender, View.TouchEventArgs e)
55         {
56             if (e.Touch.GetState(0) == PointStateType.Down)
57             {
58                 View shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "NUIWindowKVMSample.png");
59                 shadowView.Size = new Size(100, 100);
60
61                 DragData dragData;
62                 dragData.MimeType = "text/plain";
63                 dragData.Data = "Hello World";
64                 dnd.StartDragAndDrop((View)sender, shadowView, dragData, OnSourceEventHandler);
65
66                 return true;
67             }
68
69             return false;
70         }
71
72         private void OnSourceEventHandler(DragSourceEventType e)
73         {
74             if (e == DragSourceEventType.Start)
75             {
76                 Log.Debug("KVMSample", "Source App SourceEvnetType: Start");
77             }
78             else if (e == DragSourceEventType.Cancel)
79             {
80                 Log.Debug("KVMSample", "Source App SourceEvnetType: Cancel");
81             }
82             else if (e == DragSourceEventType.Accept)
83             {
84                 Log.Debug("KVMSample", "Source App SourceEvnetType: Accept");
85             }
86             else if (e == DragSourceEventType.Finish)
87             {
88                 Log.Debug("KVMSample", "Source App SourceEvnetType: Finish");
89             }
90         }
91
92         static void Main(string[] args)
93         {
94             var app = new Program();
95             app.Run(args);
96         }
97
98         private DragAndDrop dnd;
99     }
100
101     class KVMServiceWindow : Window
102     {
103         public KVMServiceWindow(Rectangle winGeometry) :
104         base("KVM service Window", new Rectangle(winGeometry.X, winGeometry.Y, winGeometry.Width, winGeometry.Height))
105         {
106             dnd = DragAndDrop.Instance;
107             this.WindowSize = new Size2D(winGeometry.Width, winGeometry.Height);
108             this.BackgroundColor = Color.Yellow;
109
110             View windowView = new View();
111             windowView.Size2D = new Size2D(winGeometry.Width, winGeometry.Height);
112             windowView.BackgroundColor = Color.Yellow;
113             this.Add(windowView);
114
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);
118
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;
124         }
125
126         private void OnDnDEvent(object sender, DragEvent e)
127         {
128             if (e.DragType == DragType.Enter)
129             {
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();
135
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();
140             }
141             if (e.DragType == DragType.Drop)
142             {
143                 Log.Debug("KVMSample", "Target(KVM) App DRagEvnetType: Drop, Data: " + e.Data);
144             }
145         }
146
147         private void OnDragStarted(object sender, EventArgs e)
148         {
149             Log.Debug("KVMSample", "Tizen KVM: Drag started");
150
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");
154         }
155
156         private void OnDragEnded(object sender, EventArgs e)
157         {
158             Log.Debug("KVMSample", "Tizen KVM: Drag ended");
159         }
160
161         private DragAndDrop dnd;
162         private Tizen.NUI.WindowSystem.Shell.TizenShell tzShell;
163         private Tizen.NUI.WindowSystem.Shell.KVMService kvmService;
164     }
165 }