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;
35 internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn)
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 DisposeQueue.Instance.Add(this);
51 /// To make FocusManager instance be disposed.
53 public override void Dispose()
55 if (!Stage.IsInstalled())
57 DisposeQueue.Instance.Add(this);
63 if (swigCPtr.Handle != global::System.IntPtr.Zero)
68 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
70 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
72 global::System.GC.SuppressFinalize(this);
79 ///Event arguments that passed via PreFocusChange signal
81 public class PreFocusChangeEventArgs : EventArgs
83 private View _current;
84 private View _proposed;
85 private View.FocusDirection _direction;
87 public View CurrentView
99 public View ProposedView
111 public View.FocusDirection Direction
124 private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
125 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
126 internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
127 private PreFocusChangeEventCallback _preFocusChangeCallback;
129 public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
133 if (_preFocusChangeEventHandler == null)
135 _preFocusChangeCallback = OnPreFocusChange;
136 PreFocusChangeSignal().Connect(_preFocusChangeCallback);
138 _preFocusChangeEventHandler += value;
142 _preFocusChangeEventHandler -= value;
143 if (_preFocusChangeEventHandler == null && _preFocusChangeCallback != null)
145 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
150 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
153 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
155 e.CurrentView = View.GetViewFromPtr(current);
156 e.ProposedView = View.GetViewFromPtr(proposed);
157 e.Direction = direction;
159 if (_preFocusChangeEventHandler != null)
161 view = _preFocusChangeEventHandler(this, e);
166 return view.GetPtrfromActor();
170 if (e.ProposedView) return proposed;
176 ///Event arguments that passed via FocusChanged signal
178 public class FocusChangedEventArgs : EventArgs
180 private View _current;
183 public View CurrentView
208 private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
209 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
210 internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
211 private FocusChangedEventCallback _focusChangedEventCallback;
213 public event EventHandler<FocusChangedEventArgs> FocusChanged
217 if (_focusChangedEventCallback == null)
219 _focusChangedEventCallback = OnFocusChanged;
220 FocusChangedSignal().Connect(_focusChangedEventCallback);
222 _focusChangedEventHandler += value;
226 _focusChangedEventHandler -= value;
228 if (_focusChangedEventCallback == null && _focusChangedEventCallback != null)
230 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
235 private void OnFocusChanged(IntPtr current, IntPtr next)
237 FocusChangedEventArgs e = new FocusChangedEventArgs();
239 e.CurrentView = View.GetViewFromPtr(current);
240 e.NextView = View.GetViewFromPtr(next);
242 if (_focusChangedEventHandler != null)
244 _focusChangedEventHandler(this, e);
249 ///Event arguments that passed via FocusGroupChanged signal
251 public class FocusGroupChangedEventArgs : EventArgs
253 private View _current;
254 private bool _forwardDirection;
256 public View CurrentView
268 public bool ForwardDirection
272 return _forwardDirection;
276 _forwardDirection = value;
281 private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
282 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
283 private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
284 private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
286 public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
290 if (_focusGroupChangedEventCallback == null)
292 _focusGroupChangedEventCallback = OnFocusGroupChanged;
293 FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
295 _focusGroupChangedEventHandler += value;
299 _focusGroupChangedEventHandler -= value;
301 if (_focusGroupChangedEventCallback == null && _focusGroupChangedEventCallback != null)
303 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
308 private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
310 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
312 e.CurrentView = View.GetViewFromPtr(current);
313 e.ForwardDirection = forwardDirection;
315 if (_focusGroupChangedEventHandler != null)
317 _focusGroupChangedEventHandler(this, e);
322 ///Event arguments that passed via FocusedViewEnterKey signal
324 public class FocusedViewEnterKeyEventArgs : EventArgs
341 private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler;
342 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
343 private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
344 private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
346 public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
350 if (_focusedViewEnterKeyEventCallback == null)
352 _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
353 FocusedActorEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
355 _focusedViewEnterKeyEventHandler += value;
359 _focusedViewEnterKeyEventHandler -= value;
361 if (_focusedViewEnterKeyEventCallback == null && _focusedViewEnterKeyEventCallback != null)
363 FocusedActorEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
368 private void OnFocusedViewEnterKey(IntPtr view)
370 FocusedViewEnterKeyEventArgs e = new FocusedViewEnterKeyEventArgs();
372 e.View = View.GetViewFromPtr(view);
374 if (_focusedViewEnterKeyEventHandler != null)
376 _focusedViewEnterKeyEventHandler(this, e);
381 internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 internal static FocusManager Get()
388 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394 /// Moves the keyboard focus to the given View.
395 /// Only one View can be focused at the same time.
396 /// The View must be in the stage already and keyboard focusable.
398 /// <param name="view">The View to be focused</param>
399 /// <returns>Whether the focus is successful or not</returns>
400 public bool SetCurrentFocusView(View view)
402 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(view));
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 /// Gets the current focused actor.
410 /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
411 public View GetCurrentFocusView()
413 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true));
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
421 /// <param name="direction">The direction of focus movement</param>
422 /// <returns>true if the movement was successful</returns>
423 public bool MoveFocus(View.FocusDirection direction)
425 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
426 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 /// Clears the focus from the current focused actor if any, so that no actor is focused in the focus chain.
432 /// It will emit FocusChanged event without current focused View.
434 public void ClearFocus()
436 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441 /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.
442 /// The focus movement is not looped by default.
444 public bool FocusGroupLoop
448 SetFocusGroupLoop(value);
452 return GetFocusGroupLoop();
456 internal void SetFocusGroupLoop(bool enabled)
458 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
459 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462 internal bool GetFocusGroupLoop()
464 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470 /// Sets whether an View is a focus group that can limit the scope of focus movement to its child actors in the focus chain.
471 /// Layout controls set themselves as focus groups by default.
473 /// <param name="view">The View to be set as a focus group</param>
474 /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
475 public void SetAsFocusGroup(View view, bool isFocusGroup)
477 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(view), isFocusGroup);
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482 /// Checks whether the actor is set as a focus group or not.
484 /// <param name="view">The View to be checked</param>
485 /// <returns>Whether the View is set as a focus group</returns>
486 public bool IsFocusGroup(View view)
488 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(view));
489 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
494 /// Returns the closest ancestor of the given actor that is a focus group.
496 /// <param name="view">The View to be checked for its focus group</param>
497 /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
498 public View GetFocusGroup(View view)
500 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(view)), true));
501 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
506 /// Sets/Gets the focus indicator View.
507 /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.
509 public View FocusIndicator
513 SetFocusIndicatorView(value);
517 return GetFocusIndicatorView();
521 internal void SetFocusIndicatorView(View indicator)
523 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
524 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
527 internal View GetFocusIndicatorView()
529 View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true));
530 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
534 internal PreFocusChangeSignal PreFocusChangeSignal()
536 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
537 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541 internal FocusChangedSignal FocusChangedSignal()
543 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
544 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 internal FocusGroupChangedSignal FocusGroupChangedSignal()
550 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
551 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
555 internal ActorSignal FocusedActorEnterKeySignal()
557 ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
558 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
562 private static readonly FocusManager instance = FocusManager.Get();
565 /// Gets the singleton of FocusManager object.
567 public static FocusManager Instance