608bbffab0043d306120f3bdce9ffce9b3639ebb
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / itemview-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 ITEMVIEW_EVENTHANDLER_TYPEMAP_EVENTARG(NameSpace, ClassName)
19 %typemap(csimports) NameSpace::ClassName %{
20 using System;
21 using System.Runtime.InteropServices;
22
23 %}
24 %enddef
25
26
27 %define ITEMVIEW_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
28 %typemap(cscode) NameSpace::ClassName %{
29
30   public class LayoutActivatedEventArgs : EventArgs
31   {
32   }
33
34   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
35   public delegate void LayoutActivatedEventHandler(object source, LayoutActivatedEventArgs e);
36
37   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
38   private delegate void LayoutActivatedEventCallbackDelegate();
39   private LayoutActivatedEventHandler _itemViewLayoutActivatedEventHandler;
40   private LayoutActivatedEventCallbackDelegate _itemViewLayoutActivatedEventCallbackDelegate;
41
42   public event LayoutActivatedEventHandler LayoutActivated
43   {
44      add
45      {
46         lock(this)
47         {
48            // Restricted to only one listener
49            if (_itemViewLayoutActivatedEventHandler == null)
50            {
51               _itemViewLayoutActivatedEventHandler += value;
52
53               _itemViewLayoutActivatedEventCallbackDelegate = new LayoutActivatedEventCallbackDelegate(OnLayoutActivated);
54               this.LayoutActivatedSignal().Connect(_itemViewLayoutActivatedEventCallbackDelegate);
55            }
56         }
57      }
58
59      remove
60      {
61         lock(this)
62         {
63            if (_itemViewLayoutActivatedEventHandler != null)
64            {
65               this.LayoutActivatedSignal().Disconnect(_itemViewLayoutActivatedEventCallbackDelegate);
66            }
67
68            _itemViewLayoutActivatedEventHandler -= value;
69         }
70      }
71   }
72
73   // Callback for ItemView LayoutActivatedSignal
74   private void OnLayoutActivated()
75   {
76      LayoutActivatedEventArgs e = new LayoutActivatedEventArgs();
77
78      if (_itemViewLayoutActivatedEventHandler != null)
79      {
80         //here we send all data to user event handlers
81         _itemViewLayoutActivatedEventHandler(this, e);
82      }
83   }
84
85 %}
86 %enddef
87
88 %define DALI_ITEMVIEW_EVENTHANDLER_PARAM( NameSpace, ClassName)
89   ITEMVIEW_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
90   ITEMVIEW_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
91 %enddef
92
93 namespace Dali
94 {
95   DALI_ITEMVIEW_EVENTHANDLER_PARAM( Dali::Toolkit, ItemView);
96 }
97