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