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