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;
25 using Tizen.NUI.BaseComponents;
28 /// Provides the functionality of handling keyboard navigation and maintaining the two dimensional keyboard focus chain.<br>
29 /// It provides functionality of setting the focus and moving the focus in four directions(i.e.Left, Right, Up and Down).<br>
30 /// It also draws a highlight for the focused View and sends a event when the focus is changed.<br>
32 public class FocusManager : BaseHandle
34 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
35 private CustomAlgorithmInterfaceWrapper _customAlgorithmInterfaceWrapper;
37 internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn)
39 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
42 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj)
44 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 /// To make FocusManager instance be disposed.
50 public override void Dispose()
52 if (!Window.IsInstalled())
54 DisposeQueue.Instance.Add(this);
60 if (swigCPtr.Handle != global::System.IntPtr.Zero)
65 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
67 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69 global::System.GC.SuppressFinalize(this);
76 ///Event arguments that passed via PreFocusChange signal
78 public class PreFocusChangeEventArgs : EventArgs
80 private View _current;
81 private View _proposed;
82 private View.FocusDirection _direction;
84 public View CurrentView
96 public View ProposedView
108 public View.FocusDirection Direction
121 private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
122 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
123 internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
124 private PreFocusChangeEventCallback _preFocusChangeCallback;
127 /// PreFocusChange will be triggered before the focus is going to be changed.<br>
128 /// FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.<br>
129 /// By connecting with this event, they can check the proposed view to focus and return a different view if they wish.<br>
130 /// This event is only triggered when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.<br>
131 /// It won't be emitted for focus movement by calling SetCurrentFocusView directly.<br>
133 public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
137 if (_preFocusChangeEventHandler == null)
140 Tizen.Log.Debug("NUI", "con1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
141 Tizen.Log.Debug("NUI", "con2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
143 _preFocusChangeCallback = OnPreFocusChange;
144 PreFocusChangeSignal().Connect(_preFocusChangeCallback);
146 Tizen.Log.Debug("NUI", "con3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
147 Tizen.Log.Debug("NUI", "con4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
150 _preFocusChangeEventHandler += value;
154 _preFocusChangeEventHandler -= value;
155 if (_preFocusChangeEventHandler == null && PreFocusChangeSignal().Empty() == false)
158 Tizen.Log.Debug("NUI", "discon1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
159 Tizen.Log.Debug("NUI", "discon2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
161 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
163 Tizen.Log.Debug("NUI", "discon3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
164 Tizen.Log.Debug("NUI", "discon4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
170 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
173 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
175 if (current != global::System.IntPtr.Zero)
177 e.CurrentView = View.GetViewFromPtr(current);
179 if (proposed != global::System.IntPtr.Zero)
181 e.ProposedView = View.GetViewFromPtr(proposed);
183 e.Direction = direction;
185 if (_preFocusChangeEventHandler != null)
187 view = _preFocusChangeEventHandler(this, e);
192 return view.GetPtrfromView();
196 //if (e.ProposedView) return proposed;
197 //else return current;
198 return current; //xb.teng
203 ///Event arguments that passed via FocusChanged signal.
205 public class FocusChangedEventArgs : EventArgs
207 private View _current;
210 public View CurrentView
235 private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
236 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
237 internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
238 private FocusChangedEventCallback _focusChangedEventCallback;
241 /// FocusGroupChanged will be triggered after the current focused view has been changed.
243 public event EventHandler<FocusChangedEventArgs> FocusChanged
247 if (_focusChangedEventCallback == null)
249 _focusChangedEventCallback = OnFocusChanged;
250 FocusChangedSignal().Connect(_focusChangedEventCallback);
252 _focusChangedEventHandler += value;
256 _focusChangedEventHandler -= value;
258 if (_focusChangedEventCallback == null && FocusChangedSignal().Empty() == false)
260 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
265 private void OnFocusChanged(IntPtr current, IntPtr next)
267 FocusChangedEventArgs e = new FocusChangedEventArgs();
269 e.CurrentView = View.GetViewFromPtr(current);
270 e.NextView = View.GetViewFromPtr(next);
272 if (_focusChangedEventHandler != null)
274 _focusChangedEventHandler(this, e);
279 ///Event arguments that passed via FocusGroupChanged signal.
281 public class FocusGroupChangedEventArgs : EventArgs
283 private View _current;
284 private bool _forwardDirection;
286 public View CurrentView
298 public bool ForwardDirection
302 return _forwardDirection;
306 _forwardDirection = value;
311 private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
312 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
313 private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
314 private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
317 /// FocusGroupChanged will be triggered when the focus group has been changed.<br>
318 /// 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>
319 /// If not, the application has to set the new focus.<br>
321 public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
325 if (_focusGroupChangedEventCallback == null)
327 _focusGroupChangedEventCallback = OnFocusGroupChanged;
328 FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
330 _focusGroupChangedEventHandler += value;
334 _focusGroupChangedEventHandler -= value;
336 if (_focusGroupChangedEventCallback == null && FocusGroupChangedSignal().Empty() == false)
338 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
343 private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
345 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
347 e.CurrentView = View.GetViewFromPtr(current);
348 e.ForwardDirection = forwardDirection;
350 if (_focusGroupChangedEventHandler != null)
352 _focusGroupChangedEventHandler(this, e);
357 ///Event arguments that passed via FocusedViewEnterKey signal
359 public class FocusedViewEnterKeyEventArgs : EventArgs
376 private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler;
377 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
378 private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
379 private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
382 /// FocusedViewEnterKeyPressed will be triggered when the current focused view has the enter key pressed on it.
384 public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
388 if (_focusedViewEnterKeyEventCallback == null)
390 _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
391 FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
393 _focusedViewEnterKeyEventHandler += value;
397 _focusedViewEnterKeyEventHandler -= value;
399 if (_focusedViewEnterKeyEventCallback == null && FocusedViewEnterKeySignal().Empty() == false)
401 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
406 private void OnFocusedViewEnterKey(IntPtr view)
408 FocusedViewEnterKeyEventArgs e = new FocusedViewEnterKeyEventArgs();
410 e.View = View.GetViewFromPtr(view);
412 if (_focusedViewEnterKeyEventHandler != null)
414 _focusedViewEnterKeyEventHandler(this, e);
419 internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 internal static FocusManager Get()
426 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
427 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 /// Moves the keyboard focus to the given View.<br>
433 /// Only one View can be focused at the same time.<br>
434 /// The View must be in the stage already and keyboard focusable.<br>
436 /// <param name="view">The View to be focused</param>
437 /// <returns>Whether the focus is successful or not</returns>
438 public bool SetCurrentFocusView(View view)
440 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, View.getCPtr(view));
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 /// Gets the current focused view.
448 /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
449 public View GetCurrentFocusView()
451 View ret = new View(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true);
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 if (ret.HasBody() == false)
461 /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
463 /// <param name="direction">The direction of focus movement</param>
464 /// <returns>true if the movement was successful</returns>
465 public bool MoveFocus(View.FocusDirection direction)
467 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
468 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473 /// Clears the focus from the current focused view if any, so that no view is focused in the focus chain.<br>
474 /// It will emit FocusChanged event without current focused View.<br>
476 public void ClearFocus()
478 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.<br>
484 /// The focus movement is not looped by default.<br>
486 public bool FocusGroupLoop
490 SetFocusGroupLoop(value);
494 return GetFocusGroupLoop();
498 internal void SetFocusGroupLoop(bool enabled)
500 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
501 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 internal bool GetFocusGroupLoop()
506 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
507 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
512 /// Sets whether an View is a focus group that can limit the scope of focus movement to its child views in the focus chain.<br>
513 /// Layout controls set themselves as focus groups by default.<br>
515 /// <param name="view">The View to be set as a focus group</param>
516 /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
517 public void SetAsFocusGroup(View view, bool isFocusGroup)
519 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, View.getCPtr(view), isFocusGroup);
520 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
524 /// Checks whether the view is set as a focus group or not.
526 /// <param name="view">The View to be checked</param>
527 /// <returns>Whether the View is set as a focus group</returns>
528 public bool IsFocusGroup(View view)
530 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, View.getCPtr(view));
531 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
536 /// Returns the closest ancestor of the given view that is a focus group.
538 /// <param name="view">The View to be checked for its focus group</param>
539 /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
540 public View GetFocusGroup(View view)
542 View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true);
543 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
544 if (ret.HasBody() == false)
552 /// Sets/Gets the focus indicator View.<br>
553 /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.<br>
555 public View FocusIndicator
559 SetFocusIndicatorView(value);
563 return GetFocusIndicatorView();
567 internal void SetFocusIndicatorView(View indicator)
569 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, View.getCPtr(indicator));
570 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
573 internal View GetFocusIndicatorView()
575 View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true);
576 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
577 if (ret.HasBody() == false)
585 /// Provide the implementation of custom Focus algorithm interface to allow the app define the focus logic.<br>
587 /// <param name="arg0">The user's implementation of ICustomFocusAlgorithm</param>
588 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0)
590 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
591 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
593 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
594 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597 internal PreFocusChangeSignal PreFocusChangeSignal()
599 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
600 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
604 internal FocusChangedSignal FocusChangedSignal()
606 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
607 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
611 internal FocusGroupChangedSignal FocusGroupChangedSignal()
613 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
614 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
618 internal ViewSignal FocusedViewEnterKeySignal()
620 ViewSignal ret = new ViewSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
621 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
625 private static readonly FocusManager instance = FocusManager.Get();
628 /// Gets the singleton of FocusManager object.
630 public static FocusManager Instance
639 /// ICustomFocusAlgorithm is used to provide custom keyboard focus algorithm for retrieving the next focusable view.<br>
640 /// The application can implement the interface and override the keyboard focus behaviour.<br>
641 /// If focus is changing within a layout container, then the layout container is queried first to provide the next focusable view.<br>
642 /// If this does not provide a valid view, then the Keyboard FocusManager will check focusable properties to determine next focusable actor.<br>
643 /// If focusable properties are not set, then the Keyboard FocusManager calls the GetNextFocusableView() method of this interface.<br>
645 public interface ICustomFocusAlgorithm
647 View GetNextFocusableView(View current, View proposed, View.FocusDirection direction);
650 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
652 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
654 public CustomAlgorithmInterfaceWrapper()
658 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
660 _customFocusAlgorithm = customFocusAlgorithm;
663 public override View GetNextFocusableView(View current, View proposed, View.FocusDirection direction)
665 View currentView = View.DownCast<View>(current);
666 View proposedView = View.DownCast<View>(proposed);
667 return _customFocusAlgorithm.GetNextFocusableView(currentView, proposedView, direction);