/*
* Copyright(c) 2021 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.BaseComponents
{
///
/// View is the base class for all views.
///
/// 3
public partial class View
{
private EventHandler offWindowEventHandler;
private OffWindowEventCallbackType offWindowEventCallback;
private EventHandlerWithReturnType wheelEventHandler;
private WheelEventCallbackType wheelEventCallback;
private EventHandlerWithReturnType keyEventHandler;
private KeyCallbackType keyCallback;
private EventHandlerWithReturnType interceptTouchDataEventHandler;
private TouchDataCallbackType interceptTouchDataCallback;
private EventHandlerWithReturnType touchDataEventHandler;
private TouchDataCallbackType touchDataCallback;
private EventHandlerWithReturnType hoverEventHandler;
private HoverEventCallbackType hoverEventCallback;
private EventHandler visibilityChangedEventHandler;
private VisibilityChangedEventCallbackType visibilityChangedEventCallback;
private EventHandler keyInputFocusGainedEventHandler;
private KeyInputFocusGainedCallbackType keyInputFocusGainedCallback;
private EventHandler keyInputFocusLostEventHandler;
private KeyInputFocusLostCallbackType keyInputFocusLostCallback;
private EventHandler onRelayoutEventHandler;
private OnRelayoutEventCallbackType onRelayoutEventCallback;
private EventHandler onWindowEventHandler;
private OnWindowEventCallbackType onWindowEventCallback;
private EventHandler layoutDirectionChangedEventHandler;
private LayoutDirectionChangedEventCallbackType layoutDirectionChangedEventCallback;
// Resource Ready Signal
private EventHandler resourcesLoadedEventHandler;
private ResourcesLoadedCallbackType ResourcesLoadedCallback;
private EventHandler backgroundResourceLoadedEventHandler;
private _backgroundResourceLoadedCallbackType backgroundResourceLoadedCallback;
private OnWindowEventCallbackType onWindowSendEventCallback;
private void SendViewAddedEventToWindow(IntPtr data)
{
// Unused parameter
_ = data;
NUIApplication.GetDefaultWindow()?.SendViewAdded(this);
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void OffWindowEventCallbackType(IntPtr control);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate bool KeyCallbackType(IntPtr control, IntPtr keyEvent);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate bool TouchDataCallbackType(IntPtr view, IntPtr touchData);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate bool HoverEventCallbackType(IntPtr view, IntPtr hoverEvent);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void ResourcesLoadedCallbackType(IntPtr control);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void _backgroundResourceLoadedCallbackType(IntPtr view);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void KeyInputFocusGainedCallbackType(IntPtr control);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void KeyInputFocusLostCallbackType(IntPtr control);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void OnRelayoutEventCallbackType(IntPtr control);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void OnWindowEventCallbackType(IntPtr control);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type);
///
/// Event when a child is removed.
///
/// 5
public new event EventHandler ChildRemoved;
///
/// Event when a child is added.
///
/// 5
public new event EventHandler ChildAdded;
///
/// An event for the KeyInputFocusGained signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The KeyInputFocusGained signal is emitted when the control gets the key input focus.
///
/// 3
public event EventHandler FocusGained
{
add
{
if (keyInputFocusGainedEventHandler == null)
{
keyInputFocusGainedCallback = OnKeyInputFocusGained;
this.KeyInputFocusGainedSignal().Connect(keyInputFocusGainedCallback);
}
keyInputFocusGainedEventHandler += value;
}
remove
{
keyInputFocusGainedEventHandler -= value;
if (keyInputFocusGainedEventHandler == null && KeyInputFocusGainedSignal().Empty() == false)
{
this.KeyInputFocusGainedSignal().Disconnect(keyInputFocusGainedCallback);
}
}
}
///
/// An event for the KeyInputFocusLost signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The KeyInputFocusLost signal is emitted when the control loses the key input focus.
///
/// 3
public event EventHandler FocusLost
{
add
{
if (keyInputFocusLostEventHandler == null)
{
keyInputFocusLostCallback = OnKeyInputFocusLost;
this.KeyInputFocusLostSignal().Connect(keyInputFocusLostCallback);
}
keyInputFocusLostEventHandler += value;
}
remove
{
keyInputFocusLostEventHandler -= value;
if (keyInputFocusLostEventHandler == null && KeyInputFocusLostSignal().Empty() == false)
{
this.KeyInputFocusLostSignal().Disconnect(keyInputFocusLostCallback);
}
}
}
///
/// An event for the KeyPressed signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The KeyPressed signal is emitted when the key event is received.
///
/// 3
public event EventHandlerWithReturnType KeyEvent
{
add
{
if (keyEventHandler == null)
{
keyCallback = OnKeyEvent;
this.KeyEventSignal().Connect(keyCallback);
}
keyEventHandler += value;
}
remove
{
keyEventHandler -= value;
if (keyEventHandler == null && KeyEventSignal().Empty() == false)
{
this.KeyEventSignal().Disconnect(keyCallback);
}
}
}
///
/// An event for the OnRelayout signal which can be used to subscribe or unsubscribe the event handler.
/// The OnRelayout signal is emitted after the size has been set on the view during relayout.
///
/// 3
public event EventHandler Relayout
{
add
{
if (onRelayoutEventHandler == null)
{
onRelayoutEventCallback = OnRelayout;
this.OnRelayoutSignal().Connect(onRelayoutEventCallback);
}
onRelayoutEventHandler += value;
}
remove
{
onRelayoutEventHandler -= value;
if (onRelayoutEventHandler == null && OnRelayoutSignal().Empty() == false)
{
this.OnRelayoutSignal().Disconnect(onRelayoutEventCallback);
onRelayoutEventCallback = null;
}
}
}
///
/// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The touched signal is emitted when the touch input is received.
/// This can receive touch events before child.
/// If it returns false, the child can receive the touch event. If it returns true, the touch event is intercepted. So child cannot receive touch event.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandlerWithReturnType InterceptTouchEvent
{
add
{
if (interceptTouchDataEventHandler == null)
{
interceptTouchDataCallback = OnInterceptTouch;
this.InterceptTouchSignal().Connect(interceptTouchDataCallback);
}
interceptTouchDataEventHandler += value;
}
remove
{
interceptTouchDataEventHandler -= value;
if (interceptTouchDataEventHandler == null && InterceptTouchSignal().Empty() == false)
{
this.InterceptTouchSignal().Disconnect(interceptTouchDataCallback);
}
}
}
///
/// If child view doesn't want the parent's view to intercept the touch, you can set it to true.
/// for example :
/// parent.Add(child);
/// parent.InterceptTouchEvent += OnInterceptTouchEvent;
/// View view = child.GetParent() as View;
/// view.DisallowInterceptTouchEvent = true;
/// This prevents the parent from intercepting touch.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public bool DisallowInterceptTouchEvent { get; set; }
///
/// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The touched signal is emitted when the touch input is received.
///
/// 3
public event EventHandlerWithReturnType TouchEvent
{
add
{
if (touchDataEventHandler == null)
{
touchDataCallback = OnTouch;
this.TouchSignal().Connect(touchDataCallback);
}
touchDataEventHandler += value;
}
remove
{
touchDataEventHandler -= value;
if (touchDataEventHandler == null && TouchSignal().Empty() == false)
{
this.TouchSignal().Disconnect(touchDataCallback);
}
}
}
///
/// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The hovered signal is emitted when the hover input is received.
///
/// 3
public event EventHandlerWithReturnType HoverEvent
{
add
{
if (hoverEventHandler == null)
{
hoverEventCallback = OnHoverEvent;
this.HoveredSignal().Connect(hoverEventCallback);
}
hoverEventHandler += value;
}
remove
{
hoverEventHandler -= value;
if (hoverEventHandler == null && HoveredSignal().Empty() == false)
{
this.HoveredSignal().Disconnect(hoverEventCallback);
}
}
}
///
/// An event for the WheelMoved signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// The WheelMoved signal is emitted when the wheel event is received.
///
/// 3
public event EventHandlerWithReturnType WheelEvent
{
add
{
if (wheelEventHandler == null)
{
wheelEventCallback = OnWheelEvent;
this.WheelEventSignal().Connect(wheelEventCallback);
}
wheelEventHandler += value;
if (WindowWheelEventHandler == null)
{
NUIApplication.GetDefaultWindow().WheelEvent += OnWindowWheelEvent;
}
WindowWheelEventHandler += value;
}
remove
{
wheelEventHandler -= value;
if (wheelEventHandler == null && WheelEventSignal().Empty() == false)
{
this.WheelEventSignal().Disconnect(wheelEventCallback);
}
WindowWheelEventHandler -= value;
if (WindowWheelEventHandler == null)
{
NUIApplication.GetDefaultWindow().WheelEvent -= OnWindowWheelEvent;
}
}
}
///
/// An event for the OnWindow signal which can be used to subscribe or unsubscribe the event handler.
/// The OnWindow signal is emitted after the view has been connected to the window.
///
/// 3
public event EventHandler AddedToWindow
{
add
{
if (onWindowEventHandler == null)
{
onWindowEventCallback = OnWindow;
this.OnWindowSignal().Connect(onWindowEventCallback);
}
onWindowEventHandler += value;
}
remove
{
onWindowEventHandler -= value;
if (onWindowEventHandler == null && OnWindowSignal().Empty() == false)
{
this.OnWindowSignal().Disconnect(onWindowEventCallback);
onWindowEventCallback = null;
}
}
}
///
/// An event for the OffWindow signal, which can be used to subscribe or unsubscribe the event handler.
/// OffWindow signal is emitted after the view has been disconnected from the window.
///
/// 3
public event EventHandler RemovedFromWindow
{
add
{
if (offWindowEventHandler == null)
{
offWindowEventCallback = OffWindow;
this.OffWindowSignal().Connect(offWindowEventCallback);
}
offWindowEventHandler += value;
}
remove
{
offWindowEventHandler -= value;
if (offWindowEventHandler == null && OffWindowSignal().Empty() == false)
{
this.OffWindowSignal().Disconnect(offWindowEventCallback);
offWindowEventCallback = null;
}
}
}
///
/// An event for visibility change which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when the visible property of this or a parent view is changed.
///
/// 3
public event EventHandler VisibilityChanged
{
add
{
if (visibilityChangedEventHandler == null)
{
visibilityChangedEventCallback = OnVisibilityChanged;
VisibilityChangedSignal(this).Connect(visibilityChangedEventCallback);
}
visibilityChangedEventHandler += value;
}
remove
{
visibilityChangedEventHandler -= value;
if (visibilityChangedEventHandler == null && VisibilityChangedSignal(this).Empty() == false)
{
VisibilityChangedSignal(this).Disconnect(visibilityChangedEventCallback);
}
}
}
///
/// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.
/// This signal is emitted when the layout direction property of this or a parent view is changed.
///
/// 4
public event EventHandler LayoutDirectionChanged
{
add
{
if (layoutDirectionChangedEventHandler == null)
{
layoutDirectionChangedEventCallback = OnLayoutDirectionChanged;
LayoutDirectionChangedSignal(this).Connect(layoutDirectionChangedEventCallback);
}
layoutDirectionChangedEventHandler += value;
}
remove
{
layoutDirectionChangedEventHandler -= value;
if (layoutDirectionChangedEventHandler == null && LayoutDirectionChangedSignal(this).Empty() == false)
{
LayoutDirectionChangedSignal(this).Disconnect(layoutDirectionChangedEventCallback);
}
}
}
///
/// An event for the ResourcesLoadedSignal signal which can be used to subscribe or unsubscribe the event handler provided by the user.
/// This signal is emitted after all resources required by a view are loaded and ready.
///
/// 3
public event EventHandler ResourcesLoaded
{
add
{
if (resourcesLoadedEventHandler == null)
{
ResourcesLoadedCallback = OnResourcesLoaded;
this.ResourcesLoadedSignal().Connect(ResourcesLoadedCallback);
}
resourcesLoadedEventHandler += value;
}
remove
{
resourcesLoadedEventHandler -= value;
if (resourcesLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
{
this.ResourcesLoadedSignal().Disconnect(ResourcesLoadedCallback);
ResourcesLoadedCallback = null;
}
}
}
private EventHandler _backKeyPressed;
///
/// An event for getting notice when physical back key is pressed.
/// This event is emitted BackKey is up.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler BackKeyPressed
{
add
{
_backKeyPressed += value;
BackKeyManager.Instance.Subscriber.Add(this);
}
remove
{
BackKeyManager.Instance.Subscriber.Remove(this);
_backKeyPressed -= value;
}
}
///
/// Function for emitting BackKeyPressed event outside of View instance
///
[EditorBrowsable(EditorBrowsableState.Never)]
internal void EmitBackKeyPressed()
{
_backKeyPressed.Invoke(this, null);
}
internal event EventHandler BackgroundResourceLoaded
{
add
{
if (backgroundResourceLoadedEventHandler == null)
{
backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
this.ResourcesLoadedSignal().Connect(backgroundResourceLoadedCallback);
}
backgroundResourceLoadedEventHandler += value;
}
remove
{
backgroundResourceLoadedEventHandler -= value;
if (backgroundResourceLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
{
this.ResourcesLoadedSignal().Disconnect(backgroundResourceLoadedCallback);
backgroundResourceLoadedCallback = null;
}
}
}
internal TouchDataSignal InterceptTouchSignal()
{
TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.ActorInterceptTouchSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal TouchDataSignal TouchSignal()
{
TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.ActorTouchSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal HoverSignal HoveredSignal()
{
HoverSignal ret = new HoverSignal(Interop.ActorSignal.ActorHoveredSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WheelSignal WheelEventSignal()
{
WheelSignal ret = new WheelSignal(Interop.ActorSignal.ActorWheelEventSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal OnWindowSignal()
{
ViewSignal ret = new ViewSignal(Interop.ActorSignal.ActorOnSceneSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal OffWindowSignal()
{
ViewSignal ret = new ViewSignal(Interop.ActorSignal.ActorOffSceneSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal OnRelayoutSignal()
{
ViewSignal ret = new ViewSignal(Interop.ActorSignal.ActorOnRelayoutSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewVisibilityChangedSignal VisibilityChangedSignal(View view)
{
ViewVisibilityChangedSignal ret = new ViewVisibilityChangedSignal(Interop.NDalic.VisibilityChangedSignal(View.getCPtr(view)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewLayoutDirectionChangedSignal LayoutDirectionChangedSignal(View view)
{
ViewLayoutDirectionChangedSignal ret = new ViewLayoutDirectionChangedSignal(Interop.Layout.LayoutDirectionChangedSignal(View.getCPtr(view)), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal ResourcesLoadedSignal()
{
ViewSignal ret = new ViewSignal(Interop.View.ResourceReadySignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ControlKeySignal KeyEventSignal()
{
ControlKeySignal ret = new ControlKeySignal(Interop.ViewSignal.KeyEventSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal KeyInputFocusSignal KeyInputFocusGainedSignal()
{
KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.KeyInputFocusGainedSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal KeyInputFocusSignal KeyInputFocusLostSignal()
{
KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.KeyInputFocusLostSignal(SwigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private void OnSize2DChanged(int? width, int? height)
{
PropertyValue temp;
if (width != null)
{
temp = new Tizen.NUI.PropertyValue((float)width);
Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeWidth, temp);
temp.Dispose();
}
if (height != null)
{
temp = new Tizen.NUI.PropertyValue((float)height);
Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeHeight, temp);
temp.Dispose();
}
}
private void OnMinimumSizeChanged(int? width, int? height)
{
if (width != null && height != null)
{
MinimumSize = new Size2D((int)width, (int)height);
}
else if (width != null && height == null)
{
MinimumSize = new Size2D((int)width, (int)this.GetMinimumSize().Height);
}
else if (width == null && height != null)
{
MinimumSize = new Size2D((int)this.GetMinimumSize().Width, (int)height);
}
else
{
//both are null, do nothing.
}
}
private void OnMaximumSizeChanged(int? width, int? height)
{
if (width != null && height != null)
{
MaximumSize = new Size2D((int)width, (int)height);
}
else if (width != null && height == null)
{
MaximumSize = new Size2D((int)width, (int)this.GetMaximumSize().Height);
}
else if (width == null && height != null)
{
MaximumSize = new Size2D((int)this.GetMaximumSize().Width, (int)height);
}
else
{
//both are null, do nothing.
}
}
private void OnPosition2DChanged(int x, int y)
{
Position2D = new Position2D(x, y);
}
private void OnSizeChanged(float? width, float? height, float? depth)
{
PropertyValue temp;
if (width != null)
{
temp = new Tizen.NUI.PropertyValue((float)width);
Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeWidth, temp);
temp.Dispose();
}
if (height != null)
{
temp = new Tizen.NUI.PropertyValue((float)height);
Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeHeight, temp);
temp.Dispose();
}
if (depth != null)
{
temp = new Tizen.NUI.PropertyValue((float)depth);
Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeDepth, temp);
temp.Dispose();
}
}
private void OnPositionChanged(float x, float y, float z)
{
Position = new Position(x, y, z);
}
private void OnParentOriginChanged(float x, float y, float z)
{
ParentOrigin = new Position(x, y, z);
}
private void OnPivotPointChanged(float x, float y, float z)
{
PivotPoint = new Position(x, y, z);
}
private void OnImageShadowChanged(ShadowBase instance)
{
ImageShadow = (ImageShadow)instance;
}
private void OnBoxShadowChanged(ShadowBase instance)
{
BoxShadow = (Shadow)instance;
}
private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
{
BackgroundImageBorder = new Rectangle(left, right, bottom, top);
}
private void OnKeyInputFocusGained(IntPtr view)
{
if (keyInputFocusGainedEventHandler != null)
{
keyInputFocusGainedEventHandler(this, null);
}
}
private void OnKeyInputFocusLost(IntPtr view)
{
if (keyInputFocusLostEventHandler != null)
{
keyInputFocusLostEventHandler(this, null);
}
}
private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
{
if (keyEvent == global::System.IntPtr.Zero)
{
NUILog.Error("keyEvent should not be null!");
return true;
}
KeyEventArgs e = new KeyEventArgs();
bool result = false;
e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
if (keyEventHandler != null)
{
Delegate[] delegateList = keyEventHandler.GetInvocationList();
// Oring the result of each callback.
foreach (EventHandlerWithReturnType del in delegateList)
{
result |= del(this, e);
}
}
return result;
}
// Callback for View OnRelayout signal
private void OnRelayout(IntPtr data)
{
if (onRelayoutEventHandler != null)
{
onRelayoutEventHandler(this, null);
}
}
// Callback for View TouchSignal
private bool OnInterceptTouch(IntPtr view, IntPtr touchData)
{
if (touchData == global::System.IntPtr.Zero)
{
NUILog.Error("touchData should not be null!");
return true;
}
// DisallowInterceptTouchEvent prevents the parent from intercepting touch.
if (DisallowInterceptTouchEvent)
{
return false;
}
TouchEventArgs e = new TouchEventArgs();
e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
bool consumed = false;
if (interceptTouchDataEventHandler != null)
{
consumed = interceptTouchDataEventHandler(this, e);
}
return consumed;
}
// Callback for View TouchSignal
private bool OnTouch(IntPtr view, IntPtr touchData)
{
if (touchData == global::System.IntPtr.Zero)
{
NUILog.Error("touchData should not be null!");
return true;
}
TouchEventArgs e = new TouchEventArgs();
e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
bool consumed = false;
if (touchDataEventHandler != null)
{
consumed = touchDataEventHandler(this, e);
}
if (enableControlState && !consumed)
{
consumed = HandleControlStateOnTouch(e.Touch);
}
return consumed;
}
// Callback for View Hover signal
private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
{
if (hoverEvent == global::System.IntPtr.Zero)
{
NUILog.Error("hoverEvent should not be null!");
return true;
}
HoverEventArgs e = new HoverEventArgs();
e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
if (hoverEventHandler != null)
{
return hoverEventHandler(this, e);
}
return false;
}
// Callback for View Wheel signal
private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
{
if (wheelEvent == global::System.IntPtr.Zero)
{
NUILog.Error("wheelEvent should not be null!");
return true;
}
WheelEventArgs e = new WheelEventArgs();
e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
if (wheelEventHandler != null)
{
return wheelEventHandler(this, e);
}
return false;
}
// Callback for View OnWindow signal
private void OnWindow(IntPtr data)
{
if (onWindowEventHandler != null)
{
onWindowEventHandler(this, null);
}
}
// Callback for View OffWindow signal
private void OffWindow(IntPtr data)
{
if (offWindowEventHandler != null)
{
offWindowEventHandler(this, null);
}
}
// Callback for View visibility change signal
private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
{
VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
if (data != null)
{
e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
}
e.Visibility = visibility;
e.Type = type;
if (visibilityChangedEventHandler != null)
{
visibilityChangedEventHandler(this, e);
}
}
// Callback for View layout direction change signal
private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
{
LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
if (data != null)
{
e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
}
e.Type = type;
if (layoutDirectionChangedEventHandler != null)
{
layoutDirectionChangedEventHandler(this, e);
}
}
private void OnResourcesLoaded(IntPtr view)
{
if (resourcesLoadedEventHandler != null)
{
resourcesLoadedEventHandler(this, null);
}
}
private void OnBackgroundResourceLoaded(IntPtr view)
{
BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
if (backgroundResourceLoadedEventHandler != null)
{
backgroundResourceLoadedEventHandler(this, e);
}
}
///
/// Event argument passed through the ChildAdded event.
///
/// 5
public class ChildAddedEventArgs : EventArgs
{
///
/// Added child view at moment.
///
/// 5
public View Added { get; set; }
}
///
/// Event argument passed through the ChildRemoved event.
///
/// 5
public class ChildRemovedEventArgs : EventArgs
{
///
/// Removed child view at moment.
///
/// 5
public View Removed { get; set; }
}
///
/// Event arguments that passed via the KeyEvent signal.
///
/// 3
public class KeyEventArgs : EventArgs
{
private Key _key;
///
/// Key - is the key sent to the view.
///
/// 3
public Key Key
{
get
{
return _key;
}
set
{
_key = value;
}
}
}
///
/// Event arguments that passed via the touch signal.
///
/// 3
public class TouchEventArgs : EventArgs
{
private Touch _touch;
///
/// Touch - contains the information of touch points.
///
/// 3
public Touch Touch
{
get
{
return _touch;
}
set
{
_touch = value;
}
}
}
///
/// Event arguments that passed via the hover signal.
///
/// 3
public class HoverEventArgs : EventArgs
{
private Hover _hover;
///
/// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
///
/// 3
public Hover Hover
{
get
{
return _hover;
}
set
{
_hover = value;
}
}
}
///
/// Event arguments that passed via the wheel signal.
///
/// 3
public class WheelEventArgs : EventArgs
{
private Wheel _wheel;
///
/// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
///
/// 3
public Wheel Wheel
{
get
{
return _wheel;
}
set
{
_wheel = value;
}
}
}
///
/// Event arguments of visibility changed.
///
/// 3
public class VisibilityChangedEventArgs : EventArgs
{
private View _view;
private bool _visibility;
private VisibilityChangeType _type;
///
/// The view, or child of view, whose visibility has changed.
///
/// 3
public View View
{
get
{
return _view;
}
set
{
_view = value;
}
}
///
/// Whether the view is now visible or not.
///
/// 3
public bool Visibility
{
get
{
return _visibility;
}
set
{
_visibility = value;
}
}
///
/// Whether the view's visible property has changed or a parent's.
///
/// 3
public VisibilityChangeType Type
{
get
{
return _type;
}
set
{
_type = value;
}
}
}
///
/// Event arguments of layout direction changed.
///
/// 4
public class LayoutDirectionChangedEventArgs : EventArgs
{
private View _view;
private ViewLayoutDirectionType _type;
///
/// The view, or child of view, whose layout direction has changed.
///
/// 4
public View View
{
get
{
return _view;
}
set
{
_view = value;
}
}
///
/// Whether the view's layout direction property has changed or a parent's.
///
/// 4
public ViewLayoutDirectionType Type
{
get
{
return _type;
}
set
{
_type = value;
}
}
}
internal class BackgroundResourceLoadedEventArgs : EventArgs
{
private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
public ResourceLoadingStatusType Status
{
get
{
return status;
}
set
{
status = value;
}
}
}
///
/// The class represents the information of the situation where the View's control state changes.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public class ControlStateChangedEventArgs : EventArgs
{
///
/// Create an instance with mandatory fields.
///
/// The previous control state.
/// The current control state.
[EditorBrowsable(EditorBrowsableState.Never)]
public ControlStateChangedEventArgs(ControlState previousState, ControlState currentState)
{
PreviousState = previousState;
CurrentState = currentState;
}
///
/// The previous control state.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public ControlState PreviousState { get; }
///
/// The current control state.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public ControlState CurrentState { get; }
}
private EventHandlerWithReturnType WindowWheelEventHandler;
private void OnWindowWheelEvent(object sender, Window.WheelEventArgs e)
{
if (e != null)
{
if (e.Wheel.Type == Wheel.WheelType.CustomWheel)
{
var arg = new WheelEventArgs()
{
Wheel = e.Wheel,
};
WindowWheelEventHandler?.Invoke(this, arg);
}
}
}
///
/// The expanded touch area.
/// TouchArea can expand the view's touchable area.
/// If you set the TouchAreaOffset on an view, when you touch the view, the touch area is used rather than the size of the view.
///
///
/// This is based on the top left x, y coordinates.
/// For example)
///
/// view.Size = new Size(100, 100);
/// view.TouchAreaOffset = new Offset(-10, 20, 30, -40); // left, right, bottom, top
///
/// Then, touch area is 130x170.
/// This is view.width + TouchAreaOffset.right - TouchAreaOffset.left and view.height + TouchAreaOffset.bottom - TouchAreaOffset.top
/// +---------------------+
/// | ^ |
/// | | |
/// | | -40 |
/// | | |
/// | | |
/// | +----+----+ |
/// | | | |
/// | -10| | 20 |
/// |<---+ +----->|
/// | | | |
/// | | | |
/// | +----+----+ |
/// | | |
/// | | 30 |
/// | | |
/// | v |
/// +---------------------+
///
[EditorBrowsable(EditorBrowsableState.Never)]
public Offset TouchAreaOffset
{
get
{
Interop.ActorInternal.GetTouchAreaOffset(SwigCPtr, out int left, out int right, out int bottom, out int top);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return new Offset(left, right, bottom, top);
}
set
{
Interop.ActorInternal.SetTouchAreaOffset(SwigCPtr, value.Left, value.Right, value.Bottom, value.Top);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
}
}
}