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