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_1( returnType, returnFunc, argumentType )
59 template<> class Signal< returnType ( argumentType ) >
66 return $self->Empty();
68 std::size_t GetConnectionCount() const
70 return $self->GetConnectionCount();
72 void Connect( returnType ( *func ) ( argumentType ) )
74 $self->Connect( func );
76 void Disconnect( returnType ( *func ) ( argumentType ) )
78 $self->Disconnect( func );
80 returnType Emit( argumentType arg)
82 returnFunc $self->Emit( arg );
88 %define SIGNAL_TEMPLATE_HELPER_2( returnType, returnFunc, argumentType1, argumentType2 )
89 template<> class Signal< returnType ( argumentType1, argumentType2 ) >
96 return $self->Empty();
98 std::size_t GetConnectionCount() const
100 return $self->GetConnectionCount();
102 void Connect( returnType ( *func ) ( argumentType1, argumentType2 ) )
104 $self->Connect( func );
106 void Disconnect( returnType ( *func ) ( argumentType1, argumentType2 ) )
108 $self->Disconnect( func );
110 returnType Emit( argumentType1 arg1, argumentType2 arg2 )
112 returnFunc $self->Emit( arg1, arg2 );
118 %define SIGNAL_TEMPLATE_HELPER_3( returnType, returnFunc, argumentType1, argumentType2, argumentType3 )
119 template<> class Signal< returnType ( argumentType1, argumentType2, argumentType3 ) >
126 return $self->Empty();
128 std::size_t GetConnectionCount() const
130 return $self->GetConnectionCount();
132 void Connect( returnType ( *func ) ( argumentType1, argumentType2, argumentType3 ) )
134 return $self->Connect( func );
136 void Disconnect( returnType ( *func ) ( argumentType1, argumentType2, argumentType3 ) )
138 $self->Disconnect( func );
140 returnType Emit( argumentType1 arg1, argumentType2 arg2, argumentType3 arg3 )
142 returnFunc $self->Emit( arg1, arg2, arg3 );
148 ////////////////////////////////
150 Macros for signals without return values
153 // the emit for some signal has to emit a return value
154 // this macro is just for signals that don't (instead of return Emit();.. it just does ;Emit();
155 %define NO_RETURN_FUNC;
158 // Macro to define a csharp signal.
159 // 1 param signals ( no return )
160 %define DALI_SIGNAL_1_PARAM( argumentType1 )
162 SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1 ) );
163 SIGNAL_TEMPLATE_HELPER_1( void, NO_RETURN_FUNC, argumentType1);
166 // 2 param signals ( no return )
167 %define DALI_SIGNAL_2_PARAM( argumentType1, argumentType2)
169 SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1, argumentType2) );
170 SIGNAL_TEMPLATE_HELPER_2( void, NO_RETURN_FUNC, argumentType1, argumentType2);
174 // 3 param signals ( no return )
175 %define DALI_SIGNAL_3_PARAM( argumentType1, argumentType2, argumentType3 )
177 SIGNAL_TYPEMAP_HELPER( void (*func) ( argumentType1, argumentType2, argumentType3 ) );
178 SIGNAL_TEMPLATE_HELPER_3( void, NO_RETURN_FUNC, argumentType1, argumentType2, argumentType3);
183 Macros for signals with return values
186 // 1 param signals ( with return )
187 %define DALI_SIGNAL_1_PARAM_RETURN( returnType, argumentType1 )
189 SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1 ) );
190 SIGNAL_TEMPLATE_HELPER_1( returnType, return, argumentType1);
194 // 2 param signals ( with return )
195 %define DALI_SIGNAL_2_PARAM_RETURN( returnType, argumentType1, argumentType2)
197 SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2) );
198 SIGNAL_TEMPLATE_HELPER_2( returnType, return, argumentType1, argumentType2);
202 // 3 param signals ( with return )
203 %define DALI_SIGNAL_3_PARAM_RETURN( returnType, argumentType1, argumentType2, argumentType3 )
205 SIGNAL_TYPEMAP_HELPER( returnType (*func) ( argumentType1, argumentType2, argumentType3 ) );
206 SIGNAL_TEMPLATE_HELPER_3( returnType, return, argumentType1, argumentType2, argumentType3);
212 // Signal< void (Actor) >
213 DALI_SIGNAL_1_PARAM( Dali::Actor );
215 // Signal< void (float) >
216 DALI_SIGNAL_1_PARAM( float );
218 // Signal< void (Dali::Application&) >
219 DALI_SIGNAL_1_PARAM( Dali::Application& );
221 // Signal< void (Dali::Application&, void*) >
222 DALI_SIGNAL_2_PARAM( Dali::Application& , void* );
224 // Signal< void (Dali::Image) >
225 DALI_SIGNAL_1_PARAM( Dali::Image );
227 // Signal< void (Dali::ResourceImage) >
228 DALI_SIGNAL_1_PARAM( Dali::ResourceImage );
230 // Signal< void (Dali::Animation&) >
231 DALI_SIGNAL_1_PARAM( Dali::Animation& );
233 // Signal< void (Dali::Actor, const Dali::TouchEvent&) >
234 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TouchEvent& );
236 // Signal< bool (Dali::Actor, const Dali::TouchData&) >
237 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Actor, const Dali::TouchData& );
239 // Signal< bool (Dali::Actor, const Dali::HoverEvent&) >
240 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::HoverEvent& );
242 // Signal< bool (Dali::Actor, const Dali::WheelEvent&) >
243 DALI_SIGNAL_2_PARAM_RETURN( bool , Dali::Actor, const Dali::WheelEvent& );
245 // Signal< void (const Dali::KeyEvent&) >
246 DALI_SIGNAL_1_PARAM( const Dali::KeyEvent& );
248 // Signal< void (const Dali::TouchData&) >
249 DALI_SIGNAL_1_PARAM( const Dali::TouchData& );
251 // Signal< void (const Dali::HoverEvent&) >
252 DALI_SIGNAL_1_PARAM( const Dali::HoverEvent& );
254 // Signal< void (const Dali::WheelEvent&) >
255 DALI_SIGNAL_1_PARAM( const Dali::WheelEvent& );
257 // Signal< void (const Dali::LongPressGesture&) >
258 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::LongPressGesture& );
260 // Signal< void (Dali::Actor, const Dali::PanGesture&) >
261 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PanGesture& );
263 // Signal< void (Dali::Actor, const Dali::PinchGesture&) >
264 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::PinchGesture& );
266 // Signal< void (Dali::Actor, const Dali::TapGesture&) >
267 DALI_SIGNAL_2_PARAM( Dali::Actor, const Dali::TapGesture& );
269 // Signal< void (Dali::PropertyNotification) >
270 DALI_SIGNAL_1_PARAM( Dali::PropertyNotification& ) ;
272 // Signal< void (Dali::BaseHandle) >
273 DALI_SIGNAL_1_PARAM( Dali::BaseHandle );
275 // Signal< void (const Dali::RefObject*) >
276 DALI_SIGNAL_1_PARAM( const Dali::RefObject* );
278 // Signal< void (const Dali::RenderTask&) >
279 DALI_SIGNAL_1_PARAM( const Dali::RenderTask& );
281 // Signal< bool ( const Dali::Toolkit::AccessibilityManager& ) >
282 DALI_SIGNAL_1_PARAM_RETURN( bool ,const Dali::Toolkit::AccessibilityManager& );
284 // Signal< bool ( const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
285 DALI_SIGNAL_2_PARAM_RETURN( bool ,const Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& );
287 // Signal< void ( const Dali::Actor Dali::Toolkit::AccessibilityManager::FocusOvershotDirection ) >
288 DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
290 // Signal< bool ( Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent& ) >
291 DALI_SIGNAL_2_PARAM_RETURN( bool ,Dali::Toolkit::AccessibilityManager&, const Dali::TouchEvent&);
293 // Signal< void ( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection) >
294 //DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
296 // Signal< void ( Dali::Toolkit::StyleManager, Dali::StyleChange::Type) >
297 DALI_SIGNAL_2_PARAM( Dali::Toolkit::StyleManager, Dali::StyleChange::Type);
299 // Signal< void ( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection )>
300 //DALI_SIGNAL_2_PARAM( Dali::Actor, Dali::Toolkit::AccessibilityManager::FocusOvershotDirection );
302 // Signal< Dali::Actor ( Dali::Actor, Dali::Actor, Dali::Actor, Dali::Toolkit::Control::KeyboardFocus::Direction) >
303 DALI_SIGNAL_3_PARAM_RETURN( Dali::Actor, Dali::Actor, Dali::Actor, Dali::Toolkit::Control::KeyboardFocus::Direction);
305 // void Signal< Dali::Actor, bool >;
306 DALI_SIGNAL_2_PARAM( Dali::Actor, bool);
308 // bool Signal< Dali::Toolkit::Button >;
309 DALI_SIGNAL_1_PARAM_RETURN( bool, Dali::Toolkit::Button);
311 // void Signal< Dali::Toolkit::GaussianBlurView >;
312 DALI_SIGNAL_1_PARAM( Dali::Toolkit::GaussianBlurView);
314 // void Signal< Dali::Toolkit::PageTurnView, unsigned int, bool >;
315 DALI_SIGNAL_3_PARAM( Dali::Toolkit::PageTurnView, unsigned int, bool );
317 // void Signal< Dali::Toolkit::PageTurnView >;
318 DALI_SIGNAL_1_PARAM( Dali::Toolkit::PageTurnView );
320 // void Signal< const Dali::Toolkit::ScrollView::SnapEvent& >;
321 DALI_SIGNAL_1_PARAM( const Dali::Toolkit::ScrollView::SnapEvent& );
323 // void Signal< const Dali::Vector2& >;
324 DALI_SIGNAL_1_PARAM( const Dali::Vector2& );
326 // void Signal< Dali::Toolkit::TextEditor >;
327 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextEditor );
329 // void Signal< Dali::Toolkit::TextField >;
330 DALI_SIGNAL_1_PARAM( Dali::Toolkit::TextField )
332 // bool Signal< Dali::Toolkit::Control, const Dali::KeyEvent& >;
333 DALI_SIGNAL_2_PARAM_RETURN( bool, Dali::Toolkit::Control, const Dali::KeyEvent& );
335 // void Signal< Dali::Toolkit::Control >;
336 DALI_SIGNAL_1_PARAM( Dali::Toolkit::Control );
338 // void Signal< Dali::Toolkit::VideoView& >;
339 DALI_SIGNAL_1_PARAM( Dali::Toolkit::VideoView& );
341 // Signal< bool (Dali::Toolkit::Slider, float) >;
342 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, float );
344 // Signal< bool(Dali::Toolkit::Slider, int) >;
345 DALI_SIGNAL_2_PARAM_RETURN( bool,Dali::Toolkit::Slider, int );