cc819cf243fd564c4367f0aebacecaa82219e4de
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / popup-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 POPUP_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 POPUP_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
29 %typemap(cscode) NameSpace::ClassName %{
30
31   public class OutsideTouchedEventArgs : EventArgs
32   {
33   }
34
35   public class ShowingEventArgs : EventArgs
36   {
37   }
38
39   public class ShownEventArgs : EventArgs
40   {
41   }
42
43   public class HidingEventArgs : EventArgs
44   {
45   }
46
47   public class HiddenEventArgs : EventArgs
48   {
49   }
50
51   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
52   public delegate void OutsideTouchedEventHandler(object source, OutsideTouchedEventArgs e);
53
54   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55   public delegate void ShowingEventHandler(object source, ShowingEventArgs e);
56
57   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
58   public delegate void ShownEventHandler(object source, ShownEventArgs e);
59
60   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
61   public delegate void HidingEventHandler(object source, HidingEventArgs e);
62
63   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
64   public delegate void HiddenEventHandler(object source, HiddenEventArgs e);
65
66   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
67   private delegate void OutsideTouchedEventCallbackDelegate();
68   private OutsideTouchedEventHandler _popUpOutsideTouchedEventHandler;
69   private OutsideTouchedEventCallbackDelegate _popUpOutsideTouchedEventCallbackDelegate;
70
71   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
72   private delegate void ShowingEventCallbackDelegate();
73   private ShowingEventHandler _popUpShowingEventHandler;
74   private ShowingEventCallbackDelegate _popUpShowingEventCallbackDelegate;
75
76   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
77   private delegate void ShownEventCallbackDelegate();
78   private ShownEventHandler _popUpShownEventHandler;
79   private ShownEventCallbackDelegate _popUpShownEventCallbackDelegate;
80
81   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
82   private delegate void HidingEventCallbackDelegate();
83   private HidingEventHandler _popUpHidingEventHandler;
84   private HidingEventCallbackDelegate _popUpHidingEventCallbackDelegate;
85
86   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
87   private delegate void HiddenEventCallbackDelegate();
88   private HiddenEventHandler _popUpHiddenEventHandler;
89   private HiddenEventCallbackDelegate _popUpHiddenEventCallbackDelegate;
90
91   public event OutsideTouchedEventHandler OutsideTouched
92   {
93      add
94      {
95         lock(this)
96         {
97            // Restricted to only one listener
98            if (_popUpOutsideTouchedEventHandler == null)
99            {
100               _popUpOutsideTouchedEventHandler += value;
101
102               _popUpOutsideTouchedEventCallbackDelegate = new OutsideTouchedEventCallbackDelegate(OnOutsideTouched);
103               this.OutsideTouchedSignal().Connect(_popUpOutsideTouchedEventCallbackDelegate);
104            }
105         }
106      }
107
108      remove
109      {
110         lock(this)
111         {
112            if (_popUpOutsideTouchedEventHandler != null)
113            {
114               this.OutsideTouchedSignal().Disconnect(_popUpOutsideTouchedEventCallbackDelegate);
115            }
116
117            _popUpOutsideTouchedEventHandler -= value;
118         }
119      }
120   }
121
122   // Callback for Popup OutsideTouchedSignal
123   private void OnOutsideTouched()
124   {
125      OutsideTouchedEventArgs e = new OutsideTouchedEventArgs();
126
127      if (_popUpOutsideTouchedEventHandler != null)
128      {
129         //here we send all data to user event handlers
130         _popUpOutsideTouchedEventHandler(this, e);
131      }
132   }
133
134   public event ShowingEventHandler Showing
135   {
136      add
137      {
138         lock(this)
139         {
140            // Restricted to only one listener
141            if (_popUpShowingEventHandler == null)
142            {
143               _popUpShowingEventHandler += value;
144
145               _popUpShowingEventCallbackDelegate = new ShowingEventCallbackDelegate(OnShowing);
146               this.ShowingSignal().Connect(_popUpShowingEventCallbackDelegate);
147            }
148         }
149      }
150
151      remove
152      {
153         lock(this)
154         {
155            if (_popUpShowingEventHandler != null)
156            {
157               this.ShowingSignal().Disconnect(_popUpShowingEventCallbackDelegate);
158            }
159
160            _popUpShowingEventHandler -= value;
161         }
162      }
163   }
164
165   // Callback for ShowingSignal
166   private void OnShowing()
167   {
168      ShowingEventArgs e = new ShowingEventArgs();
169
170      if (_popUpShowingEventHandler != null)
171      {
172         //here we send all data to user event handlers
173         _popUpShowingEventHandler(this, e);
174      }
175   }
176
177
178   public event ShownEventHandler Shown
179   {
180      add
181      {
182         lock(this)
183         {
184            // Restricted to only one listener
185            if (_popUpShownEventHandler == null)
186            {
187               _popUpShownEventHandler += value;
188
189               _popUpShownEventCallbackDelegate = new ShownEventCallbackDelegate(OnShown);
190               this.ShownSignal().Connect(_popUpShownEventCallbackDelegate);
191            }
192         }
193      }
194
195      remove
196      {
197         lock(this)
198         {
199            if (_popUpShownEventHandler != null)
200            {
201               this.ShownSignal().Disconnect(_popUpShownEventCallbackDelegate);
202            }
203
204            _popUpShownEventHandler -= value;
205         }
206      }
207   }
208
209   // Callback for ShownSignal
210   private void OnShown()
211   {
212      ShownEventArgs e = new ShownEventArgs();
213
214      if (_popUpShownEventHandler != null)
215      {
216         //here we send all data to user event handlers
217         _popUpShownEventHandler(this, e);
218      }
219   }
220
221   public event HidingEventHandler Hiding
222   {
223      add
224      {
225         lock(this)
226         {
227            // Restricted to only one listener
228            if (_popUpHidingEventHandler == null)
229            {
230               _popUpHidingEventHandler += value;
231
232               _popUpHidingEventCallbackDelegate = new HidingEventCallbackDelegate(OnHiding);
233               this.HidingSignal().Connect(_popUpHidingEventCallbackDelegate);
234            }
235         }
236      }
237
238      remove
239      {
240         lock(this)
241         {
242            if (_popUpHidingEventHandler != null)
243            {
244               this.HidingSignal().Disconnect(_popUpHidingEventCallbackDelegate);
245            }
246
247            _popUpHidingEventHandler -= value;
248         }
249      }
250   }
251
252   // Callback for HidingSignal
253   private void OnHiding()
254   {
255      HidingEventArgs e = new HidingEventArgs();
256
257      if (_popUpHidingEventHandler != null)
258      {
259         //here we send all data to user event handlers
260         _popUpHidingEventHandler(this, e);
261      }
262   }
263
264   public event HiddenEventHandler Hidden
265   {
266      add
267      {
268         lock(this)
269         {
270            // Restricted to only one listener
271            if (_popUpHiddenEventHandler == null)
272            {
273               _popUpHiddenEventHandler += value;
274
275               _popUpHiddenEventCallbackDelegate = new HiddenEventCallbackDelegate(OnHidden);
276               this.HiddenSignal().Connect(_popUpHiddenEventCallbackDelegate);
277            }
278         }
279      }
280
281      remove
282      {
283         lock(this)
284         {
285            if (_popUpHiddenEventHandler != null)
286            {
287               this.HiddenSignal().Disconnect(_popUpHiddenEventCallbackDelegate);
288            }
289
290            _popUpHiddenEventHandler -= value;
291         }
292      }
293   }
294
295   // Callback for HiddenSignal
296   private void OnHidden()
297   {
298      HiddenEventArgs e = new HiddenEventArgs();
299
300      if (_popUpHiddenEventHandler != null)
301      {
302         //here we send all data to user event handlers
303         _popUpHiddenEventHandler(this, e);
304      }
305   }
306 %}
307 %enddef
308
309 %define DALI_POPUP_EVENTHANDLER_PARAM( NameSpace, ClassName)
310   POPUP_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
311   POPUP_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
312 %enddef
313
314 namespace Dali
315 {
316   DALI_POPUP_EVENTHANDLER_PARAM( Dali::Toolkit, Popup);
317 }
318