256be7946feff427720a96b6c6621618c5bf4e02
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / scrollbar-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 SCROLLBAR_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24
25 %enddef
26
27
28 %define SCROLLBAR_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
29 %typemap(cscode) NameSpace::ClassName %{
30
31
32 public class PanFinishedEventArgs : EventArgs
33 {
34 }
35
36 public class ScrollPositionIntervalReachedEventArgs : EventArgs
37 {
38    private float _currentScrollPosition;
39
40    public float CurrentScrollPosition
41    {
42       get
43       {
44          return _currentScrollPosition;
45       }
46       set
47       {
48          _currentScrollPosition = value;
49       }
50    }
51 }
52
53   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
54   public delegate void PanFinishedEventHandler(object source, PanFinishedEventArgs e);
55
56   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
57   public delegate void ScrollPositionIntervalReachedEventHandler(object source, ScrollPositionIntervalReachedEventArgs e);
58
59   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
60   private delegate void PanFinishedEventCallbackDelegate();
61   private PanFinishedEventHandler _scrollBarPanFinishedEventHandler;
62   private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
63
64   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
65   private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
66   private ScrollPositionIntervalReachedEventHandler _scrollBarScrollPositionIntervalReachedEventHandler;
67   private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
68
69   public event PanFinishedEventHandler PanFinished
70   {
71      add
72      {
73         lock(this)
74         {
75            // Restricted to only one listener
76            if (_scrollBarPanFinishedEventHandler == null)
77            {
78               _scrollBarPanFinishedEventHandler += value;
79
80               _scrollBarPanFinishedEventCallbackDelegate = new PanFinishedEventCallbackDelegate(OnScrollBarPanFinished);
81               this.PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
82            }
83         }
84      }
85
86      remove
87      {
88         lock(this)
89         {
90            if (_scrollBarPanFinishedEventHandler != null)
91            {
92               this.PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
93            }
94
95            _scrollBarPanFinishedEventHandler -= value;
96         }
97      }
98   }
99
100   // Callback for ScrollBar PanFinishedSignal
101   private void OnScrollBarPanFinished()
102   {
103      PanFinishedEventArgs e = new PanFinishedEventArgs();
104
105      if (_scrollBarPanFinishedEventHandler != null)
106      {
107         //here we send all data to user event handlers
108         _scrollBarPanFinishedEventHandler(this, e);
109      }
110   }
111
112
113   public event ScrollPositionIntervalReachedEventHandler ScrollPositionIntervalReached
114   {
115      add
116      {
117         lock(this)
118         {
119            // Restricted to only one listener
120            if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
121            {
122               _scrollBarScrollPositionIntervalReachedEventHandler += value;
123
124               _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = new ScrollPositionIntervalReachedEventCallbackDelegate(OnScrollBarScrollPositionIntervalReached);
125               this.ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
126            }
127         }
128      }
129
130      remove
131      {
132         lock(this)
133         {
134            if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
135            {
136               this.ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
137            }
138
139            _scrollBarScrollPositionIntervalReachedEventHandler -= value;
140         }
141      }
142   }
143
144   // Callback for ScrollBar ScrollPositionIntervalReachedSignal
145   private void OnScrollBarScrollPositionIntervalReached()
146   {
147      ScrollPositionIntervalReachedEventArgs e = new ScrollPositionIntervalReachedEventArgs();
148
149      if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
150      {
151         //here we send all data to user event handlers
152         _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
153      }
154   }
155
156 %}
157 %enddef
158
159 %define DALI_SCROLLBAR_EVENTHANDLER_PARAM( NameSpace, ClassName)
160   SCROLLBAR_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
161   SCROLLBAR_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
162 %enddef
163
164 namespace Dali
165 {
166   DALI_SCROLLBAR_EVENTHANDLER_PARAM( Dali::Toolkit, ScrollBar);
167 }
168