/*
* Copyright(c) 2020 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;
using Tizen.NUI.Components;
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)
{
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;
var signal = KeyInputFocusGainedSignal();
signal?.Connect(_keyInputFocusGainedCallback);
signal?.Dispose();
}
_keyInputFocusGainedEventHandler += value;
}
remove
{
_keyInputFocusGainedEventHandler -= value;
if (_keyInputFocusGainedEventHandler == null)
{
var signal = KeyInputFocusGainedSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_keyInputFocusGainedCallback);
_keyInputFocusGainedCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = KeyInputFocusLostSignal();
signal?.Connect(_keyInputFocusLostCallback);
signal?.Dispose();
}
_keyInputFocusLostEventHandler += value;
}
remove
{
_keyInputFocusLostEventHandler -= value;
if (_keyInputFocusLostEventHandler == null)
{
var signal = KeyInputFocusLostSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_keyInputFocusLostCallback);
_keyInputFocusLostCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = KeyEventSignal();
signal?.Connect(_keyCallback);
signal?.Dispose();
}
_keyEventHandler += value;
}
remove
{
_keyEventHandler -= value;
if (_keyEventHandler == null)
{
var signal = KeyEventSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_keyCallback);
_keyCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = OnRelayoutSignal();
signal?.Connect(_onRelayoutEventCallback);
signal?.Dispose();
}
_onRelayoutEventHandler += value;
}
remove
{
_onRelayoutEventHandler -= value;
if (_onRelayoutEventHandler == null)
{
var signal = OnRelayoutSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_onRelayoutEventCallback);
_onRelayoutEventCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = InterceptTouchSignal();
signal?.Connect(_interceptTouchDataCallback);
signal?.Dispose();
}
_interceptTouchDataEventHandler += value;
}
remove
{
_interceptTouchDataEventHandler -= value;
if (_interceptTouchDataEventHandler == null)
{
var signal = InterceptTouchSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_interceptTouchDataCallback);
_interceptTouchDataCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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 interceping 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;
var signal = TouchSignal();
signal?.Connect(_touchDataCallback);
signal?.Dispose();
}
_touchDataEventHandler += value;
}
remove
{
_touchDataEventHandler -= value;
if (_touchDataEventHandler == null)
{
var signal = TouchSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_touchDataCallback);
_touchDataCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = HoveredSignal();
signal?.Connect(_hoverEventCallback);
signal?.Dispose();
}
_hoverEventHandler += value;
}
remove
{
_hoverEventHandler -= value;
if (_hoverEventHandler == null)
{
var signal = HoveredSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_hoverEventCallback);
_hoverEventCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = WheelEventSignal();
signal?.Connect(_wheelEventCallback);
signal?.Dispose();
}
_wheelEventHandler += value;
if (WindowWheelEventHandler == null)
{
NUIApplication.GetDefaultWindow().WheelEvent += OnWindowWheelEvent;
}
WindowWheelEventHandler += value;
}
remove
{
_wheelEventHandler -= value;
if (_wheelEventHandler == null)
{
var signal = WheelEventSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_wheelEventCallback);
_wheelEventCallback = null;
}
signal?.Dispose();
}
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;
var signal = OnWindowSignal();
signal?.Connect(_onWindowEventCallback);
signal?.Dispose();
}
_onWindowEventHandler += value;
}
remove
{
_onWindowEventHandler -= value;
if (_onWindowEventHandler == null)
{
var signal = OnWindowSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_onWindowEventCallback);
_onWindowEventCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = OffWindowSignal();
signal?.Connect(_offWindowEventCallback);
signal?.Dispose();
}
_offWindowEventHandler += value;
}
remove
{
_offWindowEventHandler -= value;
if (_offWindowEventHandler == null)
{
var signal = OffWindowSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_offWindowEventCallback);
_offWindowEventCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = VisibilityChangedSignal(this);
signal?.Connect(_visibilityChangedEventCallback);
signal?.Dispose();
}
_visibilityChangedEventHandler += value;
}
remove
{
_visibilityChangedEventHandler -= value;
if (_visibilityChangedEventHandler == null)
{
var signal = VisibilityChangedSignal(this);
if (signal?.Empty() == false)
{
signal?.Disconnect(_visibilityChangedEventCallback);
_visibilityChangedEventCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = LayoutDirectionChangedSignal(this);
signal?.Connect(_layoutDirectionChangedEventCallback);
signal?.Dispose();
}
_layoutDirectionChangedEventHandler += value;
}
remove
{
_layoutDirectionChangedEventHandler -= value;
if (_layoutDirectionChangedEventHandler == null)
{
var signal = LayoutDirectionChangedSignal(this);
if (signal?.Empty() == false)
{
signal?.Disconnect(_layoutDirectionChangedEventCallback);
_layoutDirectionChangedEventCallback = null;
}
signal?.Dispose();
}
}
}
///
/// 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;
var signal = ResourcesLoadedSignal();
signal?.Connect(_ResourcesLoadedCallback);
signal?.Dispose();
}
_resourcesLoadedEventHandler += value;
}
remove
{
_resourcesLoadedEventHandler -= value;
if (_resourcesLoadedEventHandler == null)
{
var signal = ResourcesLoadedSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_ResourcesLoadedCallback);
_ResourcesLoadedCallback = null;
}
signal?.Dispose();
}
}
}
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;
var signal = ResourcesLoadedSignal();
signal?.Connect(_backgroundResourceLoadedCallback);
signal?.Dispose();
}
_backgroundResourceLoadedEventHandler += value;
}
remove
{
_backgroundResourceLoadedEventHandler -= value;
if (_backgroundResourceLoadedEventHandler == null)
{
var signal = ResourcesLoadedSignal();
if (signal?.Empty() == false)
{
signal?.Disconnect(_backgroundResourceLoadedCallback);
_backgroundResourceLoadedCallback = null;
}
signal?.Dispose();
}
}
}
internal TouchDataSignal InterceptTouchSignal()
{
TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.Actor_InterceptTouchSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal TouchDataSignal TouchSignal()
{
TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.Actor_TouchSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal HoverSignal HoveredSignal()
{
HoverSignal ret = new HoverSignal(Interop.ActorSignal.Actor_HoveredSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal WheelSignal WheelEventSignal()
{
WheelSignal ret = new WheelSignal(Interop.ActorSignal.Actor_WheelEventSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal OnWindowSignal()
{
ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OnSceneSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal OffWindowSignal()
{
ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OffSceneSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending)
throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal ViewSignal OnRelayoutSignal()
{
ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OnRelayoutSignal(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.View_KeyEventSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal KeyInputFocusSignal KeyInputFocusGainedSignal()
{
KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.View_KeyInputFocusGainedSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
internal KeyInputFocusSignal KeyInputFocusLostSignal()
{
KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.View_KeyInputFocusLostSignal(swigCPtr), false);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
private void OnSize2DChanged(int? width, int? height)
{
if (width != null)
{
Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_WIDTH, new Tizen.NUI.PropertyValue((float)width));
}
if (height != null)
{
Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_HEIGHT, new Tizen.NUI.PropertyValue((float)height));
}
}
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)
{
if (width != null)
{
Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_WIDTH, new Tizen.NUI.PropertyValue((float)width));
}
if (height != null)
{
Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_HEIGHT, new Tizen.NUI.PropertyValue((float)height));
}
if (depth != null)
{
Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_DEPTH, new Tizen.NUI.PropertyValue((float)depth));
}
}
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.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);
}
}
}
///
/// 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.
/// 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();
}
}
}
}