d084ca14ea822e9009e0e1f1766506ffe0d8bb57
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / PropertyNotification.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22
23
24     internal class PropertyNotification : BaseHandle
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PropertyNotification_SWIGUpcast(cPtr), cMemoryOwn)
29         {
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyNotification obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         protected override void Dispose(DisposeTypes type)
39         {
40             if (disposed)
41             {
42                 return;
43             }
44
45             if (type == DisposeTypes.Explicit)
46             {
47                 //Called by User
48                 //Release your own managed resources here.
49                 //You should release all of your own disposable objects here.
50
51             }
52
53             //Release your own unmanaged resources here.
54             //You should not access any managed member here except static instance.
55             //because the execution order of Finalizes is non-deterministic.
56
57             if (swigCPtr.Handle != global::System.IntPtr.Zero)
58             {
59                 if (swigCMemOwn)
60                 {
61                     swigCMemOwn = false;
62                     NDalicPINVOKE.delete_PropertyNotification(swigCPtr);
63                 }
64                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
65             }
66
67             base.Dispose(type);
68         }
69
70         /**
71           * @brief Event arguments that passed via Notify signal
72           *
73           */
74         public class NotifyEventArgs : EventArgs
75         {
76             private PropertyNotification _propertyNotification;
77
78             /**
79               * @brief PropertyNotification - is the PropertyNotification handle that has the notification properties.
80               *
81               */
82             public PropertyNotification PropertyNotification
83             {
84                 get
85                 {
86                     return _propertyNotification;
87                 }
88                 set
89                 {
90                     _propertyNotification = value;
91                 }
92             }
93         }
94
95         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
96         private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
97         private DaliEventHandler<object, NotifyEventArgs> _propertyNotificationNotifyEventHandler;
98         private NotifyEventCallbackDelegate _propertyNotificationNotifyEventCallbackDelegate;
99
100         /**
101           * @brief Event for Notified signal which can be used to subscribe/unsubscribe the event handler
102           * (in the type of NotifyEventHandler-DaliEventHandler<object,NotifyEventArgs>) provided by the user.
103           * Notified signal is emitted when the notification upon a condition of the property being met, has occurred.
104           */
105         public event DaliEventHandler<object, NotifyEventArgs> Notified
106         {
107             add
108             {
109                 lock (this)
110                 {
111                     // Restricted to only one listener
112                     if (_propertyNotificationNotifyEventHandler == null)
113                     {
114                         _propertyNotificationNotifyEventHandler += value;
115
116                         _propertyNotificationNotifyEventCallbackDelegate = new NotifyEventCallbackDelegate(OnPropertyNotificationNotify);
117                         this.NotifySignal().Connect(_propertyNotificationNotifyEventCallbackDelegate);
118                     }
119                 }
120             }
121
122             remove
123             {
124                 lock (this)
125                 {
126                     if (_propertyNotificationNotifyEventHandler != null)
127                     {
128                         this.NotifySignal().Disconnect(_propertyNotificationNotifyEventCallbackDelegate);
129                     }
130
131                     _propertyNotificationNotifyEventHandler -= value;
132                 }
133             }
134         }
135
136         // Callback for PropertyNotification NotifySignal
137         private void OnPropertyNotificationNotify(IntPtr propertyNotification)
138         {
139             NotifyEventArgs e = new NotifyEventArgs();
140             e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
141
142             if (_propertyNotificationNotifyEventHandler != null)
143             {
144                 //here we send all data to user event handlers
145                 _propertyNotificationNotifyEventHandler(this, e);
146             }
147         }
148
149         public static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
150         {
151             PropertyNotification ret = new PropertyNotification(cPtr, false);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153             return ret;
154         }
155
156
157         public PropertyNotification() : this(NDalicPINVOKE.new_PropertyNotification__SWIG_0(), true)
158         {
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160         }
161
162         public static PropertyNotification DownCast(BaseHandle handle)
163         {
164             PropertyNotification ret = new PropertyNotification(NDalicPINVOKE.PropertyNotification_DownCast(BaseHandle.getCPtr(handle)), true);
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166             return ret;
167         }
168
169         public PropertyNotification(PropertyNotification handle) : this(NDalicPINVOKE.new_PropertyNotification__SWIG_1(PropertyNotification.getCPtr(handle)), true)
170         {
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172         }
173
174         public PropertyNotification Assign(PropertyNotification rhs)
175         {
176             PropertyNotification ret = new PropertyNotification(NDalicPINVOKE.PropertyNotification_Assign(swigCPtr, PropertyNotification.getCPtr(rhs)), false);
177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178             return ret;
179         }
180
181         public PropertyCondition GetCondition()
182         {
183             PropertyCondition ret = new PropertyCondition(NDalicPINVOKE.PropertyNotification_GetCondition__SWIG_0(swigCPtr), true);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187
188         public Animatable GetTarget()
189         {
190             Animatable ret = new Animatable(NDalicPINVOKE.PropertyNotification_GetTarget(swigCPtr), true);
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192             return ret;
193         }
194
195         public int GetTargetProperty()
196         {
197             int ret = NDalicPINVOKE.PropertyNotification_GetTargetProperty(swigCPtr);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         public void SetNotifyMode(PropertyNotification.NotifyMode mode)
203         {
204             NDalicPINVOKE.PropertyNotification_SetNotifyMode(swigCPtr, (int)mode);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206         }
207
208         public PropertyNotification.NotifyMode GetNotifyMode()
209         {
210             PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)NDalicPINVOKE.PropertyNotification_GetNotifyMode(swigCPtr);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         public bool GetNotifyResult()
216         {
217             bool ret = NDalicPINVOKE.PropertyNotification_GetNotifyResult(swigCPtr);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             return ret;
220         }
221
222         public PropertyNotifySignal NotifySignal()
223         {
224             PropertyNotifySignal ret = new PropertyNotifySignal(NDalicPINVOKE.PropertyNotification_NotifySignal(swigCPtr), false);
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229         public enum NotifyMode
230         {
231             Disabled,
232             NotifyOnTrue,
233             NotifyOnFalse,
234             NotifyOnChanged
235         }
236
237     }
238
239 }