2 * Copyright(c) 2019 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 System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21 using System.ComponentModel;
23 namespace Tizen.NUI.Components
26 /// Popup is one kind of common component, it can be used as popup window.
27 /// User can handle Popup button count, head title and content area.
29 /// <since_tizen> 6 </since_tizen>
30 [Obsolete("Deprecated in API8; Will be removed in API10")]
31 public class Popup : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ButtonHeightProperty = BindableProperty.Create(nameof(ButtonHeight), typeof(int), typeof(Popup), default(int), propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (Popup)bindable;
38 if (newValue != null && instance?.Style?.Buttons?.Size != null )
40 instance.Style.Buttons.Size.Height = (int)newValue;
41 instance.btGroup.Itemheight = (int)newValue;
42 instance.UpdateView();
45 defaultValueCreator: (bindable) =>
47 var instance = (Popup)bindable;
48 return (int)(instance.Style?.Buttons?.Size?.Height ?? 0);
51 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public static readonly BindableProperty ButtonTextPointSizeProperty = BindableProperty.Create(nameof(ButtonTextPointSize), typeof(float), typeof(Popup), default(float), propertyChanged: (bindable, oldValue, newValue) =>
55 var instance = (Popup)bindable;
58 if (instance.Style?.Buttons?.Text != null)
60 instance.Style.Buttons.Text.PointSize = (float)newValue;
62 instance.btGroup.ItemPointSize = (float)newValue;
65 defaultValueCreator: (bindable) =>
67 var instance = (Popup)bindable;
68 return instance.Style?.Buttons?.Text?.PointSize?.All ?? 0;
71 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public static readonly BindableProperty ButtonFontFamilyProperty = BindableProperty.Create(nameof(ButtonFontFamily), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
75 var instance = (Popup)bindable;
78 instance.Style.Buttons.Text.FontFamily = (string)newValue;
79 instance.btGroup.ItemFontFamily = (string)newValue;
82 defaultValueCreator: (bindable) =>
84 var instance = (Popup)bindable;
85 return instance.Style?.Buttons?.Text?.FontFamily.All;
88 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
89 [EditorBrowsable(EditorBrowsableState.Never)]
90 public static readonly BindableProperty ButtonTextColorProperty = BindableProperty.Create(nameof(ButtonTextColor), typeof(Color), typeof(Popup), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) =>
92 var instance = (Popup)bindable;
95 if (instance.Style?.Buttons?.Text != null)
97 instance.Style.Buttons.Text.TextColor = (Color)newValue;
99 instance.btGroup.ItemTextColor = (Color)newValue;
102 defaultValueCreator: (bindable) =>
104 var instance = (Popup)bindable;
105 return instance.Style?.Buttons?.Text?.TextColor?.All;
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 ButtonOverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(ButtonOverLayBackgroundColorSelector), typeof(Selector<Color>), typeof(Popup), new Selector<Color>(), propertyChanged: (bindable, oldValue, newValue) =>
112 var instance = (Popup)bindable;
113 if (newValue != null)
115 instance.Style.Buttons.Overlay.BackgroundColor = (Selector<Color>)newValue;
116 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
119 defaultValueCreator: (bindable) =>
121 var instance = (Popup)bindable;
122 return instance.Style?.Buttons?.Overlay?.BackgroundColor;
125 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public static readonly BindableProperty ButtonTextAlignmentProperty = BindableProperty.Create(nameof(ButtonTextAlignment), typeof(HorizontalAlignment), typeof(Popup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) =>
129 var instance = (Popup)bindable;
130 if (newValue != null)
132 instance.Style.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
133 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
136 defaultValueCreator: (bindable) =>
138 var instance = (Popup)bindable;
139 return instance.Style?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
142 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public static readonly BindableProperty ButtonBackgroundProperty = BindableProperty.Create(nameof(ButtonBackground), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
146 var instance = (Popup)bindable;
147 if (newValue != null)
149 if (instance.Style.Buttons.BackgroundImage == null)
151 instance.Style.Buttons.BackgroundImage = new Selector<string>();
153 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
154 instance.Style.Buttons.BackgroundImage = (string)newValue;
157 defaultValueCreator: (bindable) =>
159 var instance = (Popup)bindable;
160 return instance.Style?.Buttons?.BackgroundImage?.All;
163 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
164 [EditorBrowsable(EditorBrowsableState.Never)]
165 public static readonly BindableProperty ButtonBackgroundBorderProperty = BindableProperty.Create(nameof(ButtonBackgroundBorder), typeof(Rectangle), typeof(Popup), new Rectangle(0, 0, 0, 0), propertyChanged: (bindable, oldValue, newValue) =>
167 var instance = (Popup)bindable;
168 if (newValue != null)
170 if (instance.Style.Buttons.BackgroundImageBorder == null)
172 instance.Style.Buttons.BackgroundImageBorder = new Selector<Rectangle>();
174 instance.Style.Buttons.BackgroundImageBorder = (Rectangle)newValue;
175 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
178 defaultValueCreator: (bindable) =>
180 var instance = (Popup)bindable;
181 return instance.Style?.Buttons?.BackgroundImageBorder?.All;
184 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 public static readonly BindableProperty ButtonImageShadowProperty = BindableProperty.Create(nameof(ButtonImageShadow), typeof(ImageShadow), typeof(Popup), null, propertyChanged: (bindable, oldValue, newValue) =>
188 var instance = (Popup)bindable;
189 ImageShadow shadow = (ImageShadow)newValue;
190 instance.btGroup.ItemImageShadow = new ImageShadow(shadow);
191 instance.Style.Buttons.ImageShadow = new ImageShadow(shadow);
193 defaultValueCreator: (bindable) =>
195 var instance = (Popup)bindable;
196 return instance.Style?.Buttons?.ImageShadow?.All;
200 private TextLabel titleText;
201 private ButtonGroup btGroup = null;
202 private Window window = null;
203 private Layer container = new Layer();
207 /// Creates a new instance of a Popup.
209 /// <since_tizen> 6 </since_tizen>
210 [Obsolete("Deprecated in API8; Will be removed in API10")]
211 public Popup() : base()
217 /// Creates a new instance of a Popup with style.
219 /// <param name="style">Create Popup by special style defined in UX.</param>
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public Popup(string style) : base(style)
227 /// Creates a new instance of a Popup with style.
229 /// <param name="popupStyle">Create Popup by style customized by user.</param>
230 [EditorBrowsable(EditorBrowsableState.Never)]
231 public Popup(PopupStyle popupStyle) : base(popupStyle)
236 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
237 [EditorBrowsable(EditorBrowsableState.Never)]
238 public virtual void Post(Window targetWindow)
240 if (targetWindow == null)
245 window = targetWindow;
246 window.AddLayer(container);
247 container.RaiseToTop();
251 /// Dismiss the dialog
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public virtual void Dismiss()
261 window.RemoveLayer(container);
265 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
266 [EditorBrowsable(EditorBrowsableState.Never)]
267 public void AddButton(string buttonText)
269 if (Style.Buttons != null)
271 Button btn = new Button(Style.Buttons);
272 btn.Style.Text.Text = buttonText;
273 btn.ClickEvent += ButtonClickEvent;
274 btGroup.AddItem(btn);
280 /// Add button by style's name.
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public void AddButton(string buttonText, string style)
285 AddButton(buttonText);
289 /// Add button by style.
291 [EditorBrowsable(EditorBrowsableState.Never)]
292 public void AddButton(string buttonText, ButtonStyle style)
294 if (Style.Buttons != null && style != null)
296 Style.Buttons.CopyFrom(style);
297 AddButton(buttonText);
301 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
302 [EditorBrowsable(EditorBrowsableState.Never)]
303 public Button GetButton(int index)
305 return btGroup.GetItem(index);
308 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
309 [EditorBrowsable(EditorBrowsableState.Never)]
310 public void RemoveButton(int index)
312 btGroup.RemoveItem(index);
315 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
316 [EditorBrowsable(EditorBrowsableState.Never)]
317 public void AddContentText(View childView)
319 if (null != ContentView)
321 ContentView.Add(childView);
327 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
329 /// <since_tizen> 6 </since_tizen>
330 [Obsolete("Deprecated in API8; Will be removed in API10")]
331 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
334 /// Get style of popup.
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public new PopupStyle Style => ViewStyle as PopupStyle;
342 [EditorBrowsable(EditorBrowsableState.Never)]
343 public TextLabel Title
347 if (null == titleText)
349 titleText = new TextLabel();
361 /// Title text string in Popup.
363 /// <since_tizen> 6 </since_tizen>
364 [Obsolete("Deprecated in API8; Will be removed in API10")]
365 public string TitleText
369 return Style?.Title?.Text?.All;
375 if (Style?.Title != null)
377 Style.Title.Text = value;
384 /// Title text point size in Popup.
386 /// <since_tizen> 6 </since_tizen>
387 [Obsolete("Deprecated in API8; Will be removed in API10")]
388 public float TitlePointSize
392 return Style?.Title?.PointSize?.All ?? 0;
396 if (Style?.Title != null)
398 Style.Title.PointSize = value;
404 /// Title text color in Popup.
406 /// <since_tizen> 6 </since_tizen>
407 [Obsolete("Deprecated in API8; Will be removed in API10")]
408 public Color TitleTextColor
412 return Style?.Title?.TextColor?.All;
416 if (Style?.Title != null)
418 Style.Title.TextColor = value;
424 /// Title text horizontal alignment in Popup.
426 /// <since_tizen> 6 </since_tizen>
427 [Obsolete("Deprecated in API8; Will be removed in API10")]
428 public HorizontalAlignment TitleTextHorizontalAlignment
432 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
436 Style.Title.HorizontalAlignment = value;
441 /// Title text's position in Popup.
443 /// <since_tizen> 6 </since_tizen>
444 [Obsolete("Deprecated in API8; Will be removed in API10")]
445 public Position TitleTextPosition
449 return Style?.Title?.Position ?? new Position(0, 0, 0);
453 Style.Title.Position = value;
458 /// Title text's height in Popup.
460 /// <since_tizen> 6 </since_tizen>
461 [Obsolete("Deprecated in API8; Will be removed in API10")]
462 public int TitleHeight
466 return (int)(Style?.Title?.Size?.Height ?? 0);
470 if (Style?.Title?.Size != null)
472 Style.Title.Size.Height = value;
478 /// Content view in Popup, only can be gotten.
480 /// <since_tizen> 6 </since_tizen>
481 [Obsolete("Deprecated in API8; Will be removed in API10")]
482 public View ContentView
489 /// Button count in Popup.
491 /// <since_tizen> 6 </since_tizen>
492 [Obsolete("Deprecated in API8; Will be removed in API10")]
493 public int ButtonCount
500 /// Button height in Popup.
502 /// <since_tizen> 6 </since_tizen>
503 [Obsolete("Deprecated in API8; Will be removed in API10")]
504 public int ButtonHeight
508 return (int)GetValue(ButtonHeightProperty);
512 SetValue(ButtonHeightProperty, value);
517 /// Button text point size in Popup.
519 /// <since_tizen> 6 </since_tizen>
520 [Obsolete("Deprecated in API8; Will be removed in API10")]
521 public float ButtonTextPointSize
525 return (float)GetValue(ButtonTextPointSizeProperty);
529 SetValue(ButtonTextPointSizeProperty, value);
534 /// Button text font family in Popup.
536 /// <since_tizen> 6 </since_tizen>
537 [Obsolete("Deprecated in API8; Will be removed in API10")]
538 public string ButtonFontFamily
542 return (string)GetValue(ButtonFontFamilyProperty);
546 SetValue(ButtonFontFamilyProperty, value);
551 /// Button text color in Popup.
553 /// <since_tizen> 6 </since_tizen>
554 [Obsolete("Deprecated in API8; Will be removed in API10")]
555 public Color ButtonTextColor
559 return (Color)GetValue(ButtonTextColorProperty);
563 SetValue(ButtonTextColorProperty, value);
568 /// Button overlay background color selector in Popup.
570 /// <since_tizen> 6 </since_tizen>
571 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
572 [EditorBrowsable(EditorBrowsableState.Never)]
573 public Selector<Color> ButtonOverLayBackgroundColorSelector
577 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
581 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
586 /// Button text horizontal alignment in Popup.
588 /// <since_tizen> 6 </since_tizen>
589 [Obsolete("Deprecated in API8; Will be removed in API10")]
590 public HorizontalAlignment ButtonTextAlignment
594 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
598 SetValue(ButtonTextAlignmentProperty, value);
603 /// Button background image's resource url in Popup.
605 /// <since_tizen> 6 </since_tizen>
606 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
607 [EditorBrowsable(EditorBrowsableState.Never)]
608 public string ButtonBackground
612 return (string)GetValue(ButtonBackgroundProperty);
616 SetValue(ButtonBackgroundProperty, value);
621 /// Button background image's border in Popup.
623 /// <since_tizen> 6 </since_tizen>
624 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
625 [EditorBrowsable(EditorBrowsableState.Never)]
626 public Rectangle ButtonBackgroundBorder
631 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
635 SetValue(ButtonBackgroundBorderProperty, value);
640 /// Button's image shadow in Popup.
642 /// <since_tizen> 6 </since_tizen>
643 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
644 [EditorBrowsable(EditorBrowsableState.Never)]
645 public ImageShadow ButtonImageShadow
647 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
648 set => SetValue(ButtonImageShadowProperty, value);
653 /// Set button text by index.
655 /// <param name="index">Button index.</param>
656 /// <param name="text">Button text string.</param>
657 /// <since_tizen> 6 </since_tizen>
658 [Obsolete("Deprecated in API8; Will be removed in API10")]
659 public void SetButtonText(int index, string text)
665 /// Dispose Popup and all children on it.
667 /// <param name="type">Dispose type.</param>
668 /// <since_tizen> 6 </since_tizen>
669 [Obsolete("Deprecated in API8; Will be removed in API10")]
670 protected override void Dispose(DisposeTypes type)
677 if (type == DisposeTypes.Explicit)
679 if (titleText != null)
685 if (ContentView != null)
688 ContentView.Dispose();
703 /// Focus gained callback.
705 /// <since_tizen> 6 </since_tizen>
706 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
707 [EditorBrowsable(EditorBrowsableState.Never)]
708 public override void OnFocusGained()
710 base.OnFocusGained();
714 /// Focus lost callback.
716 /// <since_tizen> 6 </since_tizen>
717 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
718 [EditorBrowsable(EditorBrowsableState.Never)]
719 public override void OnFocusLost()
725 /// Apply style to popup.
727 /// <param name="viewStyle">The style to apply.</param>
728 [EditorBrowsable(EditorBrowsableState.Never)]
729 public override void ApplyStyle(ViewStyle viewStyle)
731 base.ApplyStyle(viewStyle);
732 PopupStyle ppStyle = viewStyle as PopupStyle;
735 Title.ApplyStyle(ppStyle.Title);
743 /// <returns>The default popup style.</returns>
744 [EditorBrowsable(EditorBrowsableState.Never)]
745 protected override ViewStyle CreateViewStyle()
747 return new PopupStyle();
751 /// Theme change callback when theme is changed, this callback will be trigger.
753 /// <param name="sender">The sender</param>
754 /// <param name="e">The event data</param>
755 [EditorBrowsable(EditorBrowsableState.Never)]
756 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
758 PopupStyle popupStyle = StyleManager.Instance.GetViewStyle(StyleName) as PopupStyle;
759 if (popupStyle != null)
761 string strSaveTitleText = TitleText;
762 Style.CopyFrom(popupStyle);
763 Style.Title.Text = strSaveTitleText;
768 private void Initialize()
771 container.SetTouchConsumed(true);
772 container.SetHoverConsumed(true);
774 LeaveRequired = true;
775 PropertyChanged += PopupStylePropertyChanged;
778 ContentView = new View()
780 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
781 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
782 PositionUsesPivotPoint = true
785 ContentView.RaiseToTop();
788 btGroup = new ButtonGroup(this);
791 private void UpdateView()
793 btGroup.UpdateButton(Style.Buttons);
798 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
800 if (PopupButtonClickEvent != null && btGroup.Count > 0)
802 Button button = sender as Button;
803 for (int i = 0; i < btGroup.Count; i++)
805 if (button == GetButton(i))
807 ButtonClickEventArgs args = new ButtonClickEventArgs();
808 args.ButtonIndex = i;
809 PopupButtonClickEvent(this, args);
815 private void PopupStylePropertyChanged(object sender, PropertyChangedEventArgs e)
817 if (e.PropertyName.Equals("LayoutDirection"))
819 btGroup.UpdateButton(Style.Buttons);
823 private void UpdateContentView()
829 string strText = Style.Title.Text.All;
830 if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
832 titleH = (int)titleText.Size.Height;
835 if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
837 titleX = (int)Style.Title.Position.X;
838 titleY = (int)Style.Title.Position.Y;
841 if (btGroup.Count != 0 && Style?.Buttons?.Size != null )
843 buttonH = (int)Style.Buttons.Size.Height;
845 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
846 ContentView.Position = new Position(titleX, titleY + titleH);
847 ContentView.RaiseToTop();
850 private void UpdateTitle()
852 if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
854 titleText.RaiseToTop();
858 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
860 /// <since_tizen> 6 </since_tizen>
861 [Obsolete("Deprecated in API8; Will be removed in API10")]
862 public class ButtonClickEventArgs : EventArgs
864 /// <summary> Button index which is clicked in Popup </summary>
865 /// <since_tizen> 6 </since_tizen>
866 [Obsolete("Deprecated in API8; Will be removed in API10")]
867 public int ButtonIndex;