/*
* Copyright(c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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 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 partial 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.btGroup.Itemheight = (int)newValue;
instance.UpdateView();
}
},
defaultValueCreator: (bindable) =>
{
return (int)((Popup)bindable).btGroup.Itemheight;
});
/// 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)
{
instance.btGroup.ItemPointSize = (float)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemPointSize;
});
/// 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.btGroup.ItemFontFamily = (string)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemFontFamily;
});
/// 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)
{
instance.btGroup.ItemTextColor = (Color)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemTextColor;
});
/// 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.btGroup.OverLayBackgroundColorSelector = (Selector)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.OverLayBackgroundColorSelector;
});
/// 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.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemTextAlignment;
});
/// 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)
{
instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemBackgroundImageUrl;
});
/// 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)
{
instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
}
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemBackgroundBorder;
});
/// 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);
},
defaultValueCreator: (bindable) =>
{
return ((Popup)bindable).btGroup.ItemImageShadow;
});
private TextLabel titleText;
private ButtonGroup btGroup = null;
private Window window = null;
private Layer container = new Layer();
private ButtonStyle buttonStyle = new ButtonStyle();
static Popup() { }
///
/// Creates a new instance of a Popup.
///
/// 6
[Obsolete("Deprecated in API8; Will be removed in API10")]
public Popup() : base()
{
}
///
/// 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)
{
}
///
/// 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)
{
}
/// 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)
{
Button btn = new Button(buttonStyle);
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)
{
Button btn = new Button(style);
btn.Text = buttonText;
btn.ClickEvent += ButtonClickEvent;
btGroup.AddItem(btn);
UpdateView();
}
/// 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;
///
/// 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 GetValue(TitleTextProperty) as string;
}
set
{
SetValue(TitleTextProperty, value);
NotifyPropertyChanged();
}
}
private string InternalTitleText
{
get => Title.Text;
set => Title.Text = value;
}
///
/// Title text point size in Popup.
///
/// 6
[Obsolete("Deprecated in API8; Will be removed in API10")]
public float TitlePointSize
{
get
{
return (float)GetValue(TitlePointSizeProperty);
}
set
{
SetValue(TitlePointSizeProperty, value);
NotifyPropertyChanged();
}
}
private float InternalTitlePointSize
{
get => Title.PointSize;
set => Title.PointSize = value;
}
///
/// Title text color in Popup.
///
/// 6
[Obsolete("Deprecated in API8; Will be removed in API10")]
public Color TitleTextColor
{
get
{
return GetValue(TitleTextColorProperty) as Color;
}
set
{
SetValue(TitleTextColorProperty, value);
NotifyPropertyChanged();
}
}
private Color InternalTitleTextColor
{
get => Title.TextColor;
set => Title.TextColor = value;
}
///
/// Title text horizontal alignment in Popup.
///
/// 6
[Obsolete("Deprecated in API8; Will be removed in API10")]
public HorizontalAlignment TitleTextHorizontalAlignment
{
get
{
return (HorizontalAlignment)GetValue(TitleTextHorizontalAlignmentProperty);
}
set
{
SetValue(TitleTextHorizontalAlignmentProperty, value);
NotifyPropertyChanged();
}
}
private HorizontalAlignment InternalTitleTextHorizontalAlignment
{
get => Title.HorizontalAlignment;
set => Title.HorizontalAlignment = value;
}
///
/// Title text's position in Popup.
///
/// 6
[Obsolete("Deprecated in API8; Will be removed in API10")]
public Position TitleTextPosition
{
get
{
return GetValue(TitleTextPositionProperty) as Position;
}
set
{
SetValue(TitleTextPositionProperty, value);
NotifyPropertyChanged();
}
}
private Position InternalTitleTextPosition
{
get => Title.Position;
set => 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)GetValue(TitleHeightProperty);
}
set
{
SetValue(TitleHeightProperty, value);
NotifyPropertyChanged();
}
}
private int InternalTitleHeight
{
get => (int)Title.SizeHeight;
set => Title.SizeHeight = (int)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
{
return (int)GetValue(ButtonCountProperty);
}
set
{
SetValue(ButtonCountProperty, value);
NotifyPropertyChanged();
}
}
private int InternalButtonCount
{
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")]
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
protected override void Dispose(DisposeTypes type)
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
{
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;
}
buttonStyle?.Dispose();
}
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?.SizeHeight != null)
{
ButtonHeight = (int)ppStyle.Buttons.SizeHeight;
}
buttonStyle = (ButtonStyle)ppStyle.Buttons?.Clone();
if (buttonStyle.PositionUsesPivotPoint == null) buttonStyle.PositionUsesPivotPoint = true;
if (buttonStyle.ParentOrigin == null) buttonStyle.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft;
if (buttonStyle.PivotPoint == null) buttonStyle.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft;
if (btGroup != null)
{
for (int i = 0; i < btGroup.Count; i++)
{
var button = GetButton(i);
button.ApplyStyle(buttonStyle);
}
}
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();
}
///
/// Initialize AT-SPI object.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public override void OnInitialize()
{
base.OnInitialize();
AccessibilityRole = Role.Dialog;
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);
}
///
/// Informs AT-SPI bridge about the set of AT-SPI states associated with this object.
///
[EditorBrowsable(EditorBrowsableState.Never)]
protected override AccessibilityStates AccessibilityCalculateStates()
{
var states = base.AccessibilityCalculateStates();
states[AccessibilityState.Modal] = true;
return states;
}
private void UpdateView()
{
btGroup.UpdateButton(buttonStyle);
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 is var propName && propName != null && propName.Equals("LayoutDirection"))
{
btGroup.UpdateButton(buttonStyle);
}
}
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)
{
buttonH = ButtonHeight;
}
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(Title.Text) && 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")]
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
public class ButtonClickEventArgs : EventArgs
{
/// Button index which is clicked in Popup
/// 6
/// It will be removed in API10
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
[Obsolete("Deprecated in API8; Will be removed in API10")]
public int ButtonIndex;
}
}
}