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("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("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("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("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("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("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("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("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("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("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;
232 /// Creates a new instance of a Popup.
234 /// <since_tizen> 6 </since_tizen>
235 public Popup() : base()
241 /// Creates a new instance of a Popup with style.
243 /// <param name="style">Create Popup by special style defined in UX.</param>
244 /// <since_tizen> 6 </since_tizen>
245 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public Popup(string style) : base(style)
253 /// Creates a new instance of a Popup with attributes.
255 /// <param name="attributes">Create Popup by attributes customized by user.</param>
256 /// <since_tizen> 6 </since_tizen>
257 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
258 [EditorBrowsable(EditorBrowsableState.Never)]
259 public Popup(PopupStyle attributes) : base(attributes)
264 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
265 [EditorBrowsable(EditorBrowsableState.Never)]
266 public void Post(Window win)
272 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public void AddButton(string buttonText)
276 if (Style.Buttons != null)
278 Button btn = new Button(Style.Buttons);
279 btn.Style.Text.Text = buttonText;
280 btn.ClickEvent += ButtonClickEvent;
281 btGroup.AddItem(btn);
286 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 public void AddButton(string buttonText, string style)
290 AddButton(buttonText);
293 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public void AddButton(string buttonText, ButtonStyle style)
297 if (Style.Buttons != null && style != null)
299 Style.Buttons.CopyFrom(style);
300 AddButton(buttonText);
304 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 public Button GetButton(int index)
308 return btGroup.GetItem(index);
311 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
312 [EditorBrowsable(EditorBrowsableState.Never)]
313 public void RemoveButton(int index)
315 btGroup.RemoveItem(index);
318 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
319 [EditorBrowsable(EditorBrowsableState.Never)]
320 public void AddContentText(View childView)
322 if (null != ContentView)
324 ContentView.Add(childView);
330 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
332 /// <since_tizen> 6 </since_tizen>
333 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
335 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public new PopupStyle Style => ViewStyle as PopupStyle;
340 /// Title text string in Popup.
342 /// <since_tizen> 6 </since_tizen>
343 public string TitleText
347 return Style?.Title?.Text?.All;
353 if (Style.Title.Text == null)
355 Style.Title.Text = new Selector<string>();
357 Style.Title.Text.All = value;
363 /// Title text point size in Popup.
365 /// <since_tizen> 6 </since_tizen>
366 public float TitlePointSize
370 return Style?.Title?.PointSize?.All ?? 0;
374 if (Style.Title.PointSize == null)
376 Style.Title.PointSize = new Selector<float?>();
378 Style.Title.PointSize.All = value;
383 /// Title text color in Popup.
385 /// <since_tizen> 6 </since_tizen>
386 public Color TitleTextColor
390 return Style?.Title?.TextColor?.All;
394 if (Style.Title.TextColor == null)
396 Style.Title.TextColor = new Selector<Color>();
398 Style.Title.TextColor.All = value;
403 /// Title text horizontal alignment in Popup.
405 /// <since_tizen> 6 </since_tizen>
406 public HorizontalAlignment TitleTextHorizontalAlignment
410 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
414 Style.Title.HorizontalAlignment = value;
419 /// Title text's position in Popup.
421 /// <since_tizen> 6 </since_tizen>
422 public Position TitleTextPosition
426 return Style?.Title?.Position ?? new Position(0, 0, 0);
430 Style.Title.Position = value;
435 /// Title text's height in Popup.
437 /// <since_tizen> 6 </since_tizen>
438 public int TitleHeight
442 return (int)(Style?.Title?.Size?.Height ?? 0);
446 Style.Title.Size.Height = value;
451 /// Content view in Popup, only can be gotten.
453 /// <since_tizen> 6 </since_tizen>
454 public View ContentView
461 /// Button count in Popup.
463 /// <since_tizen> 6 </since_tizen>
464 public int ButtonCount
471 /// Shadow offset in Popup, including left, right, up and bottom offset.
473 /// <since_tizen> 6 </since_tizen>
474 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
475 [EditorBrowsable(EditorBrowsableState.Never)]
476 public Vector4 ShadowOffset
483 /// Button height in Popup.
485 /// <since_tizen> 6 </since_tizen>
486 public int ButtonHeight
490 return (int)GetValue(ButtonHeightProperty);
494 SetValue(ButtonHeightProperty, value);
499 /// Button text point size in Popup.
501 /// <since_tizen> 6 </since_tizen>
502 public float ButtonTextPointSize
506 return (float)GetValue(ButtonTextPointSizeProperty);
510 SetValue(ButtonTextPointSizeProperty, value);
515 /// Button text font family in Popup.
517 /// <since_tizen> 6 </since_tizen>
518 public string ButtonFontFamily
522 return (string)GetValue(ButtonFontFamilyProperty);
526 SetValue(ButtonFontFamilyProperty, value);
531 /// Button text color in Popup.
533 /// <since_tizen> 6 </since_tizen>
534 public Color ButtonTextColor
538 return (Color)GetValue(ButtonTextColorProperty);
542 SetValue(ButtonTextColorProperty, value);
547 /// Button overlay background color selector in Popup.
549 /// <since_tizen> 6 </since_tizen>
550 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
551 [EditorBrowsable(EditorBrowsableState.Never)]
552 public Selector<Color> ButtonOverLayBackgroundColorSelector
556 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
560 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
565 /// Button text horizontal alignment in Popup.
567 /// <since_tizen> 6 </since_tizen>
568 public HorizontalAlignment ButtonTextAlignment
572 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
576 SetValue(ButtonTextAlignmentProperty, value);
581 /// Button background image's resource url in Popup.
583 /// <since_tizen> 6 </since_tizen>
584 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
585 [EditorBrowsable(EditorBrowsableState.Never)]
586 public string ButtonBackground
590 return (string)GetValue(ButtonBackgroundProperty);
594 SetValue(ButtonBackgroundProperty, value);
599 /// Button background image's border in Popup.
601 /// <since_tizen> 6 </since_tizen>
602 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
603 [EditorBrowsable(EditorBrowsableState.Never)]
604 public Rectangle ButtonBackgroundBorder
609 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
613 SetValue(ButtonBackgroundBorderProperty, value);
618 /// Button shadow's resource url 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 string ButtonShadow
627 return (string)GetValue(ButtonShadowProperty);
631 SetValue(ButtonShadowProperty, value);
636 /// Button shadow's border in Popup.
638 /// <since_tizen> 6 </since_tizen>
639 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
640 [EditorBrowsable(EditorBrowsableState.Never)]
641 public Rectangle ButtonShadowBorder
646 return (Rectangle)GetValue(ButtonShadowBorderProperty);
650 SetValue(ButtonShadowBorderProperty, value);
655 /// Set button text by index.
657 /// <param name="index">Button index.</param>
658 /// <param name="text">Button text string.</param>
659 /// <since_tizen> 6 </since_tizen>
660 public void SetButtonText(int index, string text)
664 /// Dispose Popup and all children on it.
666 /// <param name="type">Dispose type.</param>
667 /// <since_tizen> 6 </since_tizen>
668 protected override void Dispose(DisposeTypes type)
675 if (type == DisposeTypes.Explicit)
677 if (titleText != null)
683 if (ContentView != null)
686 ContentView.Dispose();
701 /// Focus gained callback.
703 /// <since_tizen> 6 </since_tizen>
704 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
705 [EditorBrowsable(EditorBrowsableState.Never)]
706 public override void OnFocusGained()
708 base.OnFocusGained();
712 /// Focus lost callback.
714 /// <since_tizen> 6 </since_tizen>
715 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
716 [EditorBrowsable(EditorBrowsableState.Never)]
717 public override void OnFocusLost()
722 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
723 [EditorBrowsable(EditorBrowsableState.Never)]
724 public override void ApplyStyle(ViewStyle viewStyle)
726 base.ApplyStyle(viewStyle);
727 PopupStyle ppStyle = viewStyle as PopupStyle;
730 if (null == titleText)
732 titleText = new TextLabel();
735 titleText.RaiseToTop();
736 titleText.ApplyStyle(ppStyle.Title);
741 /// Get Popup attribues.
743 /// <since_tizen> 6 </since_tizen>
744 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
745 [EditorBrowsable(EditorBrowsableState.Never)]
746 protected override ViewStyle GetViewStyle()
748 return new PopupStyle();
752 /// Theme change callback when theme is changed, this callback will be trigger.
754 /// <since_tizen> 6 </since_tizen>
755 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
756 [EditorBrowsable(EditorBrowsableState.Never)]
757 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
759 PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
760 if (tempAttributes != null)
762 string strSaveTitleText = TitleText;
763 Style.CopyFrom(tempAttributes);
764 Style.Title.Text = strSaveTitleText;
769 private void Initialize()
771 LeaveRequired = true;
772 PropertyChanged += PopupAttributesPropertyChanged;
775 ContentView = new View()
777 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
778 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
779 PositionUsesPivotPoint = true
782 ContentView.RaiseToTop();
785 if (null == titleText)
787 titleText = new TextLabel();
788 titleText.RaiseToTop();
793 btGroup = new ButtonGroup(this);
796 private void UpdateView()
798 UpdateShadowExtens();
799 btGroup.UpdateButton(Style.Buttons);
804 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
806 if (PopupButtonClickEvent != null && btGroup.Count > 0)
808 Button button = sender as Button;
809 for (int i = 0; i < btGroup.Count; i++)
811 if (button == GetButton(i))
813 ButtonClickEventArgs args = new ButtonClickEventArgs();
814 args.ButtonIndex = i;
815 PopupButtonClickEvent(this, args);
821 private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
823 if (e.PropertyName.Equals("LayoutDirection"))
825 btGroup.UpdateButton(Style.Buttons);
829 private void UpdateContentView()
835 string strText = Style.Title.Text.All;
836 if ((strText != null && strText != "") && Style.Title.Size != null)
838 titleH = (int)titleText.Size.Height;
841 if ((strText != null && strText != "") && Style.Title.Position != null)
843 titleX = (int)Style.Title.Position.X;
844 titleY = (int)Style.Title.Position.Y;
847 if (btGroup.Count != 0)
849 buttonH = (int)Style.Buttons.Size.Height;
851 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
852 ContentView.Position = new Position(titleX, titleY + titleH);
853 ContentView.RaiseToTop();
856 private void UpdateShadowExtens()
858 if (Style.ShadowExtents != null)
860 Style.Shadow.Size = new Size(Size.Width + Style.ShadowExtents.Start + Style.ShadowExtents.End, Size.Height + Style.ShadowExtents.Top + Style.ShadowExtents.Bottom);
864 private void UpdateTitle()
866 if (titleText != null && Style.Title.Text.All != "" && Style.Title.Size != null)
868 titleText.RaiseToTop();
872 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
874 /// <since_tizen> 6 </since_tizen>
875 public class ButtonClickEventArgs : EventArgs
877 /// <summary> Button index which is clicked in Popup </summary>
878 /// <since_tizen> 6 </since_tizen>
879 public int ButtonIndex;