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