DALi C# binding - Generic Delegates support for EventHandlers
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / actor-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 ACTOR_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20     using System;
21     using System.Runtime.InteropServices;
22 %}
23
24 %enddef
25
26 %define ACTOR_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27   %typemap(cscode) NameSpace::ClassName %{
28
29
30     /**
31       * @brief Event arguments that passed via Touch signal
32       *
33       */
34     public class TouchEventArgs : EventArgs
35     {
36        private Actor _actor;
37        private TouchData _touchData;
38
39       /**
40         * @brief Actor - is the actor that is being touched
41         *
42         */
43       public Actor Actor
44       {
45         get
46         {
47           return _actor;
48         }
49         set
50         {
51           _actor = value;
52         }
53       }
54
55       /**
56         * @brief TouchData - contains the information of touch points
57         *
58         */
59       public TouchData TouchData
60       {
61         get
62         {
63           return _touchData;
64         }
65         set
66         {
67           _touchData = value;
68         }
69       }
70     }
71
72     /**
73       * @brief Event arguments that passed via Hover signal
74       *
75       */
76     public class HoverEventArgs : EventArgs
77     {
78     private Actor _actor;
79     private HoverEvent _hoverEvent;
80
81       /**
82         * @brief Actor - is the actor that is being hovered
83         *
84         */
85       public Actor Actor
86       {
87         get
88         {
89           return _actor;
90         }
91         set
92         {
93           _actor = value;
94         }
95       }
96
97       /**
98         * @brief HoverEvent - contains touch points that represent the points
99         * that are currently being hovered or the points where a hover has stopped
100         *
101         */
102       public HoverEvent HoverEvent
103       {
104         get
105         {
106           return _hoverEvent;
107         }
108         set
109         {
110           _hoverEvent = value;
111         }
112       }
113     }
114
115     /**
116       * @brief Event arguments that passed via Wheel signal
117       *
118       */
119     public class WheelEventArgs : EventArgs
120     {
121     private Actor _actor;
122     private WheelEvent _wheelEvent;
123
124       /**
125         * @brief Actor - is the actor that is being wheeled
126         *
127         */
128       public Actor Actor
129       {
130         get
131         {
132           return _actor;
133         }
134         set
135         {
136           _actor = value;
137         }
138       }
139
140       /**
141         * @brief WheelEvent - store a wheel rolling type : MOUSE_WHEEL or CUSTOM_WHEEL
142         *
143         */
144       public WheelEvent WheelEvent
145       {
146         get
147         {
148           return _wheelEvent;
149         }
150         set
151         {
152           _wheelEvent = value;
153         }
154       }
155     }
156
157     /**
158       * @brief Event arguments that passed via OnStage signal
159       *
160       */
161     public class OnStageEventArgs : EventArgs
162     {
163     private Actor _actor;
164
165       /**
166         * @brief Actor - is the actor that is being connected to the stage
167         *
168         */
169       public Actor Actor
170       {
171         get
172         {
173           return _actor;
174         }
175         set
176         {
177           _actor = value;
178         }
179       }
180     }
181
182     /**
183       * @brief Event arguments that passed via OffStage signal
184       *
185       */
186     public class OffStageEventArgs : EventArgs
187     {
188     private Actor _actor;
189
190       /**
191         * @brief Actor - is the actor that is being disconnected from the stage
192         *
193         */
194       public Actor Actor
195       {
196         get
197         {
198           return _actor;
199         }
200         set
201         {
202           _actor = value;
203         }
204       }
205     }
206
207     /**
208       * @brief Event arguments that passed via OnRelayout signal
209       *
210       */
211     public class OnRelayoutEventArgs : EventArgs
212     {
213       private Actor _actor;
214
215       /**
216         * @brief Actor - is the actor that is being resized upon relayout
217         *
218         */
219       public Actor Actor
220       {
221         get
222         {
223           return _actor;
224         }
225         set
226         {
227           _actor = value;
228         }
229       }
230     }
231
232
233     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
234     private delegate bool TouchCallbackDelegate(IntPtr actor, IntPtr touchData);
235     private DaliEventHandlerWithReturnType<object,TouchEventArgs,bool> _actorTouchDataEventHandler;
236     private TouchCallbackDelegate _actorTouchDataCallbackDelegate;
237
238     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
239     private delegate bool HoverEventCallbackDelegate(IntPtr actor, IntPtr hoverEvent);
240     private DaliEventHandlerWithReturnType<object,HoverEventArgs,bool> _actorHoverEventHandler;
241     private HoverEventCallbackDelegate _actorHoverEventCallbackDelegate;
242
243     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
244     private delegate bool WheelEventCallbackDelegate(IntPtr actor, IntPtr wheelEvent);
245     private DaliEventHandlerWithReturnType<object,WheelEventArgs,bool> _actorWheelEventHandler;
246     private WheelEventCallbackDelegate _actorWheelEventCallbackDelegate;
247
248     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
249     private delegate void OnStageEventCallbackDelegate(IntPtr actor);
250     private DaliEventHandler<object,OnStageEventArgs> _actorOnStageEventHandler;
251     private OnStageEventCallbackDelegate _actorOnStageEventCallbackDelegate;
252
253     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
254     private delegate void OffStageEventCallbackDelegate(IntPtr actor);
255     private DaliEventHandler<object,OffStageEventArgs> _actorOffStageEventHandler;
256     private OffStageEventCallbackDelegate _actorOffStageEventCallbackDelegate;
257
258     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
259     private delegate void OnRelayoutEventCallbackDelegate(IntPtr actor);
260     private DaliEventHandler<object,OnRelayoutEventArgs> _actorOnRelayoutEventHandler;
261     private OnRelayoutEventCallbackDelegate _actorOnRelayoutEventCallbackDelegate;
262
263     /**
264       * @brief Event for Touched signal which can be used to subscribe/unsubscribe the event handler
265       * (in the type of TouchEventHandler-DaliEventHandlerWithReturnType<object,TouchEventArgs,bool>)
266       * provided by the user. Touched signal is emitted when touch input is received.
267       */
268     public event DaliEventHandlerWithReturnType<object,TouchEventArgs,bool> Touched
269     {
270       add
271       {
272         lock(this)
273         {
274           // Restricted to only one listener
275           if (_actorTouchDataEventHandler == null)
276           {
277             _actorTouchDataEventHandler += value;
278
279             _actorTouchDataCallbackDelegate = new TouchCallbackDelegate(OnTouch);
280             this.TouchSignal().Connect(_actorTouchDataCallbackDelegate);
281           }
282         }
283       }
284
285       remove
286       {
287         lock(this)
288         {
289           if (_actorTouchDataEventHandler != null)
290           {
291             this.TouchSignal().Disconnect(_actorTouchDataCallbackDelegate);
292           }
293
294           _actorTouchDataEventHandler -= value;
295         }
296       }
297     }
298
299     // Callback for Actor TouchSignal
300     private bool OnTouch(IntPtr actor, IntPtr touchData)
301     {
302       TouchEventArgs e = new TouchEventArgs();
303
304       // Populate all members of "e" (TouchEventArgs) with real data
305       e.Actor = Actor.GetActorFromPtr(actor);
306       e.TouchData = Dali.TouchData.GetTouchDataFromPtr(touchData);
307
308       if (_actorTouchDataEventHandler != null)
309       {
310         //here we send all data to user event handlers
311         return _actorTouchDataEventHandler(this, e, true);
312       }
313
314       return false;
315     }
316
317     /**
318       * @brief Event for Hovered signal which can be used to subscribe/unsubscribe the event handler
319       * (in the type of HoverEventHandler-DaliEventHandlerWithReturnType<object,HoverEventArgs,bool>)
320       * provided by the user. Hovered signal is emitted when hover input is received.
321       */
322     public event DaliEventHandlerWithReturnType<object,HoverEventArgs,bool> Hovered
323     {
324       add
325       {
326         lock(this)
327         {
328           // Restricted to only one listener
329           if (_actorHoverEventHandler == null)
330           {
331             _actorHoverEventHandler += value;
332
333             _actorHoverEventCallbackDelegate = new HoverEventCallbackDelegate(OnHoverEvent);
334             this.HoveredSignal().Connect(_actorHoverEventCallbackDelegate);
335           }
336         }
337       }
338
339       remove
340       {
341         lock(this)
342         {
343           if (_actorHoverEventHandler != null)
344           {
345             this.HoveredSignal().Disconnect(_actorHoverEventCallbackDelegate);
346           }
347
348           _actorHoverEventHandler -= value;
349         }
350       }
351     }
352
353     // Callback for Actor Hover signal
354     private bool OnHoverEvent(IntPtr actor, IntPtr hoverEvent)
355     {
356       HoverEventArgs e = new HoverEventArgs();
357
358       // Populate all members of "e" (HoverEventArgs) with real data
359       e.Actor = Actor.GetActorFromPtr(actor);
360       e.HoverEvent = Dali.HoverEvent.GetHoverEventFromPtr(hoverEvent);
361
362       if (_actorHoverEventHandler != null)
363       {
364         //here we send all data to user event handlers
365         return _actorHoverEventHandler(this, e, true);
366       }
367
368       return false;
369     }
370
371     /**
372       * @brief Event for WheelMoved signal which can be used to subscribe/unsubscribe the event handler
373       * (in the type of WheelEventHandler-DaliEventHandlerWithReturnType<object,WheelEventArgs,bool>)
374       * provided by the user. WheelMoved signal is emitted when wheel event is received.
375       */
376     public event DaliEventHandlerWithReturnType<object,WheelEventArgs,bool> WheelMoved
377     {
378       add
379       {
380         lock(this)
381         {
382           // Restricted to only one listener
383           if (_actorWheelEventHandler == null)
384           {
385             _actorWheelEventHandler += value;
386
387             _actorWheelEventCallbackDelegate = new WheelEventCallbackDelegate(OnWheelEvent);
388             this.WheelEventSignal().Connect(_actorWheelEventCallbackDelegate);
389           }
390         }
391       }
392
393       remove
394       {
395         lock(this)
396         {
397           if (_actorWheelEventHandler != null)
398           {
399             this.WheelEventSignal().Disconnect(_actorWheelEventCallbackDelegate);
400           }
401
402           _actorWheelEventHandler -= value;
403         }
404       }
405     }
406
407     // Callback for Actor Wheel signal
408     private bool OnWheelEvent(IntPtr actor, IntPtr wheelEvent)
409     {
410       WheelEventArgs e = new WheelEventArgs();
411
412       // Populate all members of "e" (WheelEventArgs) with real data
413       e.Actor = Actor.GetActorFromPtr(actor);
414       e.WheelEvent = Dali.WheelEvent.GetWheelEventFromPtr(wheelEvent);
415
416       if (_actorWheelEventHandler != null)
417       {
418         //here we send all data to user event handlers
419         return _actorWheelEventHandler(this, e, true);
420       }
421
422       return false;
423     }
424
425     /**
426       * @brief Event for OnStage signal which can be used to subscribe/unsubscribe the event handler
427       * (in the type of OnStageEventHandler) provided by the user.
428       * OnStage signal is emitted after the actor has been connected to the stage.
429       */
430     public event DaliEventHandler<object,OnStageEventArgs> OnStageEvent
431     {
432       add
433       {
434         lock(this)
435         {
436           // Restricted to only one listener
437           if (_actorOnStageEventHandler == null)
438           {
439             _actorOnStageEventHandler += value;
440
441             _actorOnStageEventCallbackDelegate = new OnStageEventCallbackDelegate(OnStage);
442             this.OnStageSignal().Connect(_actorOnStageEventCallbackDelegate);
443           }
444         }
445       }
446
447       remove
448       {
449         lock(this)
450         {
451           if (_actorOnStageEventHandler != null)
452           {
453             this.OnStageSignal().Disconnect(_actorOnStageEventCallbackDelegate);
454           }
455
456           _actorOnStageEventHandler -= value;
457         }
458       }
459     }
460
461     // Callback for Actor OnStage signal
462     private void OnStage(IntPtr data)
463     {
464       OnStageEventArgs e = new OnStageEventArgs();
465
466       // Populate all members of "e" (OnStageEventArgs) with real data
467       e.Actor = Actor.GetActorFromPtr(data);
468
469       if (_actorOnStageEventHandler != null)
470       {
471         //here we send all data to user event handlers
472         _actorOnStageEventHandler(this, e);
473       }
474     }
475
476     /**
477       * @brief Event for OffStage signal which can be used to subscribe/unsubscribe the event handler
478       * (in the type of OffStageEventHandler) provided by the user.
479       * OffStage signal is emitted after the actor has been disconnected from the stage.
480       */
481     public event DaliEventHandler<object,OffStageEventArgs> OffStageEvent
482     {
483       add
484       {
485         lock(this)
486         {
487           // Restricted to only one listener
488           if (_actorOffStageEventHandler == null)
489           {
490             _actorOffStageEventHandler += value;
491
492             _actorOffStageEventCallbackDelegate = new OffStageEventCallbackDelegate(OffStage);
493             this.OnStageSignal().Connect(_actorOffStageEventCallbackDelegate);
494           }
495         }
496       }
497
498       remove
499       {
500         lock(this)
501         {
502           if (_actorOffStageEventHandler != null)
503           {
504             this.OnStageSignal().Disconnect(_actorOffStageEventCallbackDelegate);
505           }
506
507           _actorOffStageEventHandler -= value;
508         }
509       }
510     }
511
512     // Callback for Actor OffStage signal
513     private void OffStage(IntPtr data)
514     {
515       OffStageEventArgs e = new OffStageEventArgs();
516
517       // Populate all members of "e" (OffStageEventArgs) with real data
518       e.Actor = Actor.GetActorFromPtr(data);
519
520       if (_actorOffStageEventHandler != null)
521       {
522         //here we send all data to user event handlers
523         _actorOffStageEventHandler(this, e);
524       }
525     }
526
527     /**
528       * @brief Event for OnRelayout signal which can be used to subscribe/unsubscribe the event handler
529       * (in the type of OnRelayoutEventHandler) provided by the user.
530       * OnRelayout signal is emitted after the size has been set on the actor during relayout.
531       */
532     public event DaliEventHandler<object,OnRelayoutEventArgs> OnRelayoutEvent
533     {
534       add
535       {
536         lock(this)
537         {
538           // Restricted to only one listener
539           if (_actorOnRelayoutEventHandler == null)
540           {
541             _actorOnRelayoutEventHandler += value;
542
543             _actorOnRelayoutEventCallbackDelegate = new OnRelayoutEventCallbackDelegate(OnRelayout);
544             this.OnRelayoutSignal().Connect(_actorOnRelayoutEventCallbackDelegate);
545           }
546         }
547       }
548
549       remove
550       {
551         lock(this)
552         {
553           if (_actorOnRelayoutEventHandler != null)
554           {
555             this.OnRelayoutSignal().Disconnect(_actorOnRelayoutEventCallbackDelegate);
556           }
557
558           _actorOnRelayoutEventHandler -= value;
559         }
560       }
561     }
562
563     // Callback for Actor OnRelayout signal
564     private void OnRelayout(IntPtr data)
565     {
566       OnRelayoutEventArgs e = new OnRelayoutEventArgs();
567
568       // Populate all members of "e" (OnRelayoutEventArgs) with real data
569       e.Actor = Actor.GetActorFromPtr(data);
570
571       if (_actorOnRelayoutEventHandler != null)
572       {
573         //here we send all data to user event handlers
574         _actorOnRelayoutEventHandler(this, e);
575       }
576     }
577
578     public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
579       ClassName ret = new ClassName(cPtr, false);
580       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
581       return ret;
582     }
583
584     public IntPtr GetPtrfrom ## ClassName ()
585     {
586        return (IntPtr)swigCPtr;
587     }
588
589     public Actor Parent
590     {
591       get
592       {
593         Actor parent = GetParent();
594         return parent;
595       }
596     }
597
598    public bool Vibility
599    {
600       get
601       {
602         bool visibility = IsVisible();
603         return visibility;
604       }
605     }
606
607    public float Opacity
608    {
609       set
610       {
611         SetOpacity(value);
612       }
613     }
614
615    public float CurrentOpacity
616    {
617       get
618       {
619         float ret = GetCurrentOpacity();
620         return ret;
621       }
622     }
623
624     public bool StateFocusEnable
625     {
626       set
627       {
628         SetKeyboardFocusable(value);
629       }
630       get
631       {
632         bool focusable = IsKeyboardFocusable();
633         return focusable;
634       }
635     }
636
637 %}
638
639 %enddef
640
641 %define DALI_ACTOR_EVENTHANDLER_PARAM( NameSpace, ClassName)
642
643 ACTOR_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
644 ACTOR_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
645
646 %enddef
647
648 namespace Dali
649 {
650   DALI_ACTOR_EVENTHANDLER_PARAM( Dali, Actor);
651 }