Merge "DALi C# binding - Follow Pascal case convention for enum members" into devel...
[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   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55   private delegate void SnapStartedCallbackDelegate(IntPtr data);
56   private DaliEventHandler<object,SnapStartedEventArgs> _scrollViewSnapStartedEventHandler;
57   private SnapStartedCallbackDelegate _scrollViewSnapStartedCallbackDelegate;
58
59   /**
60     * @brief Event for SnapStarted signal which can be used to subscribe/unsubscribe the event handler
61     * (in the type of SnapStartedEventHandler-DaliEventHandler<object,SnapStartedEventArgs>) provided by the user.
62     * SnapStarted signal is emitted hen the ScrollView has started to snap or flick (it tells the target
63     * position, scale, rotation for the snap or flick).
64     *
65     */
66  public event DaliEventHandler<object,SnapStartedEventArgs> SnapStarted
67   {
68      add
69      {
70         lock(this)
71         {
72            // Restricted to only one listener
73            if (_scrollViewSnapStartedEventHandler == null)
74            {
75               _scrollViewSnapStartedEventHandler += value;
76
77               _scrollViewSnapStartedCallbackDelegate = new SnapStartedCallbackDelegate(OnSnapStarted);
78               this.SnapStartedSignal().Connect(_scrollViewSnapStartedCallbackDelegate);
79            }
80         }
81      }
82
83      remove
84      {
85         lock(this)
86         {
87            if (_scrollViewSnapStartedEventHandler != null)
88            {
89               this.SnapStartedSignal().Disconnect(_scrollViewSnapStartedCallbackDelegate);
90            }
91
92            _scrollViewSnapStartedEventHandler -= value;
93         }
94      }
95   }
96
97   // Callback for ScrollView SnapStarted signal
98   private void OnSnapStarted(IntPtr data)
99   {
100      SnapStartedEventArgs e = new SnapStartedEventArgs();
101
102      // Populate all members of "e" (SnapStartedEventArgs) with real data
103      e.SnapEventInfo = SnapEvent.GetSnapEventFromPtr( data );
104
105      if (_scrollViewSnapStartedEventHandler != null)
106      {
107         //here we send all data to user event handlers
108         _scrollViewSnapStartedEventHandler(this, e);
109      }
110   }
111
112 %}
113
114 %enddef
115
116
117 %define DALI_SCROLLVIEW_EVENTHANDLER_PARAM( NameSpace, ClassName)
118
119   SCROLLVIEW_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
120   SCROLLVIEW_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
121
122 %enddef
123
124 namespace Dali
125 {
126   DALI_SCROLLVIEW_EVENTHANDLER_PARAM( Dali::Toolkit, ScrollView);
127 }