DALi C# binding - EventHandler Support
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / scrollable-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 SCROLLABLE_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 SCROLLABLE_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27 %typemap(cscode) NameSpace::ClassName %{
28
29 public class StartedEventArgs : EventArgs
30 {
31    private Vector2 _vector2;
32
33    public Vector2 Vector2
34    {
35       get
36       {
37          return _vector2;
38       }
39       set
40       {
41          _vector2 = value;
42       }
43    }
44 }
45
46 public class UpdatedEventArgs : EventArgs
47 {
48    private Vector2 _vector2;
49
50    public Vector2 Vector2
51    {
52       get
53       {
54          return _vector2;
55       }
56       set
57       {
58          _vector2 = value;
59       }
60    }
61 }
62
63 public class CompletedEventArgs : EventArgs
64 {
65    private Vector2 _vector2;
66
67    public Vector2 Vector2
68    {
69       get
70       {
71          return _vector2;
72       }
73       set
74       {
75          _vector2 = value;
76       }
77    }
78 }
79
80   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
81   public delegate void StartedEventHandler(object source, StartedEventArgs e);
82
83   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
84   public delegate void UpdatedEventHandler(object source, UpdatedEventArgs e);
85
86   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
87   public delegate void CompletedEventHandler(object source, CompletedEventArgs e);
88
89   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
90   private delegate void StartedCallbackDelegate(IntPtr vector2);
91   private StartedEventHandler _scrollableStartedEventHandler;
92   private StartedCallbackDelegate _scrollableStartedCallbackDelegate;
93
94   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
95   private delegate void UpdatedCallbackDelegate(IntPtr vector2);
96   private UpdatedEventHandler _scrollableUpdatedEventHandler;
97   private UpdatedCallbackDelegate _scrollableUpdatedCallbackDelegate;
98
99   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
100   private delegate void CompletedCallbackDelegate(IntPtr vector2);
101   private CompletedEventHandler _scrollableCompletedEventHandler;
102   private CompletedCallbackDelegate _scrollableCompletedCallbackDelegate;
103
104   public event StartedEventHandler ScrollStarted
105   {
106      add
107      {
108         lock(this)
109         {
110            // Restricted to only one listener
111            if (_scrollableStartedEventHandler == null)
112            {
113               _scrollableStartedEventHandler += value;
114
115               _scrollableStartedCallbackDelegate = new StartedCallbackDelegate(OnStarted);
116               this.ScrollStartedSignal().Connect(_scrollableStartedCallbackDelegate);
117            }
118         }
119      }
120
121      remove
122      {
123         lock(this)
124         {
125            if (_scrollableStartedEventHandler != null)
126            {
127               this.ScrollStartedSignal().Disconnect(_scrollableStartedCallbackDelegate);
128            }
129
130            _scrollableStartedEventHandler -= value;
131         }
132      }
133   }
134
135  private void OnStarted(IntPtr vector2)
136   {
137    StartedEventArgs e = new StartedEventArgs();
138
139    // Populate all members of "e" (StartedEventArgs) with real data
140    e.Vector2 = Dali.Vector2.GetVector2FromPtr(vector2);
141
142    if (_scrollableStartedEventHandler != null)
143    {
144       //here we send all data to user event handlers
145       _scrollableStartedEventHandler(this, e);
146    }
147
148   }
149
150   public event UpdatedEventHandler ScrollUpdated
151   {
152      add
153      {
154         lock(this)
155         {
156            // Restricted to only one listener
157            if (_scrollableUpdatedEventHandler == null)
158            {
159               _scrollableUpdatedEventHandler += value;
160
161               _scrollableUpdatedCallbackDelegate = new UpdatedCallbackDelegate(OnUpdated);
162               this.ScrollUpdatedSignal().Connect(_scrollableUpdatedCallbackDelegate);
163            }
164         }
165      }
166
167      remove
168      {
169         lock(this)
170         {
171            if (_scrollableUpdatedEventHandler != null)
172            {
173               this.ScrollUpdatedSignal().Disconnect(_scrollableUpdatedCallbackDelegate);
174            }
175
176            _scrollableUpdatedEventHandler -= value;
177         }
178      }
179   }
180
181  private void OnUpdated(IntPtr vector2)
182   {
183    UpdatedEventArgs e = new UpdatedEventArgs();
184
185    // Populate all members of "e" (UpdatedEventArgs) with real data
186    e.Vector2 = Dali.Vector2.GetVector2FromPtr(vector2);
187
188    if (_scrollableUpdatedEventHandler != null)
189    {
190       //here we send all data to user event handlers
191       _scrollableUpdatedEventHandler(this, e);
192    }
193
194   }
195
196   public event CompletedEventHandler ScrollCompleted
197   {
198      add
199      {
200         lock(this)
201         {
202            // Restricted to only one listener
203            if (_scrollableCompletedEventHandler == null)
204            {
205               _scrollableCompletedEventHandler += value;
206
207               _scrollableCompletedCallbackDelegate = new CompletedCallbackDelegate(OnCompleted);
208               this.ScrollCompletedSignal().Connect(_scrollableCompletedCallbackDelegate);
209            }
210         }
211      }
212
213      remove
214      {
215         lock(this)
216         {
217            if (_scrollableCompletedEventHandler != null)
218            {
219               this.ScrollCompletedSignal().Disconnect(_scrollableCompletedCallbackDelegate);
220            }
221
222            _scrollableCompletedEventHandler -= value;
223         }
224      }
225   }
226
227  private void OnCompleted(IntPtr vector2)
228   {
229    CompletedEventArgs e = new CompletedEventArgs();
230
231    // Populate all members of "e" (CompletedEventArgs) with real data
232    e.Vector2 = Dali.Vector2.GetVector2FromPtr(vector2);
233
234    if (_scrollableCompletedEventHandler != null)
235    {
236       //here we send all data to user event handlers
237       _scrollableCompletedEventHandler(this, e);
238    }
239
240   }
241
242 %}
243
244 %enddef
245
246 %define DALI_SCROLLABLE_EVENTHANDLER_PARAM( NameSpace, ClassName)
247
248   SCROLLABLE_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
249   SCROLLABLE_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
250
251 %enddef
252
253 namespace Dali
254 {
255   DALI_SCROLLABLE_EVENTHANDLER_PARAM( Dali::Toolkit, Scrollable);
256 }