6901a2479f38b488bed775c93fe07e274359f324
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Application / Application.cs
1 /*
2  * Copyright(c) 2022 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 using System;
18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
20 using System.ComponentModel;
21 using System.Diagnostics;
22 using System.Runtime.InteropServices;
23 using Tizen.NUI.Binding;
24
25 namespace Tizen.NUI
26 {
27     /**
28       * @brief Event arguments that passed via NUIApplicationInit signal
29       */
30     internal class NUIApplicationInitEventArgs : EventArgs
31     {
32         private Application application;
33
34         /**
35           * @brief Application - is the application that is being initialized
36           */
37         public Application Application
38         {
39             get
40             {
41                 return application;
42             }
43             set
44             {
45                 application = value;
46             }
47         }
48     }
49
50     /**
51       * @brief Event arguments that passed via NUIApplicationTerminate signal
52       */
53     internal class NUIApplicationTerminatingEventArgs : EventArgs
54     {
55         private Application application;
56         /**
57           * @brief Application - is the application that is being Terminated
58           */
59         public Application Application
60         {
61             get
62             {
63                 return application;
64             }
65             set
66             {
67                 application = value;
68             }
69         }
70     }
71
72     /**
73       * @brief Event arguments that passed via NUIApplicationPause signal
74       */
75     internal class NUIApplicationPausedEventArgs : EventArgs
76     {
77         private Application application;
78         /**
79           * @brief Application - is the application that is being Paused
80           */
81         public Application Application
82         {
83             get
84             {
85                 return application;
86             }
87             set
88             {
89                 application = value;
90             }
91         }
92     }
93
94     /**
95       * @brief Event arguments that passed via NUIApplicationResume signal
96       */
97     internal class NUIApplicationResumedEventArgs : EventArgs
98     {
99         private Application application;
100         /**
101           * @brief Application - is the application that is being Resumed
102           */
103         public Application Application
104         {
105             get
106             {
107                 return application;
108             }
109             set
110             {
111                 application = value;
112             }
113         }
114     }
115
116     /**
117       * @brief Event arguments that passed via NUIApplicationReset signal
118       */
119     internal class NUIApplicationResetEventArgs : EventArgs
120     {
121         private Application application;
122         /**
123           * @brief Application - is the application that is being Reset
124           */
125         public Application Application
126         {
127             get
128             {
129                 return application;
130             }
131             set
132             {
133                 application = value;
134             }
135         }
136     }
137
138     /**
139       * @brief Event arguments that passed via NUIApplicationLanguageChanged signal
140       */
141     internal class NUIApplicationLanguageChangedEventArgs : EventArgs
142     {
143         private Application application;
144         /**
145           * @brief Application - is the application that is being affected with Device's language change
146           */
147         public Application Application
148         {
149             get
150             {
151                 return application;
152             }
153             set
154             {
155                 application = value;
156             }
157         }
158     }
159
160     /**
161       * @brief Event arguments that passed via NUIApplicationRegionChanged signal
162       */
163     internal class NUIApplicationRegionChangedEventArgs : EventArgs
164     {
165         private Application application;
166         /**
167           * @brief Application - is the application that is being affected with Device's region change
168           */
169         public Application Application
170         {
171             get
172             {
173                 return application;
174             }
175             set
176             {
177                 application = value;
178             }
179         }
180     }
181
182     /**
183       * @brief Event arguments that passed via NUIApplicationBatteryLow signal
184       */
185     internal class NUIApplicationBatteryLowEventArgs : EventArgs
186     {
187         private Application.BatteryStatus status;
188         /**
189           * @brief Application - is the application that is being affected when the battery level of the device is low
190           */
191         public Application.BatteryStatus BatteryStatus
192         {
193             get
194             {
195                 return status;
196             }
197             set
198             {
199                 status = value;
200             }
201         }
202     }
203
204     /**
205       * @brief Event arguments that passed via NUIApplicationMemoryLow signal
206       */
207     internal class NUIApplicationMemoryLowEventArgs : EventArgs
208     {
209         private Application.MemoryStatus status;
210         /**
211           * @brief Application - is the application that is being affected when the memory level of the device is low
212           */
213         public Application.MemoryStatus MemoryStatus
214         {
215             get
216             {
217                 return status;
218             }
219             set
220             {
221                 status = value;
222             }
223         }
224     }
225
226     /**
227       * @brief Event arguments that passed via NUIApplicationAppControl  signal
228       */
229     internal class NUIApplicationAppControlEventArgs : EventArgs
230     {
231         private Application application;
232         private IntPtr voidp;
233         /**
234           * @brief Application - is the application that is receiving the launch request from another application
235           */
236         public Application Application
237         {
238             get
239             {
240                 return application;
241             }
242             set
243             {
244                 application = value;
245             }
246         }
247         /**
248           * @brief VoidP - contains the information about why the application is launched
249           */
250         public IntPtr VoidP
251         {
252             get
253             {
254                 return voidp;
255             }
256             set
257             {
258                 voidp = value;
259             }
260         }
261     }
262
263     /// <summary>
264     /// A class to get resources in current application.
265     /// </summary>
266     public sealed class GetResourcesProvider
267     {
268         /// <summary>
269         /// Get resources in current application.
270         /// </summary>
271         static public IResourcesProvider Get()
272         {
273             return Tizen.NUI.Application.Current;
274         }
275     }
276
277     internal class Application : BaseHandle, IResourcesProvider, IElementConfiguration<Application>
278     {
279         static Application s_current;
280
281         ReadOnlyCollection<Element> logicalChildren;
282
283         [EditorBrowsable(EditorBrowsableState.Never)]
284         public static void SetCurrentApplication(Application value) => Current = value;
285
286         public static Application Current
287         {
288             get { return s_current; }
289             set
290             {
291                 if (s_current == value)
292                     return;
293                 s_current = value;
294             }
295         }
296
297         internal override ReadOnlyCollection<Element> LogicalChildrenInternal
298         {
299             get { return logicalChildren ?? (logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
300         }
301
302         internal IResourceDictionary SystemResources { get; }
303
304         ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
305
306         ResourceDictionary resources;
307         public bool IsResourcesCreated => resources != null;
308
309         public delegate void resChangeCb(object sender, ResourcesChangedEventArgs e);
310
311         internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
312         {
313             base.OnResourcesChanged(sender, e);
314         }
315
316         public ResourceDictionary XamlResources
317         {
318             get
319             {
320                 if (resources == null)
321                 {
322                     resources = new ResourceDictionary();
323                     int hashCode = resources.GetHashCode();
324                     ((IResourceDictionary)resources).ValuesChanged += OnResourcesChanged;
325                 }
326                 return resources;
327             }
328             set
329             {
330                 if (resources == value)
331                     return;
332                 OnPropertyChanging();
333
334                 if (resources != null)
335                     ((IResourceDictionary)resources).ValuesChanged -= OnResourcesChanged;
336                 resources = value;
337                 OnResourcesChanged(value);
338                 if (resources != null)
339                     ((IResourceDictionary)resources).ValuesChanged += OnResourcesChanged;
340
341                 OnPropertyChanged();
342             }
343         }
344
345         protected override void OnParentSet()
346         {
347             throw new InvalidOperationException("Setting a Parent on Application is invalid.");
348         }
349
350         [EditorBrowsable(EditorBrowsableState.Never)]
351         public static bool IsApplicationOrNull(Element element)
352         {
353             return element == null || element is Application;
354         }
355
356         internal override void OnParentResourcesChanged(IEnumerable<KeyValuePair<string, object>> values)
357         {
358             if (values == null)
359                 return;
360
361             if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
362             {
363                 base.OnParentResourcesChanged(values);
364                 return;
365             }
366
367             var innerKeys = new HashSet<string>();
368             var changedResources = new List<KeyValuePair<string, object>>();
369             foreach (KeyValuePair<string, object> c in XamlResources)
370                 innerKeys.Add(c.Key);
371             foreach (KeyValuePair<string, object> value in values)
372             {
373                 if (innerKeys.Add(value.Key))
374                     changedResources.Add(value);
375             }
376             if (changedResources.Count != 0)
377                 OnResourcesChanged(changedResources);
378         }
379
380         internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
381         {
382             SetCurrentApplication(this);
383             s_current = this;
384         }
385
386         protected override void Dispose(DisposeTypes type)
387         {
388             if (disposed)
389             {
390                 return;
391             }
392
393             //Release your own unmanaged resources here.
394             //You should not access any managed member here except static instance.
395             //because the execution order of Finalizes is non-deterministic.
396             if (applicationInitEventCallbackDelegate != null)
397             {
398                 initSignal?.Disconnect(applicationInitEventCallbackDelegate);
399                 initSignal?.Dispose();
400                 initSignal = null;
401             }
402
403             if (applicationTerminateEventCallbackDelegate != null)
404             {
405                 terminateSignal?.Disconnect(applicationTerminateEventCallbackDelegate);
406                 terminateSignal?.Dispose();
407                 terminateSignal = null;
408             }
409
410             if (applicationPauseEventCallbackDelegate != null)
411             {
412                 pauseSignal?.Disconnect(applicationPauseEventCallbackDelegate);
413                 pauseSignal?.Dispose();
414                 pauseSignal = null;
415             }
416
417             if (applicationResumeEventCallbackDelegate != null)
418             {
419                 resumeSignal?.Disconnect(applicationResumeEventCallbackDelegate);
420                 resumeSignal?.Dispose();
421                 resumeSignal = null;
422             }
423
424             if (applicationResetEventCallbackDelegate != null)
425             {
426                 resetSignal?.Disconnect(applicationResetEventCallbackDelegate);
427                 resetSignal?.Dispose();
428                 resetSignal = null;
429             }
430
431             if (applicationLanguageChangedEventCallbackDelegate != null)
432             {
433                 languageChangedSignal?.Disconnect(applicationLanguageChangedEventCallbackDelegate);
434                 languageChangedSignal?.Dispose();
435                 languageChangedSignal = null;
436             }
437
438             if (applicationRegionChangedEventCallbackDelegate != null)
439             {
440                 regionChangedSignal?.Disconnect(applicationRegionChangedEventCallbackDelegate);
441                 regionChangedSignal?.Dispose();
442                 regionChangedSignal = null;
443             }
444
445             if (applicationBatteryLowEventCallbackDelegate != null)
446             {
447                 batteryLowSignal?.Disconnect(applicationBatteryLowEventCallbackDelegate);
448                 batteryLowSignal?.Dispose();
449                 batteryLowSignal = null;
450             }
451
452             if (applicationMemoryLowEventCallbackDelegate != null)
453             {
454                 memoryLowSignal?.Disconnect(applicationMemoryLowEventCallbackDelegate);
455                 memoryLowSignal?.Dispose();
456                 memoryLowSignal = null;
457             }
458
459             if (applicationAppControlEventCallbackDelegate != null)
460             {
461                 appControlSignal?.Disconnect(applicationAppControlEventCallbackDelegate);
462                 appControlSignal?.Dispose();
463                 appControlSignal = null;
464             }
465
466             //Task
467             if (applicationTaskInitEventCallbackDelegate != null)
468             {
469                 taskInitSignal?.Disconnect(applicationTaskInitEventCallbackDelegate);
470                 taskInitSignal?.Dispose();
471                 taskInitSignal = null;
472             }
473
474             if (applicationTaskTerminateEventCallbackDelegate != null)
475             {
476                 taskTerminateSignal?.Disconnect(applicationTaskTerminateEventCallbackDelegate);
477                 taskTerminateSignal?.Dispose();
478                 taskTerminateSignal = null;
479             }
480
481             if (applicationTaskLanguageChangedEventCallbackDelegate != null)
482             {
483                 taskLanguageChangedSignal?.Disconnect(applicationTaskLanguageChangedEventCallbackDelegate);
484                 taskLanguageChangedSignal?.Dispose();
485                 taskLanguageChangedSignal = null;
486             }
487
488             if (applicationTaskRegionChangedEventCallbackDelegate != null)
489             {
490                 taskRegionChangedSignal?.Disconnect(applicationTaskRegionChangedEventCallbackDelegate);
491                 taskRegionChangedSignal?.Dispose();
492                 taskRegionChangedSignal = null;
493             }
494
495             if (applicationTaskBatteryLowEventCallbackDelegate != null)
496             {
497                 taskBatteryLowSignal?.Disconnect(applicationTaskBatteryLowEventCallbackDelegate);
498                 taskBatteryLowSignal?.Dispose();
499                 taskBatteryLowSignal = null;
500             }
501
502             if (applicationTaskMemoryLowEventCallbackDelegate != null)
503             {
504                 taskMemoryLowSignal?.Disconnect(applicationTaskMemoryLowEventCallbackDelegate);
505                 taskMemoryLowSignal?.Dispose();
506                 taskMemoryLowSignal = null;
507             }
508
509             if (applicationTaskAppControlEventCallbackDelegate != null)
510             {
511                 taskAppControlSignal?.Disconnect(applicationTaskAppControlEventCallbackDelegate);
512                 taskAppControlSignal?.Dispose();
513                 taskAppControlSignal = null;
514             }
515
516             window?.Dispose();
517             window = null;
518
519             base.Dispose(type);
520         }
521         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
522         {
523             Interop.Application.DeleteApplication(swigCPtr);
524         }
525
526         public enum BatteryStatus
527         {
528             Normal,
529             CriticallyLow,
530             PowerOff
531         };
532
533         public enum MemoryStatus
534         {
535             Normal,
536             Low,
537             CriticallyLow
538         };
539
540         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
541         private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
542         private DaliEventHandler<object, NUIApplicationInitEventArgs> applicationInitEventHandler;
543         private NUIApplicationInitEventCallbackDelegate applicationInitEventCallbackDelegate;
544         private ApplicationSignal initSignal;
545
546         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
547         private delegate void NUIApplicationTerminateEventCallbackDelegate(IntPtr application);
548         private DaliEventHandler<object, NUIApplicationTerminatingEventArgs> applicationTerminateEventHandler;
549         private NUIApplicationTerminateEventCallbackDelegate applicationTerminateEventCallbackDelegate;
550         private ApplicationSignal terminateSignal;
551
552         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
553         private delegate void NUIApplicationPauseEventCallbackDelegate(IntPtr application);
554         private DaliEventHandler<object, NUIApplicationPausedEventArgs> applicationPauseEventHandler;
555         private NUIApplicationPauseEventCallbackDelegate applicationPauseEventCallbackDelegate;
556         private ApplicationSignal pauseSignal;
557
558         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
559         private delegate void NUIApplicationResumeEventCallbackDelegate(IntPtr application);
560         private DaliEventHandler<object, NUIApplicationResumedEventArgs> applicationResumeEventHandler;
561         private NUIApplicationResumeEventCallbackDelegate applicationResumeEventCallbackDelegate;
562         private ApplicationSignal resumeSignal;
563
564         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
565         private delegate void NUIApplicationResetEventCallbackDelegate(IntPtr application);
566         private DaliEventHandler<object, NUIApplicationResetEventArgs> applicationResetEventHandler;
567         private NUIApplicationResetEventCallbackDelegate applicationResetEventCallbackDelegate;
568         private ApplicationSignal resetSignal;
569
570         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
571         private delegate void NUIApplicationLanguageChangedEventCallbackDelegate(IntPtr application);
572         private DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> applicationLanguageChangedEventHandler;
573         private NUIApplicationLanguageChangedEventCallbackDelegate applicationLanguageChangedEventCallbackDelegate;
574         private ApplicationSignal languageChangedSignal;
575
576
577         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
578         private delegate void NUIApplicationRegionChangedEventCallbackDelegate(IntPtr application);
579         private DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> applicationRegionChangedEventHandler;
580         private NUIApplicationRegionChangedEventCallbackDelegate applicationRegionChangedEventCallbackDelegate;
581         private ApplicationSignal regionChangedSignal;
582
583         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
584         private delegate void NUIApplicationBatteryLowEventCallbackDelegate(BatteryStatus status);
585         private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> applicationBatteryLowEventHandler;
586         private NUIApplicationBatteryLowEventCallbackDelegate applicationBatteryLowEventCallbackDelegate;
587         private LowBatterySignalType batteryLowSignal;
588
589         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
590         private delegate void NUIApplicationMemoryLowEventCallbackDelegate(MemoryStatus status);
591         private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> applicationMemoryLowEventHandler;
592         private NUIApplicationMemoryLowEventCallbackDelegate applicationMemoryLowEventCallbackDelegate;
593         private LowMemorySignalType memoryLowSignal;
594
595         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
596         private delegate void NUIApplicationAppControlEventCallbackDelegate(IntPtr application, IntPtr voidp);
597         private DaliEventHandler<object, NUIApplicationAppControlEventArgs> applicationAppControlEventHandler;
598         private NUIApplicationAppControlEventCallbackDelegate applicationAppControlEventCallbackDelegate;
599         private ApplicationControlSignal appControlSignal;
600
601         private DaliEventHandler<object, NUIApplicationInitEventArgs> applicationTaskInitEventHandler;
602         private NUIApplicationInitEventCallbackDelegate applicationTaskInitEventCallbackDelegate;
603         private ApplicationSignal taskInitSignal;
604
605         private DaliEventHandler<object, NUIApplicationTerminatingEventArgs> applicationTaskTerminateEventHandler;
606         private NUIApplicationTerminateEventCallbackDelegate applicationTaskTerminateEventCallbackDelegate;
607         private ApplicationSignal taskTerminateSignal;
608
609         private DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> applicationTaskLanguageChangedEventHandler;
610         private NUIApplicationLanguageChangedEventCallbackDelegate applicationTaskLanguageChangedEventCallbackDelegate;
611         private ApplicationSignal taskLanguageChangedSignal;
612
613         private DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> applicationTaskRegionChangedEventHandler;
614         private NUIApplicationRegionChangedEventCallbackDelegate applicationTaskRegionChangedEventCallbackDelegate;
615         private ApplicationSignal taskRegionChangedSignal;
616
617         private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> applicationTaskBatteryLowEventHandler;
618         private NUIApplicationBatteryLowEventCallbackDelegate applicationTaskBatteryLowEventCallbackDelegate;
619         private LowBatterySignalType taskBatteryLowSignal;
620
621         private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> applicationTaskMemoryLowEventHandler;
622         private NUIApplicationMemoryLowEventCallbackDelegate applicationTaskMemoryLowEventCallbackDelegate;
623         private LowMemorySignalType taskMemoryLowSignal;
624
625         private DaliEventHandler<object, NUIApplicationAppControlEventArgs> applicationTaskAppControlEventHandler;
626         private NUIApplicationAppControlEventCallbackDelegate applicationTaskAppControlEventCallbackDelegate;
627         private ApplicationControlSignal taskAppControlSignal;
628
629         private Window window;
630
631         /**
632           * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
633           *  provided by the user. Initialized signal is emitted when application is initialized
634           */
635         public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
636         {
637             add
638             {
639                 // Restricted to only one listener
640                 if (applicationInitEventHandler == null)
641                 {
642                     applicationInitEventHandler += value;
643                     applicationInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationInit);
644                     initSignal = this.InitSignal();
645                     initSignal?.Connect(applicationInitEventCallbackDelegate);
646                 }
647             }
648
649             remove
650             {
651                 if (applicationInitEventHandler != null)
652                 {
653                     initSignal?.Disconnect(applicationInitEventCallbackDelegate);
654                     initSignal?.Dispose();
655                     initSignal = null;
656                 }
657
658                 applicationInitEventHandler -= value;
659             }
660         }
661
662         // Callback for Application InitSignal
663         private void OnApplicationInit(IntPtr data)
664         {
665             Log.Info("NUI", "[NUI] OnApplicationInit: DisposeQueue Initialize");
666             Tizen.Tracer.Begin("[NUI] OnApplicationInit: DisposeQueue Initialize");
667             // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
668             DisposeQueue.Instance.Initialize();
669             Tizen.Tracer.End();
670
671             Log.Info("NUI", "[NUI] OnApplicationInit: GetWindow");
672             Tizen.Tracer.Begin("[NUI] OnApplicationInit: GetWindow");
673             Window.Instance = GetWindow();
674 #if !PROFILE_TV
675             _ = FocusManager.Instance;
676 #endif
677             Tizen.Tracer.End();
678
679             Log.Info("NUI", "[NUI] OnApplicationInit: Window Show");
680             Tizen.Tracer.Begin("[NUI] OnApplicationInit: Window Show");
681             // Notify that the window is displayed to the app core.
682             if (NUIApplication.IsPreload)
683             {
684                 Window.Instance.Show();
685             }
686             Tizen.Tracer.End();
687
688             Log.Info("NUI", "[NUI] OnApplicationInit: applicationInitEventHandler Invoke");
689             Tizen.Tracer.Begin("[NUI] OnApplicationInit: applicationInitEventHandler Invoke");
690             if (applicationInitEventHandler != null)
691             {
692                 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
693                 e.Application = this;
694                 applicationInitEventHandler.Invoke(this, e);
695             }
696             Tizen.Tracer.End();
697         }
698
699         /**
700           * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
701           *  provided by the user. Terminated signal is emitted when application is terminating
702           */
703         public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
704         {
705             add
706             {
707                 // Restricted to only one listener
708                 if (applicationTerminateEventHandler == null)
709                 {
710                     applicationTerminateEventHandler += value;
711
712                     applicationTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTerminate);
713                     terminateSignal = this.TerminateSignal();
714                     terminateSignal?.Connect(applicationTerminateEventCallbackDelegate);
715                 }
716             }
717
718             remove
719             {
720                 if (applicationTerminateEventHandler != null)
721                 {
722                     terminateSignal?.Disconnect(applicationTerminateEventCallbackDelegate);
723                     terminateSignal?.Dispose();
724                     terminateSignal = null;
725                 }
726
727                 applicationTerminateEventHandler -= value;
728             }
729         }
730
731         // Callback for Application TerminateSignal
732         private void OnNUIApplicationTerminate(IntPtr data)
733         {
734             if (applicationTerminateEventHandler != null)
735             {
736                 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
737                 e.Application = this;
738                 applicationTerminateEventHandler.Invoke(this, e);
739             }
740
741             List<Window> windows = GetWindowList();
742             foreach (Window window in windows)
743             {
744                 window?.DisconnectNativeSignals();
745             }
746         }
747
748         /**
749           * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
750           * provided by the user. Paused signal is emitted when application is paused
751           */
752         public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
753         {
754             add
755             {
756                 // Restricted to only one listener
757                 if (applicationPauseEventHandler == null)
758                 {
759                     applicationPauseEventHandler += value;
760
761                     applicationPauseEventCallbackDelegate = new NUIApplicationPauseEventCallbackDelegate(OnNUIApplicationPause);
762                     pauseSignal = this.PauseSignal();
763                     pauseSignal?.Connect(applicationPauseEventCallbackDelegate);
764                 }
765             }
766
767             remove
768             {
769                 if (applicationPauseEventHandler != null)
770                 {
771                     pauseSignal?.Disconnect(applicationPauseEventCallbackDelegate);
772                     pauseSignal?.Dispose();
773                     pauseSignal = null;
774                 }
775
776                 applicationPauseEventHandler -= value;
777             }
778         }
779
780         // Callback for Application PauseSignal
781         private void OnNUIApplicationPause(IntPtr data)
782         {
783             if (applicationPauseEventHandler != null)
784             {
785                 NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
786                 e.Application = this;
787                 applicationPauseEventHandler.Invoke(this, e);
788             }
789         }
790
791         /**
792           * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
793           *  provided by the user. Resumed signal is emitted when application is resumed
794           */
795         public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
796         {
797             add
798             {
799                 // Restricted to only one listener
800                 if (applicationResumeEventHandler == null)
801                 {
802                     applicationResumeEventHandler += value;
803
804                     applicationResumeEventCallbackDelegate = new NUIApplicationResumeEventCallbackDelegate(OnNUIApplicationResume);
805                     resumeSignal = this.ResumeSignal();
806                     resumeSignal?.Connect(applicationResumeEventCallbackDelegate);
807                 }
808             }
809
810             remove
811             {
812                 if (applicationResumeEventHandler != null)
813                 {
814                     resumeSignal?.Disconnect(applicationResumeEventCallbackDelegate);
815                     resumeSignal?.Dispose();
816                     resumeSignal = null;
817                 }
818
819                 applicationResumeEventHandler -= value;
820             }
821         }
822
823         // Callback for Application ResumeSignal
824         private void OnNUIApplicationResume(IntPtr data)
825         {
826             if (applicationResumeEventHandler != null)
827             {
828                 NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
829                 e.Application = this;
830                 applicationResumeEventHandler.Invoke(this, e);
831             }
832         }
833
834         /**
835           * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
836           *  provided by the user. Reset signal is emitted when application is reset
837           */
838         public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
839         {
840             add
841             {
842                 // Restricted to only one listener
843                 if (applicationResetEventHandler == null)
844                 {
845                     applicationResetEventHandler += value;
846
847                     applicationResetEventCallbackDelegate = new NUIApplicationResetEventCallbackDelegate(OnNUIApplicationReset);
848                     resetSignal = this.ResetSignal();
849                     resetSignal?.Connect(applicationResetEventCallbackDelegate);
850                 }
851             }
852
853             remove
854             {
855                 if (applicationResetEventHandler != null)
856                 {
857                     resetSignal?.Disconnect(applicationResetEventCallbackDelegate);
858                     resetSignal?.Dispose();
859                     resetSignal = null;
860                 }
861
862                 applicationResetEventHandler -= value;
863             }
864         }
865
866         // Callback for Application ResetSignal
867         private void OnNUIApplicationReset(IntPtr data)
868         {
869             if (applicationResetEventHandler != null)
870             {
871                 NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
872                 e.Application = this;
873                 applicationResetEventHandler.Invoke(this, e);
874             }
875         }
876
877         /**
878           * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
879           *  provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
880           */
881         public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
882         {
883             add
884             {
885                 // Restricted to only one listener
886                 if (applicationLanguageChangedEventHandler == null)
887                 {
888                     applicationLanguageChangedEventHandler += value;
889
890                     applicationLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationLanguageChanged);
891                     languageChangedSignal = this.LanguageChangedSignal();
892                     languageChangedSignal?.Connect(applicationLanguageChangedEventCallbackDelegate);
893                 }
894             }
895
896             remove
897             {
898                 if (applicationLanguageChangedEventHandler != null)
899                 {
900                     languageChangedSignal?.Disconnect(applicationLanguageChangedEventCallbackDelegate);
901                     languageChangedSignal?.Dispose();
902                     languageChangedSignal = null;
903                 }
904
905                 applicationLanguageChangedEventHandler -= value;
906             }
907         }
908
909         // Callback for Application LanguageChangedSignal
910         private void OnNUIApplicationLanguageChanged(IntPtr data)
911         {
912             if (applicationLanguageChangedEventHandler != null)
913             {
914                 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
915                 e.Application = this;
916                 applicationLanguageChangedEventHandler.Invoke(this, e);
917             }
918         }
919
920         /**
921           * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
922           *  provided by the user. RegionChanged signal is emitted when the region of the device is changed.
923           */
924         public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
925         {
926             add
927             {
928                 // Restricted to only one listener
929                 if (applicationRegionChangedEventHandler == null)
930                 {
931                     applicationRegionChangedEventHandler += value;
932
933                     applicationRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationRegionChanged);
934                     regionChangedSignal = this.RegionChangedSignal();
935                     regionChangedSignal?.Connect(applicationRegionChangedEventCallbackDelegate);
936                 }
937             }
938
939             remove
940             {
941                 if (applicationRegionChangedEventHandler != null)
942                 {
943                     regionChangedSignal?.Disconnect(applicationRegionChangedEventCallbackDelegate);
944                     regionChangedSignal?.Dispose();
945                     regionChangedSignal = null;
946                 }
947
948                 applicationRegionChangedEventHandler -= value;
949             }
950         }
951
952         // Callback for Application RegionChangedSignal
953         private void OnNUIApplicationRegionChanged(IntPtr data)
954         {
955             if (applicationRegionChangedEventHandler != null)
956             {
957                 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
958                 e.Application = this;
959                 applicationRegionChangedEventHandler.Invoke(this, e);
960             }
961         }
962
963         /**
964           * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
965           * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
966           */
967         public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
968         {
969             add
970             {
971                 // Restricted to only one listener
972                 if (applicationBatteryLowEventHandler == null)
973                 {
974                     applicationBatteryLowEventHandler += value;
975
976                     applicationBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationBatteryLow);
977                     batteryLowSignal = this.BatteryLowSignal();
978                     batteryLowSignal?.Connect(applicationBatteryLowEventCallbackDelegate);
979                 }
980             }
981
982             remove
983             {
984                 if (applicationBatteryLowEventHandler != null)
985                 {
986                     batteryLowSignal?.Disconnect(applicationBatteryLowEventCallbackDelegate);
987                     batteryLowSignal?.Dispose();
988                     batteryLowSignal = null;
989                 }
990
991                 applicationBatteryLowEventHandler -= value;
992             }
993         }
994
995         // Callback for Application BatteryLowSignal
996         private void OnNUIApplicationBatteryLow(BatteryStatus status)
997         {
998             NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
999
1000             // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
1001             e.BatteryStatus = status;
1002             applicationBatteryLowEventHandler?.Invoke(this, e);
1003         }
1004
1005         /**
1006           * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
1007           *  provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
1008           */
1009         public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
1010         {
1011             add
1012             {
1013                 // Restricted to only one listener
1014                 if (applicationMemoryLowEventHandler == null)
1015                 {
1016                     applicationMemoryLowEventHandler += value;
1017
1018                     applicationMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationMemoryLow);
1019                     memoryLowSignal = this.MemoryLowSignal();
1020                     memoryLowSignal?.Connect(applicationMemoryLowEventCallbackDelegate);
1021                 }
1022             }
1023
1024             remove
1025             {
1026                 if (applicationMemoryLowEventHandler != null)
1027                 {
1028                     memoryLowSignal?.Disconnect(applicationMemoryLowEventCallbackDelegate);
1029                     memoryLowSignal?.Dispose();
1030                     memoryLowSignal = null;
1031                 }
1032
1033                 applicationMemoryLowEventHandler -= value;
1034             }
1035         }
1036
1037         // Callback for Application MemoryLowSignal
1038         private void OnNUIApplicationMemoryLow(MemoryStatus status)
1039         {
1040             NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
1041
1042             // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
1043             e.MemoryStatus = status;
1044             applicationMemoryLowEventHandler?.Invoke(this, e);
1045         }
1046
1047         /**
1048           * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
1049           *  provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
1050           */
1051         public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
1052         {
1053             add
1054             {
1055                 // Restricted to only one listener
1056                 if (applicationAppControlEventHandler == null)
1057                 {
1058                     applicationAppControlEventHandler += value;
1059
1060                     applicationAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationAppControl);
1061                     appControlSignal = this.AppControlSignal();
1062                     appControlSignal?.Connect(applicationAppControlEventCallbackDelegate);
1063                 }
1064             }
1065
1066             remove
1067             {
1068                 if (applicationAppControlEventHandler != null)
1069                 {
1070                     appControlSignal?.Disconnect(applicationAppControlEventCallbackDelegate);
1071                     appControlSignal?.Dispose();
1072                     appControlSignal = null;
1073                 }
1074
1075                 applicationAppControlEventHandler -= value;
1076             }
1077         }
1078
1079         // Callback for Application AppControlSignal
1080         private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
1081         {
1082             if (applicationAppControlEventHandler != null)
1083             {
1084                 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1085                 e.VoidP = voidp;
1086                 e.Application = this;
1087                 applicationAppControlEventHandler.Invoke(this, e);
1088             }
1089         }
1090
1091         /// <summary>
1092         /// @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
1093         ///  provided by the user. Initialized signal is emitted when application is initialized
1094         /// </summary>
1095         public event DaliEventHandler<object, NUIApplicationInitEventArgs> TaskInitialized
1096         {
1097             add
1098             {
1099                 // Restricted to only one listener
1100                 if (applicationTaskInitEventHandler == null)
1101                 {
1102                     Tizen.Log.Fatal("NUI", "TaskInitialized Property adding");
1103                     applicationTaskInitEventHandler += value;
1104                     applicationTaskInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationTaskInit);
1105                     taskInitSignal = this.TaskInitSignal();
1106                     taskInitSignal?.Connect(applicationTaskInitEventCallbackDelegate);
1107                 }
1108             }
1109
1110             remove
1111             {
1112                 if (applicationTaskInitEventHandler != null)
1113                 {
1114                     taskInitSignal?.Disconnect(applicationTaskInitEventCallbackDelegate);
1115                     taskInitSignal?.Dispose();
1116                     taskInitSignal = null;
1117                 }
1118
1119                 applicationTaskInitEventHandler -= value;
1120             }
1121         }
1122
1123         private void OnApplicationTaskInit(IntPtr data)
1124         {
1125             if (applicationTaskInitEventHandler != null)
1126             {
1127                 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
1128                 e.Application = this;
1129                 applicationTaskInitEventHandler.Invoke(this, e);
1130             }
1131
1132         }
1133
1134         /// <summary>
1135         /// @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
1136         ///  provided by the user. Terminated signal is emitted when application is terminating
1137         /// </summary>
1138         public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> TaskTerminating
1139         {
1140             add
1141             {
1142                 // Restricted to only one listener
1143                 if (applicationTaskTerminateEventHandler == null)
1144                 {
1145                     applicationTaskTerminateEventHandler += value;
1146
1147                     applicationTaskTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTaskTerminate);
1148                     taskTerminateSignal = this.TaskTerminateSignal();
1149                     taskTerminateSignal?.Connect(applicationTaskTerminateEventCallbackDelegate);
1150                 }
1151             }
1152
1153             remove
1154             {
1155                 if (applicationTaskTerminateEventHandler != null)
1156                 {
1157                     taskTerminateSignal?.Disconnect(applicationTaskTerminateEventCallbackDelegate);
1158                     taskTerminateSignal?.Dispose();
1159                     taskTerminateSignal = null;
1160                 }
1161
1162                 applicationTaskTerminateEventHandler -= value;
1163             }
1164         }
1165
1166         private void OnNUIApplicationTaskTerminate(IntPtr data)
1167         {
1168             if (applicationTaskTerminateEventHandler != null)
1169             {
1170                 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
1171                 e.Application = this;
1172                 applicationTaskTerminateEventHandler.Invoke(this, e);
1173             }
1174         }
1175
1176         /// <summary>
1177         /// @brief Event for TaskLanguageChanged signal which can be used to subscribe/unsubscribe the event handler
1178         ///  provided by the user. TaskLanguageChanged signal is emitted when the region of the device is changed.
1179         /// </summary>
1180         public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> TaskLanguageChanged
1181         {
1182             add
1183             {
1184                 // Restricted to only one listener
1185                 if (applicationTaskLanguageChangedEventHandler == null)
1186                 {
1187                     applicationTaskLanguageChangedEventHandler += value;
1188
1189                     applicationTaskLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationTaskLanguageChanged);
1190                     taskLanguageChangedSignal = this.TaskLanguageChangedSignal();
1191                     taskLanguageChangedSignal?.Connect(applicationTaskLanguageChangedEventCallbackDelegate);
1192                 }
1193             }
1194
1195             remove
1196             {
1197                 if (applicationTaskLanguageChangedEventHandler != null)
1198                 {
1199                     taskLanguageChangedSignal?.Disconnect(applicationTaskLanguageChangedEventCallbackDelegate);
1200                     taskLanguageChangedSignal?.Dispose();
1201                     taskLanguageChangedSignal = null;
1202                 }
1203
1204                 applicationTaskLanguageChangedEventHandler -= value;
1205             }
1206         }
1207
1208         private void OnNUIApplicationTaskLanguageChanged(IntPtr data)
1209         {
1210             if (applicationTaskLanguageChangedEventHandler != null)
1211             {
1212                 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
1213                 e.Application = this;
1214                 applicationTaskLanguageChangedEventHandler.Invoke(this, e);
1215             }
1216         }
1217
1218         /// <summary>
1219         /// @brief Event for TaskRegionChanged signal which can be used to subscribe/unsubscribe the event handler
1220         ///  provided by the user. TaskRegionChanged signal is emitted when the region of the device is changed.
1221         /// </summary>
1222         public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> TaskRegionChanged
1223         {
1224             add
1225             {
1226                 // Restricted to only one listener
1227                 if (applicationTaskRegionChangedEventHandler == null)
1228                 {
1229                     applicationTaskRegionChangedEventHandler += value;
1230
1231                     applicationTaskRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationTaskRegionChanged);
1232                     taskRegionChangedSignal = this.TaskRegionChangedSignal();
1233                     taskRegionChangedSignal?.Connect(applicationTaskRegionChangedEventCallbackDelegate);
1234                 }
1235             }
1236
1237             remove
1238             {
1239                 if (applicationTaskRegionChangedEventHandler != null)
1240                 {
1241                     taskRegionChangedSignal?.Disconnect(applicationTaskRegionChangedEventCallbackDelegate);
1242                     taskRegionChangedSignal?.Dispose();
1243                     taskRegionChangedSignal = null;
1244                 }
1245
1246                 applicationTaskRegionChangedEventHandler -= value;
1247             }
1248         }
1249
1250         private void OnNUIApplicationTaskRegionChanged(IntPtr data)
1251         {
1252             if (applicationTaskRegionChangedEventHandler != null)
1253             {
1254                 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
1255                 e.Application = this;
1256                 applicationTaskRegionChangedEventHandler.Invoke(this, e);
1257             }
1258         }
1259
1260         /// <summary>
1261         /// @brief Event for TaskBatteryLow signal which can be used to subscribe/unsubscribe the event handler
1262         /// provided by the user. TaskBatteryLow signal is emitted when the battery level of the device is low.
1263         /// </summary>
1264         public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> TaskBatteryLow
1265         {
1266             add
1267             {
1268                 // Restricted to only one listener
1269                 if (applicationTaskBatteryLowEventHandler == null)
1270                 {
1271                     applicationTaskBatteryLowEventHandler += value;
1272
1273                     applicationTaskBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationTaskBatteryLow);
1274                     taskBatteryLowSignal = this.TaskBatteryLowSignal();
1275                     taskBatteryLowSignal?.Connect(applicationTaskBatteryLowEventCallbackDelegate);
1276                 }
1277             }
1278
1279             remove
1280             {
1281                 if (applicationTaskBatteryLowEventHandler != null)
1282                 {
1283                     taskBatteryLowSignal?.Disconnect(applicationTaskBatteryLowEventCallbackDelegate);
1284                     taskBatteryLowSignal?.Dispose();
1285                     taskBatteryLowSignal = null;
1286                 }
1287
1288                 applicationTaskBatteryLowEventHandler -= value;
1289             }
1290         }
1291
1292         private void OnNUIApplicationTaskBatteryLow(BatteryStatus status)
1293         {
1294             NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
1295
1296             // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
1297             e.BatteryStatus = status;
1298             applicationTaskBatteryLowEventHandler?.Invoke(this, e);
1299         }
1300
1301         /// <summary>
1302         /// @brief Event for TaskMemoryLow signal which can be used to subscribe/unsubscribe the event handler
1303         /// provided by the user. TaskMemoryLow signal is emitted when the memory level of the device is low.
1304         /// </summary>
1305         public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> TaskMemoryLow
1306         {
1307             add
1308             {
1309                 // Restricted to only one listener
1310                 if (applicationTaskMemoryLowEventHandler == null)
1311                 {
1312                     applicationTaskMemoryLowEventHandler += value;
1313
1314                     applicationTaskMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationTaskMemoryLow);
1315                     taskMemoryLowSignal = this.TaskMemoryLowSignal();
1316                     taskMemoryLowSignal?.Connect(applicationTaskMemoryLowEventCallbackDelegate);
1317                 }
1318             }
1319
1320             remove
1321             {
1322                 if (applicationTaskMemoryLowEventHandler != null)
1323                 {
1324                     taskMemoryLowSignal?.Disconnect(applicationTaskMemoryLowEventCallbackDelegate);
1325                     taskMemoryLowSignal?.Dispose();
1326                     taskMemoryLowSignal = null;
1327                 }
1328
1329                 applicationTaskMemoryLowEventHandler -= value;
1330             }
1331         }
1332
1333         private void OnNUIApplicationTaskMemoryLow(MemoryStatus status)
1334         {
1335             NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
1336
1337             // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
1338             e.MemoryStatus = status;
1339             applicationTaskMemoryLowEventHandler?.Invoke(this, e);
1340         }
1341
1342         /// <summary>
1343         /// @brief Event for TaskAppControl signal which can be used to subscribe/unsubscribe the event handler
1344         /// provided by the user. TaskAppControl signal is emitted when another application sends a launch request to the application.
1345         /// </summary>
1346         public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> TaskAppControl
1347         {
1348             add
1349             {
1350                 // Restricted to only one listener
1351                 if (applicationTaskAppControlEventHandler == null)
1352                 {
1353                     applicationTaskAppControlEventHandler += value;
1354
1355                     applicationTaskAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationTaskAppControl);
1356                     taskAppControlSignal = this.TaskAppControlSignal();
1357                     taskAppControlSignal?.Connect(applicationTaskAppControlEventCallbackDelegate);
1358                 }
1359             }
1360
1361             remove
1362             {
1363                 if (applicationTaskAppControlEventHandler != null)
1364                 {
1365                     taskAppControlSignal?.Disconnect(applicationTaskAppControlEventCallbackDelegate);
1366                     taskAppControlSignal?.Dispose();
1367                     taskAppControlSignal = null;
1368                 }
1369
1370                 applicationTaskAppControlEventHandler -= value;
1371             }
1372         }
1373
1374         private void OnNUIApplicationTaskAppControl(IntPtr application, IntPtr voidp)
1375         {
1376             if (applicationTaskAppControlEventHandler != null)
1377             {
1378                 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1379                 e.VoidP = voidp;
1380                 e.Application = this;
1381                 applicationTaskAppControlEventHandler.Invoke(this, e);
1382             }
1383         }
1384
1385         protected static Application instance; // singleton
1386
1387         public static Application Instance
1388         {
1389             get
1390             {
1391                 return instance;
1392             }
1393         }
1394
1395         public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
1396         {
1397             if (cPtr == global::System.IntPtr.Zero)
1398             {
1399                 return null;
1400             }
1401
1402             Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
1403             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1404             return ret;
1405         }
1406
1407         public static Application NewApplication()
1408         {
1409             return NewApplication("", NUIApplication.WindowMode.Opaque);
1410         }
1411
1412         public static Application NewApplication(string stylesheet)
1413         {
1414             return NewApplication(stylesheet, NUIApplication.WindowMode.Opaque);
1415         }
1416
1417         public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode)
1418         {
1419             // register all Views with the type registry, so that can be created / styled via JSON
1420             //ViewRegistryHelper.Initialize(); //moved to Application side.
1421             if (instance != null)
1422             {
1423                 return instance;
1424             }
1425
1426             Application ret = New(1, stylesheet, windowMode);
1427             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1428
1429             // set the singleton
1430             instance = ret;
1431             return ret;
1432         }
1433
1434         public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1435         {
1436             if (instance != null)
1437             {
1438                 return instance;
1439             }
1440             Application ret = New(1, stylesheet, windowMode, positionSize);
1441             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1442
1443             // set the singleton
1444             instance = ret;
1445             return ret;
1446         }
1447
1448         public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
1449         {
1450             if (instance != null)
1451             {
1452                 return instance;
1453             }
1454             Application ret = New(args, stylesheet, windowMode);
1455             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1456
1457             // set the singleton
1458             instance = ret;
1459             return instance;
1460         }
1461
1462         public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1463         {
1464             if (instance != null)
1465             {
1466                 return instance;
1467             }
1468             Application ret = New(args, stylesheet, windowMode, positionSize);
1469             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1470
1471             // set the singleton
1472             instance = ret;
1473             return instance;
1474         }
1475
1476         public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode, WindowType type)
1477         {
1478             if (instance != null)
1479             {
1480                 return instance;
1481             }
1482             Application ret = New(1, stylesheet, windowMode, type);
1483             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1484
1485             instance = ret;
1486             return instance;
1487         }
1488
1489         public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize, bool useUIThread)
1490         {
1491             if (instance != null)
1492             {
1493                 return instance;
1494             }
1495             Application ret = New(args, stylesheet, windowMode, positionSize, useUIThread);
1496             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1497
1498             instance = ret;
1499             return instance;
1500         }
1501
1502         /// <summary>
1503         /// Ensures that the function passed in is called from the main loop when it is idle.
1504         /// </summary>
1505         /// <param name="func">The function to call</param>
1506         /// <returns>true if added successfully, false otherwise</returns>
1507         /// <remarks>
1508         /// It will return false when one of the following conditions is met.
1509         /// 1) the <see cref="Window"/> is hidden.
1510         /// 2) the <see cref="Window"/> is iconified.
1511         /// </remarks>
1512         public bool AddIdle(System.Delegate func)
1513         {
1514             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
1515             System.IntPtr ip2 = Interop.Application.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
1516
1517             bool ret = Interop.Application.AddIdle(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
1518
1519             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1520             return ret;
1521         }
1522
1523         /**
1524         * Outer::outer_method(int)
1525         */
1526         public static Application New()
1527         {
1528             Application ret = new Application(Interop.Application.New(), true);
1529             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1530             return ret;
1531         }
1532
1533         public static Application New(int argc)
1534         {
1535             Application ret = new Application(Interop.Application.New(argc), true);
1536             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1537             return ret;
1538         }
1539
1540         public static Application New(int argc, string stylesheet)
1541         {
1542             Application ret = new Application(Interop.Application.New(argc, stylesheet), true);
1543             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1544             return ret;
1545         }
1546
1547         public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode)
1548         {
1549             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode), true);
1550             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1551             s_current = ret;
1552             return ret;
1553         }
1554
1555         public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
1556         {
1557             Application ret = null;
1558             int argc = 0;
1559             string argvStr = "";
1560             try
1561             {
1562                 argc = args.Length;
1563                 argvStr = string.Join(" ", args);
1564             }
1565             catch (Exception exception)
1566             {
1567                 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1568                 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1569                 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1570                 throw;
1571             }
1572
1573             ret = new Application(NDalicPINVOKE.ApplicationNewManual4(argc, argvStr, stylesheet, (int)windowMode), true);
1574             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1575
1576             return ret;
1577         }
1578
1579         public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1580         {
1581             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1582             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1583             return ret;
1584         }
1585
1586         public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1587         {
1588             Application ret = null;
1589             int argc = 0;
1590             string argvStr = "";
1591             try
1592             {
1593                 argc = args.Length;
1594                 argvStr = string.Join(" ", args);
1595             }
1596             catch (Exception exception)
1597             {
1598                 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1599                 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1600                 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1601                 throw;
1602             }
1603
1604             ret = new Application(NDalicPINVOKE.ApplicationNewWithWindowSizePosition(argc, argvStr, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1605             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1606
1607             return ret;
1608         }
1609
1610         public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode, WindowType type)
1611         {
1612             // It will be removed until dali APIs are prepared.
1613             Rectangle initRectangle = new Rectangle(0, 0, 0, 0);
1614
1615             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(initRectangle), (int)type), true);
1616             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1617             return ret;
1618         }
1619
1620         public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize, bool useUIThread)
1621         {
1622             Application ret = null;
1623             int argc = 0;
1624             string argvStr = "";
1625             try
1626             {
1627                 argc = args.Length;
1628                 argvStr = string.Join(" ", args);
1629
1630                 ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize), useUIThread), true);
1631                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1632             }
1633             catch (Exception exception)
1634             {
1635                 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1636                 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1637                 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1638                 throw;
1639             }
1640
1641             return ret;
1642         }
1643
1644         public Application() : this(Interop.Application.NewApplication(), true)
1645         {
1646             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1647         }
1648
1649         public Application(Application application) : this(Interop.Application.NewApplication(Application.getCPtr(application)), true)
1650         {
1651             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1652         }
1653
1654         public Application Assign(Application application)
1655         {
1656             Application ret = new Application(Interop.Application.Assign(SwigCPtr, Application.getCPtr(application)), false);
1657             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1658             return ret;
1659         }
1660
1661         public void MainLoop()
1662         {
1663             NDalicPINVOKE.ApplicationMainLoop(SwigCPtr);
1664             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1665         }
1666
1667         public void Lower()
1668         {
1669             Interop.Application.Lower(SwigCPtr);
1670             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1671         }
1672
1673         public void Quit()
1674         {
1675             Interop.Application.Quit(SwigCPtr);
1676             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1677         }
1678
1679         internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
1680         {
1681             bool ret = Interop.Application.AddIdle(SwigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
1682             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1683             return ret;
1684         }
1685
1686         public Window GetWindow()
1687         {
1688             if (window != null)
1689             {
1690                 return window;
1691             }
1692
1693             var nativeWindow = Interop.Application.GetWindow(SwigCPtr);
1694             window = Registry.GetManagedBaseHandleFromNativePtr(nativeWindow) as Window;
1695             if (window != null)
1696             {
1697                 HandleRef CPtr = new HandleRef(this, nativeWindow);
1698                 Interop.BaseHandle.DeleteBaseHandle(CPtr);
1699                 CPtr = new HandleRef(null, IntPtr.Zero);
1700             }
1701             else
1702             {
1703                 window = new Window(nativeWindow, true);
1704             }
1705
1706             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1707             return window;
1708         }
1709
1710         public static string GetResourcePath()
1711         {
1712             string ret = Interop.Application.GetResourcePath();
1713             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1714             return ret;
1715         }
1716
1717         public string GetLanguage()
1718         {
1719             string ret = Interop.Application.GetLanguage(SwigCPtr);
1720             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1721             return ret;
1722         }
1723
1724         public string GetRegion()
1725         {
1726             string ret = Interop.Application.GetRegion(SwigCPtr);
1727             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1728             return ret;
1729         }
1730
1731         [EditorBrowsable(EditorBrowsableState.Never)]
1732         public static List<Window> GetWindowList()
1733         {
1734             uint ListSize = Interop.Application.GetWindowsListSize();
1735             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1736
1737             List<Window> WindowList = new List<Window>();
1738             for (uint i = 0; i < ListSize; ++i)
1739             {
1740                 Window currWin = WindowList.GetInstanceSafely<Window>(Interop.Application.GetWindowsFromList(i));
1741                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1742                 if (currWin != null)
1743                 {
1744                     WindowList.Add(currWin);
1745                 }
1746             }
1747             return WindowList;
1748         }
1749
1750         internal ApplicationSignal InitSignal()
1751         {
1752             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationInitSignal(SwigCPtr), false);
1753             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1754             return ret;
1755         }
1756
1757         internal ApplicationSignal TerminateSignal()
1758         {
1759             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTerminateSignal(SwigCPtr), false);
1760             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1761             return ret;
1762         }
1763
1764         internal ApplicationSignal PauseSignal()
1765         {
1766             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationPauseSignal(SwigCPtr), false);
1767             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1768             return ret;
1769         }
1770
1771         internal ApplicationSignal ResumeSignal()
1772         {
1773             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationResumeSignal(SwigCPtr), false);
1774             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1775             return ret;
1776         }
1777
1778         internal ApplicationSignal ResetSignal()
1779         {
1780             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationResetSignal(SwigCPtr), false);
1781             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1782             return ret;
1783         }
1784
1785         internal ApplicationControlSignal AppControlSignal()
1786         {
1787             ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.ApplicationAppControlSignal(SwigCPtr), false);
1788             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1789             return ret;
1790         }
1791
1792         internal ApplicationSignal LanguageChangedSignal()
1793         {
1794             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationLanguageChangedSignal(SwigCPtr), false);
1795             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1796             return ret;
1797         }
1798
1799         internal ApplicationSignal RegionChangedSignal()
1800         {
1801             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationRegionChangedSignal(SwigCPtr), false);
1802             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1803             return ret;
1804         }
1805
1806         internal LowBatterySignalType BatteryLowSignal()
1807         {
1808             LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.ApplicationLowBatterySignal(SwigCPtr), false);
1809             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1810             return ret;
1811         }
1812
1813         internal LowMemorySignalType MemoryLowSignal()
1814         {
1815             LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.ApplicationLowMemorySignal(SwigCPtr), false);
1816             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1817             return ret;
1818         }
1819
1820         //Task
1821         internal ApplicationSignal TaskInitSignal()
1822         {
1823             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskInitSignal(SwigCPtr), false);
1824             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1825             return ret;
1826         }
1827
1828         internal ApplicationSignal TaskTerminateSignal()
1829         {
1830             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskTerminateSignal(SwigCPtr), false);
1831             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1832             return ret;
1833         }
1834
1835         internal ApplicationControlSignal TaskAppControlSignal()
1836         {
1837             ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.ApplicationTaskAppControlSignal(SwigCPtr), false);
1838             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1839             return ret;
1840         }
1841
1842         internal ApplicationSignal TaskLanguageChangedSignal()
1843         {
1844             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskLanguageChangedSignal(SwigCPtr), false);
1845             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1846             return ret;
1847         }
1848
1849         internal ApplicationSignal TaskRegionChangedSignal()
1850         {
1851             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskRegionChangedSignal(SwigCPtr), false);
1852             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1853             return ret;
1854         }
1855
1856         internal LowBatterySignalType TaskBatteryLowSignal()
1857         {
1858             LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.ApplicationTaskLowBatterySignal(SwigCPtr), false);
1859             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1860             return ret;
1861         }
1862
1863         internal LowMemorySignalType TaskMemoryLowSignal()
1864         {
1865             LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.ApplicationTaskLowMemorySignal(SwigCPtr), false);
1866             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1867             return ret;
1868         }
1869     }
1870 }