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 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
332 set => Title.Text = value;
336 /// Title text point size in Popup.
338 /// <since_tizen> 6 </since_tizen>
339 [Obsolete("Deprecated in API8; Will be removed in API10")]
340 public float TitlePointSize
342 get => Title.PointSize;
343 set => Title.PointSize = value;
347 /// Title text color in Popup.
349 /// <since_tizen> 6 </since_tizen>
350 [Obsolete("Deprecated in API8; Will be removed in API10")]
351 public Color TitleTextColor
353 get => Title.TextColor;
354 set => Title.TextColor = value;
358 /// Title text horizontal alignment in Popup.
360 /// <since_tizen> 6 </since_tizen>
361 [Obsolete("Deprecated in API8; Will be removed in API10")]
362 public HorizontalAlignment TitleTextHorizontalAlignment
364 get => Title.HorizontalAlignment;
365 set => Title.HorizontalAlignment = value;
369 /// Title text's position in Popup.
371 /// <since_tizen> 6 </since_tizen>
372 [Obsolete("Deprecated in API8; Will be removed in API10")]
373 public Position TitleTextPosition
375 get => Title.Position;
376 set => Title.Position = value;
380 /// Title text's height in Popup.
382 /// <since_tizen> 6 </since_tizen>
383 [Obsolete("Deprecated in API8; Will be removed in API10")]
384 public int TitleHeight
386 get => (int)Title.SizeHeight;
387 set => Title.SizeHeight = (int)value;
391 /// Content view in Popup, only can be gotten.
393 /// <since_tizen> 6 </since_tizen>
394 [Obsolete("Deprecated in API8; Will be removed in API10")]
395 public View ContentView
402 /// Button count in Popup.
404 /// <since_tizen> 6 </since_tizen>
405 [Obsolete("Deprecated in API8; Will be removed in API10")]
406 public int ButtonCount
413 /// Button height in Popup.
415 /// <since_tizen> 6 </since_tizen>
416 [Obsolete("Deprecated in API8; Will be removed in API10")]
417 public int ButtonHeight
421 return (int)GetValue(ButtonHeightProperty);
425 SetValue(ButtonHeightProperty, value);
430 /// Button text point size in Popup.
432 /// <since_tizen> 6 </since_tizen>
433 [Obsolete("Deprecated in API8; Will be removed in API10")]
434 public float ButtonTextPointSize
438 return (float)GetValue(ButtonTextPointSizeProperty);
442 SetValue(ButtonTextPointSizeProperty, value);
447 /// Button text font family in Popup.
449 /// <since_tizen> 6 </since_tizen>
450 [Obsolete("Deprecated in API8; Will be removed in API10")]
451 public string ButtonFontFamily
455 return (string)GetValue(ButtonFontFamilyProperty);
459 SetValue(ButtonFontFamilyProperty, value);
464 /// Button text color in Popup.
466 /// <since_tizen> 6 </since_tizen>
467 [Obsolete("Deprecated in API8; Will be removed in API10")]
468 public Color ButtonTextColor
472 return (Color)GetValue(ButtonTextColorProperty);
476 SetValue(ButtonTextColorProperty, value);
481 /// Button overlay background color selector in Popup.
483 /// <since_tizen> 6 </since_tizen>
484 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
485 [EditorBrowsable(EditorBrowsableState.Never)]
486 public Selector<Color> ButtonOverLayBackgroundColorSelector
490 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
494 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
499 /// Button text horizontal alignment in Popup.
501 /// <since_tizen> 6 </since_tizen>
502 [Obsolete("Deprecated in API8; Will be removed in API10")]
503 public HorizontalAlignment ButtonTextAlignment
507 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
511 SetValue(ButtonTextAlignmentProperty, value);
516 /// Button background image's resource url in Popup.
518 /// <since_tizen> 6 </since_tizen>
519 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
520 [EditorBrowsable(EditorBrowsableState.Never)]
521 public string ButtonBackground
525 return (string)GetValue(ButtonBackgroundProperty);
529 SetValue(ButtonBackgroundProperty, value);
534 /// Button background image's border in Popup.
536 /// <since_tizen> 6 </since_tizen>
537 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
538 [EditorBrowsable(EditorBrowsableState.Never)]
539 public Rectangle ButtonBackgroundBorder
544 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
548 SetValue(ButtonBackgroundBorderProperty, value);
553 /// Button's image shadow in Popup.
555 /// <since_tizen> 6 </since_tizen>
556 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
557 [EditorBrowsable(EditorBrowsableState.Never)]
558 public ImageShadow ButtonImageShadow
560 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
561 set => SetValue(ButtonImageShadowProperty, value);
566 /// Set button text by index.
568 /// <param name="index">Button index.</param>
569 /// <param name="text">Button text string.</param>
570 /// <since_tizen> 6 </since_tizen>
571 [Obsolete("Deprecated in API8; Will be removed in API10")]
572 public void SetButtonText(int index, string text)
578 /// Dispose Popup and all children on it.
580 /// <param name="type">Dispose type.</param>
581 /// <since_tizen> 6 </since_tizen>
582 [Obsolete("Deprecated in API8; Will be removed in API10")]
583 #pragma warning disable CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
584 protected override void Dispose(DisposeTypes type)
585 #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
592 if (type == DisposeTypes.Explicit)
594 if (titleText != null)
600 if (ContentView != null)
603 ContentView.Dispose();
613 buttonStyle?.Dispose();
620 /// Focus gained callback.
622 /// <since_tizen> 6 </since_tizen>
623 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
624 [EditorBrowsable(EditorBrowsableState.Never)]
625 public override void OnFocusGained()
627 base.OnFocusGained();
631 /// Focus lost callback.
633 /// <since_tizen> 6 </since_tizen>
634 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
635 [EditorBrowsable(EditorBrowsableState.Never)]
636 public override void OnFocusLost()
642 /// Apply style to popup.
644 /// <param name="viewStyle">The style to apply.</param>
645 [EditorBrowsable(EditorBrowsableState.Never)]
646 public override void ApplyStyle(ViewStyle viewStyle)
648 base.ApplyStyle(viewStyle);
650 if (viewStyle is PopupStyle ppStyle)
652 if (ppStyle.Buttons?.SizeHeight != null)
654 ButtonHeight = (int)ppStyle.Buttons.SizeHeight;
657 buttonStyle = (ButtonStyle)ppStyle.Buttons?.Clone();
658 if (buttonStyle.PositionUsesPivotPoint == null) buttonStyle.PositionUsesPivotPoint = true;
659 if (buttonStyle.ParentOrigin == null) buttonStyle.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft;
660 if (buttonStyle.PivotPoint == null) buttonStyle.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft;
664 for (int i = 0; i < btGroup.Count; i++)
666 var button = GetButton(i);
667 button.ApplyStyle(buttonStyle);
671 Title.ApplyStyle(ppStyle.Title);
679 /// <returns>The default popup style.</returns>
680 [EditorBrowsable(EditorBrowsableState.Never)]
681 protected override ViewStyle CreateViewStyle()
683 return new PopupStyle();
687 [EditorBrowsable(EditorBrowsableState.Never)]
688 protected override void OnUpdate()
695 /// Initialize AT-SPI object.
697 [EditorBrowsable(EditorBrowsableState.Never)]
698 public override void OnInitialize()
701 SetAccessibilityConstructor(Role.Dialog);
702 AppendAccessibilityAttribute("sub-role", "Alert");
705 container.SetTouchConsumed(true);
706 container.SetHoverConsumed(true);
708 LeaveRequired = true;
709 PropertyChanged += PopupStylePropertyChanged;
712 ContentView = new View()
714 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
715 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
716 PositionUsesPivotPoint = true
719 ContentView.RaiseToTop();
722 btGroup = new ButtonGroup(this);
726 /// Informs AT-SPI bridge about the set of AT-SPI states associated with this object.
728 [EditorBrowsable(EditorBrowsableState.Never)]
729 protected override AccessibilityStates AccessibilityCalculateStates()
731 var states = base.AccessibilityCalculateStates();
732 states.Set(AccessibilityState.Modal, true);
736 private void UpdateView()
738 btGroup.UpdateButton(buttonStyle);
743 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
745 if (PopupButtonClickEvent != null && btGroup.Count > 0)
747 Button button = sender as Button;
748 for (int i = 0; i < btGroup.Count; i++)
750 if (button == GetButton(i))
752 ButtonClickEventArgs args = new ButtonClickEventArgs();
753 args.ButtonIndex = i;
754 PopupButtonClickEvent(this, args);
760 private void PopupStylePropertyChanged(object sender, PropertyChangedEventArgs e)
762 if (e.PropertyName.Equals("LayoutDirection"))
764 btGroup.UpdateButton(buttonStyle);
768 private void UpdateContentView()
774 string strText = Title.Text;
775 if (!string.IsNullOrEmpty(strText) && Title.Size != null)
777 titleH = (int)titleText.Size.Height;
780 if (!string.IsNullOrEmpty(strText) && Title.Position != null)
782 titleX = (int)Title.Position.X;
783 titleY = (int)Title.Position.Y;
786 if (btGroup.Count != 0)
788 buttonH = ButtonHeight;
790 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
791 ContentView.Position = new Position(titleX, titleY + titleH);
792 ContentView.RaiseToTop();
795 private void UpdateTitle()
797 if (titleText != null && string.IsNullOrEmpty(Title.Text) && Title.Size != null)
799 titleText.RaiseToTop();
803 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
805 /// <since_tizen> 6 </since_tizen>
806 [Obsolete("Deprecated in API8; Will be removed in API10")]
807 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
808 public class ButtonClickEventArgs : EventArgs
810 /// <summary> Button index which is clicked in Popup </summary>
811 /// <since_tizen> 6 </since_tizen>
812 /// It will be removed in API10
813 [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
814 [Obsolete("Deprecated in API8; Will be removed in API10")]
815 public int ButtonIndex;