DALi C# binding - Generic Delegates support for EventHandlers
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / tapgesture-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 TapGesture_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 TapGesture_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27 %typemap(cscode) NameSpace::ClassName %{
28
29
30 public class DetectedEventArgs : EventArgs
31 {
32    private Actor _actor;
33    private TapGesture _tapGesture;
34
35    public Actor Actor
36    {
37       get
38       {
39          return _actor;
40       }
41       set
42       {
43          _actor = value;
44       }
45    }
46
47    public TapGesture TapGesture
48    {
49       get
50       {
51          return _tapGesture;
52       }
53       set
54       {
55          _tapGesture = value;
56       }
57    }
58 }
59
60   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
61   private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr TapGesture);
62   private DaliEventHandler<object,DetectedEventArgs> _tapGestureEventHandler;
63   private DetectedCallbackDelegate _tapGestureCallbackDelegate;
64
65
66   public event DaliEventHandler<object,DetectedEventArgs> Detected
67   {
68      add
69      {
70         lock(this)
71         {
72            // Restricted to only one listener
73            if (_tapGestureEventHandler == null)
74            {
75               _tapGestureEventHandler += value;
76
77               _tapGestureCallbackDelegate = new DetectedCallbackDelegate(OnTapGestureDetected);
78               this.DetectedSignal().Connect(_tapGestureCallbackDelegate);
79            }
80         }
81      }
82
83      remove
84      {
85         lock(this)
86         {
87            if (_tapGestureEventHandler != null)
88            {
89               this.DetectedSignal().Disconnect(_tapGestureCallbackDelegate);
90            }
91
92            _tapGestureEventHandler -= value;
93         }
94      }
95   }
96
97  private void OnTapGestureDetected(IntPtr actor, IntPtr tapGesture)
98   {
99    DetectedEventArgs e = new DetectedEventArgs();
100
101    // Populate all members of "e" (DetectedEventArgs) with real data
102    e.Actor = Actor.GetActorFromPtr(actor);
103    e.TapGesture = Dali.TapGesture.GetTapGestureFromPtr(tapGesture);
104
105    if (_tapGestureEventHandler != null)
106    {
107       //here we send all data to user event handlers
108       _tapGestureEventHandler(this, e);
109    }
110
111   }
112
113
114 public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
115     ClassName ret = new ClassName(cPtr, false);
116    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117     return ret;
118   }
119
120 %}
121
122 %enddef
123
124 %define DALI_tapGesture_EVENTHANDLER_PARAM( NameSpace, ClassName)
125
126   TapGesture_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
127   TapGesture_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
128
129 %enddef
130
131 namespace Dali
132 {
133   DALI_tapGesture_EVENTHANDLER_PARAM( Dali, TapGestureDetector);
134 }