/* * Copyright(c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System.ComponentModel; using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; namespace Tizen.NUI.Components { /// /// The control component is class of image. Temporarily for SelectButton. /// /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public class ImageControl : Control { /// 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 ResourceUrlProperty = BindableProperty.Create("ImageControlResourceUrl", typeof(Selector), typeof(ImageControl), null, propertyChanged: (bindable, oldValue, newValue) => { var imageControl = (ImageControl)bindable; if (null != newValue) { imageControl.ResourceUrlSelector.Clone((Selector)newValue); } }, defaultValueCreator: (bindable) => { var imageControl = (ImageControl)bindable; return imageControl.ResourceUrlSelector; }); /// 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 BorderProperty = BindableProperty.Create("ImageControlBorder", typeof(Selector), typeof(ImageControl), null, propertyChanged: (bindable, oldValue, newValue) => { var imageControl = (ImageControl)bindable; if (null == newValue) { imageControl.BorderSelector.Clone((Selector)newValue); } }, defaultValueCreator: (bindable) => { var imageControl = (ImageControl)bindable; return imageControl.BorderSelector; }); /// /// Control style. /// /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] private ImageControlStyle imageControlStyle; /// 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 ImageControlStyle Style => imageControlStyle; internal ImageView imageView; /// /// Construct an empty Control. /// /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public ImageControl() : base() { Initialize(null); } /// /// Construct with style. /// /// Create style customized by user /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public ImageControl(ImageControlStyle style) : base(style) { Initialize(null); } /// /// Construct with style /// /// Style to be applied /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public ImageControl(string style) : base(style) { Initialize(style); } /// /// Override view's BackgroundImage. /// /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public Selector ResourceUrl { get => (Selector)GetValue(ResourceUrlProperty); set => SetValue(ResourceUrlProperty, value); } /// /// Override view's BackgroundImageBorder. /// /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public Selector Border { get => (Selector)GetValue(BorderProperty); set => SetValue(BorderProperty, value); } private TriggerableSelector _resourceUrlSelector; private TriggerableSelector ResourceUrlSelector { get { if (null == _resourceUrlSelector) { _resourceUrlSelector = new TriggerableSelector(imageView, ImageView.ResourceUrlProperty); } return _resourceUrlSelector; } } private TriggerableSelector _borderSelector; private TriggerableSelector BorderSelector { get { if (null == _borderSelector) { _borderSelector = new TriggerableSelector(imageView, ImageView.BorderProperty); } return _borderSelector; } } /// 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 void ApplyStyle(ViewStyle viewStyle) { base.ApplyStyle(viewStyle); ImageControlStyle imageControlStyle = viewStyle as ImageControlStyle; if (null != imageControlStyle) { if (null == imageView) { imageView = new ImageView() { PositionUsesPivotPoint = true, ParentOrigin = Tizen.NUI.ParentOrigin.Center, PivotPoint = Tizen.NUI.PivotPoint.Center, WidthResizePolicy = ResizePolicyType.UseNaturalSize, HeightResizePolicy = ResizePolicyType.UseNaturalSize, }; this.Add(imageView); } } } /// /// Dispose Control and all children on it. /// /// Dispose type. /// 6 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] protected override void Dispose(DisposeTypes type) { if (disposed) { return; } if (imageView != null) { Utility.Dispose(imageView); } base.Dispose(type); } /// 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 ViewStyle GetViewStyle() { imageControlStyle = new ImageControlStyle(); return imageControlStyle; } private void Initialize(string style) { if (null == imageView) { imageView = new ImageView() { PositionUsesPivotPoint = true, ParentOrigin = Tizen.NUI.ParentOrigin.Center, PivotPoint = Tizen.NUI.PivotPoint.Center, WidthResizePolicy = ResizePolicyType.UseNaturalSize, HeightResizePolicy = ResizePolicyType.UseNaturalSize, }; this.Add(imageView); } } } }