7613e20d172aa1e7e71616425b9df51d7efedf0d
[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 /* Properties earlier added by Ruby Script */
234
235   public Dali.CSharp.Color OvershootEffectColor
236   {
237     get
238     {
239       Vector4 temp = new Vector4(0.0f,0.0f,0.0f,0.0f);
240       GetProperty( Scrollable.Property.OVERSHOOT_EFFECT_COLOR).Get(  temp );
241       Dali.CSharp.Color ret = new Dali.CSharp.Color(temp.r, temp.g, temp.b, temp.a);
242       return ret;
243     }
244     set
245     {
246       SetProperty( Scrollable.Property.OVERSHOOT_EFFECT_COLOR, new Dali.Property.Value( value ) );
247     }
248   }
249   public float OvershootAnimationSpeed
250   {
251     get
252     {
253       float temp = 0.0f;
254       GetProperty( Scrollable.Property.OVERSHOOT_ANIMATION_SPEED).Get( ref temp );
255       return temp;
256     }
257     set
258     {
259       SetProperty( Scrollable.Property.OVERSHOOT_ANIMATION_SPEED, new Dali.Property.Value( value ) );
260     }
261   }
262   public bool OvershootEnabled
263   {
264     get
265     {
266       bool temp = false;
267       GetProperty( Scrollable.Property.OVERSHOOT_ENABLED).Get( ref temp );
268       return temp;
269     }
270     set
271     {
272       SetProperty( Scrollable.Property.OVERSHOOT_ENABLED, new Dali.Property.Value( value ) );
273     }
274   }
275   public Dali.CSharp.Size OvershootSize
276   {
277     get
278     {
279       Vector2 temp = new Vector2(0.0f,0.0f);
280       GetProperty( Scrollable.Property.OVERSHOOT_SIZE).Get(  temp );
281       Dali.CSharp.Size ret = new Dali.CSharp.Size(temp.x, temp.y);
282       return ret;
283     }
284     set
285     {
286       SetProperty( Scrollable.Property.OVERSHOOT_SIZE, new Dali.Property.Value( value ) );
287     }
288   }
289   public int ScrollToAlphaFunction
290   {
291     get
292     {
293       int temp = 0;
294       GetProperty( Scrollable.Property.SCROLL_TO_ALPHA_FUNCTION).Get( ref temp );
295       return temp;
296     }
297     set
298     {
299       SetProperty( Scrollable.Property.SCROLL_TO_ALPHA_FUNCTION, new Dali.Property.Value( value ) );
300     }
301   }
302   public Dali.CSharp.Size ScrollRelativePosition
303   {
304     get
305     {
306       Vector2 temp = new Vector2(0.0f,0.0f);
307       GetProperty( Scrollable.Property.SCROLL_RELATIVE_POSITION).Get(  temp );
308       Dali.CSharp.Size ret = new Dali.CSharp.Size(temp.x, temp.y);
309       return ret;
310     }
311     set
312     {
313       SetProperty( Scrollable.Property.SCROLL_RELATIVE_POSITION, new Dali.Property.Value( value ) );
314     }
315   }
316   public Dali.CSharp.Size ScrollPositionMin
317   {
318     get
319     {
320       Vector2 temp = new Vector2(0.0f,0.0f);
321       GetProperty( Scrollable.Property.SCROLL_POSITION_MIN).Get(  temp );
322       Dali.CSharp.Size ret = new Dali.CSharp.Size(temp.x, temp.y);
323       return ret;
324     }
325     set
326     {
327       SetProperty( Scrollable.Property.SCROLL_POSITION_MIN, new Dali.Property.Value( value ) );
328     }
329   }
330   public Dali.CSharp.Size ScrollPositionMax
331   {
332     get
333     {
334       Vector2 temp = new Vector2(0.0f,0.0f);
335       GetProperty( Scrollable.Property.SCROLL_POSITION_MAX).Get(  temp );
336       Dali.CSharp.Size ret = new Dali.CSharp.Size(temp.x, temp.y);
337       return ret;
338     }
339     set
340     {
341       SetProperty( Scrollable.Property.SCROLL_POSITION_MAX, new Dali.Property.Value( value ) );
342     }
343   }
344   public bool CanScrollVertical
345   {
346     get
347     {
348       bool temp = false;
349       GetProperty( Scrollable.Property.CAN_SCROLL_VERTICAL).Get( ref temp );
350       return temp;
351     }
352     set
353     {
354       SetProperty( Scrollable.Property.CAN_SCROLL_VERTICAL, new Dali.Property.Value( value ) );
355     }
356   }
357   public bool CanScrollHorizontal
358   {
359     get
360     {
361       bool temp = false;
362       GetProperty( Scrollable.Property.CAN_SCROLL_HORIZONTAL).Get( ref temp );
363       return temp;
364     }
365     set
366     {
367       SetProperty( Scrollable.Property.CAN_SCROLL_HORIZONTAL, new Dali.Property.Value( value ) );
368     }
369   }
370
371 /* Properties ends */
372
373 %}
374
375 %enddef
376
377 %define DALI_SCROLLABLE_EVENTHANDLER_PARAM( NameSpace, ClassName)
378
379   SCROLLABLE_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
380   SCROLLABLE_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
381
382 %enddef
383
384 namespace Dali
385 {
386   DALI_SCROLLABLE_EVENTHANDLER_PARAM( Dali::Toolkit, Scrollable);
387 }