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.
28 /// It provides functionality of setting the focus and moving the focus in four directions(i.e.Left, Right, Up and Down).
29 /// It also draws a highlight for the focused View and sends a event when the focus is changed.
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;
130 public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
134 if (_preFocusChangeEventHandler == null)
136 _preFocusChangeCallback = OnPreFocusChange;
137 PreFocusChangeSignal().Connect(_preFocusChangeCallback);
139 _preFocusChangeEventHandler += value;
143 _preFocusChangeEventHandler -= value;
144 if (_preFocusChangeEventHandler == null && _preFocusChangeCallback != null)
146 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
151 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
154 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
156 e.CurrentView = View.GetViewFromPtr(current);
157 e.ProposedView = View.GetViewFromPtr(proposed);
158 e.Direction = direction;
160 if (_preFocusChangeEventHandler != null)
162 view = _preFocusChangeEventHandler(this, e);
167 return view.GetPtrfromActor();
171 if (e.ProposedView) return proposed;
177 ///Event arguments that passed via FocusChanged signal
179 public class FocusChangedEventArgs : EventArgs
181 private View _current;
184 public View CurrentView
209 private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
210 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
211 internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
212 private FocusChangedEventCallback _focusChangedEventCallback;
214 public event EventHandler<FocusChangedEventArgs> FocusChanged
218 if (_focusChangedEventCallback == null)
220 _focusChangedEventCallback = OnFocusChanged;
221 FocusChangedSignal().Connect(_focusChangedEventCallback);
223 _focusChangedEventHandler += value;
227 _focusChangedEventHandler -= value;
229 if (_focusChangedEventCallback == null && _focusChangedEventCallback != null)
231 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
236 private void OnFocusChanged(IntPtr current, IntPtr next)
238 FocusChangedEventArgs e = new FocusChangedEventArgs();
240 e.CurrentView = View.GetViewFromPtr(current);
241 e.NextView = View.GetViewFromPtr(next);
243 if (_focusChangedEventHandler != null)
245 _focusChangedEventHandler(this, e);
250 ///Event arguments that passed via FocusGroupChanged signal
252 public class FocusGroupChangedEventArgs : EventArgs
254 private View _current;
255 private bool _forwardDirection;
257 public View CurrentView
269 public bool ForwardDirection
273 return _forwardDirection;
277 _forwardDirection = value;
282 private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
283 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
284 private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
285 private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
287 public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
291 if (_focusGroupChangedEventCallback == null)
293 _focusGroupChangedEventCallback = OnFocusGroupChanged;
294 FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
296 _focusGroupChangedEventHandler += value;
300 _focusGroupChangedEventHandler -= value;
302 if (_focusGroupChangedEventCallback == null && _focusGroupChangedEventCallback != null)
304 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
309 private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
311 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
313 e.CurrentView = View.GetViewFromPtr(current);
314 e.ForwardDirection = forwardDirection;
316 if (_focusGroupChangedEventHandler != null)
318 _focusGroupChangedEventHandler(this, e);
323 ///Event arguments that passed via FocusedViewEnterKey signal
325 public class FocusedViewEnterKeyEventArgs : EventArgs
342 private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler;
343 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
344 private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
345 private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
347 public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
351 if (_focusedViewEnterKeyEventCallback == null)
353 _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
354 FocusedActorEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
356 _focusedViewEnterKeyEventHandler += value;
360 _focusedViewEnterKeyEventHandler -= value;
362 if (_focusedViewEnterKeyEventCallback == null && _focusedViewEnterKeyEventCallback != null)
364 FocusedActorEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
369 private void OnFocusedViewEnterKey(IntPtr view)
371 FocusedViewEnterKeyEventArgs e = new FocusedViewEnterKeyEventArgs();
373 e.View = View.GetViewFromPtr(view);
375 if (_focusedViewEnterKeyEventHandler != null)
377 _focusedViewEnterKeyEventHandler(this, e);
382 internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
384 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 internal static FocusManager Get()
389 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
390 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395 /// Moves the keyboard focus to the given View.
396 /// Only one View can be focused at the same time.
397 /// The View must be in the stage already and keyboard focusable.
399 /// <param name="view">The View to be focused</param>
400 /// <returns>Whether the focus is successful or not</returns>
401 public bool SetCurrentFocusView(View view)
403 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(view));
404 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// Gets the current focused actor.
411 /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
412 public View GetCurrentFocusView()
414 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true));
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
422 /// <param name="direction">The direction of focus movement</param>
423 /// <returns>true if the movement was successful</returns>
424 public bool MoveFocus(View.FocusDirection direction)
426 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
427 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 /// Clears the focus from the current focused actor if any, so that no actor is focused in the focus chain.
433 /// It will emit FocusChanged event without current focused View.
435 public void ClearFocus()
437 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.
443 /// The focus movement is not looped by default.
445 public bool FocusGroupLoop
449 SetFocusGroupLoop(value);
453 return GetFocusGroupLoop();
457 internal void SetFocusGroupLoop(bool enabled)
459 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 internal bool GetFocusGroupLoop()
465 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
466 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471 /// Sets whether an View is a focus group that can limit the scope of focus movement to its child actors in the focus chain.
472 /// Layout controls set themselves as focus groups by default.
474 /// <param name="view">The View to be set as a focus group</param>
475 /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
476 public void SetAsFocusGroup(View view, bool isFocusGroup)
478 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(view), isFocusGroup);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 /// Checks whether the actor is set as a focus group or not.
485 /// <param name="view">The View to be checked</param>
486 /// <returns>Whether the View is set as a focus group</returns>
487 public bool IsFocusGroup(View view)
489 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(view));
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495 /// Returns the closest ancestor of the given actor that is a focus group.
497 /// <param name="view">The View to be checked for its focus group</param>
498 /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
499 public View GetFocusGroup(View view)
501 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(view)), true));
502 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 /// Sets/Gets the focus indicator View.
508 /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.
510 public View FocusIndicator
514 SetFocusIndicatorView(value);
518 return GetFocusIndicatorView();
522 internal void SetFocusIndicatorView(View indicator)
524 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
525 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
528 internal View GetFocusIndicatorView()
530 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true));
531 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
535 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0) {
536 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
537 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
539 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
540 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543 internal PreFocusChangeSignal PreFocusChangeSignal()
545 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
546 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550 internal FocusChangedSignal FocusChangedSignal()
552 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
553 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557 internal FocusGroupChangedSignal FocusGroupChangedSignal()
559 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
560 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
564 internal ActorSignal FocusedActorEnterKeySignal()
566 ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
567 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
571 private static readonly FocusManager instance = FocusManager.Get();
574 /// Gets the singleton of FocusManager object.
576 public static FocusManager Instance
584 public interface ICustomFocusAlgorithm
586 View GetNextFocusableActor(View current, View proposed, View.FocusDirection direction);
589 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
591 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
593 public CustomAlgorithmInterfaceWrapper()
597 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
599 _customFocusAlgorithm = customFocusAlgorithm;
602 public override Actor GetNextFocusableActor(Actor current, Actor proposed, View.FocusDirection direction)
604 View currentView = View.DownCast<View>(current);
605 View proposedView = View.DownCast<View>(proposed);
606 return _customFocusAlgorithm.GetNextFocusableActor(currentView, proposedView, direction);