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;
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)
268 if (null == win) return;
273 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
274 [EditorBrowsable(EditorBrowsableState.Never)]
275 public void AddButton(string buttonText)
277 if (Style.Buttons != null)
279 Button btn = new Button(Style.Buttons);
280 btn.Style.Text.Text = buttonText;
281 btn.ClickEvent += ButtonClickEvent;
282 btGroup.AddItem(btn);
287 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
288 [EditorBrowsable(EditorBrowsableState.Never)]
289 public void AddButton(string buttonText, string style)
291 AddButton(buttonText);
294 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
295 [EditorBrowsable(EditorBrowsableState.Never)]
296 public void AddButton(string buttonText, ButtonStyle style)
298 if (Style.Buttons != null && style != null)
300 Style.Buttons.CopyFrom(style);
301 AddButton(buttonText);
305 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
306 [EditorBrowsable(EditorBrowsableState.Never)]
307 public Button GetButton(int index)
309 return btGroup.GetItem(index);
312 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
313 [EditorBrowsable(EditorBrowsableState.Never)]
314 public void RemoveButton(int index)
316 btGroup.RemoveItem(index);
319 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
320 [EditorBrowsable(EditorBrowsableState.Never)]
321 public void AddContentText(View childView)
323 if (null != ContentView)
325 ContentView.Add(childView);
331 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
333 /// <since_tizen> 6 </since_tizen>
334 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
336 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public new PopupStyle Style => ViewStyle as PopupStyle;
341 /// Title text string in Popup.
343 /// <since_tizen> 6 </since_tizen>
344 public string TitleText
348 return Style?.Title?.Text?.All;
354 if (Style.Title.Text == null)
356 Style.Title.Text = new Selector<string>();
358 Style.Title.Text.All = value;
364 /// Title text point size in Popup.
366 /// <since_tizen> 6 </since_tizen>
367 public float TitlePointSize
371 return Style?.Title?.PointSize?.All ?? 0;
375 if (Style.Title.PointSize == null)
377 Style.Title.PointSize = new Selector<float?>();
379 Style.Title.PointSize.All = value;
384 /// Title text color in Popup.
386 /// <since_tizen> 6 </since_tizen>
387 public Color TitleTextColor
391 return Style?.Title?.TextColor?.All;
395 if (Style.Title.TextColor == null)
397 Style.Title.TextColor = new Selector<Color>();
399 Style.Title.TextColor.All = value;
404 /// Title text horizontal alignment in Popup.
406 /// <since_tizen> 6 </since_tizen>
407 public HorizontalAlignment TitleTextHorizontalAlignment
411 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
415 Style.Title.HorizontalAlignment = value;
420 /// Title text's position in Popup.
422 /// <since_tizen> 6 </since_tizen>
423 public Position TitleTextPosition
427 return Style?.Title?.Position ?? new Position(0, 0, 0);
431 Style.Title.Position = value;
436 /// Title text's height in Popup.
438 /// <since_tizen> 6 </since_tizen>
439 public int TitleHeight
443 return (int)(Style?.Title?.Size?.Height ?? 0);
447 Style.Title.Size.Height = value;
452 /// Content view in Popup, only can be gotten.
454 /// <since_tizen> 6 </since_tizen>
455 public View ContentView
462 /// Button count in Popup.
464 /// <since_tizen> 6 </since_tizen>
465 public int ButtonCount
472 /// Shadow offset in Popup, including left, right, up and bottom offset.
474 /// <since_tizen> 6 </since_tizen>
475 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
476 [EditorBrowsable(EditorBrowsableState.Never)]
477 public Vector4 ShadowOffset
484 /// Button height in Popup.
486 /// <since_tizen> 6 </since_tizen>
487 public int ButtonHeight
491 return (int)GetValue(ButtonHeightProperty);
495 SetValue(ButtonHeightProperty, value);
500 /// Button text point size in Popup.
502 /// <since_tizen> 6 </since_tizen>
503 public float ButtonTextPointSize
507 return (float)GetValue(ButtonTextPointSizeProperty);
511 SetValue(ButtonTextPointSizeProperty, value);
516 /// Button text font family in Popup.
518 /// <since_tizen> 6 </since_tizen>
519 public string ButtonFontFamily
523 return (string)GetValue(ButtonFontFamilyProperty);
527 SetValue(ButtonFontFamilyProperty, value);
532 /// Button text color in Popup.
534 /// <since_tizen> 6 </since_tizen>
535 public Color ButtonTextColor
539 return (Color)GetValue(ButtonTextColorProperty);
543 SetValue(ButtonTextColorProperty, value);
548 /// Button overlay background color selector in Popup.
550 /// <since_tizen> 6 </since_tizen>
551 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
552 [EditorBrowsable(EditorBrowsableState.Never)]
553 public Selector<Color> ButtonOverLayBackgroundColorSelector
557 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
561 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
566 /// Button text horizontal alignment in Popup.
568 /// <since_tizen> 6 </since_tizen>
569 public HorizontalAlignment ButtonTextAlignment
573 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
577 SetValue(ButtonTextAlignmentProperty, value);
582 /// Button background image's resource url in Popup.
584 /// <since_tizen> 6 </since_tizen>
585 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
586 [EditorBrowsable(EditorBrowsableState.Never)]
587 public string ButtonBackground
591 return (string)GetValue(ButtonBackgroundProperty);
595 SetValue(ButtonBackgroundProperty, value);
600 /// Button background image's border 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 Rectangle ButtonBackgroundBorder
610 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
614 SetValue(ButtonBackgroundBorderProperty, value);
619 /// Button shadow's resource url in Popup.
621 /// <since_tizen> 6 </since_tizen>
622 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
623 [EditorBrowsable(EditorBrowsableState.Never)]
624 public string ButtonShadow
628 return (string)GetValue(ButtonShadowProperty);
632 SetValue(ButtonShadowProperty, value);
637 /// Button shadow's border 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 Rectangle ButtonShadowBorder
647 return (Rectangle)GetValue(ButtonShadowBorderProperty);
651 SetValue(ButtonShadowBorderProperty, value);
656 /// Set button text by index.
658 /// <param name="index">Button index.</param>
659 /// <param name="text">Button text string.</param>
660 /// <since_tizen> 6 </since_tizen>
661 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 protected override void Dispose(DisposeTypes type)
676 if (type == DisposeTypes.Explicit)
678 if (titleText != null)
684 if (ContentView != null)
687 ContentView.Dispose();
702 /// Focus gained callback.
704 /// <since_tizen> 6 </since_tizen>
705 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
706 [EditorBrowsable(EditorBrowsableState.Never)]
707 public override void OnFocusGained()
709 base.OnFocusGained();
713 /// Focus lost callback.
715 /// <since_tizen> 6 </since_tizen>
716 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
717 [EditorBrowsable(EditorBrowsableState.Never)]
718 public override void OnFocusLost()
723 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
724 [EditorBrowsable(EditorBrowsableState.Never)]
725 public override void ApplyStyle(ViewStyle viewStyle)
727 base.ApplyStyle(viewStyle);
728 PopupStyle ppStyle = viewStyle as PopupStyle;
731 if (null == titleText)
733 titleText = new TextLabel();
736 titleText.RaiseToTop();
737 titleText.ApplyStyle(ppStyle.Title);
742 /// Get Popup attribues.
744 /// <since_tizen> 6 </since_tizen>
745 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
746 [EditorBrowsable(EditorBrowsableState.Never)]
747 protected override ViewStyle GetViewStyle()
749 return new PopupStyle();
753 /// Theme change callback when theme is changed, this callback will be trigger.
755 /// <since_tizen> 6 </since_tizen>
756 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
757 [EditorBrowsable(EditorBrowsableState.Never)]
758 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
760 PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
761 if (tempAttributes != null)
763 string strSaveTitleText = TitleText;
764 Style.CopyFrom(tempAttributes);
765 Style.Title.Text = strSaveTitleText;
770 private void Initialize()
772 LeaveRequired = true;
773 PropertyChanged += PopupAttributesPropertyChanged;
776 ContentView = new View()
778 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
779 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
780 PositionUsesPivotPoint = true
783 ContentView.RaiseToTop();
786 if (null == titleText)
788 titleText = new TextLabel();
789 titleText.RaiseToTop();
794 btGroup = new ButtonGroup(this);
797 private void UpdateView()
799 UpdateShadowExtens();
800 btGroup.UpdateButton(Style.Buttons);
805 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
807 if (PopupButtonClickEvent != null && btGroup.Count > 0)
809 Button button = sender as Button;
810 for (int i = 0; i < btGroup.Count; i++)
812 if (button == GetButton(i))
814 ButtonClickEventArgs args = new ButtonClickEventArgs();
815 args.ButtonIndex = i;
816 PopupButtonClickEvent(this, args);
822 private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
824 if (e.PropertyName.Equals("LayoutDirection"))
826 btGroup.UpdateButton(Style.Buttons);
830 private void UpdateContentView()
836 string strText = Style.Title.Text.All;
837 if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
839 titleH = (int)titleText.Size.Height;
842 if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
844 titleX = (int)Style.Title.Position.X;
845 titleY = (int)Style.Title.Position.Y;
848 if (btGroup.Count != 0)
850 buttonH = (int)Style.Buttons.Size.Height;
852 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
853 ContentView.Position = new Position(titleX, titleY + titleH);
854 ContentView.RaiseToTop();
857 private void UpdateShadowExtens()
859 if (Style.ShadowExtents != null)
861 Style.Shadow.Size = new Size(Size.Width + Style.ShadowExtents.Start + Style.ShadowExtents.End, Size.Height + Style.ShadowExtents.Top + Style.ShadowExtents.Bottom);
865 private void UpdateTitle()
867 if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
869 titleText.RaiseToTop();
873 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
875 /// <since_tizen> 6 </since_tizen>
876 public class ButtonClickEventArgs : EventArgs
878 /// <summary> Button index which is clicked in Popup </summary>
879 /// <since_tizen> 6 </since_tizen>
880 public int ButtonIndex;