Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WatchApplication.cs
1 /*
2  * Copyright (c) 2017 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 using System;
19 using System.Runtime.InteropServices;
20
21 namespace Tizen.NUI
22 {
23     internal class WatchApplication : Application
24     {
25
26         internal WatchApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
27         {
28         }
29
30         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WatchApplication obj)
31         {
32             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
33         }
34
35         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
36         {
37             Interop.Watch.delete_WatchApplication(swigCPtr);
38         }
39
40         private void DisConnectFromSignals()
41         {
42             if (_timeTickCallback != null)
43             {
44                 this.TimeTickSignal().Disconnect(_timeTickCallback);
45             }
46             if (_ambientTickCallback != null)
47             {
48                 this.AmbientTickSignal().Disconnect(_ambientTickCallback);
49             }
50             if (_ambientChangedCallback != null)
51             {
52                 this.AmbientChangedSignal().Disconnect(_ambientChangedCallback);
53             }
54         }
55
56         public static WatchApplication NewWatchApplication()
57         {
58             WatchApplication ret = New();
59             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60             // we've got an application now connect the signals
61             _instance = ret;
62             return ret;
63         }
64
65         public static WatchApplication NewWatchApplication(string[] args)
66         {
67             WatchApplication ret = New(args);
68             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69             _instance = ret;
70             return ret;
71         }
72
73         public static WatchApplication NewWatchApplication(string[] args, string stylesheet)
74         {
75             WatchApplication ret = New(args, stylesheet);
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77             _instance = ret;
78             return ret;
79         }
80
81         public new static WatchApplication New()
82         {
83             WatchApplication ret = new WatchApplication(Interop.Watch.WatchApplication_New__SWIG_0(), true);
84             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85             return ret;
86         }
87
88         public static WatchApplication New(string[] args)
89         {
90             int argc = args.Length;
91             string argvStr = string.Join(" ", args);
92
93             WatchApplication ret = new WatchApplication(Interop.Watch.WatchApplication_New__SWIG_1(argc, argvStr), true);
94             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95             return ret;
96         }
97
98         public static WatchApplication New(string[] args, string stylesheet)
99         {
100             int argc = args.Length;
101             string argvStr = string.Join(" ", args);
102
103             WatchApplication ret = new WatchApplication(Interop.Watch.WatchApplication_New__SWIG_2(argc, argvStr, stylesheet), true);
104             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105             return ret;
106         }
107
108         internal WatchApplication(WatchApplication implementation) : this(Interop.Watch.new_WatchApplication__SWIG_1(WatchApplication.getCPtr(implementation)), true)
109         {
110             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111         }
112
113         /// <summary>
114         /// Event arguments that passed via time tick event signal.
115         /// </summary>
116         /// <since_tizen> 4 </since_tizen>
117         public class TimeTickEventArgs : EventArgs
118         {
119             /// <summary>
120             /// Application.
121             /// </summary>
122             /// <since_tizen> 4 </since_tizen>
123             public Application Application
124             {
125                 get;
126                 set;
127             }
128
129             /// <summary>
130             /// WatchTime.
131             /// </summary>
132             /// <since_tizen> 4 </since_tizen>
133             public WatchTime WatchTime
134             {
135                 get;
136                 set;
137             }
138         }
139
140         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
141         private delegate void TimeTickCallbackType(IntPtr application, IntPtr watchTime);
142         private TimeTickCallbackType _timeTickCallback;
143         private DaliEventHandler<object, TimeTickEventArgs> _timeTickEventHandler;
144
145         /// <summary>
146         /// TimeTick event.
147         /// </summary>
148         public event DaliEventHandler<object, TimeTickEventArgs> TimeTick
149         {
150             add
151             {
152                 if (_timeTickEventHandler == null)
153                 {
154                     _timeTickCallback = new TimeTickCallbackType(OnTimeTick);
155                     TimeTickSignal().Connect(_timeTickCallback);
156                 }
157
158                 _timeTickEventHandler += value;
159             }
160
161             remove
162             {
163                 _timeTickEventHandler -= value;
164
165                 if (_timeTickEventHandler == null && TimeTickSignal().Empty() == false)
166                 {
167                     TimeTickSignal().Disconnect(_timeTickCallback);
168                 }
169             }
170         }
171
172         private void OnTimeTick(IntPtr application, IntPtr watchTime)
173         {
174             TimeTickEventArgs e = new TimeTickEventArgs();
175             e.Application = this;
176             e.WatchTime = WatchTime.GetWatchTimeFromPtr(watchTime);
177
178             _timeTickEventHandler?.Invoke(this, e);
179
180         }
181
182         internal WatchTimeSignal TimeTickSignal()
183         {
184             WatchTimeSignal ret = new WatchTimeSignal(Interop.Watch.WatchApplication_TimeTickSignal(swigCPtr), false);
185             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186             return ret;
187         }
188
189         /// <summary>
190         /// Event arguments that passed via ambient tick event signal.
191         /// </summary>
192         /// <since_tizen> 4 </since_tizen>
193         public class AmbientTickEventArgs : EventArgs
194         {
195             /// <summary>
196             /// Application.
197             /// </summary>
198             /// <since_tizen> 4 </since_tizen>
199             public Application Application
200             {
201                 get;
202                 set;
203             }
204
205             /// <summary>
206             /// WatchTime.
207             /// </summary>
208             /// <since_tizen> 4 </since_tizen>
209             public WatchTime WatchTime
210             {
211                 get;
212                 set;
213             }
214         }
215
216         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
217         private delegate void AmbientTickCallbackType(IntPtr application, IntPtr watchTime);
218         private AmbientTickCallbackType _ambientTickCallback;
219         private DaliEventHandler<object, AmbientTickEventArgs> _ambientTickEventHandler;
220
221         /// <summary>
222         /// AmbientTick event.
223         /// </summary>
224         public event DaliEventHandler<object, AmbientTickEventArgs> AmbientTick
225         {
226             add
227             {
228                 if (_ambientTickEventHandler == null)
229                 {
230                     _ambientTickCallback = new AmbientTickCallbackType(OnAmbientTick);
231                     AmbientTickSignal().Connect(_ambientTickCallback);
232                 }
233
234                 _ambientTickEventHandler += value;
235             }
236
237             remove
238             {
239                 _ambientTickEventHandler -= value;
240
241                 if (_ambientTickEventHandler == null && AmbientTickSignal().Empty() == false)
242                 {
243                     AmbientTickSignal().Disconnect(_ambientTickCallback);
244                 }
245             }
246         }
247
248         private void OnAmbientTick(IntPtr application, IntPtr watchTime)
249         {
250             AmbientTickEventArgs e = new AmbientTickEventArgs();
251
252             e.Application = this;
253             e.WatchTime = WatchTime.GetWatchTimeFromPtr(watchTime);
254             _ambientTickEventHandler?.Invoke(this, e);
255         }
256
257         internal WatchTimeSignal AmbientTickSignal()
258         {
259             WatchTimeSignal ret = new WatchTimeSignal(Interop.Watch.WatchApplication_AmbientTickSignal(swigCPtr), false);
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261             return ret;
262         }
263
264         /// <summary>
265         /// Event arguments that passed via ambient tick event signal.
266         /// </summary>
267         /// <since_tizen> 4 </since_tizen>
268         public class AmbientChangedEventArgs : EventArgs
269         {
270             /// <summary>
271             /// Application.
272             /// </summary>
273             /// <since_tizen> 4 </since_tizen>
274             public Application Application
275             {
276                 get;
277                 set;
278             }
279
280             /// <summary>
281             /// Changed.
282             /// </summary>
283             /// <since_tizen> 4 </since_tizen>
284             public bool Changed
285             {
286                 get;
287                 set;
288             }
289         }
290
291         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
292         private delegate void AmbientChangedCallbackType(IntPtr application, bool changed);
293         private AmbientChangedCallbackType _ambientChangedCallback;
294         private DaliEventHandler<object, AmbientChangedEventArgs> _ambientChangedEventHandler;
295
296         /// <summary>
297         /// AmbientChanged event.
298         /// </summary>
299         public event DaliEventHandler<object, AmbientChangedEventArgs> AmbientChanged
300         {
301             add
302             {
303                 if (_ambientChangedEventHandler == null)
304                 {
305                     _ambientChangedCallback = new AmbientChangedCallbackType(OnAmbientChanged);
306                     AmbientChangedSignal().Connect(_ambientChangedCallback);
307                 }
308
309                 _ambientChangedEventHandler += value;
310             }
311
312             remove
313             {
314                 _ambientChangedEventHandler -= value;
315
316                 if (_ambientChangedEventHandler == null && AmbientChangedSignal().Empty() == false)
317                 {
318                     AmbientChangedSignal().Disconnect(_ambientChangedCallback);
319                 }
320             }
321         }
322
323         private void OnAmbientChanged(IntPtr application, bool changed)
324         {
325             AmbientChangedEventArgs e = new AmbientChangedEventArgs();
326             e.Application = this;
327             e.Changed = changed;
328             _ambientChangedEventHandler?.Invoke(this, e);
329         }
330
331         internal WatchBoolSignal AmbientChangedSignal()
332         {
333             WatchBoolSignal ret = new WatchBoolSignal(Interop.Watch.WatchApplication_AmbientChangedSignal(swigCPtr), false);
334             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335             return ret;
336         }
337     }
338 }