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