2 * Copyright(c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
21 namespace Tizen.NUI.WindowSystem.Shell
24 /// Class for the Tizen KVM service.
26 /// This class is need to be hidden as inhouse API.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class KVMService : IDisposable
30 private TizenShell _tzsh;
31 private IntPtr _kvmService;
33 private bool disposed = false;
34 private bool isDisposeQueued = false;
36 private Interop.KVMService.KVMDragStartEventCallback _onDragStarted;
37 private Interop.KVMService.KVMDragEndEventCallback _onDragEnded;
39 private event EventHandler _dragStarted;
40 private event EventHandler _dragEnded;
43 /// Creates a new KVM Service handle.
45 /// <param name="tzShell">The TizenShell instance.</param>
46 /// <param name="win">The window to provide service of the quickpanel.</param>
47 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
48 /// <exception cref="ArgumentNullException">Thrown when a argument is null.</exception>
49 public KVMService(TizenShell tzShell, Window win)
53 throw new ArgumentNullException(nameof(tzShell));
55 if (tzShell.GetNativeHandle() == IntPtr.Zero)
57 throw new ArgumentException("tzShell is not initialized.");
61 throw new ArgumentNullException(nameof(win));
65 _tzshWin = win.GetNativeId();
66 _kvmService = Interop.KVMService.Create(_tzsh.GetNativeHandle(), (IntPtr)_tzshWin);
67 if (_kvmService == IntPtr.Zero)
69 int err = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
70 _tzsh.ErrorCodeThrow(err);
81 isDisposeQueued = true;
82 DisposeQueue.Instance.Add(this);
93 Dispose(DisposeTypes.Implicit);
97 Dispose(DisposeTypes.Explicit);
98 GC.SuppressFinalize(this);
103 protected virtual void Dispose(DisposeTypes type)
107 if (_kvmService != IntPtr.Zero)
109 int res = Interop.KVMService.Destroy(_kvmService);
110 _kvmService = IntPtr.Zero;
117 /// Emits the event when the drag started from any window.
119 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
120 public event EventHandler DragStarted
124 if (_dragStarted == null)
126 _onDragStarted = OnDragStarted;
127 int res = Interop.KVMService.SetDragStartEventHandler(_kvmService, _onDragStarted, IntPtr.Zero);
128 _tzsh.ErrorCodeThrow(res);
130 _dragStarted += value;
134 _dragStarted -= value;
135 if (_dragStarted == null)
137 int res = Interop.KVMService.SetDragStartEventHandler(_kvmService, null, IntPtr.Zero);
138 _tzsh.ErrorCodeThrow(res);
144 /// Emits the event when the drag ended on any window except KVM window.
146 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
147 public event EventHandler DragEnded
151 if (_dragEnded == null)
153 _onDragEnded = OnDragEnded;
154 int res = Interop.KVMService.SetDragEndEventHandler(_kvmService, _onDragEnded, IntPtr.Zero);
155 _tzsh.ErrorCodeThrow(res);
162 if (_dragEnded == null)
164 int res = Interop.KVMService.SetDragEndEventHandler(_kvmService, null, IntPtr.Zero);
165 _tzsh.ErrorCodeThrow(res);
170 private void OnDragStarted(IntPtr data, IntPtr softkeyService)
172 _dragStarted?.Invoke(this, EventArgs.Empty);
175 private void OnDragEnded(IntPtr data, IntPtr softkeyService)
177 _dragEnded?.Invoke(this, EventArgs.Empty);
181 /// Requests to perform drop to KVM window.
183 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
184 public void PerformDrop()
186 int res = Interop.KVMService.PerformDrop(_kvmService);
187 _tzsh.ErrorCodeThrow(res);
191 /// Requests to cancel current drag.
193 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
194 public void CancelDrag()
196 int res = Interop.KVMService.CancelDrag(_kvmService);
197 _tzsh.ErrorCodeThrow(res);
201 /// Requests to receive the current drag data.
202 /// the drag data will be received by the DragEvent of the window.
204 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
205 public void ReceiveDragData(string mimeType)
207 int res = Interop.KVMService.ReceiveDragData(_kvmService, mimeType);
208 _tzsh.ErrorCodeThrow(res);
212 /// Requests to set KVM window as secondary selection window.
213 /// The request name has typo and will remove soon.
214 /// Please use SetSecondarySelection.
216 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
217 public void SetSecondarySelction()
219 SetSecondarySelection();
223 /// Requests to unset secondary selection window of KVM window.
224 /// The request name has typo and will remove soon.
225 /// Please use UnsetSecondarySelection.
227 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
228 public void UnsetSecondarySelction()
230 UnsetSecondarySelection();
234 /// Requests to set KVM window as secondary selection window.
236 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
237 public void SetSecondarySelection()
239 int res = Interop.KVMService.SetSecondarySelection(_kvmService);
240 _tzsh.ErrorCodeThrow(res);
244 /// Requests to unset secondary selection window of KVM window.
246 /// <exception cref="ArgumentException">Thrown when failed of invalid argument.</exception>
247 public void UnsetSecondarySelection()
249 int res = Interop.KVMService.UnsetSecondarySelection(_kvmService);
250 _tzsh.ErrorCodeThrow(res);