1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 // Some have been manually changed
24 using System.Runtime.InteropServices;
27 /// Provides the functionality of handling keyboard navigation and maintaining the two dimensional keyboard focus chain.<br>
28 /// It provides functionality of setting the focus and moving the focus in four directions(i.e.Left, Right, Up and Down).<br>
29 /// It also draws a highlight for the focused View and sends a event when the focus is changed.<br>
31 public class FocusManager : BaseHandle
33 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 private CustomAlgorithmInterfaceWrapper _customAlgorithmInterfaceWrapper;
36 internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn)
38 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
41 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj)
43 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 DisposeQueue.Instance.Add(this);
52 /// To make FocusManager instance be disposed.
54 public override void Dispose()
56 if (!Stage.IsInstalled())
58 DisposeQueue.Instance.Add(this);
64 if (swigCPtr.Handle != global::System.IntPtr.Zero)
69 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
71 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
73 global::System.GC.SuppressFinalize(this);
80 ///Event arguments that passed via PreFocusChange signal
82 public class PreFocusChangeEventArgs : EventArgs
84 private View _current;
85 private View _proposed;
86 private View.FocusDirection _direction;
88 public View CurrentView
100 public View ProposedView
112 public View.FocusDirection Direction
125 private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
126 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
127 internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
128 private PreFocusChangeEventCallback _preFocusChangeCallback;
131 /// PreFocusChange will be triggered before the focus is going to be changed.<br>
132 /// FocusManager makes the best guess for which actor to focus towards the given direction, but applications might want to change that.<br>
133 /// By connecting with this event, they can check the proposed actor to focus and return a different actor if they wish.<br>
134 /// This event is only triggered when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.<br>
135 /// It won't be emitted for focus movement by calling SetCurrentFocusView directly.<br>
137 public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
141 if (_preFocusChangeEventHandler == null)
144 Tizen.Log.Debug("NUI", "con1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
145 Tizen.Log.Debug("NUI", "con2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
147 _preFocusChangeCallback = OnPreFocusChange;
148 PreFocusChangeSignal().Connect(_preFocusChangeCallback);
150 Tizen.Log.Debug("NUI", "con3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
151 Tizen.Log.Debug("NUI", "con4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
154 _preFocusChangeEventHandler += value;
158 _preFocusChangeEventHandler -= value;
159 if (_preFocusChangeEventHandler == null && PreFocusChangeSignal().Empty() == false)
162 Tizen.Log.Debug("NUI", "discon1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
163 Tizen.Log.Debug("NUI", "discon2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
165 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
167 Tizen.Log.Debug("NUI", "discon3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
168 Tizen.Log.Debug("NUI", "discon4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
174 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
177 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
179 e.CurrentView = View.GetViewFromPtr(current);
180 e.ProposedView = View.GetViewFromPtr(proposed);
181 e.Direction = direction;
183 if (_preFocusChangeEventHandler != null)
185 view = _preFocusChangeEventHandler(this, e);
190 return view.GetPtrfromActor();
194 if (e.ProposedView) return proposed;
200 ///Event arguments that passed via FocusChanged signal.
202 public class FocusChangedEventArgs : EventArgs
204 private View _current;
207 public View CurrentView
232 private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
233 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
234 internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
235 private FocusChangedEventCallback _focusChangedEventCallback;
238 /// FocusGroupChanged will be triggered after the current focused actor has been changed.
240 public event EventHandler<FocusChangedEventArgs> FocusChanged
244 if (_focusChangedEventCallback == null)
246 _focusChangedEventCallback = OnFocusChanged;
247 FocusChangedSignal().Connect(_focusChangedEventCallback);
249 _focusChangedEventHandler += value;
253 _focusChangedEventHandler -= value;
255 if (_focusChangedEventCallback == null && FocusChangedSignal().Empty() == false)
257 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
262 private void OnFocusChanged(IntPtr current, IntPtr next)
264 FocusChangedEventArgs e = new FocusChangedEventArgs();
266 e.CurrentView = View.GetViewFromPtr(current);
267 e.NextView = View.GetViewFromPtr(next);
269 if (_focusChangedEventHandler != null)
271 _focusChangedEventHandler(this, e);
276 ///Event arguments that passed via FocusGroupChanged signal.
278 public class FocusGroupChangedEventArgs : EventArgs
280 private View _current;
281 private bool _forwardDirection;
283 public View CurrentView
295 public bool ForwardDirection
299 return _forwardDirection;
303 _forwardDirection = value;
308 private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
309 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
310 private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
311 private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
314 /// FocusGroupChanged will be triggered when the focus group has been changed.<br>
315 /// If the current focus group has a parent layout control, FocusManager will make the best guess for the next focus group to move the focus to in the given direction (forward or backward).<br>
316 /// If not, the application has to set the new focus.<br>
318 public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
322 if (_focusGroupChangedEventCallback == null)
324 _focusGroupChangedEventCallback = OnFocusGroupChanged;
325 FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
327 _focusGroupChangedEventHandler += value;
331 _focusGroupChangedEventHandler -= value;
333 if (_focusGroupChangedEventCallback == null && FocusGroupChangedSignal().Empty() == false)
335 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
340 private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
342 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
344 e.CurrentView = View.GetViewFromPtr(current);
345 e.ForwardDirection = forwardDirection;
347 if (_focusGroupChangedEventHandler != null)
349 _focusGroupChangedEventHandler(this, e);
354 ///Event arguments that passed via FocusedViewEnterKey signal
356 public class FocusedViewEnterKeyEventArgs : EventArgs
373 private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler;
374 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
375 private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
376 private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
379 /// FocusedViewEnterKeyPressed will be triggered when the current focused actor has the enter key pressed on it.
381 public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
385 if (_focusedViewEnterKeyEventCallback == null)
387 _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
388 FocusedActorEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
390 _focusedViewEnterKeyEventHandler += value;
394 _focusedViewEnterKeyEventHandler -= value;
396 if (_focusedViewEnterKeyEventCallback == null && FocusedActorEnterKeySignal().Empty() == false)
398 FocusedActorEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
403 private void OnFocusedViewEnterKey(IntPtr view)
405 FocusedViewEnterKeyEventArgs e = new FocusedViewEnterKeyEventArgs();
407 e.View = View.GetViewFromPtr(view);
409 if (_focusedViewEnterKeyEventHandler != null)
411 _focusedViewEnterKeyEventHandler(this, e);
416 internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
418 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421 internal static FocusManager Get()
423 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
424 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
429 /// Moves the keyboard focus to the given View.<br>
430 /// Only one View can be focused at the same time.<br>
431 /// The View must be in the stage already and keyboard focusable.<br>
433 /// <param name="view">The View to be focused</param>
434 /// <returns>Whether the focus is successful or not</returns>
435 public bool SetCurrentFocusView(View view)
437 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(view));
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 /// Gets the current focused actor.
445 /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
446 public View GetCurrentFocusView()
448 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true));
449 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450 if (ret.HasBody() == false)
458 /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
460 /// <param name="direction">The direction of focus movement</param>
461 /// <returns>true if the movement was successful</returns>
462 public bool MoveFocus(View.FocusDirection direction)
464 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470 /// Clears the focus from the current focused actor if any, so that no actor is focused in the focus chain.<br>
471 /// It will emit FocusChanged event without current focused View.<br>
473 public void ClearFocus()
475 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
476 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480 /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.<br>
481 /// The focus movement is not looped by default.<br>
483 public bool FocusGroupLoop
487 SetFocusGroupLoop(value);
491 return GetFocusGroupLoop();
495 internal void SetFocusGroupLoop(bool enabled)
497 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
498 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
501 internal bool GetFocusGroupLoop()
503 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
509 /// Sets whether an View is a focus group that can limit the scope of focus movement to its child actors in the focus chain.<br>
510 /// Layout controls set themselves as focus groups by default.<br>
512 /// <param name="view">The View to be set as a focus group</param>
513 /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
514 public void SetAsFocusGroup(View view, bool isFocusGroup)
516 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(view), isFocusGroup);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
521 /// Checks whether the actor is set as a focus group or not.
523 /// <param name="view">The View to be checked</param>
524 /// <returns>Whether the View is set as a focus group</returns>
525 public bool IsFocusGroup(View view)
527 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(view));
528 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
533 /// Returns the closest ancestor of the given actor that is a focus group.
535 /// <param name="view">The View to be checked for its focus group</param>
536 /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
537 public View GetFocusGroup(View view)
539 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(view)), true));
540 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541 if (ret.HasBody() == false)
549 /// Sets/Gets the focus indicator View.<br>
550 /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.<br>
552 public View FocusIndicator
556 SetFocusIndicatorView(value);
560 return GetFocusIndicatorView();
564 internal void SetFocusIndicatorView(View indicator)
566 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
567 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
570 internal View GetFocusIndicatorView()
572 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true));
573 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574 if (ret.HasBody() == false)
582 /// Provide the implementation of custom Focus algorithm interface to allow the app define the focus logic.<br>
584 /// <param name="arg0">The user's implementation of ICustomFocusAlgorithm</param>
585 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0)
587 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
588 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
590 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
591 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594 internal PreFocusChangeSignal PreFocusChangeSignal()
596 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
597 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
601 internal FocusChangedSignal FocusChangedSignal()
603 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
604 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608 internal FocusGroupChangedSignal FocusGroupChangedSignal()
610 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
611 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
615 internal ActorSignal FocusedActorEnterKeySignal()
617 ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
618 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
622 private static readonly FocusManager instance = FocusManager.Get();
625 /// Gets the singleton of FocusManager object.
627 public static FocusManager Instance
636 /// ICustomFocusAlgorithm is used to provide custom keyboard focus algorithm for retrieving the next focusable actor.<br>
637 /// The application can implement the interface and override the keyboard focus behaviour.<br>
638 /// If focus is changing within a layout container, then the layout container is queried first to provide the next focusable actor.<br>
639 /// If this does not provide a valid actor, then the Keyboard FocusManager will check focusable properties to determine next focusable actor.<br>
640 /// If focusable properties are not set, then the Keyboard FocusManager calls the GetNextFocusableActor() method of this interface.<br>
642 public interface ICustomFocusAlgorithm
644 View GetNextFocusableActor(View current, View proposed, View.FocusDirection direction);
647 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
649 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
651 public CustomAlgorithmInterfaceWrapper()
655 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
657 _customFocusAlgorithm = customFocusAlgorithm;
660 public override Actor GetNextFocusableActor(Actor current, Actor proposed, View.FocusDirection direction)
662 View currentView = View.DownCast<View>(current);
663 View proposedView = View.DownCast<View>(proposed);
664 return _customFocusAlgorithm.GetNextFocusableActor(currentView, proposedView, direction);