/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace Tizen.NUI
{
///
/// This specifies clipboard event data.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815: Override equals and operator equals on value types")]
[EditorBrowsable(EditorBrowsableState.Never)]
public struct ClipEvent
{
///
/// The mime type of clipboard event data.
///
public string MimeType { get; set; }
///
/// The clipboard event data to receive.
///
public string Data { get; set; }
}
///
/// ClipboardEventArgs is a class to record clipboard event arguments which will be sent to user.
/// This is for internal use only.
///
internal class ClipboardEventArgs : EventArgs
{
///
/// True if data receive is successful.
///
public bool Success { get; set; }
///
/// The data request id to identify the response by request.
///
public uint Id { get; set; }
///
/// Clipboard event data.
///
public ClipEvent ClipEvent { get; set; }
}
///
/// Clipboard event.
///
public partial class Clipboard
{
private EventHandler clipboardDataReceivedEventHandler;
private ClipboardDataReceivedCallback clipboardDataReceivedCallback;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void ClipboardDataReceivedCallback(uint id, string mimeType, string data);
private event EventHandler ClipboardDataReceived
{
add
{
if (clipboardDataReceivedEventHandler == null)
{
clipboardDataReceivedCallback = (OnClipboardDataReceived);
ClipboardDataReceivedSignal().Connect(clipboardDataReceivedCallback);
}
clipboardDataReceivedEventHandler += value;
}
remove
{
clipboardDataReceivedEventHandler -= value;
if (clipboardDataReceivedEventHandler == null && ClipboardDataReceivedSignal().Empty() == false)
{
ClipboardDataReceivedSignal().Disconnect(clipboardDataReceivedCallback);
}
}
}
internal ClipboardSignal ClipboardDataReceivedSignal()
{
var ret = new ClipboardSignal(Interop.Clipboard.ClipboardDataReceivedSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private void OnClipboardDataReceived(uint id, string mimeType, string data)
{
var e = new ClipboardEventArgs();
var clipEvent = new ClipEvent()
{
MimeType = mimeType,
Data = data,
};
e.ClipEvent = clipEvent;
e.Id = id;
e.Success = (String.IsNullOrEmpty(e.ClipEvent.MimeType) && String.IsNullOrEmpty(e.ClipEvent.Data)) ? false : true;
clipboardDataReceivedEventHandler?.Invoke(this, e);
}
}
}