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