DALi C# binding - EventHandler Support
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / keyboardFocusManager-event.i
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 %define KEYBOARD_FOCUS_MANAGER_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22 %}
23
24 %enddef
25
26
27 %define KEYBOARD_FOCUS_MANAGER_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
28 %typemap(cscode) NameSpace::ClassName %{
29
30 /**
31   * @brief Event arguments that passed via FocusChanged signal
32   *
33   */
34 public class FocusChangedEventArgs : EventArgs
35 {
36    private Actor _actorCurrent;
37    private Actor _actorNext;
38
39    /**
40      * @brief Actor - is the original focused Actor
41      *
42      */
43    public Actor ActorCurrent
44    {
45       get
46       {
47          return _actorCurrent;
48       }
49       set
50       {
51          _actorCurrent = value;
52       }
53    }
54
55    /**
56      * @brief Actor - is the current focused Actor
57      *
58      */
59    public Actor ActorNext
60    {
61       get
62       {
63          return _actorNext;
64       }
65       set
66       {
67          _actorNext = value;
68       }
69    }
70 }
71
72 /**
73   * @brief Event arguments that passed via FocusGroupChanged signal
74   *
75   */
76 public class FocusGroupChangedEventArgs : EventArgs
77 {
78    private Actor _currentFocusedActor;
79    private bool _forwardDirection;
80
81    /**
82      * @brief Actor - is the current focused Actor
83      *
84      */
85    public Actor CurrentFocusedActor
86    {
87       get
88       {
89          return _currentFocusedActor;
90       }
91       set
92       {
93          _currentFocusedActor = value;
94       }
95    }
96
97    /**
98      * @brief ForwardDirection - is the direction (forward or backward) in which to move the focus next
99      *
100      */
101    public bool ForwardDirection
102    {
103       get
104       {
105          return _forwardDirection;
106       }
107       set
108       {
109          _forwardDirection = value;
110       }
111    }
112 }
113
114 /**
115   * @brief Event arguments that passed via FocusedActorEnterKey signal
116   *
117   */
118 public class FocusedActorEnterKeyEventArgs : EventArgs
119 {
120    private Actor _actor;
121
122    /**
123      * @brief Actor - is the current focused Actor which has the enter key pressed on it.
124      *
125      */
126    public Actor Actor
127    {
128       get
129       {
130          return _actor;
131       }
132       set
133       {
134          _actor = value;
135       }
136    }
137 }
138
139   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
140   public delegate void FocusChangedEventHandler(object source, FocusChangedEventArgs e);
141
142   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
143   public delegate void FocusGroupChangedEventHandler(object source, FocusGroupChangedEventArgs e);
144
145   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
146   public delegate void FocusedActorEnterKeyEventHandler(object source, FocusedActorEnterKeyEventArgs e);
147
148   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
149   private delegate void FocusChangedEventCallbackDelegate(IntPtr actorCurrent, IntPtr actorNext);
150   private FocusChangedEventHandler _keyboardFocusManagerFocusChangedEventHandler;
151   private FocusChangedEventCallbackDelegate _keyboardFocusManagerFocusChangedEventCallbackDelegate;
152
153   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
154   private delegate void FocusGroupChangedEventCallbackDelegate(IntPtr currentFocusedActor, bool forwardDirection);
155   private FocusGroupChangedEventHandler _keyboardFocusManagerFocusGroupChangedEventHandler;
156   private FocusGroupChangedEventCallbackDelegate _keyboardFocusManagerFocusGroupChangedEventCallbackDelegate;
157
158   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
159   private delegate void FocusedActorEnterKeyEventCallbackDelegate(IntPtr actor);
160   private FocusedActorEnterKeyEventHandler _keyboardFocusManagerFocusedActorEnterKeyEventHandler;
161   private FocusedActorEnterKeyEventCallbackDelegate _keyboardFocusManagerFocusedActorEnterKeyEventCallbackDelegate;
162
163   /**
164     * @brief Event for FocusChanged signal which can be used to subscribe/unsubscribe the event handler
165     * (in the type of FocusChangedEventHandler) provided by the user.
166     * FocusChanged signal is emitted after the current focused actor has been changed.
167     */
168   public event FocusChangedEventHandler FocusChanged
169   {
170      add
171      {
172         lock(this)
173         {
174            // Restricted to only one listener
175            if (_keyboardFocusManagerFocusChangedEventHandler == null)
176            {
177               _keyboardFocusManagerFocusChangedEventHandler += value;
178
179               _keyboardFocusManagerFocusChangedEventCallbackDelegate = new FocusChangedEventCallbackDelegate(OnFocusChanged);
180               this.FocusChangedSignal().Connect(_keyboardFocusManagerFocusChangedEventCallbackDelegate);
181            }
182         }
183      }
184
185      remove
186      {
187         lock(this)
188         {
189            if (_keyboardFocusManagerFocusChangedEventHandler != null)
190            {
191               this.FocusChangedSignal().Disconnect(_keyboardFocusManagerFocusChangedEventCallbackDelegate);
192            }
193
194            _keyboardFocusManagerFocusChangedEventHandler -= value;
195         }
196      }
197   }
198
199   // Callback for KeyboardFocusManager FocusChangedSignal
200   private void OnFocusChanged(IntPtr actorCurrent, IntPtr actorNext)
201   {
202      FocusChangedEventArgs e = new FocusChangedEventArgs();
203
204      // Populate all members of "e" (FocusChangedEventArgs) with real data
205      e.ActorCurrent = Actor.GetActorFromPtr(actorCurrent);
206      e.ActorNext = Actor.GetActorFromPtr(actorNext);
207
208      if (_keyboardFocusManagerFocusChangedEventHandler != null)
209      {
210         //here we send all data to user event handlers
211         _keyboardFocusManagerFocusChangedEventHandler(this, e);
212      }
213   }
214
215   /**
216     * @brief Event for FocusGroupChanged signal which can be used to subscribe/unsubscribe the event handler
217     * (in the type of FocusGroupChangedEventHandler) provided by the user.
218     * FocusGroupChanged signal is emitted when the focus group has been changed.
219     */
220   public event FocusGroupChangedEventHandler FocusGroupChanged
221   {
222      add
223      {
224         lock(this)
225         {
226            // Restricted to only one listener
227            if (_keyboardFocusManagerFocusGroupChangedEventHandler == null)
228            {
229               _keyboardFocusManagerFocusGroupChangedEventHandler += value;
230
231               _keyboardFocusManagerFocusGroupChangedEventCallbackDelegate = new FocusGroupChangedEventCallbackDelegate(OnFocusGroupChanged);
232               this.FocusGroupChangedSignal().Connect(_keyboardFocusManagerFocusGroupChangedEventCallbackDelegate);
233            }
234         }
235      }
236
237      remove
238      {
239         lock(this)
240         {
241            if (_keyboardFocusManagerFocusGroupChangedEventHandler != null)
242            {
243               this.FocusGroupChangedSignal().Disconnect(_keyboardFocusManagerFocusGroupChangedEventCallbackDelegate);
244            }
245
246            _keyboardFocusManagerFocusGroupChangedEventHandler -= value;
247         }
248      }
249   }
250
251   // Callback for KeyboardFocusManager FocusGroupChangedSignal
252   private void OnFocusGroupChanged(IntPtr currentFocusedActor, bool forwardDirection)
253   {
254      FocusGroupChangedEventArgs e = new FocusGroupChangedEventArgs();
255
256      // Populate all members of "e" (FocusGroupChangedEventArgs) with real data
257      e.CurrentFocusedActor = Actor.GetActorFromPtr(currentFocusedActor);
258      e.ForwardDirection = forwardDirection;
259
260      if (_keyboardFocusManagerFocusGroupChangedEventHandler != null)
261      {
262         //here we send all data to user event handlers
263         _keyboardFocusManagerFocusGroupChangedEventHandler(this, e);
264      }
265   }
266
267   /**
268     * @brief Event for FocusedActorEnterKeyPressed signal which can be used to subscribe/unsubscribe the event handler
269     * (in the type of FocusedActorEnterKeyEventHandler) provided by the user.
270     * FocusedActorEnterKeyPressed signal is emitted when the current focused actor has the enter key pressed on it.
271     */
272   public event FocusedActorEnterKeyEventHandler FocusedActorEnterKeyPressed
273   {
274      add
275      {
276         lock(this)
277         {
278            // Restricted to only one listener
279            if (_keyboardFocusManagerFocusedActorEnterKeyEventHandler == null)
280            {
281               _keyboardFocusManagerFocusedActorEnterKeyEventHandler += value;
282
283               _keyboardFocusManagerFocusedActorEnterKeyEventCallbackDelegate = new FocusedActorEnterKeyEventCallbackDelegate(OnFocusedActorEnterKey);
284               this.FocusedActorEnterKeySignal().Connect(_keyboardFocusManagerFocusedActorEnterKeyEventCallbackDelegate);
285            }
286         }
287      }
288
289      remove
290      {
291         lock(this)
292         {
293            if (_keyboardFocusManagerFocusedActorEnterKeyEventHandler != null)
294            {
295               this.FocusedActorEnterKeySignal().Disconnect(_keyboardFocusManagerFocusedActorEnterKeyEventCallbackDelegate);
296            }
297
298            _keyboardFocusManagerFocusedActorEnterKeyEventHandler -= value;
299         }
300      }
301   }
302
303   // Callback for KeyboardFocusManager FocusedActorEnterKeySignal
304   private void OnFocusedActorEnterKey(IntPtr actor)
305   {
306      FocusedActorEnterKeyEventArgs e = new FocusedActorEnterKeyEventArgs();
307
308      // Populate all members of "e" (FocusedActorEnterKeyEventArgs) with real data
309      e.Actor = Actor.GetActorFromPtr(actor);
310
311      if (_keyboardFocusManagerFocusedActorEnterKeyEventHandler != null)
312      {
313         //here we send all data to user event handlers
314         _keyboardFocusManagerFocusedActorEnterKeyEventHandler(this, e);
315      }
316   }
317
318 %}
319 %enddef
320
321 %define DALI_KEYBOARD_FOCUS_MANAGER_EVENTHANDLER_PARAM( NameSpace, ClassName)
322   KEYBOARD_FOCUS_MANAGER_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
323   KEYBOARD_FOCUS_MANAGER_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
324 %enddef
325
326 namespace Dali
327 {
328   DALI_KEYBOARD_FOCUS_MANAGER_EVENTHANDLER_PARAM( Dali::Toolkit, KeyboardFocusManager);
329 }
330