/*
* Copyright(c) 2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Tizen.NUI.Binding;
namespace Tizen.NUI
{
/**
* @brief Event arguments that passed via NUIApplicationInit signal
*/
internal class NUIApplicationInitEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being initialized
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationTerminate signal
*/
internal class NUIApplicationTerminatingEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being Terminated
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationPause signal
*/
internal class NUIApplicationPausedEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being Paused
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationResume signal
*/
internal class NUIApplicationResumedEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being Resumed
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationReset signal
*/
internal class NUIApplicationResetEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being Reset
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationLanguageChanged signal
*/
internal class NUIApplicationLanguageChangedEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being affected with Device's language change
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationRegionChanged signal
*/
internal class NUIApplicationRegionChangedEventArgs : EventArgs
{
private Application application;
/**
* @brief Application - is the application that is being affected with Device's region change
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationBatteryLow signal
*/
internal class NUIApplicationBatteryLowEventArgs : EventArgs
{
private Application.BatteryStatus status;
/**
* @brief Application - is the application that is being affected when the battery level of the device is low
*/
public Application.BatteryStatus BatteryStatus
{
get
{
return status;
}
set
{
status = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationMemoryLow signal
*/
internal class NUIApplicationMemoryLowEventArgs : EventArgs
{
private Application.MemoryStatus status;
/**
* @brief Application - is the application that is being affected when the memory level of the device is low
*/
public Application.MemoryStatus MemoryStatus
{
get
{
return status;
}
set
{
status = value;
}
}
}
/**
* @brief Event arguments that passed via NUIApplicationAppControl signal
*/
internal class NUIApplicationAppControlEventArgs : EventArgs
{
private Application application;
private IntPtr voidp;
/**
* @brief Application - is the application that is receiving the launch request from another application
*/
public Application Application
{
get
{
return application;
}
set
{
application = value;
}
}
/**
* @brief VoidP - contains the information about why the application is launched
*/
public IntPtr VoidP
{
get
{
return voidp;
}
set
{
voidp = value;
}
}
}
///
/// A class to get resources in current application.
///
public sealed class GetResourcesProvider
{
///
/// Get resources in current application.
///
static public IResourcesProvider Get()
{
return Tizen.NUI.Application.Current;
}
}
internal class Application : BaseHandle, IResourcesProvider, IElementConfiguration
{
static Application s_current;
ReadOnlyCollection logicalChildren;
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetCurrentApplication(Application value) => Current = value;
public static Application Current
{
get { return s_current; }
set
{
if (s_current == value)
return;
s_current = value;
}
}
internal override ReadOnlyCollection LogicalChildrenInternal
{
get { return logicalChildren ?? (logicalChildren = new ReadOnlyCollection(InternalChildren)); }
}
internal IResourceDictionary SystemResources { get; }
ObservableCollection InternalChildren { get; } = new ObservableCollection();
ResourceDictionary resources;
public bool IsResourcesCreated => resources != null;
public delegate void resChangeCb(object sender, ResourcesChangedEventArgs e);
internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
{
base.OnResourcesChanged(sender, e);
}
public ResourceDictionary XamlResources
{
get
{
if (resources == null)
{
resources = new ResourceDictionary();
int hashCode = resources.GetHashCode();
((IResourceDictionary)resources).ValuesChanged += OnResourcesChanged;
}
return resources;
}
set
{
if (resources == value)
return;
OnPropertyChanging();
if (resources != null)
((IResourceDictionary)resources).ValuesChanged -= OnResourcesChanged;
resources = value;
OnResourcesChanged(value);
if (resources != null)
((IResourceDictionary)resources).ValuesChanged += OnResourcesChanged;
OnPropertyChanged();
}
}
protected override void OnParentSet()
{
throw new InvalidOperationException("Setting a Parent on Application is invalid.");
}
[EditorBrowsable(EditorBrowsableState.Never)]
public static bool IsApplicationOrNull(Element element)
{
return element == null || element is Application;
}
internal override void OnParentResourcesChanged(IEnumerable> values)
{
if (values == null)
return;
if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
{
base.OnParentResourcesChanged(values);
return;
}
var innerKeys = new HashSet();
var changedResources = new List>();
foreach (KeyValuePair c in XamlResources)
innerKeys.Add(c.Key);
foreach (KeyValuePair value in values)
{
if (innerKeys.Add(value.Key))
changedResources.Add(value);
}
if (changedResources.Count != 0)
OnResourcesChanged(changedResources);
}
internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
{
SetCurrentApplication(this);
s_current = this;
}
protected override void Dispose(DisposeTypes type)
{
if (disposed)
{
return;
}
//Release your own unmanaged resources here.
//You should not access any managed member here except static instance.
//because the execution order of Finalizes is non-deterministic.
if (applicationInitEventCallbackDelegate != null)
{
initSignal?.Disconnect(applicationInitEventCallbackDelegate);
initSignal?.Dispose();
initSignal = null;
}
if (applicationTerminateEventCallbackDelegate != null)
{
terminateSignal?.Disconnect(applicationTerminateEventCallbackDelegate);
terminateSignal?.Dispose();
terminateSignal = null;
}
if (applicationPauseEventCallbackDelegate != null)
{
pauseSignal?.Disconnect(applicationPauseEventCallbackDelegate);
pauseSignal?.Dispose();
pauseSignal = null;
}
if (applicationResumeEventCallbackDelegate != null)
{
resumeSignal?.Disconnect(applicationResumeEventCallbackDelegate);
resumeSignal?.Dispose();
resumeSignal = null;
}
if (applicationResetEventCallbackDelegate != null)
{
resetSignal?.Disconnect(applicationResetEventCallbackDelegate);
resetSignal?.Dispose();
resetSignal = null;
}
if (applicationLanguageChangedEventCallbackDelegate != null)
{
languageChangedSignal?.Disconnect(applicationLanguageChangedEventCallbackDelegate);
languageChangedSignal?.Dispose();
languageChangedSignal = null;
}
if (applicationRegionChangedEventCallbackDelegate != null)
{
regionChangedSignal?.Disconnect(applicationRegionChangedEventCallbackDelegate);
regionChangedSignal?.Dispose();
regionChangedSignal = null;
}
if (applicationBatteryLowEventCallbackDelegate != null)
{
batteryLowSignal?.Disconnect(applicationBatteryLowEventCallbackDelegate);
batteryLowSignal?.Dispose();
batteryLowSignal = null;
}
if (applicationMemoryLowEventCallbackDelegate != null)
{
memoryLowSignal?.Disconnect(applicationMemoryLowEventCallbackDelegate);
memoryLowSignal?.Dispose();
memoryLowSignal = null;
}
if (applicationAppControlEventCallbackDelegate != null)
{
appControlSignal?.Disconnect(applicationAppControlEventCallbackDelegate);
appControlSignal?.Dispose();
appControlSignal = null;
}
window?.Dispose();
window = null;
base.Dispose(type);
}
protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
{
Interop.Application.DeleteApplication(swigCPtr);
}
public enum BatteryStatus
{
Normal,
CriticallyLow,
PowerOff
};
public enum MemoryStatus
{
Normal,
Low,
CriticallyLow
};
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
private DaliEventHandler