2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using System.ComponentModel;
22 namespace Tizen.NUI.Components
25 /// Popup is one kind of common component, it can be used as popup window.
26 /// User can handle Popup button count, head title and content area.
28 /// <since_tizen> 6 </since_tizen>
29 [Obsolete("Deprecated in API8; Will be removed in API10")]
30 public partial class Popup : Control
32 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public static readonly BindableProperty ButtonHeightProperty = BindableProperty.Create(nameof(ButtonHeight), typeof(int), typeof(Popup), default(int), propertyChanged: (bindable, oldValue, newValue) =>
36 var instance = (Popup)bindable;
39 instance.btGroup.Itemheight = (int)newValue;
40 instance.UpdateView();
43 defaultValueCreator: (bindable) =>
45 return (int)((Popup)bindable).btGroup.Itemheight;
48 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public static readonly BindableProperty ButtonTextPointSizeProperty = BindableProperty.Create(nameof(ButtonTextPointSize), typeof(float), typeof(Popup), default(float), propertyChanged: (bindable, oldValue, newValue) =>
52 var instance = (Popup)bindable;
55 instance.btGroup.ItemPointSize = (float)newValue;
58 defaultValueCreator: (bindable) =>
60 return ((Popup)bindable).btGroup.ItemPointSize;
63 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public static readonly BindableProperty ButtonFontFamilyProperty = BindableProperty.Create(nameof(ButtonFontFamily), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
67 var instance = (Popup)bindable;
70 instance.btGroup.ItemFontFamily = (string)newValue;
73 defaultValueCreator: (bindable) =>
75 return ((Popup)bindable).btGroup.ItemFontFamily;
78 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
79 [EditorBrowsable(EditorBrowsableState.Never)]
80 public static readonly BindableProperty ButtonTextColorProperty = BindableProperty.Create(nameof(ButtonTextColor), typeof(Color), typeof(Popup), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) =>
82 var instance = (Popup)bindable;
85 instance.btGroup.ItemTextColor = (Color)newValue;
88 defaultValueCreator: (bindable) =>
90 return ((Popup)bindable).btGroup.ItemTextColor;
93 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 public static readonly BindableProperty ButtonOverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(ButtonOverLayBackgroundColorSelector), typeof(Selector<Color>), typeof(Popup), new Selector<Color>(), propertyChanged: (bindable, oldValue, newValue) =>
97 var instance = (Popup)bindable;
100 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
103 defaultValueCreator: (bindable) =>
105 return ((Popup)bindable).btGroup.OverLayBackgroundColorSelector;
108 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public static readonly BindableProperty ButtonTextAlignmentProperty = BindableProperty.Create(nameof(ButtonTextAlignment), typeof(HorizontalAlignment), typeof(Popup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) =>
112 var instance = (Popup)bindable;
113 if (newValue != null)
115 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
118 defaultValueCreator: (bindable) =>
120 return ((Popup)bindable).btGroup.ItemTextAlignment;
123 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 public static readonly BindableProperty ButtonBackgroundProperty = BindableProperty.Create(nameof(ButtonBackground), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
127 var instance = (Popup)bindable;
128 if (newValue != null)
130 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
133 defaultValueCreator: (bindable) =>
135 return ((Popup)bindable).btGroup.ItemBackgroundImageUrl;
138 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public static readonly BindableProperty ButtonBackgroundBorderProperty = BindableProperty.Create(nameof(ButtonBackgroundBorder), typeof(Rectangle), typeof(Popup), new Rectangle(0, 0, 0, 0), propertyChanged: (bindable, oldValue, newValue) =>
142 var instance = (Popup)bindable;
143 if (newValue != null)
145 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
148 defaultValueCreator: (bindable) =>
150 return ((Popup)bindable).btGroup.ItemBackgroundBorder;
153 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public static readonly BindableProperty ButtonImageShadowProperty = BindableProperty.Create(nameof(ButtonImageShadow), typeof(ImageShadow), typeof(Popup), null, propertyChanged: (bindable, oldValue, newValue) =>
157 var instance = (Popup)bindable;
158 ImageShadow shadow = (ImageShadow)newValue;
159 instance.btGroup.ItemImageShadow = new ImageShadow(shadow);
161 defaultValueCreator: (bindable) =>
163 return ((Popup)bindable).btGroup.ItemImageShadow;
166 private TextLabel titleText;
167 private ButtonGroup btGroup = null;
168 private Window window = null;
169 private Layer container = new Layer();
170 private ButtonStyle buttonStyle = new ButtonStyle();
175 /// Creates a new instance of a Popup.
177 /// <since_tizen> 6 </since_tizen>
178 [Obsolete("Deprecated in API8; Will be removed in API10")]
179 public Popup() : base()
184 /// Creates a new instance of a Popup with style.
186 /// <param name="style">Create Popup by special style defined in UX.</param>
187 [EditorBrowsable(EditorBrowsableState.Never)]
188 public Popup(string style) : base(style)
193 /// Creates a new instance of a Popup with style.
195 /// <param name="popupStyle">Create Popup by style customized by user.</param>
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public Popup(PopupStyle popupStyle) : base(popupStyle)
201 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
202 [EditorBrowsable(EditorBrowsableState.Never)]
203 public virtual void Post(Window targetWindow)
205 if (targetWindow == null)
210 window = targetWindow;
211 window.AddLayer(container);
212 container.RaiseToTop();
216 /// Dismiss the dialog
218 [EditorBrowsable(EditorBrowsableState.Never)]
219 public virtual void Dismiss()
226 window.RemoveLayer(container);
230 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
231 [EditorBrowsable(EditorBrowsableState.Never)]
232 public void AddButton(string buttonText)
234 Button btn = new Button(buttonStyle);
235 btn.Text = buttonText;
236 btn.ClickEvent += ButtonClickEvent;
237 btGroup.AddItem(btn);
242 /// Add button by style's name.
244 [EditorBrowsable(EditorBrowsableState.Never)]
245 public void AddButton(string buttonText, string style)
247 AddButton(buttonText);
251 /// Add button by style.
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public void AddButton(string buttonText, ButtonStyle style)
256 Button btn = new Button(style);
257 btn.Text = buttonText;
258 btn.ClickEvent += ButtonClickEvent;
259 btGroup.AddItem(btn);
263 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public Button GetButton(int index)
267 return btGroup.GetItem(index);
270 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
271 [EditorBrowsable(EditorBrowsableState.Never)]
272 public void RemoveButton(int index)
274 btGroup.RemoveItem(index);
277 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public void AddContentText(View childView)
281 if (null != ContentView)
283 ContentView.Add(childView);
289 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
291 /// <since_tizen> 6 </since_tizen>
292 [Obsolete("Deprecated in API8; Will be removed in API10")]
293 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
298 [EditorBrowsable(EditorBrowsableState.Never)]
299 public TextLabel Title
303 if (null == titleText)
305 titleText = new TextLabel
307 PositionUsesPivotPoint = true,
308 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
309 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
310 HorizontalAlignment = HorizontalAlignment.Begin,
311 VerticalAlignment = VerticalAlignment.Bottom,
325 /// Title text string in Popup.
327 /// <since_tizen> 6 </since_tizen>
328 [Obsolete("Deprecated in API8; Will be removed in API10")]
329 public string TitleText
333 return GetValue(TitleTextProperty) as string;
337 SetValue(TitleTextProperty, value);
338 NotifyPropertyChanged();
341 private string InternalTitleText
344 set => Title.Text = value;
348 /// Title text point size in Popup.
350 /// <since_tizen> 6 </since_tizen>
351 [Obsolete("Deprecated in API8; Will be removed in API10")]
352 public float TitlePointSize
356 return (float)GetValue(TitlePointSizeProperty);
360 SetValue(TitlePointSizeProperty, value);
361 NotifyPropertyChanged();
364 private float InternalTitlePointSize
366 get => Title.PointSize;
367 set => Title.PointSize = value;
371 /// Title text color in Popup.
373 /// <since_tizen> 6 </since_tizen>
374 [Obsolete("Deprecated in API8; Will be removed in API10")]
375 public Color TitleTextColor
379 return GetValue(TitleTextColorProperty) as Color;
383 SetValue(TitleTextColorProperty, value);
384 NotifyPropertyChanged();
387 private Color InternalTitleTextColor
389 get => Title.TextColor;
390 set => Title.TextColor = value;
394 /// Title text horizontal alignment in Popup.
396 /// <since_tizen> 6 </since_tizen>
397 [Obsolete("Deprecated in API8; Will be removed in API10")]
398 public HorizontalAlignment TitleTextHorizontalAlignment
402 return (HorizontalAlignment)GetValue(TitleTextHorizontalAlignmentProperty);
406 SetValue(TitleTextHorizontalAlignmentProperty, value);
407 NotifyPropertyChanged();
410 private HorizontalAlignment InternalTitleTextHorizontalAlignment
412 get => Title.HorizontalAlignment;
413 set => Title.HorizontalAlignment = value;
417 /// Title text's position in Popup.
419 /// <since_tizen> 6 </since_tizen>
420 [Obsolete("Deprecated in API8; Will be removed in API10")]
421 public Position TitleTextPosition
425 return GetValue(TitleTextPositionProperty) as Position;
429 SetValue(TitleTextPositionProperty, value);
430 NotifyPropertyChanged();
433 private Position InternalTitleTextPosition
435 get => Title.Position;
436 set => Title.Position = value;
440 /// Title text's height in Popup.
442 /// <since_tizen> 6 </since_tizen>
443 [Obsolete("Deprecated in API8; Will be removed in API10")]
444 public int TitleHeight
448 return (int)GetValue(TitleHeightProperty);
452 SetValue(TitleHeightProperty, value);
453 NotifyPropertyChanged();
456 private int InternalTitleHeight
458 get => (int)Title.SizeHeight;
459 set => Title.SizeHeight = (int)value;
463 /// Content view in Popup, only can be gotten.
465 /// <since_tizen> 6 </since_tizen>
466 [Obsolete("Deprecated in API8; Will be removed in API10")]
467 public View ContentView
474 /// Button count in Popup.
476 /// <since_tizen> 6 </since_tizen>
477 [Obsolete("Deprecated in API8; Will be removed in API10")]
478 public int ButtonCount
482 return (int)GetValue(ButtonCountProperty);
486 SetValue(ButtonCountProperty, value);
487 NotifyPropertyChanged();
490 private int InternalButtonCount
497 /// Button height in Popup.
499 /// <since_tizen> 6 </since_tizen>
500 [Obsolete("Deprecated in API8; Will be removed in API10")]
501 public int ButtonHeight
505 return (int)GetValue(ButtonHeightProperty);
509 SetValue(ButtonHeightProperty, value);
514 /// Button text point size in Popup.
516 /// <since_tizen> 6 </since_tizen>
517 [Obsolete("Deprecated in API8; Will be removed in API10")]
518 public float ButtonTextPointSize
522 return (float)GetValue(ButtonTextPointSizeProperty);
526 SetValue(ButtonTextPointSizeProperty, value);
531 /// Button text font family in Popup.
533 /// <since_tizen> 6 </since_tizen>
534 [Obsolete("Deprecated in API8; Will be removed in API10")]
535 public string ButtonFontFamily
539 return (string)GetValue(ButtonFontFamilyProperty);
543 SetValue(ButtonFontFamilyProperty, value);
548 /// Button text color in Popup.
550 /// <since_tizen> 6 </since_tizen>
551 [Obsolete("Deprecated in API8; Will be removed in API10")]
552 public Color ButtonTextColor
556 return (Color)GetValue(ButtonTextColorProperty);
560 SetValue(ButtonTextColorProperty, value);
565 /// Button overlay background color selector in Popup.
567 /// <since_tizen> 6 </since_tizen>
568 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
569 [EditorBrowsable(EditorBrowsableState.Never)]
570 public Selector<Color> ButtonOverLayBackgroundColorSelector
574 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
578 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
583 /// Button text horizontal alignment in Popup.
585 /// <since_tizen> 6 </since_tizen>
586 [Obsolete("Deprecated in API8; Will be removed in API10")]
587 public HorizontalAlignment ButtonTextAlignment
591 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
595 SetValue(ButtonTextAlignmentProperty, value);
600 /// Button background image's resource url in Popup.
602 /// <since_tizen> 6 </since_tizen>
603 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
604 [EditorBrowsable(EditorBrowsableState.Never)]
605 public string ButtonBackground
609 return (string)GetValue(ButtonBackgroundProperty);
613 SetValue(ButtonBackgroundProperty, value);
618 /// Button background image's border in Popup.
620 /// <since_tizen> 6 </since_tizen>
621 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
622 [EditorBrowsable(EditorBrowsableState.Never)]
623 public Rectangle ButtonBackgroundBorder
628 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
632 SetValue(ButtonBackgroundBorderProperty, value);
637 /// Button's image shadow in Popup.
639 /// <since_tizen> 6 </since_tizen>
640 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
641 [EditorBrowsable(EditorBrowsableState.Never)]
642 public ImageShadow ButtonImageShadow
644 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
645 set => SetValue(ButtonImageShadowProperty, value);
650 /// Set button text by index.
652 /// <param name="index">Button index.</param>
653 /// <param name="text">Button text string.</param>
654 /// <since_tizen> 6 </since_tizen>
655 [Obsolete("Deprecated in API8; Will be removed in API10")]
656 public void SetButtonText(int index, string text)
662 /// Dispose Popup and all children on it.
664 /// <param name="type">Dispose type.</param>
665 /// <since_tizen> 6 </since_tizen>
666 [Obsolete("Deprecated in API8; Will be removed in API10")]
667 #pragma warning disable CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
668 protected override void Dispose(DisposeTypes type)
669 #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
676 if (type == DisposeTypes.Explicit)
678 if (titleText != null)
684 if (ContentView != null)
687 ContentView.Dispose();
697 buttonStyle?.Dispose();
704 /// Focus gained callback.
706 /// <since_tizen> 6 </since_tizen>
707 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
708 [EditorBrowsable(EditorBrowsableState.Never)]
709 public override void OnFocusGained()
711 base.OnFocusGained();
715 /// Focus lost callback.
717 /// <since_tizen> 6 </since_tizen>
718 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
719 [EditorBrowsable(EditorBrowsableState.Never)]
720 public override void OnFocusLost()
726 /// Apply style to popup.
728 /// <param name="viewStyle">The style to apply.</param>
729 [EditorBrowsable(EditorBrowsableState.Never)]
730 public override void ApplyStyle(ViewStyle viewStyle)
732 base.ApplyStyle(viewStyle);
734 if (viewStyle is PopupStyle ppStyle)
736 if (ppStyle.Buttons?.SizeHeight != null)
738 ButtonHeight = (int)ppStyle.Buttons.SizeHeight;
741 buttonStyle = (ButtonStyle)ppStyle.Buttons?.Clone();
742 if (buttonStyle.PositionUsesPivotPoint == null) buttonStyle.PositionUsesPivotPoint = true;
743 if (buttonStyle.ParentOrigin == null) buttonStyle.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft;
744 if (buttonStyle.PivotPoint == null) buttonStyle.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft;
748 for (int i = 0; i < btGroup.Count; i++)
750 var button = GetButton(i);
751 button.ApplyStyle(buttonStyle);
755 Title.ApplyStyle(ppStyle.Title);
763 /// <returns>The default popup style.</returns>
764 [EditorBrowsable(EditorBrowsableState.Never)]
765 protected override ViewStyle CreateViewStyle()
767 return new PopupStyle();
771 [EditorBrowsable(EditorBrowsableState.Never)]
772 protected override void OnUpdate()
779 /// Initialize AT-SPI object.
781 [EditorBrowsable(EditorBrowsableState.Never)]
782 public override void OnInitialize()
785 AccessibilityRole = Role.Dialog;
788 container.SetTouchConsumed(true);
789 container.SetHoverConsumed(true);
791 LeaveRequired = true;
792 PropertyChanged += PopupStylePropertyChanged;
795 ContentView = new View()
797 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
798 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
799 PositionUsesPivotPoint = true
802 ContentView.RaiseToTop();
805 btGroup = new ButtonGroup(this);
809 /// Informs AT-SPI bridge about the set of AT-SPI states associated with this object.
811 [EditorBrowsable(EditorBrowsableState.Never)]
812 protected override AccessibilityStates AccessibilityCalculateStates()
814 var states = base.AccessibilityCalculateStates();
816 states[AccessibilityState.Modal] = true;
821 private void UpdateView()
823 btGroup.UpdateButton(buttonStyle);
828 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
830 if (PopupButtonClickEvent != null && btGroup.Count > 0)
832 Button button = sender as Button;
833 for (int i = 0; i < btGroup.Count; i++)
835 if (button == GetButton(i))
837 ButtonClickEventArgs args = new ButtonClickEventArgs();
838 args.ButtonIndex = i;
839 PopupButtonClickEvent(this, args);
845 private void PopupStylePropertyChanged(object sender, PropertyChangedEventArgs e)
847 if (e.PropertyName.Equals("LayoutDirection"))
849 btGroup.UpdateButton(buttonStyle);
853 private void UpdateContentView()
859 string strText = Title.Text;
860 if (!string.IsNullOrEmpty(strText) && Title.Size != null)
862 titleH = (int)titleText.Size.Height;
865 if (!string.IsNullOrEmpty(strText) && Title.Position != null)
867 titleX = (int)Title.Position.X;
868 titleY = (int)Title.Position.Y;
871 if (btGroup.Count != 0)
873 buttonH = ButtonHeight;
875 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
876 ContentView.Position = new Position(titleX, titleY + titleH);
877 ContentView.RaiseToTop();
880 private void UpdateTitle()
882 if (titleText != null && string.IsNullOrEmpty(Title.Text) && Title.Size != null)
884 titleText.RaiseToTop();
888 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
890 /// <since_tizen> 6 </since_tizen>
891 [Obsolete("Deprecated in API8; Will be removed in API10")]
892 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
893 public class ButtonClickEventArgs : EventArgs
895 /// <summary> Button index which is clicked in Popup </summary>
896 /// <since_tizen> 6 </since_tizen>
897 /// It will be removed in API10
898 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
899 [Obsolete("Deprecated in API8; Will be removed in API10")]
900 public int ButtonIndex;