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