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