2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
23 // %typemap(cstype) const CDate & "System.DateTime"
26 // CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);"
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.
33 %include <dali/public-api/signals/dali-signal.h>
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.
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)"
54 * SWIG can't auto generate wrappers for template parameters that are functions ( which dali-signal has)
55 * so we have make them ourselves
58 %define SIGNAL_TEMPLATE_HELPER_0( returnType, returnFunc)
59 template<> class Signal< returnType () >
66 return $self->Empty();
68 std::size_t GetConnectionCount() const
70 return $self->GetConnectionCount();
72 void Connect( returnType ( *func ) () )
74 $self->Connect( func );
76 void Disconnect( returnType ( *func ) () )
78 $self->Disconnect( func );
82 returnFunc $self->Emit();
88 %define SIGNAL_TEMPLATE_HELPER_1( returnType, returnFunc, argumentType )
89 template<> class Signal< returnType ( argumentType ) >
96 return $self->Empty();
98 std::size_t GetConnectionCount() const
100 return $self->GetConnectionCount();
102 void Connect( returnType ( *func ) ( argumentType ) )
104 $self->Connect( func );
106 void Disconnect( returnType ( *func ) ( argumentType ) )
108 $self->Disconnect( func );
110 returnType Emit( argumentType arg)
112 returnFunc $self->Emit( arg );
118 %define SIGNAL_TEMPLATE_HELPER_2( returnType, returnFunc, argumentType1, argumentType2 )
119 template<> class Signal< returnType ( argumentType1, argumentType2 ) >
126 return $self->Empty();
128 std::size_t GetConnectionCount() const
130 return $self->GetConnectionCount();
132 void Connect( returnType ( *func ) ( argumentType1, argumentType2 ) )
134 $self->Connect( func );
136 void Disconnect( returnType ( *func ) ( argumentType1, argumentType2 ) )
138 $self->Disconnect( func );
140 returnType Emit( argumentType1 arg1, argumentType2 arg2 )
142 returnFunc $self->Emit( arg1, arg2 );
148 %define SIGNAL_TEMPLATE_HELPER_3( returnType, returnFunc, argumentType1, argumentType2, argumentType3 )
149 template<> class Signal< returnType ( argumentType1, argumentType2, argumentType3 ) >
156 return $self->Empty();
158 std::size_t GetConnectionCount() const
160 return $self->GetConnectionCount();
162 void Connect( returnType ( *func ) ( argumentType1, argumentType2, argumentType3 ) )
164 return $self->Connect( func );
166 void Disconnect( returnType ( *func ) ( argumentType1, argumentType2, argumentType3 ) )
168 $self->Disconnect( func );
170 returnType Emit( argumentType1 arg1, argumentType2 arg2, argumentType3 arg3 )
172 returnFunc $self->Emit( arg1, arg2, arg3 );
178 ////////////////////////////////
180 Macros for signals without return values
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;
188 // Macro to define a csharp signal.
189 // 0 param signals ( no return )
190 %define DALI_SIGNAL_0_PARAM()
192 SIGNAL_TYPEMAP_HELPER( void (*func) () );
193 SIGNAL_TEMPLATE_HELPER_0( void, NO_RETURN_FUNC);
196 // 1 param signals ( no return )
197 %define DALI_SIGNAL_1_PARAM( argumentType1 )
199 SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1 ) );
200 SIGNAL_TEMPLATE_HELPER_1( void, NO_RETURN_FUNC, argumentType1);
203 // 2 param signals ( no return )
204 %define DALI_SIGNAL_2_PARAM( argumentType1, argumentType2)
206 SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1, argumentType2) );
207 SIGNAL_TEMPLATE_HELPER_2( void, NO_RETURN_FUNC, argumentType1, argumentType2);
211 // 3 param signals ( no return )
212 %define DALI_SIGNAL_3_PARAM( argumentType1, argumentType2, argumentType3 )
214 SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1, argumentType2, argumentType3 ) );
215 SIGNAL_TEMPLATE_HELPER_3( void, NO_RETURN_FUNC, argumentType1, argumentType2, argumentType3);
220 Macros for signals with return values
223 // 0 param signals ( with return )
224 %define DALI_SIGNAL_0_PARAM_RETURN( returnType )
226 SIGNAL_TYPEMAP_HELPER( returnType (*func) () );
227 SIGNAL_TEMPLATE_HELPER_0( returnType, return);
230 // 1 param signals ( with return )
231 %define DALI_SIGNAL_1_PARAM_RETURN( returnType, argumentType1 )
233 SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1 ) );
234 SIGNAL_TEMPLATE_HELPER_1( returnType, return, argumentType1);
238 // 2 param signals ( with return )
239 %define DALI_SIGNAL_2_PARAM_RETURN( returnType, argumentType1, argumentType2)
241 SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2) );
242 SIGNAL_TEMPLATE_HELPER_2( returnType, return, argumentType1, argumentType2);
246 // 3 param signals ( with return )
247 %define DALI_SIGNAL_3_PARAM_RETURN( returnType, argumentType1, argumentType2, argumentType3 )
249 SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2, argumentType3 ) );
250 SIGNAL_TEMPLATE_HELPER_3( returnType, return, argumentType1, argumentType2, argumentType3);
257 DALI_SIGNAL_0_PARAM();
260 DALI_SIGNAL_0_PARAM_RETURN( bool );
262 // Signal< void (Actor) >
263 DALI_SIGNAL_1_PARAM( Dali::Actor );
265 // Signal< void (float) >
266 DALI_SIGNAL_1_PARAM( float );
268 // Signal< void (Dali::Application&) >
269 DALI_SIGNAL_1_PARAM( Dali::Application& );
271 // Signal< void (Dali::Application&, void*) >
272 DALI_SIGNAL_2_PARAM( Dali::Application& , void* );
274 // Signal< void (Dali::Image) >
275 DALI_SIGNAL_1_PARAM( Dali::Image );
277 // Signal< void (Dali::ResourceImage) >
278 DALI_SIGNAL_1_PARAM( Dali::ResourceImage );
280 // Signal< void (Dali::Animation&) >
281 DALI_SIGNAL_1_PARAM( Dali::Animation& );
283 // Signal< void (Dali::Actor, const Dali::TouchEvent&) >
284 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TouchEvent& );
286 // Signal< bool (Dali::Actor, const Dali::TouchData&) >
287 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Actor, const Dali::TouchData& );
289 // Signal< bool (Dali::Actor, const Dali::HoverEvent&) >
290 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::HoverEvent& );
292 // Signal< bool (Dali::Actor, const Dali::WheelEvent&) >
293 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::WheelEvent& );
295 // Signal< void (const Dali::KeyEvent&) >
296 DALI_SIGNAL_1_PARAM( const Dali::KeyEvent& );
298 // Signal< void (const Dali::TouchData&) >
299 DALI_SIGNAL_1_PARAM( const Dali::TouchData& );
301 // Signal< void (const Dali::HoverEvent&) >
302 DALI_SIGNAL_1_PARAM( const Dali::HoverEvent& );
304 // Signal< void (const Dali::WheelEvent&) >
305 DALI_SIGNAL_1_PARAM( const Dali::WheelEvent& );
307 // Signal< void (const Dali::LongPressGesture&) >
308 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::LongPressGesture& );
310 // Signal< void (Dali::Actor, const Dali::PanGesture&) >
311 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PanGesture& );
313 // Signal< void (Dali::Actor, const Dali::PinchGesture&) >
314 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PinchGesture& );
316 // Signal< void (Dali::Actor, const Dali::TapGesture&) >
317 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TapGesture& );
319 // Signal< void (Dali::PropertyNotification) >
320 DALI_SIGNAL_1_PARAM( Dali::PropertyNotification& ) ;
322 // Signal< void (Dali::BaseHandle) >
323 DALI_SIGNAL_1_PARAM( Dali::BaseHandle );
325 // Signal< void (const Dali::RefObject*) >
326 DALI_SIGNAL_1_PARAM( const Dali::RefObject* );
328 // Signal< void (const Dali::RenderTask&) >
329 DALI_SIGNAL_1_PARAM( const Dali::RenderTask& );
331 // Signal< bool ( const Dali::Toolkit::AccessibilityManager& ) >
332 DALI_SIGNAL_1_PARAM_RETURN( bool, Dali::Toolkit::AccessibilityManager& );
334 // Signal< bool ( const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
335 DALI_SIGNAL_2_PARAM_RETURN( bool, const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& );
337 // Signal< void ( const Dali::Actor Dali::Toolkit::AccessibilityManager::FocusOvershotDirection ) >
338 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
340 // Signal< bool ( Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
341 DALI_SIGNAL_2_PARAM_RETURN( bool ,Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent&);
343 // Signal< void ( Dali::Toolkit::StyleManager, Dali::StyleChange::Type) >
344 DALI_SIGNAL_2_PARAM( Dali::Toolkit::StyleManager, Dali::StyleChange::Type);
346 // void Signal< Dali::Actor, bool >;
347 DALI_SIGNAL_2_PARAM( Dali::Actor, bool);
349 // void Signal< Dali::Actor, Dali::Actor >;
350 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Actor);
352 // bool Signal< Dali::Toolkit::Button >;
353 DALI_SIGNAL_1_PARAM_RETURN( bool, Dali::Toolkit::Button);
355 // void Signal< Dali::Toolkit::GaussianBlurView >;
356 DALI_SIGNAL_1_PARAM( Dali::Toolkit::GaussianBlurView);
358 // void Signal< Dali::Toolkit::PageTurnView, unsigned int, bool >;
359 DALI_SIGNAL_3_PARAM( Dali::Toolkit::PageTurnView, unsigned int, bool );
361 // void Signal< Dali::Toolkit::PageTurnView >;
362 DALI_SIGNAL_1_PARAM( Dali::Toolkit::PageTurnView );
364 // void Signal< Dali::Toolkit::ProgressBar, float, float >;
365 DALI_SIGNAL_3_PARAM( Dali::Toolkit::ProgressBar, float, float );
367 // void Signal< const Dali::Toolkit::ScrollView::SnapEvent& >;
368 DALI_SIGNAL_1_PARAM( const Dali::Toolkit::ScrollView::SnapEvent& );
370 // void Signal< const Dali::Vector2& >;
371 DALI_SIGNAL_1_PARAM( const Dali::Vector2& );
373 // void Signal< Dali::Toolkit::TextEditor >;
374 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextEditor );
376 // void Signal< Dali::Toolkit::TextField >;
377 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextField );
379 // bool Signal< Dali::Toolkit::Control, const Dali::KeyEvent& >;
380 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Toolkit::Control, const Dali::KeyEvent& );
382 // void Signal< Dali::Toolkit::Control >;
383 DALI_SIGNAL_1_PARAM( Dali::Toolkit::Control );
385 // void Signal< Dali::Toolkit::VideoView& >;
386 DALI_SIGNAL_1_PARAM( Dali::Toolkit::VideoView& );
388 // Signal< bool (Dali::Toolkit::Slider, float) >;
389 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, float );
391 // Signal< bool(Dali::Toolkit::Slider, int) >;
392 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, int );