Merge "DALi C# binding - Generic Delegates support for EventHandlers" into devel...
[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   private delegate void PanFinishedEventCallbackDelegate();
55   private DaliEventHandler<object,PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
56   private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
57   
58   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59   private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
60   private DaliEventHandler<object,ScrollPositionIntervalReachedEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
61   private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
62
63   public event DaliEventHandler<object,PanFinishedEventArgs> PanFinished
64   {
65      add
66      {
67         lock(this)
68         {
69            // Restricted to only one listener
70            if (_scrollBarPanFinishedEventHandler == null)
71            {
72               _scrollBarPanFinishedEventHandler += value;
73
74               _scrollBarPanFinishedEventCallbackDelegate = new PanFinishedEventCallbackDelegate(OnScrollBarPanFinished);
75               this.PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
76            }
77         }
78      }
79
80      remove
81      {
82         lock(this)
83         {
84            if (_scrollBarPanFinishedEventHandler != null)
85            {
86               this.PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
87            }
88
89            _scrollBarPanFinishedEventHandler -= value;
90         }
91      }
92   }
93
94   // Callback for ScrollBar PanFinishedSignal
95   private void OnScrollBarPanFinished()
96   {
97      PanFinishedEventArgs e = new PanFinishedEventArgs();
98
99      if (_scrollBarPanFinishedEventHandler != null)
100      {
101         //here we send all data to user event handlers
102         _scrollBarPanFinishedEventHandler(this, e);
103      }
104   }
105
106
107   public event DaliEventHandler<object,ScrollPositionIntervalReachedEventArgs> ScrollPositionIntervalReached
108   {
109      add
110      {
111         lock(this)
112         {
113            // Restricted to only one listener
114            if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
115            {
116               _scrollBarScrollPositionIntervalReachedEventHandler += value;
117
118               _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = new ScrollPositionIntervalReachedEventCallbackDelegate(OnScrollBarScrollPositionIntervalReached);
119               this.ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
120            }
121         }
122      }
123
124      remove
125      {
126         lock(this)
127         {
128            if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
129            {
130               this.ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
131            }
132
133            _scrollBarScrollPositionIntervalReachedEventHandler -= value;
134         }
135      }
136   }
137
138   // Callback for ScrollBar ScrollPositionIntervalReachedSignal
139   private void OnScrollBarScrollPositionIntervalReached()
140   {
141      ScrollPositionIntervalReachedEventArgs e = new ScrollPositionIntervalReachedEventArgs();
142
143      if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
144      {
145         //here we send all data to user event handlers
146         _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
147      }
148   }
149
150 %}
151 %enddef
152
153 %define DALI_SCROLLBAR_EVENTHANDLER_PARAM( NameSpace, ClassName)
154   SCROLLBAR_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
155   SCROLLBAR_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
156 %enddef
157
158 namespace Dali
159 {
160   DALI_SCROLLBAR_EVENTHANDLER_PARAM( Dali::Toolkit, ScrollBar);
161 }
162