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;
20 using System.Runtime.InteropServices;
25 /// This specifies clipboard event data.
27 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815: Override equals and operator equals on value types")]
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public struct ClipEvent
32 /// The mime type of clipboard event data.
34 public string MimeType { get; set; }
36 /// The clipboard event data to receive.
38 public string Data { get; set; }
42 /// ClipboardEventArgs is a class to record clipboard event arguments which will be sent to user.<br/>
43 /// This is for internal use only.
45 internal class ClipboardEventArgs : EventArgs
48 /// True if data receive is successful.
50 public bool Success { get; set; }
53 /// The data request id to identify the response by request.
55 public uint Id { get; set; }
58 /// Clipboard event data.
60 public ClipEvent ClipEvent { get; set; }
66 public partial class Clipboard
68 private EventHandler<ClipboardEventArgs> clipboardDataReceivedEventHandler;
69 private ClipboardDataReceivedCallback clipboardDataReceivedCallback;
71 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
72 private delegate void ClipboardDataReceivedCallback(uint id, string mimeType, string data);
74 private event EventHandler<ClipboardEventArgs> ClipboardDataReceived
78 if (clipboardDataReceivedEventHandler == null)
80 clipboardDataReceivedCallback = (OnClipboardDataReceived);
81 ClipboardDataReceivedSignal().Connect(clipboardDataReceivedCallback);
83 clipboardDataReceivedEventHandler += value;
87 clipboardDataReceivedEventHandler -= value;
88 if (clipboardDataReceivedEventHandler == null && ClipboardDataReceivedSignal().Empty() == false)
90 ClipboardDataReceivedSignal().Disconnect(clipboardDataReceivedCallback);
95 internal ClipboardSignal ClipboardDataReceivedSignal()
97 var ret = new ClipboardSignal(Interop.Clipboard.ClipboardDataReceivedSignal(SwigCPtr), false);
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 private void OnClipboardDataReceived(uint id, string mimeType, string data)
104 var e = new ClipboardEventArgs();
105 var clipEvent = new ClipEvent()
110 e.ClipEvent = clipEvent;
112 e.Success = (String.IsNullOrEmpty(e.ClipEvent.MimeType) && String.IsNullOrEmpty(e.ClipEvent.Data)) ? false : true;
114 clipboardDataReceivedEventHandler?.Invoke(this, e);