[ElmSharp] Fixed the crash issue of Calendar
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / NUIApplication.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Threading;
21 using Tizen.Applications;
22 using Tizen.Applications.CoreBackend;
23
24 namespace Tizen.NUI
25 {
26
27     /// <summary>
28     /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     public class NUIApplication : CoreApplication
32     {
33         /// <summary>
34         /// Occurs whenever the application is resumed.
35         /// </summary>
36         /// <since_tizen> 4 </since_tizen>
37         public event EventHandler Resumed;
38
39         /// <summary>
40         /// Occurs whenever the application is paused.
41         /// </summary>
42         /// <since_tizen> 4 </since_tizen>
43         public event EventHandler Paused;
44
45         /// <summary>
46         /// The instance of ResourceManager.
47         /// </summary>
48         private static System.Resources.ResourceManager resourceManager = null;
49
50         /// <summary>
51         /// The default constructor.
52         /// </summary>
53         /// <since_tizen> 3 </since_tizen>
54         public NUIApplication() : base(new NUICoreBackend())
55         {
56             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
57         }
58
59         /// <summary>
60         /// The constructor with a stylesheet.
61         /// </summary>
62         /// <param name="styleSheet">The styleSheet url.</param>
63         /// <since_tizen> 3 </since_tizen>
64         public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
65         {
66             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
67         }
68
69         /// <summary>
70         /// The constructor with a stylesheet and window mode.
71         /// </summary>
72         /// <param name="styleSheet">The styleSheet url.</param>
73         /// <param name="windowMode">The windowMode.</param>
74         /// <since_tizen> 3 </since_tizen>
75         public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
76         {
77             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
78         }
79
80         /// <summary>
81         /// Overrides this method if you want to handle behavior.
82         /// </summary>
83         /// <since_tizen> 3 </since_tizen>
84         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
85         {
86             base.OnLocaleChanged(e);
87         }
88
89         /// <summary>
90         /// Overrides this method if you want to handle behavior.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         protected override void OnLowBattery(LowBatteryEventArgs e)
94         {
95             base.OnLowBattery(e);
96         }
97
98         /// <summary>
99         /// Overrides this method if you want to handle behavior.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         protected override void OnLowMemory(LowMemoryEventArgs e)
103         {
104             base.OnLowMemory(e);
105         }
106
107         /// <summary>
108         /// Overrides this method if you want to handle behavior.
109         /// </summary>
110         /// <since_tizen> 3 </since_tizen>
111         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
112         {
113             base.OnRegionFormatChanged(e);
114         }
115
116         /// <summary>
117         /// Overrides this method if you want to handle behavior.
118         /// </summary>
119         /// <since_tizen> 3 </since_tizen>
120         protected override void OnTerminate()
121         {
122             base.OnTerminate();
123         }
124
125         /// <summary>
126         /// Overrides this method if you want to handle behavior.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>
129         protected virtual void OnPause()
130         {
131             Paused?.Invoke(this, EventArgs.Empty);
132         }
133
134         /// <summary>
135         /// Overrides this method if you want to handle behavior.
136         /// </summary>
137         /// <since_tizen> 3 </since_tizen>
138         protected virtual void OnResume()
139         {
140             Resumed?.Invoke(this, EventArgs.Empty);
141         }
142
143         /// <summary>
144         /// Overrides this method if you want to handle behavior.
145         /// </summary>
146         /// <since_tizen> 3 </since_tizen>
147         protected virtual void OnPreCreate()
148         {
149         }
150
151         /// <summary>
152         /// Overrides this method if you want to handle behavior.
153         /// </summary>
154         /// <since_tizen> 3 </since_tizen>
155         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
156         {
157             if (e != null)
158             {
159                 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
160                 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
161             }
162             base.OnAppControlReceived(e);
163         }
164
165         /// <summary>
166         /// Overrides this method if you want to handle behavior.
167         /// </summary>
168         /// <since_tizen> 3 </since_tizen>
169         protected override void OnCreate()
170         {
171             // This is also required to create DisposeQueue on main thread.
172             DisposeQueue disposeQ = DisposeQueue.Instance;
173             disposeQ.Initialize();
174             base.OnCreate();
175
176             // Dali's default layer is default center origin. need to change as top left.
177             // NUI's Layer is like a transparent film which covers entire window. (Layer is not an actor of Dali)
178             // otherwise, this makes ScreenPosition as wrong value.
179             Layer defaultLayer = Window.GetDefaultLayer();
180             defaultLayer.SetParentOrigin(Tizen.NUI.ParentOrigin.TopLeft);
181             defaultLayer.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
182         }
183
184         /// <summary>
185         /// Runs the NUIApplication.
186         /// </summary>
187         /// <param name="args">Arguments from commandline.</param>
188         /// <since_tizen> 4 </since_tizen>
189         public override void Run(string[] args)
190         {
191             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
192             Backend.AddEventHandler(EventType.Resumed, OnResume);
193             Backend.AddEventHandler(EventType.Paused, OnPause);
194             base.Run(args);
195         }
196
197         /// <summary>
198         /// Exits the NUIApplication.
199         /// </summary>
200         /// <since_tizen> 4 </since_tizen>
201         public override void Exit()
202         {
203             base.Exit();
204         }
205
206         /// <summary>
207         /// Ensures that the function passed in is called from the main loop when it is idle.
208         /// </summary>
209         /// <param name="func">The function to call</param>
210         /// <returns>true if added successfully, false otherwise</returns>
211         /// <since_tizen> 4 </since_tizen>
212         public bool AddIdle(System.Delegate func)
213         {
214             return ((NUICoreBackend)this.Backend).AddIdle(func);
215         }
216
217         /// <summary>
218         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
219         /// </summary>
220         /// <since_tizen> 3 </since_tizen>
221         public enum WindowMode
222         {
223             /// <summary>
224             /// Opaque
225             /// </summary>
226             /// <since_tizen> 3 </since_tizen>
227             Opaque = 0,
228             /// <summary>
229             /// Transparent
230             /// </summary>
231             /// <since_tizen> 3 </since_tizen>
232             Transparent = 1
233         }
234
235
236         internal Application ApplicationHandle
237         {
238             get
239             {
240                 return ((NUICoreBackend)this.Backend).ApplicationHandle;
241             }
242         }
243
244         /// <summary>
245         /// ResourceManager to handle multilingual.
246         /// </summary>
247         /// <since_tizen> 4 </since_tizen>
248         public static System.Resources.ResourceManager MultilingualResourceManager
249         {
250             get
251             {
252                 return resourceManager;
253             }
254             set
255             {
256                 resourceManager = value;
257             }
258         }
259
260         /// <summary>
261         /// Gets the window instance.
262         /// </summary>
263         /// <since_tizen> 3 </since_tizen>
264         [Obsolete("Please do not use! This will be deprecated!")]
265         [EditorBrowsable(EditorBrowsableState.Never)]
266         public Window Window
267         {
268             get
269             {
270                 return Window.Instance;
271             }
272         }
273     }
274 }