Merge "Add missed parameter documentation" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / control-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 CONTROL_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24
25 %enddef
26
27 %define CONTROL_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
28 %typemap(cscode) NameSpace::ClassName %{
29
30
31 /**
32   * @brief Event arguments that passed via KeyInputFocusGained signal
33   *
34   */
35 public class KeyInputFocusGainedEventArgs : EventArgs
36 {
37    private View _view;
38
39    /**
40      * @brief View - is the view that gets Key Input Focus
41      *
42      */
43    public View View
44    {
45       get
46       {
47          return _view;
48       }
49       set
50       {
51          _view = value;
52       }
53    }
54 }
55
56 /**
57   * @brief Event arguments that passed via KeyInputFocusLost signal
58   *
59   */
60 public class KeyInputFocusLostEventArgs : EventArgs
61 {
62    private View _view;
63
64    /**
65      * @brief View - is the view that loses Key Input Focus
66      *
67      */
68    public View View
69    {
70       get
71       {
72          return _view;
73       }
74       set
75       {
76          _view = value;
77       }
78    }
79 }
80
81 /**
82   * @brief Event arguments that passed via KeyEvent signal
83   *
84   */
85 public class KeyEventArgs : EventArgs
86 {
87    private View _view;
88    private KeyEvent _keyEvent;
89
90    /**
91      * @brief View - is the view that recieves the keyevent.
92      *
93      */
94    public View View
95    {
96       get
97       {
98          return _view;
99       }
100       set
101       {
102          _view = value;
103       }
104    }
105
106    /**
107      * @brief KeyEvent - is the keyevent sent to the View.
108      *
109      */
110    public KeyEvent KeyEvent
111    {
112       get
113       {
114          return _keyEvent;
115       }
116       set
117       {
118          _keyEvent = value;
119       }
120    }
121 }
122
123   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
124   public delegate void KeyInputFocusGainedEventHandler(object source, KeyInputFocusGainedEventArgs e);
125
126   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
127   public delegate void KeyInputFocusLostEventHandler(object source, KeyInputFocusLostEventArgs e);
128
129   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
130   public delegate bool KeyEventHandler(object source, KeyEventArgs e);
131
132   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
133   private delegate void KeyInputFocusGainedCallbackDelegate(IntPtr view);
134   private KeyInputFocusGainedEventHandler _KeyInputFocusGainedEventHandler;
135   private KeyInputFocusGainedCallbackDelegate _KeyInputFocusGainedCallbackDelegate;
136
137   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
138   private delegate void KeyInputFocusLostCallbackDelegate(IntPtr view);
139   private KeyInputFocusLostEventHandler _KeyInputFocusLostEventHandler;
140   private KeyInputFocusLostCallbackDelegate _KeyInputFocusLostCallbackDelegate;
141
142   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
143   private delegate bool KeyCallbackDelegate(IntPtr view, IntPtr keyEvent);
144   private KeyEventHandler _KeyEventHandler;
145   private KeyCallbackDelegate _KeyCallbackDelegate;
146
147   /**
148     * @brief Event for KeyInputFocusGained signal which can be used to subscribe/unsubscribe the event handler
149     * (in the type of KeyInputFocusGainedEventHandler) provided by the user.
150     * KeyInputFocusGained signal is emitted when the view gets Key Input Focus.
151     */
152   public event KeyInputFocusGainedEventHandler KeyInputFocusGained
153   {
154      add
155      {
156         lock(this)
157         {
158            // Restricted to only one listener
159            if (_KeyInputFocusGainedEventHandler == null)
160            {
161               _KeyInputFocusGainedEventHandler += value;
162
163               _KeyInputFocusGainedCallbackDelegate = new KeyInputFocusGainedCallbackDelegate(OnKeyInputFocusGained);
164               this.KeyInputFocusGainedSignal().Connect(_KeyInputFocusGainedCallbackDelegate);
165            }
166         }
167      }
168
169      remove
170      {
171         lock(this)
172         {
173            if (_KeyInputFocusGainedEventHandler != null)
174            {
175               this.KeyInputFocusGainedSignal().Disconnect(_KeyInputFocusGainedCallbackDelegate);
176            }
177
178            _KeyInputFocusGainedEventHandler -= value;
179         }
180      }
181   }
182
183  private void OnKeyInputFocusGained(IntPtr view)
184   {
185    KeyInputFocusGainedEventArgs e = new KeyInputFocusGainedEventArgs();
186
187    // Populate all members of "e" (KeyInputFocusGainedEventArgs) with real data
188    e.View = Dali.View.GetViewFromPtr(view);
189
190    if (_KeyInputFocusGainedEventHandler != null)
191    {
192       //here we send all data to user event handlers
193       _KeyInputFocusGainedEventHandler(this, e);
194    }
195
196   }
197
198   /**
199     * @brief Event for KeyInputFocusLost signal which can be used to subscribe/unsubscribe the event handler
200     * (in the type of KeyInputFocusLostEventHandler) provided by the user.
201     * KeyInputFocusLost signal is emitted when the view loses Key Input Focus.
202     */
203   public event KeyInputFocusLostEventHandler KeyInputFocusLost
204   {
205      add
206      {
207         lock(this)
208         {
209            // Restricted to only one listener
210            if (_KeyInputFocusLostEventHandler == null)
211            {
212               _KeyInputFocusLostEventHandler += value;
213
214               _KeyInputFocusLostCallbackDelegate = new KeyInputFocusLostCallbackDelegate(OnKeyInputFocusLost);
215               this.KeyInputFocusLostSignal().Connect(_KeyInputFocusLostCallbackDelegate);
216            }
217         }
218      }
219
220      remove
221      {
222         lock(this)
223         {
224            if (_KeyInputFocusLostEventHandler != null)
225            {
226               this.KeyInputFocusLostSignal().Disconnect(_KeyInputFocusLostCallbackDelegate);
227            }
228
229            _KeyInputFocusLostEventHandler -= value;
230         }
231      }
232   }
233
234  private void OnKeyInputFocusLost(IntPtr view)
235   {
236    KeyInputFocusLostEventArgs e = new KeyInputFocusLostEventArgs();
237
238    // Populate all members of "e" (KeyInputFocusLostEventArgs) with real data
239    e.View = Dali.View.GetViewFromPtr(view);
240
241    if (_KeyInputFocusLostEventHandler != null)
242    {
243       //here we send all data to user event handlers
244       _KeyInputFocusLostEventHandler(this, e);
245    }
246   }
247
248   /**
249     * @brief Event for KeyPressed signal which can be used to subscribe/unsubscribe the event handler
250     * (in the type of KeyEventEventHandler) provided by the user.
251     * KeyPressed signal is emitted when key event is received.
252     */
253   public event KeyEventHandler KeyPressed
254   {
255      add
256      {
257         lock(this)
258         {
259            // Restricted to only one listener
260            if (_KeyEventHandler == null)
261            {
262               _KeyEventHandler += value;
263
264               _KeyCallbackDelegate = new KeyCallbackDelegate(OnKeyEvent);
265               this.KeyEventSignal().Connect(_KeyCallbackDelegate);
266            }
267         }
268      }
269
270      remove
271      {
272         lock(this)
273         {
274            if (_KeyEventHandler != null)
275            {
276               this.KeyEventSignal().Disconnect(_KeyCallbackDelegate);
277            }
278
279            _KeyEventHandler -= value;
280         }
281      }
282   }
283
284  private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
285   {
286    KeyEventArgs e = new KeyEventArgs();
287
288    // Populate all members of "e" (KeyEventArgs) with real data
289    e.View = Dali.View.GetViewFromPtr(view);
290    e.KeyEvent = Dali.KeyEvent.GetKeyEventFromPtr(keyEvent);
291
292    if (_KeyEventHandler != null)
293    {
294       //here we send all data to user event handlers
295       return _KeyEventHandler(this, e);
296    }
297    return false;
298
299   }
300
301  public static View GetViewFromPtr(global::System.IntPtr cPtr) {
302     View ret = new View(cPtr, false);
303    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304     return ret;
305   }
306
307 %}
308
309 %enddef
310
311 %define DALI_CONTROL_EVENTHANDLER_PARAM( NameSpace, ClassName)
312
313   CONTROL_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
314   CONTROL_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
315
316 %enddef
317
318 namespace Dali
319 {
320   DALI_CONTROL_EVENTHANDLER_PARAM( Dali::Toolkit, Control);
321 }