Merge "Changed to use ImfManager for virtual keyboard APIs" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / signals.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 // Example from Swig CSHARP documentation
19 // To allow a CDate class to take
20 // To achieve this mapping, we need to alter the default code generation slightly so that at the C# layer, a System.DateTime is converted into a CDate. The
21 // intermediary layer will still take a pointer to the underlying CDate class. The typemaps to achieve this are shown below.
22
23 // %typemap(cstype) const CDate & "System.DateTime"
24 // %typemap(csin,
25 // pre="
26 // CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);"
27 // ) const CDate &
28 // "$csclassname.getCPtr(temp$csinput)"
29 // The csin typemap is used for converting function parameter types from the type
30 // used in the proxy, module or type wrapper class to the type used in the PInvoke class.
31
32
33 %include <dali/public-api/signals/dali-signal.h>
34
35 /*
36  * By default SWIG maps Derived types, structs, and classes to C pointers.
37  * So for Signals which have a Connect /Disconnect function, the function parameter just gets maps to a C pointer.
38  * However, call backs in C# are done using delegates, so we change the Connect / Disconnect parameter from
39  * something like  void (*func)( Dali::Actor ) to a C# delegate.
40  * the parameter type is changed using the typemap(cstype)  cstype = csharp-type
41  * The actual conversion from a C# delegate to a c function pointer is done when Connect/Disconnect is called
42  * using  typemap(csin) with GetFunctionPointerForDelegate ( csin = csharp in code?).
43  * So when connect is called on a Signal it will call the   void Signal::Connect( void (*func)( Arg0 arg0 ) ) -- which
44  * just takes a standard C function pointer. Not ideal as there is no delegate / connection tracking.
45  *
46  */
47 %define SIGNAL_TYPEMAP_HELPER( SignalSignature )
48 %typemap(cstype) SignalSignature "System.Delegate"
49 %typemap(csin, pre ="System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate($csinput); ")
50    SignalSignature "new System.Runtime.InteropServices.HandleRef(this, ip)"
51 %enddef
52
53 /**
54  * SWIG can't auto generate wrappers for template parameters that are functions ( which dali-signal has)
55  * so we have make them ourselves
56  */
57
58 %define SIGNAL_TEMPLATE_HELPER_0( returnType,  returnFunc)
59   template<> class Signal< returnType () >
60   {
61   public:
62     %extend
63     {
64       bool Empty() const
65       {
66          return $self->Empty();
67       }
68       std::size_t GetConnectionCount() const
69       {
70         return $self->GetConnectionCount();
71       }
72       void Connect( returnType ( *func ) () )
73       {
74           $self->Connect( func );
75       }
76       void Disconnect( returnType ( *func ) () )
77       {
78           $self->Disconnect( func );
79       }
80       returnType Emit()
81       {
82           returnFunc $self->Emit();
83       }
84     }
85   };
86 %enddef
87
88 %define SIGNAL_TEMPLATE_HELPER_1( returnType,  returnFunc, argumentType )
89   template<> class Signal< returnType ( argumentType ) >
90   {
91   public:
92     %extend
93     {
94       bool Empty() const
95       {
96          return $self->Empty();
97       }
98       std::size_t GetConnectionCount() const
99       {
100         return $self->GetConnectionCount();
101       }
102       void Connect( returnType ( *func ) (  argumentType  ) )
103       {
104           $self->Connect( func );
105       }
106       void Disconnect( returnType ( *func ) (  argumentType  ) )
107       {
108           $self->Disconnect( func );
109       }
110       returnType Emit( argumentType arg)
111       {
112           returnFunc $self->Emit( arg );
113       }
114     }
115   };
116 %enddef
117
118 %define SIGNAL_TEMPLATE_HELPER_2( returnType,  returnFunc, argumentType1, argumentType2 )
119   template<> class Signal< returnType (  argumentType1, argumentType2 ) >
120   {
121   public:
122     %extend
123     {
124       bool Empty() const
125       {
126          return $self->Empty();
127       }
128       std::size_t GetConnectionCount() const
129       {
130         return $self->GetConnectionCount();
131       }
132       void Connect( returnType ( *func ) (  argumentType1, argumentType2   ) )
133       {
134         $self->Connect( func );
135       }
136       void Disconnect( returnType ( *func ) (  argumentType1, argumentType2  ) )
137       {
138         $self->Disconnect( func );
139       }
140       returnType Emit( argumentType1 arg1, argumentType2 arg2 )
141       {
142         returnFunc $self->Emit( arg1, arg2 );
143       }
144     }
145   };
146 %enddef
147
148 %define SIGNAL_TEMPLATE_HELPER_3( returnType, returnFunc, argumentType1, argumentType2, argumentType3 )
149   template<> class Signal< returnType ( argumentType1, argumentType2, argumentType3 ) >
150   {
151   public:
152     %extend
153     {
154       bool Empty() const
155       {
156          return $self->Empty();
157       }
158       std::size_t GetConnectionCount() const
159       {
160         return $self->GetConnectionCount();
161       }
162       void Connect( returnType ( *func ) ( argumentType1, argumentType2, argumentType3  ) )
163       {
164           return $self->Connect( func );
165       }
166       void Disconnect( returnType ( *func ) ( argumentType1, argumentType2, argumentType3  ) )
167       {
168           $self->Disconnect( func );
169       }
170       returnType Emit( argumentType1 arg1, argumentType2 arg2, argumentType3 arg3 )
171       {
172           returnFunc $self->Emit( arg1, arg2, arg3 );
173       }
174     }
175   };
176 %enddef
177
178 ////////////////////////////////
179 /*****************
180  Macros for signals  without return values
181 *****************/
182
183 // the emit for some signal has to emit a return value
184 // this macro is just for signals that don't (instead of return Emit();.. it just does ;Emit();
185 %define NO_RETURN_FUNC;
186 %enddef
187
188 // Macro to define a csharp signal.
189 // 0 param signals ( no return )
190 %define DALI_SIGNAL_0_PARAM()
191
192   SIGNAL_TYPEMAP_HELPER( void (*func) () );
193   SIGNAL_TEMPLATE_HELPER_0( void, NO_RETURN_FUNC);
194 %enddef
195
196 // 1 param signals ( no return )
197 %define DALI_SIGNAL_1_PARAM( argumentType1 )
198
199   SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1 ) );
200   SIGNAL_TEMPLATE_HELPER_1( void, NO_RETURN_FUNC, argumentType1);
201 %enddef
202
203 // 2 param signals ( no return )
204 %define DALI_SIGNAL_2_PARAM( argumentType1, argumentType2)
205
206   SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1, argumentType2) );
207   SIGNAL_TEMPLATE_HELPER_2( void, NO_RETURN_FUNC, argumentType1, argumentType2);
208
209 %enddef
210
211 // 3 param signals ( no return )
212 %define DALI_SIGNAL_3_PARAM( argumentType1, argumentType2, argumentType3 )
213
214   SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1, argumentType2, argumentType3 ) );
215   SIGNAL_TEMPLATE_HELPER_3( void, NO_RETURN_FUNC, argumentType1, argumentType2, argumentType3);
216
217 %enddef
218
219 /*****************
220  Macros for signals with return values
221 *****************/
222
223 // 0 param signals ( with return )
224 %define DALI_SIGNAL_0_PARAM_RETURN( returnType )
225
226   SIGNAL_TYPEMAP_HELPER( returnType (*func) () );
227   SIGNAL_TEMPLATE_HELPER_0( returnType, return);
228 %enddef
229
230 // 1 param signals ( with return )
231 %define DALI_SIGNAL_1_PARAM_RETURN( returnType, argumentType1 )
232
233   SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1 ) );
234   SIGNAL_TEMPLATE_HELPER_1( returnType, return, argumentType1);
235
236 %enddef
237
238 // 2 param signals ( with return )
239 %define DALI_SIGNAL_2_PARAM_RETURN( returnType, argumentType1, argumentType2)
240
241   SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2) );
242   SIGNAL_TEMPLATE_HELPER_2( returnType, return, argumentType1, argumentType2);
243
244 %enddef
245
246 // 3 param signals ( with return )
247 %define DALI_SIGNAL_3_PARAM_RETURN( returnType, argumentType1, argumentType2, argumentType3 )
248
249   SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2, argumentType3 ) );
250   SIGNAL_TEMPLATE_HELPER_3( returnType, return, argumentType1, argumentType2, argumentType3);
251
252 %enddef
253
254 namespace Dali
255 {
256 // Signal< void () >
257 DALI_SIGNAL_0_PARAM();
258
259 // Signal< bool () >
260 DALI_SIGNAL_0_PARAM_RETURN( bool );
261
262 // Signal< void (Actor) >
263 DALI_SIGNAL_1_PARAM( Dali::Actor );
264
265 //  Signal< void (float) >
266 DALI_SIGNAL_1_PARAM( float );
267
268 // Signal< void (Dali::Application&) >
269 DALI_SIGNAL_1_PARAM( Dali::Application& );
270
271 // Signal< void (Dali::Application&, void*) >
272 DALI_SIGNAL_2_PARAM( Dali::Application& , void* );
273
274 // Signal< void (Dali::Image) >
275 DALI_SIGNAL_1_PARAM( Dali::Image );
276
277 // Signal< void (Dali::ResourceImage) >
278 DALI_SIGNAL_1_PARAM( Dali::ResourceImage );
279
280 // Signal< void (Dali::Animation&) >
281 DALI_SIGNAL_1_PARAM( Dali::Animation& );
282
283 // Signal< void (Dali::Actor, const Dali::TouchEvent&) >
284 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TouchEvent& );
285
286 //  Signal< bool (Dali::Actor, const Dali::TouchData&) >
287 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Actor, const Dali::TouchData& );
288
289 // Signal< bool (Dali::Actor, const Dali::HoverEvent&) >
290 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::HoverEvent& );
291
292 // Signal< bool (Dali::Actor, const Dali::WheelEvent&) >
293 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::WheelEvent& );
294
295 // Signal< void (const Dali::KeyEvent&) >
296 DALI_SIGNAL_1_PARAM( const Dali::KeyEvent&  );
297
298 // Signal< void (const Dali::TouchData&) >
299 DALI_SIGNAL_1_PARAM( const Dali::TouchData& );
300
301 // Signal< void (const Dali::HoverEvent&) >
302 DALI_SIGNAL_1_PARAM( const Dali::HoverEvent& );
303
304 // Signal< void (const Dali::WheelEvent&) >
305 DALI_SIGNAL_1_PARAM( const Dali::WheelEvent& );
306
307 // Signal< void (const Dali::LongPressGesture&) >
308 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::LongPressGesture& );
309
310 // Signal< void (Dali::Actor, const Dali::PanGesture&) >
311 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PanGesture& );
312
313 // Signal< void (Dali::Actor, const Dali::PinchGesture&) >
314 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PinchGesture& );
315
316 // Signal< void (Dali::Actor, const Dali::TapGesture&) >
317 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TapGesture& );
318
319 // Signal< void (Dali::PropertyNotification) >
320 DALI_SIGNAL_1_PARAM( Dali::PropertyNotification& ) ;
321
322 //  Signal< void (Dali::BaseHandle) >
323 DALI_SIGNAL_1_PARAM( Dali::BaseHandle );
324
325 //  Signal< void (const Dali::RefObject*) >
326 DALI_SIGNAL_1_PARAM( const Dali::RefObject* );
327
328 // Signal< void (const Dali::RenderTask&) >
329 DALI_SIGNAL_1_PARAM( const Dali::RenderTask& );
330
331 // Signal< bool ( const Dali::Toolkit::AccessibilityManager& ) >
332 DALI_SIGNAL_1_PARAM_RETURN( bool, Dali::Toolkit::AccessibilityManager& );
333
334 // Signal< bool ( const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
335 DALI_SIGNAL_2_PARAM_RETURN( bool, const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& );
336
337 // Signal< void ( const Dali::Actor Dali::Toolkit::AccessibilityManager::FocusOvershotDirection ) >
338 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
339
340 // Signal< bool ( Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
341 DALI_SIGNAL_2_PARAM_RETURN( bool ,Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent&);
342
343 // Signal< void (  Dali::Toolkit::StyleManager, Dali::StyleChange::Type) >
344 DALI_SIGNAL_2_PARAM( Dali::Toolkit::StyleManager, Dali::StyleChange::Type);
345
346 // void Signal<  Dali::Actor, bool >;
347 DALI_SIGNAL_2_PARAM( Dali::Actor, bool);
348
349 // void Signal<  Dali::Actor, Dali::Actor >;
350 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Actor);
351
352 // bool Signal< Dali::Toolkit::Button >;
353 DALI_SIGNAL_1_PARAM_RETURN( bool, Dali::Toolkit::Button);
354
355 // void Signal< Dali::Toolkit::GaussianBlurView >;
356 DALI_SIGNAL_1_PARAM( Dali::Toolkit::GaussianBlurView);
357
358 // void Signal< Dali::Toolkit::PageTurnView, unsigned int, bool >;
359 DALI_SIGNAL_3_PARAM( Dali::Toolkit::PageTurnView, unsigned int, bool );
360
361 // void Signal< Dali::Toolkit::PageTurnView >;
362 DALI_SIGNAL_1_PARAM( Dali::Toolkit::PageTurnView );
363
364 // void Signal< Dali::Toolkit::ProgressBar, float, float >;
365 DALI_SIGNAL_3_PARAM( Dali::Toolkit::ProgressBar, float, float );
366
367 // void Signal< const Dali::Toolkit::ScrollView::SnapEvent& >;
368 DALI_SIGNAL_1_PARAM( const Dali::Toolkit::ScrollView::SnapEvent& );
369
370 // void Signal< const Dali::Vector2& >;
371 DALI_SIGNAL_1_PARAM( const Dali::Vector2& );
372
373 // void Signal< Dali::Toolkit::TextEditor >;
374 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextEditor );
375
376 // void Signal< Dali::Toolkit::TextField >;
377 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextField );
378
379 // bool Signal< Dali::Toolkit::Control, const Dali::KeyEvent& >;
380 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Toolkit::Control, const Dali::KeyEvent& );
381
382 // void Signal< Dali::Toolkit::Control >;
383 DALI_SIGNAL_1_PARAM( Dali::Toolkit::Control );
384
385 // void Signal< Dali::Toolkit::VideoView& >;
386 DALI_SIGNAL_1_PARAM( Dali::Toolkit::VideoView& );
387
388 // Signal< bool (Dali::Toolkit::Slider, float) >;
389 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, float );
390
391 //  Signal< bool(Dali::Toolkit::Slider, int) >;
392 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, int );
393
394 } // namespace DALi
395
396