Merge "DALi C# binding - Generic Delegates support for EventHandlers" into devel...
[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   private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr longPressGesture);
61   private DaliEventHandler<object,DetectedEventArgs> _longPressGestureEventHandler;
62   private DetectedCallbackDelegate _longPressGestureCallbackDelegate;
63
64
65   public event DaliEventHandler<object,DetectedEventArgs> Detected
66   {
67      add
68      {
69         lock(this)
70         {
71            // Restricted to only one listener
72            if (_longPressGestureEventHandler == null)
73            {
74               _longPressGestureEventHandler += value;
75
76               _longPressGestureCallbackDelegate = new DetectedCallbackDelegate(OnLongPressGestureDetected);
77               this.DetectedSignal().Connect(_longPressGestureCallbackDelegate);
78            }
79         }
80      }
81
82      remove
83      {
84         lock(this)
85         {
86            if (_longPressGestureEventHandler != null)
87            {
88               this.DetectedSignal().Disconnect(_longPressGestureCallbackDelegate);
89            }
90
91            _longPressGestureEventHandler -= value;
92         }
93      }
94   }
95
96  private void OnLongPressGestureDetected(IntPtr actor, IntPtr longPressGesture)
97   {
98    DetectedEventArgs e = new DetectedEventArgs();
99
100    // Populate all members of "e" (LongPressGestureEventArgs) with real data
101    e.Actor = Actor.GetActorFromPtr(actor);
102    e.LongPressGesture = Dali.LongPressGesture.GetLongPressGestureFromPtr(longPressGesture);
103
104    if (_longPressGestureEventHandler != null)
105    {
106       //here we send all data to user event handlers
107       _longPressGestureEventHandler(this, e);
108    }
109
110   }
111
112
113 public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
114     ClassName ret = new ClassName(cPtr, false);
115    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116     return ret;
117   }
118
119 %}
120
121 %enddef
122
123 %define DALI_longPressGesture_EVENTHANDLER_PARAM( NameSpace, ClassName)
124
125   LongPressGesture_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
126   LongPressGesture_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
127
128 %enddef
129
130 namespace Dali
131 {
132   DALI_longPressGesture_EVENTHANDLER_PARAM( Dali, LongPressGestureDetector);
133 }