[NUI] make Theme not be loaded in tv profile
[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             //tv profile never use default focus indicator, so this is not needed!
676             _ = FocusManager.Instance;
677 #endif
678             Tizen.Tracer.End();
679
680             Log.Info("NUI", "[NUI] OnApplicationInit: Window Show");
681             Tizen.Tracer.Begin("[NUI] OnApplicationInit: Window Show");
682             // Notify that the window is displayed to the app core.
683             if (NUIApplication.IsPreload)
684             {
685                 Window.Instance.Show();
686             }
687             Tizen.Tracer.End();
688
689             Log.Info("NUI", "[NUI] OnApplicationInit: applicationInitEventHandler Invoke");
690             Tizen.Tracer.Begin("[NUI] OnApplicationInit: applicationInitEventHandler Invoke");
691             if (applicationInitEventHandler != null)
692             {
693                 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
694                 e.Application = this;
695                 applicationInitEventHandler.Invoke(this, e);
696             }
697             Tizen.Tracer.End();
698         }
699
700         /**
701           * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
702           *  provided by the user. Terminated signal is emitted when application is terminating
703           */
704         public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
705         {
706             add
707             {
708                 // Restricted to only one listener
709                 if (applicationTerminateEventHandler == null)
710                 {
711                     applicationTerminateEventHandler += value;
712
713                     applicationTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTerminate);
714                     terminateSignal = this.TerminateSignal();
715                     terminateSignal?.Connect(applicationTerminateEventCallbackDelegate);
716                 }
717             }
718
719             remove
720             {
721                 if (applicationTerminateEventHandler != null)
722                 {
723                     terminateSignal?.Disconnect(applicationTerminateEventCallbackDelegate);
724                     terminateSignal?.Dispose();
725                     terminateSignal = null;
726                 }
727
728                 applicationTerminateEventHandler -= value;
729             }
730         }
731
732         // Callback for Application TerminateSignal
733         private void OnNUIApplicationTerminate(IntPtr data)
734         {
735             if (applicationTerminateEventHandler != null)
736             {
737                 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
738                 e.Application = this;
739                 applicationTerminateEventHandler.Invoke(this, e);
740             }
741
742             List<Window> windows = GetWindowList();
743             foreach (Window window in windows)
744             {
745                 window?.DisconnectNativeSignals();
746             }
747         }
748
749         /**
750           * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
751           * provided by the user. Paused signal is emitted when application is paused
752           */
753         public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
754         {
755             add
756             {
757                 // Restricted to only one listener
758                 if (applicationPauseEventHandler == null)
759                 {
760                     applicationPauseEventHandler += value;
761
762                     applicationPauseEventCallbackDelegate = new NUIApplicationPauseEventCallbackDelegate(OnNUIApplicationPause);
763                     pauseSignal = this.PauseSignal();
764                     pauseSignal?.Connect(applicationPauseEventCallbackDelegate);
765                 }
766             }
767
768             remove
769             {
770                 if (applicationPauseEventHandler != null)
771                 {
772                     pauseSignal?.Disconnect(applicationPauseEventCallbackDelegate);
773                     pauseSignal?.Dispose();
774                     pauseSignal = null;
775                 }
776
777                 applicationPauseEventHandler -= value;
778             }
779         }
780
781         // Callback for Application PauseSignal
782         private void OnNUIApplicationPause(IntPtr data)
783         {
784             if (applicationPauseEventHandler != null)
785             {
786                 NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
787                 e.Application = this;
788                 applicationPauseEventHandler.Invoke(this, e);
789             }
790         }
791
792         /**
793           * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
794           *  provided by the user. Resumed signal is emitted when application is resumed
795           */
796         public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
797         {
798             add
799             {
800                 // Restricted to only one listener
801                 if (applicationResumeEventHandler == null)
802                 {
803                     applicationResumeEventHandler += value;
804
805                     applicationResumeEventCallbackDelegate = new NUIApplicationResumeEventCallbackDelegate(OnNUIApplicationResume);
806                     resumeSignal = this.ResumeSignal();
807                     resumeSignal?.Connect(applicationResumeEventCallbackDelegate);
808                 }
809             }
810
811             remove
812             {
813                 if (applicationResumeEventHandler != null)
814                 {
815                     resumeSignal?.Disconnect(applicationResumeEventCallbackDelegate);
816                     resumeSignal?.Dispose();
817                     resumeSignal = null;
818                 }
819
820                 applicationResumeEventHandler -= value;
821             }
822         }
823
824         // Callback for Application ResumeSignal
825         private void OnNUIApplicationResume(IntPtr data)
826         {
827             if (applicationResumeEventHandler != null)
828             {
829                 NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
830                 e.Application = this;
831                 applicationResumeEventHandler.Invoke(this, e);
832             }
833         }
834
835         /**
836           * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
837           *  provided by the user. Reset signal is emitted when application is reset
838           */
839         public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
840         {
841             add
842             {
843                 // Restricted to only one listener
844                 if (applicationResetEventHandler == null)
845                 {
846                     applicationResetEventHandler += value;
847
848                     applicationResetEventCallbackDelegate = new NUIApplicationResetEventCallbackDelegate(OnNUIApplicationReset);
849                     resetSignal = this.ResetSignal();
850                     resetSignal?.Connect(applicationResetEventCallbackDelegate);
851                 }
852             }
853
854             remove
855             {
856                 if (applicationResetEventHandler != null)
857                 {
858                     resetSignal?.Disconnect(applicationResetEventCallbackDelegate);
859                     resetSignal?.Dispose();
860                     resetSignal = null;
861                 }
862
863                 applicationResetEventHandler -= value;
864             }
865         }
866
867         // Callback for Application ResetSignal
868         private void OnNUIApplicationReset(IntPtr data)
869         {
870             if (applicationResetEventHandler != null)
871             {
872                 NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
873                 e.Application = this;
874                 applicationResetEventHandler.Invoke(this, e);
875             }
876         }
877
878         /**
879           * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
880           *  provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
881           */
882         public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
883         {
884             add
885             {
886                 // Restricted to only one listener
887                 if (applicationLanguageChangedEventHandler == null)
888                 {
889                     applicationLanguageChangedEventHandler += value;
890
891                     applicationLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationLanguageChanged);
892                     languageChangedSignal = this.LanguageChangedSignal();
893                     languageChangedSignal?.Connect(applicationLanguageChangedEventCallbackDelegate);
894                 }
895             }
896
897             remove
898             {
899                 if (applicationLanguageChangedEventHandler != null)
900                 {
901                     languageChangedSignal?.Disconnect(applicationLanguageChangedEventCallbackDelegate);
902                     languageChangedSignal?.Dispose();
903                     languageChangedSignal = null;
904                 }
905
906                 applicationLanguageChangedEventHandler -= value;
907             }
908         }
909
910         // Callback for Application LanguageChangedSignal
911         private void OnNUIApplicationLanguageChanged(IntPtr data)
912         {
913             if (applicationLanguageChangedEventHandler != null)
914             {
915                 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
916                 e.Application = this;
917                 applicationLanguageChangedEventHandler.Invoke(this, e);
918             }
919         }
920
921         /**
922           * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
923           *  provided by the user. RegionChanged signal is emitted when the region of the device is changed.
924           */
925         public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
926         {
927             add
928             {
929                 // Restricted to only one listener
930                 if (applicationRegionChangedEventHandler == null)
931                 {
932                     applicationRegionChangedEventHandler += value;
933
934                     applicationRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationRegionChanged);
935                     regionChangedSignal = this.RegionChangedSignal();
936                     regionChangedSignal?.Connect(applicationRegionChangedEventCallbackDelegate);
937                 }
938             }
939
940             remove
941             {
942                 if (applicationRegionChangedEventHandler != null)
943                 {
944                     regionChangedSignal?.Disconnect(applicationRegionChangedEventCallbackDelegate);
945                     regionChangedSignal?.Dispose();
946                     regionChangedSignal = null;
947                 }
948
949                 applicationRegionChangedEventHandler -= value;
950             }
951         }
952
953         // Callback for Application RegionChangedSignal
954         private void OnNUIApplicationRegionChanged(IntPtr data)
955         {
956             if (applicationRegionChangedEventHandler != null)
957             {
958                 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
959                 e.Application = this;
960                 applicationRegionChangedEventHandler.Invoke(this, e);
961             }
962         }
963
964         /**
965           * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
966           * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
967           */
968         public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
969         {
970             add
971             {
972                 // Restricted to only one listener
973                 if (applicationBatteryLowEventHandler == null)
974                 {
975                     applicationBatteryLowEventHandler += value;
976
977                     applicationBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationBatteryLow);
978                     batteryLowSignal = this.BatteryLowSignal();
979                     batteryLowSignal?.Connect(applicationBatteryLowEventCallbackDelegate);
980                 }
981             }
982
983             remove
984             {
985                 if (applicationBatteryLowEventHandler != null)
986                 {
987                     batteryLowSignal?.Disconnect(applicationBatteryLowEventCallbackDelegate);
988                     batteryLowSignal?.Dispose();
989                     batteryLowSignal = null;
990                 }
991
992                 applicationBatteryLowEventHandler -= value;
993             }
994         }
995
996         // Callback for Application BatteryLowSignal
997         private void OnNUIApplicationBatteryLow(BatteryStatus status)
998         {
999             NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
1000
1001             // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
1002             e.BatteryStatus = status;
1003             applicationBatteryLowEventHandler?.Invoke(this, e);
1004         }
1005
1006         /**
1007           * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
1008           *  provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
1009           */
1010         public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
1011         {
1012             add
1013             {
1014                 // Restricted to only one listener
1015                 if (applicationMemoryLowEventHandler == null)
1016                 {
1017                     applicationMemoryLowEventHandler += value;
1018
1019                     applicationMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationMemoryLow);
1020                     memoryLowSignal = this.MemoryLowSignal();
1021                     memoryLowSignal?.Connect(applicationMemoryLowEventCallbackDelegate);
1022                 }
1023             }
1024
1025             remove
1026             {
1027                 if (applicationMemoryLowEventHandler != null)
1028                 {
1029                     memoryLowSignal?.Disconnect(applicationMemoryLowEventCallbackDelegate);
1030                     memoryLowSignal?.Dispose();
1031                     memoryLowSignal = null;
1032                 }
1033
1034                 applicationMemoryLowEventHandler -= value;
1035             }
1036         }
1037
1038         // Callback for Application MemoryLowSignal
1039         private void OnNUIApplicationMemoryLow(MemoryStatus status)
1040         {
1041             NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
1042
1043             // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
1044             e.MemoryStatus = status;
1045             applicationMemoryLowEventHandler?.Invoke(this, e);
1046         }
1047
1048         /**
1049           * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
1050           *  provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
1051           */
1052         public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
1053         {
1054             add
1055             {
1056                 // Restricted to only one listener
1057                 if (applicationAppControlEventHandler == null)
1058                 {
1059                     applicationAppControlEventHandler += value;
1060
1061                     applicationAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationAppControl);
1062                     appControlSignal = this.AppControlSignal();
1063                     appControlSignal?.Connect(applicationAppControlEventCallbackDelegate);
1064                 }
1065             }
1066
1067             remove
1068             {
1069                 if (applicationAppControlEventHandler != null)
1070                 {
1071                     appControlSignal?.Disconnect(applicationAppControlEventCallbackDelegate);
1072                     appControlSignal?.Dispose();
1073                     appControlSignal = null;
1074                 }
1075
1076                 applicationAppControlEventHandler -= value;
1077             }
1078         }
1079
1080         // Callback for Application AppControlSignal
1081         private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
1082         {
1083             if (applicationAppControlEventHandler != null)
1084             {
1085                 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1086                 e.VoidP = voidp;
1087                 e.Application = this;
1088                 applicationAppControlEventHandler.Invoke(this, e);
1089             }
1090         }
1091
1092         /// <summary>
1093         /// @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
1094         ///  provided by the user. Initialized signal is emitted when application is initialized
1095         /// </summary>
1096         public event DaliEventHandler<object, NUIApplicationInitEventArgs> TaskInitialized
1097         {
1098             add
1099             {
1100                 // Restricted to only one listener
1101                 if (applicationTaskInitEventHandler == null)
1102                 {
1103                     Tizen.Log.Fatal("NUI", "TaskInitialized Property adding");
1104                     applicationTaskInitEventHandler += value;
1105                     applicationTaskInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationTaskInit);
1106                     taskInitSignal = this.TaskInitSignal();
1107                     taskInitSignal?.Connect(applicationTaskInitEventCallbackDelegate);
1108                 }
1109             }
1110
1111             remove
1112             {
1113                 if (applicationTaskInitEventHandler != null)
1114                 {
1115                     taskInitSignal?.Disconnect(applicationTaskInitEventCallbackDelegate);
1116                     taskInitSignal?.Dispose();
1117                     taskInitSignal = null;
1118                 }
1119
1120                 applicationTaskInitEventHandler -= value;
1121             }
1122         }
1123
1124         private void OnApplicationTaskInit(IntPtr data)
1125         {
1126             if (applicationTaskInitEventHandler != null)
1127             {
1128                 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
1129                 e.Application = this;
1130                 applicationTaskInitEventHandler.Invoke(this, e);
1131             }
1132
1133         }
1134
1135         /// <summary>
1136         /// @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
1137         ///  provided by the user. Terminated signal is emitted when application is terminating
1138         /// </summary>
1139         public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> TaskTerminating
1140         {
1141             add
1142             {
1143                 // Restricted to only one listener
1144                 if (applicationTaskTerminateEventHandler == null)
1145                 {
1146                     applicationTaskTerminateEventHandler += value;
1147
1148                     applicationTaskTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTaskTerminate);
1149                     taskTerminateSignal = this.TaskTerminateSignal();
1150                     taskTerminateSignal?.Connect(applicationTaskTerminateEventCallbackDelegate);
1151                 }
1152             }
1153
1154             remove
1155             {
1156                 if (applicationTaskTerminateEventHandler != null)
1157                 {
1158                     taskTerminateSignal?.Disconnect(applicationTaskTerminateEventCallbackDelegate);
1159                     taskTerminateSignal?.Dispose();
1160                     taskTerminateSignal = null;
1161                 }
1162
1163                 applicationTaskTerminateEventHandler -= value;
1164             }
1165         }
1166
1167         private void OnNUIApplicationTaskTerminate(IntPtr data)
1168         {
1169             if (applicationTaskTerminateEventHandler != null)
1170             {
1171                 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
1172                 e.Application = this;
1173                 applicationTaskTerminateEventHandler.Invoke(this, e);
1174             }
1175         }
1176
1177         /// <summary>
1178         /// @brief Event for TaskLanguageChanged signal which can be used to subscribe/unsubscribe the event handler
1179         ///  provided by the user. TaskLanguageChanged signal is emitted when the region of the device is changed.
1180         /// </summary>
1181         public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> TaskLanguageChanged
1182         {
1183             add
1184             {
1185                 // Restricted to only one listener
1186                 if (applicationTaskLanguageChangedEventHandler == null)
1187                 {
1188                     applicationTaskLanguageChangedEventHandler += value;
1189
1190                     applicationTaskLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationTaskLanguageChanged);
1191                     taskLanguageChangedSignal = this.TaskLanguageChangedSignal();
1192                     taskLanguageChangedSignal?.Connect(applicationTaskLanguageChangedEventCallbackDelegate);
1193                 }
1194             }
1195
1196             remove
1197             {
1198                 if (applicationTaskLanguageChangedEventHandler != null)
1199                 {
1200                     taskLanguageChangedSignal?.Disconnect(applicationTaskLanguageChangedEventCallbackDelegate);
1201                     taskLanguageChangedSignal?.Dispose();
1202                     taskLanguageChangedSignal = null;
1203                 }
1204
1205                 applicationTaskLanguageChangedEventHandler -= value;
1206             }
1207         }
1208
1209         private void OnNUIApplicationTaskLanguageChanged(IntPtr data)
1210         {
1211             if (applicationTaskLanguageChangedEventHandler != null)
1212             {
1213                 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
1214                 e.Application = this;
1215                 applicationTaskLanguageChangedEventHandler.Invoke(this, e);
1216             }
1217         }
1218
1219         /// <summary>
1220         /// @brief Event for TaskRegionChanged signal which can be used to subscribe/unsubscribe the event handler
1221         ///  provided by the user. TaskRegionChanged signal is emitted when the region of the device is changed.
1222         /// </summary>
1223         public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> TaskRegionChanged
1224         {
1225             add
1226             {
1227                 // Restricted to only one listener
1228                 if (applicationTaskRegionChangedEventHandler == null)
1229                 {
1230                     applicationTaskRegionChangedEventHandler += value;
1231
1232                     applicationTaskRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationTaskRegionChanged);
1233                     taskRegionChangedSignal = this.TaskRegionChangedSignal();
1234                     taskRegionChangedSignal?.Connect(applicationTaskRegionChangedEventCallbackDelegate);
1235                 }
1236             }
1237
1238             remove
1239             {
1240                 if (applicationTaskRegionChangedEventHandler != null)
1241                 {
1242                     taskRegionChangedSignal?.Disconnect(applicationTaskRegionChangedEventCallbackDelegate);
1243                     taskRegionChangedSignal?.Dispose();
1244                     taskRegionChangedSignal = null;
1245                 }
1246
1247                 applicationTaskRegionChangedEventHandler -= value;
1248             }
1249         }
1250
1251         private void OnNUIApplicationTaskRegionChanged(IntPtr data)
1252         {
1253             if (applicationTaskRegionChangedEventHandler != null)
1254             {
1255                 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
1256                 e.Application = this;
1257                 applicationTaskRegionChangedEventHandler.Invoke(this, e);
1258             }
1259         }
1260
1261         /// <summary>
1262         /// @brief Event for TaskBatteryLow signal which can be used to subscribe/unsubscribe the event handler
1263         /// provided by the user. TaskBatteryLow signal is emitted when the battery level of the device is low.
1264         /// </summary>
1265         public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> TaskBatteryLow
1266         {
1267             add
1268             {
1269                 // Restricted to only one listener
1270                 if (applicationTaskBatteryLowEventHandler == null)
1271                 {
1272                     applicationTaskBatteryLowEventHandler += value;
1273
1274                     applicationTaskBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationTaskBatteryLow);
1275                     taskBatteryLowSignal = this.TaskBatteryLowSignal();
1276                     taskBatteryLowSignal?.Connect(applicationTaskBatteryLowEventCallbackDelegate);
1277                 }
1278             }
1279
1280             remove
1281             {
1282                 if (applicationTaskBatteryLowEventHandler != null)
1283                 {
1284                     taskBatteryLowSignal?.Disconnect(applicationTaskBatteryLowEventCallbackDelegate);
1285                     taskBatteryLowSignal?.Dispose();
1286                     taskBatteryLowSignal = null;
1287                 }
1288
1289                 applicationTaskBatteryLowEventHandler -= value;
1290             }
1291         }
1292
1293         private void OnNUIApplicationTaskBatteryLow(BatteryStatus status)
1294         {
1295             NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
1296
1297             // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
1298             e.BatteryStatus = status;
1299             applicationTaskBatteryLowEventHandler?.Invoke(this, e);
1300         }
1301
1302         /// <summary>
1303         /// @brief Event for TaskMemoryLow signal which can be used to subscribe/unsubscribe the event handler
1304         /// provided by the user. TaskMemoryLow signal is emitted when the memory level of the device is low.
1305         /// </summary>
1306         public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> TaskMemoryLow
1307         {
1308             add
1309             {
1310                 // Restricted to only one listener
1311                 if (applicationTaskMemoryLowEventHandler == null)
1312                 {
1313                     applicationTaskMemoryLowEventHandler += value;
1314
1315                     applicationTaskMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationTaskMemoryLow);
1316                     taskMemoryLowSignal = this.TaskMemoryLowSignal();
1317                     taskMemoryLowSignal?.Connect(applicationTaskMemoryLowEventCallbackDelegate);
1318                 }
1319             }
1320
1321             remove
1322             {
1323                 if (applicationTaskMemoryLowEventHandler != null)
1324                 {
1325                     taskMemoryLowSignal?.Disconnect(applicationTaskMemoryLowEventCallbackDelegate);
1326                     taskMemoryLowSignal?.Dispose();
1327                     taskMemoryLowSignal = null;
1328                 }
1329
1330                 applicationTaskMemoryLowEventHandler -= value;
1331             }
1332         }
1333
1334         private void OnNUIApplicationTaskMemoryLow(MemoryStatus status)
1335         {
1336             NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
1337
1338             // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
1339             e.MemoryStatus = status;
1340             applicationTaskMemoryLowEventHandler?.Invoke(this, e);
1341         }
1342
1343         /// <summary>
1344         /// @brief Event for TaskAppControl signal which can be used to subscribe/unsubscribe the event handler
1345         /// provided by the user. TaskAppControl signal is emitted when another application sends a launch request to the application.
1346         /// </summary>
1347         public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> TaskAppControl
1348         {
1349             add
1350             {
1351                 // Restricted to only one listener
1352                 if (applicationTaskAppControlEventHandler == null)
1353                 {
1354                     applicationTaskAppControlEventHandler += value;
1355
1356                     applicationTaskAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationTaskAppControl);
1357                     taskAppControlSignal = this.TaskAppControlSignal();
1358                     taskAppControlSignal?.Connect(applicationTaskAppControlEventCallbackDelegate);
1359                 }
1360             }
1361
1362             remove
1363             {
1364                 if (applicationTaskAppControlEventHandler != null)
1365                 {
1366                     taskAppControlSignal?.Disconnect(applicationTaskAppControlEventCallbackDelegate);
1367                     taskAppControlSignal?.Dispose();
1368                     taskAppControlSignal = null;
1369                 }
1370
1371                 applicationTaskAppControlEventHandler -= value;
1372             }
1373         }
1374
1375         private void OnNUIApplicationTaskAppControl(IntPtr application, IntPtr voidp)
1376         {
1377             if (applicationTaskAppControlEventHandler != null)
1378             {
1379                 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1380                 e.VoidP = voidp;
1381                 e.Application = this;
1382                 applicationTaskAppControlEventHandler.Invoke(this, e);
1383             }
1384         }
1385
1386         protected static Application instance; // singleton
1387
1388         public static Application Instance
1389         {
1390             get
1391             {
1392                 return instance;
1393             }
1394         }
1395
1396         public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
1397         {
1398             if (cPtr == global::System.IntPtr.Zero)
1399             {
1400                 return null;
1401             }
1402
1403             Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
1404             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1405             return ret;
1406         }
1407
1408         public static Application NewApplication()
1409         {
1410             return NewApplication("", NUIApplication.WindowMode.Opaque);
1411         }
1412
1413         public static Application NewApplication(string stylesheet)
1414         {
1415             return NewApplication(stylesheet, NUIApplication.WindowMode.Opaque);
1416         }
1417
1418         public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode)
1419         {
1420             // register all Views with the type registry, so that can be created / styled via JSON
1421             //ViewRegistryHelper.Initialize(); //moved to Application side.
1422             if (instance != null)
1423             {
1424                 return instance;
1425             }
1426
1427             Application ret = New(1, stylesheet, windowMode);
1428             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1429
1430             // set the singleton
1431             instance = ret;
1432             return ret;
1433         }
1434
1435         public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1436         {
1437             if (instance != null)
1438             {
1439                 return instance;
1440             }
1441             Application ret = New(1, stylesheet, windowMode, positionSize);
1442             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1443
1444             // set the singleton
1445             instance = ret;
1446             return ret;
1447         }
1448
1449         public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
1450         {
1451             if (instance != null)
1452             {
1453                 return instance;
1454             }
1455             Application ret = New(args, stylesheet, windowMode);
1456             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1457
1458             // set the singleton
1459             instance = ret;
1460             return instance;
1461         }
1462
1463         public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1464         {
1465             if (instance != null)
1466             {
1467                 return instance;
1468             }
1469             Application ret = New(args, stylesheet, windowMode, positionSize);
1470             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1471
1472             // set the singleton
1473             instance = ret;
1474             return instance;
1475         }
1476
1477         public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode, WindowType type)
1478         {
1479             if (instance != null)
1480             {
1481                 return instance;
1482             }
1483             Application ret = New(1, stylesheet, windowMode, type);
1484             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1485
1486             instance = ret;
1487             return instance;
1488         }
1489
1490         public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize, bool useUIThread)
1491         {
1492             if (instance != null)
1493             {
1494                 return instance;
1495             }
1496             Application ret = New(args, stylesheet, windowMode, positionSize, useUIThread);
1497             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1498
1499             instance = ret;
1500             return instance;
1501         }
1502
1503         /// <summary>
1504         /// Ensures that the function passed in is called from the main loop when it is idle.
1505         /// </summary>
1506         /// <param name="func">The function to call</param>
1507         /// <returns>true if added successfully, false otherwise</returns>
1508         /// <remarks>
1509         /// It will return false when one of the following conditions is met.
1510         /// 1) the <see cref="Window"/> is hidden.
1511         /// 2) the <see cref="Window"/> is iconified.
1512         /// </remarks>
1513         public bool AddIdle(System.Delegate func)
1514         {
1515             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
1516             System.IntPtr ip2 = Interop.Application.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
1517
1518             bool ret = Interop.Application.AddIdle(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
1519
1520             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1521             return ret;
1522         }
1523
1524         /**
1525         * Outer::outer_method(int)
1526         */
1527         public static Application New()
1528         {
1529             Application ret = new Application(Interop.Application.New(), true);
1530             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1531             return ret;
1532         }
1533
1534         public static Application New(int argc)
1535         {
1536             Application ret = new Application(Interop.Application.New(argc), true);
1537             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1538             return ret;
1539         }
1540
1541         public static Application New(int argc, string stylesheet)
1542         {
1543             Application ret = new Application(Interop.Application.New(argc, stylesheet), true);
1544             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1545             return ret;
1546         }
1547
1548         public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode)
1549         {
1550             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode), true);
1551             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1552             s_current = ret;
1553             return ret;
1554         }
1555
1556         public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
1557         {
1558             Application ret = null;
1559             int argc = 0;
1560             string argvStr = "";
1561             try
1562             {
1563                 argc = args.Length;
1564                 argvStr = string.Join(" ", args);
1565             }
1566             catch (Exception exception)
1567             {
1568                 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1569                 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1570                 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1571                 throw;
1572             }
1573
1574             ret = new Application(NDalicPINVOKE.ApplicationNewManual4(argc, argvStr, stylesheet, (int)windowMode), true);
1575             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1576
1577             return ret;
1578         }
1579
1580         public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1581         {
1582             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1583             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1584             return ret;
1585         }
1586
1587         public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1588         {
1589             Application ret = null;
1590             int argc = 0;
1591             string argvStr = "";
1592             try
1593             {
1594                 argc = args.Length;
1595                 argvStr = string.Join(" ", args);
1596             }
1597             catch (Exception exception)
1598             {
1599                 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1600                 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1601                 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1602                 throw;
1603             }
1604
1605             ret = new Application(NDalicPINVOKE.ApplicationNewWithWindowSizePosition(argc, argvStr, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1606             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1607
1608             return ret;
1609         }
1610
1611         public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode, WindowType type)
1612         {
1613             // It will be removed until dali APIs are prepared.
1614             Rectangle initRectangle = new Rectangle(0, 0, 0, 0);
1615
1616             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(initRectangle), (int)type), true);
1617             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1618             return ret;
1619         }
1620
1621         public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize, bool useUIThread)
1622         {
1623             Application ret = null;
1624             int argc = 0;
1625             string argvStr = "";
1626             try
1627             {
1628                 argc = args.Length;
1629                 argvStr = string.Join(" ", args);
1630
1631                 ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize), useUIThread), true);
1632                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1633             }
1634             catch (Exception exception)
1635             {
1636                 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1637                 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1638                 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1639                 throw;
1640             }
1641
1642             return ret;
1643         }
1644
1645         public Application() : this(Interop.Application.NewApplication(), true)
1646         {
1647             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1648         }
1649
1650         public Application(Application application) : this(Interop.Application.NewApplication(Application.getCPtr(application)), true)
1651         {
1652             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1653         }
1654
1655         public Application Assign(Application application)
1656         {
1657             Application ret = new Application(Interop.Application.Assign(SwigCPtr, Application.getCPtr(application)), false);
1658             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1659             return ret;
1660         }
1661
1662         public void MainLoop()
1663         {
1664             NDalicPINVOKE.ApplicationMainLoop(SwigCPtr);
1665             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1666         }
1667
1668         public void Lower()
1669         {
1670             Interop.Application.Lower(SwigCPtr);
1671             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1672         }
1673
1674         public void Quit()
1675         {
1676             Interop.Application.Quit(SwigCPtr);
1677             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1678         }
1679
1680         internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
1681         {
1682             bool ret = Interop.Application.AddIdle(SwigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
1683             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1684             return ret;
1685         }
1686
1687         public Window GetWindow()
1688         {
1689             if (window != null)
1690             {
1691                 return window;
1692             }
1693
1694             var nativeWindow = Interop.Application.GetWindow(SwigCPtr);
1695             window = Registry.GetManagedBaseHandleFromNativePtr(nativeWindow) as Window;
1696             if (window != null)
1697             {
1698                 HandleRef CPtr = new HandleRef(this, nativeWindow);
1699                 Interop.BaseHandle.DeleteBaseHandle(CPtr);
1700                 CPtr = new HandleRef(null, IntPtr.Zero);
1701             }
1702             else
1703             {
1704                 window = new Window(nativeWindow, true);
1705             }
1706
1707             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1708             return window;
1709         }
1710
1711         public static string GetResourcePath()
1712         {
1713             string ret = Interop.Application.GetResourcePath();
1714             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1715             return ret;
1716         }
1717
1718         public string GetLanguage()
1719         {
1720             string ret = Interop.Application.GetLanguage(SwigCPtr);
1721             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1722             return ret;
1723         }
1724
1725         public string GetRegion()
1726         {
1727             string ret = Interop.Application.GetRegion(SwigCPtr);
1728             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1729             return ret;
1730         }
1731
1732         [EditorBrowsable(EditorBrowsableState.Never)]
1733         public static List<Window> GetWindowList()
1734         {
1735             uint ListSize = Interop.Application.GetWindowsListSize();
1736             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1737
1738             List<Window> WindowList = new List<Window>();
1739             for (uint i = 0; i < ListSize; ++i)
1740             {
1741                 Window currWin = WindowList.GetInstanceSafely<Window>(Interop.Application.GetWindowsFromList(i));
1742                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1743                 if (currWin != null)
1744                 {
1745                     WindowList.Add(currWin);
1746                 }
1747             }
1748             return WindowList;
1749         }
1750
1751         internal ApplicationSignal InitSignal()
1752         {
1753             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationInitSignal(SwigCPtr), false);
1754             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1755             return ret;
1756         }
1757
1758         internal ApplicationSignal TerminateSignal()
1759         {
1760             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTerminateSignal(SwigCPtr), false);
1761             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1762             return ret;
1763         }
1764
1765         internal ApplicationSignal PauseSignal()
1766         {
1767             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationPauseSignal(SwigCPtr), false);
1768             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1769             return ret;
1770         }
1771
1772         internal ApplicationSignal ResumeSignal()
1773         {
1774             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationResumeSignal(SwigCPtr), false);
1775             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1776             return ret;
1777         }
1778
1779         internal ApplicationSignal ResetSignal()
1780         {
1781             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationResetSignal(SwigCPtr), false);
1782             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1783             return ret;
1784         }
1785
1786         internal ApplicationControlSignal AppControlSignal()
1787         {
1788             ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.ApplicationAppControlSignal(SwigCPtr), false);
1789             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1790             return ret;
1791         }
1792
1793         internal ApplicationSignal LanguageChangedSignal()
1794         {
1795             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationLanguageChangedSignal(SwigCPtr), false);
1796             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1797             return ret;
1798         }
1799
1800         internal ApplicationSignal RegionChangedSignal()
1801         {
1802             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationRegionChangedSignal(SwigCPtr), false);
1803             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1804             return ret;
1805         }
1806
1807         internal LowBatterySignalType BatteryLowSignal()
1808         {
1809             LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.ApplicationLowBatterySignal(SwigCPtr), false);
1810             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1811             return ret;
1812         }
1813
1814         internal LowMemorySignalType MemoryLowSignal()
1815         {
1816             LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.ApplicationLowMemorySignal(SwigCPtr), false);
1817             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1818             return ret;
1819         }
1820
1821         //Task
1822         internal ApplicationSignal TaskInitSignal()
1823         {
1824             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskInitSignal(SwigCPtr), false);
1825             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1826             return ret;
1827         }
1828
1829         internal ApplicationSignal TaskTerminateSignal()
1830         {
1831             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskTerminateSignal(SwigCPtr), false);
1832             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1833             return ret;
1834         }
1835
1836         internal ApplicationControlSignal TaskAppControlSignal()
1837         {
1838             ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.ApplicationTaskAppControlSignal(SwigCPtr), false);
1839             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1840             return ret;
1841         }
1842
1843         internal ApplicationSignal TaskLanguageChangedSignal()
1844         {
1845             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskLanguageChangedSignal(SwigCPtr), false);
1846             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1847             return ret;
1848         }
1849
1850         internal ApplicationSignal TaskRegionChangedSignal()
1851         {
1852             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTaskRegionChangedSignal(SwigCPtr), false);
1853             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1854             return ret;
1855         }
1856
1857         internal LowBatterySignalType TaskBatteryLowSignal()
1858         {
1859             LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.ApplicationTaskLowBatterySignal(SwigCPtr), false);
1860             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1861             return ret;
1862         }
1863
1864         internal LowMemorySignalType TaskMemoryLowSignal()
1865         {
1866             LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.ApplicationTaskLowMemorySignal(SwigCPtr), false);
1867             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1868             return ret;
1869         }
1870     }
1871 }