Merge "DALi C# binding - Follow Pascal case convention for enum members" into devel...
[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   private delegate void StartedCallbackDelegate(IntPtr vector2);
82   private DaliEventHandler<object,StartedEventArgs> _scrollableStartedEventHandler;
83   private StartedCallbackDelegate _scrollableStartedCallbackDelegate;
84
85   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
86   private delegate void UpdatedCallbackDelegate(IntPtr vector2);
87   private DaliEventHandler<object,UpdatedEventArgs> _scrollableUpdatedEventHandler;
88   private UpdatedCallbackDelegate _scrollableUpdatedCallbackDelegate;
89
90   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91   private delegate void CompletedCallbackDelegate(IntPtr vector2);
92   private DaliEventHandler<object,CompletedEventArgs> _scrollableCompletedEventHandler;
93   private CompletedCallbackDelegate _scrollableCompletedCallbackDelegate;
94
95   public event DaliEventHandler<object,StartedEventArgs> ScrollStarted
96   {
97      add
98      {
99         lock(this)
100         {
101            // Restricted to only one listener
102            if (_scrollableStartedEventHandler == null)
103            {
104               _scrollableStartedEventHandler += value;
105
106               _scrollableStartedCallbackDelegate = new StartedCallbackDelegate(OnStarted);
107               this.ScrollStartedSignal().Connect(_scrollableStartedCallbackDelegate);
108            }
109         }
110      }
111
112      remove
113      {
114         lock(this)
115         {
116            if (_scrollableStartedEventHandler != null)
117            {
118               this.ScrollStartedSignal().Disconnect(_scrollableStartedCallbackDelegate);
119            }
120
121            _scrollableStartedEventHandler -= value;
122         }
123      }
124   }
125
126  private void OnStarted(IntPtr vector2)
127   {
128    StartedEventArgs e = new StartedEventArgs();
129
130    // Populate all members of "e" (StartedEventArgs) with real data
131    e.Vector2 = Dali.Vector2.GetVector2FromPtr(vector2);
132
133    if (_scrollableStartedEventHandler != null)
134    {
135       //here we send all data to user event handlers
136       _scrollableStartedEventHandler(this, e);
137    }
138
139   }
140
141   public event DaliEventHandler<object,UpdatedEventArgs> ScrollUpdated
142   {
143      add
144      {
145         lock(this)
146         {
147            // Restricted to only one listener
148            if (_scrollableUpdatedEventHandler == null)
149            {
150               _scrollableUpdatedEventHandler += value;
151
152               _scrollableUpdatedCallbackDelegate = new UpdatedCallbackDelegate(OnUpdated);
153               this.ScrollUpdatedSignal().Connect(_scrollableUpdatedCallbackDelegate);
154            }
155         }
156      }
157
158      remove
159      {
160         lock(this)
161         {
162            if (_scrollableUpdatedEventHandler != null)
163            {
164               this.ScrollUpdatedSignal().Disconnect(_scrollableUpdatedCallbackDelegate);
165            }
166
167            _scrollableUpdatedEventHandler -= value;
168         }
169      }
170   }
171
172  private void OnUpdated(IntPtr vector2)
173   {
174    UpdatedEventArgs e = new UpdatedEventArgs();
175
176    // Populate all members of "e" (UpdatedEventArgs) with real data
177    e.Vector2 = Dali.Vector2.GetVector2FromPtr(vector2);
178
179    if (_scrollableUpdatedEventHandler != null)
180    {
181       //here we send all data to user event handlers
182       _scrollableUpdatedEventHandler(this, e);
183    }
184
185   }
186
187   public event DaliEventHandler<object,CompletedEventArgs> ScrollCompleted
188   {
189      add
190      {
191         lock(this)
192         {
193            // Restricted to only one listener
194            if (_scrollableCompletedEventHandler == null)
195            {
196               _scrollableCompletedEventHandler += value;
197
198               _scrollableCompletedCallbackDelegate = new CompletedCallbackDelegate(OnCompleted);
199               this.ScrollCompletedSignal().Connect(_scrollableCompletedCallbackDelegate);
200            }
201         }
202      }
203
204      remove
205      {
206         lock(this)
207         {
208            if (_scrollableCompletedEventHandler != null)
209            {
210               this.ScrollCompletedSignal().Disconnect(_scrollableCompletedCallbackDelegate);
211            }
212
213            _scrollableCompletedEventHandler -= value;
214         }
215      }
216   }
217
218  private void OnCompleted(IntPtr vector2)
219   {
220    CompletedEventArgs e = new CompletedEventArgs();
221
222    // Populate all members of "e" (CompletedEventArgs) with real data
223    e.Vector2 = Dali.Vector2.GetVector2FromPtr(vector2);
224
225    if (_scrollableCompletedEventHandler != null)
226    {
227       //here we send all data to user event handlers
228       _scrollableCompletedEventHandler(this, e);
229    }
230
231   }
232
233 %}
234
235 %enddef
236
237 %define DALI_SCROLLABLE_EVENTHANDLER_PARAM( NameSpace, ClassName)
238
239   SCROLLABLE_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
240   SCROLLABLE_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
241
242 %enddef
243
244 namespace Dali
245 {
246   DALI_SCROLLABLE_EVENTHANDLER_PARAM( Dali::Toolkit, Scrollable);
247 }