DALi C# binding - EventHandler Support
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / scrollview-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 SCROLLVIEW_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 SCROLLVIEW_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
27 %typemap(cscode) NameSpace::ClassName %{
28
29 /**
30   * @brief Event arguments that passed via SnapStarted signal
31   *
32   */
33 public class SnapStartedEventArgs : EventArgs
34 {
35    private Dali.ScrollView.SnapEvent _snapEvent;
36
37    /**
38      * @brief SnapEvent - is the SnapEvent information like snap or flick (it tells the target position, scale, rotation for the snap or flick).
39      *
40      */
41    public Dali.ScrollView.SnapEvent SnapEventInfo
42    {
43       get
44       {
45          return _snapEvent;
46       }
47       set
48       {
49          _snapEvent = value;
50       }
51    }
52 }
53
54
55   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
56   public delegate void SnapStartedEventHandler(object source, SnapStartedEventArgs e);
57
58   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59   private delegate void SnapStartedCallbackDelegate(IntPtr data);
60   private SnapStartedEventHandler _scrollViewSnapStartedEventHandler;
61   private SnapStartedCallbackDelegate _scrollViewSnapStartedCallbackDelegate;
62
63   /**
64     * @brief Event for SnapStarted signal which can be used to subscribe/unsubscribe the event handler
65     * (in the type of SnapStartedEventHandler) provided by the user.
66     * SnapStarted signal is emitted hen the ScrollView has started to snap or flick (it tells the target
67     * position, scale, rotation for the snap or flick).
68     *
69     */
70  public event SnapStartedEventHandler SnapStarted
71   {
72      add
73      {
74         lock(this)
75         {
76            // Restricted to only one listener
77            if (_scrollViewSnapStartedEventHandler == null)
78            {
79               _scrollViewSnapStartedEventHandler += value;
80
81               _scrollViewSnapStartedCallbackDelegate = new SnapStartedCallbackDelegate(OnSnapStarted);
82               this.SnapStartedSignal().Connect(_scrollViewSnapStartedCallbackDelegate);
83            }
84         }
85      }
86
87      remove
88      {
89         lock(this)
90         {
91            if (_scrollViewSnapStartedEventHandler != null)
92            {
93               this.SnapStartedSignal().Disconnect(_scrollViewSnapStartedCallbackDelegate);
94            }
95
96            _scrollViewSnapStartedEventHandler -= value;
97         }
98      }
99   }
100
101   // Callback for ScrollView SnapStarted signal
102   private void OnSnapStarted(IntPtr data)
103   {
104      SnapStartedEventArgs e = new SnapStartedEventArgs();
105
106      // Populate all members of "e" (SnapStartedEventArgs) with real data
107      e.SnapEventInfo = SnapEvent.GetSnapEventFromPtr( data );
108
109      if (_scrollViewSnapStartedEventHandler != null)
110      {
111         //here we send all data to user event handlers
112         _scrollViewSnapStartedEventHandler(this, e);
113      }
114   }
115
116 %}
117
118 %enddef
119
120
121 %define DALI_SCROLLVIEW_EVENTHANDLER_PARAM( NameSpace, ClassName)
122
123   SCROLLVIEW_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
124   SCROLLVIEW_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
125
126 %enddef
127
128 namespace Dali
129 {
130   DALI_SCROLLVIEW_EVENTHANDLER_PARAM( Dali::Toolkit, ScrollView);
131 }