3c84a1bf191320b85da76783d79f7b84a8d6624a
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / FocusManager.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21 using System.ComponentModel;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
26     /// Provides the functionality of handling keyboard navigation and maintaining the two-dimensional keyboard focus chain.<br />
27     /// It provides functionality of setting the focus and moving the focus in four directions( i.e., left, right, up, and down).<br />
28     /// It also draws a highlight for the focused view and sends an event when the focus is changed.<br />
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     public class FocusManager : BaseHandle
32     {
33         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34         private CustomAlgorithmInterfaceWrapper _customAlgorithmInterfaceWrapper;
35
36         internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn)
37         {
38             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39         }
40
41         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj)
42         {
43             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44         }
45
46         /// <summary>
47         /// To make the FocusManager instance be disposed.
48         /// </summary>
49         /// Please DO NOT use! This will be deprecated!
50         /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
51         /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
52         /// <since_tizen> 3 </since_tizen>
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         protected override void Dispose(DisposeTypes type)
55         {
56             if (disposed)
57             {
58                 return;
59             }
60
61             if (type == DisposeTypes.Explicit)
62             {
63                 //Called by User
64                 //Release your own managed resources here.
65                 //You should release all of your own disposable objects here.
66             }
67
68             //Release your own unmanaged resources here.
69             //You should not access any managed member here except static instance.
70             //because the execution order of Finalizes is non-deterministic.
71
72             if (_focusedViewEnterKeyEventCallback2 != null)
73             {
74                 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback2);
75             }
76
77             if (_focusedViewEnterKeyEventCallback != null)
78             {
79                 FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
80             }
81
82             if (_focusGroupChangedEventCallback != null)
83             {
84                 FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
85             }
86
87             if (_focusChangedEventCallback != null)
88             {
89                 FocusChangedSignal().Disconnect(_focusChangedEventCallback);
90             }
91
92             if (_preFocusChangeCallback != null)
93             {
94                 PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
95             }
96
97             if (swigCPtr.Handle != global::System.IntPtr.Zero)
98             {
99                 if (swigCMemOwn)
100                 {
101                     swigCMemOwn = false;
102                     NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
103                 }
104                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
105             }
106
107             base.Dispose(type);
108         }
109
110
111         ///<summary>
112         /// Event arguments that passed via the PreFocusChange signal.
113         /// </summary>
114         /// <since_tizen> 3 </since_tizen>
115         public class PreFocusChangeEventArgs : EventArgs
116         {
117             private View _current;
118             private View _proposed;
119             private View.FocusDirection _direction;
120
121             /// <summary>
122             /// The current focus view.
123             /// </summary>
124             /// <since_tizen> 3 </since_tizen>
125             public View CurrentView
126             {
127                 get
128                 {
129                     return _current;
130                 }
131                 set
132                 {
133                     _current = value;
134                 }
135             }
136
137             /// <summary>
138             /// The  proposed view.
139             /// </summary>
140             /// <since_tizen> 3 </since_tizen>
141             public View ProposedView
142             {
143                 get
144                 {
145                     return _proposed;
146                 }
147                 set
148                 {
149                     _proposed = value;
150                 }
151             }
152
153             /// <summary>
154             /// The focus move direction.
155             /// </summary>
156             /// <since_tizen> 3 </since_tizen>
157             public View.FocusDirection Direction
158             {
159                 get
160                 {
161                     return _direction;
162                 }
163                 set
164                 {
165                     _direction = value;
166                 }
167             }
168         }
169
170         private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
171         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
172         internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
173         private PreFocusChangeEventCallback _preFocusChangeCallback;
174
175         /// <summary>
176         /// PreFocusChange will be triggered before the focus is going to be changed.<br />
177         /// The FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.<br />
178         /// By connecting with this event, they can check the proposed view to focus and return a different view if they wish.<br />
179         /// This event is only triggered when the navigation key is pressed and KeyboardFocusManager tries to move the focus automatically.<br />
180         /// It won't be emitted for focus movement by calling the SetCurrentFocusView directly.<br />
181         /// </summary>
182         /// <since_tizen> 3 </since_tizen>
183         public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
184         {
185             add
186             {
187                 if (_preFocusChangeEventHandler == null)
188                 {
189 #if DEBUG_ON
190                     Tizen.Log.Debug("NUI", "con1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
191                     Tizen.Log.Debug("NUI", "con2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
192 #endif
193                     _preFocusChangeCallback = OnPreFocusChange;
194                     PreFocusChangeSignal().Connect(_preFocusChangeCallback);
195 #if DEBUG_ON
196                     Tizen.Log.Debug("NUI", "con3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
197                     Tizen.Log.Debug("NUI", "con4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
198 #endif
199                 }
200                 _preFocusChangeEventHandler += value;
201             }
202             remove
203             {
204                 _preFocusChangeEventHandler -= value;
205                 if (_preFocusChangeEventHandler == null && PreFocusChangeSignal().Empty() == false)
206                 {
207 #if DEBUG_ON
208                     Tizen.Log.Debug("NUI", "discon1) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
209                     Tizen.Log.Debug("NUI", "discon2) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
210 #endif
211                     PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
212 #if DEBUG_ON
213                     Tizen.Log.Debug("NUI", "discon3) PreFocusChangeSignal().Empty = " + PreFocusChangeSignal().Empty());
214                     Tizen.Log.Debug("NUI", "discon4) PreFocusChangeSignal().GetConnectionCount = " + PreFocusChangeSignal().GetConnectionCount());
215 #endif
216                 }
217             }
218         }
219
220         private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
221         {
222             View view = null;
223             PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
224
225             if (current != global::System.IntPtr.Zero)
226             {
227                 e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View;
228             }
229             if (proposed != global::System.IntPtr.Zero)
230             {
231                 e.ProposedView = Registry.GetManagedBaseHandleFromNativePtr(proposed) as View;
232             }
233             e.Direction = direction;
234
235             if (_preFocusChangeEventHandler != null)
236             {
237                 view = _preFocusChangeEventHandler(this, e);
238             }
239
240             if (view)
241             {
242                 return view.GetPtrfromView();
243             }
244             else
245             {
246                 //if (e.ProposedView) return proposed;
247                 //else return current;
248                 return current; //xb.teng
249             }
250         }
251
252         ///<summary>
253         /// Event arguments that passed via the FocusChanged signal.
254         /// </summary>
255         /// <since_tizen> 3 </since_tizen>
256         public class FocusChangedEventArgs : EventArgs
257         {
258             private View _current;
259             private View _next;
260
261             /// <summary>
262             /// The current focus view.
263             /// </summary>
264             /// <since_tizen> 3 </since_tizen>
265             public View CurrentView
266             {
267                 get
268                 {
269                     return _current;
270                 }
271                 set
272                 {
273                     _current = value;
274                 }
275             }
276             /// <summary>
277             /// The next focus view.
278             /// </summary>
279             /// <since_tizen> 3 </since_tizen>
280             public View NextView
281             {
282                 get
283                 {
284                     return _next;
285                 }
286                 set
287                 {
288                     _next = value;
289                 }
290             }
291         }
292
293         private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
294         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
295         internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
296         private FocusChangedEventCallback _focusChangedEventCallback;
297
298         /// <summary>
299         /// The FocusGroupChanged will be triggered after the current focused view has been changed.
300         /// </summary>
301         /// <since_tizen> 3 </since_tizen>
302         public event EventHandler<FocusChangedEventArgs> FocusChanged
303         {
304             add
305             {
306                 if (_focusChangedEventCallback == null)
307                 {
308                     _focusChangedEventCallback = OnFocusChanged;
309                     FocusChangedSignal().Connect(_focusChangedEventCallback);
310                 }
311                 _focusChangedEventHandler += value;
312             }
313             remove
314             {
315                 _focusChangedEventHandler -= value;
316
317                 if (_focusChangedEventCallback == null && FocusChangedSignal().Empty() == false)
318                 {
319                     FocusChangedSignal().Disconnect(_focusChangedEventCallback);
320                 }
321             }
322         }
323
324         private void OnFocusChanged(IntPtr current, IntPtr next)
325         {
326             FocusChangedEventArgs e = new FocusChangedEventArgs();
327
328             e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View;
329             e.NextView = Registry.GetManagedBaseHandleFromNativePtr(next) as View;
330
331             if (_focusChangedEventHandler != null)
332             {
333                 _focusChangedEventHandler(this, e);
334             }
335         }
336
337         ///<summary>
338         /// Event arguments that passed via the FocusGroupChanged signal.
339         /// </summary>
340         /// <since_tizen> 3 </since_tizen>
341         public class FocusGroupChangedEventArgs : EventArgs
342         {
343             private View _current;
344             private bool _forwardDirection;
345
346             /// <summary>
347             /// The current focus view.
348             /// </summary>
349             /// <since_tizen> 3 </since_tizen>
350             public View CurrentView
351             {
352                 get
353                 {
354                     return _current;
355                 }
356                 set
357                 {
358                     _current = value;
359                 }
360             }
361
362             /// <summary>
363             /// The forward direction.
364             /// </summary>
365             /// <since_tizen> 3 </since_tizen>
366             public bool ForwardDirection
367             {
368                 get
369                 {
370                     return _forwardDirection;
371                 }
372                 set
373                 {
374                     _forwardDirection = value;
375                 }
376             }
377         }
378
379         private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
380         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
381         private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
382         private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
383
384         /// <summary>
385         /// The FocusGroupChanged will be triggered when the focus group has been changed.<br />
386         /// If the current focus group has a parent layout control, the FocusManager will make the best guess for the next focus group to move the focus to in the given direction (forward or backward).<br />
387         /// If not, the application has to set the new focus.<br />
388         /// </summary>
389         /// <since_tizen> 3 </since_tizen>
390         public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
391         {
392             add
393             {
394                 if (_focusGroupChangedEventCallback == null)
395                 {
396                     _focusGroupChangedEventCallback = OnFocusGroupChanged;
397                     FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
398                 }
399                 _focusGroupChangedEventHandler += value;
400             }
401             remove
402             {
403                 _focusGroupChangedEventHandler -= value;
404
405                 if (_focusGroupChangedEventCallback == null && FocusGroupChangedSignal().Empty() == false)
406                 {
407                     FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
408                 }
409             }
410         }
411
412         private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
413         {
414             FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
415
416             e.CurrentView = Registry.GetManagedBaseHandleFromNativePtr(current) as View;
417             e.ForwardDirection = forwardDirection;
418
419             if (_focusGroupChangedEventHandler != null)
420             {
421                 _focusGroupChangedEventHandler(this, e);
422             }
423         }
424
425         ///<summary>
426         /// Event arguments that passed via the FocusedViewEnterKey signal.
427         /// </summary>
428         /// <since_tizen> 3 </since_tizen>
429         public class FocusedViewActivatedEventArgs : EventArgs
430         {
431             private View _view;
432
433             /// <summary>
434             /// View.
435             /// </summary>
436             /// <since_tizen> 3 </since_tizen>
437             public View View
438             {
439                 get
440                 {
441                     return _view;
442                 }
443                 set
444                 {
445                     _view = value;
446                 }
447             }
448         }
449
450         private EventHandler<FocusedViewActivatedEventArgs> _focusedViewEnterKeyEventHandler;
451         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
452         private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
453         private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
454
455         /// <summary>
456         /// The FocusedViewActivated will be triggered when the current focused view has the enter key pressed on it.
457         /// </summary>
458         /// <since_tizen> 3 </since_tizen>
459         public event EventHandler<FocusedViewActivatedEventArgs> FocusedViewActivated
460         {
461             add
462             {
463                 if (_focusedViewEnterKeyEventCallback == null)
464                 {
465                     _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
466                     FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
467                 }
468                 _focusedViewEnterKeyEventHandler += value;
469             }
470             remove
471             {
472                 _focusedViewEnterKeyEventHandler -= value;
473
474                 if (_focusedViewEnterKeyEventCallback != null && FocusedViewEnterKeySignal().Empty() == false)
475                 {
476                     FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
477                 }
478             }
479         }
480
481         private void OnFocusedViewEnterKey(IntPtr view)
482         {
483             FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs();
484
485             e.View = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
486
487             if (_focusedViewEnterKeyEventHandler != null)
488             {
489                 _focusedViewEnterKeyEventHandler(this, e);
490             }
491         }
492
493
494         internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
495         {
496             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497         }
498
499         internal static FocusManager Get()
500         {
501             FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
502             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503             return ret;
504         }
505
506         /// <summary>
507         /// Moves the keyboard focus to the given view.<br />
508         /// Only one view can be focused at the same time.<br />
509         /// The view must be in the stage already and keyboard focusable.<br />
510         /// </summary>
511         /// <param name="view">The view to be focused.</param>
512         /// <returns>Whether the focus is successful or not.</returns>
513         /// <since_tizen> 3 </since_tizen>
514         public bool SetCurrentFocusView(View view)
515         {
516             if (view == null)
517             {
518                 throw new ArgumentNullException("the target view should not be null");
519             }
520
521             bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, View.getCPtr(view));
522             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
523             return ret;
524         }
525
526         /// <summary>
527         /// Gets the current focused view.
528         /// </summary>
529         /// <returns>A handle to the current focused view or an empty handle if no view is focused.</returns>
530         /// <since_tizen> 3 </since_tizen>
531         public View GetCurrentFocusView()
532         {
533             IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr);
534
535             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
536             return ret;
537         }
538
539         /// <summary>
540         /// Moves the focus to the next focusable view in the focus chain in the given direction (according to the focus traversal order).
541         /// </summary>
542         /// <param name="direction">The direction of the focus movement.</param>
543         /// <returns>True if the movement was successful.</returns>
544         /// <since_tizen> 3 </since_tizen>
545         public bool MoveFocus(View.FocusDirection direction)
546         {
547             bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
548             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
549             return ret;
550         }
551
552         /// <summary>
553         /// Clears the focus from the current focused view if any, so that no view is focused in the focus chain.<br />
554         /// It will emit the FocusChanged event without the current focused view.<br />
555         /// </summary>
556         /// <since_tizen> 3 </since_tizen>
557         public void ClearFocus()
558         {
559             NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
560             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
561         }
562
563         /// <summary>
564         /// Move the focus to previous focused view.
565         /// </summary>
566         /// <since_tizen> 3 </since_tizen>
567         public void MoveFocusBackward()
568         {
569             NDalicManualPINVOKE.FocusManager_MoveFocusBackward(swigCPtr);
570             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
571         }
572
573         /// <summary>
574         /// Gets or sets the status of whether the focus movement should be looped within the same focus group.<br />
575         /// The focus movement is not looped by default.<br />
576         /// </summary>
577         /// <since_tizen> 3 </since_tizen>
578         public bool FocusGroupLoop
579         {
580             set
581             {
582                 SetFocusGroupLoop(value);
583             }
584             get
585             {
586                 return GetFocusGroupLoop();
587             }
588         }
589
590         internal void SetFocusGroupLoop(bool enabled)
591         {
592             NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
593             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594         }
595
596         internal bool GetFocusGroupLoop()
597         {
598             bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
599             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
600             return ret;
601         }
602
603         /// <summary>
604         /// Sets whether the view is a focus group that can limit the scope of the focus movement to its child views in the focus chain.<br />
605         /// Layout controls set themselves as focus groups by default.<br />
606         /// </summary>
607         /// <param name="view">The view to be set as a focus group.</param>
608         /// <param name="isFocusGroup">Whether to set the view as a focus group or not.</param>
609         /// <since_tizen> 3 </since_tizen>
610         public void SetAsFocusGroup(View view, bool isFocusGroup)
611         {
612             NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, View.getCPtr(view), isFocusGroup);
613             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
614         }
615
616         /// <summary>
617         /// Checks whether the view is set as a focus group or not.
618         /// </summary>
619         /// <param name="view">The view to be checked.</param>
620         /// <returns>Whether the view is set as a focus group.</returns>
621         /// <since_tizen> 3 </since_tizen>
622         public bool IsFocusGroup(View view)
623         {
624             bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, View.getCPtr(view));
625             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
626             return ret;
627         }
628
629         /// <summary>
630         /// Returns the closest ancestor of the given view that is a focus group.
631         /// </summary>
632         /// <param name="view">The view to be checked for its focus group.</param>
633         /// <returns>The focus group the given view belongs to or an empty handle if the given view.</returns>
634         /// <since_tizen> 3 </since_tizen>
635         public View GetFocusGroup(View view)
636         {
637             IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view));
638
639             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
640
641
642             /*View ret = new View(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, View.getCPtr(view)), true);
643             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
644             if (ret.HasBody() == false)
645             {
646                 return null;
647             }*/
648
649             return ret;
650         }
651
652         /// <summary>
653         /// Gets or sets the focus indicator view.<br />
654         /// This will replace the default focus indicator view in the FocusManager and will be added to the focused view as a highlight.<br />
655         /// </summary>
656         /// <since_tizen> 3 </since_tizen>
657         public View FocusIndicator
658         {
659             set
660             {
661                 SetFocusIndicatorView(value);
662             }
663             get
664             {
665                 return GetFocusIndicatorView();
666             }
667         }
668
669         internal void SetFocusIndicatorView(View indicator)
670         {
671             NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, View.getCPtr(indicator));
672             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
673         }
674
675         internal View GetFocusIndicatorView()
676         {
677             IntPtr cPtr = NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr);
678
679             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
680
681             return ret;
682         }
683
684         /// <summary>
685         /// Provides the implementation of a custom focus algorithm interface to allow the application to define the focus logic.<br />
686         /// </summary>
687         /// <param name="arg0">The user's implementation of ICustomFocusAlgorithm.</param>
688         /// <since_tizen> 3 </since_tizen>
689         public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0)
690         {
691             _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
692             _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
693
694             NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
695             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
696         }
697
698         internal PreFocusChangeSignal PreFocusChangeSignal()
699         {
700             PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
701             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
702             return ret;
703         }
704
705         internal FocusChangedSignal FocusChangedSignal()
706         {
707             FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
708             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
709             return ret;
710         }
711
712         internal FocusGroupChangedSignal FocusGroupChangedSignal()
713         {
714             FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
715             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
716             return ret;
717         }
718
719         internal ViewSignal FocusedViewEnterKeySignal()
720         {
721             ViewSignal ret = new ViewSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
722             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
723             return ret;
724         }
725
726         private static readonly FocusManager instance = FocusManager.Get();
727
728         /// <summary>
729         /// Gets the singleton of the FocusManager object.
730         /// </summary>
731         /// <since_tizen> 3 </since_tizen>
732         public static FocusManager Instance
733         {
734             get
735             {
736                 return instance;
737             }
738         }
739
740         /// <summary>
741         /// ICustomFocusAlgorithm is used to provide the custom keyboard focus algorithm for retrieving the next focusable view.<br />
742         /// The application can implement the interface and override the keyboard focus behavior.<br />
743         /// If the focus is changing within a layout container, then the layout container is queried first to provide the next focusable view.<br />
744         /// If this does not provide a valid view, then the Keyboard FocusManager will check focusable properties to determine the next focusable actor.<br />
745         /// If focusable properties are not set, then the keyboard FocusManager calls the GetNextFocusableView() method of this interface.<br />
746         /// </summary>
747         /// <since_tizen> 3 </since_tizen>
748         public interface ICustomFocusAlgorithm
749         {
750             /// <summary>
751             /// Get the next focus actor.
752             /// </summary>
753             /// <param name="current">The current focus view.</param>
754             /// <param name="proposed">The proposed focus view</param>
755             /// <param name="direction">The focus move direction</param>
756             /// <returns>The next focus actor.</returns>
757             /// <since_tizen> 3 </since_tizen>
758             View GetNextFocusableView(View current, View proposed, View.FocusDirection direction);
759         }
760
761         private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
762         {
763             private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
764
765             public CustomAlgorithmInterfaceWrapper()
766             {
767             }
768
769             public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
770             {
771                 _customFocusAlgorithm = customFocusAlgorithm;
772             }
773
774             public override View GetNextFocusableView(View current, View proposed, View.FocusDirection direction)
775             {
776                 return _customFocusAlgorithm.GetNextFocusableView(current, proposed, direction);
777             }
778         }
779
780
781         /// <summary>
782         /// Please do not use! this will be deprecated
783         /// </summary>
784         /// <since_tizen> 3 </since_tizen>
785         /// Please do not use! this will be deprecated.
786         /// Instead please use FocusedViewActivatedEventArgs.
787         [EditorBrowsable(EditorBrowsableState.Never)]
788         public class FocusedViewEnterKeyEventArgs : EventArgs
789         {
790             private View _view;
791
792             /// <summary>
793             /// View.
794             /// </summary>
795             /// <since_tizen> 3 </since_tizen>
796             public View View
797             {
798                 get
799                 {
800                     return _view;
801                 }
802                 set
803                 {
804                     _view = value;
805                 }
806             }
807         }
808
809         private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler2;
810         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
811         private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view);
812         private FocusedViewEnterKeyEventCallback2 _focusedViewEnterKeyEventCallback2;
813
814         /// <summary>
815         /// [Obsolete("Please do not use! this will be deprecated")]
816         /// </summary>
817         /// <since_tizen> 3 </since_tizen>
818         /// Please do not use! this will be deprecated!
819         /// Instead please use FocusedViewActivated.
820         [Obsolete("Please DO NOT use! This will be deprecated, instead please USE Tizen.NUI.FocusManager.FocusedViewActivated!")]
821         [EditorBrowsable(EditorBrowsableState.Never)]
822         public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
823         {
824             add
825             {
826                 if (_focusedViewEnterKeyEventCallback2 == null)
827                 {
828                     _focusedViewEnterKeyEventCallback2 = OnFocusedViewEnterKey2;
829                     FocusedViewEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback2);
830                 }
831                 _focusedViewEnterKeyEventHandler2 += value;
832             }
833             remove
834             {
835                 _focusedViewEnterKeyEventHandler2 -= value;
836
837                 if (_focusedViewEnterKeyEventCallback2 != null && FocusedViewEnterKeySignal().Empty() == false)
838                 {
839                     FocusedViewEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback2);
840                 }
841             }
842         }
843         /// <summary>
844         /// Please do not use! this will be deprecated!
845         /// </summary>
846         /// Please do not use! this will be deprecated!
847         /// Instead please use OnFocusedViewEnterKey.
848         [Obsolete("Please DO NOT use! This will be deprecated, instead please USE Tizen.NUI.FocusManager.OnFocusedViewEnterKey")]
849         [EditorBrowsable(EditorBrowsableState.Never)]
850         private void OnFocusedViewEnterKey2(IntPtr view)
851         {
852             FocusedViewActivatedEventArgs e = new FocusedViewActivatedEventArgs();
853
854             e.View = Registry.GetManagedBaseHandleFromNativePtr(view) as View;
855
856             if (_focusedViewEnterKeyEventHandler != null)
857             {
858                 _focusedViewEnterKeyEventHandler(this, e);
859             }
860         }
861     }
862 }