nui 0.2.32 manual merge, mapping to dali 1.2.32
[platform/core/csapi/tizenfx.git] / NUISamples / 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
26     /// <summary>
27     /// Provides the functionality of handling keyboard navigation and maintaining the two dimensional keyboard focus chain.
28     /// It provides functionality of setting the focus and moving the focus in four directions(i.e.Left, Right, Up and Down).
29     /// It also draws a highlight for the focused View and sends a event when the focus is changed.
30     /// </summary>
31     public class FocusManager : BaseHandle
32     {
33         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34         private CustomAlgorithmInterfaceWrapper _customAlgorithmInterfaceWrapper;
35
36         internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn)
37         {
38             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39         }
40
41         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj)
42         {
43             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44         }
45
46         ~FocusManager()
47         {
48             DisposeQueue.Instance.Add(this);
49         }
50
51         /// <summary>
52         /// To make FocusManager instance be disposed.
53         /// </summary>
54         public override void Dispose()
55         {
56             if (!Stage.IsInstalled())
57             {
58                 DisposeQueue.Instance.Add(this);
59                 return;
60             }
61
62             lock (this)
63             {
64                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
65                 {
66                     if (swigCMemOwn)
67                     {
68                         swigCMemOwn = false;
69                         NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
70                     }
71                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
72                 }
73                 global::System.GC.SuppressFinalize(this);
74                 base.Dispose();
75             }
76         }
77
78
79         ///<summary>
80         ///Event arguments that passed via PreFocusChange signal
81         /// </summary>
82         public class PreFocusChangeEventArgs : EventArgs
83         {
84             private View _current;
85             private View _proposed;
86             private View.FocusDirection _direction;
87
88             public View CurrentView
89             {
90                 get
91                 {
92                     return _current;
93                 }
94                 set
95                 {
96                     _current = value;
97                 }
98             }
99
100             public View ProposedView
101             {
102                 get
103                 {
104                     return _proposed;
105                 }
106                 set
107                 {
108                     _proposed = value;
109                 }
110             }
111
112             public View.FocusDirection Direction
113             {
114                 get
115                 {
116                     return _direction;
117                 }
118                 set
119                 {
120                     _direction = value;
121                 }
122             }
123         }
124
125         private EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> _preFocusChangeEventHandler;
126         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
127         internal delegate IntPtr PreFocusChangeEventCallback(IntPtr current, IntPtr proposed, View.FocusDirection direction);
128         private PreFocusChangeEventCallback _preFocusChangeCallback;
129
130         public event EventHandlerWithReturnType<object, PreFocusChangeEventArgs, View> PreFocusChange
131         {
132             add
133             {
134                 if (_preFocusChangeEventHandler == null)
135                 {
136                     _preFocusChangeCallback = OnPreFocusChange;
137                     PreFocusChangeSignal().Connect(_preFocusChangeCallback);
138                 }
139                 _preFocusChangeEventHandler += value;
140             }
141             remove
142             {
143                 _preFocusChangeEventHandler -= value;
144                 if (_preFocusChangeEventHandler == null && _preFocusChangeCallback != null)
145                 {
146                     PreFocusChangeSignal().Disconnect(_preFocusChangeCallback);
147                 }
148             }
149         }
150
151         private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.FocusDirection direction)
152         {
153             View view = null;
154             PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
155
156             e.CurrentView = View.GetViewFromPtr(current);
157             e.ProposedView = View.GetViewFromPtr(proposed);
158             e.Direction = direction;
159
160             if (_preFocusChangeEventHandler != null)
161             {
162                 view = _preFocusChangeEventHandler(this, e);
163             }
164
165             if (view)
166             {
167                 return view.GetPtrfromActor();
168             }
169             else
170             {
171                 if (e.ProposedView) return proposed;
172                 else return current;
173             }
174         }
175
176         ///<summary>
177         ///Event arguments that passed via FocusChanged signal
178         /// </summary>
179         public class FocusChangedEventArgs : EventArgs
180         {
181             private View _current;
182             private View _next;
183
184             public View CurrentView
185             {
186                 get
187                 {
188                     return _current;
189                 }
190                 set
191                 {
192                     _current = value;
193                 }
194             }
195
196             public View NextView
197             {
198                 get
199                 {
200                     return _next;
201                 }
202                 set
203                 {
204                     _next = value;
205                 }
206             }
207         }
208
209         private EventHandler<FocusChangedEventArgs> _focusChangedEventHandler;
210         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
211         internal delegate void FocusChangedEventCallback(IntPtr current, IntPtr next);
212         private FocusChangedEventCallback _focusChangedEventCallback;
213
214         public event EventHandler<FocusChangedEventArgs> FocusChanged
215         {
216             add
217             {
218                 if (_focusChangedEventCallback == null)
219                 {
220                     _focusChangedEventCallback = OnFocusChanged;
221                     FocusChangedSignal().Connect(_focusChangedEventCallback);
222                 }
223                 _focusChangedEventHandler += value;
224             }
225             remove
226             {
227                 _focusChangedEventHandler -= value;
228
229                 if (_focusChangedEventCallback == null && _focusChangedEventCallback != null)
230                 {
231                     FocusChangedSignal().Disconnect(_focusChangedEventCallback);
232                 }
233             }
234         }
235
236         private void OnFocusChanged(IntPtr current, IntPtr next)
237         {
238             FocusChangedEventArgs e = new FocusChangedEventArgs();
239
240             e.CurrentView = View.GetViewFromPtr(current);
241             e.NextView = View.GetViewFromPtr(next);
242
243             if (_focusChangedEventHandler != null)
244             {
245                 _focusChangedEventHandler(this, e);
246             }
247         }
248
249         ///<summary>
250         ///Event arguments that passed via FocusGroupChanged signal
251         /// </summary>
252         public class FocusGroupChangedEventArgs : EventArgs
253         {
254             private View _current;
255             private bool _forwardDirection;
256
257             public View CurrentView
258             {
259                 get
260                 {
261                     return _current;
262                 }
263                 set
264                 {
265                     _current = value;
266                 }
267             }
268
269             public bool ForwardDirection
270             {
271                 get
272                 {
273                     return _forwardDirection;
274                 }
275                 set
276                 {
277                     _forwardDirection = value;
278                 }
279             }
280         }
281
282         private EventHandler<FocusGroupChangedEventArgs> _focusGroupChangedEventHandler;
283         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
284         private delegate void FocusGroupChangedEventCallback(IntPtr current, bool forwardDirection);
285         private FocusGroupChangedEventCallback _focusGroupChangedEventCallback;
286
287         public event EventHandler<FocusGroupChangedEventArgs> FocusGroupChanged
288         {
289             add
290             {
291                 if (_focusGroupChangedEventCallback == null)
292                 {
293                     _focusGroupChangedEventCallback = OnFocusGroupChanged;
294                     FocusGroupChangedSignal().Connect(_focusGroupChangedEventCallback);
295                 }
296                 _focusGroupChangedEventHandler += value;
297             }
298             remove
299             {
300                 _focusGroupChangedEventHandler -= value;
301
302                 if (_focusGroupChangedEventCallback == null && _focusGroupChangedEventCallback != null)
303                 {
304                     FocusGroupChangedSignal().Disconnect(_focusGroupChangedEventCallback);
305                 }
306             }
307         }
308
309         private void OnFocusGroupChanged(IntPtr current, bool forwardDirection)
310         {
311             FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
312
313             e.CurrentView = View.GetViewFromPtr(current);
314             e.ForwardDirection = forwardDirection;
315
316             if (_focusGroupChangedEventHandler != null)
317             {
318                 _focusGroupChangedEventHandler(this, e);
319             }
320         }
321
322         ///<summary>
323         ///Event arguments that passed via FocusedViewEnterKey signal
324         /// </summary>
325         public class FocusedViewEnterKeyEventArgs : EventArgs
326         {
327             private View _view;
328
329             public View View
330             {
331                 get
332                 {
333                     return _view;
334                 }
335                 set
336                 {
337                     _view = value;
338                 }
339             }
340         }
341
342         private EventHandler<FocusedViewEnterKeyEventArgs> _focusedViewEnterKeyEventHandler;
343         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
344         private delegate void FocusedViewEnterKeyEventCallback(IntPtr view);
345         private FocusedViewEnterKeyEventCallback _focusedViewEnterKeyEventCallback;
346
347         public event EventHandler<FocusedViewEnterKeyEventArgs> FocusedViewEnterKeyPressed
348         {
349             add
350             {
351                 if (_focusedViewEnterKeyEventCallback == null)
352                 {
353                     _focusedViewEnterKeyEventCallback = OnFocusedViewEnterKey;
354                     FocusedActorEnterKeySignal().Connect(_focusedViewEnterKeyEventCallback);
355                 }
356                 _focusedViewEnterKeyEventHandler += value;
357             }
358             remove
359             {
360                 _focusedViewEnterKeyEventHandler -= value;
361
362                 if (_focusedViewEnterKeyEventCallback == null && _focusedViewEnterKeyEventCallback != null)
363                 {
364                     FocusedActorEnterKeySignal().Disconnect(_focusedViewEnterKeyEventCallback);
365                 }
366             }
367         }
368
369         private void OnFocusedViewEnterKey(IntPtr view)
370         {
371             FocusedViewEnterKeyEventArgs e = new FocusedViewEnterKeyEventArgs();
372
373             e.View = View.GetViewFromPtr(view);
374
375             if (_focusedViewEnterKeyEventHandler != null)
376             {
377                 _focusedViewEnterKeyEventHandler(this, e);
378             }
379         }
380
381
382         internal FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true)
383         {
384             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
385         }
386
387         internal static FocusManager Get()
388         {
389             FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
390             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391             return ret;
392         }
393
394         /// <summary>
395         /// Moves the keyboard focus to the given View.
396         /// Only one View can be focused at the same time.
397         /// The View must be in the stage already and keyboard focusable.
398         /// </summary>
399         /// <param name="view">The View to be focused</param>
400         /// <returns>Whether the focus is successful or not</returns>
401         public bool SetCurrentFocusView(View view)
402         {
403             bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(view));
404             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405             return ret;
406         }
407
408         /// <summary>
409         /// Gets the current focused actor.
410         /// </summary>
411         /// <returns>A handle to the current focused View or an empty handle if no View is focused</returns>
412         public View GetCurrentFocusView()
413         {
414             View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true));
415             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416             return ret;
417         }
418
419         /// <summary>
420         /// Moves the focus to the next focusable View in the focus chain in the given direction(according to the focus traversal order).
421         /// </summary>
422         /// <param name="direction">The direction of focus movement</param>
423         /// <returns>true if the movement was successful</returns>
424         public bool MoveFocus(View.FocusDirection direction)
425         {
426             bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
427             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428             return ret;
429         }
430
431         /// <summary>
432         /// Clears the focus from the current focused actor if any, so that no actor is focused in the focus chain.
433         /// It will emit FocusChanged event without current focused View.
434         /// </summary>
435         public void ClearFocus()
436         {
437             NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
438             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439         }
440
441         /// <summary>
442         /// Sets/Gets the status of whether the focus movement should be looped within the same focus group.
443         /// The focus movement is not looped by default.
444         /// </summary>
445         public bool FocusGroupLoop
446         {
447             set
448             {
449                 SetFocusGroupLoop(value);
450             }
451             get
452             {
453                 return GetFocusGroupLoop();
454             }
455         }
456
457         internal void SetFocusGroupLoop(bool enabled)
458         {
459             NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
460             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461         }
462
463         internal bool GetFocusGroupLoop()
464         {
465             bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
466             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
467             return ret;
468         }
469
470         /// <summary>
471         /// Sets whether an View is a focus group that can limit the scope of focus movement to its child actors in the focus chain.
472         /// Layout controls set themselves as focus groups by default.
473         /// </summary>
474         /// <param name="view">The View to be set as a focus group</param>
475         /// <param name="isFocusGroup">Whether to set the View as a focus group or not</param>
476         public void SetAsFocusGroup(View view, bool isFocusGroup)
477         {
478             NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(view), isFocusGroup);
479             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480         }
481
482         /// <summary>
483         /// Checks whether the actor is set as a focus group or not.
484         /// </summary>
485         /// <param name="view">The View to be checked</param>
486         /// <returns>Whether the View is set as a focus group</returns>
487         public bool IsFocusGroup(View view)
488         {
489             bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(view));
490             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
491             return ret;
492         }
493
494         /// <summary>
495         /// Returns the closest ancestor of the given actor that is a focus group.
496         /// </summary>
497         /// <param name="view">The View to be checked for its focus group</param>
498         /// <returns>The focus group the given view belongs to or an empty handle if the given view</returns>
499         public View GetFocusGroup(View view)
500         {
501             View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(view)), true));
502             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503             return ret;
504         }
505
506         /// <summary>
507         /// Sets/Gets the focus indicator View.
508         /// This will replace the default focus indicator view in FocusManager and will be added to the focused view as a highlight.
509         /// </summary>
510         public View FocusIndicator
511         {
512             set
513             {
514                 SetFocusIndicatorView(value);
515             }
516             get
517             {
518                 return GetFocusIndicatorView();
519             }
520         }
521
522         internal void SetFocusIndicatorView(View indicator)
523         {
524             NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
525             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
526         }
527
528         internal View GetFocusIndicatorView()
529         {
530             View ret = View.DownCast(new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true));
531             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532             return ret;
533         }
534
535         public void SetCustomAlgorithm(ICustomFocusAlgorithm arg0) {
536             _customAlgorithmInterfaceWrapper = new CustomAlgorithmInterfaceWrapper();
537             _customAlgorithmInterfaceWrapper.SetFocusAlgorithm(arg0);
538
539             NDalicPINVOKE.SetCustomAlgorithm(swigCPtr, CustomAlgorithmInterface.getCPtr(_customAlgorithmInterfaceWrapper));
540             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541         }
542
543         internal PreFocusChangeSignal PreFocusChangeSignal()
544         {
545             PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
546             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
547             return ret;
548         }
549
550         internal FocusChangedSignal FocusChangedSignal()
551         {
552             FocusChangedSignal ret = new FocusChangedSignal(NDalicManualPINVOKE.FocusManager_FocusChangedSignal(swigCPtr), false);
553             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
554             return ret;
555         }
556
557         internal FocusGroupChangedSignal FocusGroupChangedSignal()
558         {
559             FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
560             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
561             return ret;
562         }
563
564         internal ActorSignal FocusedActorEnterKeySignal()
565         {
566             ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
567             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
568             return ret;
569         }
570
571         private static readonly FocusManager instance = FocusManager.Get();
572
573         /// <summary>
574         /// Gets the singleton of FocusManager object.
575         /// </summary>
576         public static FocusManager Instance
577         {
578             get
579             {
580                 return instance;
581             }
582         }
583
584         public interface ICustomFocusAlgorithm
585         {
586             View GetNextFocusableActor(View current, View proposed, View.FocusDirection direction);
587         }
588
589         private class CustomAlgorithmInterfaceWrapper : CustomAlgorithmInterface
590         {
591             private FocusManager.ICustomFocusAlgorithm _customFocusAlgorithm;
592
593             public CustomAlgorithmInterfaceWrapper()
594             {
595             }
596
597             public void SetFocusAlgorithm(FocusManager.ICustomFocusAlgorithm customFocusAlgorithm)
598             {
599                 _customFocusAlgorithm = customFocusAlgorithm;
600             }
601
602             public override Actor GetNextFocusableActor(Actor current, Actor proposed, View.FocusDirection direction)
603             {
604                 View currentView = View.DownCast<View>(current);
605                 View proposedView = View.DownCast<View>(proposed);
606                 return _customFocusAlgorithm.GetNextFocusableActor(currentView, proposedView, direction);
607             }
608         }
609     }
610 }