Add C# bindings for Actor's POSITION_USES_ANCHOR_POINT property
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / manual / csharp / FocusManager.cs
1 /*
2  * Copyright (c) 2016 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 namespace Dali {
19
20 using System;
21 using System.Runtime.InteropServices;
22
23 public class FocusManager : BaseHandle {
24   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
25
26   internal FocusManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.FocusManager_SWIGUpcast(cPtr), cMemoryOwn) {
27     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
28   }
29
30   internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FocusManager obj) {
31     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
32   }
33
34   ~FocusManager() {
35     DisposeQueue.Instance.Add(this);
36   }
37
38   public override void Dispose() {
39     if (!Stage.IsInstalled()) {
40       DisposeQueue.Instance.Add(this);
41       return;
42     }
43
44     lock(this) {
45       if (swigCPtr.Handle != global::System.IntPtr.Zero) {
46         if (swigCMemOwn) {
47           swigCMemOwn = false;
48           NDalicManualPINVOKE.delete_FocusManager(swigCPtr);
49         }
50         swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
51       }
52       global::System.GC.SuppressFinalize(this);
53       base.Dispose();
54     }
55   }
56
57
58 /**
59   * @brief Event arguments that passed via FocusChanged signal
60   *
61   */
62 public class FocusChangedEventArgs : EventArgs
63 {
64    private Actor _actorCurrent;
65    private Actor _actorNext;
66
67    /**
68      * @brief Actor - is the original focused Actor
69      *
70      */
71    public Actor ActorCurrent
72    {
73       get
74       {
75          return _actorCurrent;
76       }
77       set
78       {
79          _actorCurrent = value;
80       }
81    }
82
83    /**
84      * @brief Actor - is the current focused Actor
85      *
86      */
87    public Actor ActorNext
88    {
89       get
90       {
91          return _actorNext;
92       }
93       set
94       {
95          _actorNext = value;
96       }
97    }
98 }
99
100 /**
101   * @brief Event arguments that passed via FocusGroupChanged signal
102   *
103   */
104 public class FocusGroupChangedEventArgs : EventArgs
105 {
106    private Actor _currentFocusedActor;
107    private bool _forwardDirection;
108
109    /**
110      * @brief Actor - is the current focused Actor
111      *
112      */
113    public Actor CurrentFocusedActor
114    {
115       get
116       {
117          return _currentFocusedActor;
118       }
119       set
120       {
121          _currentFocusedActor = value;
122       }
123    }
124
125    /**
126      * @brief ForwardDirection - is the direction (forward or backward) in which to move the focus next
127      *
128      */
129    public bool ForwardDirection
130    {
131       get
132       {
133          return _forwardDirection;
134       }
135       set
136       {
137          _forwardDirection = value;
138       }
139    }
140 }
141
142 /**
143   * @brief Event arguments that passed via FocusedActorEnterKey signal
144   *
145   */
146 public class FocusedActorEnterKeyEventArgs : EventArgs
147 {
148    private Actor _actor;
149
150    /**
151      * @brief Actor - is the current focused Actor which has the enter key pressed on it.
152      *
153      */
154    public Actor Actor
155    {
156       get
157       {
158          return _actor;
159       }
160       set
161       {
162          _actor = value;
163       }
164    }
165 }
166
167 /**
168   * @brief Event arguments that passed via PreFocusChange signal
169   *
170   */
171 public class PreFocusChangeEventArgs : EventArgs
172 {
173    private Actor _current;
174    private Actor _proposed;
175    private View.KeyboardFocus.Direction _direction;
176
177    /**
178     * @brief Actor - is the current focused Actor.
179     *
180     */
181    public Actor Current
182    {
183       get
184       {
185          return _current;
186       }
187       set
188       {
189           _current = value;
190       }
191    }
192
193     /**
194     * @brief Actor - is the proposed focused Actor.
195     *
196     */
197     public Actor Proposed
198     {
199         get
200         {
201             return _proposed;
202         }
203         set
204         {
205             _proposed = value;
206         }
207     }
208
209     /**
210     * @brief Direction - is the direction of Focus change.
211     *
212     */
213     public View.KeyboardFocus.Direction Direction
214     {
215         get
216         {
217             return _direction;
218         }
219         set
220         {
221             _direction = value;
222         }
223     }
224 }
225
226   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
227   public delegate void FocusChangedEventHandler(object source, FocusChangedEventArgs e);
228
229   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
230   public delegate void FocusGroupChangedEventHandler(object source, FocusGroupChangedEventArgs e);
231
232   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
233   public delegate void FocusedActorEnterKeyEventHandler(object source, FocusedActorEnterKeyEventArgs e);
234
235   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
236   public delegate Actor PreFocusChangeEventHandler(object source, PreFocusChangeEventArgs e);
237
238   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
239   public delegate IntPtr PreFocusChangeEventCallbackDelegate(IntPtr current, IntPtr proposed, View.KeyboardFocus.Direction direction);
240   private PreFocusChangeEventHandler _FocusManagerPreFocusChangeEventHandler;
241   private PreFocusChangeEventCallbackDelegate _FocusManagerPreFocusChangeEventCallbackDelegate;
242
243   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
244   private delegate void FocusChangedEventCallbackDelegate(IntPtr actorCurrent, IntPtr actorNext);
245   private FocusChangedEventHandler _FocusManagerFocusChangedEventHandler;
246   private FocusChangedEventCallbackDelegate _FocusManagerFocusChangedEventCallbackDelegate;
247
248   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
249   private delegate void FocusGroupChangedEventCallbackDelegate(IntPtr currentFocusedActor, bool forwardDirection);
250   private FocusGroupChangedEventHandler _FocusManagerFocusGroupChangedEventHandler;
251   private FocusGroupChangedEventCallbackDelegate _FocusManagerFocusGroupChangedEventCallbackDelegate;
252
253   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
254   private delegate void FocusedActorEnterKeyEventCallbackDelegate(IntPtr actor);
255   private FocusedActorEnterKeyEventHandler _FocusManagerFocusedActorEnterKeyEventHandler;
256   private FocusedActorEnterKeyEventCallbackDelegate _FocusManagerFocusedActorEnterKeyEventCallbackDelegate;
257
258   public event PreFocusChangeEventHandler PreFocusChange
259   {
260      add
261      {
262         lock(this)
263         {
264            // Restricted to only one listener
265            if (_FocusManagerPreFocusChangeEventHandler == null)
266            {
267                _FocusManagerPreFocusChangeEventHandler += value;
268
269                _FocusManagerPreFocusChangeEventCallbackDelegate = new PreFocusChangeEventCallbackDelegate(OnPreFocusChange);
270               this.PreFocusChangeSignal().Connect(_FocusManagerPreFocusChangeEventCallbackDelegate);
271            }
272         }
273      }
274
275      remove
276      {
277         lock(this)
278         {
279            if (_FocusManagerPreFocusChangeEventHandler != null)
280            {
281               this.PreFocusChangeSignal().Disconnect(_FocusManagerPreFocusChangeEventCallbackDelegate);
282            }
283
284            _FocusManagerPreFocusChangeEventHandler -= value;
285         }
286      }
287   }
288
289   // Callback for FocusManager PreFocusChangeSignal
290   private IntPtr OnPreFocusChange(IntPtr current, IntPtr proposed, View.KeyboardFocus.Direction direction)
291   {
292       Actor actor = null;
293       PreFocusChangeEventArgs e = new PreFocusChangeEventArgs();
294
295       // Populate all members of "e" (PreFocusChangeEventArgs) with real data
296       e.Current = Actor.GetActorFromPtr(current);
297       e.Proposed = Actor.GetActorFromPtr(proposed);
298       e.Direction = direction;
299
300       if (_FocusManagerPreFocusChangeEventHandler != null)
301       {
302         //here we send all data to user event handlers
303           actor = _FocusManagerPreFocusChangeEventHandler(this, e);
304       }
305
306       return actor.GetPtrfromActor();
307   }
308
309   /**
310     * @brief Event for FocusChanged signal which can be used to subscribe/unsubscribe the event handler
311     * (in the type of FocusChangedEventHandler) provided by the user.
312     * FocusChanged signal is emitted after the current focused actor has been changed.
313     */
314   public event FocusChangedEventHandler FocusChanged
315   {
316      add
317      {
318         lock(this)
319         {
320            // Restricted to only one listener
321            if (_FocusManagerFocusChangedEventHandler == null)
322            {
323               _FocusManagerFocusChangedEventHandler += value;
324
325               _FocusManagerFocusChangedEventCallbackDelegate = new FocusChangedEventCallbackDelegate(OnFocusChanged);
326               this.FocusChangedSignal().Connect(_FocusManagerFocusChangedEventCallbackDelegate);
327            }
328         }
329      }
330
331      remove
332      {
333         lock(this)
334         {
335            if (_FocusManagerFocusChangedEventHandler != null)
336            {
337               this.FocusChangedSignal().Disconnect(_FocusManagerFocusChangedEventCallbackDelegate);
338            }
339
340            _FocusManagerFocusChangedEventHandler -= value;
341         }
342      }
343   }
344
345   // Callback for FocusManager FocusChangedSignal
346   private void OnFocusChanged(IntPtr actorCurrent, IntPtr actorNext)
347   {
348      FocusChangedEventArgs e = new FocusChangedEventArgs();
349
350      // Populate all members of "e" (FocusChangedEventArgs) with real data
351      e.ActorCurrent = Actor.GetActorFromPtr(actorCurrent);
352      e.ActorNext = Actor.GetActorFromPtr(actorNext);
353
354      if (_FocusManagerFocusChangedEventHandler != null)
355      {
356         //here we send all data to user event handlers
357         _FocusManagerFocusChangedEventHandler(this, e);
358      }
359   }
360
361   /**
362     * @brief Event for FocusGroupChanged signal which can be used to subscribe/unsubscribe the event handler
363     * (in the type of FocusGroupChangedEventHandler) provided by the user.
364     * FocusGroupChanged signal is emitted when the focus group has been changed.
365     */
366   public event FocusGroupChangedEventHandler FocusGroupChanged
367   {
368      add
369      {
370         lock(this)
371         {
372            // Restricted to only one listener
373            if (_FocusManagerFocusGroupChangedEventHandler == null)
374            {
375               _FocusManagerFocusGroupChangedEventHandler += value;
376
377               _FocusManagerFocusGroupChangedEventCallbackDelegate = new FocusGroupChangedEventCallbackDelegate(OnFocusGroupChanged);
378               this.FocusGroupChangedSignal().Connect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
379            }
380         }
381      }
382
383      remove
384      {
385         lock(this)
386         {
387            if (_FocusManagerFocusGroupChangedEventHandler != null)
388            {
389               this.FocusGroupChangedSignal().Disconnect(_FocusManagerFocusGroupChangedEventCallbackDelegate);
390            }
391
392            _FocusManagerFocusGroupChangedEventHandler -= value;
393         }
394      }
395   }
396
397   // Callback for FocusManager FocusGroupChangedSignal
398   private void OnFocusGroupChanged(IntPtr currentFocusedActor, bool forwardDirection)
399   {
400      FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
401
402      // Populate all members of "e" (FocusGroupChangedEventArgs) with real data
403      e.CurrentFocusedActor = Actor.GetActorFromPtr(currentFocusedActor);
404      e.ForwardDirection = forwardDirection;
405
406      if (_FocusManagerFocusGroupChangedEventHandler != null)
407      {
408         //here we send all data to user event handlers
409         _FocusManagerFocusGroupChangedEventHandler(this, e);
410      }
411   }
412
413   /**
414     * @brief Event for FocusedActorEnterKeyPressed signal which can be used to subscribe/unsubscribe the event handler
415     * (in the type of FocusedActorEnterKeyEventHandler) provided by the user.
416     * FocusedActorEnterKeyPressed signal is emitted when the current focused actor has the enter key pressed on it.
417     */
418   public event FocusedActorEnterKeyEventHandler FocusedActorEnterKeyPressed
419   {
420      add
421      {
422         lock(this)
423         {
424            // Restricted to only one listener
425            if (_FocusManagerFocusedActorEnterKeyEventHandler == null)
426            {
427               _FocusManagerFocusedActorEnterKeyEventHandler += value;
428
429               _FocusManagerFocusedActorEnterKeyEventCallbackDelegate = new FocusedActorEnterKeyEventCallbackDelegate(OnFocusedActorEnterKey);
430               this.FocusedActorEnterKeySignal().Connect(_FocusManagerFocusedActorEnterKeyEventCallbackDelegate);
431            }
432         }
433      }
434
435      remove
436      {
437         lock(this)
438         {
439            if (_FocusManagerFocusedActorEnterKeyEventHandler != null)
440            {
441               this.FocusedActorEnterKeySignal().Disconnect(_FocusManagerFocusedActorEnterKeyEventCallbackDelegate);
442            }
443
444            _FocusManagerFocusedActorEnterKeyEventHandler -= value;
445         }
446      }
447   }
448
449   // Callback for FocusManager FocusedActorEnterKeySignal
450   private void OnFocusedActorEnterKey(IntPtr actor)
451   {
452      FocusedActorEnterKeyEventArgs e = new FocusedActorEnterKeyEventArgs();
453
454      // Populate all members of "e" (FocusedActorEnterKeyEventArgs) with real data
455      e.Actor = Actor.GetActorFromPtr(actor);
456
457      if (_FocusManagerFocusedActorEnterKeyEventHandler != null)
458      {
459         //here we send all data to user event handlers
460         _FocusManagerFocusedActorEnterKeyEventHandler(this, e);
461      }
462   }
463
464   public FocusManager() : this(NDalicManualPINVOKE.new_FocusManager(), true) {
465     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466   }
467
468   public static FocusManager Get() {
469     FocusManager ret = new FocusManager(NDalicManualPINVOKE.FocusManager_Get(), true);
470     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471     return ret;
472   }
473
474   public bool SetCurrentFocusActor(Actor actor) {
475     bool ret = NDalicManualPINVOKE.FocusManager_SetCurrentFocusActor(swigCPtr, Actor.getCPtr(actor));
476     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
477     return ret;
478   }
479
480   public Actor GetCurrentFocusActor() {
481     Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetCurrentFocusActor(swigCPtr), true);
482     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483     return ret;
484   }
485
486   public bool MoveFocus(View.KeyboardFocus.Direction direction) {
487     bool ret = NDalicManualPINVOKE.FocusManager_MoveFocus(swigCPtr, (int)direction);
488     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489     return ret;
490   }
491
492   public void ClearFocus() {
493     NDalicManualPINVOKE.FocusManager_ClearFocus(swigCPtr);
494     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495   }
496
497   public void SetFocusGroupLoop(bool enabled) {
498     NDalicManualPINVOKE.FocusManager_SetFocusGroupLoop(swigCPtr, enabled);
499     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
500   }
501
502   public bool GetFocusGroupLoop() {
503     bool ret = NDalicManualPINVOKE.FocusManager_GetFocusGroupLoop(swigCPtr);
504     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
505     return ret;
506   }
507
508   public void SetAsFocusGroup(Actor actor, bool isFocusGroup) {
509     NDalicManualPINVOKE.FocusManager_SetAsFocusGroup(swigCPtr, Actor.getCPtr(actor), isFocusGroup);
510     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511   }
512
513   public bool IsFocusGroup(Actor actor) {
514     bool ret = NDalicManualPINVOKE.FocusManager_IsFocusGroup(swigCPtr, Actor.getCPtr(actor));
515     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
516     return ret;
517   }
518
519   public Actor GetFocusGroup(Actor actor) {
520     Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetFocusGroup(swigCPtr, Actor.getCPtr(actor)), true);
521     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522     return ret;
523   }
524
525   public void SetFocusIndicatorActor(Actor indicator) {
526     NDalicManualPINVOKE.FocusManager_SetFocusIndicatorActor(swigCPtr, Actor.getCPtr(indicator));
527     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
528   }
529
530   public Actor GetFocusIndicatorActor() {
531     Actor ret = new Actor(NDalicManualPINVOKE.FocusManager_GetFocusIndicatorActor(swigCPtr), true);
532     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
533     return ret;
534   }
535
536   public PreFocusChangeSignal PreFocusChangeSignal() {
537     PreFocusChangeSignal ret = new PreFocusChangeSignal(NDalicManualPINVOKE.FocusManager_PreFocusChangeSignal(swigCPtr), false);
538     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539     return ret;
540   }
541
542   public FocusChangedSignal FocusChangedSignal() {
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   public FocusGroupChangedSignal FocusGroupChangedSignal() {
549     FocusGroupChangedSignal ret = new FocusGroupChangedSignal(NDalicManualPINVOKE.FocusManager_FocusGroupChangedSignal(swigCPtr), false);
550     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
551     return ret;
552   }
553
554   public ActorSignal FocusedActorEnterKeySignal() {
555     ActorSignal ret = new ActorSignal(NDalicManualPINVOKE.FocusManager_FocusedActorEnterKeySignal(swigCPtr), false);
556     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557     return ret;
558   }
559
560   private static readonly FocusManager instance = FocusManager.Get();
561
562   public static FocusManager Instance
563   {
564       get
565       {
566           return instance;
567       }
568   }
569
570
571 }
572
573 }