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