d70708a89614f7ea19616040caf4e609f9f42fb2
[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   private delegate void LayoutActivatedEventCallbackDelegate();
36   private DaliEventHandler<object,LayoutActivatedEventArgs> _itemViewLayoutActivatedEventHandler;
37   private LayoutActivatedEventCallbackDelegate _itemViewLayoutActivatedEventCallbackDelegate;
38
39   public event DaliEventHandler<object,LayoutActivatedEventArgs> LayoutActivated
40   {
41      add
42      {
43         lock(this)
44         {
45            // Restricted to only one listener
46            if (_itemViewLayoutActivatedEventHandler == null)
47            {
48               _itemViewLayoutActivatedEventHandler += value;
49
50               _itemViewLayoutActivatedEventCallbackDelegate = new LayoutActivatedEventCallbackDelegate(OnLayoutActivated);
51               this.LayoutActivatedSignal().Connect(_itemViewLayoutActivatedEventCallbackDelegate);
52            }
53         }
54      }
55
56      remove
57      {
58         lock(this)
59         {
60            if (_itemViewLayoutActivatedEventHandler != null)
61            {
62               this.LayoutActivatedSignal().Disconnect(_itemViewLayoutActivatedEventCallbackDelegate);
63            }
64
65            _itemViewLayoutActivatedEventHandler -= value;
66         }
67      }
68   }
69
70   // Callback for ItemView LayoutActivatedSignal
71   private void OnLayoutActivated()
72   {
73      LayoutActivatedEventArgs e = new LayoutActivatedEventArgs();
74
75      if (_itemViewLayoutActivatedEventHandler != null)
76      {
77         //here we send all data to user event handlers
78         _itemViewLayoutActivatedEventHandler(this, e);
79      }
80   }
81
82 %}
83 %enddef
84
85 %define DALI_ITEMVIEW_EVENTHANDLER_PARAM( NameSpace, ClassName)
86   ITEMVIEW_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
87   ITEMVIEW_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
88 %enddef
89
90 namespace Dali
91 {
92   DALI_ITEMVIEW_EVENTHANDLER_PARAM( Dali::Toolkit, ItemView);
93 }
94