/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*
*/
+#if !PROFILE_TV
+#define ExternalThemeEnabled
+#endif
using System;
using System.ComponentModel;
using System.Reflection;
using Tizen.Applications;
using Tizen.Applications.CoreBackend;
-using Tizen.NUI.Binding;
using Tizen.NUI.Xaml;
namespace Tizen.NUI
/// The instance of ResourceManager.
/// </summary>
private static System.Resources.ResourceManager resourceManager = null;
- private Size2D _windowSize2D = null;
- private Position2D _windowPosition2D = null;
- private TransitionOptions transitionOptions;
- private string appId = null;
- internal static NUIApplication me;
+ private static string currentLoadedXaml = null;
- private static bool isPreLoad = false;
+ /// <summary>
+ /// The border window
+ /// </summary>
+ private bool borderEnabled = false;
+ private IBorderInterface borderInterface = null;
+
+ /// <summary>
+ /// Xaml loaded delegate.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public delegate void XamlLoadedHandler(string xamlName);
+
+ static NUIApplication()
+ {
+ Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
+ }
/// <summary>
/// The default constructor.
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
public NUIApplication() : base(new NUICoreBackend())
{
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- me = this;
}
/// <summary>
/// <param name="windowPosition">The window position.</param>
/// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
[EditorBrowsable(EditorBrowsableState.Never)]
- public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", WindowMode.Opaque, windowSize, windowPosition))
+ public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
{
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- _windowSize2D = windowSize;
- _windowPosition2D = windowPosition;
- me = this;
}
/// <summary>
/// </summary>
/// <param name="styleSheet">The styleSheet url.</param>
/// <since_tizen> 3 </since_tizen>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
{
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- me = this;
}
/// <summary>
/// <param name="windowPosition">The window position.</param>
/// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
[EditorBrowsable(EditorBrowsableState.Never)]
public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
{
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- _windowSize2D = windowSize;
- _windowPosition2D = windowPosition;
- me = this;
}
/// <summary>
/// <param name="styleSheet">The styleSheet url.</param>
/// <param name="windowMode">The windowMode.</param>
/// <since_tizen> 3 </since_tizen>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
{
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- me = this;
}
/// <summary>
/// <param name="windowPosition">The window position.</param>
/// <since_tizen> 5 </since_tizen>
/// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
[EditorBrowsable(EditorBrowsableState.Never)]
public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
{
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- _windowSize2D = windowSize;
- _windowPosition2D = windowPosition;
- me = this;
}
/// <summary>
/// <param name="windowSize"></param>
/// <param name="windowPosition"></param>
/// <param name="styleSheet"></param>
- /// InhouseAPI, this could be opend in NextTizen
- [Obsolete("Please do not use! This will be deprecated!")]
+ /// InhouseAPI, this could be opened in NextTizen
+ [Obsolete("Do not use! This will be deprecated!")]
[EditorBrowsable(EditorBrowsableState.Never)]
public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
{
- //windowMode and styleSheet will be added later. currenlty it's not working as expected.
+ //windowMode and styleSheet will be added later. currently it's not working as expected.
Graphics.Backend = backend;
Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
+ }
- if (windowSize != null) { _windowSize2D = windowSize; }
- if (windowPosition != null) { _windowPosition2D = windowPosition; }
- Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
- me = this;
+ /// <summary>
+ /// The constructor with theme option.
+ /// </summary>
+ /// <param name="option">The theme option.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ public NUIApplication(ThemeOptions option) : base(new NUICoreBackend())
+ {
+ ApplyThemeOption(option);
+ }
+
+ /// <summary>
+ /// The constructor with window size and position and theme option.
+ /// </summary>
+ /// <param name="windowSize">The window size.</param>
+ /// <param name="windowPosition">The window position.</param>
+ /// <param name="option">The theme option.</param>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public NUIApplication(Size2D windowSize, Position2D windowPosition, ThemeOptions option) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
+ {
+ ApplyThemeOption(option);
+ }
+
+ /// <summary>
+ /// The constructor with a stylesheet, window mode and default window type.
+ /// It is the only way to create an IME window.
+ /// </summary>
+ /// <param name="styleSheet">The styleSheet URL.</param>
+ /// <param name="windowMode">The windowMode.</param>
+ /// <param name="type">The default window type.</param>
+ /// <since_tizen> 9 </since_tizen>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ public NUIApplication(string styleSheet, WindowMode windowMode, WindowType type) : base(new NUICoreBackend(styleSheet, windowMode, type))
+ {
+ ExternalThemeManager.Initialize();
+ }
+
+ /// <summary>
+ /// The constructor with a stylesheet, size, position, boderInterface and window mode
+ /// </summary>
+ /// <param name="styleSheet">The styleSheet URL.</param>
+ /// <param name="windowSize">The window size.</param>
+ /// <param name="windowPosition">The window position.</param>
+ /// <param name="borderInterface"><see cref="Tizen.NUI.IBorderInterface"/>If borderInterface is null, defaultBorder is enabled.</param>
+ /// <param name="windowMode">The windowMode.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition, IBorderInterface borderInterface, WindowMode windowMode = WindowMode.Opaque) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
+ {
+ EnableBorder(borderInterface);
+ }
+
+ /// <summary>
+ /// The constructor with theme option and borderInterface.
+ /// </summary>
+ /// <param name="option">The theme option.</param>
+ /// <param name="borderInterface"><see cref="Tizen.NUI.IBorderInterface"/>If borderInterface is null, defaultBorder is enabled.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ public NUIApplication(ThemeOptions option, IBorderInterface borderInterface) : base(new NUICoreBackend())
+ {
+ EnableBorder(borderInterface);
+ ApplyThemeOption(option);
+ }
+
+ /// <summary>
+ /// The constructor with window size, position, theme option and borderInterface.
+ /// </summary>
+ /// <param name="windowSize">The window size.</param>
+ /// <param name="windowPosition">The window position.</param>
+ /// <param name="option">The theme option.</param>
+ /// <param name="borderInterface"><see cref="Tizen.NUI.IBorderInterface"/>If borderInterface is null, defaultBorder is enabled.</param>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public NUIApplication(Size2D windowSize, Position2D windowPosition, ThemeOptions option, IBorderInterface borderInterface) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
+ {
+ EnableBorder(borderInterface);
+ ApplyThemeOption(option);
+ }
+
+ /// <summary>
+ /// The constructor with a stylesheet, window mode, coretask
+ /// </summary>
+ /// <note>
+ /// There is the UI thread feature.
+ /// UI thread is an additional thread that an Application object creates. The thread is for UI events.
+ /// To enable the UI Thread, you have to pass CoreTask object using this contructor.
+ /// When the UI thread feature is enabled, The methods of CoreTask are emitted on the main thread,
+ /// and the NUIApplication's events are emitted on the UI thread.
+ /// If you want to handle windows or actors in cases like when the memory level of the device is low, you have to use the NUIApplication events, not the CoreTask methods.
+ /// The CoreTask is not for handling GUI.
+ /// Callbacks of the all events in NUIApplication except the CoreTask are emitted on the UI thread.
+ /// </note>
+ /// <param name="styleSheet">The styleSheet URL.</param>
+ /// <param name="windowMode">The windowMode.</param>
+ /// <param name="task">True If app creates a UI Thread</param>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public NUIApplication(string styleSheet, WindowMode windowMode, CoreTask task) : base(new NUICoreBackend(styleSheet, windowMode), task)
+ {
+ }
+
+ /// <summary>
+ /// The constructor with a stylesheet, window mode, window size, position, coretask
+ /// </summary>
+ /// <param name="styleSheet">The styleSheet URL.</param>
+ /// <param name="windowMode">The windowMode.</param>
+ /// <param name="windowSize">The window size.</param>
+ /// <param name="windowPosition">The window position.</param>
+ /// <param name="task">True If app creates a UI Thread</param>
+ [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition, CoreTask task) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition), task)
+ {
}
/// <summary>
public event EventHandler Paused;
/// <summary>
+ /// Xaml loaded event.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static event XamlLoadedHandler XamlLoaded;
+
+ /// <summary>
/// Enumeration for deciding whether a NUI application window is opaque or transparent.
/// </summary>
/// <since_tizen> 3 </since_tizen>
}
/// <summary>
+ /// Enumeration for theme options of the NUIApplication.
+ /// </summary>
+ [Flags]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum ThemeOptions : int
+ {
+ /// <summary>
+ /// No option specified.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ None = 0,
+
+ /// <summary>
+ /// Enable platform theme.
+ /// When this option is on, all views in the NUIApplication is affected by platform theme (e.g. light/dark).
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ PlatformThemeEnabled = 1 << 0,
+
+ /// <summary>
+ /// Sets the default value of View.ThemeChangeSensitive.
+ /// when this option is on, all views are made sensitive on theme changing by default.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ ThemeChangeSensitive = 1 << 1,
+ };
+
+ /// <summary>
+ /// Current loaded xaml's full name.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static string CurrentLoadedXaml
+ {
+ get
+ {
+ return currentLoadedXaml;
+ }
+ set
+ {
+ if (currentLoadedXaml != value)
+ {
+ currentLoadedXaml = value;
+ XamlLoaded?.Invoke(value);
+ }
+ }
+ }
+
+ /// <summary>
/// ResourceManager to handle multilingual.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// Gets the window instance.
/// </summary>
/// <since_tizen> 3 </since_tizen>
- [Obsolete("Please do not use! This will be deprecated!")]
+ [Obsolete("Do not use! This will be deprecated!")]
[EditorBrowsable(EditorBrowsableState.Never)]
public Window Window
{
{
get
{
- return appId;
+ return Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId;
}
}
/// <since_tizen> 3 </since_tizen>
protected virtual void OnPreCreate()
{
+ Tizen.Tracer.Begin("[NUI] OnPreCreate()");
+
+ if (borderEnabled)
+ {
+ GetDefaultWindow().EnableBorder(borderInterface, new Window.BorderCloseDelegate(Exit));
+ }
+
+ Tizen.Tracer.End();
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
protected override void OnCreate()
{
+ Tizen.Tracer.Begin("[NUI] OnCreate()");
+
base.OnCreate();
- appId = Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId;
+
+ Tizen.Tracer.End();
}
/// <summary>
/// This is used to improve application launch performance.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- static public void PreLoad()
+ static public void Preload()
{
Interop.Application.PreInitialize();
- isPreLoad = true;
+#if ExternalThemeEnabled
+ ThemeManager.Preload();
+#endif
+ IsPreload = true;
}
/// <summary>
- /// This is used to improve application launch performance.
+ /// Check if it is loaded as dotnet-loader-nui.
/// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void SendLaunchRequest(AppControl appControl)
- {
- transitionOptions.SendLaunchRequest(appControl);
- }
+ static internal bool IsPreload { get; set; }
- /// <summary>
- /// This is used to improve application launch performance.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public TransitionOptions TransitionOptions
+ private void ApplyThemeOption(ThemeOptions option)
{
- get
+ if ((option & ThemeOptions.PlatformThemeEnabled) != 0)
{
- return transitionOptions;
+ ThemeManager.PlatformThemeEnabled = true;
}
- set
+
+ if ((option & ThemeOptions.ThemeChangeSensitive) != 0)
{
- transitionOptions = value;
+ ThemeManager.ApplicationThemeChangeSensitive = true;
}
}
- /// <summary>
- /// Check if it is loaded as dotnet-loader-nui.
- /// </summary>
- static internal bool IsPreLoad
+ private void EnableBorder(IBorderInterface borderInterface)
{
- get
- {
- return isPreLoad;
- }
+ borderEnabled = true;
+ this.borderInterface = borderInterface;
}
}
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1052:StaticHolderTypesShouldBeStaticOrNotInheritable")]
[EditorBrowsable(EditorBrowsableState.Never)]
- [Obsolete("Please do not use! This will be deprecated!")]
+ [Obsolete("Do not use! This will be deprecated!")]
public class Graphics
{
/// <summary>
internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";
}
-
}