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 (swigCPtr.Handle != global::System.IntPtr.Zero)
73 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
75 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
83 ///Event arguments that passed via PreFocusChange signal
85 public class PreFocusChangeEventArgs : EventArgs
87 private View _current;
88 private View _proposed;
89 private View.FocusDirection _direction;
91 public View CurrentView
103 public View ProposedView
115 public View.FocusDirection Direction
128 private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
129 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
130 internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
131 private PreFocusChangeEventCallback _preFocusChangeCallback;
134 /// PreFocusChange will be triggered before the focus is going to be changed.<br>
135 /// FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.<br>
136 /// By connecting with this event, they can check the proposed view to focus and return a different view if they wish.<br>
137 /// This event is only triggered when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.<br>
138 /// It won't be emitted for focus movement by calling SetCurrentFocusView directly.<br>
140 public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
144 if (_preFocusChangeEventHandler == null)
147 Tizen.Log.Debug("NUI", "con1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
148 Tizen.Log.Debug("NUI", "con2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
150 _preFocusChangeCallback = OnPreFocusChange;
151 PreFocusChangeSignal().Connect(_preFocusChangeCallback);
153 Tizen.Log.Debug("NUI", "con3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
154 Tizen.Log.Debug("NUI", "con4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
157 _preFocusChangeEventHandler += value;
161 _preFocusChangeEventHandler -= value;
162 if (_preFocusChangeEventHandler == null && PreFocusChangeSignal().Empty() == false)
165 Tizen.Log.Debug("NUI", "discon1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
166 Tizen.Log.Debug("NUI", "discon2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
168 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
170 Tizen.Log.Debug("NUI", "discon3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
171 Tizen.Log.Debug("NUI", "discon4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
177 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
180 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
182 if (current != global::System.IntPtr.Zero)
184 e.CurrentView = View.GetViewFromPtr(current);
186 if (proposed != global::System.IntPtr.Zero)
188 e.ProposedView = View.GetViewFromPtr(proposed);
190 e.Direction = direction;
192 if (_preFocusChangeEventHandler != null)
194 view = _preFocusChangeEventHandler(this, e);
199 return view.GetPtrfromView();
203 //if (e.ProposedView) return proposed;
204 //else return current;
205 return current; //xb.teng
210 ///Event arguments that passed via FocusChanged signal.
212 public class FocusChangedEventArgs : EventArgs
214 private View _current;
217 public View CurrentView
242 private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
243 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
244 internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
245 private FocusChangedEventCallback _focusChangedEventCallback;
248 /// FocusGroupChanged will be triggered after the current focused view has been changed.
250 public event EventHandler<FocusChangedEventArgs> FocusChanged
254 if (_focusChangedEventCallback == null)
256 _focusChangedEventCallback = OnFocusChanged;
257 FocusChangedSignal().Connect(_focusChangedEventCallback);
259 _focusChangedEventHandler += value;
263 _focusChangedEventHandler -= value;
265 if (_focusChangedEventCallback == null && FocusChangedSignal().Empty() == false)
267 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
272 private void OnFocusChanged(IntPtr current, IntPtr next)
274 FocusChangedEventArgs e = new FocusChangedEventArgs();
276 e.CurrentView = View.GetViewFromPtr(current);
277 e.NextView = View.GetViewFromPtr(next);
279 if (_focusChangedEventHandler != null)
281 _focusChangedEventHandler(this, e);
286 ///Event arguments that passed via FocusGroupChanged signal.
288 public class FocusGroupChangedEventArgs : EventArgs
290 private View _current;
291 private bool _forwardDirection;
293 public View CurrentView
305 public bool ForwardDirection
309 return _forwardDirection;
313 _forwardDirection = value;
318 private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
319 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
320 private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
321 private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
324 /// FocusGroupChanged will be triggered when the focus group has been changed.<br>
325 /// 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>
326 /// If not, the application has to set the new focus.<br>
328 public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
332 if (_focusGroupChangedEventCallback == null)
334 _focusGroupChangedEventCallback = OnFocusGroupChanged;
335 FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
337 _focusGroupChangedEventHandler += value;
341 _focusGroupChangedEventHandler -= value;
343 if (_focusGroupChangedEventCallback == null && FocusGroupChangedSignal().Empty() == false)
345 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
350 private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
352 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
354 e.CurrentView = View.GetViewFromPtr(current);
355 e.ForwardDirection = forwardDirection;
357 if (_focusGroupChangedEventHandler != null)
359 _focusGroupChangedEventHandler(this, e);
364 ///Event arguments that passed via FocusedViewEnterKey signal
366 public class FocusedViewActivatedEventArgs : EventArgs
383 private EventHandler<FocusedViewActivatedEventArgs> _focusedViewEnterKeyEventHandler;
384 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
385 private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
386 private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
389 /// FocusedViewActivated will be triggered when the current focused view has the enter key pressed on it.
391 public event EventHandler<FocusedViewActivatedEventArgs> FocusedViewActivated
395 if (_focusedViewEnterKeyEventCallback == null)
397 _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
398 FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
400 _focusedViewEnterKeyEventHandler += value;
404 _focusedViewEnterKeyEventHandler -= value;
406 if (_focusedViewEnterKeyEventCallback == null && FocusedViewEnterKeySignal().Empty() == false)
408 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
413 private void OnFocusedViewEnterKey(IntPtr view)
415 FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs();
417 e.View = View.GetViewFromPtr(view);
419 if (_focusedViewEnterKeyEventHandler != null)
421 _focusedViewEnterKeyEventHandler(this, e);
426 internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 internal static FocusManager Get()
433 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 /// Moves the keyboard focus to the given View.<br>
440 /// Only one View can be focused at the same time.<br>
441 /// The View must be in the stage already and keyboard focusable.<br>
443 /// <param name="view">The View to be focused</param>
444 /// <returns>Whether the focus is successful or not</returns>
445 public bool SetCurrentFocusView(View view)
447 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, View.getCPtr(view));
448 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 /// Gets the current focused view.
455 /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
456 public View GetCurrentFocusView()
458 View ret = new View(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460 if (ret.HasBody() == false)
468 /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
470 /// <param name="direction">The direction of focus movement</param>
471 /// <returns>true if the movement was successful</returns>
472 public bool MoveFocus(View.FocusDirection direction)
474 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
475 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480 /// Clears the focus from the current focused view if any, so that no view is focused in the focus chain.<br>
481 /// It will emit FocusChanged event without current focused View.<br>
483 public void ClearFocus()
485 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 /// Move the focus to prev focused view.
492 public void MoveFocusBackward()
494 NDalicManualPINVOKE.FocusManager_MoveFocusBackward(swigCPtr);
495 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
499 /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.<br>
500 /// The focus movement is not looped by default.<br>
502 public bool FocusGroupLoop
506 SetFocusGroupLoop(value);
510 return GetFocusGroupLoop();
514 internal void SetFocusGroupLoop(bool enabled)
516 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
517 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520 internal bool GetFocusGroupLoop()
522 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
523 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
528 /// 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>
529 /// Layout controls set themselves as focus groups by default.<br>
531 /// <param name="view">The View to be set as a focus group</param>
532 /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
533 public void SetAsFocusGroup(View view, bool isFocusGroup)
535 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, View.getCPtr(view), isFocusGroup);
536 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
540 /// Checks whether the view is set as a focus group or not.
542 /// <param name="view">The View to be checked</param>
543 /// <returns>Whether the View is set as a focus group</returns>
544 public bool IsFocusGroup(View view)
546 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, View.getCPtr(view));
547 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
552 /// Returns the closest ancestor of the given view that is a focus group.
554 /// <param name="view">The View to be checked for its focus group</param>
555 /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
556 public View GetFocusGroup(View view)
558 View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true);
559 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560 if (ret.HasBody() == false)
568 /// Sets/Gets the focus indicator View.<br>
569 /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.<br>
571 public View FocusIndicator
575 SetFocusIndicatorView(value);
579 return GetFocusIndicatorView();
583 internal void SetFocusIndicatorView(View indicator)
585 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, View.getCPtr(indicator));
586 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
589 internal View GetFocusIndicatorView()
591 View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true);
592 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
593 if (ret.HasBody() == false)
601 /// Provide the implementation of custom Focus algorithm interface to allow the app define the focus logic.<br>
603 /// <param name="arg0">The user's implementation of ICustomFocusAlgorithm</param>
604 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0)
606 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
607 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
609 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
610 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
613 internal PreFocusChangeSignal PreFocusChangeSignal()
615 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
616 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
620 internal FocusChangedSignal FocusChangedSignal()
622 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
623 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
627 internal FocusGroupChangedSignal FocusGroupChangedSignal()
629 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
630 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
634 internal ViewSignal FocusedViewEnterKeySignal()
636 ViewSignal ret = new ViewSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
637 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
641 private static readonly FocusManager instance = FocusManager.Get();
644 /// Gets the singleton of FocusManager object.
646 public static FocusManager Instance
655 /// ICustomFocusAlgorithm is used to provide custom keyboard focus algorithm for retrieving the next focusable view.<br>
656 /// The application can implement the interface and override the keyboard focus behaviour.<br>
657 /// If focus is changing within a layout container, then the layout container is queried first to provide the next focusable view.<br>
658 /// If this does not provide a valid view, then the Keyboard FocusManager will check focusable properties to determine next focusable actor.<br>
659 /// If focusable properties are not set, then the Keyboard FocusManager calls the GetNextFocusableView() method of this interface.<br>
661 public interface ICustomFocusAlgorithm
663 View GetNextFocusableView(View current, View proposed, View.FocusDirection direction);
666 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
668 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
670 public CustomAlgorithmInterfaceWrapper()
674 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
676 _customFocusAlgorithm = customFocusAlgorithm;
679 public override View GetNextFocusableView(View current, View proposed, View.FocusDirection direction)
681 View currentView = View.DownCast<View>(current);
682 View proposedView = View.DownCast<View>(proposed);
683 return _customFocusAlgorithm.GetNextFocusableView(currentView, proposedView, direction);