Merge "Add missed parameter documentation" 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   public delegate void NotifyEventHandler(object source, NotifyEventArgs e);
58
59   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
60   private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
61   private NotifyEventHandler _propertyNotificationNotifyEventHandler;
62   private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate;
63
64   /**
65     * @brief Event for Notified signal which can be used to subscribe/unsubscribe the event handler
66     * (in the type of NotifyEventHandler) provided by the user.
67     * Notified signal is emitted when the notification upon a condition of the property being met, has occurred.
68     */
69   public event NotifyEventHandler Notified
70   {
71      add
72      {
73         lock(this)
74         {
75            // Restricted to only one listener
76            if (_propertyNotificationNotifyEventHandler == null)
77            {
78               _propertyNotificationNotifyEventHandler += value;
79
80               _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
81               this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate);
82            }
83         }
84      }
85
86      remove
87      {
88         lock(this)
89         {
90            if (_propertyNotificationNotifyEventHandler != null)
91            {
92               this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate);
93            }
94
95            _propertyNotificationNotifyEventHandler -= value;
96         }
97      }
98   }
99
100   // Callback for PropertyNotification NotifySignal
101   private void OnPropertyNotificationNotify(IntPtr propertyNotification)
102   {
103      NotifyEventArgs e = new NotifyEventArgs();
104      e.PropertyNotification  = GetPropertyNotificationFromPtr(propertyNotification);
105
106      if (_propertyNotificationNotifyEventHandler != null)
107      {
108         //here we send all data to user event handlers
109         _propertyNotificationNotifyEventHandler(this, e);
110      }
111   }
112
113   public static ClassName Get ## ClassName ## FromPtr(global::System.IntPtr cPtr) {
114     ClassName ret = new ClassName(cPtr, false);
115    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116     return ret;
117   }
118
119 %}
120 %enddef
121
122 %define DALI_PROPERTYNOTIFICATION_EVENTHANDLER_PARAM( NameSpace, ClassName)
123   PROPERTYNOTIFICATION_EVENTHANDLER_TYPEMAP_EVENTARG( NameSpace, ClassName);
124   PROPERTYNOTIFICATION_EVENTHANDLER_TYPEMAP_HELPER( NameSpace, ClassName);
125 %enddef
126
127 namespace Dali
128 {
129   DALI_PROPERTYNOTIFICATION_EVENTHANDLER_PARAM( Dali, PropertyNotification);
130 }
131