[NUI] Fix build warning[CA1064]
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / NUIApplication.cs
1 /*
2  * Copyright (c) 2019 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.Diagnostics.CodeAnalysis;
21 using System.Threading;
22 using System.Reflection;
23 using Tizen.Applications;
24 using Tizen.Applications.CoreBackend;
25 using Tizen.NUI.Binding;
26 using Tizen.NUI.Xaml;
27
28 namespace Tizen.NUI
29 {
30
31     /// <summary>
32     /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
33     /// </summary>
34     /// <since_tizen> 3 </since_tizen>
35     public class NUIApplication : CoreApplication
36     {
37         /// <summary>
38         /// The instance of ResourceManager.
39         /// </summary>
40         private static System.Resources.ResourceManager resourceManager = null;
41         private Size2D _windowSize2D = null;
42         private Position2D _windowPosition2D = null;
43         private TransitionOptions transitionOptions;
44
45         private static bool isPreLoad = false;
46
47         /// <summary>
48         /// The default constructor.
49         /// </summary>
50         /// <since_tizen> 3 </since_tizen>
51         public NUIApplication() : base(new NUICoreBackend())
52         {
53             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
54         }
55
56         /// <summary>
57         /// The constructor with window size and position.
58         /// </summary>
59         /// <param name="windowSize">The window size.</param>
60         /// <param name="windowPosition">The window position.</param>
61         /// <since_tizen> 5 </since_tizen>
62         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
63         [EditorBrowsable(EditorBrowsableState.Never)]
64         public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", WindowMode.Opaque, windowSize, windowPosition))
65         {
66             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
67             _windowSize2D = windowSize;
68             _windowPosition2D = windowPosition;
69         }
70
71         /// <summary>
72         /// The constructor with a stylesheet.
73         /// </summary>
74         /// <param name="styleSheet">The styleSheet url.</param>
75         /// <since_tizen> 3 </since_tizen>
76         public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
77         {
78             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
79         }
80
81         /// <summary>
82         /// The constructor with a stylesheet, window size, and position.
83         /// </summary>
84         /// <param name="styleSheet">The styleSheet URL.</param>
85         /// <param name="windowSize">The window size.</param>
86         /// <param name="windowPosition">The window position.</param>
87         /// <since_tizen> 5 </since_tizen>
88         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
89         [EditorBrowsable(EditorBrowsableState.Never)]
90         public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
91         {
92             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
93             _windowSize2D = windowSize;
94             _windowPosition2D = windowPosition;
95         }
96
97         /// <summary>
98         /// The constructor with a stylesheet and window mode.
99         /// </summary>
100         /// <param name="styleSheet">The styleSheet url.</param>
101         /// <param name="windowMode">The windowMode.</param>
102         /// <since_tizen> 3 </since_tizen>
103         public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
104         {
105             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
106         }
107
108         /// <summary>
109         /// The constructor with a stylesheet, window mode, window size, and position.
110         /// </summary>
111         /// <param name="styleSheet">The styleSheet URL.</param>
112         /// <param name="windowMode">The windowMode.</param>
113         /// <param name="windowSize">The window size.</param>
114         /// <param name="windowPosition">The window position.</param>
115         /// <since_tizen> 5 </since_tizen>
116         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
117         [EditorBrowsable(EditorBrowsableState.Never)]
118         public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
119         {
120             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
121             _windowSize2D = windowSize;
122             _windowPosition2D = windowPosition;
123         }
124
125         /// <summary>
126         /// Internal inhouse constructor with Graphics Backend Type
127         /// </summary>
128         /// <param name="backend"></param>
129         /// <param name="windowMode"></param>
130         /// <param name="windowSize"></param>
131         /// <param name="windowPosition"></param>
132         /// <param name="styleSheet"></param>
133         /// InhouseAPI, this could be opend in NextTizen
134         [Obsolete("Please do not use! This will be deprecated!")]
135         [EditorBrowsable(EditorBrowsableState.Never)]
136         public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
137         {
138             //windowMode and styleSheet will be added later. currenlty it's not working as expected.
139             Graphics.Backend = backend;
140             Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
141
142             if (windowSize != null) { _windowSize2D = windowSize; }
143             if (windowPosition != null) { _windowPosition2D = windowPosition; }
144             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
145         }
146
147         /// <summary>
148         /// Occurs whenever the application is resumed.
149         /// </summary>
150         /// <since_tizen> 4 </since_tizen>
151         public event EventHandler Resumed;
152
153         /// <summary>
154         /// Occurs whenever the application is paused.
155         /// </summary>
156         /// <since_tizen> 4 </since_tizen>
157         public event EventHandler Paused;
158
159         /// <summary>
160         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
161         /// </summary>
162         /// <since_tizen> 3 </since_tizen>
163         public enum WindowMode
164         {
165             /// <summary>
166             /// Opaque
167             /// </summary>
168             /// <since_tizen> 3 </since_tizen>
169             Opaque = 0,
170             /// <summary>
171             /// Transparent
172             /// </summary>
173             /// <since_tizen> 3 </since_tizen>
174             Transparent = 1
175         }
176
177         /// <summary>
178         /// ResourceManager to handle multilingual.
179         /// </summary>
180         /// <since_tizen> 4 </since_tizen>
181         public static System.Resources.ResourceManager MultilingualResourceManager
182         {
183             get
184             {
185                 return resourceManager;
186             }
187             set
188             {
189                 resourceManager = value;
190             }
191         }
192
193         /// <summary>
194         /// Gets the window instance.
195         /// </summary>
196         /// <since_tizen> 3 </since_tizen>
197         [Obsolete("Please do not use! This will be deprecated!")]
198         [EditorBrowsable(EditorBrowsableState.Never)]
199         public Window Window
200         {
201             get
202             {
203                 return GetDefaultWindow();
204             }
205         }
206
207         /// <summary>
208         /// Gets the default window.
209         /// </summary>
210         /// <returns>The default Window.</returns>
211         /// <since_tizen> 6 </since_tizen>
212         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
213         [EditorBrowsable(EditorBrowsableState.Never)]
214         public static Window GetDefaultWindow()
215         {
216             return Window.Instance;
217         }
218
219         internal Application ApplicationHandle
220         {
221             get
222             {
223                 return ((NUICoreBackend)this.Backend).ApplicationHandle;
224             }
225         }
226
227         /// <summary>
228         /// Register the assembly to XAML.
229         /// </summary>
230         /// <since_tizen> 5 </since_tizen>
231         public static void RegisterAssembly(Assembly assembly)
232         {
233             XamlParser.s_assemblies.Add(assembly);
234         }
235
236         /// <summary>
237         /// Runs the NUIApplication.
238         /// </summary>
239         /// <param name="args">Arguments from commandline.</param>
240         /// <since_tizen> 4 </since_tizen>
241         public override void Run(string[] args)
242         {
243             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
244             Backend.AddEventHandler(EventType.Resumed, OnResume);
245             Backend.AddEventHandler(EventType.Paused, OnPause);
246             base.Run(args);
247         }
248
249         /// <summary>
250         /// Exits the NUIApplication.
251         /// </summary>
252         /// <since_tizen> 4 </since_tizen>
253         public override void Exit()
254         {
255             base.Exit();
256         }
257
258         /// <summary>
259         /// Ensures that the function passed in is called from the main loop when it is idle.
260         /// </summary>
261         /// <param name="func">The function to call</param>
262         /// <returns>true if added successfully, false otherwise</returns>
263         /// <since_tizen> 4 </since_tizen>
264         public bool AddIdle(System.Delegate func)
265         {
266             return ((NUICoreBackend)this.Backend).AddIdle(func);
267         }
268
269         /// <summary>
270         /// Sets the number of frames per render.
271         /// </summary>
272         /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
273         /// <remarks>
274         /// Suggest this is a power of two:
275         /// 1 - render each vsync frame.
276         /// 2 - render every other vsync frame.
277         /// 4 - render every fourth vsync frame.
278         /// 8 - render every eighth vsync frame. <br />
279         /// For example, if an application runs on 60 FPS and SetRenderRefreshRate(2) is called, the frames per second will be changed to 30.
280         ///</remarks>
281         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
282         [EditorBrowsable(EditorBrowsableState.Never)]
283         public static void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
284         {
285             Adaptor.Instance.SetRenderRefreshRate(numberOfVSyncsPerRender);
286         }
287
288         /// <summary>
289         /// Overrides this method if you want to handle behavior.
290         /// </summary>
291         /// <since_tizen> 3 </since_tizen>
292         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
293         {
294             base.OnLocaleChanged(e);
295         }
296
297         /// <summary>
298         /// Overrides this method if you want to handle behavior.
299         /// </summary>
300         /// <since_tizen> 3 </since_tizen>
301         protected override void OnLowBattery(LowBatteryEventArgs e)
302         {
303             base.OnLowBattery(e);
304         }
305
306         /// <summary>
307         /// Overrides this method if you want to handle behavior.
308         /// </summary>
309         /// <since_tizen> 3 </since_tizen>
310         protected override void OnLowMemory(LowMemoryEventArgs e)
311         {
312             base.OnLowMemory(e);
313         }
314
315         /// <summary>
316         /// Overrides this method if you want to handle behavior.
317         /// </summary>
318         /// <since_tizen> 3 </since_tizen>
319         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
320         {
321             base.OnRegionFormatChanged(e);
322         }
323
324         /// <summary>
325         /// Overrides this method if you want to handle behavior.
326         /// </summary>
327         /// <since_tizen> 3 </since_tizen>
328         protected override void OnTerminate()
329         {
330             base.OnTerminate();
331         }
332
333         /// <summary>
334         /// Overrides this method if you want to handle behavior.
335         /// </summary>
336         /// <since_tizen> 3 </since_tizen>
337         protected virtual void OnPause()
338         {
339             Paused?.Invoke(this, EventArgs.Empty);
340         }
341
342         /// <summary>
343         /// Overrides this method if you want to handle behavior.
344         /// </summary>
345         /// <since_tizen> 3 </since_tizen>
346         protected virtual void OnResume()
347         {
348             Resumed?.Invoke(this, EventArgs.Empty);
349         }
350
351         /// <summary>
352         /// Overrides this method if you want to handle behavior.
353         /// </summary>
354         /// <since_tizen> 3 </since_tizen>
355         protected virtual void OnPreCreate()
356         {
357         }
358
359         /// <summary>
360         /// Overrides this method if you want to handle behavior.
361         /// </summary>
362         /// <since_tizen> 3 </since_tizen>
363         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
364         {
365             if (e != null)
366             {
367                 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
368                 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
369             }
370             base.OnAppControlReceived(e);
371         }
372
373         /// <summary>
374         /// Overrides this method if you want to handle behavior.
375         /// </summary>
376         /// <since_tizen> 3 </since_tizen>
377         protected override void OnCreate()
378         {
379             base.OnCreate();
380         }
381
382         /// <summary>
383         /// This is used to improve application launch performance.
384         /// </summary>
385         [EditorBrowsable(EditorBrowsableState.Never)]
386         static public void PreLoad()
387         {
388             Interop.Application.PreInitialize();
389             isPreLoad = true;
390         }
391
392         /// <summary>
393         /// This is used to improve application launch performance.
394         /// </summary>
395         [EditorBrowsable(EditorBrowsableState.Never)]
396         public void SendLaunchRequest(AppControl appControl)
397         {
398             transitionOptions.SendLaunchRequest(appControl);
399         }
400
401         /// <summary>
402         /// This is used to improve application launch performance.
403         /// </summary>
404         [EditorBrowsable(EditorBrowsableState.Never)]
405         public TransitionOptions TransitionOptions
406         {
407             get
408             {
409                 return transitionOptions;
410             }
411             set
412             {
413                 transitionOptions = value;
414             }
415         }
416
417         /// <summary>
418         /// Check if it is loaded as dotnet-loader-nui.
419         /// </summary>
420         static internal bool IsPreLoad
421         {
422             get
423             {
424                 return isPreLoad;
425             }
426         }
427     }
428
429     /// <summary>
430     /// Graphics Backend Type.
431     /// </summary>
432     [SuppressMessage("Microsoft.Design", "CA1052:StaticHolderTypesShouldBeStaticOrNotInheritable")]
433     [EditorBrowsable(EditorBrowsableState.Never)]
434     [Obsolete("Please do not use! This will be deprecated!")]
435     public class Graphics
436     {
437         /// <summary>
438         /// Graphics Backend Type.
439         /// </summary>
440         public enum BackendType
441         {
442             /// <summary>
443             /// The GLES backend.
444             /// </summary>
445             Gles,
446             /// <summary>
447             /// The Vulkan backend.
448             /// </summary>
449             Vulkan
450         }
451
452         /// <summary>
453         /// The backend used by the NUIApplication.
454         /// </summary>
455         [EditorBrowsable(EditorBrowsableState.Never)]
456         internal static BackendType Backend = BackendType.Gles;
457
458         internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
459         internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";
460     }
461
462 }