// Copyright (c) 2017 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. // // // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts // Some have been manually changed namespace Tizen.NUI { using System; using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; /// /// Provides the functionality of handling keyboard navigation and maintaining the two-dimensional keyboard focus chain.
/// It provides functionality of setting the focus and moving the focus in four directions( i.e., left, right, up, and down).
/// It also draws a highlight for the focused view and sends an event when the focus is changed.
///
public class FocusManager : BaseHandle { private global::System.Runtime.InteropServices.HandleRef swigCPtr; private CustomAlgorithmInterfaceWrapper _customAlgorithmInterfaceWrapper; internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } /// /// To make the FocusManager instance be disposed. /// protected override void Dispose(DisposeTypes type) { if(disposed) { return; } if(type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. } //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. if (_focusedViewEnterKeyEventCallback2 != null) { FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback2); } if (_focusedViewEnterKeyEventCallback != null) { FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback); } if (_focusGroupChangedEventCallback != null) { FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback); } if (_focusChangedEventCallback != null) { FocusChangedSignal().Disconnect(_focusChangedEventCallback); } if (_preFocusChangeCallback != null) { PreFocusChangeSignal().Disconnect(_preFocusChangeCallback); } if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; NDalicManualPINVOKE.delete_FocusManager(swigCPtr); } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } base.Dispose(type); } /// /// Event arguments that passed via the PreFocusChange signal. /// public class PreFocusChangeEventArgs : EventArgs { private View _current; private View _proposed; private View.FocusDirection _direction; public View CurrentView { get { return _current; } set { _current = value; } } public View ProposedView { get { return _proposed; } set { _proposed = value; } } public View.FocusDirection Direction { get { return _direction; } set { _direction = value; } } } private EventHandlerWithReturnType _preFocusChangeEventHandler; [UnmanagedFunctionPointer(CallingConvention.StdCall)] internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction); private PreFocusChangeEventCallback _preFocusChangeCallback; /// /// PreFocusChange will be triggered before the focus is going to be changed.
/// The FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.
/// By connecting with this event, they can check the proposed view to focus and return a different view if they wish.
/// This event is only triggered when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.
/// It won't be emitted for focus movement by calling the SetCurrentFocusView directly.
///
public event EventHandlerWithReturnType PreFocusChange { add { if (_preFocusChangeEventHandler == null) { #if DEBUG_ON Tizen.Log.Debug("NUI", "con1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty()); Tizen.Log.Debug("NUI", "con2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount()); #endif _preFocusChangeCallback = OnPreFocusChange; PreFocusChangeSignal().Connect(_preFocusChangeCallback); #if DEBUG_ON Tizen.Log.Debug("NUI", "con3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty()); Tizen.Log.Debug("NUI", "con4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount()); #endif } _preFocusChangeEventHandler += value; } remove { _preFocusChangeEventHandler -= value; if (_preFocusChangeEventHandler == null && PreFocusChangeSignal().Empty() == false) { #if DEBUG_ON Tizen.Log.Debug("NUI", "discon1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty()); Tizen.Log.Debug("NUI", "discon2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount()); #endif PreFocusChangeSignal().Disconnect(_preFocusChangeCallback); #if DEBUG_ON Tizen.Log.Debug("NUI", "discon3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty()); Tizen.Log.Debug("NUI", "discon4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount()); #endif } } } private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction) { View view = null; PreFocusChangeEventArgs e = new PreFocusChangeEventArgs(); if (current != global::System.IntPtr.Zero) { e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View; } if (proposed != global::System.IntPtr.Zero) { e.ProposedView = Registry.GetManagedBaseHandleFromNativePtr(proposed) as View; } e.Direction = direction; if (_preFocusChangeEventHandler != null) { view = _preFocusChangeEventHandler(this, e); } if (view) { return view.GetPtrfromView(); } else { //if (e.ProposedView) return proposed; //else return current; return current; //xb.teng } } /// /// Event arguments that passed via the FocusChanged signal. /// public class FocusChangedEventArgs : EventArgs { private View _current; private View _next; public View CurrentView { get { return _current; } set { _current = value; } } public View NextView { get { return _next; } set { _next = value; } } } private EventHandler _focusChangedEventHandler; [UnmanagedFunctionPointer(CallingConvention.StdCall)] internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next); private FocusChangedEventCallback _focusChangedEventCallback; /// /// The FocusGroupChanged will be triggered after the current focused view has been changed. /// public event EventHandler FocusChanged { add { if (_focusChangedEventCallback == null) { _focusChangedEventCallback = OnFocusChanged; FocusChangedSignal().Connect(_focusChangedEventCallback); } _focusChangedEventHandler += value; } remove { _focusChangedEventHandler -= value; if (_focusChangedEventCallback == null && FocusChangedSignal().Empty() == false) { FocusChangedSignal().Disconnect(_focusChangedEventCallback); } } } private void OnFocusChanged(IntPtr current, IntPtr next) { FocusChangedEventArgs e = new FocusChangedEventArgs(); e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View; e.NextView = Registry.GetManagedBaseHandleFromNativePtr(next) as View; if (_focusChangedEventHandler != null) { _focusChangedEventHandler(this, e); } } /// /// Event arguments that passed via the FocusGroupChanged signal. /// public class FocusGroupChangedEventArgs : EventArgs { private View _current; private bool _forwardDirection; public View CurrentView { get { return _current; } set { _current = value; } } public bool ForwardDirection { get { return _forwardDirection; } set { _forwardDirection = value; } } } private EventHandler _focusGroupChangedEventHandler; [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection); private FocusGroupChangedEventCallback _focusGroupChangedEventCallback; /// /// The FocusGroupChanged will be triggered when the focus group has been changed.
/// If the current focus group has a parent layout control, the FocusManager will make the best guess for the next focus group to move the focus to in the given direction (forward or backward).
/// If not, the application has to set the new focus.
///
public event EventHandler FocusGroupChanged { add { if (_focusGroupChangedEventCallback == null) { _focusGroupChangedEventCallback = OnFocusGroupChanged; FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback); } _focusGroupChangedEventHandler += value; } remove { _focusGroupChangedEventHandler -= value; if (_focusGroupChangedEventCallback == null && FocusGroupChangedSignal().Empty() == false) { FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback); } } } private void OnFocusGroupChanged(IntPtr current, bool forwardDirection) { FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs(); e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View; e.ForwardDirection = forwardDirection; if (_focusGroupChangedEventHandler != null) { _focusGroupChangedEventHandler(this, e); } } /// /// Event arguments that passed via the FocusedViewEnterKey signal. /// public class FocusedViewActivatedEventArgs : EventArgs { private View _view; public View View { get { return _view; } set { _view = value; } } } private EventHandler _focusedViewEnterKeyEventHandler; [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void FocusedViewEnterKeyEventCallback(IntPtr view); private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback; /// /// The FocusedViewActivated will be triggered when the current focused view has the enter key pressed on it. /// public event EventHandler FocusedViewActivated { add { if (_focusedViewEnterKeyEventCallback == null) { _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey; FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback); } _focusedViewEnterKeyEventHandler += value; } remove { _focusedViewEnterKeyEventHandler -= value; if (_focusedViewEnterKeyEventCallback != null && FocusedViewEnterKeySignal().Empty() == false) { FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback); } } } private void OnFocusedViewEnterKey(IntPtr view) { FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs(); e.View = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (_focusedViewEnterKeyEventHandler != null) { _focusedViewEnterKeyEventHandler(this, e); } } internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal static FocusManager Get() { FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Moves the keyboard focus to the given view.
/// Only one view can be focused at the same time.
/// The view must be in the stage already and keyboard focusable.
///
/// The view to be focused. /// Whether the focus is successful or not. public bool SetCurrentFocusView(View view) { if(view == null) { throw new ArgumentNullException("the target view should not be null"); } bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, View.getCPtr(view)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the current focused view. /// /// A handle to the current focused view or an empty handle if no view is focused. public View GetCurrentFocusView() { IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr); View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; return ret; } /// /// Moves the focus to the next focusable view in the focus chain in the given direction (according to the focus traversal order). /// /// The direction of the focus movement. /// True if the movement was successful. public bool MoveFocus(View.FocusDirection direction) { bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Clears the focus from the current focused view if any, so that no view is focused in the focus chain.
/// It will emit the FocusChanged event without the current focused view.
///
public void ClearFocus() { NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Move the focus to previous focused view. /// public void MoveFocusBackward() { NDalicManualPINVOKE.FocusManager_MoveFocusBackward(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Gets or sets the status of whether the focus movement should be looped within the same focus group.
/// The focus movement is not looped by default.
///
public bool FocusGroupLoop { set { SetFocusGroupLoop(value); } get { return GetFocusGroupLoop(); } } internal void SetFocusGroupLoop(bool enabled) { NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal bool GetFocusGroupLoop() { bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Sets whether the view is a focus group that can limit the scope of the focus movement to its child views in the focus chain.
/// Layout controls set themselves as focus groups by default.
///
/// The view to be set as a focus group. /// Whether to set the view as a focus group or not. public void SetAsFocusGroup(View view, bool isFocusGroup) { NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, View.getCPtr(view), isFocusGroup); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Checks whether the view is set as a focus group or not. /// /// The view to be checked. /// Whether the view is set as a focus group. public bool IsFocusGroup(View view) { bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, View.getCPtr(view)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the closest ancestor of the given view that is a focus group. /// /// The view to be checked for its focus group. /// The focus group the given view belongs to or an empty handle if the given view. public View GetFocusGroup(View view) { IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)); View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; /*View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); if (ret.HasBody() == false) { return null; }*/ return ret; } /// /// Gets or sets the focus indicator view.
/// This will replace the default focus indicator view in the FocusManager and will be added to the focused view as a highlight.
///
public View FocusIndicator { set { SetFocusIndicatorView(value); } get { return GetFocusIndicatorView(); } } internal void SetFocusIndicatorView(View indicator) { NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, View.getCPtr(indicator)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal View GetFocusIndicatorView() { IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr); View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View; return ret; } /// /// Provides the implementation of a custom focus algorithm interface to allow the application to define the focus logic.
///
/// The user's implementation of ICustomFocusAlgorithm. public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0) { _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper(); _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0); NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal PreFocusChangeSignal PreFocusChangeSignal() { PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal FocusChangedSignal FocusChangedSignal() { FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal FocusGroupChangedSignal FocusGroupChangedSignal() { FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal ViewSignal FocusedViewEnterKeySignal() { ViewSignal ret = new ViewSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private static readonly FocusManager instance = FocusManager.Get(); /// /// Gets the singleton of the FocusManager object. /// public static FocusManager Instance { get { return instance; } } /// /// ICustomFocusAlgorithm is used to provide the custom keyboard focus algorithm for retrieving the next focusable view.
/// The application can implement the interface and override the keyboard focus behavior.
/// If the focus is changing within a layout container, then the layout container is queried first to provide the next focusable view.
/// If this does not provide a valid view, then the Keyboard FocusManager will check focusable properties to determine the next focusable actor.
/// If focusable properties are not set, then the keyboard FocusManager calls the GetNextFocusableView() method of this interface.
///
public interface ICustomFocusAlgorithm { View GetNextFocusableView(View current, View proposed, View.FocusDirection direction); } private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface { private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm; public CustomAlgorithmInterfaceWrapper() { } public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm) { _customFocusAlgorithm = customFocusAlgorithm; } public override View GetNextFocusableView(View current, View proposed, View.FocusDirection direction) { return _customFocusAlgorithm.GetNextFocusableView(current, proposed, direction); } } [Obsolete("Please do not use! this will be deprecated")] public class FocusedViewEnterKeyEventArgs : EventArgs { private View _view; public View View { get { return _view; } set { _view = value; } } } private EventHandler _focusedViewEnterKeyEventHandler2; [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view); private FocusedViewEnterKeyEventCallback2 _focusedViewEnterKeyEventCallback2; [Obsolete("Please do not use! this will be deprecated")] public event EventHandler FocusedViewEnterKeyPressed { add { if (_focusedViewEnterKeyEventCallback2 == null) { _focusedViewEnterKeyEventCallback2 = OnFocusedViewEnterKey2; FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback2); } _focusedViewEnterKeyEventHandler2 += value; } remove { _focusedViewEnterKeyEventHandler2 -= value; if (_focusedViewEnterKeyEventCallback2 != null && FocusedViewEnterKeySignal().Empty() == false) { FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback2); } } } [Obsolete("Please do not use! this will be deprecated")] private void OnFocusedViewEnterKey2(IntPtr view) { FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs(); e.View = Registry.GetManagedBaseHandleFromNativePtr(view) as View; if (_focusedViewEnterKeyEventHandler != null) { _focusedViewEnterKeyEventHandler(this, e); } } } }