2 * Copyright (c) 2017 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 (!Window.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 View _viewCurrent;
66 private View _viewNext;
69 * @brief ViewCurrent - is the original focused View
72 public View ViewCurrent
85 * @brief ViewNext - is the current focused View
102 * @brief Event arguments that passed via FocusGroupChanged signal
105 public class FocusGroupChangedEventArgs : EventArgs
107 private View _currentFocusedView;
108 private bool _forwardDirection;
111 * @brief CurrentFocusedView - is the current focused View
114 public View CurrentFocusedView
118 return _currentFocusedView;
122 _currentFocusedView = 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 FocusedViewEnterKey signal
147 public class FocusedViewEnterKeyEventArgs : EventArgs
152 * @brief View - is the current focused View which has the enter key pressed on it.
169 * @brief Event arguments that passed via PreFocusChange signal
172 public class PreFocusChangeEventArgs : EventArgs
174 private View _current;
175 private View _proposed;
176 private View.KeyboardFocus.Direction _direction;
179 * @brief Current - is the current focused View.
195 * @brief Proposed - is the proposed focused View.
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 FocusedViewEnterKeyEventHandler(object source, FocusedViewEnterKeyEventArgs e);
236 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
237 public delegate View 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 FocusedViewEnterKeyEventCallbackDelegate(IntPtr actor);
256 private FocusedViewEnterKeyEventHandler _FocusManagerFocusedViewEnterKeyEventHandler;
257 private FocusedViewEnterKeyEventCallbackDelegate _FocusManagerFocusedViewEnterKeyEventCallbackDelegate;
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 if (current != global::System.IntPtr.Zero)
299 e.Current = View.GetViewFromPtr(current);
302 if (proposed != global::System.IntPtr.Zero)
304 e.Proposed = View.GetViewFromPtr(proposed);
307 e.Direction = direction;
309 if (_FocusManagerPreFocusChangeEventHandler != null)
311 //here we send all data to user event handlers
312 view = _FocusManagerPreFocusChangeEventHandler(this, e);
317 return view.GetPtrfromView();
326 * @brief Event for FocusChanged signal which can be used to subscribe/unsubscribe the event handler
327 * (in the type of FocusChangedEventHandler) provided by the user.
328 * FocusChanged signal is emitted after the current focused view has been changed.
330 public event FocusChangedEventHandler FocusChanged
336 // Restricted to only one listener
337 if (_FocusManagerFocusChangedEventHandler == null)
339 _FocusManagerFocusChangedEventHandler += value;
341 _FocusManagerFocusChangedEventCallbackDelegate = new FocusChangedEventCallbackDelegate(OnFocusChanged);
342 this.FocusChangedSignal().Connect(_FocusManagerFocusChangedEventCallbackDelegate);
351 if (_FocusManagerFocusChangedEventHandler != null)
353 this.FocusChangedSignal().Disconnect(_FocusManagerFocusChangedEventCallbackDelegate);
356 _FocusManagerFocusChangedEventHandler -= value;
361 // Callback for FocusManager FocusChangedSignal
362 private void OnFocusChanged(IntPtr viewCurrent, IntPtr viewNext)
364 FocusChangedEventArgs e = new FocusChangedEventArgs();
366 // Populate all members of "e" (FocusChangedEventArgs) with real data
367 e.ViewCurrent = View.GetViewFromPtr(viewCurrent);
368 e.ViewNext = View.GetViewFromPtr(viewNext);
370 if (_FocusManagerFocusChangedEventHandler != null)
372 //here we send all data to user event handlers
373 _FocusManagerFocusChangedEventHandler(this, e);
378 * @brief Event for FocusGroupChanged signal which can be used to subscribe/unsubscribe the event handler
379 * (in the type of FocusGroupChangedEventHandler) provided by the user.
380 * FocusGroupChanged signal is emitted when the focus group has been changed.
382 public event FocusGroupChangedEventHandler FocusGroupChanged
388 // Restricted to only one listener
389 if (_FocusManagerFocusGroupChangedEventHandler == null)
391 _FocusManagerFocusGroupChangedEventHandler += value;
393 _FocusManagerFocusGroupChangedEventCallbackDelegate = new FocusGroupChangedEventCallbackDelegate(OnFocusGroupChanged);
394 this.FocusGroupChangedSignal().Connect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
403 if (_FocusManagerFocusGroupChangedEventHandler != null)
405 this.FocusGroupChangedSignal().Disconnect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
408 _FocusManagerFocusGroupChangedEventHandler -= value;
413 // Callback for FocusManager FocusGroupChangedSignal
414 private void OnFocusGroupChanged(IntPtr currentFocusedView, bool forwardDirection)
416 FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
418 // Populate all members of "e" (FocusGroupChangedEventArgs) with real data
419 e.CurrentFocusedView = View.GetViewFromPtr(currentFocusedView);
420 e.ForwardDirection = forwardDirection;
422 if (_FocusManagerFocusGroupChangedEventHandler != null)
424 //here we send all data to user event handlers
425 _FocusManagerFocusGroupChangedEventHandler(this, e);
430 * @brief Event for FocusedViewEnterKeyPressed signal which can be used to subscribe/unsubscribe the event handler
431 * (in the type of FocusedViewEnterKeyEventHandler) provided by the user.
432 * FocusedViewEnterKeyPressed signal is emitted when the current focused view has the enter key pressed on it.
434 public event FocusedViewEnterKeyEventHandler FocusedViewEnterKeyPressed
440 // Restricted to only one listener
441 if (_FocusManagerFocusedViewEnterKeyEventHandler == null)
443 _FocusManagerFocusedViewEnterKeyEventHandler += value;
445 _FocusManagerFocusedViewEnterKeyEventCallbackDelegate = new FocusedViewEnterKeyEventCallbackDelegate(OnFocusedViewEnterKey);
446 this.FocusedViewEnterKeySignal().Connect(_FocusManagerFocusedViewEnterKeyEventCallbackDelegate);
455 if (_FocusManagerFocusedViewEnterKeyEventHandler != null)
457 this.FocusedViewEnterKeySignal().Disconnect(_FocusManagerFocusedViewEnterKeyEventCallbackDelegate);
460 _FocusManagerFocusedViewEnterKeyEventHandler -= value;
465 // Callback for FocusManager FocusedViewEnterKeySignal
466 private void OnFocusedViewEnterKey(IntPtr view)
468 FocusedViewEnterKeyEventArgs e = new FocusedViewEnterKeyEventArgs();
470 // Populate all members of "e" (FocusedViewEnterKeyEventArgs) with real data
471 e.View = View.GetViewFromPtr(view);
473 if (_FocusManagerFocusedViewEnterKeyEventHandler != null)
475 //here we send all data to user event handlers
476 _FocusManagerFocusedViewEnterKeyEventHandler(this, e);
480 public FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true) {
481 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
484 public static FocusManager Get() {
485 FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
486 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 public bool SetCurrentFocusView(View view) {
491 bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, View.getCPtr(view));
492 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
496 public View GetCurrentFocusView() {
497 View ret = new View(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true);
498 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
502 public bool MoveFocus(View.KeyboardFocus.Direction direction) {
503 bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
504 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
508 public void ClearFocus() {
509 NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
510 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
513 public void SetFocusGroupLoop(bool enabled) {
514 NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
515 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 public bool GetFocusGroupLoop() {
519 bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
520 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
524 public void SetAsFocusGroup(View view, bool isFocusGroup) {
525 NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, View.getCPtr(view), isFocusGroup);
526 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
529 public bool IsFocusGroup(View view) {
530 bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, View.getCPtr(view));
531 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
535 public View GetFocusGroup(View view) {
536 View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true);
537 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541 public void SetFocusIndicatorView(View indicator) {
542 NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, View.getCPtr(indicator));
543 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
546 public View GetFocusIndicatorView() {
547 View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true);
548 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
552 public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0) {
553 _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
554 _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
556 NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
557 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560 public PreFocusChangeSignal PreFocusChangeSignal() {
561 PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
562 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
566 public FocusChangedSignal FocusChangedSignal() {
567 FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
568 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
572 public FocusGroupChangedSignal FocusGroupChangedSignal() {
573 FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
574 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
578 public ViewSignal FocusedViewEnterKeySignal() {
579 ViewSignal ret = new ViewSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
580 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
584 private static readonly FocusManager instance = FocusManager.Get();
586 public static FocusManager Instance
594 public interface ICustomFocusAlgorithm
596 View GetNextFocusableView(View current, View proposed, View.KeyboardFocus.Direction direction);
599 private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
601 private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
603 public CustomAlgorithmInterfaceWrapper()
607 public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
609 _customFocusAlgorithm = customFocusAlgorithm;
612 public override View GetNextFocusableView(View current, View proposed, View.KeyboardFocus.Direction direction)
614 View currentView = View.DownCast<View>(current);
615 View proposedView = View.DownCast<View>(proposed);
616 return _customFocusAlgorithm.GetNextFocusableView(currentView, proposedView, direction);