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 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.Style.Buttons.Size.Height = (int)newValue;
40 instance.btGroup.Itemheight = (int)newValue;
41 instance.UpdateView();
44 defaultValueCreator: (bindable) =>
46 var instance = (Popup)bindable;
47 return (int)(instance.Style?.Buttons?.Size?.Height ?? 0);
50 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
51 [EditorBrowsable(EditorBrowsableState.Never)]
52 public static readonly BindableProperty ButtonTextPointSizeProperty = BindableProperty.Create(nameof(ButtonTextPointSize), typeof(float), typeof(Popup), default(float), propertyChanged: (bindable, oldValue, newValue) =>
54 var instance = (Popup)bindable;
57 if (instance.Style.Buttons.Text.PointSize == null)
59 instance.Style.Buttons.Text.PointSize = new Selector<float?>();
61 instance.Style.Buttons.Text.PointSize.All = (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.TextColor == null)
97 instance.Style.Buttons.Text.TextColor = new Selector<Color>();
99 instance.Style.Buttons.Text.TextColor.All = (Color)newValue;
100 instance.btGroup.ItemTextColor = (Color)newValue;
103 defaultValueCreator: (bindable) =>
105 var instance = (Popup)bindable;
106 return instance.Style?.Buttons?.Text?.TextColor?.All;
109 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public static readonly BindableProperty ButtonOverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(ButtonOverLayBackgroundColorSelector), typeof(Selector<Color>), typeof(Popup), new Selector<Color>(), propertyChanged: (bindable, oldValue, newValue) =>
113 var instance = (Popup)bindable;
114 if (newValue != null)
116 instance.Style.Buttons.Overlay.BackgroundColor = (Selector<Color>)newValue;
117 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
120 defaultValueCreator: (bindable) =>
122 var instance = (Popup)bindable;
123 return instance.Style?.Buttons?.Overlay?.BackgroundColor;
126 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
127 [EditorBrowsable(EditorBrowsableState.Never)]
128 public static readonly BindableProperty ButtonTextAlignmentProperty = BindableProperty.Create(nameof(ButtonTextAlignment), typeof(HorizontalAlignment), typeof(Popup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) =>
130 var instance = (Popup)bindable;
131 if (newValue != null)
133 instance.Style.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
134 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
137 defaultValueCreator: (bindable) =>
139 var instance = (Popup)bindable;
140 return instance.Style?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
143 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 public static readonly BindableProperty ButtonBackgroundProperty = BindableProperty.Create(nameof(ButtonBackground), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
147 var instance = (Popup)bindable;
148 if (newValue != null)
150 if (instance.Style.Buttons.BackgroundImage == null)
152 instance.Style.Buttons.BackgroundImage = new Selector<string>();
154 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
155 instance.Style.Buttons.BackgroundImage = (string)newValue;
158 defaultValueCreator: (bindable) =>
160 var instance = (Popup)bindable;
161 return instance.Style?.Buttons?.BackgroundImage?.All;
164 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
165 [EditorBrowsable(EditorBrowsableState.Never)]
166 public static readonly BindableProperty ButtonBackgroundBorderProperty = BindableProperty.Create(nameof(ButtonBackgroundBorder), typeof(Rectangle), typeof(Popup), new Rectangle(0, 0, 0, 0), propertyChanged: (bindable, oldValue, newValue) =>
168 var instance = (Popup)bindable;
169 if (newValue != null)
171 if (instance.Style.Buttons.BackgroundImageBorder == null)
173 instance.Style.Buttons.BackgroundImageBorder = new Selector<Rectangle>();
175 instance.Style.Buttons.BackgroundImageBorder = (Rectangle)newValue;
176 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
179 defaultValueCreator: (bindable) =>
181 var instance = (Popup)bindable;
182 return instance.Style?.Buttons?.BackgroundImageBorder?.All;
185 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public static readonly BindableProperty ButtonShadowProperty = BindableProperty.Create(nameof(ButtonShadow), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
189 var instance = (Popup)bindable;
190 if (newValue != null)
192 if (instance.Style.Buttons.Shadow.ResourceUrl == null)
194 instance.Style.Buttons.Shadow.ResourceUrl = new Selector<string>();
196 instance.btGroup.ItemShadowUrl = (string)newValue;
197 instance.Style.Buttons.Shadow.ResourceUrl = (string)newValue;
200 defaultValueCreator: (bindable) =>
202 var instance = (Popup)bindable;
203 return instance.Style?.Buttons?.Shadow?.ResourceUrl?.All;
206 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
207 [EditorBrowsable(EditorBrowsableState.Never)]
208 public static readonly BindableProperty ButtonShadowBorderProperty = BindableProperty.Create(nameof(ButtonShadowBorder), typeof(Rectangle), typeof(Popup), new Rectangle(0, 0, 0, 0), propertyChanged: (bindable, oldValue, newValue) =>
210 var instance = (Popup)bindable;
211 if (newValue != null)
213 if (instance.Style.Buttons.Shadow.Border == null)
215 instance.Style.Buttons.Shadow.Border = new Selector<Rectangle>();
217 instance.btGroup.ItemShadowBorder = (Rectangle)newValue;
218 instance.Style.Buttons.Shadow.Border = (Rectangle)newValue;
221 defaultValueCreator: (bindable) =>
223 var instance = (Popup)bindable;
224 return instance.Style?.Buttons?.Shadow?.Border?.All;
227 private TextLabel titleText;
228 private ButtonGroup btGroup = null;
229 private Window window = null;
233 /// Creates a new instance of a Popup.
235 /// <since_tizen> 6 </since_tizen>
236 public Popup() : base()
242 /// Creates a new instance of a Popup with style.
244 /// <param name="style">Create Popup by special style defined in UX.</param>
245 /// <since_tizen> 6 </since_tizen>
246 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
247 [EditorBrowsable(EditorBrowsableState.Never)]
248 public Popup(string style) : base(style)
254 /// Creates a new instance of a Popup with attributes.
256 /// <param name="attributes">Create Popup by attributes customized by user.</param>
257 /// <since_tizen> 6 </since_tizen>
258 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
259 [EditorBrowsable(EditorBrowsableState.Never)]
260 public Popup(PopupStyle attributes) : base(attributes)
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 Post(Window win)
269 if (null == win) return;
274 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
275 [EditorBrowsable(EditorBrowsableState.Never)]
276 public void AddButton(string buttonText)
278 if (Style.Buttons != null)
280 Button btn = new Button(Style.Buttons);
281 btn.Style.Text.Text = buttonText;
282 btn.ClickEvent += ButtonClickEvent;
283 btGroup.AddItem(btn);
288 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
289 [EditorBrowsable(EditorBrowsableState.Never)]
290 public void AddButton(string buttonText, string style)
292 AddButton(buttonText);
295 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
296 [EditorBrowsable(EditorBrowsableState.Never)]
297 public void AddButton(string buttonText, ButtonStyle style)
299 if (Style.Buttons != null && style != null)
301 Style.Buttons.CopyFrom(style);
302 AddButton(buttonText);
306 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
307 [EditorBrowsable(EditorBrowsableState.Never)]
308 public Button GetButton(int index)
310 return btGroup.GetItem(index);
313 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
314 [EditorBrowsable(EditorBrowsableState.Never)]
315 public void RemoveButton(int index)
317 btGroup.RemoveItem(index);
320 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
321 [EditorBrowsable(EditorBrowsableState.Never)]
322 public void AddContentText(View childView)
324 if (null != ContentView)
326 ContentView.Add(childView);
332 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
334 /// <since_tizen> 6 </since_tizen>
335 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
337 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
338 [EditorBrowsable(EditorBrowsableState.Never)]
339 public new PopupStyle Style => ViewStyle as PopupStyle;
342 /// Title text string in Popup.
344 /// <since_tizen> 6 </since_tizen>
345 public string TitleText
349 return Style?.Title?.Text?.All;
355 if (Style.Title.Text == null)
357 Style.Title.Text = new Selector<string>();
359 Style.Title.Text.All = value;
365 /// Title text point size in Popup.
367 /// <since_tizen> 6 </since_tizen>
368 public float TitlePointSize
372 return Style?.Title?.PointSize?.All ?? 0;
376 if (Style.Title.PointSize == null)
378 Style.Title.PointSize = new Selector<float?>();
380 Style.Title.PointSize.All = value;
385 /// Title text color in Popup.
387 /// <since_tizen> 6 </since_tizen>
388 public Color TitleTextColor
392 return Style?.Title?.TextColor?.All;
396 if (Style.Title.TextColor == null)
398 Style.Title.TextColor = new Selector<Color>();
400 Style.Title.TextColor.All = value;
405 /// Title text horizontal alignment in Popup.
407 /// <since_tizen> 6 </since_tizen>
408 public HorizontalAlignment TitleTextHorizontalAlignment
412 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
416 Style.Title.HorizontalAlignment = value;
421 /// Title text's position in Popup.
423 /// <since_tizen> 6 </since_tizen>
424 public Position TitleTextPosition
428 return Style?.Title?.Position ?? new Position(0, 0, 0);
432 Style.Title.Position = value;
437 /// Title text's height in Popup.
439 /// <since_tizen> 6 </since_tizen>
440 public int TitleHeight
444 return (int)(Style?.Title?.Size?.Height ?? 0);
448 Style.Title.Size.Height = value;
453 /// Content view in Popup, only can be gotten.
455 /// <since_tizen> 6 </since_tizen>
456 public View ContentView
463 /// Button count in Popup.
465 /// <since_tizen> 6 </since_tizen>
466 public int ButtonCount
473 /// Shadow offset in Popup, including left, right, up and bottom offset.
475 /// <since_tizen> 6 </since_tizen>
476 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
477 [EditorBrowsable(EditorBrowsableState.Never)]
478 public Vector4 ShadowOffset
485 /// Button height in Popup.
487 /// <since_tizen> 6 </since_tizen>
488 public int ButtonHeight
492 return (int)GetValue(ButtonHeightProperty);
496 SetValue(ButtonHeightProperty, value);
501 /// Button text point size in Popup.
503 /// <since_tizen> 6 </since_tizen>
504 public float ButtonTextPointSize
508 return (float)GetValue(ButtonTextPointSizeProperty);
512 SetValue(ButtonTextPointSizeProperty, value);
517 /// Button text font family in Popup.
519 /// <since_tizen> 6 </since_tizen>
520 public string ButtonFontFamily
524 return (string)GetValue(ButtonFontFamilyProperty);
528 SetValue(ButtonFontFamilyProperty, value);
533 /// Button text color in Popup.
535 /// <since_tizen> 6 </since_tizen>
536 public Color ButtonTextColor
540 return (Color)GetValue(ButtonTextColorProperty);
544 SetValue(ButtonTextColorProperty, value);
549 /// Button overlay background color selector in Popup.
551 /// <since_tizen> 6 </since_tizen>
552 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
553 [EditorBrowsable(EditorBrowsableState.Never)]
554 public Selector<Color> ButtonOverLayBackgroundColorSelector
558 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
562 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
567 /// Button text horizontal alignment in Popup.
569 /// <since_tizen> 6 </since_tizen>
570 public HorizontalAlignment ButtonTextAlignment
574 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
578 SetValue(ButtonTextAlignmentProperty, value);
583 /// Button background image's resource url in Popup.
585 /// <since_tizen> 6 </since_tizen>
586 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
587 [EditorBrowsable(EditorBrowsableState.Never)]
588 public string ButtonBackground
592 return (string)GetValue(ButtonBackgroundProperty);
596 SetValue(ButtonBackgroundProperty, value);
601 /// Button background image's border in Popup.
603 /// <since_tizen> 6 </since_tizen>
604 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
605 [EditorBrowsable(EditorBrowsableState.Never)]
606 public Rectangle ButtonBackgroundBorder
611 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
615 SetValue(ButtonBackgroundBorderProperty, value);
620 /// Button shadow's resource url in Popup.
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 string ButtonShadow
629 return (string)GetValue(ButtonShadowProperty);
633 SetValue(ButtonShadowProperty, value);
638 /// Button shadow's border in Popup.
640 /// <since_tizen> 6 </since_tizen>
641 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
642 [EditorBrowsable(EditorBrowsableState.Never)]
643 public Rectangle ButtonShadowBorder
648 return (Rectangle)GetValue(ButtonShadowBorderProperty);
652 SetValue(ButtonShadowBorderProperty, value);
657 /// Set button text by index.
659 /// <param name="index">Button index.</param>
660 /// <param name="text">Button text string.</param>
661 /// <since_tizen> 6 </since_tizen>
662 public void SetButtonText(int index, string text)
666 /// Dispose Popup and all children on it.
668 /// <param name="type">Dispose type.</param>
669 /// <since_tizen> 6 </since_tizen>
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()
724 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
725 [EditorBrowsable(EditorBrowsableState.Never)]
726 public override void ApplyStyle(ViewStyle viewStyle)
728 base.ApplyStyle(viewStyle);
729 PopupStyle ppStyle = viewStyle as PopupStyle;
732 if (null == titleText)
734 titleText = new TextLabel();
737 titleText.RaiseToTop();
738 titleText.ApplyStyle(ppStyle.Title);
743 /// Get Popup attribues.
745 /// <since_tizen> 6 </since_tizen>
746 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
747 [EditorBrowsable(EditorBrowsableState.Never)]
748 protected override ViewStyle GetViewStyle()
750 return new PopupStyle();
754 /// Theme change callback when theme is changed, this callback will be trigger.
756 /// <since_tizen> 6 </since_tizen>
757 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
758 [EditorBrowsable(EditorBrowsableState.Never)]
759 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
761 PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
762 if (tempAttributes != null)
764 string strSaveTitleText = TitleText;
765 Style.CopyFrom(tempAttributes);
766 Style.Title.Text = strSaveTitleText;
771 private void Initialize()
773 LeaveRequired = true;
774 PropertyChanged += PopupAttributesPropertyChanged;
777 ContentView = new View()
779 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
780 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
781 PositionUsesPivotPoint = true
784 ContentView.RaiseToTop();
787 if (null == titleText)
789 titleText = new TextLabel();
790 titleText.RaiseToTop();
795 btGroup = new ButtonGroup(this);
798 private void UpdateView()
800 UpdateShadowExtens();
801 btGroup.UpdateButton(Style.Buttons);
806 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
808 if (PopupButtonClickEvent != null && btGroup.Count > 0)
810 Button button = sender as Button;
811 for (int i = 0; i < btGroup.Count; i++)
813 if (button == GetButton(i))
815 ButtonClickEventArgs args = new ButtonClickEventArgs();
816 args.ButtonIndex = i;
817 PopupButtonClickEvent(this, args);
823 private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
825 if (e.PropertyName.Equals("LayoutDirection"))
827 btGroup.UpdateButton(Style.Buttons);
831 private void UpdateContentView()
837 string strText = Style.Title.Text.All;
838 if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
840 titleH = (int)titleText.Size.Height;
843 if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
845 titleX = (int)Style.Title.Position.X;
846 titleY = (int)Style.Title.Position.Y;
849 if (btGroup.Count != 0)
851 buttonH = (int)Style.Buttons.Size.Height;
853 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
854 ContentView.Position = new Position(titleX, titleY + titleH);
855 ContentView.RaiseToTop();
858 private void UpdateShadowExtens()
860 if (Style.ShadowExtents != null)
862 Style.Shadow.Size = new Size(Size.Width + Style.ShadowExtents.Start + Style.ShadowExtents.End, Size.Height + Style.ShadowExtents.Top + Style.ShadowExtents.Bottom);
866 private void UpdateTitle()
868 if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
870 titleText.RaiseToTop();
874 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
876 /// <since_tizen> 6 </since_tizen>
877 public class ButtonClickEventArgs : EventArgs
879 /// <summary> Button index which is clicked in Popup </summary>
880 /// <since_tizen> 6 </since_tizen>
881 public int ButtonIndex;