[NUI] Split NUI Assemblies (#865)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Application.cs
1 /*
2  * Copyright(c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 namespace Tizen.NUI
19 {
20
21     using System;
22     using System.Collections.Generic;
23     using System.Collections.ObjectModel;
24     using System.ComponentModel;
25     using System.Runtime.InteropServices;
26     using System.Threading;
27     using System.Threading.Tasks;
28
29     /**
30       * @brief Event arguments that passed via NUIApplicationInit signal
31       *
32       */
33     internal class NUIApplicationInitEventArgs : EventArgs
34     {
35         private Application _application;
36
37         /**
38           * @brief Application - is the application that is being initialized
39           *
40           */
41         public Application Application
42         {
43             get
44             {
45                 return _application;
46             }
47             set
48             {
49                 _application = value;
50             }
51         }
52     }
53
54     /**
55       * @brief Event arguments that passed via NUIApplicationTerminate signal
56       *
57       */
58     internal class NUIApplicationTerminatingEventArgs : EventArgs
59     {
60         private Application _application;
61         /**
62           * @brief Application - is the application that is being Terminated
63           *
64           */
65         public Application Application
66         {
67             get
68             {
69                 return _application;
70             }
71             set
72             {
73                 _application = value;
74             }
75         }
76     }
77
78     /**
79       * @brief Event arguments that passed via NUIApplicationPause signal
80       *
81       */
82     internal class NUIApplicationPausedEventArgs : EventArgs
83     {
84         private Application _application;
85         /**
86           * @brief Application - is the application that is being Paused
87           *
88           */
89         public Application Application
90         {
91             get
92             {
93                 return _application;
94             }
95             set
96             {
97                 _application = value;
98             }
99         }
100     }
101
102     /**
103       * @brief Event arguments that passed via NUIApplicationResume signal
104       *
105       */
106     internal class NUIApplicationResumedEventArgs : EventArgs
107     {
108         private Application _application;
109         /**
110           * @brief Application - is the application that is being Resumed
111           *
112           */
113         public Application Application
114         {
115             get
116             {
117                 return _application;
118             }
119             set
120             {
121                 _application = value;
122             }
123         }
124     }
125
126     /**
127       * @brief Event arguments that passed via NUIApplicationReset signal
128       *
129       */
130     internal class NUIApplicationResetEventArgs : EventArgs
131     {
132         private Application _application;
133         /**
134           * @brief Application - is the application that is being Reset
135           *
136           */
137         public Application Application
138         {
139             get
140             {
141                 return _application;
142             }
143             set
144             {
145                 _application = value;
146             }
147         }
148     }
149
150     /**
151       * @brief Event arguments that passed via NUIApplicationResize signal
152       *
153       */
154     internal class NUIApplicationResizedEventArgs : EventArgs
155     {
156         private Application _application;
157         /**
158           * @brief Application - is the application that is being Resized
159           *
160           */
161         public Application Application
162         {
163             get
164             {
165                 return _application;
166             }
167             set
168             {
169                 _application = value;
170             }
171         }
172     }
173
174     /**
175       * @brief Event arguments that passed via NUIApplicationLanguageChanged signal
176       *
177       */
178     internal class NUIApplicationLanguageChangedEventArgs : EventArgs
179     {
180         private Application _application;
181         /**
182           * @brief Application - is the application that is being affected with Device's language change
183           *
184           */
185         public Application Application
186         {
187             get
188             {
189                 return _application;
190             }
191             set
192             {
193                 _application = value;
194             }
195         }
196     }
197
198     /**
199       * @brief Event arguments that passed via NUIApplicationRegionChanged signal
200       *
201       */
202     internal class NUIApplicationRegionChangedEventArgs : EventArgs
203     {
204         private Application _application;
205         /**
206           * @brief Application - is the application that is being affected with Device's region change
207           *
208           */
209         public Application Application
210         {
211             get
212             {
213                 return _application;
214             }
215             set
216             {
217                 _application = value;
218             }
219         }
220     }
221
222     /**
223       * @brief Event arguments that passed via NUIApplicationBatteryLow signal
224       *
225       */
226     internal class NUIApplicationBatteryLowEventArgs : EventArgs
227     {
228         private Application.BatteryStatus _status;
229         /**
230           * @brief Application - is the application that is being affected when the battery level of the device is low
231           *
232           */
233         public Application.BatteryStatus BatteryStatus
234         {
235             get
236             {
237                 return _status;
238             }
239             set
240             {
241                 _status = value;
242             }
243         }
244     }
245
246     /**
247       * @brief Event arguments that passed via NUIApplicationMemoryLow signal
248       *
249       */
250     internal class NUIApplicationMemoryLowEventArgs : EventArgs
251     {
252         private Application.MemoryStatus _status;
253         /**
254           * @brief Application - is the application that is being affected when the memory level of the device is low
255           *
256           */
257         public Application.MemoryStatus MemoryStatus
258         {
259             get
260             {
261                 return _status;
262             }
263             set
264             {
265                 _status = value;
266             }
267         }
268     }
269
270     /**
271       * @brief Event arguments that passed via NUIApplicationAppControl  signal
272       *
273       */
274     internal class NUIApplicationAppControlEventArgs : EventArgs
275     {
276         private Application _application;
277         private IntPtr _voidp;
278         /**
279           * @brief Application - is the application that is receiving the launch request from another application
280           *
281           */
282         public Application Application
283         {
284             get
285             {
286                 return _application;
287             }
288             set
289             {
290                 _application = value;
291             }
292         }
293         /**
294           * @brief VoidP - contains the information about why the application is launched
295           *
296           */
297         public IntPtr VoidP
298         {
299             get
300             {
301                 return _voidp;
302             }
303             set
304             {
305                 _voidp = value;
306             }
307         }
308     }
309
310     internal class Application : BaseHandle
311     {
312         static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
313
314         [EditorBrowsable(EditorBrowsableState.Never)]
315         public int PanGestureId { get; set; }
316
317         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
318
319         internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Application_SWIGUpcast(cPtr), cMemoryOwn)
320         {
321             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
322         }
323
324         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj)
325         {
326             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
327         }
328
329         protected override void Dispose(DisposeTypes type)
330         {
331             if (disposed)
332             {
333                 return;
334             }
335
336             if (type == DisposeTypes.Explicit)
337             {
338                 //Called by User
339                 //Release your own managed resources here.
340                 //You should release all of your own disposable objects here.
341
342             }
343
344             //Release your own unmanaged resources here.
345             //You should not access any managed member here except static instance.
346             //because the execution order of Finalizes is non-deterministic.
347
348             if (_applicationInitEventCallbackDelegate != null)
349             {
350                 this.InitSignal().Disconnect(_applicationInitEventCallbackDelegate);
351             }
352
353             if (_applicationTerminateEventCallbackDelegate != null)
354             {
355                 this.TerminateSignal().Disconnect(_applicationTerminateEventCallbackDelegate);
356             }
357
358             if (_applicationPauseEventCallbackDelegate != null)
359             {
360                 this.PauseSignal().Disconnect(_applicationPauseEventCallbackDelegate);
361             }
362
363             if (_applicationResumeEventCallbackDelegate != null)
364             {
365                 this.ResumeSignal().Disconnect(_applicationResumeEventCallbackDelegate);
366             }
367
368             if (_applicationResetEventCallbackDelegate != null)
369             {
370                 this.ResetSignal().Disconnect(_applicationResetEventCallbackDelegate);
371             }
372
373             if (_applicationResizeEventCallbackDelegate != null)
374             {
375                 this.ResizeSignal().Disconnect(_applicationResizeEventCallbackDelegate);
376             }
377
378             if (_applicationLanguageChangedEventCallbackDelegate != null)
379             {
380                 this.LanguageChangedSignal().Disconnect(_applicationLanguageChangedEventCallbackDelegate);
381             }
382
383             if (_applicationRegionChangedEventCallbackDelegate != null)
384             {
385                 this.RegionChangedSignal().Disconnect(_applicationRegionChangedEventCallbackDelegate);
386             }
387
388             if (_applicationBatteryLowEventCallbackDelegate != null)
389             {
390                 this.BatteryLowSignal().Disconnect(_applicationBatteryLowEventCallbackDelegate);
391             }
392
393             if (_applicationMemoryLowEventCallbackDelegate != null)
394             {
395                 this.MemoryLowSignal().Disconnect(_applicationMemoryLowEventCallbackDelegate);
396             }
397
398             if (_applicationAppControlEventCallbackDelegate != null)
399             {
400                 this.AppControlSignal().Disconnect(_applicationAppControlEventCallbackDelegate);
401             }
402
403             if (swigCPtr.Handle != global::System.IntPtr.Zero)
404             {
405                 if (swigCMemOwn)
406                 {
407                     swigCMemOwn = false;
408                     Interop.Application.delete_Application(swigCPtr);
409                 }
410                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
411             }
412
413             base.Dispose(type);
414         }
415
416         /// <since_tizen> 4 </since_tizen>
417         public enum BatteryStatus
418         {
419             Normal,
420             CriticallyLow,
421             PowerOff
422         };
423
424         /// <since_tizen> 4 </since_tizen>
425         public enum MemoryStatus
426         {
427             Normal,
428             Low,
429             CriticallyLow
430         };
431
432         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
433         private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
434         private DaliEventHandler<object, NUIApplicationInitEventArgs> _applicationInitEventHandler;
435         private NUIApplicationInitEventCallbackDelegate _applicationInitEventCallbackDelegate;
436
437
438         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
439         private delegate void NUIApplicationTerminateEventCallbackDelegate(IntPtr application);
440         private DaliEventHandler<object, NUIApplicationTerminatingEventArgs> _applicationTerminateEventHandler;
441         private NUIApplicationTerminateEventCallbackDelegate _applicationTerminateEventCallbackDelegate;
442
443
444         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
445         private delegate void NUIApplicationPauseEventCallbackDelegate(IntPtr application);
446         private DaliEventHandler<object, NUIApplicationPausedEventArgs> _applicationPauseEventHandler;
447         private NUIApplicationPauseEventCallbackDelegate _applicationPauseEventCallbackDelegate;
448
449         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
450         private delegate void NUIApplicationResumeEventCallbackDelegate(IntPtr application);
451         private DaliEventHandler<object, NUIApplicationResumedEventArgs> _applicationResumeEventHandler;
452         private NUIApplicationResumeEventCallbackDelegate _applicationResumeEventCallbackDelegate;
453
454         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
455         private delegate void NUIApplicationResetEventCallbackDelegate(IntPtr application);
456         private DaliEventHandler<object, NUIApplicationResetEventArgs> _applicationResetEventHandler;
457         private NUIApplicationResetEventCallbackDelegate _applicationResetEventCallbackDelegate;
458
459         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
460         private delegate void NUIApplicationResizeEventCallbackDelegate(IntPtr application);
461         private DaliEventHandler<object, NUIApplicationResizedEventArgs> _applicationResizeEventHandler;
462         private NUIApplicationResizeEventCallbackDelegate _applicationResizeEventCallbackDelegate;
463
464         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
465         private delegate void NUIApplicationLanguageChangedEventCallbackDelegate(IntPtr application);
466         private DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> _applicationLanguageChangedEventHandler;
467         private NUIApplicationLanguageChangedEventCallbackDelegate _applicationLanguageChangedEventCallbackDelegate;
468
469
470         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
471         private delegate void NUIApplicationRegionChangedEventCallbackDelegate(IntPtr application);
472         private DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> _applicationRegionChangedEventHandler;
473         private NUIApplicationRegionChangedEventCallbackDelegate _applicationRegionChangedEventCallbackDelegate;
474
475         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
476         private delegate void NUIApplicationBatteryLowEventCallbackDelegate(BatteryStatus status);
477         private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> _applicationBatteryLowEventHandler;
478         private NUIApplicationBatteryLowEventCallbackDelegate _applicationBatteryLowEventCallbackDelegate;
479
480         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
481         private delegate void NUIApplicationMemoryLowEventCallbackDelegate(MemoryStatus status);
482         private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> _applicationMemoryLowEventHandler;
483         private NUIApplicationMemoryLowEventCallbackDelegate _applicationMemoryLowEventCallbackDelegate;
484
485         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
486         private delegate void NUIApplicationAppControlEventCallbackDelegate(IntPtr application, IntPtr voidp);
487         private DaliEventHandler<object, NUIApplicationAppControlEventArgs> _applicationAppControlEventHandler;
488         private NUIApplicationAppControlEventCallbackDelegate _applicationAppControlEventCallbackDelegate;
489
490         /**
491           * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
492           *  provided by the user. Initialized signal is emitted when application is initialised
493           */
494         public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
495         {
496             add
497             {
498                 lock (this)
499                 {
500                     // Restricted to only one listener
501                     if (_applicationInitEventHandler == null)
502                     {
503                         _applicationInitEventHandler += value;
504
505                         _applicationInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationInit);
506                         this.InitSignal().Connect(_applicationInitEventCallbackDelegate);
507                     }
508                 }
509             }
510
511             remove
512             {
513                 lock (this)
514                 {
515                     if (_applicationInitEventHandler != null)
516                     {
517                         this.InitSignal().Disconnect(_applicationInitEventCallbackDelegate);
518                     }
519
520                     _applicationInitEventHandler -= value;
521                 }
522             }
523         }
524
525         // Callback for Application InitSignal
526         private void OnApplicationInit(IntPtr data)
527         {
528             // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
529             DisposeQueue.Instance.Initialize();
530
531             if (_applicationInitEventHandler != null)
532             {
533                 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
534                 e.Application = this;
535                 _applicationInitEventHandler.Invoke(this, e);
536             }
537
538         }
539
540         /**
541           * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
542           *  provided by the user. Terminated signal is emitted when application is terminating
543           */
544         public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
545         {
546             add
547             {
548                 lock (this)
549                 {
550                     // Restricted to only one listener
551                     if (_applicationTerminateEventHandler == null)
552                     {
553                         _applicationTerminateEventHandler += value;
554
555                         _applicationTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTerminate);
556                         this.TerminateSignal().Connect(_applicationTerminateEventCallbackDelegate);
557                     }
558                 }
559             }
560
561             remove
562             {
563                 lock (this)
564                 {
565                     if (_applicationTerminateEventHandler != null)
566                     {
567                         this.TerminateSignal().Disconnect(_applicationTerminateEventCallbackDelegate);
568                     }
569
570                     _applicationTerminateEventHandler -= value;
571                 }
572             }
573         }
574
575         // Callback for Application TerminateSignal
576         private void OnNUIApplicationTerminate(IntPtr data)
577         {
578             if (_applicationTerminateEventHandler != null)
579             {
580                 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
581                 e.Application = this;
582                 _applicationTerminateEventHandler.Invoke(this, e);
583             }
584             if (Window.Instance)
585             {
586                 Window.Instance.DisconnectNativeSignals();
587             }
588         }
589
590         /**
591           * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
592           * provided by the user. Paused signal is emitted when application is paused
593           */
594         public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
595         {
596             add
597             {
598                 lock (this)
599                 {
600                     // Restricted to only one listener
601                     if (_applicationPauseEventHandler == null)
602                     {
603                         _applicationPauseEventHandler += value;
604
605                         _applicationPauseEventCallbackDelegate = new NUIApplicationPauseEventCallbackDelegate(OnNUIApplicationPause);
606                         this.PauseSignal().Connect(_applicationPauseEventCallbackDelegate);
607                     }
608                 }
609             }
610
611             remove
612             {
613                 lock (this)
614                 {
615                     if (_applicationPauseEventHandler != null)
616                     {
617                         this.PauseSignal().Disconnect(_applicationPauseEventCallbackDelegate);
618                     }
619
620                     _applicationPauseEventHandler -= value;
621                 }
622             }
623         }
624
625         // Callback for Application PauseSignal
626         private void OnNUIApplicationPause(IntPtr data)
627         {
628             if (_applicationPauseEventHandler != null)
629             {
630                 NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
631                 e.Application = this;
632                 _applicationPauseEventHandler.Invoke(this, e);
633             }
634         }
635
636         /**
637           * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
638           *  provided by the user. Resumed signal is emitted when application is resumed
639           */
640         public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
641         {
642             add
643             {
644                 lock (this)
645                 {
646                     // Restricted to only one listener
647                     if (_applicationResumeEventHandler == null)
648                     {
649                         _applicationResumeEventHandler += value;
650
651                         _applicationResumeEventCallbackDelegate = new NUIApplicationResumeEventCallbackDelegate(OnNUIApplicationResume);
652                         this.ResumeSignal().Connect(_applicationResumeEventCallbackDelegate);
653                     }
654                 }
655             }
656
657             remove
658             {
659                 lock (this)
660                 {
661                     if (_applicationResumeEventHandler != null)
662                     {
663                         this.ResumeSignal().Disconnect(_applicationResumeEventCallbackDelegate);
664                     }
665
666                     _applicationResumeEventHandler -= value;
667                 }
668             }
669         }
670
671         // Callback for Application ResumeSignal
672         private void OnNUIApplicationResume(IntPtr data)
673         {
674             if (_applicationResumeEventHandler != null)
675             {
676                 NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
677                 e.Application = this;
678                 _applicationResumeEventHandler.Invoke(this, e);
679             }
680         }
681
682         /**
683           * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
684           *  provided by the user. Reset signal is emitted when application is reset
685           */
686         public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
687         {
688             add
689             {
690                 lock (this)
691                 {
692                     // Restricted to only one listener
693                     if (_applicationResetEventHandler == null)
694                     {
695                         _applicationResetEventHandler += value;
696
697                         _applicationResetEventCallbackDelegate = new NUIApplicationResetEventCallbackDelegate(OnNUIApplicationReset);
698                         this.ResetSignal().Connect(_applicationResetEventCallbackDelegate);
699                     }
700                 }
701             }
702
703             remove
704             {
705                 lock (this)
706                 {
707                     if (_applicationResetEventHandler != null)
708                     {
709                         this.ResetSignal().Disconnect(_applicationResetEventCallbackDelegate);
710                     }
711
712                     _applicationResetEventHandler -= value;
713                 }
714             }
715         }
716
717         // Callback for Application ResetSignal
718         private void OnNUIApplicationReset(IntPtr data)
719         {
720             if (_applicationResetEventHandler != null)
721             {
722                 NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
723                 e.Application = this;
724                 _applicationResetEventHandler.Invoke(this, e);
725             }
726         }
727
728         /**
729           * @brief Event for Resized signal which can be used to subscribe/unsubscribe the event handler
730           *  provided by the user. Resized signal is emitted when application is resized
731           */
732         public event DaliEventHandler<object, NUIApplicationResizedEventArgs> Resized
733         {
734             add
735             {
736                 lock (this)
737                 {
738                     // Restricted to only one listener
739                     if (_applicationResizeEventHandler == null)
740                     {
741                         _applicationResizeEventHandler += value;
742
743                         _applicationResizeEventCallbackDelegate = new NUIApplicationResizeEventCallbackDelegate(OnNUIApplicationResize);
744                         this.ResizeSignal().Connect(_applicationResizeEventCallbackDelegate);
745                     }
746                 }
747             }
748
749             remove
750             {
751                 lock (this)
752                 {
753                     if (_applicationResizeEventHandler != null)
754                     {
755                         this.ResizeSignal().Disconnect(_applicationResizeEventCallbackDelegate);
756                     }
757
758                     _applicationResizeEventHandler -= value;
759                 }
760             }
761         }
762
763         // Callback for Application ResizeSignal
764         private void OnNUIApplicationResize(IntPtr data)
765         {
766             if (_applicationResizeEventHandler != null)
767             {
768                 NUIApplicationResizedEventArgs e = new NUIApplicationResizedEventArgs();
769                 e.Application = this;
770                 _applicationResizeEventHandler.Invoke(this, e);
771             }
772         }
773
774         /**
775           * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
776           *  provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
777           */
778         public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
779         {
780             add
781             {
782                 lock (this)
783                 {
784                     // Restricted to only one listener
785                     if (_applicationLanguageChangedEventHandler == null)
786                     {
787                         _applicationLanguageChangedEventHandler += value;
788
789                         _applicationLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationLanguageChanged);
790                         this.LanguageChangedSignal().Connect(_applicationLanguageChangedEventCallbackDelegate);
791                     }
792                 }
793             }
794
795             remove
796             {
797                 lock (this)
798                 {
799                     if (_applicationLanguageChangedEventHandler != null)
800                     {
801                         this.LanguageChangedSignal().Disconnect(_applicationLanguageChangedEventCallbackDelegate);
802                     }
803
804                     _applicationLanguageChangedEventHandler -= value;
805                 }
806             }
807         }
808
809         // Callback for Application LanguageChangedSignal
810         private void OnNUIApplicationLanguageChanged(IntPtr data)
811         {
812             if (_applicationLanguageChangedEventHandler != null)
813             {
814                 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
815                 e.Application = this;
816                 _applicationLanguageChangedEventHandler.Invoke(this, e);
817             }
818         }
819
820         /**
821           * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
822           *  provided by the user. RegionChanged signal is emitted when the region of the device is changed.
823           */
824         public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
825         {
826             add
827             {
828                 lock (this)
829                 {
830                     // Restricted to only one listener
831                     if (_applicationRegionChangedEventHandler == null)
832                     {
833                         _applicationRegionChangedEventHandler += value;
834
835                         _applicationRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationRegionChanged);
836                         this.RegionChangedSignal().Connect(_applicationRegionChangedEventCallbackDelegate);
837                     }
838                 }
839             }
840
841             remove
842             {
843                 lock (this)
844                 {
845                     if (_applicationRegionChangedEventHandler != null)
846                     {
847                         this.RegionChangedSignal().Disconnect(_applicationRegionChangedEventCallbackDelegate);
848                     }
849
850                     _applicationRegionChangedEventHandler -= value;
851                 }
852             }
853         }
854
855         // Callback for Application RegionChangedSignal
856         private void OnNUIApplicationRegionChanged(IntPtr data)
857         {
858             if (_applicationRegionChangedEventHandler != null)
859             {
860                 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
861                 e.Application = this;
862                 _applicationRegionChangedEventHandler.Invoke(this, e);
863             }
864         }
865
866         /**
867           * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
868           * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
869           */
870         public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
871         {
872             add
873             {
874                 lock (this)
875                 {
876                     // Restricted to only one listener
877                     if (_applicationBatteryLowEventHandler == null)
878                     {
879                         _applicationBatteryLowEventHandler += value;
880
881                         _applicationBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationBatteryLow);
882                         this.BatteryLowSignal().Connect(_applicationBatteryLowEventCallbackDelegate);
883                     }
884                 }
885             }
886
887             remove
888             {
889                 lock (this)
890                 {
891                     if (_applicationBatteryLowEventHandler != null)
892                     {
893                         this.BatteryLowSignal().Disconnect(_applicationBatteryLowEventCallbackDelegate);
894                     }
895
896                     _applicationBatteryLowEventHandler -= value;
897                 }
898             }
899         }
900
901         // Callback for Application BatteryLowSignal
902         private void OnNUIApplicationBatteryLow(BatteryStatus status)
903         {
904             lock (this)
905             {
906                 NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
907
908                 // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
909                 e.BatteryStatus = status;
910                 _applicationBatteryLowEventHandler?.Invoke(this, e);
911             }
912         }
913
914         /**
915           * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
916           *  provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
917           */
918         public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
919         {
920             add
921             {
922                 lock (this)
923                 {
924                     // Restricted to only one listener
925                     if (_applicationMemoryLowEventHandler == null)
926                     {
927                         _applicationMemoryLowEventHandler += value;
928
929                         _applicationMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationMemoryLow);
930                         this.MemoryLowSignal().Connect(_applicationMemoryLowEventCallbackDelegate);
931                     }
932                 }
933             }
934
935             remove
936             {
937                 lock (this)
938                 {
939                     if (_applicationMemoryLowEventHandler != null)
940                     {
941                         this.MemoryLowSignal().Disconnect(_applicationMemoryLowEventCallbackDelegate);
942                     }
943
944                     _applicationMemoryLowEventHandler -= value;
945                 }
946             }
947         }
948
949         // Callback for Application MemoryLowSignal
950         private void OnNUIApplicationMemoryLow(MemoryStatus status)
951         {
952             lock (this)
953             {
954                 NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
955
956                 // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
957                 e.MemoryStatus = status;
958                 _applicationMemoryLowEventHandler?.Invoke(this, e);
959             }
960         }
961
962         /**
963           * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
964           *  provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
965           */
966         public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
967         {
968             add
969             {
970                 lock (this)
971                 {
972                     // Restricted to only one listener
973                     if (_applicationAppControlEventHandler == null)
974                     {
975                         _applicationAppControlEventHandler += value;
976
977                         _applicationAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationAppControl);
978                         this.AppControlSignal().Connect(_applicationAppControlEventCallbackDelegate);
979                     }
980                 }
981             }
982
983             remove
984             {
985                 lock (this)
986                 {
987                     if (_applicationAppControlEventHandler != null)
988                     {
989                         this.AppControlSignal().Disconnect(_applicationAppControlEventCallbackDelegate);
990                     }
991
992                     _applicationAppControlEventHandler -= value;
993                 }
994             }
995         }
996
997         // Callback for Application AppControlSignal
998         private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
999         {
1000             if (_applicationAppControlEventHandler != null)
1001             {
1002                 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1003                 e.VoidP = voidp;
1004                 e.Application = this;
1005                 _applicationAppControlEventHandler.Invoke(this, e);
1006             }
1007         }
1008
1009         private static Application _instance; // singleton
1010
1011         public static Application Instance
1012         {
1013             get
1014             {
1015                 return _instance;
1016             }
1017         }
1018
1019         public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
1020         {
1021             if (cPtr == global::System.IntPtr.Zero)
1022             {
1023                 return null;
1024             }
1025
1026             Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
1027             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1028             return ret;
1029         }
1030
1031         public static Application NewApplication()
1032         {
1033             return NewApplication("", Application.WindowMode.Opaque);
1034         }
1035
1036         public static Application NewApplication(string stylesheet)
1037         {
1038             return NewApplication(stylesheet, Application.WindowMode.Opaque);
1039         }
1040
1041         public static Application NewApplication(string stylesheet, Application.WindowMode windowMode)
1042         {
1043             // register all Views with the type registry, so that can be created / styled via JSON
1044             //ViewRegistryHelper.Initialize(); //moved to Application side.
1045
1046             Application ret = New(1, stylesheet, windowMode);
1047             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1048
1049             // set the singleton
1050             _instance = ret;
1051             return ret;
1052         }
1053
1054
1055         public static Application NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode)
1056         {
1057             Application ret = New(args, stylesheet, (Application.WindowMode)windowMode);
1058             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1059
1060             // set the singleton
1061             _instance = ret;
1062             return _instance;
1063         }
1064
1065         /// <summary>
1066         /// Ensures that the function passed in is called from the main loop when it is idle.
1067         /// </summary>
1068         /// <param name="func">The function to call</param>
1069         /// <returns>true if added successfully, false otherwise</returns>
1070         public bool AddIdle(System.Delegate func)
1071         {
1072             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
1073             System.IntPtr ip2 = Interop.Application.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
1074
1075             bool ret = Interop.Application.Application_AddIdle(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
1076
1077             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1078             return ret;
1079         }
1080
1081         /**
1082         * Outer::outer_method(int)
1083         */
1084         public static Application New()
1085         {
1086             Application ret = new Application(Interop.Application.Application_New__SWIG_0(), true);
1087             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1088             return ret;
1089         }
1090
1091         public static Application New(int argc)
1092         {
1093             Application ret = new Application(Interop.Application.Application_New__SWIG_1(argc), true);
1094             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1095             return ret;
1096         }
1097
1098         public static Application New(int argc, string stylesheet)
1099         {
1100             Application ret = new Application(Interop.Application.Application_New__SWIG_2(argc, stylesheet), true);
1101             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1102             return ret;
1103         }
1104
1105         public static Application New(int argc, string stylesheet, Application.WindowMode windowMode)
1106         {
1107             Application ret = new Application(Interop.Application.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true);
1108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1109             return ret;
1110         }
1111
1112         public static Application New(string[] args, string stylesheet, Application.WindowMode windowMode)
1113         {
1114             int argc = args.Length;
1115             string argvStr = string.Join(" ", args);
1116
1117             Application ret = new Application(NDalicPINVOKE.Application_New__MANUAL_4(argc, argvStr, stylesheet, (int)windowMode), true);
1118
1119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1120
1121             return ret;
1122         }
1123
1124         public static Application New(int argc, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
1125         {
1126             Application ret = new Application(Interop.Application.Application_New__SWIG_4(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1128             return ret;
1129         }
1130
1131         public Application() : this(Interop.Application.new_Application__SWIG_0(), true)
1132         {
1133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1134         }
1135
1136         public Application(Application application) : this(Interop.Application.new_Application__SWIG_1(Application.getCPtr(application)), true)
1137         {
1138             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1139         }
1140
1141         public Application Assign(Application application)
1142         {
1143             Application ret = new Application(Interop.Application.Application_Assign(swigCPtr, Application.getCPtr(application)), false);
1144             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1145             return ret;
1146         }
1147
1148         public void MainLoop()
1149         {
1150             NDalicPINVOKE.Application_MainLoop__SWIG_0(swigCPtr);
1151             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1152         }
1153
1154         internal void MainLoop(SWIGTYPE_p_Configuration__ContextLoss configuration)
1155         {
1156             Interop.Application.Application_MainLoop__SWIG_1(swigCPtr, SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration));
1157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1158         }
1159
1160         public void Lower()
1161         {
1162             Interop.Application.Application_Lower(swigCPtr);
1163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1164         }
1165
1166         public void Quit()
1167         {
1168             Interop.Application.Application_Quit(swigCPtr);
1169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1170         }
1171
1172         internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
1173         {
1174             bool ret = Interop.Application.Application_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
1175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1176             return ret;
1177         }
1178
1179         public Window GetWindow()
1180         {
1181             Window ret = new Window(Interop.Application.Application_GetWindow(swigCPtr), true);
1182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1183             return ret;
1184         }
1185
1186         public void ReplaceWindow(Rectangle windowPosition, string name)
1187         {
1188             Interop.Application.Application_ReplaceWindow(swigCPtr, Rectangle.getCPtr(windowPosition), name);
1189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1190         }
1191
1192         public static string GetResourcePath()
1193         {
1194             string ret = Interop.Application.Application_GetResourcePath();
1195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1196             return ret;
1197         }
1198
1199         public string GetLanguage()
1200         {
1201             string ret = Interop.Application.Application_GetLanguage(swigCPtr);
1202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1203             return ret;
1204         }
1205
1206         public string GetRegion()
1207         {
1208             string ret = Interop.Application.Application_GetRegion(swigCPtr);
1209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1210             return ret;
1211         }
1212
1213
1214         internal ApplicationSignal InitSignal()
1215         {
1216             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_InitSignal(swigCPtr), false);
1217             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1218             return ret;
1219         }
1220
1221         internal ApplicationSignal TerminateSignal()
1222         {
1223             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_TerminateSignal(swigCPtr), false);
1224             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1225             return ret;
1226         }
1227
1228         internal ApplicationSignal PauseSignal()
1229         {
1230             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_PauseSignal(swigCPtr), false);
1231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1232             return ret;
1233         }
1234
1235         internal ApplicationSignal ResumeSignal()
1236         {
1237             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResumeSignal(swigCPtr), false);
1238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1239             return ret;
1240         }
1241
1242         internal ApplicationSignal ResetSignal()
1243         {
1244             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResetSignal(swigCPtr), false);
1245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1246             return ret;
1247         }
1248
1249         internal ApplicationSignal ResizeSignal()
1250         {
1251             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResizeSignal(swigCPtr), false);
1252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1253             return ret;
1254         }
1255
1256         internal ApplicationControlSignal AppControlSignal()
1257         {
1258             ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.Application_AppControlSignal(swigCPtr), false);
1259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1260             return ret;
1261         }
1262
1263         internal ApplicationSignal LanguageChangedSignal()
1264         {
1265             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_LanguageChangedSignal(swigCPtr), false);
1266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1267             return ret;
1268         }
1269
1270         internal ApplicationSignal RegionChangedSignal()
1271         {
1272             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_RegionChangedSignal(swigCPtr), false);
1273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1274             return ret;
1275         }
1276
1277         internal LowBatterySignalType BatteryLowSignal()
1278         {
1279             LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.Application_LowBatterySignal(swigCPtr), false);
1280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1281             return ret;
1282         }
1283
1284         internal LowMemorySignalType MemoryLowSignal()
1285         {
1286             LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.Application_LowMemorySignal(swigCPtr), false);
1287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1288             return ret;
1289         }
1290
1291         /// <since_tizen> 3 </since_tizen>
1292         public enum WindowMode
1293         {
1294             Opaque = 0,
1295             Transparent = 1
1296         }
1297
1298     }
1299
1300 }