Fix license issue
[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 // 1 param signals ( with return )
224 %define DALI_SIGNAL_1_PARAM_RETURN( returnType, argumentType1 )
225
226   SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1 ) );
227   SIGNAL_TEMPLATE_HELPER_1( returnType, return, argumentType1);
228
229 %enddef
230
231 // 2 param signals ( with return )
232 %define DALI_SIGNAL_2_PARAM_RETURN( returnType, argumentType1, argumentType2)
233
234   SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2) );
235   SIGNAL_TEMPLATE_HELPER_2( returnType, return, argumentType1, argumentType2);
236
237 %enddef
238
239 // 3 param signals ( with return )
240 %define DALI_SIGNAL_3_PARAM_RETURN( returnType, argumentType1, argumentType2, argumentType3 )
241
242   SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2, argumentType3 ) );
243   SIGNAL_TEMPLATE_HELPER_3( returnType, return, argumentType1, argumentType2, argumentType3);
244
245 %enddef
246
247 namespace Dali
248 {
249 // Signal< void () >
250 DALI_SIGNAL_0_PARAM();
251
252 // Signal< void (Actor) >
253 DALI_SIGNAL_1_PARAM( Dali::Actor );
254
255 //  Signal< void (float) >
256 DALI_SIGNAL_1_PARAM( float );
257
258 // Signal< void (Dali::Application&) >
259 DALI_SIGNAL_1_PARAM( Dali::Application& );
260
261 // Signal< void (Dali::Application&, void*) >
262 DALI_SIGNAL_2_PARAM( Dali::Application& , void* );
263
264 // Signal< void (Dali::Image) >
265 DALI_SIGNAL_1_PARAM( Dali::Image );
266
267 // Signal< void (Dali::ResourceImage) >
268 DALI_SIGNAL_1_PARAM( Dali::ResourceImage );
269
270 // Signal< void (Dali::Animation&) >
271 DALI_SIGNAL_1_PARAM( Dali::Animation& );
272
273 // Signal< void (Dali::Actor, const Dali::TouchEvent&) >
274 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TouchEvent& );
275
276 //  Signal< bool (Dali::Actor, const Dali::TouchData&) >
277 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Actor, const Dali::TouchData& );
278
279 // Signal< bool (Dali::Actor, const Dali::HoverEvent&) >
280 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::HoverEvent& );
281
282 // Signal< bool (Dali::Actor, const Dali::WheelEvent&) >
283 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::WheelEvent& );
284
285 // Signal< void (const Dali::KeyEvent&) >
286 DALI_SIGNAL_1_PARAM( const Dali::KeyEvent&  );
287
288 // Signal< void (const Dali::TouchData&) >
289 DALI_SIGNAL_1_PARAM( const Dali::TouchData& );
290
291 // Signal< void (const Dali::HoverEvent&) >
292 DALI_SIGNAL_1_PARAM( const Dali::HoverEvent& );
293
294 // Signal< void (const Dali::WheelEvent&) >
295 DALI_SIGNAL_1_PARAM( const Dali::WheelEvent& );
296
297 // Signal< void (const Dali::LongPressGesture&) >
298 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::LongPressGesture& );
299
300 // Signal< void (Dali::Actor, const Dali::PanGesture&) >
301 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PanGesture& );
302
303 // Signal< void (Dali::Actor, const Dali::PinchGesture&) >
304 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PinchGesture& );
305
306 // Signal< void (Dali::Actor, const Dali::TapGesture&) >
307 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TapGesture& );
308
309 // Signal< void (Dali::PropertyNotification) >
310 DALI_SIGNAL_1_PARAM( Dali::PropertyNotification& ) ;
311
312 //  Signal< void (Dali::BaseHandle) >
313 DALI_SIGNAL_1_PARAM( Dali::BaseHandle );
314
315 //  Signal< void (const Dali::RefObject*) >
316 DALI_SIGNAL_1_PARAM( const Dali::RefObject* );
317
318 // Signal< void (const Dali::RenderTask&) >
319 DALI_SIGNAL_1_PARAM( const Dali::RenderTask& );
320
321 // Signal< bool ( const Dali::Toolkit::AccessibilityManager& ) >
322 DALI_SIGNAL_1_PARAM_RETURN( bool ,Dali::Toolkit::AccessibilityManager& );
323
324 // Signal< bool ( const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
325 DALI_SIGNAL_2_PARAM_RETURN( bool ,const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& );
326
327 // Signal< void ( const Dali::Actor Dali::Toolkit::AccessibilityManager::FocusOvershotDirection ) >
328 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
329
330 // Signal< bool ( Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
331 DALI_SIGNAL_2_PARAM_RETURN( bool ,Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent&);
332
333 // Signal< void ( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection) >
334 //DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
335
336 // Signal< void (  Dali::Toolkit::StyleManager, Dali::StyleChange::Type) >
337 DALI_SIGNAL_2_PARAM( Dali::Toolkit::StyleManager, Dali::StyleChange::Type);
338
339 // Signal< void (  Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection )>
340 //DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
341
342 // Signal<  Dali::Actor (  Dali::Actor, Dali::Actor, Dali::Actor, Dali::Toolkit::Control::KeyboardFocus::Direction) >
343 DALI_SIGNAL_3_PARAM_RETURN( Dali::Actor, Dali::Actor, Dali::Actor, Dali::Toolkit::Control::KeyboardFocus::Direction);
344
345 // void Signal<  Dali::Actor, bool >;
346 DALI_SIGNAL_2_PARAM( Dali::Actor, bool);
347
348 // void Signal<  Dali::Actor, Dali::Actor >;
349 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Actor);
350
351 // bool Signal< Dali::Toolkit::Button >;
352 DALI_SIGNAL_1_PARAM_RETURN( bool, Dali::Toolkit::Button);
353
354 // void Signal< Dali::Toolkit::GaussianBlurView >;
355 DALI_SIGNAL_1_PARAM( Dali::Toolkit::GaussianBlurView);
356
357 // void Signal< Dali::Toolkit::PageTurnView, unsigned int, bool >;
358 DALI_SIGNAL_3_PARAM( Dali::Toolkit::PageTurnView, unsigned int, bool );
359
360 // void Signal< Dali::Toolkit::PageTurnView >;
361 DALI_SIGNAL_1_PARAM( Dali::Toolkit::PageTurnView );
362
363 // void Signal< const Dali::Toolkit::ScrollView::SnapEvent& >;
364 DALI_SIGNAL_1_PARAM( const Dali::Toolkit::ScrollView::SnapEvent& );
365
366 // void Signal< const Dali::Vector2& >;
367 DALI_SIGNAL_1_PARAM( const Dali::Vector2& );
368
369 // void Signal< Dali::Toolkit::TextEditor >;
370 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextEditor );
371
372 // void Signal< Dali::Toolkit::TextField >;
373 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextField );
374
375 // bool Signal< Dali::Toolkit::Control, const Dali::KeyEvent& >;
376 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Toolkit::Control, const Dali::KeyEvent& );
377
378 // void Signal< Dali::Toolkit::Control >;
379 DALI_SIGNAL_1_PARAM( Dali::Toolkit::Control );
380
381 // void Signal< Dali::Toolkit::VideoView& >;
382 DALI_SIGNAL_1_PARAM( Dali::Toolkit::VideoView& );
383
384 // Signal< bool (Dali::Toolkit::Slider, float) >;
385 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, float );
386
387 //  Signal< bool(Dali::Toolkit::Slider, int) >;
388 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, int );
389
390 } // namespace DALi
391
392