From: AdunFang <30402408+AdunFang@users.noreply.github.com> Date: Wed, 26 Jun 2019 04:31:19 +0000 (+0800) Subject: [NUI] Adjust directory (#903) X-Git-Tag: submit/tizen/20190626.133529~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=368328aebd879e0001fc169b128023f3794d2c97;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Adjust directory (#903) * [NUI] Fix memory leak * [NUI] Change some Xaml class to public --- diff --git a/src/Tizen.NUI/src/internal/Application.cs b/src/Tizen.NUI/src/internal/Application.cs index d51819900..f10567d5a 100755 --- a/src/Tizen.NUI/src/internal/Application.cs +++ b/src/Tizen.NUI/src/internal/Application.cs @@ -323,33 +323,15 @@ namespace Tizen.NUI } } - internal class Application : BaseHandle, IResourcesProvider, IApplicationController, IElementConfiguration + internal class Application : BaseHandle, IResourcesProvider, IElementConfiguration { static Application s_current; - Task> _propertiesTask; - readonly Lazy> _platformConfigurationRegistry; - - IAppIndexingProvider _appIndexProvider; ReadOnlyCollection _logicalChildren; - Page _mainPage; - static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1); - public IAppLinks AppLinks - { - get - { - if (_appIndexProvider == null) - throw new ArgumentException("No IAppIndexingProvider was provided"); - if (_appIndexProvider.AppLinks == null) - throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Xamarin.Forms.AppLinks"); - return _appIndexProvider.AppLinks; - } - } - [EditorBrowsable(EditorBrowsableState.Never)] public static void SetCurrentApplication(Application value) => Current = value; @@ -366,70 +348,15 @@ namespace Tizen.NUI } } - public Page MainPage - { - get { return _mainPage; } - set - { - if (value == null) - throw new ArgumentNullException("value"); - - if (_mainPage == value) - return; - - OnPropertyChanging(); - if (_mainPage != null) - { - InternalChildren.Remove(_mainPage); - _mainPage.Parent = null; - } - - _mainPage = value; - - if (_mainPage != null) - { - _mainPage.Parent = this; - _mainPage.NavigationProxy.Inner = NavigationProxy; - InternalChildren.Add(_mainPage); - } - OnPropertyChanged(); - } - } - - public IDictionary Properties - { - get - { - if (_propertiesTask == null) - { - _propertiesTask = GetPropertiesAsync(); - } - - return _propertiesTask.Result; - } - } - internal override ReadOnlyCollection LogicalChildrenInternal { get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection(InternalChildren)); } } - [EditorBrowsable(EditorBrowsableState.Never)] - public new NavigationProxy NavigationProxy { get; } - - [EditorBrowsable(EditorBrowsableState.Never)] - public int PanGestureId { get; set; } - internal IResourceDictionary SystemResources { get; } ObservableCollection InternalChildren { get; } = new ObservableCollection(); - [EditorBrowsable(EditorBrowsableState.Never)] - public void SetAppIndexingProvider(IAppIndexingProvider provider) - { - _appIndexProvider = provider; - } - ResourceDictionary _resources; public bool IsResourcesCreated => _resources != null; @@ -495,88 +422,11 @@ namespace Tizen.NUI } } - public event EventHandler ModalPopped; - - public event EventHandler ModalPopping; - - public event EventHandler ModalPushed; - - public event EventHandler ModalPushing; - - public event EventHandler PageAppearing; - - public event EventHandler PageDisappearing; - - - async void SaveProperties() - { - try - { - await SetPropertiesAsync(); - } - catch (Exception exc) - { - Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}"); - } - } - - public async Task SavePropertiesAsync() - { - if (Device.IsInvokeRequired) - { - Device.BeginInvokeOnMainThread(SaveProperties); - } - else - { - await SetPropertiesAsync(); - } - } - - // Don't use this unless there really is no better option - internal void SavePropertiesAsFireAndForget() - { - if (Device.IsInvokeRequired) - { - Device.BeginInvokeOnMainThread(SaveProperties); - } - else - { - SaveProperties(); - } - } - - public IPlatformElementConfiguration On() where T : IConfigPlatform - { - return _platformConfigurationRegistry.Value.On(); - } - - protected virtual void OnAppLinkRequestReceived(Uri uri) - { - } - protected override void OnParentSet() { throw new InvalidOperationException("Setting a Parent on Application is invalid."); } - protected virtual void OnResume() - { - } - - protected virtual void OnSleep() - { - } - - protected virtual void OnStart() - { - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static void ClearCurrent() - { - s_current = null; - } - [EditorBrowsable(EditorBrowsableState.Never)] public static bool IsApplicationOrNull(Element element) { @@ -603,151 +453,15 @@ namespace Tizen.NUI OnResourcesChanged(changedResources); } - internal event EventHandler PopCanceled; - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendOnAppLinkRequestReceived(Uri uri) - { - OnAppLinkRequestReceived(uri); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendResume() - { - s_current = this; - OnResume(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendSleep() - { - OnSleep(); - SavePropertiesAsFireAndForget(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public Task SendSleepAsync() - { - OnSleep(); - return SavePropertiesAsync(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendStart() - { - OnStart(); - } - - async Task> GetPropertiesAsync() - { - var deserializer = DependencyService.Get(); - if (deserializer == null) - { - Console.WriteLine("Startup", "No IDeserialzier was found registered"); - return new Dictionary(4); - } - - IDictionary properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false); - if (properties == null) - properties = new Dictionary(4); - - return properties; - } - - internal void OnPageAppearing(Page page) - => PageAppearing?.Invoke(this, page); - - internal void OnPageDisappearing(Page page) - => PageDisappearing?.Invoke(this, page); - - void OnModalPopped(Page modalPage) - => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage)); - - bool OnModalPopping(Page modalPage) - { - var args = new ModalPoppingEventArgs(modalPage); - ModalPopping?.Invoke(this, args); - return args.Cancel; - } - - void OnModalPushed(Page modalPage) - => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage)); - - void OnModalPushing(Page modalPage) - => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage)); - - void OnPopCanceled() - => PopCanceled?.Invoke(this, EventArgs.Empty); - - async Task SetPropertiesAsync() - { - await SaveSemaphore.WaitAsync(); - try - { - await DependencyService.Get()?.SerializePropertiesAsync(Properties); - } - finally - { - SaveSemaphore.Release(); - } - - } - - class NavigationImpl : NavigationProxy - { - readonly Application _owner; - - public NavigationImpl(Application owner) - { - _owner = owner; - } - - protected override async Task OnPopModal(bool animated) - { - Page modal = ModalStack[ModalStack.Count - 1]; - if (_owner.OnModalPopping(modal)) - { - _owner.OnPopCanceled(); - return null; - } - Page result = await base.OnPopModal(animated); - result.Parent = null; - _owner.OnModalPopped(result); - return result; - } - - protected override async Task OnPushModal(Page modal, bool animated) - { - _owner.OnModalPushing(modal); - - modal.Parent = _owner; - - if (modal.NavigationProxy.ModalStack.Count == 0) - { - modal.NavigationProxy.Inner = this; - await base.OnPushModal(modal, animated); - } - else - { - await base.OnPushModal(modal, animated); - modal.NavigationProxy.Inner = this; - } - - _owner.OnModalPushed(modal); - } - } - private global::System.Runtime.InteropServices.HandleRef swigCPtr; internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Application_SWIGUpcast(cPtr), cMemoryOwn) { - NavigationProxy = new NavigationImpl(this); SetCurrentApplication(this); - _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); - SendResume(); + s_current = this; } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj) @@ -1535,7 +1249,7 @@ namespace Tizen.NUI { Application ret = new Application(Interop.Application.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - ret.SendResume(); + s_current = ret; return ret; } diff --git a/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs b/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs index 47076ac1e..4c5ce060c 100755 --- a/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs +++ b/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs @@ -449,7 +449,6 @@ namespace Tizen.NUI.Xaml var elementType = element.GetType(); var binding = value.ConvertTo(typeof(BindingBase),pinfoRetriever:null,serviceProvider:null) as BindingBase; var bindable = element as BindableObject; - var nativeBindingService = DependencyService.Get(); if (binding == null) return false; @@ -459,12 +458,6 @@ namespace Tizen.NUI.Xaml return true; } - if (nativeBindingService != null && property != null && nativeBindingService.TrySetBinding(element, property, binding)) - return true; - - if (nativeBindingService != null && nativeBindingService.TrySetBinding(element, localName, binding)) - return true; - if (property != null) exception = new XamlParseException($"{elementType.Name} is not a BindableObject or does not support native bindings", lineInfo); @@ -477,7 +470,6 @@ namespace Tizen.NUI.Xaml var elementType = element.GetType(); var bindable = element as BindableObject; - var nativeBindingService = DependencyService.Get(); if (property == null) return false; @@ -509,9 +501,6 @@ namespace Tizen.NUI.Xaml return TryAddValue(bindable, property, value, serviceProvider); } - if (nativeBindingService != null && nativeBindingService.TrySetValue(element, property, convertedValue)) - return true; - exception = new XamlParseException($"{elementType.Name} is not a BindableObject or does not support setting native BindableProperties", lineInfo); return false; } diff --git a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs index 9801ff88a..e6ab251b7 100755 --- a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs +++ b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs @@ -225,7 +225,7 @@ namespace Tizen.NUI.Xaml if (!node.Properties.ContainsKey(XmlName.xFactoryMethod)) { //non-default ctor - object ret = Activator.CreateInstance(nodeType, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, null, arguments, CultureInfo.CurrentCulture); ; + object ret = Activator.CreateInstance(nodeType, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance | BindingFlags.OptionalParamBinding, null, arguments, CultureInfo.CurrentCulture); if (ret is Element) { if (null != Application.Current) diff --git a/src/Tizen.NUI/src/internal/Xaml/IMarkupExtension.cs b/src/Tizen.NUI/src/internal/Xaml/IMarkupExtension.cs deleted file mode 100755 index a6f26a54a..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IMarkupExtension.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Tizen.NUI.Xaml -{ - internal interface IMarkupExtension : IMarkupExtension - { - new T ProvideValue(IServiceProvider serviceProvider); - } - - internal interface IMarkupExtension - { - object ProvideValue(IServiceProvider serviceProvider); - } - - [AttributeUsage(AttributeTargets.Class, Inherited = false)] - internal sealed class AcceptEmptyServiceProviderAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/INativeValueConverterService.cs b/src/Tizen.NUI/src/internal/Xaml/INativeValueConverterService.cs deleted file mode 100755 index a5a60f273..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/INativeValueConverterService.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Tizen.NUI.Xaml.Internals -{ - internal interface INativeValueConverterService - { - bool ConvertTo(object value, Type toType, out object nativeValue); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/IProvideValueTarget.cs b/src/Tizen.NUI/src/internal/Xaml/IProvideValueTarget.cs deleted file mode 100755 index cdf7b79c1..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IProvideValueTarget.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Tizen.NUI.Xaml -{ - internal interface IProvideValueTarget - { - object TargetObject { get; } - object TargetProperty { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/IReferenceProvider.cs b/src/Tizen.NUI/src/internal/Xaml/IReferenceProvider.cs deleted file mode 100755 index 89cb53fef..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IReferenceProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Tizen.NUI.Xaml -{ - internal interface IReferenceProvider - { - object FindByName(string name); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/IRootObjectProvider.cs b/src/Tizen.NUI/src/internal/Xaml/IRootObjectProvider.cs deleted file mode 100755 index 057ae542b..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IRootObjectProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Tizen.NUI.Xaml -{ - internal interface IRootObjectProvider - { - object RootObject { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/IValueProvider.cs b/src/Tizen.NUI/src/internal/Xaml/IValueProvider.cs deleted file mode 100755 index a93a3e5ba..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IValueProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Tizen.NUI.Xaml -{ - internal interface IValueProvider - { - object ProvideValue(IServiceProvider serviceProvider); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/IXamlTypeResolver.cs b/src/Tizen.NUI/src/internal/Xaml/IXamlTypeResolver.cs deleted file mode 100755 index fbf2d37b3..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IXamlTypeResolver.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Tizen.NUI.Xaml -{ - internal interface IXamlTypeResolver - { - Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider = null); - bool TryResolve(string qualifiedTypeName, out Type type); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/IXmlLineInfoProvider.cs b/src/Tizen.NUI/src/internal/Xaml/IXmlLineInfoProvider.cs deleted file mode 100755 index da9ac5a9c..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/IXmlLineInfoProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Xml; - -namespace Tizen.NUI.Xaml -{ - internal interface IXmlLineInfoProvider - { - IXmlLineInfo XmlLineInfo { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/ArrayExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/ArrayExtension.cs deleted file mode 100755 index ce20e18d2..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/ArrayExtension.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty("Items")] - [AcceptEmptyServiceProvider] - internal class ArrayExtension : IMarkupExtension - { - public ArrayExtension() - { - Items = new List(); - } - - public IList Items { get; } - - public Type Type { get; set; } - - public Array ProvideValue(IServiceProvider serviceProvider) - { - if (Type == null) - throw new InvalidOperationException("Type argument mandatory for x:Array extension"); - - if (Items == null) - return null; - - var array = Array.CreateInstance(Type, Items.Count); - for (var i = 0; i < Items.Count; i++) - ((IList)array)[i] = Items[i]; - - return array; - } - - object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - return (this as IMarkupExtension).ProvideValue(serviceProvider); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/BindingExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/BindingExtension.cs deleted file mode 100755 index 927678304..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/BindingExtension.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty("Path")] - [AcceptEmptyServiceProvider] - internal sealed class BindingExtension : IMarkupExtension - { - public string Path { get; set; } = Binding.Binding.SelfPath; - public BindingMode Mode { get; set; } = BindingMode.Default; - - public IValueConverter Converter { get; set; } - - public object ConverterParameter { get; set; } - - public string StringFormat { get; set; } - - public object Source { get; set; } - - public string UpdateSourceEventName { get; set; } - - public object TargetNullValue { get; set; } - - public object FallbackValue { get; set; } - - public TypedBindingBase TypedBinding { get; set; } - - BindingBase IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - if (TypedBinding == null) - return new Tizen.NUI.Binding.Binding(Path, Mode, Converter, ConverterParameter, StringFormat, Source) - { - UpdateSourceEventName = UpdateSourceEventName, - FallbackValue = FallbackValue, - TargetNullValue = TargetNullValue, - }; - - TypedBinding.Mode = Mode; - TypedBinding.Converter = Converter; - TypedBinding.ConverterParameter = ConverterParameter; - TypedBinding.StringFormat = StringFormat; - TypedBinding.Source = Source; - TypedBinding.UpdateSourceEventName = UpdateSourceEventName; - TypedBinding.FallbackValue = FallbackValue; - TypedBinding.TargetNullValue = TargetNullValue; - return TypedBinding; - } - - object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - return (this as IMarkupExtension).ProvideValue(serviceProvider); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/DynamicResourceExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/DynamicResourceExtension.cs deleted file mode 100755 index 2991b81a2..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/DynamicResourceExtension.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Tizen.NUI.Binding; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty("Key")] - internal sealed class DynamicResourceExtension : IMarkupExtension - { - public string Key { get; set; } - - public object ProvideValue(IServiceProvider serviceProvider) - { - return ((IMarkupExtension)this).ProvideValue(serviceProvider); - } - - DynamicResource IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - if (Key == null) - { - var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; - var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); - throw new XamlParseException("DynamicResource markup require a Key", lineInfo); - } - return new DynamicResource(Key); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/NullExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/NullExtension.cs deleted file mode 100755 index b5a310c3e..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/NullExtension.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Tizen.NUI.Xaml -{ - [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.NullExtension")] - [AcceptEmptyServiceProvider] - internal class NullExtension : IMarkupExtension - { - public object ProvideValue(IServiceProvider serviceProvider) - { - return null; - } - } -} diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/ReferenceExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/ReferenceExtension.cs deleted file mode 100755 index b825389b7..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/ReferenceExtension.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.Xaml.Internals; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty("Name")] - internal class ReferenceExtension : IMarkupExtension - { - public string Name { get; set; } - - public object ProvideValue(IServiceProvider serviceProvider) - { - if (serviceProvider == null) - throw new ArgumentNullException(nameof(serviceProvider)); - var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues; - if (valueProvider == null) - throw new ArgumentException("serviceProvider does not provide an IProvideValueTarget"); - var namescopeprovider = serviceProvider.GetService(typeof (INameScopeProvider)) as INameScopeProvider; - if (namescopeprovider != null && namescopeprovider.NameScope != null) - { - var value = namescopeprovider.NameScope.FindByName(Name); - if (value != null) - return value; - } - - foreach (var target in valueProvider.ParentObjects) - { - var ns = target as INameScope; - if (ns == null) - continue; - var value = ns.FindByName(Name); - if (value != null) - return value; - } - - var lineInfo = (serviceProvider?.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo ?? new XmlLineInfo(); - throw new XamlParseException($"Can not find the object referenced by `{Name}`", lineInfo); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StaticExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StaticExtension.cs deleted file mode 100755 index 5a4151d35..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StaticExtension.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Xml; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty(nameof(Member))] - [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.StaticExtension")] - internal class StaticExtension : IMarkupExtension - { - public string Member { get; set; } - - public object ProvideValue(IServiceProvider serviceProvider) - { - IXmlLineInfoProvider lineInfoProvider; - IXmlLineInfo lineInfo; - - if (serviceProvider == null) - throw new ArgumentNullException(nameof(serviceProvider)); - var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver; - if (typeResolver == null) - throw new ArgumentException("No IXamlTypeResolver in IServiceProvider"); - - if (string.IsNullOrEmpty(Member) || !Member.Contains(".")) - { - lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; - lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); - throw new XamlParseException("Syntax for x:Static is [Member=][prefix:]typeName.staticMemberName", lineInfo); - } - - var dotIdx = Member.LastIndexOf('.'); - var typename = Member.Substring(0, dotIdx); - var membername = Member.Substring(dotIdx + 1); - - var type = typeResolver.Resolve(typename, serviceProvider); - - var pinfo = type.GetRuntimeProperties().FirstOrDefault(pi => pi.GetMethod != null && pi.Name == membername && pi.GetMethod.IsStatic); - if (pinfo != null) - return pinfo.GetMethod?.Invoke(null, Array.Empty()); - - var finfo = type.GetRuntimeFields().FirstOrDefault(fi => fi.Name == membername && fi.IsStatic); - if (finfo != null) - return finfo.GetValue(null); - - lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; - lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); - throw new XamlParseException($"No static member found for {Member}", lineInfo); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StaticResourceExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StaticResourceExtension.cs deleted file mode 100755 index c5577cdbe..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StaticResourceExtension.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Xml; -using System.Reflection; -using System.Linq; -using Tizen.NUI.Binding; - - -namespace Tizen.NUI.Xaml -{ - [ContentProperty("Key")] - internal sealed class StaticResourceExtension : IMarkupExtension - { - public string Key { get; set; } - - public object ProvideValue(IServiceProvider serviceProvider) - { - if (serviceProvider == null) - throw new ArgumentNullException(nameof(serviceProvider)); - if (Key == null) { - var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; - var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); - throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo); - } - var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues; - if (valueProvider == null) - throw new ArgumentException(); - var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; - var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null; - object resource = null; - - foreach (var p in valueProvider.ParentObjects) { - var irp = p as IResourcesProvider; - var resDict = irp != null && irp.IsResourcesCreated ? irp.XamlResources : p as ResourceDictionary; - if (resDict == null) - continue; - if (resDict.TryGetValue(Key, out resource)) - break; - } - resource = resource ?? GetApplicationLevelResource(Key, xmlLineInfo); - - var bp = valueProvider.TargetProperty as BindableProperty; - var pi = valueProvider.TargetProperty as PropertyInfo; - var propertyType = bp?.ReturnType ?? pi?.PropertyType; - if (propertyType == null) { - if (resource != null) { - if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) { - // This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty - var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() }); - if (method != null) { - resource = method.Invoke(null, new[] { resource }); - } - } - } - return resource; - } - if (propertyType.IsAssignableFrom(resource?.GetType())) - return resource; - var implicit_op = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType) - ?? propertyType.GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType); - if (implicit_op != null) - return implicit_op.Invoke(resource, new [] { resource }); - - if (resource != null) { - //Special case for https://bugzilla.xamarin.com/show_bug.cgi?id=59818 - //On OnPlatform, check for an opImplicit from the targetType - if ( Device.Flags != null - && Device.Flags.Contains("xamlDoubleImplicitOpHack") - && resource.GetType().GetTypeInfo().IsGenericType - && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>))) { - var tType = resource.GetType().GenericTypeArguments[0]; - var opImplicit = tType.GetImplicitConversionOperator(fromType: tType, toType: propertyType) - ?? propertyType.GetImplicitConversionOperator(fromType: tType, toType: propertyType); - - if (opImplicit != null) { - //convert the OnPlatform to T - var opPlatformImplicitConversionOperator = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: tType); - resource = opPlatformImplicitConversionOperator?.Invoke(null, new[] { resource }); - - //and convert to toType - resource = opImplicit.Invoke(null, new[] { resource }); - return resource; - } - } - } - return resource; - } - - internal object GetApplicationLevelResource(string key, IXmlLineInfo xmlLineInfo) - { - object resource = null; - if (Application.Current == null || !((IResourcesProvider)Application.Current).IsResourcesCreated || !Application.Current.XamlResources.TryGetValue(Key, out resource)) - throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo); - return resource; - } - } -} diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StyleSheetExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StyleSheetExtension.cs deleted file mode 100755 index 2b4c48371..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/StyleSheetExtension.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Xml; -using Tizen.NUI.StyleSheets; -using System.Reflection; -using System.IO; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty(nameof(Style))] - [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")] - internal sealed class StyleSheetExtension : IValueProvider - { - public string Style { get; set; } - public Uri Source { get; set; } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - IXmlLineInfo lineInfo; - - if (!string.IsNullOrEmpty(Style) && Source != null) { - lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; - throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo); - } - - if (Source != null) { - lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; - if (Source.IsAbsoluteUri) - throw new XamlParseException($"Source only accepts Relative URIs", lineInfo); - - var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType(); - if (rootObjectType == null) - return null; - var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType); - var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath); - var resString = DependencyService.Get()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo); - return StyleSheet.FromString(resString); - } - - if (!string.IsNullOrEmpty(Style)) { - using (var reader = new StringReader(Style)) - return StyleSheet.FromReader(reader); - } - - lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; - throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/TemplateBindingExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/TemplateBindingExtension.cs deleted file mode 100755 index d06f2420d..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/TemplateBindingExtension.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty("Path")] - [AcceptEmptyServiceProvider] - internal sealed class TemplateBindingExtension : IMarkupExtension - { - internal TemplateBindingExtension() - { - Mode = BindingMode.Default; - Path = Tizen.NUI.Binding.Binding.SelfPath; - } - - public string Path { get; set; } - - public BindingMode Mode { get; set; } - - public IValueConverter Converter { get; set; } - - public object ConverterParameter { get; set; } - - public string StringFormat { get; set; } - - BindingBase IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - return new TemplateBinding(Path, Mode, Converter, ConverterParameter, StringFormat); - } - - object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - return (this as IMarkupExtension).ProvideValue(serviceProvider); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/TypeExtension.cs b/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/TypeExtension.cs deleted file mode 100755 index 9bcd36b9c..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/MarkupExtensions/TypeExtension.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ContentProperty(nameof(TypeName))] - [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.TypeExtension")] - internal class TypeExtension : IMarkupExtension - { - public string TypeName { get; set; } - - public Type ProvideValue(IServiceProvider serviceProvider) - { - if (string.IsNullOrEmpty(TypeName)) - throw new InvalidOperationException("TypeName isn't set."); - if (serviceProvider == null) - throw new ArgumentNullException(nameof(serviceProvider)); - var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver; - if (typeResolver == null) - throw new ArgumentException("No IXamlTypeResolver in IServiceProvider"); - - return typeResolver.Resolve(TypeName, serviceProvider); - } - - object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) - { - return (this as IMarkupExtension).ProvideValue(serviceProvider); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/TypeConversionAttribute.cs b/src/Tizen.NUI/src/internal/Xaml/TypeConversionAttribute.cs deleted file mode 100755 index 2b81846ff..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/TypeConversionAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace Tizen.NUI.Xaml -{ - [System.AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)] - internal sealed class TypeConversionAttribute : Attribute - { - public Type TargetType { get; private set; } - - public TypeConversionAttribute(Type targetType) - { - TargetType = targetType; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs b/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs index 8f465936f..80341aec4 100755 --- a/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs +++ b/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs @@ -202,12 +202,6 @@ namespace Tizen.NUI.Xaml } } - var nativeValueConverterService = DependencyService.Get(); - - object nativeValue = null; - if (nativeValueConverterService != null && nativeValueConverterService.ConvertTo(value, toType, out nativeValue)) - return nativeValue; - return value; } diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlCompilationAttribute.cs b/src/Tizen.NUI/src/internal/Xaml/XamlCompilationAttribute.cs deleted file mode 100755 index df4a1cb1c..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/XamlCompilationAttribute.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -namespace Tizen.NUI.Xaml -{ - [Flags] - internal enum XamlCompilationOptions - { - Skip = 1 << 0, - Compile = 1 << 1 - } - - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class, Inherited = false)] - internal sealed class XamlCompilationAttribute : Attribute - { - public XamlCompilationAttribute(XamlCompilationOptions xamlCompilationOptions) - { - XamlCompilationOptions = xamlCompilationOptions; - } - - public XamlCompilationOptions XamlCompilationOptions { get; set; } - } - - internal static class XamlCExtensions - { - public static bool IsCompiled(this Type type) - { - var attr = type.GetTypeInfo().GetCustomAttribute(); - if (attr != null) - return attr.XamlCompilationOptions == XamlCompilationOptions.Compile; - attr = type.GetTypeInfo().Module.GetCustomAttribute(); - if (attr != null) - return attr.XamlCompilationOptions == XamlCompilationOptions.Compile; - attr = type.GetTypeInfo().Assembly.GetCustomAttribute(); - if (attr != null) - return attr.XamlCompilationOptions == XamlCompilationOptions.Compile; - - return false; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlFilePathAttribute.cs b/src/Tizen.NUI/src/internal/Xaml/XamlFilePathAttribute.cs deleted file mode 100755 index 982479d79..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/XamlFilePathAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace Tizen.NUI.Xaml -{ - [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] - internal sealed class XamlFilePathAttribute : Attribute - { - public XamlFilePathAttribute([CallerFilePath] string filePath = "") - { - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlLoader.cs b/src/Tizen.NUI/src/internal/Xaml/XamlLoader.cs index 601ef7d89..c3c8bc6d0 100755 --- a/src/Tizen.NUI/src/internal/Xaml/XamlLoader.cs +++ b/src/Tizen.NUI/src/internal/Xaml/XamlLoader.cs @@ -39,13 +39,16 @@ using Tizen.NUI.Binding.Internals; namespace Tizen.NUI.Xaml.Internals { - [Obsolete("Replaced by ResourceLoader")] - internal static class XamlLoader + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete ("Replaced by ResourceLoader")] + public static class XamlLoader { static Func xamlFileProvider; - public static Func XamlFileProvider - { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static Func XamlFileProvider { get { return xamlFileProvider; } internal set { diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlParseException.cs b/src/Tizen.NUI/src/internal/Xaml/XamlParseException.cs deleted file mode 100755 index 27a5841ba..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/XamlParseException.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Diagnostics; -using System.Text; -using System.Xml; - -namespace Tizen.NUI.Xaml -{ - internal class XamlParseException : Exception - { - readonly string _unformattedMessage; - - static private StringBuilder GetStackInfo() - { - StringBuilder ret = new StringBuilder("\nStack:\n"); - - StackTrace st = new StackTrace(); - - for (int i = 2; i < st.FrameCount; i++) - { - StackFrame sf = st.GetFrame(i); - ret.AppendFormat("File:{0}, Method:{1}, Line:{2}\n", sf.GetFileName(), sf.GetMethod().Name, sf.GetFileLineNumber()); - } - - return ret; - } - - public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message + GetStackInfo(), xmlInfo), innerException) - { - _unformattedMessage = message; - XmlInfo = xmlInfo; - } - - public IXmlLineInfo XmlInfo { get; private set; } - - internal string UnformattedMessage - { - get { return _unformattedMessage ?? Message; } - } - - static string FormatMessage(string message, IXmlLineInfo xmlinfo) - { - if (xmlinfo == null || !xmlinfo.HasLineInfo()) - return message; - return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlParser.cs b/src/Tizen.NUI/src/internal/Xaml/XamlParser.cs index c2707dd3f..fa00be6dc 100755 --- a/src/Tizen.NUI/src/internal/Xaml/XamlParser.cs +++ b/src/Tizen.NUI/src/internal/Xaml/XamlParser.cs @@ -274,22 +274,8 @@ namespace Tizen.NUI.Xaml foreach (var kvp in xmlns) { var prefix = kvp.Key; - string typeName = null, ns = null, asm = null, targetPlatform = null; - XmlnsHelper.ParseXmlns(kvp.Value, out typeName, out ns, out asm, out targetPlatform); - if (targetPlatform == null) - continue; - try { - if (targetPlatform != Device.RuntimePlatform) - { - // Special case for Windows backward compatibility - if (targetPlatform == "Windows" && Device.RuntimePlatform == Device.UWP) - continue; - - prefixes.Add(prefix); - } - } catch (InvalidOperationException) { - prefixes.Add(prefix); - } + string typeName = null, ns = null, asm = null; + XmlnsHelper.ParseXmlns(kvp.Value, out typeName, out ns, out asm); } return prefixes; } @@ -355,7 +341,7 @@ namespace Tizen.NUI.Xaml if (lookupAssemblies.Count == 0) { string ns, asmstring, _; - XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring, out _); + XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring); lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns) { AssemblyName = asmstring ?? currentAssembly.FullName }); diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlResourceIdAttribute.cs b/src/Tizen.NUI/src/internal/Xaml/XamlResourceIdAttribute.cs deleted file mode 100755 index b95bfcf40..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/XamlResourceIdAttribute.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Reflection; - -namespace Tizen.NUI.Xaml -{ - [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)] - internal sealed class XamlResourceIdAttribute : Attribute - { - public string ResourceId { get; set; } - public string Path { get; set; } - public Type Type { get; set; } - - public XamlResourceIdAttribute(string resourceId, string path, Type type) - { - ResourceId = resourceId; - Path = path; - Type = type; - } - - internal static string GetResourceIdForType(Type type) - { - var assembly = type.GetTypeInfo().Assembly; - foreach (var xria in assembly.GetCustomAttributes()) { - if (xria.Type == type) - return xria.ResourceId; - } - return null; - } - - internal static string GetPathForType(Type type) - { - var assembly = type.GetTypeInfo().Assembly; - foreach (var xria in assembly.GetCustomAttributes()) { - if (xria.Type == type) - return xria.Path; - } - return null; - } - - internal static string GetResourceIdForPath(Assembly assembly, string path) - { - foreach (var xria in assembly.GetCustomAttributes()) { - if (xria.Path == path) - return xria.ResourceId; - } - return null; - } - - internal static Type GetTypeForResourceId(Assembly assembly, string resourceId) - { - foreach (var xria in assembly.GetCustomAttributes()) { - if (xria.ResourceId == resourceId) - return xria.Type; - } - return null; - } - - internal static Type GetTypeForPath(Assembly assembly, string path) - { - foreach (var xria in assembly.GetCustomAttributes()) { - if (xria.Path == path) - return xria.Type; - } - return null; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/XamlServiceProvider.cs b/src/Tizen.NUI/src/internal/Xaml/XamlServiceProvider.cs deleted file mode 100755 index be1d5e83f..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/XamlServiceProvider.cs +++ /dev/null @@ -1,305 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Xml; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Xaml -{ - internal class XamlServiceProvider : IServiceProvider - { - readonly Dictionary services = new Dictionary(); - - internal XamlServiceProvider(INode node, HydrationContext context) - { - object targetObject; - if (node != null && node.Parent != null && context.Values.TryGetValue(node.Parent, out targetObject)) - IProvideValueTarget = new XamlValueTargetProvider(targetObject, node, context, null); - if (context != null) - IRootObjectProvider = new XamlRootObjectProvider(context.RootElement); - if (node != null) - { - IXamlTypeResolver = new XamlTypeResolver(node.NamespaceResolver, XamlParser.GetElementType, - context?.RootElement.GetType().GetTypeInfo().Assembly); - - var enode = node; - while (enode != null && !(enode is IElementNode)) - enode = enode.Parent; - if (enode != null) - INameScopeProvider = new NameScopeProvider { NameScope = (enode as IElementNode).Namescope }; - } - - var xmlLineInfo = node as IXmlLineInfo; - if (xmlLineInfo != null) - IXmlLineInfoProvider = new XmlLineInfoProvider(xmlLineInfo); - - IValueConverterProvider = new ValueConverterProvider(); - } - - public XamlServiceProvider() - { - IValueConverterProvider = new ValueConverterProvider(); - } - - internal IProvideValueTarget IProvideValueTarget - { - get { return (IProvideValueTarget)GetService(typeof (IProvideValueTarget)); } - set { services[typeof (IProvideValueTarget)] = value; } - } - - internal IXamlTypeResolver IXamlTypeResolver - { - get { return (IXamlTypeResolver)GetService(typeof (IXamlTypeResolver)); } - set { services[typeof (IXamlTypeResolver)] = value; } - } - - internal IRootObjectProvider IRootObjectProvider - { - get { return (IRootObjectProvider)GetService(typeof (IRootObjectProvider)); } - set { services[typeof (IRootObjectProvider)] = value; } - } - - internal IXmlLineInfoProvider IXmlLineInfoProvider - { - get { return (IXmlLineInfoProvider)GetService(typeof (IXmlLineInfoProvider)); } - set { services[typeof (IXmlLineInfoProvider)] = value; } - } - - internal INameScopeProvider INameScopeProvider - { - get { return (INameScopeProvider)GetService(typeof (INameScopeProvider)); } - set { services[typeof (INameScopeProvider)] = value; } - } - - internal IValueConverterProvider IValueConverterProvider - { - get { return (IValueConverterProvider)GetService(typeof (IValueConverterProvider)); } - set { services[typeof (IValueConverterProvider)] = value; } - } - - public object GetService(Type serviceType) - { - object service; - return services.TryGetValue(serviceType, out service) ? service : null; - } - - public void Add(Type type, object service) - { - services.Add(type, service); - } - } - - internal class XamlValueTargetProvider : IProvideParentValues, IProvideValueTarget - { - public XamlValueTargetProvider(object targetObject, INode node, HydrationContext context, object targetProperty) - { - Context = context; - Node = node; - TargetObject = targetObject; - TargetProperty = targetProperty; - } - - INode Node { get; } - - HydrationContext Context { get; } - public object TargetObject { get; } - public object TargetProperty { get; internal set; } = null; - - IEnumerable IProvideParentValues.ParentObjects - { - get - { - if (Node == null || Context == null) - yield break; - var n = Node; - object obj = null; - var context = Context; - while (n.Parent != null && context != null) - { - if (n.Parent is IElementNode) - { - if (context.Values.TryGetValue(n.Parent, out obj)) - yield return obj; - else - { - context = context.ParentContext; - continue; - } - } - n = n.Parent; - } - } - } - } - - internal class SimpleValueTargetProvider : IProvideParentValues, IProvideValueTarget - { - readonly object[] objectAndParents; - readonly object targetProperty; - - [Obsolete("SimpleValueTargetProvider(object[] objectAndParents) is obsolete as of version 2.3.4. Please use SimpleValueTargetProvider(object[] objectAndParents, object targetProperty) instead.")] - public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null) - { - } - - public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty) - { - if (objectAndParents == null) - throw new ArgumentNullException(nameof(objectAndParents)); - if (objectAndParents.Length == 0) - throw new ArgumentException(); - - this.objectAndParents = objectAndParents; - this.targetProperty = targetProperty; - } - - IEnumerable IProvideParentValues.ParentObjects - { - get { return objectAndParents; } - } - - object IProvideValueTarget.TargetObject - { - get { return objectAndParents[0]; } - } - - object IProvideValueTarget.TargetProperty - { - get { return targetProperty; } - } - } - - internal class XamlTypeResolver : IXamlTypeResolver - { - readonly Assembly currentAssembly; - readonly GetTypeFromXmlName getTypeFromXmlName; - readonly IXmlNamespaceResolver namespaceResolver; - - public XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, Assembly currentAssembly) - : this(namespaceResolver, XamlParser.GetElementType, currentAssembly) - { - } - - internal XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, GetTypeFromXmlName getTypeFromXmlName, - Assembly currentAssembly) - { - this.currentAssembly = currentAssembly; - if (namespaceResolver == null) - throw new ArgumentNullException(); - if (getTypeFromXmlName == null) - throw new ArgumentNullException(); - - this.namespaceResolver = namespaceResolver; - this.getTypeFromXmlName = getTypeFromXmlName; - } - - Type IXamlTypeResolver.Resolve(string qualifiedTypeName, IServiceProvider serviceProvider) - { - XamlParseException e; - var type = Resolve(qualifiedTypeName, serviceProvider, out e); - if (e != null) - throw e; - return type; - } - - bool IXamlTypeResolver.TryResolve(string qualifiedTypeName, out Type type) - { - XamlParseException exception; - type = Resolve(qualifiedTypeName, null, out exception); - return exception == null; - } - - Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider, out XamlParseException exception) - { - exception = null; - var split = qualifiedTypeName.Split(':'); - if (split.Length > 2) - return null; - - string prefix, name; - if (split.Length == 2) - { - prefix = split[0]; - name = split[1]; - } - else - { - prefix = ""; - name = split[0]; - } - - IXmlLineInfo xmlLineInfo = null; - if (serviceProvider != null) - { - var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; - if (lineInfoProvider != null) - xmlLineInfo = lineInfoProvider.XmlLineInfo; - } - - var namespaceuri = namespaceResolver.LookupNamespace(prefix); - if (namespaceuri == null) - { - exception = new XamlParseException(string.Format("No xmlns declaration for prefix \"{0}\"", prefix), xmlLineInfo); - return null; - } - - return getTypeFromXmlName(new XmlType(namespaceuri, name, null), xmlLineInfo, currentAssembly, out exception); - } - - internal delegate Type GetTypeFromXmlName( - XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly, out XamlParseException exception); - } - - internal class XamlRootObjectProvider : IRootObjectProvider - { - public XamlRootObjectProvider(object rootObject) - { - RootObject = rootObject; - } - - public object RootObject { get; } - } - - internal class XmlLineInfoProvider : IXmlLineInfoProvider - { - public XmlLineInfoProvider(IXmlLineInfo xmlLineInfo) - { - XmlLineInfo = xmlLineInfo; - } - - public IXmlLineInfo XmlLineInfo { get; } - } - - internal class NameScopeProvider : INameScopeProvider - { - public INameScope NameScope { get; set; } - } - - internal class XmlNamespaceResolver : IXmlNamespaceResolver - { - readonly Dictionary namespaces = new Dictionary(); - - public IDictionary GetNamespacesInScope(XmlNamespaceScope scope) - { - throw new NotImplementedException(); - } - - public string LookupNamespace(string prefix) - { - string result; - if (namespaces.TryGetValue(prefix, out result)) - return result; - return null; - } - - public string LookupPrefix(string namespaceName) - { - throw new NotImplementedException(); - } - - public void Add(string prefix, string ns) - { - namespaces.Add(prefix, ns); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/XmlLineInfo.cs b/src/Tizen.NUI/src/internal/Xaml/XmlLineInfo.cs deleted file mode 100755 index 52a886bad..000000000 --- a/src/Tizen.NUI/src/internal/Xaml/XmlLineInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Xml; - -namespace Tizen.NUI.Xaml -{ - internal class XmlLineInfo : IXmlLineInfo - { - readonly bool _hasLineInfo; - - public XmlLineInfo() - { - } - - public XmlLineInfo(int linenumber, int lineposition) - { - _hasLineInfo = true; - LineNumber = linenumber; - LinePosition = lineposition; - } - - public bool HasLineInfo() - { - return _hasLineInfo; - } - - public int LineNumber { get; } - - public int LinePosition { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Xaml/XmlnsHelper.cs b/src/Tizen.NUI/src/internal/Xaml/XmlnsHelper.cs index 8f86874fd..ff51cf42c 100755 --- a/src/Tizen.NUI/src/internal/Xaml/XmlnsHelper.cs +++ b/src/Tizen.NUI/src/internal/Xaml/XmlnsHelper.cs @@ -9,29 +9,27 @@ namespace Tizen.NUI.Xaml string typeName; string ns; string asm; - string targetPlatform; - - ParseXmlns(xmlns, out typeName, out ns, out asm, out targetPlatform); + ParseXmlns(xmlns, out typeName, out ns, out asm); return ns; } - public static void ParseXmlns(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform) + public static void ParseXmlns(string xmlns, out string typeName, out string ns, out string asm) { - typeName = ns = asm = targetPlatform = null; + typeName = ns = asm = null; xmlns = xmlns.Trim(); if (xmlns.StartsWith("using:", StringComparison.Ordinal)) { - ParseUsing(xmlns, out typeName, out ns, out asm, out targetPlatform); + ParseUsing(xmlns, out typeName, out ns, out asm); return; } - ParseClrNamespace(xmlns, out typeName, out ns, out asm, out targetPlatform); + ParseClrNamespace(xmlns, out typeName, out ns, out asm); } - static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform) + static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm) { - typeName = ns = asm = targetPlatform = null; + typeName = ns = asm = null; foreach (var decl in xmlns.Split(';')) { @@ -40,15 +38,13 @@ namespace Tizen.NUI.Xaml ns = decl.Substring(14, decl.Length - 14); continue; } + if (decl.StartsWith("assembly=", StringComparison.Ordinal)) { asm = decl.Substring(9, decl.Length - 9); continue; } - if (decl.StartsWith("targetPlatform=", StringComparison.Ordinal)) { - targetPlatform = decl.Substring(15, decl.Length - 15); - continue; - } + var nsind = decl.LastIndexOf(".", StringComparison.Ordinal); if (nsind > 0) { @@ -60,9 +56,9 @@ namespace Tizen.NUI.Xaml } } - static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform) + static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm) { - typeName = ns = asm = targetPlatform = null; + typeName = ns = asm = null; foreach (var decl in xmlns.Split(';')) { if (decl.StartsWith("using:", StringComparison.Ordinal)) { diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Accelerator.cs b/src/Tizen.NUI/src/internal/XamlBinding/Accelerator.cs deleted file mode 100755 index 30501fa4b..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Accelerator.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - [System.ComponentModel.TypeConverter(typeof(AcceleratorTypeConverter))] - internal class Accelerator - { - const char Separator = '+'; - string _text; - - internal Accelerator(string text) - { - if (string.IsNullOrEmpty(text)) - throw new ArgumentNullException(nameof(text)); - _text = text; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public IEnumerable Modifiers { get; set; } - - [EditorBrowsable(EditorBrowsableState.Never)] - public IEnumerable Keys { get; set; } - - public static Accelerator FromString(string text) - { - var accelarat = new Accelerator(text); - - var acceleratorParts = text.Split(Separator); - - if (acceleratorParts.Length > 1) - { - var modifiers = new List(); - for (int i = 0; i < acceleratorParts.Length; i++) - { - var modifierMask = acceleratorParts[i]; - var modiferMaskLower = modifierMask.ToLower(); - switch (modiferMaskLower) - { - case "ctrl": - case "cmd": - case "alt": - case "shift": - case "fn": - case "win": - modifiers.Add(modiferMaskLower); - text = text.Replace(modifierMask, ""); - break; - } - } - accelarat.Modifiers = modifiers; - - } - - var keys = text.Split(new char[] { Separator }, StringSplitOptions.RemoveEmptyEntries); - accelarat.Keys = keys; - return accelarat; - } - - public override string ToString() - { - return _text; - } - - public override bool Equals(object obj) - { - return obj != null && obj is Accelerator && Equals((Accelerator)obj); - } - - bool Equals(Accelerator other) - { - return other.ToString() == ToString(); - } - - public override int GetHashCode() - { - return ToString().GetHashCode(); - } - - public static implicit operator Accelerator(string accelerator) - { - return FromString(accelerator); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/AcceleratorTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/AcceleratorTypeConverter.cs deleted file mode 100755 index 63601840b..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/AcceleratorTypeConverter.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal class AcceleratorTypeConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value == null) - return null; - - return Accelerator.FromString(value); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Application.cs b/src/Tizen.NUI/src/internal/XamlBinding/Application.cs deleted file mode 100755 index 1461a00f0..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Application.cs +++ /dev/null @@ -1,406 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Threading; -using System.ComponentModel; -using System.Threading.Tasks; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Binding -{ - internal class Application : Element, IResourcesProvider, IApplicationController, IElementConfiguration - { - static Application s_current; - Task> _propertiesTask; - readonly Lazy> _platformConfigurationRegistry; - - IAppIndexingProvider _appIndexProvider; - - ReadOnlyCollection _logicalChildren; - - Page _mainPage; - - static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1); - - public Application() - { - // var f = false; - // if (f) - // Loader.Load(); - NavigationProxy = new NavigationImpl(this); - SetCurrentApplication(this); - - SystemResources = DependencyService.Get()?.GetSystemResources(); - SystemResources.ValuesChanged += OnParentResourcesChanged; - _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); - } - - public void Quit() - { - Device.PlatformServices?.QuitApplication(); - } - - public IAppLinks AppLinks - { - get - { - if (_appIndexProvider == null) - throw new ArgumentException("No IAppIndexingProvider was provided"); - if (_appIndexProvider.AppLinks == null) - throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Tizen.NUI.Binding.AppLinks"); - return _appIndexProvider.AppLinks; - } - } - - [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; - if (value == null) - s_current = null; //Allow to reset current for unittesting - s_current = value; - } - } - - public Page MainPage - { - get { return _mainPage; } - set - { - if (value == null) - throw new ArgumentNullException("value"); - - if (_mainPage == value) - return; - - OnPropertyChanging(); - if (_mainPage != null) - { - InternalChildren.Remove(_mainPage); - _mainPage.Parent = null; - } - - _mainPage = value; - - if (_mainPage != null) - { - _mainPage.Parent = this; - _mainPage.NavigationProxy.Inner = NavigationProxy; - InternalChildren.Add(_mainPage); - } - OnPropertyChanged(); - } - } - - public IDictionary Properties - { - get - { - if (_propertiesTask == null) - { - _propertiesTask = GetPropertiesAsync(); - } - - return _propertiesTask.Result; - } - } - - internal override ReadOnlyCollection LogicalChildrenInternal - { - get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection(InternalChildren)); } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public NavigationProxy NavigationProxy { get; } - - [EditorBrowsable(EditorBrowsableState.Never)] - public int PanGestureId { get; set; } - - internal IResourceDictionary SystemResources { get; } - - ObservableCollection InternalChildren { get; } = new ObservableCollection(); - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SetAppIndexingProvider(IAppIndexingProvider provider) - { - _appIndexProvider = provider; - } - - ResourceDictionary _resources; - bool IResourcesProvider.IsResourcesCreated => _resources != null; - - public ResourceDictionary XamlResources - { - get - { - if (_resources != null) - return _resources; - - _resources = new ResourceDictionary(); - ((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(); - } - } - - public event EventHandler ModalPopped; - - public event EventHandler ModalPopping; - - public event EventHandler ModalPushed; - - public event EventHandler ModalPushing; - - public event EventHandler PageAppearing; - - public event EventHandler PageDisappearing; - - - async void SaveProperties() - { - try - { - await SetPropertiesAsync(); - } - catch (Exception exc) - { - Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}"); - } - } - - public async Task SavePropertiesAsync() - { - if (Device.IsInvokeRequired) - { - Device.BeginInvokeOnMainThread(SaveProperties); - } - else - { - await SetPropertiesAsync(); - } - } - - // Don't use this unless there really is no better option - internal void SavePropertiesAsFireAndForget() - { - if (Device.IsInvokeRequired) - { - Device.BeginInvokeOnMainThread(SaveProperties); - } - else - { - SaveProperties(); - } - } - - public IPlatformElementConfiguration On() where T : IConfigPlatform - { - return _platformConfigurationRegistry.Value.On(); - } - - protected virtual void OnAppLinkRequestReceived(Uri uri) - { - } - - protected override void OnParentSet() - { - throw new InvalidOperationException("Setting a Parent on Application is invalid."); - } - - protected virtual void OnResume() - { - } - - protected virtual void OnSleep() - { - } - - protected virtual void OnStart() - { - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static void ClearCurrent() - { - s_current = null; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static bool IsApplicationOrNull(Element element) - { - return element == null || element is Application; - } - - internal override void OnParentResourcesChanged(IEnumerable> values) - { - 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); - } - OnResourcesChanged(changedResources); - } - - internal event EventHandler PopCanceled; - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendOnAppLinkRequestReceived(Uri uri) - { - OnAppLinkRequestReceived(uri); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendResume() - { - s_current = this; - OnResume(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendSleep() - { - OnSleep(); - SavePropertiesAsFireAndForget(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public Task SendSleepAsync() - { - OnSleep(); - return SavePropertiesAsync(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendStart() - { - OnStart(); - } - - async Task> GetPropertiesAsync() - { - var deserializer = DependencyService.Get(); - if (deserializer == null) - { - Console.WriteLine("Startup", "No IDeserialzier was found registered"); - return new Dictionary(4); - } - - IDictionary properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false); - if (properties == null) - properties = new Dictionary(4); - - return properties; - } - - internal void OnPageAppearing(Page page) - => PageAppearing?.Invoke(this, page); - - internal void OnPageDisappearing(Page page) - => PageDisappearing?.Invoke(this, page); - - void OnModalPopped(Page modalPage) - => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage)); - - bool OnModalPopping(Page modalPage) - { - var args = new ModalPoppingEventArgs(modalPage); - ModalPopping?.Invoke(this, args); - return args.Cancel; - } - - void OnModalPushed(Page modalPage) - => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage)); - - void OnModalPushing(Page modalPage) - => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage)); - - void OnPopCanceled() - => PopCanceled?.Invoke(this, EventArgs.Empty); - - async Task SetPropertiesAsync() - { - await SaveSemaphore.WaitAsync(); - try - { - await DependencyService.Get()?.SerializePropertiesAsync(Properties); - } - finally - { - SaveSemaphore.Release(); - } - - } - - class NavigationImpl : NavigationProxy - { - readonly Application _owner; - - public NavigationImpl(Application owner) - { - _owner = owner; - } - - protected override async Task OnPopModal(bool animated) - { - Page modal = ModalStack[ModalStack.Count - 1]; - if (_owner.OnModalPopping(modal)) - { - _owner.OnPopCanceled(); - return null; - } - Page result = await base.OnPopModal(animated); - result.Parent = null; - _owner.OnModalPopped(result); - return result; - } - - protected override async Task OnPushModal(Page modal, bool animated) - { - _owner.OnModalPushing(modal); - - modal.Parent = _owner; - - if (modal.NavigationProxy.ModalStack.Count == 0) - { - modal.NavigationProxy.Inner = this; - await base.OnPushModal(modal, animated); - } - else - { - await base.OnPushModal(modal, animated); - modal.NavigationProxy.Inner = this; - } - - _owner.OnModalPushed(modal); - } - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BaseMenuItem.cs b/src/Tizen.NUI/src/internal/XamlBinding/BaseMenuItem.cs deleted file mode 100755 index c0abdb0b7..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BaseMenuItem.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Binding -{ - internal abstract class BaseMenuItem : Element - { - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindableObjectExtensions.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindableObjectExtensions.cs deleted file mode 100755 index 8c096d061..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindableObjectExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Linq.Expressions; - -namespace Tizen.NUI.Binding -{ - internal static class BindableObjectExtensions - { - public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, - string stringFormat = null) - { - if (self == null) - throw new ArgumentNullException("self"); - if (targetProperty == null) - throw new ArgumentNullException("targetProperty"); - - var binding = new Binding(path, mode, converter, stringFormat: stringFormat); - self.SetBinding(targetProperty, binding); - } - - [Obsolete] - public static void SetBinding(this BindableObject self, BindableProperty targetProperty, Expression> sourceProperty, BindingMode mode = BindingMode.Default, - IValueConverter converter = null, string stringFormat = null) - { - if (self == null) - throw new ArgumentNullException("self"); - if (targetProperty == null) - throw new ArgumentNullException("targetProperty"); - if (sourceProperty == null) - throw new ArgumentNullException("sourceProperty"); - - Binding binding = Binding.Create(sourceProperty, mode, converter, stringFormat: stringFormat); - self.SetBinding(targetProperty, binding); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindableProperty.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindableProperty.cs deleted file mode 100755 index 9aa62d802..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindableProperty.cs +++ /dev/null @@ -1,560 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq.Expressions; -using System.Reflection; -using System.ComponentModel; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - /// - /// A BindableProperty is a backing store for properties allowing bindings on BindableObject. - /// - [DebuggerDisplay("{PropertyName}")] - [TypeConverter(typeof(BindablePropertyConverter))] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class BindableProperty - { - /// - /// Delegate for BindableProperty.PropertyChanged. - /// - /// The bindable object that contains the property. - /// The old property value. - /// The new property value. - public delegate void BindingPropertyChangedDelegate(BindableObject bindable, object oldValue, object newValue); - - /// - /// Strongly-typed delegate for BindableProperty.PropertyChanged. - /// - /// The type of the bound property. - /// The bindable object that contains the property. - /// The old property value. - /// The new property value. - public delegate void BindingPropertyChangedDelegate(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue); - - /// - /// Delegate for BindableProperty.PropertyChanging. - /// - /// The bindable object that contains the property. - /// The old property value. - /// The new property value. - public delegate void BindingPropertyChangingDelegate(BindableObject bindable, object oldValue, object newValue); - - /// - /// Strongly-typed delegate for BindableProperty.PropertyChanging. - /// - /// The type of the bound property. - /// The bindable object that contains the property. - /// The old property value. - /// The new property value. - public delegate void BindingPropertyChangingDelegate(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue); - - /// - /// Delegate for BindableProperty.CoerceValue. - /// - /// The bindable object that contains the property. - /// The value to coerce. - /// System.Object - public delegate object CoerceValueDelegate(BindableObject bindable, object value); - - /// - /// Strongly-typed delegate for BindableProperty.CoerceValue. - /// - /// The type of the bound property. - /// The bindable object that contains the property. - /// The value to coerce. - /// TPropertyType - public delegate TPropertyType CoerceValueDelegate(BindableObject bindable, TPropertyType value); - - /// - /// Delegate for BindableProperty.DefaultValueCreator. - /// - /// The bindable object that contains the property. - /// System.Object - public delegate object CreateDefaultValueDelegate(BindableObject bindable); - - /// - /// Strongly-typed delegate for BindableProperty.DefaultValueCreator. - /// - /// The type of the object that delared the property. - /// The type of the bound property. - /// The bindable object that contains the property. - /// TPropertyType - public delegate TPropertyType CreateDefaultValueDelegate(TDeclarer bindable); - - /// - /// Delegate for BindableProperty.ValidateValue. - /// - /// The bindable object that contains the property. - /// The default value. - /// System.Boolean - public delegate bool ValidateValueDelegate(BindableObject bindable, object value); - - /// - /// Strongly-typed delegate for BindableProperty.ValidateValue. - /// - /// The type of the bound property. - /// The bindable object that contains the property. - /// The default value. - /// System.Boolean - public delegate bool ValidateValueDelegate(BindableObject bindable, TPropertyType value); - - static readonly Dictionary WellKnownConvertTypes = new Dictionary - { - { typeof(Uri), new UriTypeConverter() }, - { typeof(Color), new ColorTypeConverter() }, - { typeof(Size2D), new Size2DTypeConverter() }, - { typeof(Position2D), new Position2DTypeConverter() }, - { typeof(Size), new SizeTypeConverter() }, - { typeof(Position), new PositionTypeConverter() }, - { typeof(Rectangle), new RectangleTypeConverter() }, - { typeof(Rotation), new RotationTypeConverter() }, - { typeof(Thickness), new ThicknessTypeConverter() }, - { typeof(Vector2), new Vector2TypeConverter() }, - { typeof(Vector3), new Vector3TypeConverter() }, - { typeof(Vector4), new Vector4TypeConverter() }, - { typeof(RelativeVector2), new RelativeVector2TypeConverter() }, - { typeof(RelativeVector3), new RelativeVector3TypeConverter() }, - { typeof(RelativeVector4), new RelativeVector4TypeConverter() }, - }; - - //Modification for NUI XAML : user defined converter for DynamicResource can be added - static internal Dictionary UserCustomConvertTypes = new Dictionary - { - }; - - // more or less the encoding of this, without the need to reflect - // http://msdn.microsoft.com/en-us/library/y5b434w4.aspx - static readonly Dictionary SimpleConvertTypes = new Dictionary - { - { typeof(sbyte), new[] { typeof(string), typeof(short), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(byte), new[] { typeof(string), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(short), new[] { typeof(string), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(ushort), new[] { typeof(string), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(int), new[] { typeof(string), typeof(long), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(uint), new[] { typeof(string), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(long), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(char), new[] { typeof(string), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, - { typeof(float), new[] { typeof(string), typeof(double) } }, - { typeof(ulong), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } } - }; - - BindableProperty(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, - ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null) - { - if (propertyName == null) - throw new ArgumentNullException("propertyName"); - if (ReferenceEquals(returnType, null)) - throw new ArgumentNullException("returnType"); - if (ReferenceEquals(declaringType, null)) - throw new ArgumentNullException("declaringType"); - - // don't use Enum.IsDefined as its redonkulously expensive for what it does - if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime) - throw new ArgumentException("Not a valid type of BindingMode", "defaultBindingMode"); - if (defaultValue == null && Nullable.GetUnderlyingType(returnType) == null && returnType.GetTypeInfo().IsValueType) - throw new ArgumentException("Not a valid default value", "defaultValue"); - if (defaultValue != null && !returnType.IsInstanceOfType(defaultValue)) - throw new ArgumentException("Default value did not match return type", "defaultValue"); - if (defaultBindingMode == BindingMode.Default) - defaultBindingMode = BindingMode.OneWay; - - PropertyName = propertyName; - ReturnType = returnType; - ReturnTypeInfo = returnType.GetTypeInfo(); - DeclaringType = declaringType; - DefaultValue = defaultValue; - DefaultBindingMode = defaultBindingMode; - PropertyChanged = propertyChanged; - PropertyChanging = propertyChanging; - ValidateValue = validateValue; - CoerceValue = coerceValue; - BindingChanging = bindingChanging; - IsReadOnly = isReadOnly; - DefaultValueCreator = defaultValueCreator; - } - - /// - /// Gets the type declaring the BindableProperty. - /// - public Type DeclaringType { get; private set; } - - /// - /// Gets the default BindingMode. - /// - public BindingMode DefaultBindingMode { get; private set; } - - /// - /// Gets the default value for the BindableProperty. - /// - public object DefaultValue { get; } - - /// - /// Gets a value indicating if the BindableProperty is created form a BindablePropertyKey. - /// - public bool IsReadOnly { get; private set; } - - /// - /// Gets the property name. - /// - public string PropertyName { get; } - - /// - /// Gets the type of the BindableProperty. - /// - public Type ReturnType { get; } - - internal BindablePropertyBindingChanging BindingChanging { get; private set; } - - internal CoerceValueDelegate CoerceValue { get; private set; } - - internal CreateDefaultValueDelegate DefaultValueCreator { get; } - - internal BindingPropertyChangedDelegate PropertyChanged { get; private set; } - - internal BindingPropertyChangingDelegate PropertyChanging { get; private set; } - - internal System.Reflection.TypeInfo ReturnTypeInfo { get; } - - internal ValidateValueDelegate ValidateValue { get; private set; } - - /// - /// Deprecated. Do not use. - /// - /// The type of the declaring object. - /// The type of the property. - /// An expression identifying the getter for the property using this BindableProperty as backing store. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created BindableProperty. - [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] - public static BindableProperty Create(Expression> getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, - ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, - BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, - CreateDefaultValueDelegate defaultValueCreator = null) where TDeclarer : BindableObject - { - return Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, defaultValueCreator: defaultValueCreator); - } - - /// - /// Creates a new instance of the BindableProperty class. - /// - /// The name of the BindableProperty. - /// The type of the property. - /// The type of the declaring object. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created BindableProperty. - public static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue = null, BindingMode defaultBindingMode = BindingMode.OneWay, - ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) - { - return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, - defaultValueCreator: defaultValueCreator); - } - - /// - /// Deprecated. Do not use. - /// - /// The type of the declaring object. - /// The type of the property. - /// An expression identifying a static method returning the value of the property using this BindableProperty as backing store. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] - public static BindableProperty CreateAttached(Expression> staticgetter, TPropertyType defaultValue, - BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, - BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, - CreateDefaultValueDelegate defaultValueCreator = null) - { - return CreateAttached(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, - defaultValueCreator: defaultValueCreator); - } - - /// - /// Creates a new instance of the BindableProperty class for an attached property. - /// - /// The name of the BindableProperty. - /// The type of the property. - /// The type of the declaring object. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created BindableProperty. - public static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, - ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) - { - return CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, false, defaultValueCreator); - } - - /// - /// Deprecated. Do not use. - /// - /// The type of the declaring object. - /// The type of the property. - /// An expression identifying a static method returning the value of the property using this BindableProperty as backing store. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created attached read-only BindablePropertyKey. - [Obsolete("CreateAttachedReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] - public static BindablePropertyKey CreateAttachedReadOnly(Expression> staticgetter, TPropertyType defaultValue, - BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate validateValue = null, - BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) - - { - return - new BindablePropertyKey(CreateAttached(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, - defaultValueCreator)); - } - - /// - /// Creates a new instance of the BindableProperty class for attached read-only properties. - /// - /// The name of the BindableProperty. - /// The type of the property. - /// The type of the declaring object. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created attached read-only BindablePropertyKey. - public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, - ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) - { - return - new BindablePropertyKey(CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, - defaultValueCreator)); - } - - /// - /// Deprecated. Do not use. - /// - /// The type of the declaring object. - /// The type of the property. - /// An expression identifying the getter for the property using this BindableProperty as backing store. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created BindablePropertyKey. - [Obsolete("CreateReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] - public static BindablePropertyKey CreateReadOnly(Expression> getter, TPropertyType defaultValue, - BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate validateValue = null, - BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) where TDeclarer : BindableObject - { - return new BindablePropertyKey(Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, defaultValueCreator)); - } - - /// - /// Creates a new instance of the BindablePropertyKey class. - /// - /// The name of the BindableProperty. - /// The type of the property. - /// The type of the declaring object. - /// The default value for the property. - /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. - /// A delegate to be run when a value is set. This parameter is optional. Default is null. - /// A delegate to be run when the value has changed. This parameter is optional. Default is null. - /// A delegate to be run when the value will change. This parameter is optional. Default is null. - /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. - /// A Func used to initialize default value for reference types. - /// A newly created BindablePropertyKey. - public static BindablePropertyKey CreateReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, - ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, - CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) - { - return - new BindablePropertyKey(new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, - isReadOnly: true, defaultValueCreator: defaultValueCreator)); - } - - [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] - internal static BindableProperty Create(Expression> getter, TPropertyType defaultValue, BindingMode defaultBindingMode, - ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, - CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false, - CreateDefaultValueDelegate defaultValueCreator = null) where TDeclarer : BindableObject - { - if (getter == null) - throw new ArgumentNullException("getter"); - - Expression expr = getter.Body; - - var unary = expr as UnaryExpression; - if (unary != null) - expr = unary.Operand; - - var member = expr as MemberExpression; - if (member == null) - throw new ArgumentException("getter must be a MemberExpression", "getter"); - - var property = (PropertyInfo)member.Member; - - ValidateValueDelegate untypedValidateValue = null; - BindingPropertyChangedDelegate untypedBindingPropertyChanged = null; - BindingPropertyChangingDelegate untypedBindingPropertyChanging = null; - CoerceValueDelegate untypedCoerceValue = null; - CreateDefaultValueDelegate untypedDefaultValueCreator = null; - if (validateValue != null) - untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value); - if (propertyChanged != null) - untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); - if (propertyChanging != null) - untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); - if (coerceValue != null) - untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value); - if (defaultValueCreator != null) - untypedDefaultValueCreator = o => defaultValueCreator((TDeclarer)o); - - return new BindableProperty(property.Name, property.PropertyType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged, - untypedBindingPropertyChanging, untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator); - } - - internal static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, - BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, - CreateDefaultValueDelegate defaultValueCreator = null) - { - return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging, - defaultValueCreator: defaultValueCreator); - } - - [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] - internal static BindableProperty CreateAttached(Expression> staticgetter, TPropertyType defaultValue, BindingMode defaultBindingMode, - ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, - CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false, - CreateDefaultValueDelegate defaultValueCreator = null) - { - if (staticgetter == null) - throw new ArgumentNullException("staticgetter"); - - Expression expr = staticgetter.Body; - - var unary = expr as UnaryExpression; - if (unary != null) - expr = unary.Operand; - - var methodcall = expr as MethodCallExpression; - if (methodcall == null) - throw new ArgumentException("staticgetter must be a MethodCallExpression", "staticgetter"); - - MethodInfo method = methodcall.Method; - if (!method.Name.StartsWith("Get", StringComparison.Ordinal)) - throw new ArgumentException("staticgetter name must start with Get", "staticgetter"); - - string propertyname = method.Name.Substring(3); - - ValidateValueDelegate untypedValidateValue = null; - BindingPropertyChangedDelegate untypedBindingPropertyChanged = null; - BindingPropertyChangingDelegate untypedBindingPropertyChanging = null; - CoerceValueDelegate untypedCoerceValue = null; - CreateDefaultValueDelegate untypedDefaultValueCreator = null; - if (validateValue != null) - untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value); - if (propertyChanged != null) - untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); - if (propertyChanging != null) - untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); - if (coerceValue != null) - untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value); - if (defaultValueCreator != null) - untypedDefaultValueCreator = o => defaultValueCreator(o); - - return new BindableProperty(propertyname, method.ReturnType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged, untypedBindingPropertyChanging, - untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator); - } - - internal static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, - BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, - bool isReadOnly, CreateDefaultValueDelegate defaultValueCreator = null) - { - return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging, isReadOnly, - defaultValueCreator); - } - - internal object GetDefaultValue(BindableObject bindable) - { - if (DefaultValueCreator != null) - return DefaultValueCreator(bindable); - - return DefaultValue; - } - - internal bool TryConvert(ref object value) - { - if (value == null) - { - return !ReturnTypeInfo.IsValueType || ReturnTypeInfo.IsGenericType && ReturnTypeInfo.GetGenericTypeDefinition() == typeof(Nullable<>); - } - - Type valueType = value.GetType(); - Type type = ReturnType; - - // Dont support arbitrary IConvertible by limiting which types can use this - Type[] convertableTo; - TypeConverter typeConverterTo; - if (SimpleConvertTypes.TryGetValue(valueType, out convertableTo) && Array.IndexOf(convertableTo, type) != -1) - { - value = Convert.ChangeType(value, type); - } - else if (WellKnownConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType)) - { - value = typeConverterTo.ConvertFromInvariantString(value.ToString()); - } - else if (UserCustomConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType)) - { - //Modification for NUI XAML : user defined converter for DynamicResource can be added - value = typeConverterTo.ConvertFromInvariantString(value.ToString()); - } - else if (!ReturnTypeInfo.IsAssignableFrom(valueType.GetTypeInfo())) - { - var cast = type.GetImplicitConversionOperator(fromType: valueType, toType: type) - ?? valueType.GetImplicitConversionOperator(fromType: valueType, toType: type); - - if (cast == null) - return false; - - value = cast.Invoke(null, new[] { value }); - } - - return true; - } - - internal delegate void BindablePropertyBindingChanging(BindableObject bindable, BindingBase oldValue, BindingBase newValue); - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyConverter.cs deleted file mode 100755 index ea258e617..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyConverter.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Reflection; -using System.Xml; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindablePropertyConverter")] - [Xaml.TypeConversion(typeof(BindableProperty))] - internal sealed class BindablePropertyConverter : TypeConverter, IExtendedTypeConverter - { - object IExtendedTypeConverter.ConvertFrom(CultureInfo culture, object value, IServiceProvider serviceProvider) - { - return ((IExtendedTypeConverter)this).ConvertFromInvariantString(value as string, serviceProvider); - } - - object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider) - { - if (string.IsNullOrWhiteSpace(value)) - return null; - if (serviceProvider == null) - return null; - var parentValuesProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues; - var typeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; - if (typeResolver == null) - return null; - IXmlLineInfo lineinfo = null; - var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; - if (xmlLineInfoProvider != null) - lineinfo = xmlLineInfoProvider.XmlLineInfo; - string[] parts = value.Split('.'); - Type type = null; - if (parts.Length == 1) - { - if (parentValuesProvider == null) - { - string msg = string.Format("Can't resolve {0}", parts[0]); - throw new XamlParseException(msg, lineinfo); - } - object parent = parentValuesProvider.ParentObjects.Skip(1).FirstOrDefault(); - if (parentValuesProvider.TargetObject is Setter) - { - var style = parent as Style; - var triggerBase = parent as TriggerBase; - var visualState = parent as VisualState; - if (style != null) - type = style.TargetType; - else if (triggerBase != null) - type = triggerBase.TargetType; - else if (visualState != null) - type = FindTypeForVisualState(parentValuesProvider, lineinfo); - } - else if (parentValuesProvider.TargetObject is Trigger) - type = (parentValuesProvider.TargetObject as Trigger).TargetType; - else if (parentValuesProvider.TargetObject is XamlPropertyCondition && (parent as TriggerBase) != null) - type = (parent as TriggerBase).TargetType; - - if (type == null) - throw new XamlParseException($"Can't resolve {parts [0]}", lineinfo); - - return ConvertFrom(type, parts[0], lineinfo); - } - if (parts.Length == 2) - { - if (!typeResolver.TryResolve(parts[0], out type)) - { - string msg = string.Format("Can't resolve {0}", parts[0]); - throw new XamlParseException(msg, lineinfo); - } - return ConvertFrom(type, parts[1], lineinfo); - } - throw new XamlParseException($"Can't resolve {value}. Syntax is [[prefix:]Type.]PropertyName.", lineinfo); - } - - public override object ConvertFromInvariantString(string value) - { - if (string.IsNullOrWhiteSpace(value)) - return null; - if (value.Contains(":")) - { - Console.WriteLine(null, "Can't resolve properties with xml namespace prefix."); - return null; - } - string[] parts = value.Split('.'); - if (parts.Length != 2) - { - Console.WriteLine(null, $"Can't resolve {value}. Accepted syntax is Type.PropertyName."); - return null; - } - Type type = Type.GetType("Tizen.NUI." + parts[0]); - return ConvertFrom(type, parts[1], null); - } - - BindableProperty ConvertFrom(Type type, string propertyName, IXmlLineInfo lineinfo) - { - string name = propertyName + "Property"; - FieldInfo bpinfo = type.GetField(fi => fi.Name == name && fi.IsStatic && fi.IsPublic && fi.FieldType == typeof(BindableProperty)); - if (bpinfo == null) - throw new XamlParseException($"Can't resolve {name} on {type.Name}", lineinfo); - var bp = bpinfo.GetValue(null) as BindableProperty; - var isObsolete = bpinfo.GetCustomAttribute() != null; - if (bp != null && bp.PropertyName != propertyName && !isObsolete) - throw new XamlParseException($"The PropertyName of {type.Name}.{name} is not {propertyName}", lineinfo); - return bp; - } - - Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo) - { - var parents = parentValueProvider.ParentObjects.ToList(); - - // Skip 0; we would not be making this check if TargetObject were not a Setter - // Skip 1; we would not be making this check if the immediate parent were not a VisualState - - // VisualStates must be in a VisualStateGroup - if(!(parents[2] is VisualStateGroup)) { - throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo); - } - - var vsTarget = parents[3]; - - // Are these Visual States directly on a VisualElement? - if (vsTarget is /*VisualElement*/BaseHandle) - { - return vsTarget.GetType(); - } - - if (!(parents[3] is VisualStateGroupList)) - { - throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo); - } - - if (!(parents[4] is Setter)) - { - throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo); - } - - // These must be part of a Style; verify that - if (!(parents[5] is Style style)) - { - throw new XamlParseException($"Expected {nameof(Style)} but found {parents[5]}.", lineInfo); - } - - return style.TargetType; - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyKey.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyKey.cs deleted file mode 100755 index 4ab8e4a74..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindablePropertyKey.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// The secret key to a BindableProperty, used to implement a BindableProperty with restricted write access. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class BindablePropertyKey - { - internal BindablePropertyKey(BindableProperty property) - { - if (property == null) - throw new ArgumentNullException("property"); - - BindableProperty = property; - } - - /// - /// Gets the BindableProperty. - /// - public BindableProperty BindableProperty { get; private set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Binding.cs b/src/Tizen.NUI/src/internal/XamlBinding/Binding.cs deleted file mode 100755 index bbbd9d918..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Binding.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Text; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Binding -{ - internal sealed class Binding : BindingBase - { - internal const string SelfPath = "."; - IValueConverter _converter; - object _converterParameter; - - BindingExpression _expression; - string _path; - object _source; - string _updateSourceEventName; - - public Binding() - { - } - - public Binding(string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, string stringFormat = null, object source = null) - { - if (path == null) - throw new ArgumentNullException("path"); - if (string.IsNullOrWhiteSpace(path)) - throw new ArgumentException("path can not be an empty string", "path"); - - Path = path; - Converter = converter; - ConverterParameter = converterParameter; - Mode = mode; - StringFormat = stringFormat; - Source = source; - } - - public IValueConverter Converter - { - get { return _converter; } - set - { - ThrowIfApplied(); - - _converter = value; - } - } - - public object ConverterParameter - { - get { return _converterParameter; } - set - { - ThrowIfApplied(); - - _converterParameter = value; - } - } - - public string Path - { - get { return _path; } - set - { - ThrowIfApplied(); - - _path = value; - _expression = new BindingExpression(this, !string.IsNullOrWhiteSpace(value) ? value : SelfPath); - } - } - - public object Source - { - get { return _source; } - set - { - ThrowIfApplied(); - _source = value; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public string UpdateSourceEventName { - get { return _updateSourceEventName; } - set { - ThrowIfApplied(); - _updateSourceEventName = value; - } - } - - [Obsolete] - public static Binding Create(Expression> propertyGetter, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, - string stringFormat = null) - { - if (propertyGetter == null) - throw new ArgumentNullException("propertyGetter"); - - return new Binding(GetBindingPath(propertyGetter), mode, converter, converterParameter, stringFormat); - } - - internal override void Apply(bool fromTarget) - { - base.Apply(fromTarget); - - if (_expression == null) - _expression = new BindingExpression(this, SelfPath); - - _expression.Apply(fromTarget); - } - - internal override void Apply(object newContext, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false) - { - object src = _source; - var isApplied = IsApplied; - - base.Apply(src ?? newContext, bindObj, targetProperty, fromBindingContextChanged: fromBindingContextChanged); - - if (src != null && isApplied && fromBindingContextChanged) - return; - - object bindingContext = src ?? Context ?? newContext; - if (_expression == null && bindingContext != null) - _expression = new BindingExpression(this, SelfPath); - - _expression?.Apply(bindingContext, bindObj, targetProperty); - } - - internal override BindingBase Clone() - { - return new Binding(Path, Mode) { Converter = Converter, ConverterParameter = ConverterParameter, StringFormat = StringFormat, Source = Source, UpdateSourceEventName = UpdateSourceEventName }; - } - - internal override object GetSourceValue(object value, Type targetPropertyType) - { - if (Converter != null) - value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture); - - return base.GetSourceValue(value, targetPropertyType); - } - - internal override object GetTargetValue(object value, Type sourcePropertyType) - { - if (Converter != null) - value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture); - - return base.GetTargetValue(value, sourcePropertyType); - } - - internal override void Unapply(bool fromBindingContextChanged = false) - { - if (Source != null && fromBindingContextChanged && IsApplied) - return; - - base.Unapply(fromBindingContextChanged: fromBindingContextChanged); - - if (_expression != null) - _expression.Unapply(); - } - - [Obsolete] - static string GetBindingPath(Expression> propertyGetter) - { - Expression expr = propertyGetter.Body; - - var unary = expr as UnaryExpression; - if (unary != null) - expr = unary.Operand; - - var builder = new StringBuilder(); - - var indexed = false; - - var member = expr as MemberExpression; - if (member == null) - { - var methodCall = expr as MethodCallExpression; - if (methodCall != null) - { - if (methodCall.Arguments.Count == 0) - throw new ArgumentException("Method calls are not allowed in binding expression"); - - var arguments = new List(methodCall.Arguments.Count); - foreach (Expression arg in methodCall.Arguments) - { - if (arg.NodeType != ExpressionType.Constant) - throw new ArgumentException("Only constants can be used as indexer arguments"); - - object value = ((ConstantExpression)arg).Value; - arguments.Add(value != null ? value.ToString() : "null"); - } - - Type declarerType = methodCall.Method.DeclaringType; - DefaultMemberAttribute defaultMember = declarerType.GetTypeInfo().GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType().FirstOrDefault(); - string indexerName = defaultMember != null ? defaultMember.MemberName : "Item"; - - MethodInfo getterInfo = - declarerType.GetProperties().Where(pi => (pi.GetMethod != null) && pi.Name == indexerName && pi.CanRead && pi.GetMethod.IsPublic && !pi.GetMethod.IsStatic).Select(pi => pi.GetMethod).FirstOrDefault(); - if (getterInfo != null) - { - if (getterInfo == methodCall.Method) - { - indexed = true; - builder.Append("["); - - var first = true; - foreach (string argument in arguments) - { - if (!first) - builder.Append(","); - - builder.Append(argument); - first = false; - } - - builder.Append("]"); - - member = methodCall.Object as MemberExpression; - } - else - throw new ArgumentException("Method calls are not allowed in binding expressions"); - } - else - throw new ArgumentException("Public indexer not found"); - } - else - throw new ArgumentException("Invalid expression type"); - } - - while (member != null) - { - var property = (PropertyInfo)member.Member; - if (builder.Length != 0) - { - if (!indexed) - builder.Insert(0, "."); - else - indexed = false; - } - - builder.Insert(0, property.Name); - - // member = member.Expression as MemberExpression ?? (member.Expression as UnaryExpression)?.Operand as MemberExpression; - member = member.Expression as MemberExpression ?? (member.Expression is UnaryExpression ? (member.Expression as UnaryExpression).Operand as MemberExpression : null); - } - - return builder.ToString(); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindingBase.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindingBase.cs deleted file mode 100755 index 93a2355f8..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindingBase.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System; -using System.Collections; -using System.Runtime.CompilerServices; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// An abstract class that provides a BindingMode and a formatting option. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal abstract class BindingBase - { - static readonly ConditionalWeakTable SynchronizedCollections = new ConditionalWeakTable(); - - BindingMode _mode = BindingMode.Default; - string _stringFormat; - object _targetNullValue; - object _fallbackValue; - - internal BindingBase() - { - } - - /// - /// Gets or sets the mode for this binding. - /// - public BindingMode Mode - { - get { return _mode; } - set - { - if ( value != BindingMode.Default - && value != BindingMode.OneWay - && value != BindingMode.OneWayToSource - && value != BindingMode.TwoWay - && value != BindingMode.OneTime) - throw new ArgumentException("mode is not a valid BindingMode", "mode"); - - ThrowIfApplied(); - - _mode = value; - } - } - - /// - /// Gets or sets the string format for this binding. - /// - public string StringFormat - { - get { return _stringFormat; } - set - { - ThrowIfApplied(); - - _stringFormat = value; - } - } - - public object TargetNullValue - { - get { return _targetNullValue; } - set { - ThrowIfApplied(); - _targetNullValue = value; - } - } - - public object FallbackValue { - get => _fallbackValue; - set { - ThrowIfApplied(); - _fallbackValue = value; - } - } - - internal bool AllowChaining { get; set; } - - internal object Context { get; set; } - - internal bool IsApplied { get; private set; } - - /// - /// Stops synchronization on the collection. - /// - /// The collection on which to stop synchronization. - public static void DisableCollectionSynchronization(IEnumerable collection) - { - if (collection == null) - throw new ArgumentNullException(nameof(collection)); - - SynchronizedCollections.Remove(collection); - } - - public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback) - { - if (collection == null) - throw new ArgumentNullException(nameof(collection)); - if (callback == null) - throw new ArgumentNullException(nameof(callback)); - - SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback)); - } - - /// - /// Throws an InvalidOperationException if the binding has been applied. - /// - protected void ThrowIfApplied() - { - if (IsApplied) - throw new InvalidOperationException("Can not change a binding while it's applied"); - } - - internal virtual void Apply(bool fromTarget) - { - IsApplied = true; - } - - internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false) - { - IsApplied = true; - } - - internal abstract BindingBase Clone(); - - internal virtual object GetSourceValue(object value, Type targetPropertyType) - { - if (value == null && TargetNullValue != null) - return TargetNullValue; - if (StringFormat != null) - return string.Format(StringFormat, value); - - return value; - } - - internal virtual object GetTargetValue(object value, Type sourcePropertyType) - { - return value; - } - - internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext) - { - if (collection == null) - throw new ArgumentNullException(nameof(collection)); - - return SynchronizedCollections.TryGetValue(collection, out synchronizationContext); - } - - internal virtual void Unapply(bool fromBindingContextChanged = false) - { - IsApplied = false; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindingMode.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindingMode.cs deleted file mode 100755 index bf1ff9ab9..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindingMode.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// The direction of changes propagation for bindings. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public enum BindingMode - { - /// - /// When used in Bindings, indicates that the Binding should use the DefaultBindingMode. When used in BindableProperty declaration, defaults to BindingMode.OneWay. - /// - Default, - - /// - /// Indicates that the binding should propagates changes from source (usually the View Model) to target (the BindableObject) in both directions. - /// - TwoWay, - - /// - /// Indicates that the binding should only propagate changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values. - /// - OneWay, - - /// - /// Indicates that the binding should only propagate changes from target (the BindableObject) to source (usually the View Model). This is mainly used for read-only BindableProperty values. - /// - OneWayToSource, - - /// - /// Indicates that the binding will be applied only when the binding context changes and the value will not be monitored for changes with INotifyPropertyChanged. - /// - OneTime, - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/BindingTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/BindingTypeConverter.cs deleted file mode 100755 index 62839e27e..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/BindingTypeConverter.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Tizen.NUI.Binding -{ - [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindingTypeConverter")] - [Xaml.TypeConversion(typeof(Binding))] - internal sealed class BindingTypeConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - return new Binding(value); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/CollectionSynchronizationCallback.cs b/src/Tizen.NUI/src/internal/XamlBinding/CollectionSynchronizationCallback.cs deleted file mode 100755 index 056dfe867..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/CollectionSynchronizationCallback.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; -using System.Collections; - -namespace Tizen.NUI.Binding -{ - internal delegate void CollectionSynchronizationCallback(IEnumerable collection, object context, Action accessMethod, bool writeAccess); -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ColorTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/ColorTypeConverter.cs deleted file mode 100755 index 51cb27334..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ColorTypeConverter.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Globalization; - -namespace Tizen.NUI.Binding -{ - [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ColorTypeConverter")] - [Xaml.TypeConversion(typeof(Color))] - internal class ColorTypeConverter : TypeConverter - { - // Supported inputs - // HEX #rgb, #argb, #rrggbb, #aarrggbb - // float array 0.5,0.5,0.5,0.5 - // Predefined color case insensitive - public override object ConvertFromInvariantString(string value) - { - if (value != null) - { - value = value.Trim(); - if (value.StartsWith("#", StringComparison.Ordinal)) - { - return FromHex(value); - } - - string[] parts = value.Split(','); - if (parts.Length == 1) //like Red or Color.Red - { - parts = value.Split('.'); - if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "Color")) - { - string color = parts[parts.Length - 1]; - switch (color) - { - case "Black": return Color.Black; - case "White": return Color.White; - case "Red": return Color.Red; - case "Green": return Color.Green; - case "Blue": return Color.Blue; - case "Yellow": return Color.Yellow; - case "Magenta": return Color.Magenta; - case "Cyan": return Color.Cyan; - case "Transparent": return Color.Transparent; - } - } - } - else if (parts.Length == 4) //like 0.5,0.5,0.5,0.5 - { - return new Color(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), - Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), - Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture), - Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture)); - } - } - - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Color)}"); - } - - static uint ToHex(char c) - { - ushort x = (ushort)c; - if (x >= '0' && x <= '9') - return (uint)(x - '0'); - - x |= 0x20; - if (x >= 'a' && x <= 'f') - return (uint)(x - 'a' + 10); - return 0; - } - - static uint ToHexD(char c) - { - var j = ToHex(c); - return (j << 4) | j; - } - - public static Color FromRgba(int r, int g, int b, int a) - { - float red = (float)r / 255; - float green = (float)g / 255; - float blue = (float)b / 255; - float alpha = (float)a / 255; - return new Color(red, green, blue, alpha); - } - - public static Color FromRgb(int r, int g, int b) - { - return FromRgba(r, g, b, 255); - } - - static Color FromHex(string hex) - { - // Undefined - if (hex.Length < 3) - return Color.Black; - int idx = (hex[0] == '#') ? 1 : 0; - - switch (hex.Length - idx) - { - case 3: //#rgb => ffrrggbb - var t1 = ToHexD(hex[idx++]); - var t2 = ToHexD(hex[idx++]); - var t3 = ToHexD(hex[idx]); - - return FromRgb((int)t1, (int)t2, (int)t3); - - case 4: //#argb => aarrggbb - var f1 = ToHexD(hex[idx++]); - var f2 = ToHexD(hex[idx++]); - var f3 = ToHexD(hex[idx++]); - var f4 = ToHexD(hex[idx]); - return FromRgba((int)f2, (int)f3, (int)f4, (int)f1); - - case 6: //#rrggbb => ffrrggbb - return FromRgb((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx]))); - - case 8: //#aarrggbb - var a1 = ToHex(hex[idx++]) << 4 | ToHex(hex[idx++]); - return FromRgba((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), - (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])), - (int)a1); - - default: //everything else will result in unexpected results - return Color.Black; - } - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Configuration.cs b/src/Tizen.NUI/src/internal/XamlBinding/Configuration.cs deleted file mode 100755 index a99a5c2c2..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Configuration.cs +++ /dev/null @@ -1,21 +0,0 @@ - -namespace Tizen.NUI.Binding -{ - internal class Configuration : IPlatformElementConfiguration - where TPlatform : IConfigPlatform - where TElement : Element - - { - public Configuration(TElement element) - { - Element = element; - } - - public TElement Element { get; } - - public static Configuration Create(TElement element) - { - return new Configuration(element); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/DependencyService.cs b/src/Tizen.NUI/src/internal/XamlBinding/DependencyService.cs index 54e1424b4..d83d49360 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/DependencyService.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/DependencyService.cs @@ -108,7 +108,7 @@ namespace Tizen.NUI.Binding catch (System.IO.FileNotFoundException) { // Sometimes the previewer doesn't actually have everything required for these loads to work - Console.WriteLine(nameof(Registrar), "Could not load assembly: {0} for Attibute {1} | Some renderers may not be loaded", assembly.FullName, targetAttrType.FullName); + Tizen.Log.Fatal("NUI", "Could not load assembly: {0} for Attibute {1} | Some renderers may not be loaded", assembly.FullName, targetAttrType.FullName); continue; } diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Device.cs b/src/Tizen.NUI/src/internal/XamlBinding/Device.cs index 8987212e5..17156aa18 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/Device.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/Device.cs @@ -22,8 +22,6 @@ namespace Tizen.NUI.Binding [EditorBrowsable(EditorBrowsableState.Never)] public static DeviceInfo info; - static IPlatformServices s_platformServices; - [EditorBrowsable(EditorBrowsableState.Never)] public static void SetIdiom(TargetIdiom value) => Idiom = value; public static TargetIdiom Idiom { get; internal set; } @@ -53,7 +51,7 @@ namespace Tizen.NUI.Binding } #pragma warning restore 0618 - public static string RuntimePlatform => PlatformServices?.RuntimePlatform; + public static string RuntimePlatform => null; [EditorBrowsable(EditorBrowsableState.Never)] public static DeviceInfo Info @@ -71,28 +69,6 @@ namespace Tizen.NUI.Binding public static void SetFlowDirection(FlowDirection value) => FlowDirection = value; public static FlowDirection FlowDirection { get; internal set; } - [EditorBrowsable(EditorBrowsableState.Never)] - public static bool IsInvokeRequired - { - get { return PlatformServices.IsInvokeRequired; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static IPlatformServices PlatformServices - { - get - { - if (s_platformServices == null) - throw new InvalidOperationException("You MUST call Tizen.NUI.Init(); prior to using it."); - return s_platformServices; - } - set - { - s_platformServices = value; - Console.WriteLine("Device s_platformServices : " + s_platformServices ); - } - } - [EditorBrowsable(EditorBrowsableState.Never)] public static IReadOnlyList Flags { get; private set; } @@ -104,7 +80,6 @@ namespace Tizen.NUI.Binding public static void BeginInvokeOnMainThread(Action action) { - PlatformServices?.BeginInvokeOnMainThread(action); action(); Console.WriteLine("Device BeginInvokeOnMainThread action called"); } @@ -119,37 +94,6 @@ namespace Tizen.NUI.Binding // return GetNamedSize(size, targetElementType, false); // } - [Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")] - public static void OnPlatform(Action iOS = null, Action Android = null, Action WinPhone = null, Action Default = null) - { - switch (OS) - { - case TargetPlatform.iOS: - if (iOS != null) - iOS(); - else if (Default != null) - Default(); - break; - case TargetPlatform.Android: - if (Android != null) - Android(); - else if (Default != null) - Default(); - break; - case TargetPlatform.Windows: - case TargetPlatform.WinPhone: - if (WinPhone != null) - WinPhone(); - else if (Default != null) - Default(); - break; - case TargetPlatform.Other: - if (Default != null) - Default(); - break; - } - } - [Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")] public static T OnPlatform(T iOS, T Android, T WinPhone) { @@ -172,15 +116,10 @@ namespace Tizen.NUI.Binding // PlatformServices?.OpenUriAction(uri); } - public static void StartTimer(TimeSpan interval, Func callback) - { - PlatformServices.StartTimer(interval, callback); - } - [EditorBrowsable(EditorBrowsableState.Never)] public static Assembly[] GetAssemblies() { - return PlatformServices?.GetAssemblies(); + return null; } // [EditorBrowsable(EditorBrowsableState.Never)] @@ -189,11 +128,6 @@ namespace Tizen.NUI.Binding // return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes); // } - internal static Task GetStreamAsync(Uri uri, CancellationToken cancellationToken) - { - return PlatformServices?.GetStreamAsync(uri, cancellationToken); - } - public static class Styles { public static readonly string TitleStyleKey = "TitleStyle"; diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Effect.cs b/src/Tizen.NUI/src/internal/XamlBinding/Effect.cs deleted file mode 100755 index a70c710ad..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Effect.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.ComponentModel; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Binding -{ - /// - /// A collection of styles and properties that can be added to an element at run time. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal abstract class Effect - { - internal Effect() - { - } - - /// - /// Gets the element to which the style is attached. - /// - public Element Element { get; internal set; } - - /// - /// Gets a value that tells whether the effect is attached to an element. - /// - public bool IsAttached { get; private set; } - - /// - /// Gets the ID that is used to resolve this effect at runtime. - /// - public string ResolveId { get; internal set; } - - #region Statics - /// - /// Returns an Effect for the specified name, which is of the form ResolutionGroupName.ExportEffect. - /// - /// The name of the effect to get. - /// The uniquely identified effect. - public static Effect Resolve(string name) - { - Effect result = null; - if (Tizen.NUI.Binding.Internals.Registrar.Effects.TryGetValue(name, out Type effectType)) - { - result = (Effect)DependencyResolver.ResolveOrCreate(effectType); - } - - if (result == null) - result = new NullEffect(); - result.ResolveId = name; - return result; - } - - #endregion - - /// - /// Method that is called after the effect is attached and made valid. - /// - protected abstract void OnAttached(); - - /// - /// Method that is called after the effect is detached and invalidated. - /// - protected abstract void OnDetached(); - - internal virtual void ClearEffect() - { - if (IsAttached) - SendDetached(); - Element = null; - } - - internal virtual void SendAttached() - { - if (IsAttached) - return; - OnAttached(); - IsAttached = true; - } - - internal virtual void SendDetached() - { - if (!IsAttached) - return; - OnDetached(); - IsAttached = false; - } - - internal virtual void SendOnElementPropertyChanged(PropertyChangedEventArgs args) - { - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/EffectiveFlowDirection.cs b/src/Tizen.NUI/src/internal/XamlBinding/EffectiveFlowDirection.cs deleted file mode 100755 index 605588d07..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/EffectiveFlowDirection.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - [Flags] - internal enum EffectiveFlowDirection - { - RightToLeft = 1 << 0, - Explicit = 1 << 1, - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/EffectiveFlowDirectionExtensions.cs b/src/Tizen.NUI/src/internal/XamlBinding/EffectiveFlowDirectionExtensions.cs deleted file mode 100755 index 513b27bb9..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/EffectiveFlowDirectionExtensions.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.ComponentModel; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Binding -{ - [EditorBrowsable(EditorBrowsableState.Never)] - internal static class EffectiveFlowDirectionExtensions - { - internal static EffectiveFlowDirection ToEffectiveFlowDirection(this FlowDirection self, bool isExplicit = false) - { - switch (self) - { - case FlowDirection.MatchParent: - return default(EffectiveFlowDirection); - - - case FlowDirection.LeftToRight: - if (isExplicit) - { - return EffectiveFlowDirection.Explicit; - } - else - { - return default(EffectiveFlowDirection); - } - - case FlowDirection.RightToLeft: - if (isExplicit) - { - return EffectiveFlowDirection.RightToLeft | EffectiveFlowDirection.Explicit; - } - else - { - return EffectiveFlowDirection.RightToLeft; - } - - default: - throw new InvalidOperationException($"Cannot convert {self} to {nameof(EffectiveFlowDirection)}."); - } - } - - internal static FlowDirection ToFlowDirection(this EffectiveFlowDirection self) - { - if (self.IsLeftToRight()) - return FlowDirection.LeftToRight; - else - return FlowDirection.RightToLeft; - - throw new InvalidOperationException($"Cannot convert {self} to {nameof(FlowDirection)}."); - } - - public static bool IsRightToLeft(this EffectiveFlowDirection self) - { - return (self & EffectiveFlowDirection.RightToLeft) == EffectiveFlowDirection.RightToLeft; - } - - public static bool IsLeftToRight(this EffectiveFlowDirection self) - { - return (self & EffectiveFlowDirection.RightToLeft) != EffectiveFlowDirection.RightToLeft; - } - - public static bool IsImplicit(this EffectiveFlowDirection self) - { - return (self & EffectiveFlowDirection.Explicit) != EffectiveFlowDirection.Explicit; - } - - public static bool IsExplicit(this EffectiveFlowDirection self) - { - return (self & EffectiveFlowDirection.Explicit) == EffectiveFlowDirection.Explicit; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ElementCollection.cs b/src/Tizen.NUI/src/internal/XamlBinding/ElementCollection.cs deleted file mode 100755 index 6427287c6..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ElementCollection.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.ObjectModel; - -namespace Tizen.NUI.Binding -{ - internal class ElementCollection : ObservableWrapper where T : Element - { - public ElementCollection(ObservableCollection list) : base(list) - { - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ElementEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ElementEventArgs.cs deleted file mode 100755 index fcdeacd90..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ElementEventArgs.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal class ElementEventArgs : EventArgs - { - public ElementEventArgs(Element element) - { - if (element == null) - throw new ArgumentNullException("element"); - - Element = element; - } - - public Element Element { get; private set; } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/FileImageSource.cs b/src/Tizen.NUI/src/internal/XamlBinding/FileImageSource.cs deleted file mode 100755 index f65a0e8ee..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/FileImageSource.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Threading.Tasks; - -namespace Tizen.NUI.Binding -{ - [TypeConverter(typeof(FileImageSourceConverter))] - internal sealed class FileImageSource : ImageSource - { - public static readonly BindableProperty FileProperty = BindableProperty.Create("File", typeof(string), typeof(FileImageSource), default(string)); - - public string File - { - get { return (string)GetValue(FileProperty); } - set { SetValue(FileProperty, value); } - } - - public override Task Cancel() - { - return Task.FromResult(false); - } - - public override string ToString() - { - return $"File: {File}"; - } - - public static implicit operator FileImageSource(string file) - { - return (FileImageSource)FromFile(file); - } - - public static implicit operator string(FileImageSource file) - { - return file != null ? file.File : null; - } - - protected override void OnPropertyChanged(string propertyName = null) - { - if (propertyName == FileProperty.PropertyName) - OnSourceChanged(); - base.OnPropertyChanged(propertyName); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/FileImageSourceConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/FileImageSourceConverter.cs deleted file mode 100755 index cf5c00995..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/FileImageSourceConverter.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - [Xaml.TypeConversion(typeof(FileImageSource))] - internal sealed class FileImageSourceConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value != null) - return (FileImageSource)ImageSource.FromFile(value); - - throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FileImageSource))); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IAppIndexingProvider.cs b/src/Tizen.NUI/src/internal/XamlBinding/IAppIndexingProvider.cs deleted file mode 100755 index 3af69c6d4..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IAppIndexingProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal interface IAppIndexingProvider - { - IAppLinks AppLinks { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IAppLinkEntry.cs b/src/Tizen.NUI/src/internal/XamlBinding/IAppLinkEntry.cs deleted file mode 100755 index e08ea97df..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IAppLinkEntry.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Tizen.NUI.Binding -{ - internal interface IAppLinkEntry - { - Uri AppLinkUri { get; set; } - - string Description { get; set; } - - bool IsLinkActive { get; set; } - - IDictionary KeyValues { get; } - - ImageSource Thumbnail { get; set; } - - string Title { get; set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IAppLinks.cs b/src/Tizen.NUI/src/internal/XamlBinding/IAppLinks.cs deleted file mode 100755 index 4cc17fbdd..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IAppLinks.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal interface IAppLinks - { - void DeregisterLink(IAppLinkEntry appLink); - void DeregisterLink(Uri appLinkUri); - void RegisterLink(IAppLinkEntry appLink); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IApplicationController.cs b/src/Tizen.NUI/src/internal/XamlBinding/IApplicationController.cs deleted file mode 100755 index 296b6ccce..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IApplicationController.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal interface IApplicationController - { - void SetAppIndexingProvider(IAppIndexingProvider appIndexing); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IEffectControlProvider.cs b/src/Tizen.NUI/src/internal/XamlBinding/IEffectControlProvider.cs deleted file mode 100755 index 8f61b223a..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IEffectControlProvider.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// When implemented in a renderer, registers a platform-specific effect on an element. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal interface IEffectControlProvider - { - /// - /// Registers the effect with the element by establishing the parent-child relations needed for rendering on the specific platform. - /// - /// The effect to register. - void RegisterEffect(Effect effect); - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ILayout.cs b/src/Tizen.NUI/src/internal/XamlBinding/ILayout.cs deleted file mode 100755 index dee1f59c2..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ILayout.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal interface ILayout - { - event EventHandler LayoutChanged; - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ILayoutController.cs b/src/Tizen.NUI/src/internal/XamlBinding/ILayoutController.cs deleted file mode 100755 index 7ac639dc8..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ILayoutController.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Tizen.NUI.Binding -{ - internal interface ILayoutController - { - IReadOnlyList Children { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IMenuItemController.cs b/src/Tizen.NUI/src/internal/XamlBinding/IMenuItemController.cs deleted file mode 100755 index 42627ddbb..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IMenuItemController.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal interface IMenuItemController - { - bool IsEnabled { get; set; } - string IsEnabledPropertyName { get; } - - void Activate(); - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/INavigation.cs b/src/Tizen.NUI/src/internal/XamlBinding/INavigation.cs deleted file mode 100755 index d3b98e37f..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/INavigation.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// Interface abstracting platform-specific navigation. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal interface INavigation - { - /// - /// Gets the modal navigation stack. - /// - IReadOnlyList ModalStack { get; } - - /// - /// Gets the stack of pages in the navigation. - /// - IReadOnlyList NavigationStack { get; } - - /// - /// Inserts a page in the navigation stack before an existing page in the stack. - /// - /// The page to add. - /// The existing page, before which page will be inserted. - void InsertPageBefore(Page page, Page before); - - /// - /// Asynchronously removes the most recent Page from the navigation stack. - /// - /// The Page that had been at the top of the navigation stack. - Task PopAsync(); - - /// - /// Asynchronously removes the most recent Page from the navigation stack, with optional animation. - /// - /// Whether to animate the pop. - /// The Page that had been at the top of the navigation stack. - Task PopAsync(bool animated); - - /// - /// Asynchronously dismisses the most recent modally presented Page. - /// - /// An awaitable instance, indicating the PopModalAsync completion. The Task.Result is the Page that has been popped. - Task PopModalAsync(); - - /// - /// Asynchronously dismisses the most recent modally presented Page, with optional animation. - /// - /// Whether to animate the pop. - /// An awaitable, indicating the PopModalAsync completion. The Task.Result is the Page that has been popped. - Task PopModalAsync(bool animated); - - /// - /// Pops all but the root Page off the navigation stack. - /// - /// A task representing the asynchronous dismiss operation. - Task PopToRootAsync(); - - /// - /// Pops all but the root Page off the navigation stack, with optional animation. - /// - /// Whether to animate the pop. - /// A task representing the asynchronous dismiss operation. - Task PopToRootAsync(bool animated); - - /// - /// Asynchronously adds a Page to the top of the navigation stack. - /// - /// The Page to be pushed on top of the navigation stack. - /// A task that represents the asynchronous push operation. - Task PushAsync(Page page); - - /// - /// Asynchronously adds a Page to the top of the navigation stack, with optional animation. - /// - /// The page to push. - /// Whether to animate the push. - /// A task that represents the asynchronous push operation. - Task PushAsync(Page page, bool animated); - - /// - /// Presents a Page modally. - /// - /// The Page to present modally. - /// An awaitable Task, indicating the PushModal completion. - Task PushModalAsync(Page page); - - /// - /// Presents a Page modally, with optional animation. - /// - /// The page to push. - /// Whether to animate the push. - /// An awaitable Task, indicating the PushModal completion. - Task PushModalAsync(Page page, bool animated); - - /// - /// Removes the specified page from the navigation stack. - /// - /// The page to remove. - void RemovePage(Page page); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/INavigationMenuController.cs b/src/Tizen.NUI/src/internal/XamlBinding/INavigationMenuController.cs deleted file mode 100755 index 057bf854a..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/INavigationMenuController.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal interface INavigationMenuController : IViewController - { - void SendTargetSelected(Page target); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/INavigationPageController.cs b/src/Tizen.NUI/src/internal/XamlBinding/INavigationPageController.cs deleted file mode 100755 index 7b9bb3055..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/INavigationPageController.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Binding -{ - internal interface INavigationPageController - { - Task RemoveAsyncInner(Page page, bool animated, bool fast); - - Page Peek(int depth = 0); - - IEnumerable Pages { get; } - - int StackDepth { get; } - - Task PopAsyncInner(bool animated, bool fast = false); - - event EventHandler InsertPageBeforeRequested; - - event EventHandler PopRequested; - - event EventHandler PopToRootRequested; - - event EventHandler PushRequested; - - event EventHandler RemovePageRequested; - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IPaddingElement.cs b/src/Tizen.NUI/src/internal/XamlBinding/IPaddingElement.cs deleted file mode 100755 index e0c395ee3..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IPaddingElement.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Tizen.NUI.Binding -{ - interface IPaddingElement - { - //note to implementor: implement this property publicly - // Thickness Padding { get; } - - //note to implementor: but implement this method explicitly - void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue); - Thickness PaddingDefaultValueCreator(); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IPlatform.cs b/src/Tizen.NUI/src/internal/XamlBinding/IPlatform.cs deleted file mode 100755 index ca89cee1e..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IPlatform.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal interface IPlatform - { - /// - /// Returns the native size. - /// - /// The view - /// The width constraint. - /// The height constraint. - /// The native size. - SizeRequest GetNativeSize(BaseHandle view, double widthConstraint, double heightConstraint); - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IPlatformElementConfiguration.cs b/src/Tizen.NUI/src/internal/XamlBinding/IPlatformElementConfiguration.cs deleted file mode 100755 index 85ad36f70..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IPlatformElementConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// Marker interface for returning platform-specific configuration elements. - /// - /// The platform type. - /// The element type. - [EditorBrowsable(EditorBrowsableState.Never)] - internal interface IPlatformElementConfiguration : IConfigElement - where TPlatform : IConfigPlatform - where TElement : Element - { - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IPlatformServices.cs b/src/Tizen.NUI/src/internal/XamlBinding/IPlatformServices.cs index 5e46ac08c..0f2e260d7 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/IPlatformServices.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/IPlatformServices.cs @@ -15,8 +15,6 @@ namespace Tizen.NUI.Binding void BeginInvokeOnMainThread(Action action); - Ticker CreateTicker(); - Assembly[] GetAssemblies(); string GetMD5Hash(string input); diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IRegisterable.cs b/src/Tizen.NUI/src/internal/XamlBinding/IRegisterable.cs deleted file mode 100755 index 6974fccf2..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IRegisterable.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal interface IRegisterable - { - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ITimer.cs b/src/Tizen.NUI/src/internal/XamlBinding/ITimer.cs deleted file mode 100755 index 1a18f7a7e..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ITimer.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - //this will go once Timer is included in Pcl profiles - internal interface ITimer - { - void Change(int dueTime, int period); - void Change(long dueTime, long period); - void Change(TimeSpan dueTime, TimeSpan period); - void Change(uint dueTime, uint period); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IViewContainer.cs b/src/Tizen.NUI/src/internal/XamlBinding/IViewContainer.cs deleted file mode 100755 index 9346c6cde..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IViewContainer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Tizen.NUI.Binding -{ - internal interface IViewContainer where T : /*VisualElement*/BaseHandle - { - IList Children { get; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IViewController.cs b/src/Tizen.NUI/src/internal/XamlBinding/IViewController.cs deleted file mode 100755 index 76e9152f4..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IViewController.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal interface IViewController : IVisualElementController - { - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/IVisualElementController.cs b/src/Tizen.NUI/src/internal/XamlBinding/IVisualElementController.cs deleted file mode 100755 index 94eec775c..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/IVisualElementController.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Binding -{ - internal interface IVisualElementController : IElementController - { - void NativeSizeChanged(); - void InvalidateMeasure(InvalidationTrigger trigger); - bool Batched { get; } - bool DisableLayout { get; set; } - EffectiveFlowDirection EffectiveFlowDirection { get; } - bool IsInNativeLayout { get; set; } - bool IsNativeStateConsistent { get; set; } - bool IsPlatformEnabled { get; set; } - NavigationProxy NavigationProxy { get; } - event EventHandler> BatchCommitted; - event EventHandler FocusChangeRequested; - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ImageSource.cs b/src/Tizen.NUI/src/internal/XamlBinding/ImageSource.cs deleted file mode 100755 index fa59903e1..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ImageSource.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.IO; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; - -namespace Tizen.NUI.Binding -{ - [TypeConverter(typeof(ImageSourceConverter))] - internal abstract class ImageSource : Element - { - readonly object _synchandle = new object(); - CancellationTokenSource _cancellationTokenSource; - - TaskCompletionSource _completionSource; - - readonly WeakEventManager _weakEventManager = new WeakEventManager(); - - protected ImageSource() - { - } - - protected CancellationTokenSource CancellationTokenSource - { - get { return _cancellationTokenSource; } - private set - { - if (_cancellationTokenSource == value) - return; - if (_cancellationTokenSource != null) - _cancellationTokenSource.Cancel(); - _cancellationTokenSource = value; - } - } - - bool IsLoading - { - get { return _cancellationTokenSource != null; } - } - - public virtual Task Cancel() - { - if (!IsLoading) - return Task.FromResult(false); - - var tcs = new TaskCompletionSource(); - TaskCompletionSource original = Interlocked.CompareExchange(ref _completionSource, tcs, null); - if (original == null) - { - _cancellationTokenSource.Cancel(); - } - else - tcs = original; - - return tcs.Task; - } - - public static ImageSource FromFile(string file) - { - return new FileImageSource { File = file }; - } - - public static ImageSource FromResource(string resource, Type resolvingType) - { - return FromResource(resource, resolvingType.GetTypeInfo().Assembly); - } - - public static ImageSource FromResource(string resource, Assembly sourceAssembly = null) - { -#if NETSTANDARD2_0 - sourceAssembly = sourceAssembly ?? Assembly.GetCallingAssembly(); -#else - if (sourceAssembly == null) - { - MethodInfo callingAssemblyMethod = typeof(Assembly).GetTypeInfo().GetDeclaredMethod("GetCallingAssembly"); - if (callingAssemblyMethod != null) - { - sourceAssembly = (Assembly)callingAssemblyMethod.Invoke(null, new object[0]); - } - else - { - Internals.Log.Warning("Warning", "Can not find CallingAssembly, pass resolvingType to FromResource to ensure proper resolution"); - return null; - } - } -#endif - return FromStream(() => sourceAssembly.GetManifestResourceStream(resource)); - } - - public static ImageSource FromStream(Func stream) - { - // return new StreamImageSource { Stream = token => Task.Run(stream, token) }; - return null; - } - - public static ImageSource FromUri(Uri uri) - { - if (!uri.IsAbsoluteUri) - throw new ArgumentException("uri is relative"); - // return new UriImageSource { Uri = uri }; - return null; - } - - public static implicit operator ImageSource(string source) - { - Uri uri; - return Uri.TryCreate(source, UriKind.Absolute, out uri) && uri.Scheme != "file" ? FromUri(uri) : FromFile(source); - } - - public static implicit operator ImageSource(Uri uri) - { - if (!uri.IsAbsoluteUri) - throw new ArgumentException("uri is relative"); - return FromUri(uri); - } - - protected void OnLoadingCompleted(bool cancelled) - { - if (!IsLoading || _completionSource == null) - return; - - TaskCompletionSource tcs = Interlocked.Exchange(ref _completionSource, null); - if (tcs != null) - tcs.SetResult(cancelled); - - lock (_synchandle) - { - CancellationTokenSource = null; - } - } - - protected void OnLoadingStarted() - { - lock (_synchandle) - { - CancellationTokenSource = new CancellationTokenSource(); - } - } - - protected void OnSourceChanged() - { - _weakEventManager.HandleEvent(this, EventArgs.Empty, nameof(SourceChanged)); - } - - internal event EventHandler SourceChanged - { - add { _weakEventManager.AddEventHandler(nameof(SourceChanged), value); } - remove { _weakEventManager.RemoveEventHandler(nameof(SourceChanged), value); } - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ImageSourceConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/ImageSourceConverter.cs deleted file mode 100755 index 1082dc2f5..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ImageSourceConverter.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - [Xaml.TypeConversion(typeof(ImageSource))] - internal sealed class ImageSourceConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value != null) - { - Uri uri; - return Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme != "file" ? ImageSource.FromUri(uri) : ImageSource.FromFile(value); - } - - throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(ImageSource))); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Behavior.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Behavior.cs deleted file mode 100755 index 388f3a837..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Behavior.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Reflection; - -namespace Tizen.NUI.Binding -{ - internal abstract class Behavior : BindableObject, IAttachedObject - { - internal Behavior(Type associatedType) - { - if (associatedType == null) - throw new ArgumentNullException("associatedType"); - AssociatedType = associatedType; - } - - protected Type AssociatedType { get; } - - void IAttachedObject.AttachTo(BindableObject bindable) - { - if (bindable == null) - throw new ArgumentNullException("bindable"); - if (!AssociatedType.IsInstanceOfType(bindable)) - throw new InvalidOperationException("bindable not an instance of AssociatedType"); - OnAttachedTo(bindable); - } - - void IAttachedObject.DetachFrom(BindableObject bindable) - { - OnDetachingFrom(bindable); - } - - protected virtual void OnAttachedTo(BindableObject bindable) - { - } - - protected virtual void OnDetachingFrom(BindableObject bindable) - { - } - } - - internal abstract class Behavior : Behavior where T : BindableObject - { - protected Behavior() : base(typeof(T)) - { - } - - protected override void OnAttachedTo(BindableObject bindable) - { - base.OnAttachedTo(bindable); - OnAttachedTo((T)bindable); - } - - protected virtual void OnAttachedTo(T bindable) - { - } - - protected override void OnDetachingFrom(BindableObject bindable) - { - OnDetachingFrom((T)bindable); - base.OnDetachingFrom(bindable); - } - - protected virtual void OnDetachingFrom(T bindable) - { - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/BindingCondition.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/BindingCondition.cs deleted file mode 100755 index 63f031924..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/BindingCondition.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] - [AcceptEmptyServiceProvider] - internal sealed class BindingCondition : Condition, IValueProvider - { - readonly BindableProperty _boundProperty; - - BindingBase _binding; - object _triggerValue; - - public BindingCondition() - { - _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged); - } - - public BindingBase Binding - { - get { return _binding; } - set - { - if (_binding == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Binding once the Condition has been applied."); - _binding = value; - } - } - - public object Value - { - get { return _triggerValue; } - set - { - if (_triggerValue == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Value once the Condition has been applied."); - _triggerValue = value; - } - } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - //This is no longer required - return this; - } - - internal override bool GetState(BindableObject bindable) - { - object newValue = bindable.GetValue(_boundProperty); - return EqualsToValue(newValue); - } - - internal override void SetUp(BindableObject bindable) - { - if (Binding != null) - bindable.SetBinding(_boundProperty, Binding.Clone()); - } - - internal override void TearDown(BindableObject bindable) - { - bindable.RemoveBinding(_boundProperty); - bindable.ClearValue(_boundProperty); - } - - static IValueConverterProvider s_valueConverter = DependencyService.Get(); - - bool EqualsToValue(object other) - { - if ((other == Value) || (other != null && other.Equals(Value))) - return true; - - object converted = null; - if (s_valueConverter != null) - converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null); - else - return false; - - return (other == converted) || (other != null && other.Equals(converted)); - } - - void OnBoundPropertyChanged(BindableObject bindable, object oldValue, object newValue) - { - bool oldState = EqualsToValue(oldValue); - bool newState = EqualsToValue(newValue); - - if (newState == oldState) - return; - - if (ConditionChanged != null) - ConditionChanged(bindable, oldState, newState); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Condition.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Condition.cs deleted file mode 100755 index 74ee0a2eb..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Condition.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal abstract class Condition - { - Action _conditionChanged; - - bool _isSealed; - - internal Condition() - { - } - - internal Action ConditionChanged - { - get { return _conditionChanged; } - set - { - if (_conditionChanged == value) - return; - if (_conditionChanged != null) - throw new InvalidOperationException("The same condition instance can not be reused"); - _conditionChanged = value; - } - } - - internal bool IsSealed - { - get { return _isSealed; } - set - { - if (_isSealed == value) - return; - if (!value) - throw new InvalidOperationException("What is sealed can not be unsealed."); - _isSealed = value; - OnSealed(); - } - } - - internal abstract bool GetState(BindableObject bindable); - - internal virtual void OnSealed() - { - } - - internal abstract void SetUp(BindableObject bindable); - internal abstract void TearDown(BindableObject bindable); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/DataTrigger.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/DataTrigger.cs deleted file mode 100755 index 96e881550..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/DataTrigger.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Setters")] - [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] - [AcceptEmptyServiceProvider] - internal sealed class DataTrigger : TriggerBase, IValueProvider - { - public DataTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new BindingCondition(), targetType) - { - } - - public BindingBase Binding - { - get { return ((BindingCondition)Condition).Binding; } - set - { - if (((BindingCondition)Condition).Binding == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Binding once the Trigger has been applied."); - OnPropertyChanging(); - ((BindingCondition)Condition).Binding = value; - OnPropertyChanged(); - } - } - - public new IList Setters - { - get { return base.Setters; } - } - - public object Value - { - get { return ((BindingCondition)Condition).Value; } - set - { - if (((BindingCondition)Condition).Value == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); - OnPropertyChanging(); - ((BindingCondition)Condition).Value = value; - OnPropertyChanged(); - } - } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - //This is no longer required - return this; - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/EventTrigger.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/EventTrigger.cs deleted file mode 100755 index 749b3ec0c..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/EventTrigger.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Tizen.NUI.Binding.Internals; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Actions")] - internal sealed class EventTrigger : TriggerBase - { - static readonly MethodInfo s_handlerinfo = typeof(EventTrigger).GetRuntimeMethods().Single(mi => mi.Name == "OnEventTriggered" && mi.IsPublic == false); - readonly List _associatedObjects = new List(); - - EventInfo _eventinfo; - - string _eventname; - Delegate _handlerdelegate; - - public EventTrigger() : base(typeof(BindableObject)) - { - Actions = new SealedList(); - } - - public IList Actions { get; } - - public string Event - { - get { return _eventname; } - set - { - if (_eventname == value) - return; - if (IsSealed) - throw new InvalidOperationException("Event cannot be changed once the Trigger has been applied"); - OnPropertyChanging(); - _eventname = value; - OnPropertyChanged(); - } - } - - internal override void OnAttachedTo(BindableObject bindable) - { - base.OnAttachedTo(bindable); - if (!string.IsNullOrEmpty(Event)) - AttachHandlerTo(bindable); - _associatedObjects.Add(bindable); - } - - internal override void OnDetachingFrom(BindableObject bindable) - { - _associatedObjects.Remove(bindable); - DetachHandlerFrom(bindable); - base.OnDetachingFrom(bindable); - } - - internal override void OnSeal() - { - base.OnSeal(); - ((SealedList)Actions).IsReadOnly = true; - } - - void AttachHandlerTo(BindableObject bindable) - { - try - { - _eventinfo = bindable.GetType().GetRuntimeEvent(Event); - _handlerdelegate = s_handlerinfo.CreateDelegate(_eventinfo?.EventHandlerType, this); - } - catch (Exception) - { - Console.WriteLine("EventTrigger", "Can not attach EventTrigger to {0}.{1}. Check if the handler exists and if the signature is right.", bindable.GetType(), Event); - } - if (_eventinfo != null && _handlerdelegate != null) - _eventinfo.AddEventHandler(bindable, _handlerdelegate); - } - - void DetachHandlerFrom(BindableObject bindable) - { - if (_eventinfo != null && _handlerdelegate != null) - _eventinfo.RemoveEventHandler(bindable, _handlerdelegate); - } - - // [Preserve] - void OnEventTriggered(object sender, EventArgs e) - { - var bindable = (BindableObject)sender; - foreach (TriggerAction action in Actions) - action.DoInvoke(bindable); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/MultiTrigger.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/MultiTrigger.cs deleted file mode 100755 index 0311a3b87..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/MultiTrigger.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Setters")] - internal sealed class MultiTrigger : TriggerBase - { - public MultiTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new MultiCondition(), targetType) - { - } - - public IList Conditions - { - get { return ((MultiCondition)Condition).Conditions; } - } - - public new IList Setters - { - get { return base.Setters; } - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/PropertyCondition.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/PropertyCondition.cs deleted file mode 100755 index 54bc675fc..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/PropertyCondition.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.ComponentModel; -using System.Reflection; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Xaml -{ - [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] - [AcceptEmptyServiceProvider] - internal sealed class PropertyCondition : Condition, IValueProvider - { - readonly BindableProperty _stateProperty; - - BindableProperty _property; - object _triggerValue; - - public PropertyCondition() - { - _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(PropertyCondition), false, propertyChanged: OnStatePropertyChanged); - } - - public BindableProperty Property - { - get { return _property; } - set - { - if (_property == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Property once the Trigger has been applied."); - _property = value; - - //convert the value - if (_property != null && s_valueConverter != null) - { - Func minforetriever = () => Property.DeclaringType.GetRuntimeProperty(Property.PropertyName); - Value = s_valueConverter.Convert(Value, Property.ReturnType, minforetriever, null); - } - } - } - - public object Value - { - get { return _triggerValue; } - set - { - if (_triggerValue == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); - - //convert the value - if (_property != null && s_valueConverter != null) - { - Func minforetriever = () => Property.DeclaringType.GetRuntimeProperty(Property.PropertyName); - value = s_valueConverter.Convert(value, Property.ReturnType, minforetriever, null); - } - _triggerValue = value; - } - } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - //This is no longer required - return this; - } - - internal override bool GetState(BindableObject bindable) - { - return (bool)bindable.GetValue(_stateProperty); - } - - static IValueConverterProvider s_valueConverter = DependencyService.Get(); - - internal override void SetUp(BindableObject bindable) - { - object newvalue = bindable.GetValue(Property); - bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); - bindable.SetValue(_stateProperty, newState); - bindable.PropertyChanged += OnAttachedObjectPropertyChanged; - } - - internal override void TearDown(BindableObject bindable) - { - bindable.ClearValue(_stateProperty); - bindable.PropertyChanged -= OnAttachedObjectPropertyChanged; - } - - void OnAttachedObjectPropertyChanged(object sender, PropertyChangedEventArgs e) - { - var bindable = (BindableObject)sender; - var oldState = (bool)bindable.GetValue(_stateProperty); - - if (Property == null) - return; - if (e.PropertyName != Property.PropertyName) - return; - object newvalue = bindable.GetValue(Property); - bool newstate = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); - if (oldState != newstate) - bindable.SetValue(_stateProperty, newstate); - } - - void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue) - { - if ((bool)oldValue == (bool)newValue) - return; - - ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Trigger.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Trigger.cs deleted file mode 100755 index 28fd9446e..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/Trigger.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Setters")] - [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] - [AcceptEmptyServiceProvider] - internal sealed class Trigger : TriggerBase, IValueProvider - { - public Trigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new XamlPropertyCondition(), targetType) - { - } - - public BindableProperty Property - { - get { return ((XamlPropertyCondition)Condition).Property; } - set - { - if (((XamlPropertyCondition)Condition).Property == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Property once the Trigger has been applied."); - OnPropertyChanging(); - ((XamlPropertyCondition)Condition).Property = value; - OnPropertyChanged(); - } - } - - public new IList Setters - { - get { return base.Setters; } - } - - public object Value - { - get { return ((XamlPropertyCondition)Condition).Value; } - set - { - if (((XamlPropertyCondition)Condition).Value == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); - OnPropertyChanging(); - ((XamlPropertyCondition)Condition).Value = value; - OnPropertyChanged(); - } - } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - //This is no longer required - return this; - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/TriggerAction.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/TriggerAction.cs deleted file mode 100755 index 7aa32d766..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/TriggerAction.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal abstract class TriggerAction - { - internal TriggerAction(Type associatedType) - { - if (associatedType == null) - throw new ArgumentNullException("associatedType"); - AssociatedType = associatedType; - } - - protected Type AssociatedType { get; private set; } - - protected abstract void Invoke(object sender); - - internal virtual void DoInvoke(object sender) - { - Invoke(sender); - } - } - - internal abstract class TriggerAction : TriggerAction where T : BindableObject - { - protected TriggerAction() : base(typeof(T)) - { - } - - protected override void Invoke(object sender) - { - Invoke((T)sender); - } - - protected abstract void Invoke(T sender); - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/TriggerBase.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/TriggerBase.cs deleted file mode 100755 index 6eef4829f..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/TriggerBase.cs +++ /dev/null @@ -1,213 +0,0 @@ -using System; -using System.Reflection; -using System.Collections; -using System.Collections.Generic; - -namespace Tizen.NUI.Binding -{ - internal abstract class TriggerBase : BindableObject, IAttachedObject - { - bool _isSealed; - - internal TriggerBase(Type targetType) - { - if (targetType == null) - throw new ArgumentNullException("targetType"); - TargetType = targetType; - - EnterActions = new SealedList(); - ExitActions = new SealedList(); - } - - internal TriggerBase(Condition condition, Type targetType) : this(targetType) - { - Setters = new SealedList(); - Condition = condition; - Condition.ConditionChanged = OnConditionChanged; - } - - public IList EnterActions { get; } - - public IList ExitActions { get; } - - public bool IsSealed - { - get { return _isSealed; } - private set - { - if (_isSealed == value) - return; - if (!value) - throw new InvalidOperationException("What is sealed can not be unsealed."); - _isSealed = value; - OnSeal(); - } - } - - public Type TargetType { get; } - - internal Condition Condition { get; } - - //Setters and Condition are used by Trigger, DataTrigger and MultiTrigger - internal IList Setters { get; } - - void IAttachedObject.AttachTo(BindableObject bindable) - { - IsSealed = true; - - if (bindable == null) - throw new ArgumentNullException("bindable"); - if (!TargetType.IsInstanceOfType(bindable)) - throw new InvalidOperationException("bindable not an instance of AssociatedType"); - OnAttachedTo(bindable); - } - - void IAttachedObject.DetachFrom(BindableObject bindable) - { - if (bindable == null) - throw new ArgumentNullException("bindable"); - OnDetachingFrom(bindable); - } - - internal virtual void OnAttachedTo(BindableObject bindable) - { - if (Condition != null) - Condition.SetUp(bindable); - } - - internal virtual void OnDetachingFrom(BindableObject bindable) - { - if (Condition != null) - Condition.TearDown(bindable); - } - - internal virtual void OnSeal() - { - ((SealedList)EnterActions).IsReadOnly = true; - ((SealedList)ExitActions).IsReadOnly = true; - if (Setters != null) - ((SealedList)Setters).IsReadOnly = true; - if (Condition != null) - Condition.IsSealed = true; - } - - void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue) - { - if (newValue) - { - foreach (TriggerAction action in EnterActions) - action.DoInvoke(bindable); - foreach (Setter setter in Setters) - setter.Apply(bindable); - } - else - { - foreach (Setter setter in Setters) - setter.UnApply(bindable); - foreach (TriggerAction action in ExitActions) - action.DoInvoke(bindable); - } - } - - internal class SealedList : IList - { - readonly IList _actual; - - bool _isReadOnly; - - public SealedList() - { - _actual = new List(); - } - - public void Add(T item) - { - if (IsReadOnly) - throw new InvalidOperationException("This list is ReadOnly"); - _actual.Add(item); - } - - public void Clear() - { - if (IsReadOnly) - throw new InvalidOperationException("This list is ReadOnly"); - _actual.Clear(); - } - - public bool Contains(T item) - { - return _actual.Contains(item); - } - - public void CopyTo(T[] array, int arrayIndex) - { - _actual.CopyTo(array, arrayIndex); - } - - public int Count - { - get { return _actual.Count; } - } - - public bool IsReadOnly - { - get { return _isReadOnly; } - set - { - if (_isReadOnly == value) - return; - if (!value) - throw new InvalidOperationException("Can't change this back to non readonly"); - _isReadOnly = value; - } - } - - public bool Remove(T item) - { - if (IsReadOnly) - throw new InvalidOperationException("This list is ReadOnly"); - return _actual.Remove(item); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)_actual).GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return _actual.GetEnumerator(); - } - - public int IndexOf(T item) - { - return _actual.IndexOf(item); - } - - public void Insert(int index, T item) - { - if (IsReadOnly) - throw new InvalidOperationException("This list is ReadOnly"); - _actual.Insert(index, item); - } - - public T this[int index] - { - get { return _actual[index]; } - set - { - if (IsReadOnly) - throw new InvalidOperationException("This list is ReadOnly"); - _actual[index] = value; - } - } - - public void RemoveAt(int index) - { - if (IsReadOnly) - throw new InvalidOperationException("This list is ReadOnly"); - _actual.RemoveAt(index); - } - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/XamlPropertyCondition.cs b/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/XamlPropertyCondition.cs deleted file mode 100755 index b17ac58f4..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Interactivity/XamlPropertyCondition.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.ComponentModel; -using System.Reflection; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")] - [AcceptEmptyServiceProvider] - internal sealed class XamlPropertyCondition : Condition, IValueProvider - { - readonly BindableProperty _stateProperty; - - BindableProperty _property; - object _triggerValue; - - public XamlPropertyCondition() - { - _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged); - } - - public BindableProperty Property - { - get { return _property; } - set - { - if (_property == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Property once the Trigger has been applied."); - _property = value; - - //convert the value - if (_property != null && s_valueConverter != null) - { - Func minforetriever = () => _property.DeclaringType.GetRuntimeProperty(_property.PropertyName); - Value = s_valueConverter.Convert(Value, _property.ReturnType, minforetriever, null); - } - } - } - - public object Value - { - get { return _triggerValue; } - set - { - if (_triggerValue == value) - return; - if (IsSealed) - throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); - - //convert the value - if (_property != null && s_valueConverter != null) - { - Func minforetriever = () => _property.DeclaringType.GetRuntimeProperty(_property.PropertyName); - _triggerValue = s_valueConverter.Convert(value, _property.ReturnType, minforetriever, null); - } - else - { - _triggerValue = value; - } - - } - } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - //This is no longer required - return this; - } - - internal override bool GetState(BindableObject bindable) - { - return (bool)bindable.GetValue(_stateProperty); - } - - static IValueConverterProvider s_valueConverter = DependencyService.Get(); - - internal override void SetUp(BindableObject bindable) - { - object newvalue = bindable.GetValue(Property); - bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); - bindable.SetValue(_stateProperty, newState); - bindable.PropertyChanged += OnAttachedObjectPropertyChanged; - } - - internal override void TearDown(BindableObject bindable) - { - bindable.ClearValue(_stateProperty); - bindable.PropertyChanged -= OnAttachedObjectPropertyChanged; - } - - void OnAttachedObjectPropertyChanged(object sender, PropertyChangedEventArgs e) - { - var bindable = (BindableObject)sender; - var oldState = (bool)bindable.GetValue(_stateProperty); - - if (Property == null) - return; - if (e.PropertyName != Property.PropertyName) - return; - object newvalue = bindable.GetValue(Property); - bool newstate = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); - if (oldState != newstate) - bindable.SetValue(_stateProperty, newstate); - } - - void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue) - { - if ((bool)oldValue == (bool)newValue) - return; - - ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Internals/DynamicResource.cs b/src/Tizen.NUI/src/internal/XamlBinding/Internals/DynamicResource.cs deleted file mode 100755 index 30545a84f..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Internals/DynamicResource.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel; - -namespace Tizen.NUI.Binding.Internals -{ - internal class DynamicResource - { - public DynamicResource(string key) - { - Key = key; - } - - public string Key { get; private set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Internals/IDynamicResourceHandler.cs b/src/Tizen.NUI/src/internal/XamlBinding/Internals/IDynamicResourceHandler.cs deleted file mode 100755 index 62d53a225..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Internals/IDynamicResourceHandler.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.ComponentModel; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Binding.Internals -{ - internal interface IDynamicResourceHandler - { - void SetDynamicResource(BindableProperty property, string key); - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Internals/INameScope.cs b/src/Tizen.NUI/src/internal/XamlBinding/Internals/INameScope.cs deleted file mode 100755 index c9b6ba83d..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Internals/INameScope.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.ComponentModel; -using System.Xml; - -namespace Tizen.NUI.Binding.Internals -{ - internal interface INameScope - { - object FindByName(string name); - void RegisterName(string name, object scopedElement); - void UnregisterName(string name); - [Obsolete]void RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo); - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Internals/NameScope.cs b/src/Tizen.NUI/src/internal/XamlBinding/Internals/NameScope.cs deleted file mode 100755 index 13b4bfa43..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Internals/NameScope.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Xml; -using Tizen.NUI.Binding; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding.Internals -{ - internal class NameScope : INameScope - { - public static readonly BindableProperty NameScopeProperty = BindableProperty.CreateAttached("NameScope", typeof(INameScope), typeof(NameScope), default(INameScope)); - - readonly Dictionary _names = new Dictionary(); - - object INameScope.FindByName(string name) - { - if (_names.ContainsKey(name)) - return _names[name]; - return null; - } - - void INameScope.RegisterName(string name, object scopedElement) - { - if (_names.ContainsKey(name)) - throw new ArgumentException("An element with the same key already exists in NameScope", "name"); - - _names[name] = scopedElement; - } - - [Obsolete] - void INameScope.RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo) - { - try - { - ((INameScope)this).RegisterName(name, scopedElement); - } - catch (ArgumentException) - { - throw new XamlParseException(string.Format("An element with the name \"{0}\" already exists in this NameScope", name), xmlLineInfo); - } - } - - void INameScope.UnregisterName(string name) - { - _names.Remove(name); - } - - public static INameScope GetNameScope(BindableObject bindable) - { - return (INameScope)bindable.GetValue(NameScopeProperty); - } - - public static void SetNameScope(BindableObject bindable, INameScope value) - { - bindable.SetValue(NameScopeProperty, value); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Internals/Ticker.cs b/src/Tizen.NUI/src/internal/XamlBinding/Internals/Ticker.cs deleted file mode 100755 index 7b00bb973..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Internals/Ticker.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Binding.Internals -{ - internal abstract class Ticker - { - static Ticker s_ticker; - readonly Stopwatch _stopwatch; - readonly List>> _timeouts; - - int _count; - bool _enabled; - - protected Ticker() - { - _count = 0; - _timeouts = new List>>(); - - _stopwatch = new Stopwatch(); - } - - public static void SetDefault(Ticker ticker) => Default = ticker; - public static Ticker Default - { - internal set { s_ticker = value; } - get { return s_ticker ?? (s_ticker = Device.PlatformServices.CreateTicker()); } - } - - public virtual int Insert(Func timeout) - { - _count++; - _timeouts.Add(new Tuple>(_count, timeout)); - - if (!_enabled) - { - _enabled = true; - Enable(); - } - - return _count; - } - - public virtual void Remove(int handle) - { - Device.BeginInvokeOnMainThread(() => - { - _timeouts.RemoveAll(t => t.Item1 == handle); - - if (!_timeouts.Any()) - { - _enabled = false; - Disable(); - } - }); - } - - protected abstract void DisableTimer(); - - protected abstract void EnableTimer(); - - protected void SendSignals(int timestep = -1) - { - long step = timestep >= 0 ? timestep : _stopwatch.ElapsedMilliseconds; - _stopwatch.Reset(); - _stopwatch.Start(); - - var localCopy = new List>>(_timeouts); - foreach (Tuple> timeout in localCopy) - { - bool remove = !timeout.Item2(step); - if (remove) - _timeouts.RemoveAll(t => t.Item1 == timeout.Item1); - } - - if (!_timeouts.Any()) - { - _enabled = false; - Disable(); - } - } - - void Disable() - { - _stopwatch.Reset(); - DisableTimer(); - } - - void Enable() - { - _stopwatch.Start(); - EnableTimer(); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Internals/TypedBinding.cs b/src/Tizen.NUI/src/internal/XamlBinding/Internals/TypedBinding.cs deleted file mode 100755 index ed30914a7..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Internals/TypedBinding.cs +++ /dev/null @@ -1,299 +0,0 @@ -#define DO_NOT_CHECK_FOR_BINDING_REUSE - -using System; -using System.ComponentModel; -using System.Globalization; -using System.Collections.Generic; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Binding.Internals -{ - //FIXME: need a better name for this, and share with Binding, so we can share more unittests - internal abstract class TypedBindingBase : BindingBase - { - IValueConverter _converter; - object _converterParameter; - object _source; - string _updateSourceEventName; - - public IValueConverter Converter { - get { return _converter; } - set { - ThrowIfApplied(); - _converter = value; - } - } - - public object ConverterParameter { - get { return _converterParameter; } - set { - ThrowIfApplied(); - _converterParameter = value; - } - } - - public object Source { - get { return _source; } - set { - ThrowIfApplied(); - _source = value; - } - } - - internal string UpdateSourceEventName { - get { return _updateSourceEventName; } - set { - ThrowIfApplied(); - _updateSourceEventName = value; - } - } - - internal TypedBindingBase() - { - } - } - - internal sealed class TypedBinding : TypedBindingBase - { - readonly Func _getter; - readonly Action _setter; - readonly PropertyChangedProxy [] _handlers; - - public TypedBinding(Func getter, Action setter, Tuple, string> [] handlers) - { - if (getter == null) - throw new ArgumentNullException(nameof(getter)); - - _getter = getter; - _setter = setter; - - if (handlers == null) - return; - - _handlers = new PropertyChangedProxy [handlers.Length]; - for (var i = 0; i < handlers.Length; i++) - _handlers [i] = new PropertyChangedProxy(handlers [i].Item1, handlers [i].Item2, this); - } - - readonly WeakReference _weakSource = new WeakReference(null); - readonly WeakReference _weakTarget = new WeakReference(null); - BindableProperty _targetProperty; - - // Applies the binding to a previously set source and target. - internal override void Apply(bool fromTarget = false) - { - base.Apply(fromTarget); - - BindableObject target; -#if DO_NOT_CHECK_FOR_BINDING_REUSE - if (!_weakTarget.TryGetTarget(out target)) - throw new InvalidOperationException(); -#else - if (!_weakTarget.TryGetTarget(out target) || target == null) { - Unapply(); - return; - } -#endif - object source; - if (_weakSource.TryGetTarget(out source) && source != null) - ApplyCore(source, target, _targetProperty, fromTarget); - } - - // Applies the binding to a new source or target. - internal override void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false) - { - _targetProperty = targetProperty; - var source = Source ?? Context ?? context; - var isApplied = IsApplied; - - if (Source != null && isApplied && fromBindingContextChanged) - return; - - base.Apply(source, bindObj, targetProperty, fromBindingContextChanged); - -#if (!DO_NOT_CHECK_FOR_BINDING_REUSE) - BindableObject prevTarget; - if (_weakTarget.TryGetTarget(out prevTarget) && !ReferenceEquals(prevTarget, bindObj)) - throw new InvalidOperationException("Binding instances can not be reused"); - - object previousSource; - if (_weakSource.TryGetTarget(out previousSource) && !ReferenceEquals(previousSource, source)) - throw new InvalidOperationException("Binding instances can not be reused"); -#endif - _weakSource.SetTarget(source); - _weakTarget.SetTarget(bindObj); - - ApplyCore(source, bindObj, targetProperty); - } - - internal override BindingBase Clone() - { - Tuple, string> [] handlers = _handlers == null ? null : new Tuple, string> [_handlers.Length]; - if (handlers != null) { - for (var i = 0; i < _handlers.Length; i++) - handlers [i] = new Tuple, string>(_handlers [i].PartGetter, _handlers [i].PropertyName); - } - return new TypedBinding(_getter, _setter, handlers) { - Mode = Mode, - Converter = Converter, - ConverterParameter = ConverterParameter, - StringFormat = StringFormat, - Source = Source, - UpdateSourceEventName = UpdateSourceEventName, - }; - } - - internal override object GetSourceValue(object value, Type targetPropertyType) - { - if (Converter != null) - value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture); - - //return base.GetSourceValue(value, targetPropertyType); - if (StringFormat != null) - return string.Format(StringFormat, value); - - return value; - } - - internal override object GetTargetValue(object value, Type sourcePropertyType) - { - if (Converter != null) - value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture); - - //return base.GetTargetValue(value, sourcePropertyType); - return value; - } - - internal override void Unapply(bool fromBindingContextChanged = false) - { - if (Source != null && fromBindingContextChanged && IsApplied) - return; - -#if (!DO_NOT_CHECK_FOR_BINDING_REUSE) - base.Unapply(fromBindingContextChanged:fromBindingContextChanged); -#endif - if (_handlers != null) - Unsubscribe(); - -#if (!DO_NOT_CHECK_FOR_BINDING_REUSE) - _weakSource.SetTarget(null); - _weakTarget.SetTarget(null); -#endif - } - - // ApplyCore is as slim as it should be: - // Setting 100000 values : 17ms. - // ApplyCore 100000 (w/o INPC, w/o unnapply) : 20ms. - internal void ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget = false) - { - var isTSource = sourceObject != null && sourceObject is TSource; - var mode = this.GetRealizedMode(property); - if ((mode == BindingMode.OneWay || mode == BindingMode.OneTime) && fromTarget) - return; - - var needsGetter = (mode == BindingMode.TwoWay && !fromTarget) || mode == BindingMode.OneWay || mode == BindingMode.OneTime; - - if (isTSource && (mode == BindingMode.OneWay || mode == BindingMode.TwoWay) && _handlers != null) - Subscribe((TSource)sourceObject); - - if (needsGetter) { - var value = property.DefaultValue; - if (isTSource) { - try { - value = GetSourceValue(_getter((TSource)sourceObject), property.ReturnType); - } catch (Exception ex) when (ex is NullReferenceException || ex is KeyNotFoundException) { - } - } - if (!TryConvert(ref value, property, property.ReturnType, true)) { - // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType); - return; - } - target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false); - return; - } - - var needsSetter = (mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource; - if (needsSetter && _setter != null && isTSource) { - var value = GetTargetValue(target.GetValue(property), typeof(TProperty)); - if (!TryConvert(ref value, property, typeof(TProperty), false)) { - // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, typeof(TProperty)); - return; - } - _setter((TSource)sourceObject, (TProperty)value); - } - } - - static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget) - { - if (value == null) - return true; - if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value))) - return true; - - object original = value; - try { - value = Convert.ChangeType(value, convertTo, CultureInfo.InvariantCulture); - return true; - } catch (Exception ex ) when (ex is InvalidCastException || ex is FormatException||ex is OverflowException) { - value = original; - return false; - } - } - - class PropertyChangedProxy - { - public Func PartGetter { get; } - public string PropertyName { get; } - public BindingExpression.WeakPropertyChangedProxy Listener { get; } - WeakReference _weakPart = new WeakReference(null); - readonly BindingBase _binding; - - public INotifyPropertyChanged Part { - get { - INotifyPropertyChanged target; - if (_weakPart.TryGetTarget(out target)) - return target; - return null; - } - set { - _weakPart.SetTarget(value); - Listener.SubscribeTo(value, OnPropertyChanged); - } - } - - public PropertyChangedProxy(Func partGetter, string propertyName, BindingBase binding) - { - PartGetter = partGetter; - PropertyName = propertyName; - _binding = binding; - Listener = new BindingExpression.WeakPropertyChangedProxy(); - } - - void OnPropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (!string.IsNullOrEmpty(e.PropertyName) && string.CompareOrdinal(e.PropertyName, PropertyName) != 0) - return; - Device.BeginInvokeOnMainThread(() => _binding.Apply(false)); - } - } - - void Subscribe(TSource sourceObject) - { - for (var i = 0; i < _handlers.Length; i++) { - var part = _handlers [i].PartGetter(sourceObject); - if (part == null) - break; - var inpc = part as INotifyPropertyChanged; - if (inpc == null) - continue; - _handlers [i].Part = (inpc); - } - } - - void Unsubscribe() - { - for (var i = 0; i < _handlers.Length; i++) - _handlers [i].Listener.Unsubscribe(); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Layout.cs b/src/Tizen.NUI/src/internal/XamlBinding/Layout.cs deleted file mode 100755 index f3a00719d..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Layout.cs +++ /dev/null @@ -1,319 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Linq; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.BaseComponents; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Children")] - internal abstract class Layout : Layout, IViewContainer where T : View - { - readonly ElementCollection _children; - - protected Layout() - { - _children = new ElementCollection(InternalChildren); - } - - public new IList Children - { - get { return _children; } - } - - protected virtual void OnAdded(T view) - { - } - - protected override void OnChildAdded(Element child) - { - base.OnChildAdded(child); - - var typedChild = child as T; - if (typedChild != null) - OnAdded(typedChild); - } - - protected override void OnChildRemoved(Element child) - { - base.OnChildRemoved(child); - - var typedChild = child as T; - if (typedChild != null) - OnRemoved(typedChild); - } - - protected virtual void OnRemoved(T view) - { - } - } - - internal abstract class Layout : View, ILayout, ILayoutController, IPaddingElement - { - public static readonly BindableProperty IsClippedToBoundsProperty = BindableProperty.Create("IsClippedToBounds", typeof(bool), typeof(Layout), false); - - public static readonly BindableProperty CascadeInputTransparentProperty = BindableProperty.Create( - nameof(CascadeInputTransparent), typeof(bool), typeof(Layout), true); - - public static new readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty; - - static IList> s_resolutionList = new List>(); - static bool s_relayoutInProgress; - - bool _hasDoneLayout; - Size _lastLayoutSize = new Size(-1, -1, 0); - - ReadOnlyCollection _logicalChildren; - - protected Layout() - { - //if things were added in base ctor (through implicit styles), the items added aren't properly parented - if (InternalChildren.Count > 0) - InternalChildrenOnCollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, InternalChildren)); - - InternalChildren.CollectionChanged += InternalChildrenOnCollectionChanged; - } - - public bool IsClippedToBounds - { - get { return (bool)GetValue(IsClippedToBoundsProperty); } - set { SetValue(IsClippedToBoundsProperty, value); } - } - - public new Thickness Padding - { - get { return (Thickness)GetValue(PaddingElement.PaddingProperty); } - set { SetValue(PaddingElement.PaddingProperty, value); } - } - - public bool CascadeInputTransparent - { - get { return (bool)GetValue(CascadeInputTransparentProperty); } - set { SetValue(CascadeInputTransparentProperty, value); } - } - - Thickness IPaddingElement.PaddingDefaultValueCreator() - { - return default(Thickness); - } - - void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) - { - UpdateChildrenLayout(); - } - - internal ObservableCollection InternalChildren { get; } = new ObservableCollection(); - - internal override ReadOnlyCollection LogicalChildrenInternal - { - get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection(InternalChildren)); } - } - - /// - /// Raised when the layout of the Page has changed. - /// - public event EventHandler LayoutChanged; - - [EditorBrowsable(EditorBrowsableState.Never)] - public new IReadOnlyList Children - { - get { return InternalChildren; } - } - - public void ForceLayout() - { - } - - - public static void LayoutChildIntoBoundingRegion(BaseHandle child, Rectangle region) - { - var view = child as View; - if (view == null) - { - return; - } - } - - public void LowerChild(View view) - { - if (!InternalChildren.Contains(view) || (InternalChildren.First() as BaseHandle) == view) - return; - - InternalChildren.Move(InternalChildren.IndexOf(view), 0); - } - - public void RaiseChild(View view) - { - if (!InternalChildren.Contains(view) || (InternalChildren.Last() as BaseHandle) == view) - return; - - InternalChildren.Move(InternalChildren.IndexOf(view), InternalChildren.Count - 1); - } - - protected virtual void InvalidateLayout() - { - _hasDoneLayout = false; - if (!_hasDoneLayout) - ForceLayout(); - } - - protected abstract void LayoutChildren(double x, double y, double width, double height); - - protected void OnChildMeasureInvalidated(object sender, EventArgs e) - { - InvalidationTrigger trigger = (e as InvalidationEventArgs)?.Trigger ?? InvalidationTrigger.Undefined; - OnChildMeasureInvalidated((BaseHandle)sender, trigger); - OnChildMeasureInvalidated(); - } - - protected virtual void OnChildMeasureInvalidated() - { - } - - protected virtual bool ShouldInvalidateOnChildAdded(View child) - { - return true; - } - - protected virtual bool ShouldInvalidateOnChildRemoved(View child) - { - return true; - } - - protected void UpdateChildrenLayout() - { - _hasDoneLayout = true; - - if (!ShouldLayoutChildren()) - return; - - LayoutChanged?.Invoke(this, EventArgs.Empty); - } - - internal static void LayoutChildIntoBoundingRegion(View child, Rectangle region, SizeRequest childSizeRequest) - { - } - - internal virtual void OnChildMeasureInvalidated(BaseHandle child, InvalidationTrigger trigger) - { - ReadOnlyCollection children = LogicalChildrenInternal; - int count = children.Count; - for (var index = 0; index < count; index++) - { - var v = LogicalChildrenInternal[index] as BaseHandle; - if (v != null) - { - return; - } - } - - var view = child as View; - if (view != null) - { - //we can ignore the request if we are either fully constrained or when the size request changes and we were already fully constrainted - if ((trigger == InvalidationTrigger.MeasureChanged) || - (trigger == InvalidationTrigger.SizeRequestChanged)) - { - return; - } - } - - s_resolutionList.Add(new KeyValuePair(this, GetElementDepth(this))); - if (!s_relayoutInProgress) - { - s_relayoutInProgress = true; - Device.BeginInvokeOnMainThread(() => - { - // if thread safety mattered we would need to lock this and compareexchange above - IList> copy = s_resolutionList; - s_resolutionList = new List>(); - s_relayoutInProgress = false; - }); - } - } - - static int GetElementDepth(Element view) - { - var result = 0; - while (view.Parent != null) - { - result++; - view = view.Parent; - } - return result; - } - - void InternalChildrenOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - if (e.Action == NotifyCollectionChangedAction.Move) - { - return; - } - - if (e.OldItems != null) - { - foreach (object item in e.OldItems) - { - var v = item as View; - if (v == null) - continue; - - OnInternalRemoved(v); - } - } - - if (e.NewItems != null) - { - foreach (object item in e.NewItems) - { - var v = item as View; - if (v == null) - continue; - - if ((item as BaseHandle) == this) - throw new InvalidOperationException("Can not add self to own child collection."); - - OnInternalAdded(v); - } - } - } - - void OnInternalAdded(View view) - { - var parent = view.GetParent() as Layout; - parent?.InternalChildren.Remove(view); - - OnChildAdded(view); - if (ShouldInvalidateOnChildAdded(view)) - InvalidateLayout(); - } - - void OnInternalRemoved(View view) - { - OnChildRemoved(view); - if (ShouldInvalidateOnChildRemoved(view)) - InvalidateLayout(); - } - - bool ShouldLayoutChildren() - { - if ( !LogicalChildrenInternal.Any() ) - { - return false; - } - - foreach (Element element in VisibleDescendants()) - { - var visual = element as BaseHandle; - if (visual == null) - { - continue; - } - } - return true; - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/LayoutAlignment.cs b/src/Tizen.NUI/src/internal/XamlBinding/LayoutAlignment.cs deleted file mode 100755 index 66f478920..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/LayoutAlignment.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - [Flags] - internal enum LayoutAlignment - { - Start = 0, - Center = 1, - End = 2, - Fill = 3 - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/LayoutExpandFlag.cs b/src/Tizen.NUI/src/internal/XamlBinding/LayoutExpandFlag.cs deleted file mode 100755 index 4cc3c2b86..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/LayoutExpandFlag.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - [Flags] - internal enum LayoutExpandFlag - { - Expand = 4 - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/LayoutOptions.cs b/src/Tizen.NUI/src/internal/XamlBinding/LayoutOptions.cs deleted file mode 100755 index 2c9bf7af2..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/LayoutOptions.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - [TypeConverter(typeof(LayoutOptionsConverter))] - internal struct LayoutOptions - { - int _flags; - - public static readonly LayoutOptions Start = new LayoutOptions(LayoutAlignment.Start, false); - public static readonly LayoutOptions Center = new LayoutOptions(LayoutAlignment.Center, false); - public static readonly LayoutOptions End = new LayoutOptions(LayoutAlignment.End, false); - public static readonly LayoutOptions Fill = new LayoutOptions(LayoutAlignment.Fill, false); - public static readonly LayoutOptions StartAndExpand = new LayoutOptions(LayoutAlignment.Start, true); - public static readonly LayoutOptions CenterAndExpand = new LayoutOptions(LayoutAlignment.Center, true); - public static readonly LayoutOptions EndAndExpand = new LayoutOptions(LayoutAlignment.End, true); - public static readonly LayoutOptions FillAndExpand = new LayoutOptions(LayoutAlignment.Fill, true); - - public LayoutOptions(LayoutAlignment alignment, bool expands) - { - var a = (int)alignment; - if (a < 0 || a > 3) - throw new ArgumentOutOfRangeException(); - _flags = (int)alignment | (expands ? (int)LayoutExpandFlag.Expand : 0); - } - - public LayoutAlignment Alignment - { - get { return (LayoutAlignment)(_flags & 3); } - set { _flags = (_flags & ~3) | (int)value; } - } - - public bool Expands - { - get { return (_flags & (int)LayoutExpandFlag.Expand) != 0; } - set { _flags = (_flags & 3) | (value ? (int)LayoutExpandFlag.Expand : 0); } - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/LayoutOptionsConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/LayoutOptionsConverter.cs deleted file mode 100755 index 98cddaa36..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/LayoutOptionsConverter.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using Tizen.NUI.Binding.Internals; - -using Tizen.NUI; - -namespace Tizen.NUI.Binding -{ - [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.LayoutOptionsConverter")] - [Xaml.TypeConversion(typeof(LayoutOptions))] - internal sealed class LayoutOptionsConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value != null) { - var parts = value.Split('.'); - if (parts.Length > 2 || (parts.Length == 2 && parts [0] != "LayoutOptions")) - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(LayoutOptions)}"); - value = parts [parts.Length - 1]; - switch (value) { - case "Start": return LayoutOptions.Start; - case "Center": return LayoutOptions.Center; - case "End": return LayoutOptions.End; - case "Fill": return LayoutOptions.Fill; - case "StartAndExpand": return LayoutOptions.StartAndExpand; - case "CenterAndExpand": return LayoutOptions.CenterAndExpand; - case "EndAndExpand": return LayoutOptions.EndAndExpand; - case "FillAndExpand": return LayoutOptions.FillAndExpand; - } - FieldInfo field = typeof(LayoutOptions).GetFields().FirstOrDefault(fi => fi.IsStatic && fi.Name == value); - if (field != null) - return (LayoutOptions)field.GetValue(null); - } - - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(LayoutOptions)}"); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/MenuItem.cs b/src/Tizen.NUI/src/internal/XamlBinding/MenuItem.cs deleted file mode 100755 index fd3acd69c..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/MenuItem.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Windows.Input; - -namespace Tizen.NUI.Binding -{ - - internal class MenuItem : BaseMenuItem, IMenuItemController - { - public static readonly BindableProperty AcceleratorProperty = BindableProperty.CreateAttached(nameof(Accelerator), typeof(Accelerator), typeof(MenuItem), null); - - public static Accelerator GetAccelerator(BindableObject bindable) => (Accelerator)bindable.GetValue(AcceleratorProperty); - - public static void SetAccelerator(BindableObject bindable, Accelerator value) => bindable.SetValue(AcceleratorProperty, value); - - public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(MenuItem), null); - - public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(MenuItem), null, - propertyChanging: (bo, o, n) => ((MenuItem)bo).OnCommandChanging(), propertyChanged: (bo, o, n) => ((MenuItem)bo).OnCommandChanged()); - - public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(MenuItem), null, - propertyChanged: (bo, o, n) => ((MenuItem)bo).OnCommandParameterChanged()); - - public static readonly BindableProperty IsDestructiveProperty = BindableProperty.Create("IsDestructive", typeof(bool), typeof(MenuItem), false); - - public static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(FileImageSource), typeof(MenuItem), default(FileImageSource)); - - [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create("IsEnabled", typeof(bool), typeof(ToolbarItem), true); - - [EditorBrowsable(EditorBrowsableState.Never)] - public string IsEnabledPropertyName - { - get - { - return IsEnabledProperty.PropertyName; - } - } - - public ICommand Command - { - get { return (ICommand)GetValue(CommandProperty); } - set { SetValue(CommandProperty, value); } - } - - public object CommandParameter - { - get { return GetValue(CommandParameterProperty); } - set { SetValue(CommandParameterProperty, value); } - } - - public FileImageSource Icon - { - get { return (FileImageSource)GetValue(IconProperty); } - set { SetValue(IconProperty, value); } - } - - public bool IsDestructive - { - get { return (bool)GetValue(IsDestructiveProperty); } - set { SetValue(IsDestructiveProperty, value); } - } - - public string Text - { - get { return (string)GetValue(TextProperty); } - set { SetValue(TextProperty, value); } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEnabled - { - get { return (bool)GetValue(IsEnabledProperty); } - set { SetValue(IsEnabledProperty, value); } - } - - bool IsEnabledCore - { - set { SetValueCore(IsEnabledProperty, value); } - } - - public event EventHandler Clicked; - - protected virtual void OnClicked() - => Clicked?.Invoke(this, EventArgs.Empty); - - [EditorBrowsable(EditorBrowsableState.Never)] - public void Activate() - { - if (Command != null) - { - if (IsEnabled) - Command.Execute(CommandParameter); - } - - OnClicked(); - } - - void OnCommandCanExecuteChanged(object sender, EventArgs eventArgs) - { - IsEnabledCore = Command.CanExecute(CommandParameter); - } - - void OnCommandChanged() - { - if (Command == null) - { - IsEnabledCore = true; - return; - } - - IsEnabledCore = Command.CanExecute(CommandParameter); - - Command.CanExecuteChanged += OnCommandCanExecuteChanged; - } - - void OnCommandChanging() - { - if (Command == null) - return; - - Command.CanExecuteChanged -= OnCommandCanExecuteChanged; - } - - void OnCommandParameterChanged() - { - if (Command == null) - return; - - IsEnabledCore = Command.CanExecute(CommandParameter); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/MergedStyle.cs b/src/Tizen.NUI/src/internal/XamlBinding/MergedStyle.cs index eb8710d0b..635800808 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/MergedStyle.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/MergedStyle.cs @@ -11,7 +11,7 @@ namespace Tizen.NUI.Binding { ////If the base type is one of these, stop registering dynamic resources further ////The last one (typeof(Element)) is a safety guard as we might be creating VisualElement directly in internal code - static readonly IList s_stopAtTypes = new List { typeof(View), typeof(Layout<>), typeof(Element) }; + static readonly IList s_stopAtTypes = new List { typeof(View), typeof(Element) }; IList _classStyleProperties; diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ModalEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ModalEventArgs.cs deleted file mode 100755 index 50f582176..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ModalEventArgs.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal abstract class ModalEventArgs : EventArgs - { - protected ModalEventArgs(Page modal) - { - Modal = modal; - } - - public Page Modal { get; private set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ModalPoppedEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ModalPoppedEventArgs.cs deleted file mode 100755 index f634bffc7..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ModalPoppedEventArgs.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal class ModalPoppedEventArgs : ModalEventArgs - { - public ModalPoppedEventArgs(Page modal) : base(modal) - { - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ModalPoppingEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ModalPoppingEventArgs.cs deleted file mode 100755 index 1d89ddb63..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ModalPoppingEventArgs.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal class ModalPoppingEventArgs : ModalEventArgs - { - public ModalPoppingEventArgs(Page modal) : base(modal) - { - } - - public bool Cancel { get; set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ModalPushedEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ModalPushedEventArgs.cs deleted file mode 100755 index d15115331..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ModalPushedEventArgs.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal class ModalPushedEventArgs : ModalEventArgs - { - public ModalPushedEventArgs(Page modal) : base(modal) - { - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ModalPushingEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ModalPushingEventArgs.cs deleted file mode 100755 index e7018c6db..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ModalPushingEventArgs.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal class ModalPushingEventArgs : ModalEventArgs - { - public ModalPushingEventArgs(Page modal) : base(modal) - { - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NamedSize.cs b/src/Tizen.NUI/src/internal/XamlBinding/NamedSize.cs deleted file mode 100755 index ffd65628e..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NamedSize.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal enum NamedSize - { - Default = 0, - Micro = 1, - Small = 2, - Medium = 3, - Large = 4 - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NavigationEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/NavigationEventArgs.cs deleted file mode 100755 index 5b9a8bd47..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NavigationEventArgs.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// EventArgs for the NavigationPage's navigation events. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal class NavigationEventArgs : EventArgs - { - /// - /// Create a NavigationEventArgs instance. - /// - /// The page that was popped or is newly visible. - public NavigationEventArgs(Page page) - { - if (page == null) - throw new ArgumentNullException("page"); - - Page = page; - } - - /// - /// Gets the page that was removed or is newly visible. - /// - public Page Page { get; private set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NavigationMenu.cs b/src/Tizen.NUI/src/internal/XamlBinding/NavigationMenu.cs deleted file mode 100755 index c45cb55c7..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NavigationMenu.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using Tizen.NUI; -using Tizen.NUI.BaseComponents; - -namespace Tizen.NUI.Binding -{ - // Mark as internal until renderers are ready for release after 1.0 - // [RenderWith(typeof(_NavigationMenuRenderer))] - [EditorBrowsable(EditorBrowsableState.Never)] - internal class NavigationMenu : View, /*INavigationMenuController,*/ IElementConfiguration - { - readonly List _targets = new List(); - - readonly Lazy> _platformConfigurationRegistry; - - public NavigationMenu() - { - _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); - } - - public IEnumerable Targets - { - get { return _targets; } - set - { - if (_targets.AsEnumerable().SequenceEqual(value)) - return; - - foreach (Page page in value) - { - VerifyTarget(page); - } - - OnPropertyChanging(); - _targets.Clear(); - _targets.AddRange(value); - OnPropertyChanged(); - } - } - - public void Add(Page target) - { - if (_targets.Contains(target)) - return; - VerifyTarget(target); - - OnPropertyChanging("Targets"); - _targets.Add(target); - OnPropertyChanged("Targets"); - } - - public void Remove(Page target) - { - if (_targets.Contains(target)) - { - OnPropertyChanging("Targets"); - if (_targets.Remove(target)) - OnPropertyChanged("Targets"); - } - } - - public IPlatformElementConfiguration On() where T : IConfigPlatform - { - return _platformConfigurationRegistry.Value.On(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public void SendTargetSelected(Page target) - { - Navigation.PushAsync(target); - } - - void VerifyTarget(Page target) - { - if (target.Icon == null || string.IsNullOrWhiteSpace(target.Icon.File)) - throw new Exception("Icon must be set for each page before adding them to a Navigation Menu"); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NavigationModel.cs b/src/Tizen.NUI/src/internal/XamlBinding/NavigationModel.cs deleted file mode 100755 index 4420a90ef..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NavigationModel.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; - -namespace Tizen.NUI.Binding -{ - [EditorBrowsable(EditorBrowsableState.Never)] - internal class NavigationModel - { - readonly List _modalStack = new List(); - readonly List> _navTree = new List>(); - - public Page CurrentPage - { - get - { - if (_navTree.Any()) - return _navTree.Last().Last(); - return null; - } - } - - public IEnumerable Modals - { - get { return _modalStack; } - } - - public IEnumerable Roots - { - get - { - foreach (List list in _navTree) - { - yield return list[0]; - } - } - } - - public IReadOnlyList> Tree - { - get { return _navTree; } - } - - public void Clear() - { - _navTree.Clear(); - _modalStack.Clear(); - } - - public void InsertPageBefore(Page page, Page before) - { - List currentStack = _navTree.Last(); - int index = currentStack.IndexOf(before); - - if (index == -1) - throw new ArgumentException("before must be in the current navigation context"); - - currentStack.Insert(index, page); - } - - public Page Pop(Page ancestralNav) - { - ancestralNav = AncestorToRoot(ancestralNav); - foreach (List stack in _navTree) - { - if (stack.Contains(ancestralNav)) - { - if (stack.Count <= 1) - throw new InvalidNavigationException("Can not pop final item in stack"); - Page result = stack.Last(); - stack.Remove(result); - return result; - } - } - - throw new InvalidNavigationException("Popped from unpushed item?"); - } - - public Page PopModal() - { - if (_navTree.Count <= 1) - throw new InvalidNavigationException("Can't pop modal without any modals pushed"); - Page modal = _navTree.Last().First(); - _modalStack.Remove(modal); - _navTree.Remove(_navTree.Last()); - return modal; - } - - public Page PopTopPage() - { - Page itemToRemove; - if (_navTree.Count == 1) - { - if (_navTree[0].Count > 1) - { - itemToRemove = _navTree[0].Last(); - _navTree[0].Remove(itemToRemove); - return itemToRemove; - } - return null; - } - itemToRemove = _navTree.Last().Last(); - _navTree.Last().Remove(itemToRemove); - if (!_navTree.Last().Any()) - { - _navTree.RemoveAt(_navTree.Count - 1); - } - return itemToRemove; - } - - public void PopToRoot(Page ancestralNav) - { - ancestralNav = AncestorToRoot(ancestralNav); - foreach (List stack in _navTree) - { - if (stack.Contains(ancestralNav)) - { - if (stack.Count <= 1) - throw new InvalidNavigationException("Can not pop final item in stack"); - stack.RemoveRange(1, stack.Count - 1); - return; - } - } - - throw new InvalidNavigationException("Popped from unpushed item?"); - } - - public void Push(Page page, Page ancestralNav) - { - if (ancestralNav == null) - { - if (_navTree.Any()) - throw new InvalidNavigationException("Ancestor must be provided for all pushes except first"); - _navTree.Add(new List { page }); - return; - } - - ancestralNav = AncestorToRoot(ancestralNav); - - foreach (List stack in _navTree) - { - if (stack.Contains(ancestralNav)) - { - stack.Add(page); - return; - } - } - - throw new InvalidNavigationException("Invalid ancestor passed"); - } - - public void PushModal(Page page) - { - _navTree.Add(new List { page }); - _modalStack.Add(page); - } - - public bool RemovePage(Page page) - { - bool found; - List currentStack = _navTree.Last(); - var i = 0; - while (!(found = currentStack.Remove(page)) && i < _navTree.Count - 1) - { - currentStack = _navTree[i++]; - } - - return found; - } - - Page AncestorToRoot(Page ancestor) - { - Page result = ancestor; - // while (!Application.IsApplicationOrNull(result.RealParent)) - result = (Page)result.RealParent; - return result; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NavigationPage.cs b/src/Tizen.NUI/src/internal/XamlBinding/NavigationPage.cs deleted file mode 100755 index d72def2a6..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NavigationPage.cs +++ /dev/null @@ -1,627 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.Binding; - -namespace Tizen.NUI -{ - /// - /// A Page that manages the navigation and user-experience of a stack of other pages. - /// - // [RenderWith(typeof(_NavigationPageRenderer))] - [EditorBrowsable(EditorBrowsableState.Never)] - internal class NavigationPage : Page, IPageContainer, INavigationPageController, IElementConfiguration - { - /// - /// Identifies the property associated with the title of the back button. - /// - public static readonly BindableProperty BackButtonTitleProperty = BindableProperty.CreateAttached("BackButtonTitle", typeof(string), typeof(Page), null); - - /// - /// Backing store for the HasNavigationBar property. - /// - public static readonly BindableProperty HasNavigationBarProperty = BindableProperty.CreateAttached("HasNavigationBar", typeof(bool), typeof(Page), true); - - /// - /// Backing store for the HasBackButton property. - /// - public static readonly BindableProperty HasBackButtonProperty = BindableProperty.CreateAttached("HasBackButton", typeof(bool), typeof(NavigationPage), true); - - /// - /// Identifies the Tint bindable property. - /// - [Obsolete("TintProperty is obsolete as of version 1.2.0. Please use BarBackgroundColorProperty and BarTextColorProperty to change NavigationPage bar color properties.")] - public static readonly BindableProperty TintProperty = BindableProperty.Create("Tint", typeof(Color), typeof(NavigationPage), /*Color.Default*/Color.Black); - - /// - /// Identifies the property associated with the color of the NavigationPage's bar background color. - /// - public static readonly BindableProperty BarBackgroundColorProperty = BindableProperty.Create("BarBackgroundColor", typeof(Color), typeof(NavigationPage), /*Color.Default*/Color.Black); - - /// - /// Identifies the property associated with the color of the NavigationPage's bar text color. - /// - public static readonly BindableProperty BarTextColorProperty = BindableProperty.Create("BarTextColor", typeof(Color), typeof(NavigationPage), /*Color.Default*/Color.Black); - - /// - /// Indicates the NavigationPage.SetTitleIcon/NavigationPage.GetTitleIcon property. - /// - public static readonly BindableProperty TitleIconProperty = BindableProperty.CreateAttached("TitleIcon", typeof(FileImageSource), typeof(NavigationPage), default(FileImageSource)); - - static readonly BindablePropertyKey CurrentPagePropertyKey = BindableProperty.CreateReadOnly("CurrentPage", typeof(Page), typeof(NavigationPage), null); - - /// - /// Identifies the property associated with NavigationPage.CurrentPage - /// - public static readonly BindableProperty CurrentPageProperty = CurrentPagePropertyKey.BindableProperty; - - static readonly BindablePropertyKey RootPagePropertyKey = BindableProperty.CreateReadOnly(nameof(RootPage), typeof(Page), typeof(NavigationPage), null); - /// - /// Identifies the property associated with NavigationPage.RootPage - /// - public static readonly BindableProperty RootPageProperty = RootPagePropertyKey.BindableProperty; - - /// - /// Initializes a new NavigationPage object. - /// - public NavigationPage() - { - _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); - - Navigation = new NavigationImpl(this); - } - - /// - /// Creates a new NavigationPage element with root as its root element. - /// - /// The root page. - public NavigationPage(Page root) : this() - { - PushPage(root); - } - - /// - /// Gets or sets the background color for the bar at the top of the NavigationPage. - /// - public Color BarBackgroundColor - { - get { return (Color)GetValue(BarBackgroundColorProperty); } - set { SetValue(BarBackgroundColorProperty, value); } - } - - /// - /// Gets or sets the text that appears on the bar at the top of the NavigationPage. - /// - public Color BarTextColor - { - get { return (Color)GetValue(BarTextColorProperty); } - set { SetValue(BarTextColorProperty, value); } - } - - /// - /// The color to be used as the Tint of the NavigationPage. - /// - [Obsolete("Tint is obsolete as of version 1.2.0. Please use BarBackgroundColor and BarTextColor to change NavigationPage bar color properties.")] - public Color Tint - { - get { return (Color)GetValue(TintProperty); } - set { SetValue(TintProperty, value); } - } - - internal Task CurrentNavigationTask { get; set; } - - /// - /// For internal use - /// - /// The depth - /// The page instance - [EditorBrowsable(EditorBrowsableState.Never)] - public Page Peek(int depth) - { - if (depth < 0) - { - return null; - } - - if (InternalChildren.Count <= depth) - { - return null; - } - - return (Page)InternalChildren[InternalChildren.Count - depth - 1]; - } - - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public IEnumerable Pages => InternalChildren.Cast(); - - /// - /// For internal use - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public int StackDepth - { - get { return InternalChildren.Count; } - } - - /// - /// The Page that is currently top-most on the navigation stack. - /// - public Page CurrentPage - { - get { return (Page)GetValue(CurrentPageProperty); } - private set { SetValue(CurrentPagePropertyKey, value); } - } - - /// - /// The Page that is the root of the navigation stack. - /// - public Page RootPage - { - get { return (Page)GetValue(RootPageProperty); } - private set { SetValue(RootPagePropertyKey, value); } - } - - /// - /// The title of the back button for the specified page. - /// - /// The Page whose back-button's title is being requested. - /// The title of the back button that would be shown if the specified page were the Tizen.NUI.Xaml.CurrentPage. - public static string GetBackButtonTitle(BindableObject page) - { - return (string)page.GetValue(BackButtonTitleProperty); - } - - /// - /// Returns a value that indicates whether page has a back button. - /// - /// The page to be checked - /// true if the page has a back button. - public static bool GetHasBackButton(Page page) - { - if (page == null) - throw new ArgumentNullException("page"); - return (bool)page.GetValue(HasBackButtonProperty); - } - - /// - /// Returns a value that indicates whether the page has a navigation bar. - /// - /// The Page being queried. - /// true if page would display a navigation bar were it the CurrentPage. - public static bool GetHasNavigationBar(BindableObject page) - { - return (bool)page.GetValue(HasNavigationBarProperty); - } - - internal static FileImageSource GetTitleIcon(BindableObject bindable) - { - return (FileImageSource)bindable.GetValue(TitleIconProperty); - } - - /// - /// Asynchronously removes the top Page from the navigation stack. - /// - /// The Page that had been at the top of the navigation stack. - public Task PopAsync() - { - return PopAsync(true); - } - - /// - /// Asynchronously removes the top Page from the navigation stack, with optional animation. - /// - /// Whether to animate the pop. - /// The Page that had been at the top of the navigation stack. - public async Task PopAsync(bool animated) - { - var tcs = new TaskCompletionSource(); - if (CurrentNavigationTask != null && !CurrentNavigationTask.IsCompleted) - { - var oldTask = CurrentNavigationTask; - CurrentNavigationTask = tcs.Task; - await oldTask; - } - else - CurrentNavigationTask = tcs.Task; - - var result = await PopAsyncInner(animated, false); - tcs.SetResult(true); - return result; - } - - /// - /// Event that is raised after a page is popped from this NavigationPage element. - /// - public event EventHandler Popped; - - /// - /// Pops all but the root Page off the navigation stack. - /// - /// A task that represents the asynchronous dismiss operation. - public Task PopToRootAsync() - { - return PopToRootAsync(true); - } - - /// - /// A task for asynchronously popping all pages off of the navigation stack. - /// - /// Whether to animate the pop. - /// A task that represents the asynchronous dismiss operation. - public async Task PopToRootAsync(bool animated) - { - if (CurrentNavigationTask != null && !CurrentNavigationTask.IsCompleted) - { - var tcs = new TaskCompletionSource(); - Task oldTask = CurrentNavigationTask; - CurrentNavigationTask = tcs.Task; - await oldTask; - - await PopToRootAsyncInner(animated); - tcs.SetResult(true); - return; - } - - Task result = PopToRootAsyncInner(animated); - CurrentNavigationTask = result; - await result; - } - - /// - /// Presents a Page modally. - /// - /// The Page to present modally. - /// An awaitable Task, indicating the PushModal completion. - public Task PushAsync(Page page) - { - return PushAsync(page, true); - } - - /// - /// A task for asynchronously pushing a page onto the navigation stack, with optional animation. - /// - /// The Page to present modally. - /// Whether to animate the pop. - /// An awaitable Task, indicating the PushModal completion. - public async Task PushAsync(Page page, bool animated) - { - if (CurrentNavigationTask != null && !CurrentNavigationTask.IsCompleted) - { - var tcs = new TaskCompletionSource(); - Task oldTask = CurrentNavigationTask; - CurrentNavigationTask = tcs.Task; - await oldTask; - - await PushAsyncInner(page, animated); - tcs.SetResult(true); - return; - } - - CurrentNavigationTask = PushAsyncInner(page, animated); - await CurrentNavigationTask; - } - - /// - /// Event that is raised when a page is pushed onto this NavigationPage element. - /// - public event EventHandler Pushed; - - /// - /// Sets the title that appears on the back button for page. - /// - /// The BindableObject object. - /// The value to set. - public static void SetBackButtonTitle(BindableObject page, string value) - { - page.SetValue(BackButtonTitleProperty, value); - } - - /// - /// Adds or removes a back button to page, with optional animation. - /// - /// The page object. - /// The value to set. - public static void SetHasBackButton(Page page, bool value) - { - if (page == null) - throw new ArgumentNullException("page"); - page.SetValue(HasBackButtonProperty, value); - } - - /// - /// Sets a value that indicates whether or not this NavigationPage element has a navigation bar. - /// - /// The BindableObject object - /// The value to set - public static void SetHasNavigationBar(BindableObject page, bool value) - { - page.SetValue(HasNavigationBarProperty, value); - } - - internal static void SetTitleIcon(BindableObject bindable, FileImageSource value) - { - bindable.SetValue(TitleIconProperty, value); - } - - /// - /// Event that is raised when the hardware back button is pressed. - /// - /// true if consumed - protected override bool OnBackButtonPressed() - { - if (CurrentPage.SendBackButtonPressed()) - return true; - - if (StackDepth > 1) - { - SafePop(); - return true; - } - - return base.OnBackButtonPressed(); - } - - /// - /// For internal use - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler InsertPageBeforeRequested; - - /// - /// For internal use - /// - /// Whether animate the pop. - /// - /// A task that represents the asynchronous dismiss operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public async Task PopAsyncInner(bool animated, bool fast) - { - if (StackDepth == 1) - { - return null; - } - - var page = (Page)InternalChildren.Last(); - - return await (this as INavigationPageController).RemoveAsyncInner(page, animated, fast); - } - - async Task INavigationPageController.RemoveAsyncInner(Page page, bool animated, bool fast) - { - if (StackDepth == 1) - { - return null; - } - - var args = new NavigationRequestedEventArgs(page, animated); - - var removed = true; - - EventHandler requestPop = PopRequested; - if (requestPop != null) - { - requestPop(this, args); - - if (args.Task != null && !fast) - removed = await args.Task; - } - - if (!removed && !fast) - return CurrentPage; - - InternalChildren.Remove(page); - - CurrentPage = (Page)InternalChildren.Last(); - - if (Popped != null) - Popped(this, args); - - return page; - } - - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler PopRequested; - - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler PopToRootRequested; - - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler PushRequested; - - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler RemovePageRequested; - - void InsertPageBefore(Page page, Page before) - { - if (page == null) - throw new ArgumentNullException($"{nameof(page)} cannot be null."); - - if (before == null) - throw new ArgumentNullException($"{nameof(before)} cannot be null."); - - if (!InternalChildren.Contains(before)) - throw new ArgumentException($"{nameof(before)} must be a child of the NavigationPage", nameof(before)); - - if (InternalChildren.Contains(page)) - throw new ArgumentException("Cannot insert page which is already in the navigation stack"); - - EventHandler handler = InsertPageBeforeRequested; - handler?.Invoke(this, new NavigationRequestedEventArgs(page, before, false)); - - int index = InternalChildren.IndexOf(before); - InternalChildren.Insert(index, page); - - if (index == 0) - RootPage = page; - - // Shouldn't be required? - // if (Width > 0 && Height > 0) - ForceLayout(); - } - - async Task PopToRootAsyncInner(bool animated) - { - if (StackDepth == 1) - return; - - Element[] childrenToRemove = InternalChildren.Skip(1).ToArray(); - foreach (Element child in childrenToRemove) - InternalChildren.Remove(child); - - CurrentPage = RootPage; - - var args = new NavigationRequestedEventArgs(RootPage, animated); - - EventHandler requestPopToRoot = PopToRootRequested; - if (requestPopToRoot != null) - { - requestPopToRoot(this, args); - - if (args.Task != null) - await args.Task; - } - - // PoppedToRoot?.Invoke(this, new PoppedToRootEventArgs(RootPage, childrenToRemove.OfType().ToList())); - } - - async Task PushAsyncInner(Page page, bool animated) - { - if (InternalChildren.Contains(page)) - return; - - PushPage(page); - - var args = new NavigationRequestedEventArgs(page, animated); - - EventHandler requestPush = PushRequested; - if (requestPush != null) - { - requestPush(this, args); - - if (args.Task != null) - await args.Task; - } - - Pushed?.Invoke(this, args); - } - - void PushPage(Page page) - { - InternalChildren.Add(page); - - if (InternalChildren.Count == 1) - RootPage = page; - - CurrentPage = page; - } - - void RemovePage(Page page) - { - if (page == null) - throw new ArgumentNullException($"{nameof(page)} cannot be null."); - - if (page == CurrentPage && CurrentPage == RootPage) - throw new InvalidOperationException("Cannot remove root page when it is also the currently displayed page."); - if (page == CurrentPage) - { - // Log.Warning("NavigationPage", "RemovePage called for CurrentPage object. This can result in undesired behavior, consider calling PopAsync instead."); - PopAsync(); - return; - } - - if (!InternalChildren.Contains(page)) - throw new ArgumentException("Page to remove must be contained on this Navigation Page"); - - EventHandler handler = RemovePageRequested; - handler?.Invoke(this, new NavigationRequestedEventArgs(page, true)); - - InternalChildren.Remove(page); - if (RootPage == page) - RootPage = (Page)InternalChildren.First(); - } - - void SafePop() - { - PopAsync(true).ContinueWith(t => - { - if (t.IsFaulted) - throw t.Exception; - }); - } - - class NavigationImpl : NavigationProxy - { - // readonly Lazy> _castingList; - - public NavigationImpl(NavigationPage owner) - { - Owner = owner; - // _castingList = new Lazy>(() => new ReadOnlyCastingList(Owner.InternalChildren)); - } - - NavigationPage Owner { get; } - - protected override IReadOnlyList GetNavigationStack() - { - // return _castingList.Value; - return null; - } - - protected override void OnInsertPageBefore(Page page, Page before) - { - Owner.InsertPageBefore(page, before); - } - - protected override Task OnPopAsync(bool animated) - { - return Owner.PopAsync(animated); - } - - protected override Task OnPopToRootAsync(bool animated) - { - return Owner.PopToRootAsync(animated); - } - - protected override Task OnPushAsync(Page root, bool animated) - { - return Owner.PushAsync(root, animated); - } - - protected override void OnRemovePage(Page page) - { - Owner.RemovePage(page); - } - } - - readonly Lazy> _platformConfigurationRegistry; - - /// - /// Returns the platform-specific instance of this NavigationPage, on which a platform-specific method may be called. - /// - /// The platform for which to return an instance. - /// The platform-specific instance of this NavigationPage - public new IPlatformElementConfiguration On() where T : IConfigPlatform - { - return _platformConfigurationRegistry.Value.On(); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NavigationProxy.cs b/src/Tizen.NUI/src/internal/XamlBinding/NavigationProxy.cs deleted file mode 100755 index 263cc339d..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NavigationProxy.cs +++ /dev/null @@ -1,346 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; - -namespace Tizen.NUI.Binding -{ - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal class NavigationProxy : INavigation - { - INavigation _inner; - Lazy> _modalStack = new Lazy>(() => new List()); - - Lazy> _pushStack = new Lazy>(() => new List()); - - internal INavigation Inner - { - get { return _inner; } - set - { - if (_inner == value) - return; - _inner = value; - // reverse so that things go into the new stack in the same order - // null out to release memory that will likely never be needed again - - if (ReferenceEquals(_inner, null)) - { - _pushStack = new Lazy>(() => new List()); - _modalStack = new Lazy>(() => new List()); - } - else - { - if (_pushStack != null && _pushStack.IsValueCreated) - { - foreach (Page page in _pushStack.Value) - { - _inner.PushAsync(page); - } - } - - if (_modalStack != null && _modalStack.IsValueCreated) - { - foreach (Page page in _modalStack.Value) - { - _inner.PushModalAsync(page); - } - } - - _pushStack = null; - _modalStack = null; - } - } - } - - /// - /// Inserts a page in the navigation stack before an existing page in the stack. - /// - /// The page to add. - /// The existing page, before which page will be inserted. - public void InsertPageBefore(Page page, Page before) - { - OnInsertPageBefore(page, before); - } - - /// - /// Gets the modal navigation stack. - /// - public IReadOnlyList ModalStack - { - get { return GetModalStack(); } - } - - /// - /// Gets the stack of pages in the navigation. - /// - public IReadOnlyList NavigationStack - { - get { return GetNavigationStack(); } - } - - /// - /// Asynchronously removes the most recent Page from the navigation stack. - /// - /// The Page that had been at the top of the navigation stack. - public Task PopAsync() - { - return OnPopAsync(true); - } - - /// - /// Asynchronously removes the top Page from the navigation stack, with optional animation. - /// - /// Whether to animate the pop. - /// The Page that had been at the top of the navigation stack. - public Task PopAsync(bool animated) - { - return OnPopAsync(animated); - } - - /// - /// Asynchronously dismisses the most recent modally presented Page. - /// - /// An awaitable instance, indicating the PopModalAsync completion. The Task.Result is the Page that has been popped. - public Task PopModalAsync() - { - return OnPopModal(true); - } - - /// - /// Asynchronously removes the top Page from the navigation stack, with optional animation. - /// - /// Whether to animate the pop. - /// The Page that had been at the top of the navigation stack. - public Task PopModalAsync(bool animated) - { - return OnPopModal(animated); - } - - /// - /// Pops all but the root Page off the navigation stack. - /// - /// A task representing the asynchronous dismiss operation. - public Task PopToRootAsync() - { - return OnPopToRootAsync(true); - } - - /// - /// Pops all but the root Page off the navigation stack, with optional animation. - /// - /// Whether to animate the pop. - /// A task representing the asynchronous dismiss operation. - public Task PopToRootAsync(bool animated) - { - return OnPopToRootAsync(animated); - } - - /// - /// Asynchronously adds a Page to the top of the navigation stack. - /// - /// The Page to be pushed on top of the navigation stack. - /// A task that represents the asynchronous push operation. - public Task PushAsync(Page root) - { - return PushAsync(root, true); - } - - /// - /// Asynchronously adds a Page to the top of the navigation stack, with optional animation. - /// - /// The page to push. - /// Whether to animate the push. - /// A task that represents the asynchronous push operation. - public Task PushAsync(Page root, bool animated) - { - if (root.RealParent != null) - throw new InvalidOperationException("Page must not already have a parent."); - return OnPushAsync(root, animated); - } - - /// - /// Presents a Page modally. - /// - /// The Page to present modally. - /// An awaitable Task, indicating the PushModal completion. - public Task PushModalAsync(Page modal) - { - return PushModalAsync(modal, true); - } - - /// - /// Presents a Page modally, with optional animation. - /// - /// The page to push. - /// Whether to animate the push. - /// An awaitable Task, indicating the PushModal completion. - public Task PushModalAsync(Page modal, bool animated) - { - if (modal.RealParent != null) - throw new InvalidOperationException("Page must not already have a parent."); - return OnPushModal(modal, animated); - } - - /// - /// Removes the specified page from the navigation stack. - /// - /// The page to remove. - public void RemovePage(Page page) - { - OnRemovePage(page); - } - - /// - /// For internal use. Returns the modal navigation stack. - /// - /// The modal navigation stack. - protected virtual IReadOnlyList GetModalStack() - { - INavigation currentInner = Inner; - return currentInner == null ? _modalStack.Value : currentInner.ModalStack; - } - - /// - /// For internal use. Returns the stack of pages in the navigation. - /// - /// The stack of pages in the navigation. - protected virtual IReadOnlyList GetNavigationStack() - { - INavigation currentInner = Inner; - return currentInner == null ? _pushStack.Value : currentInner.NavigationStack; - } - - /// - /// The method called when insert a page in the navigation stack before an existing page in the stack. - /// - /// The page to add. - /// The existing page, before which page will be inserted. - protected virtual void OnInsertPageBefore(Page page, Page before) - { - INavigation currentInner = Inner; - if (currentInner == null) - { - int index = _pushStack.Value.IndexOf(before); - if (index == -1) - throw new ArgumentException("before must be in the pushed stack of the current context"); - _pushStack.Value.Insert(index, page); - } - else - { - currentInner.InsertPageBefore(page, before); - } - } - - /// - /// This method calls when removes the top Page from the navigation stack - /// - /// Whether to animate the pop. - /// - protected virtual Task OnPopAsync(bool animated) - { - INavigation inner = Inner; - return inner == null ? Task.FromResult(Pop()) : inner.PopAsync(animated); - } - - /// - /// This method calls when removes the top Page from the navigation stack - /// - /// Whether to animate the pop. - /// An awaitable instance, indicating the PopModalAsync completion - protected virtual Task OnPopModal(bool animated) - { - INavigation innerNav = Inner; - return innerNav == null ? Task.FromResult(PopModal()) : innerNav.PopModalAsync(animated); - } - - /// - /// This method calls when Pops all but the root Page off the navigation stack. - /// - /// Whether to animate the pop. - /// A task representing the asynchronous dismiss operation. - protected virtual Task OnPopToRootAsync(bool animated) - { - INavigation currentInner = Inner; - if (currentInner == null) - { - Page root = _pushStack.Value.Last(); - _pushStack.Value.Clear(); - _pushStack.Value.Add(root); - return Task.FromResult(root); - } - return currentInner.PopToRootAsync(animated); - } - - /// - /// This method calls when adds a Page to the top of the navigation stack, with optional animation. - /// - /// The page to add - /// Whether to animate the pop. - /// A task that represents the asynchronous push operation. - protected virtual Task OnPushAsync(Page page, bool animated) - { - INavigation currentInner = Inner; - if (currentInner == null) - { - _pushStack.Value.Add(page); - return Task.FromResult(page); - } - return currentInner.PushAsync(page, animated); - } - - /// - /// This method calls when Presents a Page modally, with optional animation. - /// - /// The page to push. - /// Whether to animate the pop. - /// An awaitable Task, indicating the PushModal completion. - protected virtual Task OnPushModal(Page modal, bool animated) - { - INavigation currentInner = Inner; - if (currentInner == null) - { - _modalStack.Value.Add(modal); - return Task.FromResult(null); - } - return currentInner.PushModalAsync(modal, animated); - } - - /// - /// This method calls when Removes the specified page from the navigation stack. - /// - /// The page to add. - protected virtual void OnRemovePage(Page page) - { - INavigation currentInner = Inner; - if (currentInner == null) - { - _pushStack.Value.Remove(page); - } - else - { - currentInner.RemovePage(page); - } - } - - Page Pop() - { - List list = _pushStack.Value; - Page result = list[list.Count - 1]; - list.RemoveAt(list.Count - 1); - return result; - } - - Page PopModal() - { - List list = _modalStack.Value; - Page result = list[list.Count - 1]; - list.RemoveAt(list.Count - 1); - return result; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NavigationRequestedEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/NavigationRequestedEventArgs.cs deleted file mode 100755 index 42a75633d..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NavigationRequestedEventArgs.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.ComponentModel; -using System.Threading.Tasks; -using Tizen.NUI; - -namespace Tizen.NUI.Binding -{ - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal class NavigationRequestedEventArgs : NavigationEventArgs - { - /// - /// Constructor. - /// - /// - /// - /// - public NavigationRequestedEventArgs(Page page, bool animated, bool realize = true) : base(page) - { - Animated = animated; - Realize = realize; - } - - /// - /// Constructor. - /// - /// - /// - /// - public NavigationRequestedEventArgs(Page page, Page before, bool animated) : this(page, animated) - { - BeforePage = before; - } - - /// - /// Gets or Sets the whether animate. - /// - public bool Animated { get; set; } - - /// - /// Gets or Sets the before page. - /// - public Page BeforePage { get; set; } - - /// - /// Gets or Sets the realize. - /// - public bool Realize { get; set; } - - /// - /// Gets or Sets the Task. - /// - public Task Task { get; set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/NullEffect.cs b/src/Tizen.NUI/src/internal/XamlBinding/NullEffect.cs deleted file mode 100755 index 28260452f..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/NullEffect.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal class NullEffect : Effect - { - protected override void OnAttached() - { - } - - protected override void OnDetached() - { - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs b/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs deleted file mode 100755 index 2a220ea7f..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs +++ /dev/null @@ -1,256 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.Linq; - -namespace Tizen.NUI.Binding -{ - internal class ObservableWrapper : IList, INotifyCollectionChanged where TTrack : Element where TRestrict : TTrack - { - readonly ObservableCollection _list; - - public ObservableWrapper(ObservableCollection list) - { - if (list == null) - throw new ArgumentNullException("list"); - - _list = list; - - list.CollectionChanged += ListOnCollectionChanged; - } - - public void Add(TRestrict item) - { - if (item == null) - throw new ArgumentNullException("item"); - if (IsReadOnly) - throw new NotSupportedException("The collection is read-only."); - - if (_list.Contains(item)) - return; - - item.Owned = true; - _list.Add(item); - } - - public void Clear() - { - if (IsReadOnly) - throw new NotSupportedException("The collection is read-only."); - - foreach (TRestrict item in _list.OfType().ToArray()) - { - _list.Remove(item); - item.Owned = false; - } - } - - public bool Contains(TRestrict item) - { - return item.Owned && _list.Contains(item); - } - - public void CopyTo(TRestrict[] array, int destIndex) - { - if (array.Length - destIndex < Count) - throw new ArgumentException("Destination array was not long enough. Check destIndex and length, and the array's lower bounds."); - foreach (TRestrict item in this) - { - array[destIndex] = item; - destIndex++; - } - } - - public int Count - { - get { return _list.Where(i => i.Owned).OfType().Count(); } - } - - public bool IsReadOnly { get; internal set; } - - public bool Remove(TRestrict item) - { - if (item == null) - throw new ArgumentNullException("item"); - if (IsReadOnly) - throw new NotSupportedException("The collection is read-only."); - - if (!item.Owned) - return false; - - if (_list.Remove(item)) - { - item.Owned = false; - return true; - } - return false; - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return _list.Where(i => i.Owned).OfType().GetEnumerator(); - } - - public int IndexOf(TRestrict value) - { - int innerIndex = _list.IndexOf(value); - if (innerIndex == -1) - return -1; - return ToOuterIndex(innerIndex); - } - - public void Insert(int index, TRestrict item) - { - if (item == null) - throw new ArgumentNullException("item"); - if (IsReadOnly) - throw new NotSupportedException("The collection is read-only."); - - item.Owned = true; - _list.Insert(ToInnerIndex(index), item); - } - - public TRestrict this[int index] - { - get { return (TRestrict)_list[ToInnerIndex(index)]; } - set - { - int innerIndex = ToInnerIndex(index); - if (value != null) - value.Owned = true; - TTrack old = _list[innerIndex]; - _list[innerIndex] = value; - - if (old != null) - old.Owned = false; - } - } - - public void RemoveAt(int index) - { - if (IsReadOnly) - throw new NotSupportedException("The collection is read-only"); - int innerIndex = ToInnerIndex(index); - TTrack item = _list[innerIndex]; - if (item != null && item.Owned) - { - _list.RemoveAt(innerIndex); - item.Owned = false; - } - } - - public event NotifyCollectionChangedEventHandler CollectionChanged; - - void ListOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - NotifyCollectionChangedEventHandler handler = CollectionChanged; - if (handler == null) - return; - - switch (e.Action) - { - case NotifyCollectionChangedAction.Add: - if (e.NewStartingIndex == -1 || e.NewItems?.Count > 1) - goto case NotifyCollectionChangedAction.Reset; - - var newItem = e.NewItems?[0] as TRestrict; - if (newItem == null || !newItem.Owned) - break; - - int outerIndex = ToOuterIndex(e.NewStartingIndex); - handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, e.NewItems, outerIndex)); - break; - case NotifyCollectionChangedAction.Move: - if (e.NewStartingIndex == -1 || e.OldStartingIndex == -1 || e.NewItems?.Count > 1) - goto case NotifyCollectionChangedAction.Reset; - - var movedItem = e.NewItems?[0] as TRestrict; - if (movedItem == null || !movedItem.Owned) - break; - - int outerOldIndex = ToOuterIndex(e.OldStartingIndex); - int outerNewIndex = ToOuterIndex(e.NewStartingIndex); - handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, e.NewItems, outerNewIndex, outerOldIndex)); - break; - case NotifyCollectionChangedAction.Remove: - if (e.OldStartingIndex == -1 || e.OldItems?.Count > 1) - goto case NotifyCollectionChangedAction.Reset; - - var removedItem = e.OldItems?[0] as TRestrict; - if (removedItem == null || !removedItem.Owned) - break; - - int outerRemovedIndex = ToOuterIndex(e.OldStartingIndex); - var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedItem, outerRemovedIndex); - handler(this, args); - break; - case NotifyCollectionChangedAction.Replace: - if (e.NewStartingIndex == -1 || e.OldStartingIndex == -1 || e.NewItems?.Count > 1) - goto case NotifyCollectionChangedAction.Reset; - - var newReplaceItem = e.NewItems?[0] as TRestrict; - var oldReplaceItem = e.OldItems?[0] as TRestrict; - - if ((newReplaceItem == null || !newReplaceItem.Owned) && (oldReplaceItem == null || !oldReplaceItem.Owned)) - { - break; - } - if (newReplaceItem == null || !newReplaceItem.Owned || oldReplaceItem == null || !oldReplaceItem.Owned) - { - goto case NotifyCollectionChangedAction.Reset; - } - - int index = ToOuterIndex(e.NewStartingIndex); - - var replaceArgs = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, newReplaceItem, oldReplaceItem, index); - handler(this, replaceArgs); - break; - case NotifyCollectionChangedAction.Reset: - handler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - int ToInnerIndex(int outterIndex) - { - var outerIndex = 0; - int innerIndex; - for (innerIndex = 0; innerIndex < _list.Count; innerIndex++) - { - TTrack item = _list[innerIndex]; - if (item is TRestrict && item.Owned) - { - if (outerIndex == outterIndex) - return innerIndex; - outerIndex++; - } - } - - return innerIndex; - } - - int ToOuterIndex(int innerIndex) - { - var outerIndex = 0; - for (var index = 0; index < innerIndex; index++) - { - TTrack item = _list[index]; - if (item is TRestrict && item.Owned) - { - outerIndex++; - } - } - - return outerIndex; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/PaddingElement.cs b/src/Tizen.NUI/src/internal/XamlBinding/PaddingElement.cs deleted file mode 100755 index 817e81e09..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/PaddingElement.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace Tizen.NUI.Binding -{ - internal static class PaddingElement - { - internal static readonly BindableProperty PaddingProperty = - BindableProperty.Create("Padding", typeof(Thickness), typeof(IPaddingElement), default(Thickness), - propertyChanged: OnPaddingPropertyChanged, - defaultValueCreator: PaddingDefaultValueCreator); - - static void OnPaddingPropertyChanged(BindableObject bindable, object oldValue, object newValue) - { - ((IPaddingElement)bindable).OnPaddingPropertyChanged((Thickness)oldValue, (Thickness)newValue); - } - - static object PaddingDefaultValueCreator(BindableObject bindable) - { - return ((IPaddingElement)bindable).PaddingDefaultValueCreator(); - } - - public static readonly BindableProperty PaddingLeftProperty = - BindableProperty.Create("PaddingLeft", typeof(double), typeof(IPaddingElement), default(double), - propertyChanged: OnPaddingLeftChanged); - - static void OnPaddingLeftChanged(BindableObject bindable, object oldValue, object newValue) - { - var padding = (Thickness)bindable.GetValue(PaddingProperty); - padding.Left = (double)newValue; - bindable.SetValue(PaddingProperty, padding); - } - - public static readonly BindableProperty PaddingTopProperty = - BindableProperty.Create("PaddingTop", typeof(double), typeof(IPaddingElement), default(double), - propertyChanged: OnPaddingTopChanged); - - static void OnPaddingTopChanged(BindableObject bindable, object oldValue, object newValue) - { - var padding = (Thickness)bindable.GetValue(PaddingProperty); - padding.Top = (double)newValue; - bindable.SetValue(PaddingProperty, padding); - } - - public static readonly BindableProperty PaddingRightProperty = - BindableProperty.Create("PaddingRight", typeof(double), typeof(IPaddingElement), default(double), - propertyChanged: OnPaddingRightChanged); - - static void OnPaddingRightChanged(BindableObject bindable, object oldValue, object newValue) - { - var padding = (Thickness)bindable.GetValue(PaddingProperty); - padding.Right = (double)newValue; - bindable.SetValue(PaddingProperty, padding); - } - - public static readonly BindableProperty PaddingBottomProperty = - BindableProperty.Create("PaddingBottom", typeof(double), typeof(IPaddingElement), default(double), - propertyChanged: OnPaddingBottomChanged); - - static void OnPaddingBottomChanged(BindableObject bindable, object oldValue, object newValue) - { - var padding = (Thickness)bindable.GetValue(PaddingProperty); - padding.Bottom = (double)newValue; - bindable.SetValue(PaddingProperty, padding); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/PlatformConfigurationRegistry.cs b/src/Tizen.NUI/src/internal/XamlBinding/PlatformConfigurationRegistry.cs deleted file mode 100755 index 6cb752e15..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/PlatformConfigurationRegistry.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Tizen.NUI.Binding -{ - /// - /// Helper that handles storing and lookup of platform specifics implementations - /// - /// The Element type - internal class PlatformConfigurationRegistry : IElementConfiguration - where TElement : Element - { - readonly TElement _element; - readonly Dictionary _platformSpecifics = new Dictionary(); - - internal PlatformConfigurationRegistry(TElement element) - { - _element = element; - } - - - public IPlatformElementConfiguration On() where T : IConfigPlatform - { - if (_platformSpecifics.ContainsKey(typeof(T))) - { - return (IPlatformElementConfiguration)_platformSpecifics[typeof(T)]; - } - - var emptyConfig = Configuration.Create(_element); - - _platformSpecifics.Add(typeof(T), emptyConfig); - - return emptyConfig; - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Registrar.cs b/src/Tizen.NUI/src/internal/XamlBinding/Registrar.cs deleted file mode 100755 index ee075dc50..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Registrar.cs +++ /dev/null @@ -1,284 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using Tizen.NUI.Binding; - -namespace Tizen.NUI.Binding -{ - // Previewer uses reflection to bind to this method; Removal or modification of visibility will break previewer. - internal static class Registrar - { - internal static void RegisterAll(Type[] attrTypes) => Internals.Registrar.RegisterAll(attrTypes); - } -} - -namespace Tizen.NUI.Binding.Internals -{ - /// - /// For internal use. - /// - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal class Registrar where TRegistrable : class - { - readonly Dictionary _handlers = new Dictionary(); - - /// - /// Register. - /// - /// The type of the view - /// The type of the render. - public void Register(Type tview, Type trender) - { - //avoid caching null renderers - if (trender == null) - return; - _handlers[tview] = trender; - } - - internal TRegistrable GetHandler(Type type) - { - Type handlerType = GetHandlerType(type); - if (handlerType == null) - return null; - - object handler = DependencyResolver.ResolveOrCreate(handlerType); - - return (TRegistrable)handler; - } - - internal TRegistrable GetHandler(Type type, params object[] args) - { - if (args.Length == 0) - { - return GetHandler(type); - } - - Type handlerType = GetHandlerType(type); - if (handlerType == null) - return null; - - return (TRegistrable)DependencyResolver.ResolveOrCreate(handlerType, args); - } - - /// - /// For internal use. Returns handler. - /// - /// The type of the handler - /// The type. - /// The handler instance. - public TOut GetHandler(Type type) where TOut : TRegistrable - { - return (TOut)GetHandler(type); - } - - /// - /// For internal use. Returns handler. - /// - /// The type of the handler - /// The type. - /// The args of the type - /// The handler instance. - public TOut GetHandler(Type type, params object[] args) where TOut : TRegistrable - { - return (TOut)GetHandler(type, args); - } - - /// - /// For internal use. Return the handler of the object. - /// - /// Thetype - /// The object instance. - /// The handle of the obj. - public TOut GetHandlerForObject(object obj) where TOut : TRegistrable - { - if (obj == null) - throw new ArgumentNullException(nameof(obj)); - - var reflectableType = obj as IReflectableType; - var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType(); - - return (TOut)GetHandler(type); - } - - /// - /// For inetrnal use. Return the handler of the object. - /// - /// The type - /// The object instance - /// The args of the type - /// The handler of the object. - public TOut GetHandlerForObject(object obj, params object[] args) where TOut : TRegistrable - { - if (obj == null) - throw new ArgumentNullException(nameof(obj)); - - var reflectableType = obj as IReflectableType; - var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType(); - - return (TOut)GetHandler(type, args); - } - - /// - /// For internal use. Returns the handle type. - /// - /// The view type. - /// The type of the handle. - public Type GetHandlerType(Type viewType) - { - Type type; - if (LookupHandlerType(viewType, out type)) - return type; - - // lazy load render-view association with RenderWithAttribute (as opposed to using ExportRenderer) - var attribute = viewType.GetTypeInfo().GetCustomAttribute(); - if (attribute == null) - { - Register(viewType, null); // Cache this result so we don't have to do GetCustomAttribute again - return null; - } - - type = attribute.Type; - - if (type.Name.StartsWith("_", StringComparison.Ordinal)) - { - // TODO: Remove attribute2 once renderer names have been unified across all platforms - var attribute2 = type.GetTypeInfo().GetCustomAttribute(); - if (attribute2 != null) - type = attribute2.Type; - - if (type.Name.StartsWith("_", StringComparison.Ordinal)) - { - Register(viewType, null); // Cache this result so we don't work through this chain again - return null; - } - } - - Register(viewType, type); // Register this so we don't have to look for the RenderWith Attibute again in the future - - return type; - } - - /// - /// For internal use. Return the handle type of the object - /// - /// The object instance. - /// The type of the handler. - public Type GetHandlerTypeForObject(object obj) - { - if (obj == null) - throw new ArgumentNullException(nameof(obj)); - - var reflectableType = obj as IReflectableType; - var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType(); - - return GetHandlerType(type); - } - - bool LookupHandlerType(Type viewType, out Type handlerType) - { - Type type = viewType; - - while (type != null) - { - if (_handlers.ContainsKey(type)) - { - handlerType = _handlers[type]; - return true; - } - - type = type.GetTypeInfo().BaseType; - } - - handlerType = null; - return false; - } - } - - /// - /// For internal use - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal static class Registrar - { - static Registrar() - { - Registered = new Registrar(); - } - - internal static Dictionary Effects { get; } = new Dictionary(); - internal static Dictionary StyleProperties { get; } = new Dictionary(); - - public static IEnumerable ExtraAssemblies { get; set; } - - public static Registrar Registered { get; internal set; } - - public static void RegisterAll(Type[] attrTypes) - { - Assembly[] assemblies = Device.GetAssemblies(); - if (ExtraAssemblies != null) - assemblies = assemblies.Union(ExtraAssemblies).ToArray(); - - Assembly defaultRendererAssembly = Device.PlatformServices.GetType().GetTypeInfo().Assembly; - int indexOfExecuting = Array.IndexOf(assemblies, defaultRendererAssembly); - - if (indexOfExecuting > 0) - { - assemblies[indexOfExecuting] = assemblies[0]; - assemblies[0] = defaultRendererAssembly; - } - - // Don't use LINQ for performance reasons - // Naive implementation can easily take over a second to run - foreach (Assembly assembly in assemblies) - { - foreach (Type attrType in attrTypes) - { - Attribute[] attributes; - try - { - attributes = assembly.GetCustomAttributes(attrType).ToArray(); - } - catch (System.IO.FileNotFoundException) - { - // Sometimes the previewer doesn't actually have everything required for these loads to work - Console.WriteLine(nameof(Registrar), "Could not load assembly: {0} for Attibute {1} | Some renderers may not be loaded", assembly.FullName, attrType.FullName); - continue; - } - var length = attributes.Length; - for (var i = 0; i < length;i++) - { - var attribute = (HandlerAttribute)attributes[i]; - if (attribute.ShouldRegister()) - Registered.Register(attribute.HandlerType, attribute.TargetType); - } - } - - string resolutionName = assembly.FullName; - var resolutionNameAttribute = (ResolutionGroupNameAttribute)assembly.GetCustomAttribute(typeof(ResolutionGroupNameAttribute)); - if (resolutionNameAttribute != null) - resolutionName = resolutionNameAttribute.ShortName; - - Attribute[] effectAttributes = assembly.GetCustomAttributes(typeof(ExportEffectAttribute)).ToArray(); - var exportEffectsLength = effectAttributes.Length; - for (var i = 0; i < exportEffectsLength;i++) - { - var effect = (ExportEffectAttribute)effectAttributes[i]; - Effects [resolutionName + "." + effect.Id] = effect.Type; - } - - Attribute[] styleAttributes = assembly.GetCustomAttributes(typeof(StyleSheets.StylePropertyAttribute)).ToArray(); - var stylePropertiesLength = styleAttributes.Length; - for (var i = 0; i < stylePropertiesLength; i++) - { - var attribute = (StyleSheets.StylePropertyAttribute)styleAttributes[i]; - StyleProperties[attribute.CssPropertyName] = attribute; - } - } - - DependencyService.Initialize(assemblies); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/RoutingEffect.cs b/src/Tizen.NUI/src/internal/XamlBinding/RoutingEffect.cs deleted file mode 100755 index 35acf4f43..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/RoutingEffect.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - internal class RoutingEffect : Effect - { - internal readonly Effect Inner; - - protected RoutingEffect(string effectId) - { - Inner = Resolve(effectId); - } - - protected override void OnAttached() - { - } - - protected override void OnDetached() - { - } - - internal override void ClearEffect() - { - Inner?.ClearEffect(); - } - - internal override void SendAttached() - { - Inner?.SendAttached(); - } - - internal override void SendDetached() - { - Inner?.SendDetached(); - } - - internal override void SendOnElementPropertyChanged(PropertyChangedEventArgs args) - { - Inner?.SendOnElementPropertyChanged(args); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Setter.cs b/src/Tizen.NUI/src/internal/XamlBinding/Setter.cs deleted file mode 100755 index 7e0bb79bd..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Setter.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Xml; -using Tizen.NUI.Binding.Internals; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Value")] - [ProvideCompiled("Tizen.NUI.Core.XamlC.SetterValueProvider")] - internal sealed class Setter : IValueProvider - { - readonly ConditionalWeakTable _originalValues = new ConditionalWeakTable(); - - public BindableProperty Property { get; set; } - - public object Value { get; set; } - - object IValueProvider.ProvideValue(IServiceProvider serviceProvider) - { - if (Property == null) - { - var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; - IXmlLineInfo lineInfo = lineInfoProvider != null ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); - throw new XamlParseException("Property not set", lineInfo); - } - var valueconverter = serviceProvider.GetService(typeof(IValueConverterProvider)) as IValueConverterProvider; - - Func minforetriever = - () => - (MemberInfo)Property.DeclaringType.GetRuntimeProperty(Property.PropertyName) ?? (MemberInfo)Property.DeclaringType.GetRuntimeMethod("Get" + Property.PropertyName, new[] { typeof(BindableObject) }); - - object value = valueconverter?.Convert(Value, Property.ReturnType, minforetriever, serviceProvider); - Value = value; - return this; - } - - internal void Apply(BindableObject target, bool fromStyle = false) - { - if (target == null) - throw new ArgumentNullException("target"); - if (Property == null) - return; - - object originalValue = target.GetValue(Property); - if (!Equals(originalValue, Property.DefaultValue)) - { - _originalValues.Remove(target); - _originalValues.Add(target, originalValue); - } - - var dynamicResource = Value as DynamicResource; - var binding = Value as BindingBase; - if (binding != null) - target.SetBinding(Property, binding.Clone(), fromStyle); - else if (dynamicResource != null) - target.SetDynamicResource(Property, dynamicResource.Key, fromStyle); - else - { - if (Value is IList visualStateGroupCollection) - target.SetValue(Property, visualStateGroupCollection.Clone(), fromStyle); - else - target.SetValue(Property, Value, fromStyle); - } - } - - internal void UnApply(BindableObject target, bool fromStyle = false) - { - if (target == null) - throw new ArgumentNullException(nameof(target)); - if (Property == null) - return; - - object actual = target.GetValue(Property); - if (!Equals(actual, Value) && !(Value is Tizen.NUI.Binding.Binding) && !(Value is DynamicResource)) - { - //Do not reset default value if the value has been changed - _originalValues.Remove(target); - return; - } - - object defaultValue; - if (_originalValues.TryGetValue(target, out defaultValue)) - { - //reset default value, unapply bindings and dynamicResource - target.SetValue(Property, defaultValue, fromStyle); - _originalValues.Remove(target); - } - else - target.ClearValue(Property); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/SizeRequest.cs b/src/Tizen.NUI/src/internal/XamlBinding/SizeRequest.cs deleted file mode 100755 index f9e1eb398..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/SizeRequest.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Diagnostics; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// Struct that defines minimum and maximum Sizes. - /// - [DebuggerDisplay("Request={Request.Width}x{Request.Height}, Minimum={Minimum.Width}x{Minimum.Height}")] - [EditorBrowsable(EditorBrowsableState.Never)] - internal struct SizeRequest - { - /// - /// The requested size. - /// - public Size Request { get; set; } - - /// - /// The minimum acceptable size. - /// - public Size Minimum { get; set; } - - /// - /// Creates a new SizeRequest object that requests at least the size minimum, but preferably the size request. - /// - /// The size of the request. - /// The minimum size for the request. - public SizeRequest(Size request, Size minimum) - { - Request = request; - Minimum = minimum; - } - - /// - /// Creates a new SizeRequest with the specified request size. - /// - /// The size of the request. - public SizeRequest(Size request) - { - Request = request; - Minimum = request; - } - - /// - /// Returns a string representation of the size request. - /// - /// a string representation of the size request. - public override string ToString() - { - return string.Format("{{Request={0} Minimum={1}}}", Request, Minimum); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/SizeTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/SizeTypeConverter.cs deleted file mode 100755 index d5277159a..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/SizeTypeConverter.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Globalization; - -using Tizen.NUI; -using Tizen.NUI.Xaml; - -namespace Tizen.NUI.Binding -{ - [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")] - internal class SizeTypeConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value != null) - { - string[] parts = value.Split(','); - if (parts.Length == 3) - { - int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim()); - int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim()); - int z = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[2].Trim()); - return new Size(x, y, z); - } - } - - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size)}"); - } - } - - [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")] - internal class Size2DTypeConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value != null) - { - string[] parts = value.Split(','); - if (parts.Length == 2) - { - int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim()); - int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim()); - return new Size2D(x, y); - } - } - - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size2D)}"); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Style.cs b/src/Tizen.NUI/src/internal/XamlBinding/Style.cs deleted file mode 100755 index 1c9b2a9da..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Style.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using Tizen.NUI.StyleSheets; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - [ContentProperty("Setters")] - internal sealed class Style : IStyle - { - internal const string StyleClassPrefix = "Tizen.NUI.Binding.StyleClass."; - - readonly BindableProperty _basedOnResourceProperty = BindableProperty.CreateAttached("BasedOnResource", typeof(Style), typeof(Style), default(Style), - propertyChanged: OnBasedOnResourceChanged); - - readonly List> _targets = new List>(4); - - Style _basedOnStyle; - - string _baseResourceKey; - - IList _behaviors; - - IList _triggers; - - public Style([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) - { - if (targetType == null) - throw new ArgumentNullException("targetType"); - - TargetType = targetType; - Setters = new List(); - } - - public bool ApplyToDerivedTypes { get; set; } - - public Style BasedOn - { - get { return _basedOnStyle; } - set - { - if (_basedOnStyle == value) - return; - if (!ValidateBasedOn(value)) - throw new ArgumentException("BasedOn.TargetType is not compatible with TargetType"); - Style oldValue = _basedOnStyle; - _basedOnStyle = value; - BasedOnChanged(oldValue, value); - if (value != null) - BaseResourceKey = null; - } - } - - public string BaseResourceKey - { - get { return _baseResourceKey; } - set - { - if (_baseResourceKey == value) - return; - _baseResourceKey = value; - //update all DynamicResources - foreach (WeakReference bindableWr in _targets) - { - BindableObject target; - if (!bindableWr.TryGetTarget(out target)) - continue; - target.RemoveDynamicResource(_basedOnResourceProperty); - if (value != null) - target.SetDynamicResource(_basedOnResourceProperty, value); - } - if (value != null) - BasedOn = null; - } - } - - internal IList Behaviors - { - get { return _behaviors ?? (_behaviors = new AttachedCollection()); } - } - - public bool CanCascade { get; set; } - - public string Class { get; set; } - - public IList Setters { get; } - - /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public IList Triggers - { - get { return _triggers ?? (_triggers = new AttachedCollection()); } - } - - void IStyle.Apply(BindableObject bindable) - { - _targets.Add(new WeakReference(bindable)); - if (BaseResourceKey != null) - bindable.SetDynamicResource(_basedOnResourceProperty, BaseResourceKey); - ApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable)); - } - - public Type TargetType { get; } - - void IStyle.UnApply(BindableObject bindable) - { - UnApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable)); - bindable.RemoveDynamicResource(_basedOnResourceProperty); - _targets.RemoveAll(wr => - { - BindableObject target; - return wr.TryGetTarget(out target) && target == bindable; - }); - } - - internal bool CanBeAppliedTo(Type targetType) - { - if (TargetType == targetType) - return true; - if (!ApplyToDerivedTypes) - return false; - do - { - targetType = targetType.GetTypeInfo().BaseType; - if (TargetType == targetType) - return true; - } while (targetType != typeof(Element)); - return false; - } - - void ApplyCore(BindableObject bindable, Style basedOn) - { - if (basedOn != null) - ((IStyle)basedOn).Apply(bindable); - - foreach (Setter setter in Setters) - setter.Apply(bindable, true); - ((AttachedCollection)Behaviors).AttachTo(bindable); - ((AttachedCollection)Triggers).AttachTo(bindable); - } - - void BasedOnChanged(Style oldValue, Style newValue) - { - foreach (WeakReference bindableRef in _targets) - { - BindableObject bindable; - if (!bindableRef.TryGetTarget(out bindable)) - continue; - - UnApplyCore(bindable, oldValue); - ApplyCore(bindable, newValue); - } - } - - Style GetBasedOnResource(BindableObject bindable) - { - return (Style)bindable.GetValue(_basedOnResourceProperty); - } - - static void OnBasedOnResourceChanged(BindableObject bindable, object oldValue, object newValue) - { - // Style style = (bindable as /*VisualElement*/BaseHandle).Style; - // if (style == null) - // return; - // style.UnApplyCore(bindable, (Style)oldValue); - // style.ApplyCore(bindable, (Style)newValue); - } - - void UnApplyCore(BindableObject bindable, Style basedOn) - { - ((AttachedCollection)Triggers).DetachFrom(bindable); - ((AttachedCollection)Behaviors).DetachFrom(bindable); - foreach (Setter setter in Setters) - setter.UnApply(bindable, true); - - if (basedOn != null) - ((IStyle)basedOn).UnApply(bindable); - } - - bool ValidateBasedOn(Style value) - { - if (value == null) - return true; - return value.TargetType.IsAssignableFrom(TargetType); - } - } -} diff --git a/src/Tizen.NUI/src/internal/XamlBinding/Thickness.cs b/src/Tizen.NUI/src/internal/XamlBinding/Thickness.cs deleted file mode 100755 index 5bf3d9b14..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/Thickness.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System.Diagnostics; -using System.ComponentModel; - -namespace Tizen.NUI.Binding -{ - /// - /// Struct defining thickness around the edges of a Rectangle using doubles. - /// - [DebuggerDisplay("Left={Left}, Top={Top}, Right={Right}, Bottom={Bottom}, HorizontalThickness={HorizontalThickness}, VerticalThickness={VerticalThickness}")] - [TypeConverter(typeof(ThicknessTypeConverter))] - [EditorBrowsable(EditorBrowsableState.Never)] - internal struct Thickness - { - /// - /// The thickness of the left side of a rectangle. - /// - public double Left { get; set; } - - /// - /// The thickness of the top of a rectangle. - /// - public double Top { get; set; } - - /// - /// The thickness of the right side of a rectangle. - /// - public double Right { get; set; } - - /// - /// The thickness of the bottom of a rectangle. - /// - public double Bottom { get; set; } - - /// - /// The sum of Left and Right. - /// - public double HorizontalThickness - { - get { return Left + Right; } - } - - /// - /// The sum of Top and Bottom. - /// - public double VerticalThickness - { - get { return Top + Bottom; } - } - - internal bool IsDefault - { - get { return Left == 0 && Top == 0 && Right == 0 && Bottom == 0; } - } - - /// - /// Creates a new Thickness object that represents a uniform thickness of size uniformSize. - /// - /// The uniform size of all edges in the new thickness. - public Thickness(double uniformSize) : this(uniformSize, uniformSize, uniformSize, uniformSize) - { - } - - /// - /// Creates a new Thickness object that has a horizontal thickness of horizontalSize and a vertical thickness of verticalSize. - /// - /// The width of the left and right thicknesses. - /// The height of the top and bottom thicknesses. - public Thickness(double horizontalSize, double verticalSize) : this(horizontalSize, verticalSize, horizontalSize, verticalSize) - { - } - - /// - /// Creates a new Thickness object with thicknesses defined by left, top, right, and bottom. - /// - /// The width of the left thickness. - /// The height of the top thickness. - /// The width of the right thickness. - /// The height of the bottom thickness. - public Thickness(double left, double top, double right, double bottom) : this() - { - Left = left; - Top = top; - Right = right; - Bottom = bottom; - } - - /// - /// Converts a Size into a Thickness. - /// - /// A Size to convert to a Thickness - public static implicit operator Thickness(Size size) - { - return new Thickness(size.Width, size.Height, size.Width, size.Height); - } - - /// - /// Implicit cast operator from Double. - /// - /// The value for the uniform Thickness. - public static implicit operator Thickness(double uniformSize) - { - return new Thickness(uniformSize); - } - - /// - /// Whether the other has equivalent values. - /// - /// A Thickness to be compared. - /// true if other has equivalent values. - bool Equals(Thickness other) - { - return Left.Equals(other.Left) && Top.Equals(other.Top) && Right.Equals(other.Right) && Bottom.Equals(other.Bottom); - } - - /// - /// Whether the obj has equivalent values. - /// - /// A Thickness to be compared. - /// true if obj is a Thickness and has equivalent values. - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - return obj is Thickness && Equals((Thickness)obj); - } - - /// - /// A hash value for this Thickness. - /// - /// The hash value - public override int GetHashCode() - { - unchecked - { - int hashCode = Left.GetHashCode(); - hashCode = (hashCode * 397) ^ Top.GetHashCode(); - hashCode = (hashCode * 397) ^ Right.GetHashCode(); - hashCode = (hashCode * 397) ^ Bottom.GetHashCode(); - return hashCode; - } - } - - /// - /// Whether two Thicknesses have identical values. - /// - /// A Thickness to be compared. - /// A Thickness to be compared. - /// true if left and right have identical values for Left,Right, Top, and Bottom. - public static bool operator ==(Thickness left, Thickness right) - { - return left.Equals(right); - } - - /// - /// Whether the values of two Thickness's have at least one difference. - /// - /// A Thickness to be compared. - /// A Thickness to be compared. - /// true if any of the Left,Right, Top, and Bottom values differ between left and right. - public static bool operator !=(Thickness left, Thickness right) - { - return !left.Equals(right); - } - - /// - /// Stores the components of the thickness in the corresponding arguments. - /// - /// Variable in which to store the left thickness of thickness object. - /// Variable in which to store the top thickness of thickness object. - /// Variable in which to store the right thickness of thickness object. - /// Variable in which to store the bottom thickness of thickness object. - public void Deconstruct(out double left, out double top, out double right, out double bottom) - { - left = Left; - top = Top; - right = Right; - bottom = Bottom; - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ThicknessTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/ThicknessTypeConverter.cs deleted file mode 100755 index 72271c330..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ThicknessTypeConverter.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Globalization; - -namespace Tizen.NUI.Binding -{ - [Xaml.ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ThicknessTypeConverter")] - [Xaml.TypeConversion(typeof(Thickness))] - internal class ThicknessTypeConverter : TypeConverter - { - public override object ConvertFromInvariantString(string value) - { - if (value != null) { - value = value.Trim(); - if (value.Contains(",")) { //Xaml - var thickness = value.Split(','); - switch (thickness.Length) { - case 2: - if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double h) - && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double v)) - return new Thickness(h, v); - break; - case 4: - if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double l) - && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double t) - && double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out double r) - && double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out double b)) - return new Thickness(l, t, r, b); - break; - } - } - else if (value.Contains(" ")) { //CSS - var thickness = value.Split(' '); - switch (thickness.Length) { - case 2: - if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double v) - && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double h)) - return new Thickness(h, v); - break; - case 3: - if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double t) - && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out h) - && double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out double b)) - return new Thickness(h, t, h, b); - break; - case 4: - if ( double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out t) - && double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double r) - && double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out b) - && double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out double l)) - return new Thickness(l, t, r, b); - break; - } - } - else { //single uniform thickness - if (double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out double l)) - return new Thickness(l); - } - } - - throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Thickness)}"); - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/TizenPlatformServices.cs b/src/Tizen.NUI/src/internal/XamlBinding/TizenPlatformServices.cs index d05bf0867..995624e53 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/TizenPlatformServices.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/TizenPlatformServices.cs @@ -24,83 +24,12 @@ namespace Tizen.NUI.Binding s_context = SynchronizationContext.Current; } - public class TizenTicker : Ticker - { - readonly System.Threading.Timer _timer; - - public TizenTicker() - { - _timer = new System.Threading.Timer((object o) => HandleElapsed(o), this, Timeout.Infinite, Timeout.Infinite); - } - - protected override void EnableTimer() - { - _timer.Change(16, 16); - } - - protected override void DisableTimer() - { - _timer.Change(-1, -1); - } - - void HandleElapsed(object state) - { - s_context.Post((o) => SendSignals(-1), null); - } - } #region IPlatformServices implementation - - // public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes) - // { - // int pt; - // // Actual font size depends on the target idiom. - // switch (size) - // { - // case NamedSize.Micro: - // pt = Device.Idiom == TargetIdiom.TV || Device.Idiom == TargetIdiom.Watch ? 24 : 19; - // break; - // case NamedSize.Small: - // pt = Device.Idiom == TargetIdiom.TV ? 26 : (Device.Idiom == TargetIdiom.Watch ? 30 : 22); - // break; - // case NamedSize.Default: - // case NamedSize.Medium: - // pt = Device.Idiom == TargetIdiom.TV ? 28 : (Device.Idiom == TargetIdiom.Watch ? 32 : 25); - // break; - // case NamedSize.Large: - // pt = Device.Idiom == TargetIdiom.TV ? 84 : (Device.Idiom == TargetIdiom.Watch ? 36 : 31); - // break; - // default: - // throw new ArgumentOutOfRangeException(); - // } - // return Forms.ConvertToDPFont(pt); - // } - - // public void OpenUriAction(Uri uri) - // { - // if (uri == null || uri.AbsoluteUri == null) - // { - // throw new ArgumentNullException(nameof(uri)); - // } - // TAppControl tAppControl = new TAppControl() { Operation = "%", Uri = uri.AbsoluteUri }; - // var matchedApplications = TAppControl.GetMatchedApplicationIds(tAppControl); - // if (matchedApplications.Count() > 0) - // { - // TAppControl.SendLaunchRequest(tAppControl); - // return; - // } - // throw new PlatformNotSupportedException(); - // } - public void BeginInvokeOnMainThread(Action action) { s_context.Post((o) => action(), null); } - public Ticker CreateTicker() - { - return new TizenTicker(); - } - public void StartTimer(TimeSpan interval, Func callback) { Console.WriteLine("TizenPlatformServices StartTimer ..."); diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ToolbarItem.cs b/src/Tizen.NUI/src/internal/XamlBinding/ToolbarItem.cs deleted file mode 100755 index ceb68207d..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ToolbarItem.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal class ToolbarItem : MenuItem - { - static readonly BindableProperty OrderProperty = BindableProperty.Create("Order", typeof(ToolbarItemOrder), typeof(ToolbarItem), ToolbarItemOrder.Default, validateValue: (bo, o) => - { - var order = (ToolbarItemOrder)o; - return order == ToolbarItemOrder.Default || order == ToolbarItemOrder.Primary || order == ToolbarItemOrder.Secondary; - }); - - static readonly BindableProperty PriorityProperty = BindableProperty.Create("Priority", typeof(int), typeof(ToolbarItem), 0); - - public ToolbarItem() - { - } - - public ToolbarItem(string name, string icon, Action activated, ToolbarItemOrder order = ToolbarItemOrder.Default, int priority = 0) - { - if (activated == null) - throw new ArgumentNullException("activated"); - - Text = name; - Icon = icon; - Clicked += (s, e) => activated(); - Order = order; - Priority = priority; - } - - [Obsolete("Name is obsolete as of version 1.3.0. Please use Text instead.")] - public string Name - { - get { return Text; } - set { Text = value; } - } - - public ToolbarItemOrder Order - { - get { return (ToolbarItemOrder)GetValue(OrderProperty); } - set { SetValue(OrderProperty, value); } - } - - public int Priority - { - get { return (int)GetValue(PriorityProperty); } - set { SetValue(PriorityProperty, value); } - } - - [Obsolete("Activated is obsolete as of version 1.3.0. Please use Clicked instead.")] - public event EventHandler Activated - { - add { Clicked += value; } - remove { Clicked -= value; } - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ToolbarItemEventArgs.cs b/src/Tizen.NUI/src/internal/XamlBinding/ToolbarItemEventArgs.cs deleted file mode 100755 index d1cb9b00f..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/ToolbarItemEventArgs.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Tizen.NUI.Binding -{ - internal class ToolbarItemEventArgs : EventArgs - { - public ToolbarItemEventArgs(ToolbarItem item) - { - ToolbarItem = item; - } - - public ToolbarItem ToolbarItem { get; private set; } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/XamlBinding/TypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/TypeConverter.cs deleted file mode 100755 index bdc67a840..000000000 --- a/src/Tizen.NUI/src/internal/XamlBinding/TypeConverter.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Globalization; - -namespace Tizen.NUI.Binding -{ - internal abstract class TypeConverter - { - public virtual bool CanConvertFrom(Type sourceType) - { - if (sourceType == null) - throw new ArgumentNullException(nameof(sourceType)); - - return sourceType == typeof(string); - } - - [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")] - public virtual object ConvertFrom(object o) - { - return null; - } - - [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")] - public virtual object ConvertFrom(CultureInfo culture, object o) - { - return null; - } - - public virtual object ConvertFromInvariantString(string value) - { -#pragma warning disable 0618 // retain until ConvertFrom removed - return ConvertFrom(CultureInfo.InvariantCulture, value); -#pragma warning restore - } - } -} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Animation.cs b/src/Tizen.NUI/src/public/Animation.cs index f2e036f6f..3eb777285 100755 --- a/src/Tizen.NUI/src/public/Animation.cs +++ b/src/Tizen.NUI/src/public/Animation.cs @@ -993,12 +993,6 @@ namespace Tizen.NUI } } - var nativeValueConverterService = DependencyService.Get(); - - object nativeValue = null; - if (nativeValueConverterService != null && nativeValueConverterService.ConvertTo(value, toType, out nativeValue)) - return nativeValue; - return value; } diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index 73bff938e..8e40ac4ab 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -1997,7 +1997,9 @@ namespace Tizen.NUI.BaseComponents } } - internal override bool IsCreateByXaml + /// Only used by the IL of xaml, will never changed to not hidden. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool IsCreateByXaml { get { diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index 4553a9aed..73a9b7e55 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -2081,7 +2081,9 @@ namespace Tizen.NUI.BaseComponents } } - internal override bool IsCreateByXaml + /// Only used by the IL of xaml, will never changed to not hidden. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool IsCreateByXaml { get { diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 5597b46bd..8e2b5228c 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -90,7 +90,6 @@ namespace Tizen.NUI.BaseComponents /// View is the base class for all views. /// /// 3 - [ContentProperty("Children")] public class View : Container, IResourcesProvider { /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -3482,7 +3481,10 @@ namespace Tizen.NUI.BaseComponents } } - internal Style Style + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Style Style { get { diff --git a/src/Tizen.NUI/src/public/BaseHandle.cs b/src/Tizen.NUI/src/public/BaseHandle.cs index 88dcd0b69..3b150bb18 100755 --- a/src/Tizen.NUI/src/public/BaseHandle.cs +++ b/src/Tizen.NUI/src/public/BaseHandle.cs @@ -29,13 +29,6 @@ namespace Tizen.NUI /// 3 public class BaseHandle : Element, global::System.IDisposable { - internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(/*VisualElement*/BaseHandle), default(INavigation)); - - /// - /// Backing store for the Navigation property. - /// - internal static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty; - /// /// swigCMemOwn /// @@ -135,23 +128,6 @@ namespace Tizen.NUI } } - /// - /// For internal use. - /// - internal NavigationProxy NavigationProxy - { - get { return Navigation as NavigationProxy; } - } - - /// - /// Gets the navigation. - /// - internal INavigation Navigation - { - get { return (INavigation)GetValue(NavigationProperty); } - set { SetValue(NavigationPropertyKey, value); } - } - /// /// Returns the bool value true to indicate that an operand is true and returns false otherwise. /// diff --git a/src/Tizen.NUI/src/public/Container.cs b/src/Tizen.NUI/src/public/Container.cs index 4971a4e6d..9f21585c3 100755 --- a/src/Tizen.NUI/src/public/Container.cs +++ b/src/Tizen.NUI/src/public/Container.cs @@ -17,7 +17,9 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using Tizen.NUI.BaseComponents; +using Tizen.NUI.Binding; namespace Tizen.NUI { diff --git a/src/Tizen.NUI/src/public/NUIApplication.cs b/src/Tizen.NUI/src/public/NUIApplication.cs index 129d86b47..3f82bd7ac 100755 --- a/src/Tizen.NUI/src/public/NUIApplication.cs +++ b/src/Tizen.NUI/src/public/NUIApplication.cs @@ -354,7 +354,6 @@ namespace Tizen.NUI protected override void OnCreate() { base.OnCreate(); - Device.PlatformServices = new TizenPlatformServices(); } } diff --git a/src/Tizen.NUI/src/public/UIComponents/PushButton.cs b/src/Tizen.NUI/src/public/UIComponents/PushButton.cs index 9505d8d09..cdafc0629 100755 --- a/src/Tizen.NUI/src/public/UIComponents/PushButton.cs +++ b/src/Tizen.NUI/src/public/UIComponents/PushButton.cs @@ -84,7 +84,9 @@ namespace Tizen.NUI.UIComponents } } - internal override bool IsCreateByXaml + /// Only used by the IL of xaml, will never changed to not hidden. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool IsCreateByXaml { get { diff --git a/src/Tizen.NUI/src/public/UIComponents/Slider.cs b/src/Tizen.NUI/src/public/UIComponents/Slider.cs index 599e1f138..9e9279610 100755 --- a/src/Tizen.NUI/src/public/UIComponents/Slider.cs +++ b/src/Tizen.NUI/src/public/UIComponents/Slider.cs @@ -634,7 +634,9 @@ namespace Tizen.NUI.UIComponents } } - internal override bool IsCreateByXaml + /// Only used by the IL of xaml, will never changed to not hidden. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool IsCreateByXaml { get { diff --git a/src/Tizen.NUI/src/public/Xaml/IMarkupExtension.cs b/src/Tizen.NUI/src/public/Xaml/IMarkupExtension.cs new file mode 100755 index 000000000..717e98770 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IMarkupExtension.cs @@ -0,0 +1,30 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IMarkupExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + new T ProvideValue(IServiceProvider serviceProvider); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object ProvideValue(IServiceProvider serviceProvider); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [AttributeUsage(AttributeTargets.Class, Inherited = false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public sealed class AcceptEmptyServiceProviderAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/IProvideValueTarget.cs b/src/Tizen.NUI/src/public/Xaml/IProvideValueTarget.cs new file mode 100755 index 000000000..cca7fa9be --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IProvideValueTarget.cs @@ -0,0 +1,17 @@ +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IProvideValueTarget + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object TargetObject { get; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object TargetProperty { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/IReferenceProvider.cs b/src/Tizen.NUI/src/public/Xaml/IReferenceProvider.cs new file mode 100755 index 000000000..ac89fe0b4 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IReferenceProvider.cs @@ -0,0 +1,13 @@ +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IReferenceProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object FindByName(string name); + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/IRootObjectProvider.cs b/src/Tizen.NUI/src/public/Xaml/IRootObjectProvider.cs new file mode 100755 index 000000000..6206ce852 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IRootObjectProvider.cs @@ -0,0 +1,13 @@ +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + internal interface IRootObjectProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object RootObject { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/IValueProvider.cs b/src/Tizen.NUI/src/public/Xaml/IValueProvider.cs new file mode 100755 index 000000000..4ba8d3db8 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IValueProvider.cs @@ -0,0 +1,14 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IValueProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object ProvideValue(IServiceProvider serviceProvider); + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/IXamlTypeResolver.cs b/src/Tizen.NUI/src/public/Xaml/IXamlTypeResolver.cs new file mode 100755 index 000000000..88e482cb6 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IXamlTypeResolver.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IXamlTypeResolver + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider = null); + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + bool TryResolve(string qualifiedTypeName, out Type type); + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/IXmlLineInfoProvider.cs b/src/Tizen.NUI/src/public/Xaml/IXmlLineInfoProvider.cs new file mode 100755 index 000000000..56ce8229e --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/IXmlLineInfoProvider.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using System.Xml; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IXmlLineInfoProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + IXmlLineInfo XmlLineInfo { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ArrayExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ArrayExtension.cs new file mode 100755 index 000000000..bd8f1ae20 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ArrayExtension.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Items")] + [AcceptEmptyServiceProvider] + public class ArrayExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ArrayExtension() + { + Items = new List(); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList Items { get; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type Type { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Array ProvideValue(IServiceProvider serviceProvider) + { + if (Type == null) + throw new InvalidOperationException("Type argument mandatory for x:Array extension"); + + if (Items == null) + return null; + + var array = Array.CreateInstance(Type, Items.Count); + for (var i = 0; i < Items.Count; i++) + ((IList)array)[i] = Items[i]; + + return array; + } + + object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + return (this as IMarkupExtension).ProvideValue(serviceProvider); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/BindingExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/BindingExtension.cs new file mode 100755 index 000000000..e2fe6c76f --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/BindingExtension.cs @@ -0,0 +1,80 @@ +using System; +using Tizen.NUI.Binding.Internals; +using Tizen.NUI.Binding; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Path")] + [AcceptEmptyServiceProvider] + public sealed class BindingExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Path { get; set; } = Binding.Binding.SelfPath; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindingMode Mode { get; set; } = BindingMode.Default; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IValueConverter Converter { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ConverterParameter { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string StringFormat { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Source { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string UpdateSourceEventName { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object TargetNullValue { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object FallbackValue { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TypedBindingBase TypedBinding { get; set; } + + BindingBase IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + if (TypedBinding == null) + return new Tizen.NUI.Binding.Binding(Path, Mode, Converter, ConverterParameter, StringFormat, Source) + { + UpdateSourceEventName = UpdateSourceEventName, + FallbackValue = FallbackValue, + TargetNullValue = TargetNullValue, + }; + + TypedBinding.Mode = Mode; + TypedBinding.Converter = Converter; + TypedBinding.ConverterParameter = ConverterParameter; + TypedBinding.StringFormat = StringFormat; + TypedBinding.Source = Source; + TypedBinding.UpdateSourceEventName = UpdateSourceEventName; + TypedBinding.FallbackValue = FallbackValue; + TypedBinding.TargetNullValue = TargetNullValue; + return TypedBinding; + } + + object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + return (this as IMarkupExtension).ProvideValue(serviceProvider); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/DynamicResourceExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/DynamicResourceExtension.cs new file mode 100755 index 000000000..49e19c9dc --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/DynamicResourceExtension.cs @@ -0,0 +1,35 @@ +using System; +using System.ComponentModel; +using Tizen.NUI.Binding; +using Tizen.NUI.Binding.Internals; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Key")] + public sealed class DynamicResourceExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Key { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ProvideValue(IServiceProvider serviceProvider) + { + return ((IMarkupExtension)this).ProvideValue(serviceProvider); + } + + DynamicResource IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + if (Key == null) + { + var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; + var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); + throw new XamlParseException("DynamicResource markup require a Key", lineInfo); + } + return new DynamicResource(Key); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/NullExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/NullExtension.cs new file mode 100755 index 000000000..1983406c7 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/NullExtension.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.NullExtension")] + [AcceptEmptyServiceProvider] + public class NullExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ProvideValue(IServiceProvider serviceProvider) + { + return null; + } + } +} diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ReferenceExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ReferenceExtension.cs new file mode 100755 index 000000000..0641dc98e --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/ReferenceExtension.cs @@ -0,0 +1,61 @@ +using System; +using Tizen.NUI.Binding.Internals; +using Tizen.NUI.Xaml.Internals; +using Tizen.NUI.Binding; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Name")] + public class ReferenceExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Name { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ProvideValue(IServiceProvider serviceProvider) + { + if (serviceProvider == null) + throw new ArgumentNullException(nameof(serviceProvider)); + var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues; + if (valueProvider == null) + throw new ArgumentException("serviceProvider does not provide an IProvideValueTarget"); + var namescopeprovider = serviceProvider.GetService(typeof (INameScopeProvider)) as INameScopeProvider; + if (namescopeprovider != null && namescopeprovider.NameScope != null) + { + var value = namescopeprovider.NameScope.FindByName(Name); + if (value != null) + return value; + } + + foreach (var target in valueProvider.ParentObjects) + { + var bo = target as BindableObject; + if (bo == null) + continue; + var ns = NameScope.GetNameScope(bo) as INameScope; + if (ns == null) + continue; + var value = ns.FindByName(Name); + if (value != null) + return value; + } + //foreach (var target in valueProvider.ParentObjects) + //{ + // var ns = target as INameScope; + // if (ns == null) + // continue; + // var value = ns.FindByName(Name); + // if (value != null) + // return value; + //} + + var lineInfo = (serviceProvider?.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo ?? new XmlLineInfo(); + throw new XamlParseException($"Can not find the object referenced by `{Name}`", lineInfo); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/StaticExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/StaticExtension.cs new file mode 100755 index 000000000..0bbbc9b3e --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/StaticExtension.cs @@ -0,0 +1,59 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Xml; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty(nameof(Member))] + [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.StaticExtension")] + public class StaticExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Member { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ProvideValue(IServiceProvider serviceProvider) + { + IXmlLineInfoProvider lineInfoProvider; + IXmlLineInfo lineInfo; + + if (serviceProvider == null) + throw new ArgumentNullException(nameof(serviceProvider)); + var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver; + if (typeResolver == null) + throw new ArgumentException("No IXamlTypeResolver in IServiceProvider"); + + if (string.IsNullOrEmpty(Member) || !Member.Contains(".")) + { + lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; + lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); + throw new XamlParseException("Syntax for x:Static is [Member=][prefix:]typeName.staticMemberName", lineInfo); + } + + var dotIdx = Member.LastIndexOf('.'); + var typename = Member.Substring(0, dotIdx); + var membername = Member.Substring(dotIdx + 1); + + var type = typeResolver.Resolve(typename, serviceProvider); + + var pinfo = type.GetRuntimeProperties().FirstOrDefault(pi => pi.GetMethod != null && pi.Name == membername && pi.GetMethod.IsStatic); + if (pinfo != null) + return pinfo.GetMethod?.Invoke(null, Array.Empty()); + + var finfo = type.GetRuntimeFields().FirstOrDefault(fi => fi.Name == membername && fi.IsStatic); + if (finfo != null) + return finfo.GetValue(null); + + lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; + lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); + throw new XamlParseException($"No static member found for {Member}", lineInfo); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/StyleSheetExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/StyleSheetExtension.cs new file mode 100755 index 000000000..781642092 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/StyleSheetExtension.cs @@ -0,0 +1,57 @@ +using System; +using System.Xml; +using Tizen.NUI.StyleSheets; +using System.Reflection; +using System.IO; +using Tizen.NUI.Binding; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty(nameof(Style))] + [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")] + public sealed class StyleSheetExtension : IValueProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Style { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Uri Source { get; set; } + + object IValueProvider.ProvideValue(IServiceProvider serviceProvider) + { + IXmlLineInfo lineInfo; + + if (!string.IsNullOrEmpty(Style) && Source != null) { + lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; + throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo); + } + + if (Source != null) { + lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; + if (Source.IsAbsoluteUri) + throw new XamlParseException($"Source only accepts Relative URIs", lineInfo); + + var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType(); + if (rootObjectType == null) + return null; + var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType); + var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath); + var resString = DependencyService.Get()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo); + return StyleSheet.FromString(resString); + } + + if (!string.IsNullOrEmpty(Style)) { + using (var reader = new StringReader(Style)) + return StyleSheet.FromReader(reader); + } + + lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; + throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/TemplateBindingExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/TemplateBindingExtension.cs new file mode 100755 index 000000000..89c89bf58 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/TemplateBindingExtension.cs @@ -0,0 +1,49 @@ +using System; +using System.ComponentModel; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Path")] + [AcceptEmptyServiceProvider] + public sealed class TemplateBindingExtension : IMarkupExtension + { + internal TemplateBindingExtension() + { + Mode = BindingMode.Default; + Path = Tizen.NUI.Binding.Binding.SelfPath; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Path { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindingMode Mode { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IValueConverter Converter { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ConverterParameter { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string StringFormat { get; set; } + + BindingBase IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + return new TemplateBinding(Path, Mode, Converter, ConverterParameter, StringFormat); + } + + object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + return (this as IMarkupExtension).ProvideValue(serviceProvider); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/TypeExtension.cs b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/TypeExtension.cs new file mode 100755 index 000000000..9bcd36b9c --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/MarkupExtensions/TypeExtension.cs @@ -0,0 +1,30 @@ +using System; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Xaml +{ + [ContentProperty(nameof(TypeName))] + [ProvideCompiled("Tizen.NUI.Xaml.Build.Tasks.TypeExtension")] + internal class TypeExtension : IMarkupExtension + { + public string TypeName { get; set; } + + public Type ProvideValue(IServiceProvider serviceProvider) + { + if (string.IsNullOrEmpty(TypeName)) + throw new InvalidOperationException("TypeName isn't set."); + if (serviceProvider == null) + throw new ArgumentNullException(nameof(serviceProvider)); + var typeResolver = serviceProvider.GetService(typeof (IXamlTypeResolver)) as IXamlTypeResolver; + if (typeResolver == null) + throw new ArgumentException("No IXamlTypeResolver in IServiceProvider"); + + return typeResolver.Resolve(TypeName, serviceProvider); + } + + object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) + { + return (this as IMarkupExtension).ProvideValue(serviceProvider); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/StaticResourceExtension.cs b/src/Tizen.NUI/src/public/Xaml/StaticResourceExtension.cs new file mode 100755 index 000000000..b5319095b --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/StaticResourceExtension.cs @@ -0,0 +1,102 @@ +using System; +using System.Xml; +using System.Reflection; +using System.Linq; +using Tizen.NUI.Binding; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Key")] + public sealed class StaticResourceExtension : IMarkupExtension + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Key { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ProvideValue(IServiceProvider serviceProvider) + { + if (serviceProvider == null) + throw new ArgumentNullException(nameof(serviceProvider)); + if (Key == null) { + var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; + var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); + throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo); + } + var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues; + if (valueProvider == null) + throw new ArgumentException(); + var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; + var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null; + object resource = null; + + foreach (var p in valueProvider.ParentObjects) { + var irp = p as IResourcesProvider; + var resDict = irp != null && irp.IsResourcesCreated ? irp.XamlResources : p as ResourceDictionary; + if (resDict == null) + continue; + if (resDict.TryGetValue(Key, out resource)) + break; + } + resource = resource ?? GetApplicationLevelResource(Key, xmlLineInfo); + + var bp = valueProvider.TargetProperty as BindableProperty; + var pi = valueProvider.TargetProperty as PropertyInfo; + var propertyType = bp?.ReturnType ?? pi?.PropertyType; + if (propertyType == null) { + if (resource != null) { + if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) { + // This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty + var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() }); + if (method != null) { + resource = method.Invoke(null, new[] { resource }); + } + } + } + return resource; + } + if (propertyType.IsAssignableFrom(resource?.GetType())) + return resource; + var implicit_op = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType) + ?? propertyType.GetImplicitConversionOperator(fromType: resource?.GetType(), toType: propertyType); + if (implicit_op != null) + return implicit_op.Invoke(resource, new [] { resource }); + + if (resource != null) { + //Special case for https://bugzilla.xamarin.com/show_bug.cgi?id=59818 + //On OnPlatform, check for an opImplicit from the targetType + if ( Device.Flags != null + && Device.Flags.Contains("xamlDoubleImplicitOpHack") + && resource.GetType().GetTypeInfo().IsGenericType + && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>))) { + var tType = resource.GetType().GenericTypeArguments[0]; + var opImplicit = tType.GetImplicitConversionOperator(fromType: tType, toType: propertyType) + ?? propertyType.GetImplicitConversionOperator(fromType: tType, toType: propertyType); + + if (opImplicit != null) { + //convert the OnPlatform to T + var opPlatformImplicitConversionOperator = resource?.GetType().GetImplicitConversionOperator(fromType: resource?.GetType(), toType: tType); + resource = opPlatformImplicitConversionOperator?.Invoke(null, new[] { resource }); + + //and convert to toType + resource = opImplicit.Invoke(null, new[] { resource }); + return resource; + } + } + } + return resource; + } + + internal object GetApplicationLevelResource(string key, IXmlLineInfo xmlLineInfo) + { + object resource = null; + if (Application.Current == null || !((IResourcesProvider)Application.Current).IsResourcesCreated || !Application.Current.XamlResources.TryGetValue(Key, out resource)) + throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo); + return resource; + } + } +} diff --git a/src/Tizen.NUI/src/public/Xaml/TypeConversionAttribute.cs b/src/Tizen.NUI/src/public/Xaml/TypeConversionAttribute.cs new file mode 100755 index 000000000..8ba332be7 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/TypeConversionAttribute.cs @@ -0,0 +1,22 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [System.AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)] + public sealed class TypeConversionAttribute : Attribute + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type TargetType { get; private set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TypeConversionAttribute(Type targetType) + { + TargetType = targetType; + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/XamlCompilationAttribute.cs b/src/Tizen.NUI/src/public/Xaml/XamlCompilationAttribute.cs new file mode 100755 index 000000000..c132a9865 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/XamlCompilationAttribute.cs @@ -0,0 +1,56 @@ +using System; +using System.ComponentModel; +using System.Reflection; +using System.Runtime.CompilerServices; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Flags] + public enum XamlCompilationOptions + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + Skip = 1 << 0, + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + Compile = 1 << 1 + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class, Inherited = false)] + public sealed class XamlCompilationAttribute : Attribute + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlCompilationAttribute(XamlCompilationOptions xamlCompilationOptions) + { + XamlCompilationOptions = xamlCompilationOptions; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlCompilationOptions XamlCompilationOptions { get; set; } + } + + internal static class XamlCExtensions + { + public static bool IsCompiled(this Type type) + { + var attr = type.GetTypeInfo().GetCustomAttribute(); + if (attr != null) + return attr.XamlCompilationOptions == XamlCompilationOptions.Compile; + attr = type.GetTypeInfo().Module.GetCustomAttribute(); + if (attr != null) + return attr.XamlCompilationOptions == XamlCompilationOptions.Compile; + attr = type.GetTypeInfo().Assembly.GetCustomAttribute(); + if (attr != null) + return attr.XamlCompilationOptions == XamlCompilationOptions.Compile; + + return false; + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/XamlFilePathAttribute.cs b/src/Tizen.NUI/src/public/Xaml/XamlFilePathAttribute.cs new file mode 100755 index 000000000..148340239 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/XamlFilePathAttribute.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] + public sealed class XamlFilePathAttribute : Attribute + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlFilePathAttribute([CallerFilePath] string filePath = "") + { + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/XamlParseException.cs b/src/Tizen.NUI/src/public/Xaml/XamlParseException.cs new file mode 100755 index 000000000..f22a050f2 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/XamlParseException.cs @@ -0,0 +1,54 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Text; +using System.Xml; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class XamlParseException : Exception + { + readonly string _unformattedMessage; + + static private StringBuilder GetStackInfo() + { + StringBuilder ret = new StringBuilder("\nStack:\n"); + + StackTrace st = new StackTrace(); + + for (int i = 2; i < st.FrameCount; i++) + { + StackFrame sf = st.GetFrame(i); + ret.AppendFormat("File:{0}, Method:{1}, Line:{2}\n", sf.GetFileName(), sf.GetMethod().Name, sf.GetFileLineNumber()); + } + + return ret; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message + GetStackInfo(), xmlInfo), innerException) + { + _unformattedMessage = message; + XmlInfo = xmlInfo; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IXmlLineInfo XmlInfo { get; private set; } + + internal string UnformattedMessage + { + get { return _unformattedMessage ?? Message; } + } + + static string FormatMessage(string message, IXmlLineInfo xmlinfo) + { + if (xmlinfo == null || !xmlinfo.HasLineInfo()) + return message; + return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/XamlResourceIdAttribute.cs b/src/Tizen.NUI/src/public/Xaml/XamlResourceIdAttribute.cs new file mode 100755 index 000000000..432ee8005 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/XamlResourceIdAttribute.cs @@ -0,0 +1,80 @@ +using System; +using System.ComponentModel; +using System.Reflection; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)] + public sealed class XamlResourceIdAttribute : Attribute + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string ResourceId { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Path { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type Type { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlResourceIdAttribute(string resourceId, string path, Type type) + { + ResourceId = resourceId; + Path = path; + Type = type; + } + + internal static string GetResourceIdForType(Type type) + { + var assembly = type.GetTypeInfo().Assembly; + foreach (var xria in assembly.GetCustomAttributes()) { + if (xria.Type == type) + return xria.ResourceId; + } + return null; + } + + internal static string GetPathForType(Type type) + { + var assembly = type.GetTypeInfo().Assembly; + foreach (var xria in assembly.GetCustomAttributes()) { + if (xria.Type == type) + return xria.Path; + } + return null; + } + + internal static string GetResourceIdForPath(Assembly assembly, string path) + { + foreach (var xria in assembly.GetCustomAttributes()) { + if (xria.Path == path) + return xria.ResourceId; + } + return null; + } + + internal static Type GetTypeForResourceId(Assembly assembly, string resourceId) + { + foreach (var xria in assembly.GetCustomAttributes()) { + if (xria.ResourceId == resourceId) + return xria.Type; + } + return null; + } + + internal static Type GetTypeForPath(Assembly assembly, string path) + { + foreach (var xria in assembly.GetCustomAttributes()) { + if (xria.Path == path) + return xria.Type; + } + return null; + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/XamlServiceProvider.cs b/src/Tizen.NUI/src/public/Xaml/XamlServiceProvider.cs new file mode 100755 index 000000000..0062f5f27 --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/XamlServiceProvider.cs @@ -0,0 +1,371 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; +using System.Xml; +using Tizen.NUI.Binding; +using Tizen.NUI.Binding.Internals; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class XamlServiceProvider : IServiceProvider + { + readonly Dictionary services = new Dictionary(); + + internal XamlServiceProvider(INode node, HydrationContext context) + { + object targetObject; + if (node != null && node.Parent != null && context.Values.TryGetValue(node.Parent, out targetObject)) + IProvideValueTarget = new XamlValueTargetProvider(targetObject, node, context, null); + if (context != null) + IRootObjectProvider = new XamlRootObjectProvider(context.RootElement); + if (node != null) + { + IXamlTypeResolver = new XamlTypeResolver(node.NamespaceResolver, XamlParser.GetElementType, + context?.RootElement.GetType().GetTypeInfo().Assembly); + + Add(typeof(IReferenceProvider), new ReferenceProvider(node)); + } + + var xmlLineInfo = node as IXmlLineInfo; + if (xmlLineInfo != null) + IXmlLineInfoProvider = new XmlLineInfoProvider(xmlLineInfo); + + IValueConverterProvider = new ValueConverterProvider(); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlServiceProvider() + { + IValueConverterProvider = new ValueConverterProvider(); + } + + internal IProvideValueTarget IProvideValueTarget + { + get { return (IProvideValueTarget)GetService(typeof (IProvideValueTarget)); } + set { services[typeof (IProvideValueTarget)] = value; } + } + + internal IXamlTypeResolver IXamlTypeResolver + { + get { return (IXamlTypeResolver)GetService(typeof (IXamlTypeResolver)); } + set { services[typeof (IXamlTypeResolver)] = value; } + } + + internal IRootObjectProvider IRootObjectProvider + { + get { return (IRootObjectProvider)GetService(typeof (IRootObjectProvider)); } + set { services[typeof (IRootObjectProvider)] = value; } + } + + internal IXmlLineInfoProvider IXmlLineInfoProvider + { + get { return (IXmlLineInfoProvider)GetService(typeof (IXmlLineInfoProvider)); } + set { services[typeof (IXmlLineInfoProvider)] = value; } + } + + internal INameScopeProvider INameScopeProvider + { + get { return (INameScopeProvider)GetService(typeof (INameScopeProvider)); } + set { services[typeof (INameScopeProvider)] = value; } + } + + internal IValueConverterProvider IValueConverterProvider + { + get { return (IValueConverterProvider)GetService(typeof (IValueConverterProvider)); } + set { services[typeof (IValueConverterProvider)] = value; } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object GetService(Type serviceType) + { + object service; + return services.TryGetValue(serviceType, out service) ? service : null; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void Add(Type type, object service) + { + services.Add(type, service); + } + } + + internal class XamlValueTargetProvider : IProvideParentValues, IProvideValueTarget + { + public XamlValueTargetProvider(object targetObject, INode node, HydrationContext context, object targetProperty) + { + Context = context; + Node = node; + TargetObject = targetObject; + TargetProperty = targetProperty; + } + + INode Node { get; } + + HydrationContext Context { get; } + public object TargetObject { get; } + public object TargetProperty { get; internal set; } = null; + + IEnumerable IProvideParentValues.ParentObjects + { + get + { + if (Node == null || Context == null) + yield break; + var n = Node; + object obj = null; + var context = Context; + while (n.Parent != null && context != null) + { + if (n.Parent is IElementNode) + { + if (context.Values.TryGetValue(n.Parent, out obj)) + yield return obj; + else + { + context = context.ParentContext; + continue; + } + } + n = n.Parent; + } + } + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class SimpleValueTargetProvider : IProvideParentValues, IProvideValueTarget, IReferenceProvider + { + readonly object[] objectAndParents; + readonly object targetProperty; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("SimpleValueTargetProvider(object[] objectAndParents) is obsolete as of version 2.3.4. Please use SimpleValueTargetProvider(object[] objectAndParents, object targetProperty) instead.")] + public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null) + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty) + { + if (objectAndParents == null) + throw new ArgumentNullException(nameof(objectAndParents)); + if (objectAndParents.Length == 0) + throw new ArgumentException(); + + this.objectAndParents = objectAndParents; + this.targetProperty = targetProperty; + } + + IEnumerable IProvideParentValues.ParentObjects + => objectAndParents; + + object IProvideValueTarget.TargetObject + => objectAndParents[0]; + + object IProvideValueTarget.TargetProperty + => targetProperty; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object FindByName(string name) + { + for (var i = 0; i < objectAndParents.Length; i++) { + var bo = objectAndParents[i] as BindableObject; + if (bo == null) continue; + var ns = NameScope.GetNameScope(bo) as INameScope; + if (ns == null) continue; + var value = ns.FindByName(name); + if (value != null) + return value; + } + return null; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class XamlTypeResolver : IXamlTypeResolver + { + readonly Assembly currentAssembly; + readonly GetTypeFromXmlName getTypeFromXmlName; + readonly IXmlNamespaceResolver namespaceResolver; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, Assembly currentAssembly) + : this(namespaceResolver, XamlParser.GetElementType, currentAssembly) + { + } + + internal XamlTypeResolver(IXmlNamespaceResolver namespaceResolver, GetTypeFromXmlName getTypeFromXmlName, + Assembly currentAssembly) + { + this.currentAssembly = currentAssembly; + if (namespaceResolver == null) + throw new ArgumentNullException(); + if (getTypeFromXmlName == null) + throw new ArgumentNullException(); + + this.namespaceResolver = namespaceResolver; + this.getTypeFromXmlName = getTypeFromXmlName; + } + + Type IXamlTypeResolver.Resolve(string qualifiedTypeName, IServiceProvider serviceProvider) + { + XamlParseException e; + var type = Resolve(qualifiedTypeName, serviceProvider, out e); + if (e != null) + throw e; + return type; + } + + bool IXamlTypeResolver.TryResolve(string qualifiedTypeName, out Type type) + { + XamlParseException exception; + type = Resolve(qualifiedTypeName, null, out exception); + return exception == null; + } + + Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider, out XamlParseException exception) + { + exception = null; + var split = qualifiedTypeName.Split(':'); + if (split.Length > 2) + return null; + + string prefix, name; + if (split.Length == 2) + { + prefix = split[0]; + name = split[1]; + } + else + { + prefix = ""; + name = split[0]; + } + + IXmlLineInfo xmlLineInfo = null; + if (serviceProvider != null) + { + var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider; + if (lineInfoProvider != null) + xmlLineInfo = lineInfoProvider.XmlLineInfo; + } + + var namespaceuri = namespaceResolver.LookupNamespace(prefix); + if (namespaceuri == null) + { + exception = new XamlParseException(string.Format("No xmlns declaration for prefix \"{0}\"", prefix), xmlLineInfo); + return null; + } + + return getTypeFromXmlName(new XmlType(namespaceuri, name, null), xmlLineInfo, currentAssembly, out exception); + } + + internal delegate Type GetTypeFromXmlName( + XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly, out XamlParseException exception); + } + + internal class XamlRootObjectProvider : IRootObjectProvider + { + public XamlRootObjectProvider(object rootObject) + { + RootObject = rootObject; + } + + public object RootObject { get; } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class XmlLineInfoProvider : IXmlLineInfoProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XmlLineInfoProvider(IXmlLineInfo xmlLineInfo) + { + XmlLineInfo = xmlLineInfo; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IXmlLineInfo XmlLineInfo { get; } + } + + class ReferenceProvider : IReferenceProvider + { + readonly INode _node; + internal ReferenceProvider(INode node) + => _node = node; + + public object FindByName(string name) + { + var n = _node; + object value = null; + while (n != null) { + if ((value = (n as IElementNode)?.Namescope?.FindByName(name)) != null) + return value; + n = n.Parent; + } + return null; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete] + public class NameScopeProvider : INameScopeProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public INameScope NameScope { get; set; } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class XmlNamespaceResolver : IXmlNamespaceResolver + { + readonly Dictionary namespaces = new Dictionary(); + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IDictionary GetNamespacesInScope(XmlNamespaceScope scope) + { + throw new NotImplementedException(); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string LookupNamespace(string prefix) + { + string result; + if (namespaces.TryGetValue(prefix, out result)) + return result; + return null; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string LookupPrefix(string namespaceName) + { + throw new NotImplementedException(); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void Add(string prefix, string ns) + { + namespaces.Add(prefix, ns); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Xaml/XmlLineInfo.cs b/src/Tizen.NUI/src/public/Xaml/XmlLineInfo.cs new file mode 100755 index 000000000..0a51d66ae --- /dev/null +++ b/src/Tizen.NUI/src/public/Xaml/XmlLineInfo.cs @@ -0,0 +1,42 @@ +using System.ComponentModel; +using System.Xml; + +namespace Tizen.NUI.Xaml +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class XmlLineInfo : IXmlLineInfo + { + readonly bool _hasLineInfo; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XmlLineInfo() + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XmlLineInfo(int linenumber, int lineposition) + { + _hasLineInfo = true; + LineNumber = linenumber; + LinePosition = lineposition; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool HasLineInfo() + { + return _hasLineInfo; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int LineNumber { get; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int LinePosition { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs b/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs index 7ddbc048e..c5a4e626f 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs @@ -146,13 +146,17 @@ namespace Tizen.NUI.Binding /// /// The BindableProperty on which to set a binding. /// The binding to set. - internal void SetBinding(BindableProperty targetProperty, BindingBase binding) + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void SetBinding(BindableProperty targetProperty, BindingBase binding) { SetBinding(targetProperty, binding, false); } private bool isCreateByXaml = false; - internal virtual bool IsCreateByXaml + /// Only used by the IL of xaml, will never changed to not hidden. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool IsCreateByXaml { get { diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindableObjectExtensions.cs b/src/Tizen.NUI/src/public/XamlBinding/BindableObjectExtensions.cs new file mode 100755 index 000000000..3c9023d28 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindableObjectExtensions.cs @@ -0,0 +1,42 @@ +using System; +using System.ComponentModel; +using System.Linq.Expressions; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static class BindableObjectExtensions + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, + string stringFormat = null) + { + if (self == null) + throw new ArgumentNullException("self"); + if (targetProperty == null) + throw new ArgumentNullException("targetProperty"); + + var binding = new Binding(path, mode, converter, stringFormat: stringFormat); + self.SetBinding(targetProperty, binding); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete] + public static void SetBinding(this BindableObject self, BindableProperty targetProperty, Expression> sourceProperty, BindingMode mode = BindingMode.Default, + IValueConverter converter = null, string stringFormat = null) + { + if (self == null) + throw new ArgumentNullException("self"); + if (targetProperty == null) + throw new ArgumentNullException("targetProperty"); + if (sourceProperty == null) + throw new ArgumentNullException("sourceProperty"); + + Binding binding = Binding.Create(sourceProperty, mode, converter, stringFormat: stringFormat); + self.SetBinding(targetProperty, binding); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindableProperty.cs b/src/Tizen.NUI/src/public/XamlBinding/BindableProperty.cs new file mode 100755 index 000000000..4ab7a5900 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindableProperty.cs @@ -0,0 +1,559 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq.Expressions; +using System.Reflection; +using System.ComponentModel; +using Tizen.NUI.Binding.Internals; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// + /// A BindableProperty is a backing store for properties allowing bindings on BindableObject. + /// + [DebuggerDisplay("{PropertyName}")] + [TypeConverter(typeof(BindablePropertyConverter))] + [EditorBrowsable(EditorBrowsableState.Never)] + public sealed class BindableProperty + { + /// + /// Delegate for BindableProperty.PropertyChanged. + /// + /// The bindable object that contains the property. + /// The old property value. + /// The new property value. + public delegate void BindingPropertyChangedDelegate(BindableObject bindable, object oldValue, object newValue); + + /// + /// Strongly-typed delegate for BindableProperty.PropertyChanged. + /// + /// The type of the bound property. + /// The bindable object that contains the property. + /// The old property value. + /// The new property value. + public delegate void BindingPropertyChangedDelegate(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue); + + /// + /// Delegate for BindableProperty.PropertyChanging. + /// + /// The bindable object that contains the property. + /// The old property value. + /// The new property value. + public delegate void BindingPropertyChangingDelegate(BindableObject bindable, object oldValue, object newValue); + + /// + /// Strongly-typed delegate for BindableProperty.PropertyChanging. + /// + /// The type of the bound property. + /// The bindable object that contains the property. + /// The old property value. + /// The new property value. + public delegate void BindingPropertyChangingDelegate(BindableObject bindable, TPropertyType oldValue, TPropertyType newValue); + + /// + /// Delegate for BindableProperty.CoerceValue. + /// + /// The bindable object that contains the property. + /// The value to coerce. + /// System.Object + public delegate object CoerceValueDelegate(BindableObject bindable, object value); + + /// + /// Strongly-typed delegate for BindableProperty.CoerceValue. + /// + /// The type of the bound property. + /// The bindable object that contains the property. + /// The value to coerce. + /// TPropertyType + public delegate TPropertyType CoerceValueDelegate(BindableObject bindable, TPropertyType value); + + /// + /// Delegate for BindableProperty.DefaultValueCreator. + /// + /// The bindable object that contains the property. + /// System.Object + public delegate object CreateDefaultValueDelegate(BindableObject bindable); + + /// + /// Strongly-typed delegate for BindableProperty.DefaultValueCreator. + /// + /// The type of the object that delared the property. + /// The type of the bound property. + /// The bindable object that contains the property. + /// TPropertyType + public delegate TPropertyType CreateDefaultValueDelegate(TDeclarer bindable); + + /// + /// Delegate for BindableProperty.ValidateValue. + /// + /// The bindable object that contains the property. + /// The default value. + /// System.Boolean + public delegate bool ValidateValueDelegate(BindableObject bindable, object value); + + /// + /// Strongly-typed delegate for BindableProperty.ValidateValue. + /// + /// The type of the bound property. + /// The bindable object that contains the property. + /// The default value. + /// System.Boolean + public delegate bool ValidateValueDelegate(BindableObject bindable, TPropertyType value); + + static readonly Dictionary WellKnownConvertTypes = new Dictionary + { + { typeof(Uri), new UriTypeConverter() }, + { typeof(Color), new ColorTypeConverter() }, + { typeof(Size2D), new Size2DTypeConverter() }, + { typeof(Position2D), new Position2DTypeConverter() }, + { typeof(Size), new SizeTypeConverter() }, + { typeof(Position), new PositionTypeConverter() }, + { typeof(Rectangle), new RectangleTypeConverter() }, + { typeof(Rotation), new RotationTypeConverter() }, + { typeof(Vector2), new Vector2TypeConverter() }, + { typeof(Vector3), new Vector3TypeConverter() }, + { typeof(Vector4), new Vector4TypeConverter() }, + { typeof(RelativeVector2), new RelativeVector2TypeConverter() }, + { typeof(RelativeVector3), new RelativeVector3TypeConverter() }, + { typeof(RelativeVector4), new RelativeVector4TypeConverter() }, + }; + + //Modification for NUI XAML : user defined converter for DynamicResource can be added + static internal Dictionary UserCustomConvertTypes = new Dictionary + { + }; + + // more or less the encoding of this, without the need to reflect + // http://msdn.microsoft.com/en-us/library/y5b434w4.aspx + static readonly Dictionary SimpleConvertTypes = new Dictionary + { + { typeof(sbyte), new[] { typeof(string), typeof(short), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(byte), new[] { typeof(string), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(short), new[] { typeof(string), typeof(int), typeof(long), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(ushort), new[] { typeof(string), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(int), new[] { typeof(string), typeof(long), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(uint), new[] { typeof(string), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(long), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(char), new[] { typeof(string), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal) } }, + { typeof(float), new[] { typeof(string), typeof(double) } }, + { typeof(ulong), new[] { typeof(string), typeof(float), typeof(double), typeof(decimal) } } + }; + + BindableProperty(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, + ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null) + { + if (propertyName == null) + throw new ArgumentNullException("propertyName"); + if (ReferenceEquals(returnType, null)) + throw new ArgumentNullException("returnType"); + if (ReferenceEquals(declaringType, null)) + throw new ArgumentNullException("declaringType"); + + // don't use Enum.IsDefined as its redonkulously expensive for what it does + if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime) + throw new ArgumentException("Not a valid type of BindingMode", "defaultBindingMode"); + if (defaultValue == null && Nullable.GetUnderlyingType(returnType) == null && returnType.GetTypeInfo().IsValueType) + throw new ArgumentException("Not a valid default value", "defaultValue"); + if (defaultValue != null && !returnType.IsInstanceOfType(defaultValue)) + throw new ArgumentException("Default value did not match return type", "defaultValue"); + if (defaultBindingMode == BindingMode.Default) + defaultBindingMode = BindingMode.OneWay; + + PropertyName = propertyName; + ReturnType = returnType; + ReturnTypeInfo = returnType.GetTypeInfo(); + DeclaringType = declaringType; + DefaultValue = defaultValue; + DefaultBindingMode = defaultBindingMode; + PropertyChanged = propertyChanged; + PropertyChanging = propertyChanging; + ValidateValue = validateValue; + CoerceValue = coerceValue; + BindingChanging = bindingChanging; + IsReadOnly = isReadOnly; + DefaultValueCreator = defaultValueCreator; + } + + /// + /// Gets the type declaring the BindableProperty. + /// + public Type DeclaringType { get; private set; } + + /// + /// Gets the default BindingMode. + /// + public BindingMode DefaultBindingMode { get; private set; } + + /// + /// Gets the default value for the BindableProperty. + /// + public object DefaultValue { get; } + + /// + /// Gets a value indicating if the BindableProperty is created form a BindablePropertyKey. + /// + public bool IsReadOnly { get; private set; } + + /// + /// Gets the property name. + /// + public string PropertyName { get; } + + /// + /// Gets the type of the BindableProperty. + /// + public Type ReturnType { get; } + + internal BindablePropertyBindingChanging BindingChanging { get; private set; } + + internal CoerceValueDelegate CoerceValue { get; private set; } + + internal CreateDefaultValueDelegate DefaultValueCreator { get; } + + internal BindingPropertyChangedDelegate PropertyChanged { get; private set; } + + internal BindingPropertyChangingDelegate PropertyChanging { get; private set; } + + internal System.Reflection.TypeInfo ReturnTypeInfo { get; } + + internal ValidateValueDelegate ValidateValue { get; private set; } + + /// + /// Deprecated. Do not use. + /// + /// The type of the declaring object. + /// The type of the property. + /// An expression identifying the getter for the property using this BindableProperty as backing store. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created BindableProperty. + [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] + public static BindableProperty Create(Expression> getter, TPropertyType defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, + ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, + BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, + CreateDefaultValueDelegate defaultValueCreator = null) where TDeclarer : BindableObject + { + return Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, defaultValueCreator: defaultValueCreator); + } + + /// + /// Creates a new instance of the BindableProperty class. + /// + /// The name of the BindableProperty. + /// The type of the property. + /// The type of the declaring object. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created BindableProperty. + public static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue = null, BindingMode defaultBindingMode = BindingMode.OneWay, + ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) + { + return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, + defaultValueCreator: defaultValueCreator); + } + + /// + /// Deprecated. Do not use. + /// + /// The type of the declaring object. + /// The type of the property. + /// An expression identifying a static method returning the value of the property using this BindableProperty as backing store. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] + public static BindableProperty CreateAttached(Expression> staticgetter, TPropertyType defaultValue, + BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, + BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, + CreateDefaultValueDelegate defaultValueCreator = null) + { + return CreateAttached(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, + defaultValueCreator: defaultValueCreator); + } + + /// + /// Creates a new instance of the BindableProperty class for an attached property. + /// + /// The name of the BindableProperty. + /// The type of the property. + /// The type of the declaring object. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created BindableProperty. + public static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, + ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) + { + return CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, false, defaultValueCreator); + } + + /// + /// Deprecated. Do not use. + /// + /// The type of the declaring object. + /// The type of the property. + /// An expression identifying a static method returning the value of the property using this BindableProperty as backing store. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created attached read-only BindablePropertyKey. + [Obsolete("CreateAttachedReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] + public static BindablePropertyKey CreateAttachedReadOnly(Expression> staticgetter, TPropertyType defaultValue, + BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate validateValue = null, + BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) + + { + return + new BindablePropertyKey(CreateAttached(staticgetter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, + defaultValueCreator)); + } + + /// + /// Creates a new instance of the BindableProperty class for attached read-only properties. + /// + /// The name of the BindableProperty. + /// The type of the property. + /// The type of the declaring object. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created attached read-only BindablePropertyKey. + public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, + ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) + { + return + new BindablePropertyKey(CreateAttached(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, + defaultValueCreator)); + } + + /// + /// Deprecated. Do not use. + /// + /// The type of the declaring object. + /// The type of the property. + /// An expression identifying the getter for the property using this BindableProperty as backing store. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created BindablePropertyKey. + [Obsolete("CreateReadOnly<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] + public static BindablePropertyKey CreateReadOnly(Expression> getter, TPropertyType defaultValue, + BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate validateValue = null, + BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) where TDeclarer : BindableObject + { + return new BindablePropertyKey(Create(getter, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, null, true, defaultValueCreator)); + } + + /// + /// Creates a new instance of the BindablePropertyKey class. + /// + /// The name of the BindableProperty. + /// The type of the property. + /// The type of the declaring object. + /// The default value for the property. + /// The BindingMode to use on SetBinding() if no BindingMode is given. This parameter is optional. Default is BindingMode.OneWay. + /// A delegate to be run when a value is set. This parameter is optional. Default is null. + /// A delegate to be run when the value has changed. This parameter is optional. Default is null. + /// A delegate to be run when the value will change. This parameter is optional. Default is null. + /// A delegate used to coerce the range of a value. This parameter is optional. Default is null. + /// A Func used to initialize default value for reference types. + /// A newly created BindablePropertyKey. + public static BindablePropertyKey CreateReadOnly(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, + ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, + CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) + { + return + new BindablePropertyKey(new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, + isReadOnly: true, defaultValueCreator: defaultValueCreator)); + } + + [Obsolete("Create<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] + internal static BindableProperty Create(Expression> getter, TPropertyType defaultValue, BindingMode defaultBindingMode, + ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, + CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false, + CreateDefaultValueDelegate defaultValueCreator = null) where TDeclarer : BindableObject + { + if (getter == null) + throw new ArgumentNullException("getter"); + + Expression expr = getter.Body; + + var unary = expr as UnaryExpression; + if (unary != null) + expr = unary.Operand; + + var member = expr as MemberExpression; + if (member == null) + throw new ArgumentException("getter must be a MemberExpression", "getter"); + + var property = (PropertyInfo)member.Member; + + ValidateValueDelegate untypedValidateValue = null; + BindingPropertyChangedDelegate untypedBindingPropertyChanged = null; + BindingPropertyChangingDelegate untypedBindingPropertyChanging = null; + CoerceValueDelegate untypedCoerceValue = null; + CreateDefaultValueDelegate untypedDefaultValueCreator = null; + if (validateValue != null) + untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value); + if (propertyChanged != null) + untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); + if (propertyChanging != null) + untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); + if (coerceValue != null) + untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value); + if (defaultValueCreator != null) + untypedDefaultValueCreator = o => defaultValueCreator((TDeclarer)o); + + return new BindableProperty(property.Name, property.PropertyType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged, + untypedBindingPropertyChanging, untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator); + } + + internal static BindableProperty Create(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, + BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, + CreateDefaultValueDelegate defaultValueCreator = null) + { + return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging, + defaultValueCreator: defaultValueCreator); + } + + [Obsolete("CreateAttached<> (generic) is obsolete as of version 2.1.0 and is no longer supported.")] + internal static BindableProperty CreateAttached(Expression> staticgetter, TPropertyType defaultValue, BindingMode defaultBindingMode, + ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, + CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false, + CreateDefaultValueDelegate defaultValueCreator = null) + { + if (staticgetter == null) + throw new ArgumentNullException("staticgetter"); + + Expression expr = staticgetter.Body; + + var unary = expr as UnaryExpression; + if (unary != null) + expr = unary.Operand; + + var methodcall = expr as MethodCallExpression; + if (methodcall == null) + throw new ArgumentException("staticgetter must be a MethodCallExpression", "staticgetter"); + + MethodInfo method = methodcall.Method; + if (!method.Name.StartsWith("Get", StringComparison.Ordinal)) + throw new ArgumentException("staticgetter name must start with Get", "staticgetter"); + + string propertyname = method.Name.Substring(3); + + ValidateValueDelegate untypedValidateValue = null; + BindingPropertyChangedDelegate untypedBindingPropertyChanged = null; + BindingPropertyChangingDelegate untypedBindingPropertyChanging = null; + CoerceValueDelegate untypedCoerceValue = null; + CreateDefaultValueDelegate untypedDefaultValueCreator = null; + if (validateValue != null) + untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value); + if (propertyChanged != null) + untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); + if (propertyChanging != null) + untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue); + if (coerceValue != null) + untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value); + if (defaultValueCreator != null) + untypedDefaultValueCreator = o => defaultValueCreator(o); + + return new BindableProperty(propertyname, method.ReturnType, typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged, untypedBindingPropertyChanging, + untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator); + } + + internal static BindableProperty CreateAttached(string propertyName, Type returnType, Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, + BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, + bool isReadOnly, CreateDefaultValueDelegate defaultValueCreator = null) + { + return new BindableProperty(propertyName, returnType, declaringType, defaultValue, defaultBindingMode, validateValue, propertyChanged, propertyChanging, coerceValue, bindingChanging, isReadOnly, + defaultValueCreator); + } + + internal object GetDefaultValue(BindableObject bindable) + { + if (DefaultValueCreator != null) + return DefaultValueCreator(bindable); + + return DefaultValue; + } + + internal bool TryConvert(ref object value) + { + if (value == null) + { + return !ReturnTypeInfo.IsValueType || ReturnTypeInfo.IsGenericType && ReturnTypeInfo.GetGenericTypeDefinition() == typeof(Nullable<>); + } + + Type valueType = value.GetType(); + Type type = ReturnType; + + // Dont support arbitrary IConvertible by limiting which types can use this + Type[] convertableTo; + TypeConverter typeConverterTo; + if (SimpleConvertTypes.TryGetValue(valueType, out convertableTo) && Array.IndexOf(convertableTo, type) != -1) + { + value = Convert.ChangeType(value, type); + } + else if (WellKnownConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType)) + { + value = typeConverterTo.ConvertFromInvariantString(value.ToString()); + } + else if (UserCustomConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType)) + { + //Modification for NUI XAML : user defined converter for DynamicResource can be added + value = typeConverterTo.ConvertFromInvariantString(value.ToString()); + } + else if (!ReturnTypeInfo.IsAssignableFrom(valueType.GetTypeInfo())) + { + var cast = type.GetImplicitConversionOperator(fromType: valueType, toType: type) + ?? valueType.GetImplicitConversionOperator(fromType: valueType, toType: type); + + if (cast == null) + return false; + + value = cast.Invoke(null, new[] { value }); + } + + return true; + } + + internal delegate void BindablePropertyBindingChanging(BindableObject bindable, BindingBase oldValue, BindingBase newValue); + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs new file mode 100755 index 000000000..3e87dd22a --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyConverter.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Xml; +using Tizen.NUI.Binding.Internals; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindablePropertyConverter")] + [TypeConversion(typeof(BindableProperty))] + public sealed class BindablePropertyConverter : TypeConverter, IExtendedTypeConverter + { + object IExtendedTypeConverter.ConvertFrom(CultureInfo culture, object value, IServiceProvider serviceProvider) + { + return ((IExtendedTypeConverter)this).ConvertFromInvariantString(value as string, serviceProvider); + } + + object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider) + { + if (string.IsNullOrWhiteSpace(value)) + return null; + if (serviceProvider == null) + return null; + var parentValuesProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues; + var typeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; + if (typeResolver == null) + return null; + IXmlLineInfo lineinfo = null; + var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; + if (xmlLineInfoProvider != null) + lineinfo = xmlLineInfoProvider.XmlLineInfo; + string[] parts = value.Split('.'); + Type type = null; + if (parts.Length == 1) + { + if (parentValuesProvider == null) + { + string msg = string.Format("Can't resolve {0}", parts[0]); + throw new XamlParseException(msg, lineinfo); + } + object parent = parentValuesProvider.ParentObjects.Skip(1).FirstOrDefault(); + if (parentValuesProvider.TargetObject is Setter) + { + var style = parent as Style; + var triggerBase = parent as TriggerBase; + var visualState = parent as VisualState; + if (style != null) + type = style.TargetType; + else if (triggerBase != null) + type = triggerBase.TargetType; + else if (visualState != null) + type = FindTypeForVisualState(parentValuesProvider, lineinfo); + } + else if (parentValuesProvider.TargetObject is Trigger) + type = (parentValuesProvider.TargetObject as Trigger).TargetType; + else if (parentValuesProvider.TargetObject is XamlPropertyCondition && (parent as TriggerBase) != null) + type = (parent as TriggerBase).TargetType; + + if (type == null) + throw new XamlParseException($"Can't resolve {parts [0]}", lineinfo); + + return ConvertFrom(type, parts[0], lineinfo); + } + if (parts.Length == 2) + { + if (!typeResolver.TryResolve(parts[0], out type)) + { + string msg = string.Format("Can't resolve {0}", parts[0]); + throw new XamlParseException(msg, lineinfo); + } + return ConvertFrom(type, parts[1], lineinfo); + } + throw new XamlParseException($"Can't resolve {value}. Syntax is [[prefix:]Type.]PropertyName.", lineinfo); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override object ConvertFromInvariantString(string value) + { + if (string.IsNullOrWhiteSpace(value)) + return null; + if (value.Contains(":")) + { + Console.WriteLine(null, "Can't resolve properties with xml namespace prefix."); + return null; + } + string[] parts = value.Split('.'); + if (parts.Length != 2) + { + Console.WriteLine(null, $"Can't resolve {value}. Accepted syntax is Type.PropertyName."); + return null; + } + Type type = Type.GetType("Tizen.NUI." + parts[0]); + return ConvertFrom(type, parts[1], null); + } + + BindableProperty ConvertFrom(Type type, string propertyName, IXmlLineInfo lineinfo) + { + string name = propertyName + "Property"; + FieldInfo bpinfo = type.GetField(fi => fi.Name == name && fi.IsStatic && fi.IsPublic && fi.FieldType == typeof(BindableProperty)); + if (bpinfo == null) + throw new XamlParseException($"Can't resolve {name} on {type.Name}", lineinfo); + var bp = bpinfo.GetValue(null) as BindableProperty; + var isObsolete = bpinfo.GetCustomAttribute() != null; + if (bp != null && bp.PropertyName != propertyName && !isObsolete) + throw new XamlParseException($"The PropertyName of {type.Name}.{name} is not {propertyName}", lineinfo); + return bp; + } + + Type FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo) + { + var parents = parentValueProvider.ParentObjects.ToList(); + + // Skip 0; we would not be making this check if TargetObject were not a Setter + // Skip 1; we would not be making this check if the immediate parent were not a VisualState + + // VisualStates must be in a VisualStateGroup + if(!(parents[2] is VisualStateGroup)) { + throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parents[2]}.", lineInfo); + } + + var vsTarget = parents[3]; + + // Are these Visual States directly on a VisualElement? + if (vsTarget is /*VisualElement*/BaseHandle) + { + return vsTarget.GetType(); + } + + if (!(parents[3] is VisualStateGroupList)) + { + throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo); + } + + if (!(parents[4] is Setter)) + { + throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo); + } + + // These must be part of a Style; verify that + if (!(parents[5] is Style style)) + { + throw new XamlParseException($"Expected {nameof(Style)} but found {parents[5]}.", lineInfo); + } + + return style.TargetType; + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyKey.cs b/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyKey.cs new file mode 100755 index 000000000..4ab8e4a74 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindablePropertyKey.cs @@ -0,0 +1,25 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// + /// The secret key to a BindableProperty, used to implement a BindableProperty with restricted write access. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public sealed class BindablePropertyKey + { + internal BindablePropertyKey(BindableProperty property) + { + if (property == null) + throw new ArgumentNullException("property"); + + BindableProperty = property; + } + + /// + /// Gets the BindableProperty. + /// + public BindableProperty BindableProperty { get; private set; } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Binding.cs b/src/Tizen.NUI/src/public/XamlBinding/Binding.cs new file mode 100755 index 000000000..1697c0fdc --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Binding.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; +using Tizen.NUI.Binding.Internals; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public sealed class Binding : BindingBase + { + internal const string SelfPath = "."; + IValueConverter _converter; + object _converterParameter; + + BindingExpression _expression; + string _path; + object _source; + string _updateSourceEventName; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Binding() + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Binding(string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, string stringFormat = null, object source = null) + { + if (path == null) + throw new ArgumentNullException("path"); + if (string.IsNullOrWhiteSpace(path)) + throw new ArgumentException("path can not be an empty string", "path"); + + Path = path; + Converter = converter; + ConverterParameter = converterParameter; + Mode = mode; + StringFormat = stringFormat; + Source = source; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IValueConverter Converter + { + get { return _converter; } + set + { + ThrowIfApplied(); + + _converter = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ConverterParameter + { + get { return _converterParameter; } + set + { + ThrowIfApplied(); + + _converterParameter = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Path + { + get { return _path; } + set + { + ThrowIfApplied(); + + _path = value; + _expression = new BindingExpression(this, !string.IsNullOrWhiteSpace(value) ? value : SelfPath); + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Source + { + get { return _source; } + set + { + ThrowIfApplied(); + _source = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string UpdateSourceEventName { + get { return _updateSourceEventName; } + set { + ThrowIfApplied(); + _updateSourceEventName = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete] + public static Binding Create(Expression> propertyGetter, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, + string stringFormat = null) + { + if (propertyGetter == null) + throw new ArgumentNullException("propertyGetter"); + + return new Binding(GetBindingPath(propertyGetter), mode, converter, converterParameter, stringFormat); + } + + internal override void Apply(bool fromTarget) + { + base.Apply(fromTarget); + + if (_expression == null) + _expression = new BindingExpression(this, SelfPath); + + _expression.Apply(fromTarget); + } + + internal override void Apply(object newContext, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false) + { + object src = _source; + var isApplied = IsApplied; + + base.Apply(src ?? newContext, bindObj, targetProperty, fromBindingContextChanged: fromBindingContextChanged); + + if (src != null && isApplied && fromBindingContextChanged) + return; + + object bindingContext = src ?? Context ?? newContext; + if (_expression == null && bindingContext != null) + _expression = new BindingExpression(this, SelfPath); + + _expression?.Apply(bindingContext, bindObj, targetProperty); + } + + internal override BindingBase Clone() + { + return new Binding(Path, Mode) { Converter = Converter, ConverterParameter = ConverterParameter, StringFormat = StringFormat, Source = Source, UpdateSourceEventName = UpdateSourceEventName }; + } + + internal override object GetSourceValue(object value, Type targetPropertyType) + { + if (Converter != null) + value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture); + + return base.GetSourceValue(value, targetPropertyType); + } + + internal override object GetTargetValue(object value, Type sourcePropertyType) + { + if (Converter != null) + value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture); + + return base.GetTargetValue(value, sourcePropertyType); + } + + internal override void Unapply(bool fromBindingContextChanged = false) + { + if (Source != null && fromBindingContextChanged && IsApplied) + return; + + base.Unapply(fromBindingContextChanged: fromBindingContextChanged); + + if (_expression != null) + _expression.Unapply(); + } + + [Obsolete] + static string GetBindingPath(Expression> propertyGetter) + { + Expression expr = propertyGetter.Body; + + var unary = expr as UnaryExpression; + if (unary != null) + expr = unary.Operand; + + var builder = new StringBuilder(); + + var indexed = false; + + var member = expr as MemberExpression; + if (member == null) + { + var methodCall = expr as MethodCallExpression; + if (methodCall != null) + { + if (methodCall.Arguments.Count == 0) + throw new ArgumentException("Method calls are not allowed in binding expression"); + + var arguments = new List(methodCall.Arguments.Count); + foreach (Expression arg in methodCall.Arguments) + { + if (arg.NodeType != ExpressionType.Constant) + throw new ArgumentException("Only constants can be used as indexer arguments"); + + object value = ((ConstantExpression)arg).Value; + arguments.Add(value != null ? value.ToString() : "null"); + } + + Type declarerType = methodCall.Method.DeclaringType; + DefaultMemberAttribute defaultMember = declarerType.GetTypeInfo().GetCustomAttributes(typeof(DefaultMemberAttribute), true).OfType().FirstOrDefault(); + string indexerName = defaultMember != null ? defaultMember.MemberName : "Item"; + + MethodInfo getterInfo = + declarerType.GetProperties().Where(pi => (pi.GetMethod != null) && pi.Name == indexerName && pi.CanRead && pi.GetMethod.IsPublic && !pi.GetMethod.IsStatic).Select(pi => pi.GetMethod).FirstOrDefault(); + if (getterInfo != null) + { + if (getterInfo == methodCall.Method) + { + indexed = true; + builder.Append("["); + + var first = true; + foreach (string argument in arguments) + { + if (!first) + builder.Append(","); + + builder.Append(argument); + first = false; + } + + builder.Append("]"); + + member = methodCall.Object as MemberExpression; + } + else + throw new ArgumentException("Method calls are not allowed in binding expressions"); + } + else + throw new ArgumentException("Public indexer not found"); + } + else + throw new ArgumentException("Invalid expression type"); + } + + while (member != null) + { + var property = (PropertyInfo)member.Member; + if (builder.Length != 0) + { + if (!indexed) + builder.Insert(0, "."); + else + indexed = false; + } + + builder.Insert(0, property.Name); + + // member = member.Expression as MemberExpression ?? (member.Expression as UnaryExpression)?.Operand as MemberExpression; + member = member.Expression as MemberExpression ?? (member.Expression is UnaryExpression ? (member.Expression as UnaryExpression).Operand as MemberExpression : null); + } + + return builder.ToString(); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindingBase.cs b/src/Tizen.NUI/src/public/XamlBinding/BindingBase.cs new file mode 100755 index 000000000..3f6e28df1 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindingBase.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections; +using System.Runtime.CompilerServices; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// + /// An abstract class that provides a BindingMode and a formatting option. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class BindingBase + { + static readonly ConditionalWeakTable SynchronizedCollections = new ConditionalWeakTable(); + + BindingMode _mode = BindingMode.Default; + string _stringFormat; + object _targetNullValue; + object _fallbackValue; + + internal BindingBase() + { + } + + /// + /// Gets or sets the mode for this binding. + /// + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindingMode Mode + { + get { return _mode; } + set + { + if ( value != BindingMode.Default + && value != BindingMode.OneWay + && value != BindingMode.OneWayToSource + && value != BindingMode.TwoWay + && value != BindingMode.OneTime) + throw new ArgumentException("mode is not a valid BindingMode", "mode"); + + ThrowIfApplied(); + + _mode = value; + } + } + + /// + /// Gets or sets the string format for this binding. + /// + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string StringFormat + { + get { return _stringFormat; } + set + { + ThrowIfApplied(); + + _stringFormat = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object TargetNullValue + { + get { return _targetNullValue; } + set { + ThrowIfApplied(); + _targetNullValue = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object FallbackValue { + get => _fallbackValue; + set { + ThrowIfApplied(); + _fallbackValue = value; + } + } + + internal bool AllowChaining { get; set; } + + internal object Context { get; set; } + + internal bool IsApplied { get; private set; } + + /// + /// Stops synchronization on the collection. + /// + /// The collection on which to stop synchronization. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static void DisableCollectionSynchronization(IEnumerable collection) + { + if (collection == null) + throw new ArgumentNullException(nameof(collection)); + + SynchronizedCollections.Remove(collection); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static void EnableCollectionSynchronization(IEnumerable collection, object context, CollectionSynchronizationCallback callback) + { + if (collection == null) + throw new ArgumentNullException(nameof(collection)); + if (callback == null) + throw new ArgumentNullException(nameof(callback)); + + SynchronizedCollections.Add(collection, new CollectionSynchronizationContext(context, callback)); + } + + /// + /// Throws an InvalidOperationException if the binding has been applied. + /// + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected void ThrowIfApplied() + { + if (IsApplied) + throw new InvalidOperationException("Can not change a binding while it's applied"); + } + + internal virtual void Apply(bool fromTarget) + { + IsApplied = true; + } + + internal virtual void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false) + { + IsApplied = true; + } + + internal abstract BindingBase Clone(); + + internal virtual object GetSourceValue(object value, Type targetPropertyType) + { + if (value == null && TargetNullValue != null) + return TargetNullValue; + if (StringFormat != null) + return string.Format(StringFormat, value); + + return value; + } + + internal virtual object GetTargetValue(object value, Type sourcePropertyType) + { + return value; + } + + internal static bool TryGetSynchronizedCollection(IEnumerable collection, out CollectionSynchronizationContext synchronizationContext) + { + if (collection == null) + throw new ArgumentNullException(nameof(collection)); + + return SynchronizedCollections.TryGetValue(collection, out synchronizationContext); + } + + internal virtual void Unapply(bool fromBindingContextChanged = false) + { + IsApplied = false; + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindingMode.cs b/src/Tizen.NUI/src/public/XamlBinding/BindingMode.cs new file mode 100755 index 000000000..bf1ff9ab9 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindingMode.cs @@ -0,0 +1,36 @@ +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// + /// The direction of changes propagation for bindings. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum BindingMode + { + /// + /// When used in Bindings, indicates that the Binding should use the DefaultBindingMode. When used in BindableProperty declaration, defaults to BindingMode.OneWay. + /// + Default, + + /// + /// Indicates that the binding should propagates changes from source (usually the View Model) to target (the BindableObject) in both directions. + /// + TwoWay, + + /// + /// Indicates that the binding should only propagate changes from source (usually the View Model) to target (the BindableObject). This is the default mode for most BindableProperty values. + /// + OneWay, + + /// + /// Indicates that the binding should only propagate changes from target (the BindableObject) to source (usually the View Model). This is mainly used for read-only BindableProperty values. + /// + OneWayToSource, + + /// + /// Indicates that the binding will be applied only when the binding context changes and the value will not be monitored for changes with INotifyPropertyChanged. + /// + OneTime, + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/BindingTypeConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/BindingTypeConverter.cs new file mode 100755 index 000000000..984501c5d --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/BindingTypeConverter.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.BindingTypeConverter")] + [TypeConversion(typeof(Binding))] + public sealed class BindingTypeConverter : TypeConverter + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override object ConvertFromInvariantString(string value) + { + return new Binding(value); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/CollectionSynchronizationCallback.cs b/src/Tizen.NUI/src/public/XamlBinding/CollectionSynchronizationCallback.cs new file mode 100755 index 000000000..e85593eec --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/CollectionSynchronizationCallback.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public delegate void CollectionSynchronizationCallback(IEnumerable collection, object context, Action accessMethod, bool writeAccess); +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/ColorTypeConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/ColorTypeConverter.cs new file mode 100755 index 000000000..92d786da1 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/ColorTypeConverter.cs @@ -0,0 +1,139 @@ +using System; +using System.ComponentModel; +using System.Globalization; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.ColorTypeConverter")] + [TypeConversion(typeof(Color))] + public class ColorTypeConverter : TypeConverter + { + // Supported inputs + // HEX #rgb, #argb, #rrggbb, #aarrggbb + // float array 0.5,0.5,0.5,0.5 + // Predefined color case insensitive + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + value = value.Trim(); + if (value.StartsWith("#", StringComparison.Ordinal)) + { + return FromHex(value); + } + + string[] parts = value.Split(','); + if (parts.Length == 1) //like Red or Color.Red + { + parts = value.Split('.'); + if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "Color")) + { + string color = parts[parts.Length - 1]; + switch (color) + { + case "Black": return Color.Black; + case "White": return Color.White; + case "Red": return Color.Red; + case "Green": return Color.Green; + case "Blue": return Color.Blue; + case "Yellow": return Color.Yellow; + case "Magenta": return Color.Magenta; + case "Cyan": return Color.Cyan; + case "Transparent": return Color.Transparent; + } + } + } + else if (parts.Length == 4) //like 0.5,0.5,0.5,0.5 + { + return new Color(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture), + Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture)); + } + } + + throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Color)}"); + } + + static uint ToHex(char c) + { + ushort x = (ushort)c; + if (x >= '0' && x <= '9') + return (uint)(x - '0'); + + x |= 0x20; + if (x >= 'a' && x <= 'f') + return (uint)(x - 'a' + 10); + return 0; + } + + static uint ToHexD(char c) + { + var j = ToHex(c); + return (j << 4) | j; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static Color FromRgba(int r, int g, int b, int a) + { + float red = (float)r / 255; + float green = (float)g / 255; + float blue = (float)b / 255; + float alpha = (float)a / 255; + return new Color(red, green, blue, alpha); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static Color FromRgb(int r, int g, int b) + { + return FromRgba(r, g, b, 255); + } + + static Color FromHex(string hex) + { + // Undefined + if (hex.Length < 3) + return Color.Black; + int idx = (hex[0] == '#') ? 1 : 0; + + switch (hex.Length - idx) + { + case 3: //#rgb => ffrrggbb + var t1 = ToHexD(hex[idx++]); + var t2 = ToHexD(hex[idx++]); + var t3 = ToHexD(hex[idx]); + + return FromRgb((int)t1, (int)t2, (int)t3); + + case 4: //#argb => aarrggbb + var f1 = ToHexD(hex[idx++]); + var f2 = ToHexD(hex[idx++]); + var f3 = ToHexD(hex[idx++]); + var f4 = ToHexD(hex[idx]); + return FromRgba((int)f2, (int)f3, (int)f4, (int)f1); + + case 6: //#rrggbb => ffrrggbb + return FromRgb((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), + (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), + (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx]))); + + case 8: //#aarrggbb + var a1 = ToHex(hex[idx++]) << 4 | ToHex(hex[idx++]); + return FromRgba((int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), + (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx++])), + (int)(ToHex(hex[idx++]) << 4 | ToHex(hex[idx])), + (int)a1); + + default: //everything else will result in unexpected results + return Color.Black; + } + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Element.cs b/src/Tizen.NUI/src/public/XamlBinding/Element.cs index 59a9cda07..5e868ee97 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/Element.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/Element.cs @@ -15,19 +15,6 @@ namespace Tizen.NUI.Binding [EditorBrowsable(EditorBrowsableState.Never)] public abstract partial class Element : BindableObject, IElement, INameScope, IElementController { - - // public static readonly BindableProperty MenuProperty = BindableProperty.CreateAttached(nameof(Menu), typeof(Menu), typeof(Element), null); - - // public static Menu GetMenu(BindableObject bindable) - // { - // return (Menu)bindable.GetValue(MenuProperty); - // } - - // public static void SetMenu(BindableObject bindable, Menu menu) - // { - // bindable.SetValue(MenuProperty, menu); - // } - internal static readonly ReadOnlyCollection EmptyChildren = new ReadOnlyCollection(new Element[0]); /// @@ -43,16 +30,10 @@ namespace Tizen.NUI.Binding Dictionary _dynamicResources; - IEffectControlProvider _effectControlProvider; - - TrackableCollection _effects; - Guid? _id; Element _parentOverride; - IPlatform _platform; - string _styleId; /// @@ -82,20 +63,6 @@ namespace Tizen.NUI.Binding set { SetValue(ClassIdProperty, value); } } - internal IList Effects - { - get - { - if (_effects == null) - { - _effects = new TrackableCollection(); - _effects.CollectionChanged += EffectsOnCollectionChanged; - _effects.Clearing += EffectsOnClearing; - } - return _effects; - } - } - /// /// Gets a value that can be used to uniquely identify an element through the run of an application. /// @@ -182,31 +149,6 @@ namespace Tizen.NUI.Binding } } - /// - /// For internal use. - /// - internal IPlatform Platform - { - get - { - if (_platform == null && RealParent != null) - return RealParent.Platform; - return _platform; - } - set - { - if (_platform == value) - return; - _platform = value; - PlatformSet?.Invoke(this, EventArgs.Empty); - foreach (Element descendant in Descendants()) - { - descendant._platform = _platform; - descendant.PlatformSet?.Invoke(this, EventArgs.Empty); - } - } - } - /// /// For internal use. /// @@ -260,13 +202,6 @@ namespace Tizen.NUI.Binding OnParentSet(); - if (RealParent != null) - { - IPlatform platform = RealParent.Platform; - if (platform != null) - Platform = platform; - } - OnPropertyChanged(); } } @@ -278,33 +213,6 @@ namespace Tizen.NUI.Binding _changeHandlers.Remove(onchanged); } - /// - /// For internal use. - /// - internal IEffectControlProvider EffectControlProvider - { - get { return _effectControlProvider; } - set - { - if (_effectControlProvider == value) - return; - if (_effectControlProvider != null && _effects != null) - { - foreach (Effect effect in _effects) - effect?.SendDetached(); - } - _effectControlProvider = value; - if (_effectControlProvider != null && _effects != null) - { - foreach (Effect effect in _effects) - { - if (effect != null) - AttachEffect(effect); - } - } - } - } - //void IElementController.SetValueFromRenderer(BindableProperty property, object value) => SetValueFromRenderer(property, value); /// @@ -327,22 +235,6 @@ namespace Tizen.NUI.Binding SetValueCore(property, value); } - /// - /// For internal use. - /// - /// The nameof the effect - /// true if attached - [EditorBrowsable(EditorBrowsableState.Never)] - public bool EffectIsAttached(string name) - { - foreach (var effect in Effects) - { - if (effect.ResolveId == name) - return true; - } - return false; - } - object INameScope.FindByName(string name) { INameScope namescope = GetNameScope(); @@ -449,8 +341,6 @@ namespace Tizen.NUI.Binding protected virtual void OnChildAdded(Element child) { child.Parent = this; - if (Platform != null) - child.Platform = Platform; child.ApplyBindings(skipBindingContext: false, fromBindingContextChanged:true); @@ -498,15 +388,6 @@ namespace Tizen.NUI.Binding protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { base.OnPropertyChanged(propertyName); - - if (_effects == null || _effects.Count == 0) - return; - - var args = new PropertyChangedEventArgs(propertyName); - foreach (Effect effect in _effects) - { - effect?.SendOnElementPropertyChanged(args); - } } /// @@ -615,12 +496,6 @@ namespace Tizen.NUI.Binding { } - /// - /// For internal use. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler PlatformSet; - internal virtual void SetChildInheritedBindingContext(Element child, object context) { SetInheritedBindingContext(child, context); @@ -647,78 +522,6 @@ namespace Tizen.NUI.Binding } } - void AttachEffect(Effect effect) - { - if (_effectControlProvider == null) - return; - if (effect.IsAttached) - throw new InvalidOperationException("Cannot attach Effect to multiple sources"); - - Effect effectToRegister = effect; - if (effect is RoutingEffect) - effectToRegister = ((RoutingEffect)effect).Inner; - _effectControlProvider.RegisterEffect(effectToRegister); - effectToRegister.Element = this; - effect.SendAttached(); - } - - void EffectsOnClearing(object sender, EventArgs eventArgs) - { - foreach (Effect effect in _effects) - { - effect?.ClearEffect(); - } - } - - void EffectsOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - switch (e.Action) - { - case NotifyCollectionChangedAction.Add: - foreach (Effect effect in e.NewItems) - { - AttachEffect(effect); - } - break; - case NotifyCollectionChangedAction.Move: - break; - case NotifyCollectionChangedAction.Remove: - foreach (Effect effect in e.OldItems) - { - effect.ClearEffect(); - } - break; - case NotifyCollectionChangedAction.Replace: - foreach (Effect effect in e.NewItems) - { - AttachEffect(effect); - } - foreach (Effect effect in e.OldItems) - { - effect.ClearEffect(); - } - break; - case NotifyCollectionChangedAction.Reset: - if (e.NewItems != null) - { - foreach (Effect effect in e.NewItems) - { - AttachEffect(effect); - } - } - if (e.OldItems != null) - { - foreach (Effect effect in e.OldItems) - { - effect.ClearEffect(); - } - } - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - INameScope GetNameScope() { INameScope namescope = NameScope.GetNameScope(this); diff --git a/src/Tizen.NUI/src/public/XamlBinding/ElementEventArgs.cs b/src/Tizen.NUI/src/public/XamlBinding/ElementEventArgs.cs new file mode 100755 index 000000000..35af51c5d --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/ElementEventArgs.cs @@ -0,0 +1,24 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class ElementEventArgs : EventArgs + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public ElementEventArgs(Element element) + { + if (element == null) + throw new ArgumentNullException("element"); + + Element = element; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Element Element { get; private set; } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/IRegisterable.cs b/src/Tizen.NUI/src/public/XamlBinding/IRegisterable.cs new file mode 100755 index 000000000..ab41c611b --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/IRegisterable.cs @@ -0,0 +1,10 @@ +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IRegisterable + { + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/Behavior.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/Behavior.cs new file mode 100755 index 000000000..a1a44c31c --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/Behavior.cs @@ -0,0 +1,87 @@ +using System; +using System.ComponentModel; +using System.Reflection; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class Behavior : BindableObject, IAttachedObject + { + internal Behavior(Type associatedType) + { + if (associatedType == null) + throw new ArgumentNullException("associatedType"); + AssociatedType = associatedType; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected Type AssociatedType { get; } + + void IAttachedObject.AttachTo(BindableObject bindable) + { + if (bindable == null) + throw new ArgumentNullException("bindable"); + if (!AssociatedType.IsInstanceOfType(bindable)) + throw new InvalidOperationException("bindable not an instance of AssociatedType"); + OnAttachedTo(bindable); + } + + void IAttachedObject.DetachFrom(BindableObject bindable) + { + OnDetachingFrom(bindable); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected virtual void OnAttachedTo(BindableObject bindable) + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected virtual void OnDetachingFrom(BindableObject bindable) + { + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class Behavior : Behavior where T : BindableObject + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected Behavior() : base(typeof(T)) + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void OnAttachedTo(BindableObject bindable) + { + base.OnAttachedTo(bindable); + OnAttachedTo((T)bindable); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected virtual void OnAttachedTo(T bindable) + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void OnDetachingFrom(BindableObject bindable) + { + OnDetachingFrom((T)bindable); + base.OnDetachingFrom(bindable); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected virtual void OnDetachingFrom(T bindable) + { + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/BindingCondition.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/BindingCondition.cs new file mode 100755 index 000000000..279d374a8 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/BindingCondition.cs @@ -0,0 +1,107 @@ +using System; +using System.ComponentModel; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] + [AcceptEmptyServiceProvider] + public sealed class BindingCondition : Condition, IValueProvider + { + readonly BindableProperty _boundProperty; + + BindingBase _binding; + object _triggerValue; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindingCondition() + { + _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindingBase Binding + { + get { return _binding; } + set + { + if (_binding == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Binding once the Condition has been applied."); + _binding = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Value + { + get { return _triggerValue; } + set + { + if (_triggerValue == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Value once the Condition has been applied."); + _triggerValue = value; + } + } + + object IValueProvider.ProvideValue(IServiceProvider serviceProvider) + { + //This is no longer required + return this; + } + + internal override bool GetState(BindableObject bindable) + { + object newValue = bindable.GetValue(_boundProperty); + return EqualsToValue(newValue); + } + + internal override void SetUp(BindableObject bindable) + { + if (Binding != null) + bindable.SetBinding(_boundProperty, Binding.Clone()); + } + + internal override void TearDown(BindableObject bindable) + { + bindable.RemoveBinding(_boundProperty); + bindable.ClearValue(_boundProperty); + } + + static IValueConverterProvider s_valueConverter = DependencyService.Get(); + + bool EqualsToValue(object other) + { + if ((other == Value) || (other != null && other.Equals(Value))) + return true; + + object converted = null; + if (s_valueConverter != null) + converted = s_valueConverter.Convert(Value, other != null ? other.GetType() : typeof(object), null, null); + else + return false; + + return (other == converted) || (other != null && other.Equals(converted)); + } + + void OnBoundPropertyChanged(BindableObject bindable, object oldValue, object newValue) + { + bool oldState = EqualsToValue(oldValue); + bool newState = EqualsToValue(newValue); + + if (newState == oldState) + return; + + if (ConditionChanged != null) + ConditionChanged(bindable, oldState, newState); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/Condition.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/Condition.cs new file mode 100755 index 000000000..0d4ece0ea --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/Condition.cs @@ -0,0 +1,54 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class Condition + { + Action _conditionChanged; + + bool _isSealed; + + internal Condition() + { + } + + internal Action ConditionChanged + { + get { return _conditionChanged; } + set + { + if (_conditionChanged == value) + return; + if (_conditionChanged != null) + throw new InvalidOperationException("The same condition instance can not be reused"); + _conditionChanged = value; + } + } + + internal bool IsSealed + { + get { return _isSealed; } + set + { + if (_isSealed == value) + return; + if (!value) + throw new InvalidOperationException("What is sealed can not be unsealed."); + _isSealed = value; + OnSealed(); + } + } + + internal abstract bool GetState(BindableObject bindable); + + internal virtual void OnSealed() + { + } + + internal abstract void SetUp(BindableObject bindable); + internal abstract void TearDown(BindableObject bindable); + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/DataTrigger.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/DataTrigger.cs new file mode 100755 index 000000000..526b526cb --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/DataTrigger.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Setters")] + [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] + [AcceptEmptyServiceProvider] + public sealed class DataTrigger : TriggerBase, IValueProvider + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DataTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new BindingCondition(), targetType) + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindingBase Binding + { + get { return ((BindingCondition)Condition).Binding; } + set + { + if (((BindingCondition)Condition).Binding == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Binding once the Trigger has been applied."); + OnPropertyChanging(); + ((BindingCondition)Condition).Binding = value; + OnPropertyChanged(); + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public new IList Setters + { + get { return base.Setters; } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Value + { + get { return ((BindingCondition)Condition).Value; } + set + { + if (((BindingCondition)Condition).Value == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); + OnPropertyChanging(); + ((BindingCondition)Condition).Value = value; + OnPropertyChanged(); + } + } + + object IValueProvider.ProvideValue(IServiceProvider serviceProvider) + { + //This is no longer required + return this; + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/EventTrigger.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/EventTrigger.cs new file mode 100755 index 000000000..e8b37b8ef --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/EventTrigger.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using Tizen.NUI.Binding.Internals; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Actions")] + public sealed class EventTrigger : TriggerBase + { + static readonly MethodInfo s_handlerinfo = typeof(EventTrigger).GetRuntimeMethods().Single(mi => mi.Name == "OnEventTriggered" && mi.IsPublic == false); + readonly List _associatedObjects = new List(); + + EventInfo _eventinfo; + + string _eventname; + Delegate _handlerdelegate; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public EventTrigger() : base(typeof(BindableObject)) + { + Actions = new SealedList(); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList Actions { get; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Event + { + get { return _eventname; } + set + { + if (_eventname == value) + return; + if (IsSealed) + throw new InvalidOperationException("Event cannot be changed once the Trigger has been applied"); + OnPropertyChanging(); + _eventname = value; + OnPropertyChanged(); + } + } + + internal override void OnAttachedTo(BindableObject bindable) + { + base.OnAttachedTo(bindable); + if (!string.IsNullOrEmpty(Event)) + AttachHandlerTo(bindable); + _associatedObjects.Add(bindable); + } + + internal override void OnDetachingFrom(BindableObject bindable) + { + _associatedObjects.Remove(bindable); + DetachHandlerFrom(bindable); + base.OnDetachingFrom(bindable); + } + + internal override void OnSeal() + { + base.OnSeal(); + ((SealedList)Actions).IsReadOnly = true; + } + + void AttachHandlerTo(BindableObject bindable) + { + try + { + _eventinfo = bindable.GetType().GetRuntimeEvent(Event); + _handlerdelegate = s_handlerinfo.CreateDelegate(_eventinfo?.EventHandlerType, this); + } + catch (Exception) + { + Console.WriteLine("EventTrigger", "Can not attach EventTrigger to {0}.{1}. Check if the handler exists and if the signature is right.", bindable.GetType(), Event); + } + if (_eventinfo != null && _handlerdelegate != null) + _eventinfo.AddEventHandler(bindable, _handlerdelegate); + } + + void DetachHandlerFrom(BindableObject bindable) + { + if (_eventinfo != null && _handlerdelegate != null) + _eventinfo.RemoveEventHandler(bindable, _handlerdelegate); + } + + // [Preserve] + void OnEventTriggered(object sender, EventArgs e) + { + var bindable = (BindableObject)sender; + foreach (TriggerAction action in Actions) + action.DoInvoke(bindable); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/MultiTrigger.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/MultiTrigger.cs new file mode 100755 index 000000000..928c8f544 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/MultiTrigger.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Setters")] + public sealed class MultiTrigger : TriggerBase + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public MultiTrigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new MultiCondition(), targetType) + { + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList Conditions + { + get { return ((MultiCondition)Condition).Conditions; } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public new IList Setters + { + get { return base.Setters; } + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Interactivity/XamlPropertyCondition.cs b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/XamlPropertyCondition.cs new file mode 100755 index 000000000..eac49d01a --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Interactivity/XamlPropertyCondition.cs @@ -0,0 +1,124 @@ +using System; +using System.ComponentModel; +using System.Reflection; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiled("Tizen.NUI.Core.XamlC.PassthroughValueProvider")] + [AcceptEmptyServiceProvider] + public sealed class XamlPropertyCondition : Condition, IValueProvider + { + readonly BindableProperty _stateProperty; + + BindableProperty _property; + object _triggerValue; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public XamlPropertyCondition() + { + _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(XamlPropertyCondition), false, propertyChanged: OnStatePropertyChanged); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindableProperty Property + { + get { return _property; } + set + { + if (_property == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Property once the Trigger has been applied."); + _property = value; + + //convert the value + if (_property != null && s_valueConverter != null) + { + Func minforetriever = () => _property.DeclaringType.GetRuntimeProperty(_property.PropertyName); + Value = s_valueConverter.Convert(Value, _property.ReturnType, minforetriever, null); + } + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Value + { + get { return _triggerValue; } + set + { + if (_triggerValue == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); + + //convert the value + if (_property != null && s_valueConverter != null) + { + Func minforetriever = () => _property.DeclaringType.GetRuntimeProperty(_property.PropertyName); + _triggerValue = s_valueConverter.Convert(value, _property.ReturnType, minforetriever, null); + } + else + { + _triggerValue = value; + } + + } + } + + object IValueProvider.ProvideValue(IServiceProvider serviceProvider) + { + //This is no longer required + return this; + } + + internal override bool GetState(BindableObject bindable) + { + return (bool)bindable.GetValue(_stateProperty); + } + + static IValueConverterProvider s_valueConverter = DependencyService.Get(); + + internal override void SetUp(BindableObject bindable) + { + object newvalue = bindable.GetValue(Property); + bool newState = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); + bindable.SetValue(_stateProperty, newState); + bindable.PropertyChanged += OnAttachedObjectPropertyChanged; + } + + internal override void TearDown(BindableObject bindable) + { + bindable.ClearValue(_stateProperty); + bindable.PropertyChanged -= OnAttachedObjectPropertyChanged; + } + + void OnAttachedObjectPropertyChanged(object sender, PropertyChangedEventArgs e) + { + var bindable = (BindableObject)sender; + var oldState = (bool)bindable.GetValue(_stateProperty); + + if (Property == null) + return; + if (e.PropertyName != Property.PropertyName) + return; + object newvalue = bindable.GetValue(Property); + bool newstate = (newvalue == Value) || (newvalue != null && newvalue.Equals(Value)); + if (oldState != newstate) + bindable.SetValue(_stateProperty, newstate); + } + + void OnStatePropertyChanged(BindableObject bindable, object oldValue, object newValue) + { + if ((bool)oldValue == (bool)newValue) + return; + + ConditionChanged?.Invoke(bindable, (bool)oldValue, (bool)newValue); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Internals/DynamicResource.cs b/src/Tizen.NUI/src/public/XamlBinding/Internals/DynamicResource.cs new file mode 100755 index 000000000..5e317abf0 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Internals/DynamicResource.cs @@ -0,0 +1,20 @@ +using System.ComponentModel; + +namespace Tizen.NUI.Binding.Internals +{ + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class DynamicResource + { + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public DynamicResource(string key) + { + Key = key; + } + + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Key { get; private set; } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Internals/IDynamicResourceHandler.cs b/src/Tizen.NUI/src/public/XamlBinding/Internals/IDynamicResourceHandler.cs new file mode 100755 index 000000000..8916eae02 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Internals/IDynamicResourceHandler.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Binding.Internals +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IDynamicResourceHandler + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + void SetDynamicResource(BindableProperty property, string key); + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Internals/INameScope.cs b/src/Tizen.NUI/src/public/XamlBinding/Internals/INameScope.cs new file mode 100755 index 000000000..d224f473c --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Internals/INameScope.cs @@ -0,0 +1,27 @@ +using System; +using System.ComponentModel; +using System.Xml; + +namespace Tizen.NUI.Binding.Internals +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface INameScope + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + object FindByName(string name); + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + void RegisterName(string name, object scopedElement); + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + void UnregisterName(string name); + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete]void RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo); + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Internals/NameScope.cs b/src/Tizen.NUI/src/public/XamlBinding/Internals/NameScope.cs new file mode 100755 index 000000000..f6d57b32d --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Internals/NameScope.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Xml; +using Tizen.NUI.Binding; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding.Internals +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class NameScope : INameScope + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly BindableProperty NameScopeProperty = BindableProperty.CreateAttached("NameScope", typeof(INameScope), typeof(NameScope), default(INameScope)); + + readonly Dictionary _names = new Dictionary(); + + object INameScope.FindByName(string name) + { + if (_names.ContainsKey(name)) + return _names[name]; + return null; + } + + void INameScope.RegisterName(string name, object scopedElement) + { + if (_names.ContainsKey(name)) + throw new ArgumentException("An element with the same key already exists in NameScope", "name"); + + _names[name] = scopedElement; + } + + [Obsolete] + void INameScope.RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo) + { + try + { + ((INameScope)this).RegisterName(name, scopedElement); + } + catch (ArgumentException) + { + throw new XamlParseException(string.Format("An element with the name \"{0}\" already exists in this NameScope", name), xmlLineInfo); + } + } + + void INameScope.UnregisterName(string name) + { + _names.Remove(name); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static INameScope GetNameScope(BindableObject bindable) + { + return (INameScope)bindable.GetValue(NameScopeProperty); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static void SetNameScope(BindableObject bindable, INameScope value) + { + bindable.SetValue(NameScopeProperty, value); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Page.cs b/src/Tizen.NUI/src/public/XamlBinding/Page.cs index c11ca0318..a4134c1df 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/Page.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/Page.cs @@ -32,7 +32,7 @@ namespace Tizen.NUI /// // [RenderWith(typeof(_PageRenderer))] [EditorBrowsable(EditorBrowsableState.Never)] - public class Page : /*VisualElement*/BaseHandle, ILayout, IPageController, IElementConfiguration, IPaddingElement + public class Page : BaseHandle, IPageController, IElementConfiguration { /// /// For internal use. @@ -57,37 +57,13 @@ namespace Tizen.NUI internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create("IgnoresContainerArea", typeof(bool), typeof(Page), false); - /// - /// Identifies the BackgroundImage property. - /// - internal static readonly BindableProperty BackgroundImageProperty = BindableProperty.Create("BackgroundImage", typeof(string), typeof(Page), default(string)); - /// /// Identifies the IsBusy property. /// internal static readonly BindableProperty IsBusyProperty = BindableProperty.Create("IsBusy", typeof(bool), typeof(Page), false, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged()); - /// - /// Identifies the Padding property. - /// - internal static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty; - - /// - /// Identifies the Title property. - /// - internal static readonly BindableProperty TitleProperty = BindableProperty.Create("Title", typeof(string), typeof(Page), null); - - /// - /// Identifies the Icon property. - /// - internal static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(FileImageSource), typeof(Page), default(FileImageSource)); - - readonly Lazy> _platformConfigurationRegistry; - Rectangle _containerArea; - bool _containerAreaSet; - bool _hasAppeared; ReadOnlyCollection _logicalChildren; @@ -99,28 +75,8 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public Page() { - var toolbarItems = new ObservableCollection(); - toolbarItems.CollectionChanged += OnToolbarItemsCollectionChanged; // ToolbarItems = toolbarItems; InternalChildren.CollectionChanged += InternalChildrenOnCollectionChanged; - _platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); - } - - /// - /// Identifies the image used as a background for the Page. - /// - /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string BackgroundImage - { - get { return (string)GetValue(BackgroundImageProperty); } - set { SetValue(BackgroundImageProperty, value); } - } - - internal FileImageSource Icon - { - get { return (FileImageSource)GetValue(IconProperty); } - set { SetValue(IconProperty, value); } } /// @@ -134,38 +90,6 @@ namespace Tizen.NUI set { SetValue(IsBusyProperty, value); } } - /// - /// The space between the content of the Page and it's border. - /// - internal Thickness Padding - { - get { return (Thickness)GetValue(PaddingElement.PaddingProperty); } - set { SetValue(PaddingElement.PaddingProperty, value); } - } - - Thickness IPaddingElement.PaddingDefaultValueCreator() - { - return default(Thickness); - } - - void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) - { - UpdateChildrenLayout(); - } - - /// - /// The Page's title. - /// - /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string Title - { - get { return (string)GetValue(TitleProperty); } - set { SetValue(TitleProperty, value); } - } - - internal IList ToolbarItems { get;/* internal set;*/ } - /// /// For internal use. /// @@ -177,7 +101,7 @@ namespace Tizen.NUI { if (_containerArea == value) return; - _containerAreaSet = true; + _containerArea = value; ForceLayout(); } @@ -202,13 +126,6 @@ namespace Tizen.NUI internal override ReadOnlyCollection LogicalChildrenInternal => _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection(InternalChildren)); - /// - /// Raised when the layout of the Page has changed. - /// - /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler LayoutChanged; - /// /// ndicates that the Page is about to appear. /// @@ -294,31 +211,6 @@ namespace Tizen.NUI return OnBackButtonPressed(); } - /// - /// Lays out children Elements into the specified area. - /// - /// Left-hand side of layout area. - /// Top of layout area. - /// Width of layout area. - /// Height of layout area. - /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected virtual void LayoutChildren(double x, double y, double width, double height) - { - var area = new Rectangle((int)x, (int)y, (int)width, (int)height); - Rectangle originalArea = area; - if (_containerAreaSet) - { - area = ContainerArea; - area.X += (int)Padding.Left; - area.Y += (int)Padding.Right; - area.Width -= (int)Padding.HorizontalThickness; - area.Height -= (int)Padding.VerticalThickness; - area.Width = Math.Max(0, area.Width); - area.Height = Math.Max(0, area.Height); - } - } - /// /// When overridden, allows application developers to customize behavior immediately prior to the Page becoming visible. /// @@ -340,7 +232,6 @@ namespace Tizen.NUI var canceled = false; EventHandler handler = (sender, args) => { canceled = true; }; - Navigation.PopModalAsync().ContinueWith(t => { throw t.Exception; }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()); return !canceled; } @@ -387,25 +278,6 @@ namespace Tizen.NUI base.OnParentSet(); } - /// - /// Requests that the children Elements of the Page update their layouts. - /// - /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - protected void UpdateChildrenLayout() - { - if (!ShouldLayoutChildren()) - return; - - double x = Padding.Left; - double y = Padding.Top; - - for (var i = 0; i < LogicalChildren.Count; i++) - { - LayoutChanged?.Invoke(this, EventArgs.Empty); - } - } - internal virtual void OnChildMeasureInvalidated(BaseHandle child, InvalidationTrigger trigger) { var container = this as IPageContainer; @@ -550,15 +422,5 @@ namespace Tizen.NUI } return !any; } - - /// - /// Returns the platform-specific instance of this Page, on which a platform-specific method may be called. - /// - /// The platform for which to return an instance. - /// The platform-specific instance of this Page - internal IPlatformElementConfiguration On() where T : IConfigPlatform - { - return _platformConfigurationRegistry.Value.On(); - } } } \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/Registrar.cs b/src/Tizen.NUI/src/public/XamlBinding/Registrar.cs new file mode 100755 index 000000000..5518b42dd --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Registrar.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Binding.Internals +{ + /// + /// For internal use. + /// + /// + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public class Registrar where TRegistrable : class + { + readonly Dictionary _handlers = new Dictionary(); + + /// + /// Register. + /// + /// The type of the view + /// The type of the render. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void Register(Type tview, Type trender) + { + //avoid caching null renderers + if (trender == null) + return; + _handlers[tview] = trender; + } + + internal TRegistrable GetHandler(Type type) + { + Type handlerType = GetHandlerType(type); + if (handlerType == null) + return null; + + object handler = DependencyResolver.ResolveOrCreate(handlerType); + + return (TRegistrable)handler; + } + + internal TRegistrable GetHandler(Type type, params object[] args) + { + if (args.Length == 0) + { + return GetHandler(type); + } + + Type handlerType = GetHandlerType(type); + if (handlerType == null) + return null; + + return (TRegistrable)DependencyResolver.ResolveOrCreate(handlerType, args); + } + + /// + /// For internal use. Returns handler. + /// + /// The type of the handler + /// The type. + /// The handler instance. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TOut GetHandler(Type type) where TOut : TRegistrable + { + return (TOut)GetHandler(type); + } + + /// + /// For internal use. Returns handler. + /// + /// The type of the handler + /// The type. + /// The args of the type + /// The handler instance. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TOut GetHandler(Type type, params object[] args) where TOut : TRegistrable + { + return (TOut)GetHandler(type, args); + } + + /// + /// For internal use. Return the handler of the object. + /// + /// Thetype + /// The object instance. + /// The handle of the obj. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TOut GetHandlerForObject(object obj) where TOut : TRegistrable + { + if (obj == null) + throw new ArgumentNullException(nameof(obj)); + + var reflectableType = obj as IReflectableType; + var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType(); + + return (TOut)GetHandler(type); + } + + /// + /// For inetrnal use. Return the handler of the object. + /// + /// The type + /// The object instance + /// The args of the type + /// The handler of the object. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public TOut GetHandlerForObject(object obj, params object[] args) where TOut : TRegistrable + { + if (obj == null) + throw new ArgumentNullException(nameof(obj)); + + var reflectableType = obj as IReflectableType; + var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType(); + + return (TOut)GetHandler(type, args); + } + + /// + /// For internal use. Returns the handle type. + /// + /// The view type. + /// The type of the handle. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type GetHandlerType(Type viewType) + { + Type type; + if (LookupHandlerType(viewType, out type)) + return type; + + // lazy load render-view association with RenderWithAttribute (as opposed to using ExportRenderer) + var attribute = viewType.GetTypeInfo().GetCustomAttribute(); + if (attribute == null) + { + Register(viewType, null); // Cache this result so we don't have to do GetCustomAttribute again + return null; + } + + type = attribute.Type; + + if (type.Name.StartsWith("_", StringComparison.Ordinal)) + { + // TODO: Remove attribute2 once renderer names have been unified across all platforms + var attribute2 = type.GetTypeInfo().GetCustomAttribute(); + if (attribute2 != null) + type = attribute2.Type; + + if (type.Name.StartsWith("_", StringComparison.Ordinal)) + { + Register(viewType, null); // Cache this result so we don't work through this chain again + return null; + } + } + + Register(viewType, type); // Register this so we don't have to look for the RenderWith Attibute again in the future + + return type; + } + + /// + /// For internal use. Return the handle type of the object + /// + /// The object instance. + /// The type of the handler. + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type GetHandlerTypeForObject(object obj) + { + if (obj == null) + throw new ArgumentNullException(nameof(obj)); + + var reflectableType = obj as IReflectableType; + var type = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : obj.GetType(); + + return GetHandlerType(type); + } + + bool LookupHandlerType(Type viewType, out Type handlerType) + { + Type type = viewType; + + while (type != null) + { + if (_handlers.ContainsKey(type)) + { + handlerType = _handlers[type]; + return true; + } + + type = type.GetTypeInfo().BaseType; + } + + handlerType = null; + return false; + } + } + + /// + /// For internal use + /// + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static class Registrar + { + static Registrar() + { + Registered = new Registrar(); + } + + internal static Dictionary Effects { get; } = new Dictionary(); + internal static Dictionary StyleProperties { get; } = new Dictionary(); + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static IEnumerable ExtraAssemblies { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public static Registrar Registered { get; internal set; } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Setter.cs b/src/Tizen.NUI/src/public/XamlBinding/Setter.cs new file mode 100755 index 000000000..569298467 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Setter.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Xml; +using Tizen.NUI.Binding.Internals; +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Value")] + [ProvideCompiled("Tizen.NUI.Core.XamlC.SetterValueProvider")] + public sealed class Setter : IValueProvider + { + readonly ConditionalWeakTable _originalValues = new ConditionalWeakTable(); + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindableProperty Property { get; set; } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Value { get; set; } + + object IValueProvider.ProvideValue(IServiceProvider serviceProvider) + { + if (Property == null) + { + var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider; + IXmlLineInfo lineInfo = lineInfoProvider != null ? lineInfoProvider.XmlLineInfo : new XmlLineInfo(); + throw new XamlParseException("Property not set", lineInfo); + } + var valueconverter = serviceProvider.GetService(typeof(IValueConverterProvider)) as IValueConverterProvider; + + Func minforetriever = + () => + (MemberInfo)Property.DeclaringType.GetRuntimeProperty(Property.PropertyName) ?? (MemberInfo)Property.DeclaringType.GetRuntimeMethod("Get" + Property.PropertyName, new[] { typeof(BindableObject) }); + + object value = valueconverter?.Convert(Value, Property.ReturnType, minforetriever, serviceProvider); + Value = value; + return this; + } + + internal void Apply(BindableObject target, bool fromStyle = false) + { + if (target == null) + throw new ArgumentNullException("target"); + if (Property == null) + return; + + object originalValue = target.GetValue(Property); + if (!Equals(originalValue, Property.DefaultValue)) + { + _originalValues.Remove(target); + _originalValues.Add(target, originalValue); + } + + var dynamicResource = Value as DynamicResource; + var binding = Value as BindingBase; + if (binding != null) + target.SetBinding(Property, binding.Clone(), fromStyle); + else if (dynamicResource != null) + target.SetDynamicResource(Property, dynamicResource.Key, fromStyle); + else + { + if (Value is IList visualStateGroupCollection) + target.SetValue(Property, visualStateGroupCollection.Clone(), fromStyle); + else + target.SetValue(Property, Value, fromStyle); + } + } + + internal void UnApply(BindableObject target, bool fromStyle = false) + { + if (target == null) + throw new ArgumentNullException(nameof(target)); + if (Property == null) + return; + + object actual = target.GetValue(Property); + if (!Equals(actual, Value) && !(Value is Tizen.NUI.Binding.Binding) && !(Value is DynamicResource)) + { + //Do not reset default value if the value has been changed + _originalValues.Remove(target); + return; + } + + object defaultValue; + if (_originalValues.TryGetValue(target, out defaultValue)) + { + //reset default value, unapply bindings and dynamicResource + target.SetValue(Property, defaultValue, fromStyle); + _originalValues.Remove(target); + } + else + target.ClearValue(Property); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/SizeTypeConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/SizeTypeConverter.cs new file mode 100755 index 000000000..68a2db0c4 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/SizeTypeConverter.cs @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Globalization; + +using Tizen.NUI; +using Tizen.NUI.Xaml; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")] + public class SizeTypeConverter : TypeConverter + { + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + string[] parts = value.Split(','); + if (parts.Length == 3) + { + int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim()); + int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim()); + int z = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[2].Trim()); + return new Size(x, y, z); + } + } + + throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size)}"); + } + } + + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.Size2DTypeConverter")] + public class Size2DTypeConverter : TypeConverter + { + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + string[] parts = value.Split(','); + if (parts.Length == 2) + { + int x = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim()); + int y = (int)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim()); + return new Size2D(x, y); + } + } + + throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Size2D)}"); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Style.cs b/src/Tizen.NUI/src/public/XamlBinding/Style.cs new file mode 100755 index 000000000..e5841cb89 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Style.cs @@ -0,0 +1,212 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Tizen.NUI.StyleSheets; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Setters")] + public sealed class Style : IStyle + { + internal const string StyleClassPrefix = "Tizen.NUI.Binding.StyleClass."; + + readonly BindableProperty _basedOnResourceProperty = BindableProperty.CreateAttached("BasedOnResource", typeof(Style), typeof(Style), default(Style), + propertyChanged: OnBasedOnResourceChanged); + + readonly List> _targets = new List>(4); + + Style _basedOnStyle; + + string _baseResourceKey; + + IList _behaviors; + + IList _triggers; + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Style([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) + { + if (targetType == null) + throw new ArgumentNullException("targetType"); + + TargetType = targetType; + Setters = new List(); + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool ApplyToDerivedTypes { get; set; } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Style BasedOn + { + get { return _basedOnStyle; } + set + { + if (_basedOnStyle == value) + return; + if (!ValidateBasedOn(value)) + throw new ArgumentException("BasedOn.TargetType is not compatible with TargetType"); + Style oldValue = _basedOnStyle; + _basedOnStyle = value; + BasedOnChanged(oldValue, value); + if (value != null) + BaseResourceKey = null; + } + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string BaseResourceKey + { + get { return _baseResourceKey; } + set + { + if (_baseResourceKey == value) + return; + _baseResourceKey = value; + //update all DynamicResources + foreach (WeakReference bindableWr in _targets) + { + BindableObject target; + if (!bindableWr.TryGetTarget(out target)) + continue; + target.RemoveDynamicResource(_basedOnResourceProperty); + if (value != null) + target.SetDynamicResource(_basedOnResourceProperty, value); + } + if (value != null) + BasedOn = null; + } + } + + internal IList Behaviors + { + get { return _behaviors ?? (_behaviors = new AttachedCollection()); } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool CanCascade { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public string Class { get; set; } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList Setters { get; } + + /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList Triggers + { + get { return _triggers ?? (_triggers = new AttachedCollection()); } + } + + void IStyle.Apply(BindableObject bindable) + { + _targets.Add(new WeakReference(bindable)); + if (BaseResourceKey != null) + bindable.SetDynamicResource(_basedOnResourceProperty, BaseResourceKey); + ApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable)); + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type TargetType { get; } + + void IStyle.UnApply(BindableObject bindable) + { + UnApplyCore(bindable, BasedOn ?? GetBasedOnResource(bindable)); + bindable.RemoveDynamicResource(_basedOnResourceProperty); + _targets.RemoveAll(wr => + { + BindableObject target; + return wr.TryGetTarget(out target) && target == bindable; + }); + } + + internal bool CanBeAppliedTo(Type targetType) + { + if (TargetType == targetType) + return true; + if (!ApplyToDerivedTypes) + return false; + do + { + targetType = targetType.GetTypeInfo().BaseType; + if (TargetType == targetType) + return true; + } while (targetType != typeof(Element)); + return false; + } + + void ApplyCore(BindableObject bindable, Style basedOn) + { + if (basedOn != null) + ((IStyle)basedOn).Apply(bindable); + + foreach (Setter setter in Setters) + setter.Apply(bindable, true); + ((AttachedCollection)Behaviors).AttachTo(bindable); + ((AttachedCollection)Triggers).AttachTo(bindable); + } + + void BasedOnChanged(Style oldValue, Style newValue) + { + foreach (WeakReference bindableRef in _targets) + { + BindableObject bindable; + if (!bindableRef.TryGetTarget(out bindable)) + continue; + + UnApplyCore(bindable, oldValue); + ApplyCore(bindable, newValue); + } + } + + Style GetBasedOnResource(BindableObject bindable) + { + return (Style)bindable.GetValue(_basedOnResourceProperty); + } + + static void OnBasedOnResourceChanged(BindableObject bindable, object oldValue, object newValue) + { + // Style style = (bindable as /*VisualElement*/BaseHandle).Style; + // if (style == null) + // return; + // style.UnApplyCore(bindable, (Style)oldValue); + // style.ApplyCore(bindable, (Style)newValue); + } + + void UnApplyCore(BindableObject bindable, Style basedOn) + { + ((AttachedCollection)Triggers).DetachFrom(bindable); + ((AttachedCollection)Behaviors).DetachFrom(bindable); + foreach (Setter setter in Setters) + setter.UnApply(bindable, true); + + if (basedOn != null) + ((IStyle)basedOn).UnApply(bindable); + } + + bool ValidateBasedOn(Style value) + { + if (value == null) + return true; + return value.TargetType.IsAssignableFrom(TargetType); + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/Trigger.cs b/src/Tizen.NUI/src/public/XamlBinding/Trigger.cs new file mode 100755 index 000000000..001716158 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/Trigger.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; + +using Tizen.NUI.Xaml; + +namespace Tizen.NUI.Binding +{ + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [ContentProperty("Setters")] + [ProvideCompiled("Tizen.NUI.Xaml.Core.XamlC.PassthroughValueProvider")] + [AcceptEmptyServiceProvider] + public sealed class Trigger : TriggerBase, IValueProvider + { + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Trigger([TypeConverter(typeof(TypeTypeConverter))] [Parameter("TargetType")] Type targetType) : base(new XamlPropertyCondition(), targetType) + { + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public BindableProperty Property + { + get { return ((XamlPropertyCondition)Condition).Property; } + set + { + if (((XamlPropertyCondition)Condition).Property == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Property once the Trigger has been applied."); + OnPropertyChanging(); + ((XamlPropertyCondition)Condition).Property = value; + OnPropertyChanged(); + } + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public new IList Setters + { + get { return base.Setters; } + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Value + { + get { return ((XamlPropertyCondition)Condition).Value; } + set + { + if (((XamlPropertyCondition)Condition).Value == value) + return; + if (IsSealed) + throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); + OnPropertyChanging(); + ((XamlPropertyCondition)Condition).Value = value; + OnPropertyChanged(); + } + } + + object IValueProvider.ProvideValue(IServiceProvider serviceProvider) + { + //This is no longer required + return this; + } + } +} diff --git a/src/Tizen.NUI/src/public/XamlBinding/TriggerAction.cs b/src/Tizen.NUI/src/public/XamlBinding/TriggerAction.cs new file mode 100755 index 000000000..1b5c861e2 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/TriggerAction.cs @@ -0,0 +1,47 @@ +using System; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class TriggerAction + { + internal TriggerAction(Type associatedType) + { + if (associatedType == null) + throw new ArgumentNullException("associatedType"); + AssociatedType = associatedType; + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected Type AssociatedType { get; private set; } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + protected abstract void Invoke(object sender); + + internal virtual void DoInvoke(object sender) + { + Invoke(sender); + } + } + + internal abstract class TriggerAction : TriggerAction where T : BindableObject + { + protected TriggerAction() : base(typeof(T)) + { + } + + protected override void Invoke(object sender) + { + Invoke((T)sender); + } + + protected abstract void Invoke(T sender); + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/TriggerBase.cs b/src/Tizen.NUI/src/public/XamlBinding/TriggerBase.cs new file mode 100755 index 000000000..de86ef770 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/TriggerBase.cs @@ -0,0 +1,229 @@ +using System; +using System.Reflection; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; + +namespace Tizen.NUI.Binding +{ + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class TriggerBase : BindableObject, IAttachedObject + { + bool _isSealed; + + internal TriggerBase(Type targetType) + { + if (targetType == null) + throw new ArgumentNullException("targetType"); + TargetType = targetType; + + EnterActions = new SealedList(); + ExitActions = new SealedList(); + } + + internal TriggerBase(Condition condition, Type targetType) : this(targetType) + { + Setters = new SealedList(); + Condition = condition; + Condition.ConditionChanged = OnConditionChanged; + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList EnterActions { get; } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IList ExitActions { get; } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public bool IsSealed + { + get { return _isSealed; } + private set + { + if (_isSealed == value) + return; + if (!value) + throw new InvalidOperationException("What is sealed can not be unsealed."); + _isSealed = value; + OnSeal(); + } + } + + /// 6 + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public Type TargetType { get; } + + internal Condition Condition { get; } + + //Setters and Condition are used by Trigger, DataTrigger and MultiTrigger + internal IList Setters { get; } + + void IAttachedObject.AttachTo(BindableObject bindable) + { + IsSealed = true; + + if (bindable == null) + throw new ArgumentNullException("bindable"); + if (!TargetType.IsInstanceOfType(bindable)) + throw new InvalidOperationException("bindable not an instance of AssociatedType"); + OnAttachedTo(bindable); + } + + void IAttachedObject.DetachFrom(BindableObject bindable) + { + if (bindable == null) + throw new ArgumentNullException("bindable"); + OnDetachingFrom(bindable); + } + + internal virtual void OnAttachedTo(BindableObject bindable) + { + if (Condition != null) + Condition.SetUp(bindable); + } + + internal virtual void OnDetachingFrom(BindableObject bindable) + { + if (Condition != null) + Condition.TearDown(bindable); + } + + internal virtual void OnSeal() + { + ((SealedList)EnterActions).IsReadOnly = true; + ((SealedList)ExitActions).IsReadOnly = true; + if (Setters != null) + ((SealedList)Setters).IsReadOnly = true; + if (Condition != null) + Condition.IsSealed = true; + } + + void OnConditionChanged(BindableObject bindable, bool oldValue, bool newValue) + { + if (newValue) + { + foreach (TriggerAction action in EnterActions) + action.DoInvoke(bindable); + foreach (Setter setter in Setters) + setter.Apply(bindable); + } + else + { + foreach (Setter setter in Setters) + setter.UnApply(bindable); + foreach (TriggerAction action in ExitActions) + action.DoInvoke(bindable); + } + } + + internal class SealedList : IList + { + readonly IList _actual; + + bool _isReadOnly; + + public SealedList() + { + _actual = new List(); + } + + public void Add(T item) + { + if (IsReadOnly) + throw new InvalidOperationException("This list is ReadOnly"); + _actual.Add(item); + } + + public void Clear() + { + if (IsReadOnly) + throw new InvalidOperationException("This list is ReadOnly"); + _actual.Clear(); + } + + public bool Contains(T item) + { + return _actual.Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + _actual.CopyTo(array, arrayIndex); + } + + public int Count + { + get { return _actual.Count; } + } + + public bool IsReadOnly + { + get { return _isReadOnly; } + set + { + if (_isReadOnly == value) + return; + if (!value) + throw new InvalidOperationException("Can't change this back to non readonly"); + _isReadOnly = value; + } + } + + public bool Remove(T item) + { + if (IsReadOnly) + throw new InvalidOperationException("This list is ReadOnly"); + return _actual.Remove(item); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)_actual).GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return _actual.GetEnumerator(); + } + + public int IndexOf(T item) + { + return _actual.IndexOf(item); + } + + public void Insert(int index, T item) + { + if (IsReadOnly) + throw new InvalidOperationException("This list is ReadOnly"); + _actual.Insert(index, item); + } + + public T this[int index] + { + get { return _actual[index]; } + set + { + if (IsReadOnly) + throw new InvalidOperationException("This list is ReadOnly"); + _actual[index] = value; + } + } + + public void RemoveAt(int index) + { + if (IsReadOnly) + throw new InvalidOperationException("This list is ReadOnly"); + _actual.RemoveAt(index); + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/TypeConverter.cs b/src/Tizen.NUI/src/public/XamlBinding/TypeConverter.cs new file mode 100755 index 000000000..10c6f2512 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/TypeConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel; +using System.Globalization; + +namespace Tizen.NUI.Binding +{ + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class TypeConverter + { + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool CanConvertFrom(Type sourceType) + { + if (sourceType == null) + throw new ArgumentNullException(nameof(sourceType)); + + return sourceType == typeof(string); + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")] + public virtual object ConvertFrom(object o) + { + return null; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("ConvertFrom is obsolete as of version 2.2.0. Please use ConvertFromInvariantString (string) instead.")] + public virtual object ConvertFrom(CultureInfo culture, object o) + { + return null; + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual object ConvertFromInvariantString(string value) + { +#pragma warning disable 0618 // retain until ConvertFrom removed + return ConvertFrom(CultureInfo.InvariantCulture, value); +#pragma warning restore + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs b/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs new file mode 100755 index 000000000..e40db3ce5 --- /dev/null +++ b/src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs @@ -0,0 +1,307 @@ +#define DO_NOT_CHECK_FOR_BINDING_REUSE + +using System; +using System.ComponentModel; +using System.Globalization; +using System.Collections.Generic; +using Tizen.NUI.Binding; + +namespace Tizen.NUI.Binding.Internals +{ + //FIXME: need a better name for this, and share with Binding, so we can share more unittests + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public abstract class TypedBindingBase : BindingBase + { + IValueConverter _converter; + object _converterParameter; + object _source; + string _updateSourceEventName; + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public IValueConverter Converter { + get { return _converter; } + set { + ThrowIfApplied(); + _converter = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object ConverterParameter { + get { return _converterParameter; } + set { + ThrowIfApplied(); + _converterParameter = value; + } + } + + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public object Source { + get { return _source; } + set { + ThrowIfApplied(); + _source = value; + } + } + + internal string UpdateSourceEventName { + get { return _updateSourceEventName; } + set { + ThrowIfApplied(); + _updateSourceEventName = value; + } + } + + internal TypedBindingBase() + { + } + } + + internal sealed class TypedBinding : TypedBindingBase + { + readonly Func _getter; + readonly Action _setter; + readonly PropertyChangedProxy [] _handlers; + + public TypedBinding(Func getter, Action setter, Tuple, string> [] handlers) + { + if (getter == null) + throw new ArgumentNullException(nameof(getter)); + + _getter = getter; + _setter = setter; + + if (handlers == null) + return; + + _handlers = new PropertyChangedProxy [handlers.Length]; + for (var i = 0; i < handlers.Length; i++) + _handlers [i] = new PropertyChangedProxy(handlers [i].Item1, handlers [i].Item2, this); + } + + readonly WeakReference _weakSource = new WeakReference(null); + readonly WeakReference _weakTarget = new WeakReference(null); + BindableProperty _targetProperty; + + // Applies the binding to a previously set source and target. + internal override void Apply(bool fromTarget = false) + { + base.Apply(fromTarget); + + BindableObject target; +#if DO_NOT_CHECK_FOR_BINDING_REUSE + if (!_weakTarget.TryGetTarget(out target)) + throw new InvalidOperationException(); +#else + if (!_weakTarget.TryGetTarget(out target) || target == null) { + Unapply(); + return; + } +#endif + object source; + if (_weakSource.TryGetTarget(out source) && source != null) + ApplyCore(source, target, _targetProperty, fromTarget); + } + + // Applies the binding to a new source or target. + internal override void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false) + { + _targetProperty = targetProperty; + var source = Source ?? Context ?? context; + var isApplied = IsApplied; + + if (Source != null && isApplied && fromBindingContextChanged) + return; + + base.Apply(source, bindObj, targetProperty, fromBindingContextChanged); + +#if (!DO_NOT_CHECK_FOR_BINDING_REUSE) + BindableObject prevTarget; + if (_weakTarget.TryGetTarget(out prevTarget) && !ReferenceEquals(prevTarget, bindObj)) + throw new InvalidOperationException("Binding instances can not be reused"); + + object previousSource; + if (_weakSource.TryGetTarget(out previousSource) && !ReferenceEquals(previousSource, source)) + throw new InvalidOperationException("Binding instances can not be reused"); +#endif + _weakSource.SetTarget(source); + _weakTarget.SetTarget(bindObj); + + ApplyCore(source, bindObj, targetProperty); + } + + internal override BindingBase Clone() + { + Tuple, string> [] handlers = _handlers == null ? null : new Tuple, string> [_handlers.Length]; + if (handlers != null) { + for (var i = 0; i < _handlers.Length; i++) + handlers [i] = new Tuple, string>(_handlers [i].PartGetter, _handlers [i].PropertyName); + } + return new TypedBinding(_getter, _setter, handlers) { + Mode = Mode, + Converter = Converter, + ConverterParameter = ConverterParameter, + StringFormat = StringFormat, + Source = Source, + UpdateSourceEventName = UpdateSourceEventName, + }; + } + + internal override object GetSourceValue(object value, Type targetPropertyType) + { + if (Converter != null) + value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture); + + //return base.GetSourceValue(value, targetPropertyType); + if (StringFormat != null) + return string.Format(StringFormat, value); + + return value; + } + + internal override object GetTargetValue(object value, Type sourcePropertyType) + { + if (Converter != null) + value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture); + + //return base.GetTargetValue(value, sourcePropertyType); + return value; + } + + internal override void Unapply(bool fromBindingContextChanged = false) + { + if (Source != null && fromBindingContextChanged && IsApplied) + return; + +#if (!DO_NOT_CHECK_FOR_BINDING_REUSE) + base.Unapply(fromBindingContextChanged:fromBindingContextChanged); +#endif + if (_handlers != null) + Unsubscribe(); + +#if (!DO_NOT_CHECK_FOR_BINDING_REUSE) + _weakSource.SetTarget(null); + _weakTarget.SetTarget(null); +#endif + } + + // ApplyCore is as slim as it should be: + // Setting 100000 values : 17ms. + // ApplyCore 100000 (w/o INPC, w/o unnapply) : 20ms. + internal void ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget = false) + { + var isTSource = sourceObject != null && sourceObject is TSource; + var mode = this.GetRealizedMode(property); + if ((mode == BindingMode.OneWay || mode == BindingMode.OneTime) && fromTarget) + return; + + var needsGetter = (mode == BindingMode.TwoWay && !fromTarget) || mode == BindingMode.OneWay || mode == BindingMode.OneTime; + + if (isTSource && (mode == BindingMode.OneWay || mode == BindingMode.TwoWay) && _handlers != null) + Subscribe((TSource)sourceObject); + + if (needsGetter) { + var value = property.DefaultValue; + if (isTSource) { + try { + value = GetSourceValue(_getter((TSource)sourceObject), property.ReturnType); + } catch (Exception ex) when (ex is NullReferenceException || ex is KeyNotFoundException) { + } + } + if (!TryConvert(ref value, property, property.ReturnType, true)) { + // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType); + return; + } + target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false); + return; + } + + var needsSetter = (mode == BindingMode.TwoWay && fromTarget) || mode == BindingMode.OneWayToSource; + if (needsSetter && _setter != null && isTSource) { + var value = GetTargetValue(target.GetValue(property), typeof(TProperty)); + if (!TryConvert(ref value, property, typeof(TProperty), false)) { + // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, typeof(TProperty)); + return; + } + _setter((TSource)sourceObject, (TProperty)value); + } + } + + static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget) + { + if (value == null) + return true; + if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value))) + return true; + + object original = value; + try { + value = Convert.ChangeType(value, convertTo, CultureInfo.InvariantCulture); + return true; + } catch (Exception ex ) when (ex is InvalidCastException || ex is FormatException||ex is OverflowException) { + value = original; + return false; + } + } + + class PropertyChangedProxy + { + public Func PartGetter { get; } + public string PropertyName { get; } + public BindingExpression.WeakPropertyChangedProxy Listener { get; } + WeakReference _weakPart = new WeakReference(null); + readonly BindingBase _binding; + + public INotifyPropertyChanged Part { + get { + INotifyPropertyChanged target; + if (_weakPart.TryGetTarget(out target)) + return target; + return null; + } + set { + _weakPart.SetTarget(value); + Listener.SubscribeTo(value, OnPropertyChanged); + } + } + + public PropertyChangedProxy(Func partGetter, string propertyName, BindingBase binding) + { + PartGetter = partGetter; + PropertyName = propertyName; + _binding = binding; + Listener = new BindingExpression.WeakPropertyChangedProxy(); + } + + void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (!string.IsNullOrEmpty(e.PropertyName) && string.CompareOrdinal(e.PropertyName, PropertyName) != 0) + return; + Device.BeginInvokeOnMainThread(() => _binding.Apply(false)); + } + } + + void Subscribe(TSource sourceObject) + { + for (var i = 0; i < _handlers.Length; i++) { + var part = _handlers [i].PartGetter(sourceObject); + if (part == null) + break; + var inpc = part as INotifyPropertyChanged; + if (inpc == null) + continue; + _handlers [i].Part = (inpc); + } + } + + void Unsubscribe() + { + for (var i = 0; i < _handlers.Length; i++) + _handlers [i].Listener.Unsubscribe(); + } + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/XamlBinding/XmlnsDefinitionAttribute.cs b/src/Tizen.NUI/src/public/XamlBinding/XmlnsDefinitionAttribute.cs index baee6f12c..c118e9fd4 100755 --- a/src/Tizen.NUI/src/public/XamlBinding/XmlnsDefinitionAttribute.cs +++ b/src/Tizen.NUI/src/public/XamlBinding/XmlnsDefinitionAttribute.cs @@ -26,6 +26,10 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public string AssemblyName { get; set; } + /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public int Level { get; set; } + /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace) @@ -37,6 +41,7 @@ namespace Tizen.NUI ClrNamespace = clrNamespace; XmlNamespace = xmlNamespace; + Level = 0; } } } \ No newline at end of file