/* * 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; using System.Collections.Generic; using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; using System.ComponentModel; namespace Tizen.NUI.Components { /// /// Popup is one kind of common component, it can be used as popup window. /// User can handle Popup button count, head title and content area. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public class Popup : 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 ButtonHeightProperty = BindableProperty.Create(nameof(ButtonHeight), typeof(int), typeof(Popup), default(int), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null && instance?.popupStyle?.Buttons?.Size != null ) { instance.popupStyle.Buttons.Size.Height = (int)newValue; instance.btGroup.Itemheight = (int)newValue; instance.UpdateView(); } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return (int)(instance.popupStyle?.Buttons?.Size?.Height ?? 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)] public static readonly BindableProperty ButtonTextPointSizeProperty = BindableProperty.Create(nameof(ButtonTextPointSize), typeof(float), typeof(Popup), default(float), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { if (instance.popupStyle?.Buttons?.Text != null) { instance.popupStyle.Buttons.Text.PointSize = (float)newValue; } instance.btGroup.ItemPointSize = (float)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.Text?.PointSize?.All ?? 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)] public static readonly BindableProperty ButtonFontFamilyProperty = BindableProperty.Create(nameof(ButtonFontFamily), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { instance.popupStyle.Buttons.Text.FontFamily = (string)newValue; instance.btGroup.ItemFontFamily = (string)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.Text?.FontFamily.All; }); /// 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 ButtonTextColorProperty = BindableProperty.Create(nameof(ButtonTextColor), typeof(Color), typeof(Popup), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { if (instance.popupStyle?.Buttons?.Text != null) { instance.popupStyle.Buttons.Text.TextColor = (Color)newValue; } instance.btGroup.ItemTextColor = (Color)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.Text?.TextColor?.All; }); /// 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 ButtonOverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(ButtonOverLayBackgroundColorSelector), typeof(Selector), typeof(Popup), new Selector(), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { instance.popupStyle.Buttons.Overlay.BackgroundColor = (Selector)newValue; instance.btGroup.OverLayBackgroundColorSelector = (Selector)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.Overlay?.BackgroundColor; }); /// 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 ButtonTextAlignmentProperty = BindableProperty.Create(nameof(ButtonTextAlignment), typeof(HorizontalAlignment), typeof(Popup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { instance.popupStyle.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue; instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center; }); /// 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 ButtonBackgroundProperty = BindableProperty.Create(nameof(ButtonBackground), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { if (instance.popupStyle.Buttons.BackgroundImage == null) { instance.popupStyle.Buttons.BackgroundImage = new Selector(); } instance.popupStyle.Buttons.BackgroundColor = new Selector(); instance.popupStyle.Buttons.BackgroundImage = (string)newValue; instance.btGroup.ItemBackgroundImageUrl = (string)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.BackgroundImage?.All; }); /// 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 ButtonBackgroundBorderProperty = BindableProperty.Create(nameof(ButtonBackgroundBorder), typeof(Rectangle), typeof(Popup), new Rectangle(0, 0, 0, 0), propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; if (newValue != null) { if (instance.popupStyle.Buttons.BackgroundImageBorder == null) { instance.popupStyle.Buttons.BackgroundImageBorder = new Selector(); } instance.popupStyle.Buttons.BackgroundImageBorder = (Rectangle)newValue; instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue; } }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.BackgroundImageBorder?.All; }); /// 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 ButtonImageShadowProperty = BindableProperty.Create(nameof(ButtonImageShadow), typeof(ImageShadow), typeof(Popup), null, propertyChanged: (bindable, oldValue, newValue) => { var instance = (Popup)bindable; ImageShadow shadow = (ImageShadow)newValue; instance.btGroup.ItemImageShadow = new ImageShadow(shadow); instance.popupStyle.Buttons.ImageShadow = new ImageShadow(shadow); }, defaultValueCreator: (bindable) => { var instance = (Popup)bindable; return instance.popupStyle?.Buttons?.ImageShadow?.All; }); private PopupStyle popupStyle => ViewStyle as PopupStyle; private TextLabel titleText; private ButtonGroup btGroup = null; private Window window = null; private Layer container = new Layer(); static Popup() { } /// /// Creates a new instance of a Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public Popup() : base() { Initialize(); } /// /// Creates a new instance of a Popup with style. /// /// Create Popup by special style defined in UX. [EditorBrowsable(EditorBrowsableState.Never)] public Popup(string style) : base(style) { Initialize(); } /// /// Creates a new instance of a Popup with style. /// /// Create Popup by style customized by user. [EditorBrowsable(EditorBrowsableState.Never)] public Popup(PopupStyle popupStyle) : base(popupStyle) { Initialize(); } /// 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 virtual void Post(Window targetWindow) { if (targetWindow == null) { return; } window = targetWindow; window.AddLayer(container); container.RaiseToTop(); } /// /// Dismiss the dialog /// [EditorBrowsable(EditorBrowsableState.Never)] public virtual void Dismiss() { if (window == null) { return; } window.RemoveLayer(container); window = null; } /// 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 void AddButton(string buttonText) { if (popupStyle.Buttons != null) { Button btn = new Button(popupStyle.Buttons); btn.Text = buttonText; btn.ClickEvent += ButtonClickEvent; btGroup.AddItem(btn); UpdateView(); } } /// /// Add button by style's name. /// [EditorBrowsable(EditorBrowsableState.Never)] public void AddButton(string buttonText, string style) { AddButton(buttonText); } /// /// Add button by style. /// [EditorBrowsable(EditorBrowsableState.Never)] public void AddButton(string buttonText, ButtonStyle style) { if (popupStyle.Buttons != null && style != null) { popupStyle.Buttons.CopyFrom(style); AddButton(buttonText); } } /// 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 Button GetButton(int index) { return btGroup.GetItem(index); } /// 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 void RemoveButton(int index) { btGroup.RemoveItem(index); } /// 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 void AddContentText(View childView) { if (null != ContentView) { ContentView.Add(childView); } UpdateView(); } /// /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.
///
/// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public event EventHandler PopupButtonClickEvent; /// /// Get style of popup. /// [EditorBrowsable(EditorBrowsableState.Never)] public new PopupStyle Style { get { var result = new PopupStyle(popupStyle); result.CopyPropertiesFromView(this); result.Title.CopyPropertiesFromView(titleText); return result; } } /// /// Popup Title. /// [EditorBrowsable(EditorBrowsableState.Never)] public TextLabel Title { get { if (null == titleText) { titleText = new TextLabel { PositionUsesPivotPoint = true, ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, PivotPoint = Tizen.NUI.PivotPoint.TopLeft, HorizontalAlignment = HorizontalAlignment.Begin, VerticalAlignment = VerticalAlignment.Bottom, Text = "Title" }; Add(titleText); } return titleText; } internal set { titleText = value; } } /// /// Title text string in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public string TitleText { get { return popupStyle?.Title?.Text?.All; } set { if (value != null) { if (popupStyle?.Title != null) { popupStyle.Title.Text = value; } } } } /// /// Title text point size in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public float TitlePointSize { get { return popupStyle?.Title?.PointSize?.All ?? 0; } set { if (popupStyle?.Title != null) { popupStyle.Title.PointSize = value; } } } /// /// Title text color in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public Color TitleTextColor { get { return popupStyle?.Title?.TextColor?.All; } set { if (popupStyle?.Title != null) { popupStyle.Title.TextColor = value; } } } /// /// Title text horizontal alignment in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public HorizontalAlignment TitleTextHorizontalAlignment { get { return popupStyle?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center; } set { popupStyle.Title.HorizontalAlignment = value; } } /// /// Title text's position in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public Position TitleTextPosition { get { return popupStyle?.Title?.Position ?? new Position(0, 0, 0); } set { popupStyle.Title.Position = value; } } /// /// Title text's height in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public int TitleHeight { get { return (int)(popupStyle?.Title?.Size?.Height ?? 0); } set { if (popupStyle?.Title?.Size != null) { popupStyle.Title.Size.Height = value; } } } /// /// Content view in Popup, only can be gotten. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public View ContentView { get; private set; } /// /// Button count in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public int ButtonCount { get; set; } /// /// Button height in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public int ButtonHeight { get { return (int)GetValue(ButtonHeightProperty); } set { SetValue(ButtonHeightProperty, value); } } /// /// Button text point size in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public float ButtonTextPointSize { get { return (float)GetValue(ButtonTextPointSizeProperty); } set { SetValue(ButtonTextPointSizeProperty, value); } } /// /// Button text font family in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public string ButtonFontFamily { get { return (string)GetValue(ButtonFontFamilyProperty); } set { SetValue(ButtonFontFamilyProperty, value); } } /// /// Button text color in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public Color ButtonTextColor { get { return (Color)GetValue(ButtonTextColorProperty); } set { SetValue(ButtonTextColorProperty, value); } } /// /// Button overlay background color selector in Popup. /// /// 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 Selector ButtonOverLayBackgroundColorSelector { get { return (Selector)GetValue(ButtonOverLayBackgroundColorSelectorProperty); } set { SetValue(ButtonOverLayBackgroundColorSelectorProperty, value); } } /// /// Button text horizontal alignment in Popup. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public HorizontalAlignment ButtonTextAlignment { get { return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty); } set { SetValue(ButtonTextAlignmentProperty, value); } } /// /// Button background image's resource url in Popup. /// /// 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 string ButtonBackground { get { return (string)GetValue(ButtonBackgroundProperty); } set { SetValue(ButtonBackgroundProperty, value); } } /// /// Button background image's border in Popup. /// /// 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 Rectangle ButtonBackgroundBorder { get { return (Rectangle)GetValue(ButtonBackgroundBorderProperty); } set { SetValue(ButtonBackgroundBorderProperty, value); } } /// /// Button's image shadow in Popup. /// /// 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 ImageShadow ButtonImageShadow { get => (ImageShadow)GetValue(ButtonImageShadowProperty); set => SetValue(ButtonImageShadowProperty, value); } /// /// Set button text by index. /// /// Button index. /// Button text string. /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public void SetButtonText(int index, string text) { AddButton(text); } /// /// Dispose Popup and all children on it. /// /// Dispose type. /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] protected override void Dispose(DisposeTypes type) { if (disposed) { return; } if (type == DisposeTypes.Explicit) { if (titleText != null) { Remove(titleText); titleText.Dispose(); titleText = null; } if (ContentView != null) { Remove(ContentView); ContentView.Dispose(); ContentView = null; } if (btGroup != null) { btGroup.Dispose(); btGroup = null; } } base.Dispose(type); } /// /// Focus gained callback. /// /// 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 override void OnFocusGained() { base.OnFocusGained(); } /// /// Focus lost callback. /// /// 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 override void OnFocusLost() { base.OnFocusLost(); } /// /// Apply style to popup. /// /// The style to apply. [EditorBrowsable(EditorBrowsableState.Never)] public override void ApplyStyle(ViewStyle viewStyle) { base.ApplyStyle(viewStyle); if (viewStyle is PopupStyle ppStyle) { if (ppStyle.Buttons == null) { ppStyle.Buttons = new ButtonStyle(); } if (ppStyle.Buttons.PositionUsesPivotPoint == null) ppStyle.Buttons.PositionUsesPivotPoint = true; if (ppStyle.Buttons.ParentOrigin == null) ppStyle.Buttons.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft; if (ppStyle.Buttons.PivotPoint == null) ppStyle.Buttons.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft; if (btGroup != null) { for (int i = 0; i < btGroup.Count; i++) { GetButton(i)?.ApplyStyle(ppStyle.Buttons); } } Title.ApplyStyle(ppStyle.Title); Title.RaiseToTop(); } } /// /// Get Popup style. /// /// The default popup style. [EditorBrowsable(EditorBrowsableState.Never)] protected override ViewStyle CreateViewStyle() { return new PopupStyle(); } /// [EditorBrowsable(EditorBrowsableState.Never)] protected override void OnUpdate() { base.OnUpdate(); UpdateView(); } private void Initialize() { container.Add(this); container.SetTouchConsumed(true); container.SetHoverConsumed(true); LeaveRequired = true; PropertyChanged += PopupStylePropertyChanged; // ContentView ContentView = new View() { ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft, PivotPoint = Tizen.NUI.PivotPoint.TopLeft, PositionUsesPivotPoint = true }; Add(ContentView); ContentView.RaiseToTop(); // Button btGroup = new ButtonGroup(this); } private void UpdateView() { if (popupStyle == null) return; btGroup.UpdateButton(popupStyle.Buttons); UpdateContentView(); UpdateTitle(); } private void ButtonClickEvent(object sender, Button.ClickEventArgs e) { if (PopupButtonClickEvent != null && btGroup.Count > 0) { Button button = sender as Button; for (int i = 0; i < btGroup.Count; i++) { if (button == GetButton(i)) { ButtonClickEventArgs args = new ButtonClickEventArgs(); args.ButtonIndex = i; PopupButtonClickEvent(this, args); } } } } private void PopupStylePropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName.Equals("LayoutDirection")) { btGroup.UpdateButton(popupStyle.Buttons); } } private void UpdateContentView() { int titleX = 0; int titleY = 0; int titleH = 0; int buttonH = 0; string strText = Title.Text; if (!string.IsNullOrEmpty(strText) && Title.Size != null) { titleH = (int)titleText.Size.Height; } if (!string.IsNullOrEmpty(strText) && Title.Position != null) { titleX = (int)Title.Position.X; titleY = (int)Title.Position.Y; } if (btGroup.Count != 0 && popupStyle?.Buttons?.Size != null ) { buttonH = (int)popupStyle.Buttons.Size.Height; } ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH); ContentView.Position = new Position(titleX, titleY + titleH); ContentView.RaiseToTop(); } private void UpdateTitle() { if (titleText != null && string.IsNullOrEmpty(popupStyle.Title.Text.All) && popupStyle.Title.Size != null) { titleText.RaiseToTop(); } } /// /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user. /// /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public class ButtonClickEventArgs : EventArgs { /// Button index which is clicked in Popup /// 6 [Obsolete("Deprecated in API8; Will be removed in API10")] public int ButtonIndex; } } }