2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 using System.Runtime.InteropServices;
23 public class FocusManager : BaseHandle {
24 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
25 private CustomAlgorithmInterfaceWrapper _customAlgorithmInterfaceWrapper;
27 internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn) {
28 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj) {
32 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36 DisposeQueue.Instance.Add(this);
39 public override void Dispose() {
40 if (!Stage.IsInstalled()) {
41 DisposeQueue.Instance.Add(this);
46 if (swigCPtr.Handle != global::System.IntPtr.Zero) {
49 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
51 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
53 global::System.GC.SuppressFinalize(this);
60 * @brief Event arguments that passed via FocusChanged signal
63 public class FocusChangedEventArgs : EventArgs
65 private Actor _actorCurrent;
66 private Actor _actorNext;
69 * @brief Actor - is the original focused Actor
72 public Actor ActorCurrent
80 _actorCurrent = value;
85 * @brief Actor - is the current focused Actor
88 public Actor ActorNext
102 * @brief Event arguments that passed via FocusGroupChanged signal
105 public class FocusGroupChangedEventArgs : EventArgs
107 private Actor _currentFocusedActor;
108 private bool _forwardDirection;
111 * @brief Actor - is the current focused Actor
114 public Actor CurrentFocusedActor
118 return _currentFocusedActor;
122 _currentFocusedActor = value;
127 * @brief ForwardDirection - is the direction (forward or backward) in which to move the focus next
130 public bool ForwardDirection
134 return _forwardDirection;
138 _forwardDirection = value;
144 * @brief Event arguments that passed via FocusedActorEnterKey signal
147 public class FocusedActorEnterKeyEventArgs : EventArgs
149 private Actor _actor;
152 * @brief Actor - is the current focused Actor which has the enter key pressed on it.
169 * @brief Event arguments that passed via PreFocusChange signal
172 public class PreFocusChangeEventArgs : EventArgs
174 private Actor _current;
175 private Actor _proposed;
176 private View.KeyboardFocus.Direction _direction;
179 * @brief Actor - is the current focused Actor.
195 * @brief Actor - is the proposed focused Actor.
198 public Actor Proposed
211 * @brief Direction - is the direction of Focus change.
214 public View.KeyboardFocus.Direction Direction
227 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
228 public delegate void FocusChangedEventHandler(object source, FocusChangedEventArgs e);
230 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
231 public delegate void FocusGroupChangedEventHandler(object source, FocusGroupChangedEventArgs e);
233 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
234 public delegate void FocusedActorEnterKeyEventHandler(object source, FocusedActorEnterKeyEventArgs e);
236 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
237 public delegate Actor PreFocusChangeEventHandler(object source, PreFocusChangeEventArgs e);
239 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
240 public delegate IntPtr PreFocusChangeEventCallbackDelegate(IntPtr current, IntPtr proposed, View.KeyboardFocus.Direction direction);
241 private PreFocusChangeEventHandler _FocusManagerPreFocusChangeEventHandler;
242 private PreFocusChangeEventCallbackDelegate _FocusManagerPreFocusChangeEventCallbackDelegate;
244 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
245 private delegate void FocusChangedEventCallbackDelegate(IntPtr actorCurrent, IntPtr actorNext);
246 private FocusChangedEventHandler _FocusManagerFocusChangedEventHandler;
247 private FocusChangedEventCallbackDelegate _FocusManagerFocusChangedEventCallbackDelegate;
249 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
250 private delegate void FocusGroupChangedEventCallbackDelegate(IntPtr currentFocusedActor, bool forwardDirection);
251 private FocusGroupChangedEventHandler _FocusManagerFocusGroupChangedEventHandler;
252 private FocusGroupChangedEventCallbackDelegate _FocusManagerFocusGroupChangedEventCallbackDelegate;
254 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
255 private delegate void FocusedActorEnterKeyEventCallbackDelegate(IntPtr actor);
256 private FocusedActorEnterKeyEventHandler _FocusManagerFocusedActorEnterKeyEventHandler;
257 private FocusedActorEnterKeyEventCallbackDelegate _FocusManagerFocusedActorEnterKeyEventCallbackDelegate;
259 public event PreFocusChangeEventHandler PreFocusChange
265 // Restricted to only one listener
266 if (_FocusManagerPreFocusChangeEventHandler == null)
268 _FocusManagerPreFocusChangeEventHandler += value;
270 _FocusManagerPreFocusChangeEventCallbackDelegate = new PreFocusChangeEventCallbackDelegate(OnPreFocusChange);
271 this.PreFocusChangeSignal().Connect(_FocusManagerPreFocusChangeEventCallbackDelegate);
280 if (_FocusManagerPreFocusChangeEventHandler != null)
282 this.PreFocusChangeSignal().Disconnect(_FocusManagerPreFocusChangeEventCallbackDelegate);
285 _FocusManagerPreFocusChangeEventHandler -= value;
290 // Callback for FocusManager PreFocusChangeSignal
291 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.KeyboardFocus.Direction direction)
294 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
296 // Populate all members of "e" (PreFocusChangeEventArgs) with real data
297 e.Current = Actor.GetActorFromPtr(current);
298 e.Proposed = Actor.GetActorFromPtr(proposed);
299 e.Direction = direction;
301 if (_FocusManagerPreFocusChangeEventHandler != null)
303 //here we send all data to user event handlers
304 actor = _FocusManagerPreFocusChangeEventHandler(this, e);
307 return actor.GetPtrfromActor();
311 * @brief Event for FocusChanged signal which can be used to subscribe/unsubscribe the event handler
312 * (in the type of FocusChangedEventHandler) provided by the user.
313 * FocusChanged signal is emitted after the current focused actor has been changed.
315 public event FocusChangedEventHandler FocusChanged
321 // Restricted to only one listener
322 if (_FocusManagerFocusChangedEventHandler == null)
324 _FocusManagerFocusChangedEventHandler += value;
326 _FocusManagerFocusChangedEventCallbackDelegate = new FocusChangedEventCallbackDelegate(OnFocusChanged);
327 this.FocusChangedSignal().Connect(_FocusManagerFocusChangedEventCallbackDelegate);
336 if (_FocusManagerFocusChangedEventHandler != null)
338 this.FocusChangedSignal().Disconnect(_FocusManagerFocusChangedEventCallbackDelegate);
341 _FocusManagerFocusChangedEventHandler -= value;
346 // Callback for FocusManager FocusChangedSignal
347 private void OnFocusChanged(IntPtr actorCurrent, IntPtr actorNext)
349 FocusChangedEventArgs e = new FocusChangedEventArgs();
351 // Populate all members of "e" (FocusChangedEventArgs) with real data
352 e.ActorCurrent = Actor.GetActorFromPtr(actorCurrent);
353 e.ActorNext = Actor.GetActorFromPtr(actorNext);
355 if (_FocusManagerFocusChangedEventHandler != null)
357 //here we send all data to user event handlers
358 _FocusManagerFocusChangedEventHandler(this, e);
363 * @brief Event for FocusGroupChanged signal which can be used to subscribe/unsubscribe the event handler
364 * (in the type of FocusGroupChangedEventHandler) provided by the user.
365 * FocusGroupChanged signal is emitted when the focus group has been changed.
367 public event FocusGroupChangedEventHandler FocusGroupChanged
373 // Restricted to only one listener
374 if (_FocusManagerFocusGroupChangedEventHandler == null)
376 _FocusManagerFocusGroupChangedEventHandler += value;
378 _FocusManagerFocusGroupChangedEventCallbackDelegate = new FocusGroupChangedEventCallbackDelegate(OnFocusGroupChanged);
379 this.FocusGroupChangedSignal().Connect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
388 if (_FocusManagerFocusGroupChangedEventHandler != null)
390 this.FocusGroupChangedSignal().Disconnect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
393 _FocusManagerFocusGroupChangedEventHandler -= value;
398 // Callback for FocusManager FocusGroupChangedSignal
399 private void OnFocusGroupChanged(IntPtr currentFocusedActor, bool forwardDirection)
401 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
403 // Populate all members of "e" (FocusGroupChangedEventArgs) with real data
404 e.CurrentFocusedActor = Actor.GetActorFromPtr(currentFocusedActor);
405 e.ForwardDirection = forwardDirection;
407 if (_FocusManagerFocusGroupChangedEventHandler != null)
409 //here we send all data to user event handlers
410 _FocusManagerFocusGroupChangedEventHandler(this, e);
415 * @brief Event for FocusedActorEnterKeyPressed signal which can be used to subscribe/unsubscribe the event handler
416 * (in the type of FocusedActorEnterKeyEventHandler) provided by the user.
417 * FocusedActorEnterKeyPressed signal is emitted when the current focused actor has the enter key pressed on it.
419 public event FocusedActorEnterKeyEventHandler FocusedActorEnterKeyPressed
425 // Restricted to only one listener
426 if (_FocusManagerFocusedActorEnterKeyEventHandler == null)
428 _FocusManagerFocusedActorEnterKeyEventHandler += value;
430 _FocusManagerFocusedActorEnterKeyEventCallbackDelegate = new FocusedActorEnterKeyEventCallbackDelegate(OnFocusedActorEnterKey);
431 this.FocusedActorEnterKeySignal().Connect(_FocusManagerFocusedActorEnterKeyEventCallbackDelegate);
440 if (_FocusManagerFocusedActorEnterKeyEventHandler != null)
442 this.FocusedActorEnterKeySignal().Disconnect(_FocusManagerFocusedActorEnterKeyEventCallbackDelegate);
445 _FocusManagerFocusedActorEnterKeyEventHandler -= value;
450 // Callback for FocusManager FocusedActorEnterKeySignal
451 private void OnFocusedActorEnterKey(IntPtr actor)
453 FocusedActorEnterKeyEventArgs e = new FocusedActorEnterKeyEventArgs();
455 // Populate all members of "e" (FocusedActorEnterKeyEventArgs) with real data
456 e.Actor = Actor.GetActorFromPtr(actor);
458 if (_FocusManagerFocusedActorEnterKeyEventHandler != null)
460 //here we send all data to user event handlers
461 _FocusManagerFocusedActorEnterKeyEventHandler(this, e);
465 public FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true) {
466 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 public static FocusManager Get() {
470 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
471 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475 public bool SetCurrentFocusActor(Actor actor) {
476 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(actor));
477 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 public Actor GetCurrentFocusActor() {
482 Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true);
483 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
487 public bool MoveFocus(View.KeyboardFocus.Direction direction) {
488 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
489 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
493 public void ClearFocus() {
494 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
495 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498 public void SetFocusGroupLoop(bool enabled) {
499 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503 public bool GetFocusGroupLoop() {
504 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
505 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
509 public void SetAsFocusGroup(Actor actor, bool isFocusGroup) {
510 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(actor), isFocusGroup);
511 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514 public bool IsFocusGroup(Actor actor) {
515 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(actor));
516 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520 public Actor GetFocusGroup(Actor actor) {
521 Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(actor)), true);
522 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
526 public void SetFocusIndicatorActor(Actor indicator) {
527 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
528 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531 public Actor GetFocusIndicatorActor() {
532 Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true);
533 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
537 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0) {
538 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
539 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
541 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
542 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
545 public PreFocusChangeSignal PreFocusChangeSignal() {
546 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
547 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
551 public FocusChangedSignal FocusChangedSignal() {
552 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
553 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557 public FocusGroupChangedSignal FocusGroupChangedSignal() {
558 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
559 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
563 public ActorSignal FocusedActorEnterKeySignal() {
564 ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
565 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
569 private static readonly FocusManager instance = FocusManager.Get();
571 public static FocusManager Instance
579 public interface ICustomFocusAlgorithm
581 View GetNextFocusableActor(View current, View proposed, View.KeyboardFocus.Direction direction);
584 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
586 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
588 public CustomAlgorithmInterfaceWrapper()
592 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
594 _customFocusAlgorithm = customFocusAlgorithm;
597 public override Actor GetNextFocusableActor(Actor current, Actor proposed, View.KeyboardFocus.Direction direction)
599 View currentView = View.DownCast<View>(current);
600 View proposedView = View.DownCast<View>(proposed);
601 return _customFocusAlgorithm.GetNextFocusableActor(currentView, proposedView, direction);