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 protected override void Dispose(DisposeTypes type)
57 if(type == DisposeTypes.Explicit)
60 //Release your own managed resources here.
61 //You should release all of your own disposable objects here.
64 //Release your own unmanaged resources here.
65 //You should not access any managed member here except static instance.
66 //because the execution order of Finalizes is non-deterministic.
68 if (_focusedViewEnterKeyEventCallback2 != null)
70 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback2);
73 if (_focusedViewEnterKeyEventCallback != null)
75 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
78 if (_focusGroupChangedEventCallback != null)
80 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
83 if (_focusChangedEventCallback != null)
85 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
88 if (_preFocusChangeCallback != null)
90 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
93 if (swigCPtr.Handle != global::System.IntPtr.Zero)
98 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
100 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
108 ///Event arguments that passed via PreFocusChange signal
110 public class PreFocusChangeEventArgs : EventArgs
112 private View _current;
113 private View _proposed;
114 private View.FocusDirection _direction;
116 public View CurrentView
128 public View ProposedView
140 public View.FocusDirection Direction
153 private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
154 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
155 internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
156 private PreFocusChangeEventCallback _preFocusChangeCallback;
159 /// PreFocusChange will be triggered before the focus is going to be changed.<br>
160 /// FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.<br>
161 /// By connecting with this event, they can check the proposed view to focus and return a different view if they wish.<br>
162 /// This event is only triggered when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.<br>
163 /// It won't be emitted for focus movement by calling SetCurrentFocusView directly.<br>
165 public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
169 if (_preFocusChangeEventHandler == null)
172 Tizen.Log.Debug("NUI", "con1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
173 Tizen.Log.Debug("NUI", "con2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
175 _preFocusChangeCallback = OnPreFocusChange;
176 PreFocusChangeSignal().Connect(_preFocusChangeCallback);
178 Tizen.Log.Debug("NUI", "con3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
179 Tizen.Log.Debug("NUI", "con4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
182 _preFocusChangeEventHandler += value;
186 _preFocusChangeEventHandler -= value;
187 if (_preFocusChangeEventHandler == null && PreFocusChangeSignal().Empty() == false)
190 Tizen.Log.Debug("NUI", "discon1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
191 Tizen.Log.Debug("NUI", "discon2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
193 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
195 Tizen.Log.Debug("NUI", "discon3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
196 Tizen.Log.Debug("NUI", "discon4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
202 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
205 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
207 if (current != global::System.IntPtr.Zero)
209 e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View;
211 if (proposed != global::System.IntPtr.Zero)
213 e.ProposedView = Registry.GetManagedBaseHandleFromNativePtr(proposed) as View;
215 e.Direction = direction;
217 if (_preFocusChangeEventHandler != null)
219 view = _preFocusChangeEventHandler(this, e);
224 return view.GetPtrfromView();
228 //if (e.ProposedView) return proposed;
229 //else return current;
230 return current; //xb.teng
235 ///Event arguments that passed via FocusChanged signal.
237 public class FocusChangedEventArgs : EventArgs
239 private View _current;
242 public View CurrentView
267 private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
268 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
269 internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
270 private FocusChangedEventCallback _focusChangedEventCallback;
273 /// FocusGroupChanged will be triggered after the current focused view has been changed.
275 public event EventHandler<FocusChangedEventArgs> FocusChanged
279 if (_focusChangedEventCallback == null)
281 _focusChangedEventCallback = OnFocusChanged;
282 FocusChangedSignal().Connect(_focusChangedEventCallback);
284 _focusChangedEventHandler += value;
288 _focusChangedEventHandler -= value;
290 if (_focusChangedEventCallback == null && FocusChangedSignal().Empty() == false)
292 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
297 private void OnFocusChanged(IntPtr current, IntPtr next)
299 FocusChangedEventArgs e = new FocusChangedEventArgs();
301 e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View;
302 e.NextView = Registry.GetManagedBaseHandleFromNativePtr(next) as View;
304 if (_focusChangedEventHandler != null)
306 _focusChangedEventHandler(this, e);
311 ///Event arguments that passed via FocusGroupChanged signal.
313 public class FocusGroupChangedEventArgs : EventArgs
315 private View _current;
316 private bool _forwardDirection;
318 public View CurrentView
330 public bool ForwardDirection
334 return _forwardDirection;
338 _forwardDirection = value;
343 private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
344 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
345 private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
346 private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
349 /// FocusGroupChanged will be triggered when the focus group has been changed.<br>
350 /// 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>
351 /// If not, the application has to set the new focus.<br>
353 public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
357 if (_focusGroupChangedEventCallback == null)
359 _focusGroupChangedEventCallback = OnFocusGroupChanged;
360 FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
362 _focusGroupChangedEventHandler += value;
366 _focusGroupChangedEventHandler -= value;
368 if (_focusGroupChangedEventCallback == null && FocusGroupChangedSignal().Empty() == false)
370 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
375 private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
377 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
379 e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View;
380 e.ForwardDirection = forwardDirection;
382 if (_focusGroupChangedEventHandler != null)
384 _focusGroupChangedEventHandler(this, e);
389 ///Event arguments that passed via FocusedViewEnterKey signal
391 public class FocusedViewActivatedEventArgs : EventArgs
408 private EventHandler<FocusedViewActivatedEventArgs> _focusedViewEnterKeyEventHandler;
409 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
410 private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
411 private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
414 /// FocusedViewActivated will be triggered when the current focused view has the enter key pressed on it.
416 public event EventHandler<FocusedViewActivatedEventArgs> FocusedViewActivated
420 if (_focusedViewEnterKeyEventCallback == null)
422 _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
423 FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
425 _focusedViewEnterKeyEventHandler += value;
429 _focusedViewEnterKeyEventHandler -= value;
431 if (_focusedViewEnterKeyEventCallback != null && FocusedViewEnterKeySignal().Empty() == false)
433 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
438 private void OnFocusedViewEnterKey(IntPtr view)
440 FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs();
442 e.View = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
444 if (_focusedViewEnterKeyEventHandler != null)
446 _focusedViewEnterKeyEventHandler(this, e);
451 internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 internal static FocusManager Get()
458 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464 /// Moves the keyboard focus to the given View.<br>
465 /// Only one View can be focused at the same time.<br>
466 /// The View must be in the stage already and keyboard focusable.<br>
468 /// <param name="view">The View to be focused</param>
469 /// <returns>Whether the focus is successful or not</returns>
470 public bool SetCurrentFocusView(View view)
474 throw new ArgumentNullException("the target view should not be null");
477 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, View.getCPtr(view));
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 /// Gets the current focused view.
485 /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
486 public View GetCurrentFocusView()
488 IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr);
490 View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
495 /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
497 /// <param name="direction">The direction of focus movement</param>
498 /// <returns>true if the movement was successful</returns>
499 public bool MoveFocus(View.FocusDirection direction)
501 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
502 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
507 /// Clears the focus from the current focused view if any, so that no view is focused in the focus chain.<br>
508 /// It will emit FocusChanged event without current focused View.<br>
510 public void ClearFocus()
512 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
513 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
517 /// Move the focus to prev focused view.
519 public void MoveFocusBackward()
521 NDalicManualPINVOKE.FocusManager_MoveFocusBackward(swigCPtr);
522 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
526 /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.<br>
527 /// The focus movement is not looped by default.<br>
529 public bool FocusGroupLoop
533 SetFocusGroupLoop(value);
537 return GetFocusGroupLoop();
541 internal void SetFocusGroupLoop(bool enabled)
543 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
544 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547 internal bool GetFocusGroupLoop()
549 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
550 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
555 /// 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>
556 /// Layout controls set themselves as focus groups by default.<br>
558 /// <param name="view">The View to be set as a focus group</param>
559 /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
560 public void SetAsFocusGroup(View view, bool isFocusGroup)
562 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, View.getCPtr(view), isFocusGroup);
563 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
567 /// Checks whether the view is set as a focus group or not.
569 /// <param name="view">The View to be checked</param>
570 /// <returns>Whether the View is set as a focus group</returns>
571 public bool IsFocusGroup(View view)
573 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, View.getCPtr(view));
574 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
579 /// Returns the closest ancestor of the given view that is a focus group.
581 /// <param name="view">The View to be checked for its focus group</param>
582 /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
583 public View GetFocusGroup(View view)
585 IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view));
587 View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
590 /*View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true);
591 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
592 if (ret.HasBody() == false)
601 /// Sets/Gets the focus indicator View.<br>
602 /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.<br>
604 public View FocusIndicator
608 SetFocusIndicatorView(value);
612 return GetFocusIndicatorView();
616 internal void SetFocusIndicatorView(View indicator)
618 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, View.getCPtr(indicator));
619 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
622 internal View GetFocusIndicatorView()
624 IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr);
626 View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
632 /// Provide the implementation of custom Focus algorithm interface to allow the app define the focus logic.<br>
634 /// <param name="arg0">The user's implementation of ICustomFocusAlgorithm</param>
635 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0)
637 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
638 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
640 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
641 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
644 internal PreFocusChangeSignal PreFocusChangeSignal()
646 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
647 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
651 internal FocusChangedSignal FocusChangedSignal()
653 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
654 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
658 internal FocusGroupChangedSignal FocusGroupChangedSignal()
660 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
661 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
665 internal ViewSignal FocusedViewEnterKeySignal()
667 ViewSignal ret = new ViewSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
668 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
672 private static readonly FocusManager instance = FocusManager.Get();
675 /// Gets the singleton of FocusManager object.
677 public static FocusManager Instance
686 /// ICustomFocusAlgorithm is used to provide custom keyboard focus algorithm for retrieving the next focusable view.<br>
687 /// The application can implement the interface and override the keyboard focus behaviour.<br>
688 /// If focus is changing within a layout container, then the layout container is queried first to provide the next focusable view.<br>
689 /// If this does not provide a valid view, then the Keyboard FocusManager will check focusable properties to determine next focusable actor.<br>
690 /// If focusable properties are not set, then the Keyboard FocusManager calls the GetNextFocusableView() method of this interface.<br>
692 public interface ICustomFocusAlgorithm
694 View GetNextFocusableView(View current, View proposed, View.FocusDirection direction);
697 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
699 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
701 public CustomAlgorithmInterfaceWrapper()
705 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
707 _customFocusAlgorithm = customFocusAlgorithm;
710 public override View GetNextFocusableView(View current, View proposed, View.FocusDirection direction)
712 return _customFocusAlgorithm.GetNextFocusableView(current, proposed, direction);
718 [Obsolete("Please do not use! this will be deprecated")]
719 public class FocusedViewEnterKeyEventArgs : EventArgs
736 private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler2;
737 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
738 private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view);
739 private FocusedViewEnterKeyEventCallback2 _focusedViewEnterKeyEventCallback2;
741 [Obsolete("Please do not use! this will be deprecated")]
742 public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
746 if (_focusedViewEnterKeyEventCallback2 == null)
748 _focusedViewEnterKeyEventCallback2 = OnFocusedViewEnterKey2;
749 FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback2);
751 _focusedViewEnterKeyEventHandler2 += value;
755 _focusedViewEnterKeyEventHandler2 -= value;
757 if (_focusedViewEnterKeyEventCallback2 != null && FocusedViewEnterKeySignal().Empty() == false)
759 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback2);
764 [Obsolete("Please do not use! this will be deprecated")]
765 private void OnFocusedViewEnterKey2(IntPtr view)
767 FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs();
769 e.View = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
771 if (_focusedViewEnterKeyEventHandler != null)
773 _focusedViewEnterKeyEventHandler(this, e);