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;
26 internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn) {
27 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj) {
31 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35 DisposeQueue.Instance.Add(this);
38 public override void Dispose() {
39 if (!Stage.IsInstalled()) {
40 DisposeQueue.Instance.Add(this);
45 if (swigCPtr.Handle != global::System.IntPtr.Zero) {
48 NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
50 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
52 global::System.GC.SuppressFinalize(this);
59 * @brief Event arguments that passed via FocusChanged signal
62 public class FocusChangedEventArgs : EventArgs
64 private Actor _actorCurrent;
65 private Actor _actorNext;
68 * @brief Actor - is the original focused Actor
71 public Actor ActorCurrent
79 _actorCurrent = value;
84 * @brief Actor - is the current focused Actor
87 public Actor ActorNext
101 * @brief Event arguments that passed via FocusGroupChanged signal
104 public class FocusGroupChangedEventArgs : EventArgs
106 private Actor _currentFocusedActor;
107 private bool _forwardDirection;
110 * @brief Actor - is the current focused Actor
113 public Actor CurrentFocusedActor
117 return _currentFocusedActor;
121 _currentFocusedActor = value;
126 * @brief ForwardDirection - is the direction (forward or backward) in which to move the focus next
129 public bool ForwardDirection
133 return _forwardDirection;
137 _forwardDirection = value;
143 * @brief Event arguments that passed via FocusedActorEnterKey signal
146 public class FocusedActorEnterKeyEventArgs : EventArgs
148 private Actor _actor;
151 * @brief Actor - is the current focused Actor which has the enter key pressed on it.
168 * @brief Event arguments that passed via PreFocusChange signal
171 public class PreFocusChangeEventArgs : EventArgs
173 private Actor _current;
174 private Actor _proposed;
175 private View.KeyboardFocus.Direction _direction;
178 * @brief Actor - is the current focused Actor.
194 * @brief Actor - is the proposed focused Actor.
197 public Actor Proposed
210 * @brief Direction - is the direction of Focus change.
213 public View.KeyboardFocus.Direction Direction
226 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
227 public delegate void FocusChangedEventHandler(object source, FocusChangedEventArgs e);
229 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
230 public delegate void FocusGroupChangedEventHandler(object source, FocusGroupChangedEventArgs e);
232 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
233 public delegate void FocusedActorEnterKeyEventHandler(object source, FocusedActorEnterKeyEventArgs e);
235 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
236 public delegate Actor PreFocusChangeEventHandler(object source, PreFocusChangeEventArgs e);
238 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
239 public delegate IntPtr PreFocusChangeEventCallbackDelegate(IntPtr current, IntPtr proposed, View.KeyboardFocus.Direction direction);
240 private PreFocusChangeEventHandler _FocusManagerPreFocusChangeEventHandler;
241 private PreFocusChangeEventCallbackDelegate _FocusManagerPreFocusChangeEventCallbackDelegate;
243 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
244 private delegate void FocusChangedEventCallbackDelegate(IntPtr actorCurrent, IntPtr actorNext);
245 private FocusChangedEventHandler _FocusManagerFocusChangedEventHandler;
246 private FocusChangedEventCallbackDelegate _FocusManagerFocusChangedEventCallbackDelegate;
248 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
249 private delegate void FocusGroupChangedEventCallbackDelegate(IntPtr currentFocusedActor, bool forwardDirection);
250 private FocusGroupChangedEventHandler _FocusManagerFocusGroupChangedEventHandler;
251 private FocusGroupChangedEventCallbackDelegate _FocusManagerFocusGroupChangedEventCallbackDelegate;
253 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
254 private delegate void FocusedActorEnterKeyEventCallbackDelegate(IntPtr actor);
255 private FocusedActorEnterKeyEventHandler _FocusManagerFocusedActorEnterKeyEventHandler;
256 private FocusedActorEnterKeyEventCallbackDelegate _FocusManagerFocusedActorEnterKeyEventCallbackDelegate;
258 public event PreFocusChangeEventHandler PreFocusChange
264 // Restricted to only one listener
265 if (_FocusManagerPreFocusChangeEventHandler == null)
267 _FocusManagerPreFocusChangeEventHandler += value;
269 _FocusManagerPreFocusChangeEventCallbackDelegate = new PreFocusChangeEventCallbackDelegate(OnPreFocusChange);
270 this.PreFocusChangeSignal().Connect(_FocusManagerPreFocusChangeEventCallbackDelegate);
279 if (_FocusManagerPreFocusChangeEventHandler != null)
281 this.PreFocusChangeSignal().Disconnect(_FocusManagerPreFocusChangeEventCallbackDelegate);
284 _FocusManagerPreFocusChangeEventHandler -= value;
289 // Callback for FocusManager PreFocusChangeSignal
290 private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.KeyboardFocus.Direction direction)
293 PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
295 // Populate all members of "e" (PreFocusChangeEventArgs) with real data
296 e.Current = Actor.GetActorFromPtr(current);
297 e.Proposed = Actor.GetActorFromPtr(proposed);
298 e.Direction = direction;
300 if (_FocusManagerPreFocusChangeEventHandler != null)
302 //here we send all data to user event handlers
303 actor = _FocusManagerPreFocusChangeEventHandler(this, e);
306 return actor.GetPtrfromActor();
310 * @brief Event for FocusChanged signal which can be used to subscribe/unsubscribe the event handler
311 * (in the type of FocusChangedEventHandler) provided by the user.
312 * FocusChanged signal is emitted after the current focused actor has been changed.
314 public event FocusChangedEventHandler FocusChanged
320 // Restricted to only one listener
321 if (_FocusManagerFocusChangedEventHandler == null)
323 _FocusManagerFocusChangedEventHandler += value;
325 _FocusManagerFocusChangedEventCallbackDelegate = new FocusChangedEventCallbackDelegate(OnFocusChanged);
326 this.FocusChangedSignal().Connect(_FocusManagerFocusChangedEventCallbackDelegate);
335 if (_FocusManagerFocusChangedEventHandler != null)
337 this.FocusChangedSignal().Disconnect(_FocusManagerFocusChangedEventCallbackDelegate);
340 _FocusManagerFocusChangedEventHandler -= value;
345 // Callback for FocusManager FocusChangedSignal
346 private void OnFocusChanged(IntPtr actorCurrent, IntPtr actorNext)
348 FocusChangedEventArgs e = new FocusChangedEventArgs();
350 // Populate all members of "e" (FocusChangedEventArgs) with real data
351 e.ActorCurrent = Actor.GetActorFromPtr(actorCurrent);
352 e.ActorNext = Actor.GetActorFromPtr(actorNext);
354 if (_FocusManagerFocusChangedEventHandler != null)
356 //here we send all data to user event handlers
357 _FocusManagerFocusChangedEventHandler(this, e);
362 * @brief Event for FocusGroupChanged signal which can be used to subscribe/unsubscribe the event handler
363 * (in the type of FocusGroupChangedEventHandler) provided by the user.
364 * FocusGroupChanged signal is emitted when the focus group has been changed.
366 public event FocusGroupChangedEventHandler FocusGroupChanged
372 // Restricted to only one listener
373 if (_FocusManagerFocusGroupChangedEventHandler == null)
375 _FocusManagerFocusGroupChangedEventHandler += value;
377 _FocusManagerFocusGroupChangedEventCallbackDelegate = new FocusGroupChangedEventCallbackDelegate(OnFocusGroupChanged);
378 this.FocusGroupChangedSignal().Connect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
387 if (_FocusManagerFocusGroupChangedEventHandler != null)
389 this.FocusGroupChangedSignal().Disconnect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
392 _FocusManagerFocusGroupChangedEventHandler -= value;
397 // Callback for FocusManager FocusGroupChangedSignal
398 private void OnFocusGroupChanged(IntPtr currentFocusedActor, bool forwardDirection)
400 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
402 // Populate all members of "e" (FocusGroupChangedEventArgs) with real data
403 e.CurrentFocusedActor = Actor.GetActorFromPtr(currentFocusedActor);
404 e.ForwardDirection = forwardDirection;
406 if (_FocusManagerFocusGroupChangedEventHandler != null)
408 //here we send all data to user event handlers
409 _FocusManagerFocusGroupChangedEventHandler(this, e);
414 * @brief Event for FocusedActorEnterKeyPressed signal which can be used to subscribe/unsubscribe the event handler
415 * (in the type of FocusedActorEnterKeyEventHandler) provided by the user.
416 * FocusedActorEnterKeyPressed signal is emitted when the current focused actor has the enter key pressed on it.
418 public event FocusedActorEnterKeyEventHandler FocusedActorEnterKeyPressed
424 // Restricted to only one listener
425 if (_FocusManagerFocusedActorEnterKeyEventHandler == null)
427 _FocusManagerFocusedActorEnterKeyEventHandler += value;
429 _FocusManagerFocusedActorEnterKeyEventCallbackDelegate = new FocusedActorEnterKeyEventCallbackDelegate(OnFocusedActorEnterKey);
430 this.FocusedActorEnterKeySignal().Connect(_FocusManagerFocusedActorEnterKeyEventCallbackDelegate);
439 if (_FocusManagerFocusedActorEnterKeyEventHandler != null)
441 this.FocusedActorEnterKeySignal().Disconnect(_FocusManagerFocusedActorEnterKeyEventCallbackDelegate);
444 _FocusManagerFocusedActorEnterKeyEventHandler -= value;
449 // Callback for FocusManager FocusedActorEnterKeySignal
450 private void OnFocusedActorEnterKey(IntPtr actor)
452 FocusedActorEnterKeyEventArgs e = new FocusedActorEnterKeyEventArgs();
454 // Populate all members of "e" (FocusedActorEnterKeyEventArgs) with real data
455 e.Actor = Actor.GetActorFromPtr(actor);
457 if (_FocusManagerFocusedActorEnterKeyEventHandler != null)
459 //here we send all data to user event handlers
460 _FocusManagerFocusedActorEnterKeyEventHandler(this, e);
464 public FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true) {
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 public static FocusManager Get() {
469 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
470 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
474 public bool SetCurrentFocusActor(Actor actor) {
475 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(actor));
476 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480 public Actor GetCurrentFocusActor() {
481 Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true);
482 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486 public bool MoveFocus(View.KeyboardFocus.Direction direction) {
487 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
488 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 public void ClearFocus() {
493 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
494 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497 public void SetFocusGroupLoop(bool enabled) {
498 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
499 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
502 public bool GetFocusGroupLoop() {
503 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
508 public void SetAsFocusGroup(Actor actor, bool isFocusGroup) {
509 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(actor), isFocusGroup);
510 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513 public bool IsFocusGroup(Actor actor) {
514 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(actor));
515 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
519 public Actor GetFocusGroup(Actor actor) {
520 Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(actor)), true);
521 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525 public void SetFocusIndicatorActor(Actor indicator) {
526 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
527 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
530 public Actor GetFocusIndicatorActor() {
531 Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true);
532 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
536 public PreFocusChangeSignal PreFocusChangeSignal() {
537 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
538 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
542 public FocusChangedSignal FocusChangedSignal() {
543 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
544 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548 public FocusGroupChangedSignal FocusGroupChangedSignal() {
549 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
550 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
554 public ActorSignal FocusedActorEnterKeySignal() {
555 ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
556 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560 private static readonly FocusManager instance = FocusManager.Get();
562 public static FocusManager Instance