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