Merge "Move Event Handlers to View class" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / SWIG / events / propertynotification-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 PROPERTYNOTIFICATION_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 PROPERTYNOTIFICATION_EVENTHANDLER_TYPEMAP_HELPER(NameSpace, ClassName)
29 %typemap(cscode) NameSpace::ClassName %{
30
31 /**
32   * @brief Event arguments that passed via Notify signal
33   *
34   */
35 public class NotifyEventArgs : EventArgs
36 {
37    private PropertyNotification _propertyNotification;
38
39    /**
40      * @brief PropertyNotification - is the PropertyNotification handle that has the notification properties.
41      *
42      */
43    public PropertyNotification PropertyNotification
44    {
45       get
46       {
47          return _propertyNotification;
48       }
49       set
50       {
51          _propertyNotification = value;
52       }
53    }
54 }
55
56   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
57   private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
58   private DaliEventHandler<object,NotifyEventArgs> _propertyNotificationNotifyEventHandler;
59   private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate;
60
61   /**
62     * @brief Event for Notified signal which can be used to subscribe/unsubscribe the event handler
63     * (in the type of NotifyEventHandler-DaliEventHandler<object,NotifyEventArgs>) provided by the user.
64     * Notified signal is emitted when the notification upon a condition of the property being met, has occurred.
65     */
66   public event DaliEventHandler<object,NotifyEventArgs> Notified
67   {
68      add
69      {
70         lock(this)
71         {
72            // Restricted to only one listener
73            if (_propertyNotificationNotifyEventHandler == null)
74            {
75               _propertyNotificationNotifyEventHandler += value;
76
77               _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
78               this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate);
79            }
80         }
81      }
82
83      remove
84      {
85         lock(this)
86         {
87            if (_propertyNotificationNotifyEventHandler != null)
88            {
89               this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate);
90            }
91
92            _propertyNotificationNotifyEventHandler -= value;
93         }
94      }
95   }
96
97   // Callback for PropertyNotification NotifySignal
98   private void OnPropertyNotificationNotify(IntPtr propertyNotification)
99   {
100      NotifyEventArgs e = new NotifyEventArgs();
101      e.PropertyNotification  = GetPropertyNotificationFromPtr(propertyNotification);
102
103      if (_propertyNotificationNotifyEventHandler != null)
104      {
105         //here we send all data to user event handlers
106         _propertyNotificationNotifyEventHandler(this, e);
107      }
108   }
109
110   public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
111     ClassName ret = new ClassName(cPtr, false);
112    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113     return ret;
114   }
115
116 %}
117 %enddef
118
119 %define DALI_PROPERTYNOTIFICATION_EVENTHANDLER_PARAM( NameSpace, ClassName)
120   PROPERTYNOTIFICATION_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
121   PROPERTYNOTIFICATION_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
122 %enddef
123
124 namespace Dali
125 {
126   DALI_PROPERTYNOTIFICATION_EVENTHANDLER_PARAM( Dali, PropertyNotification);
127 }
128