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;
37 if (newValue != null && instance?.Style?.Buttons?.Size != null )
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 != null)
59 instance.Style.Buttons.Text.PointSize = (float)newValue;
61 instance.btGroup.ItemPointSize = (float)newValue;
64 defaultValueCreator: (bindable) =>
66 var instance = (Popup)bindable;
67 return instance.Style?.Buttons?.Text?.PointSize?.All ?? 0;
70 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
71 [EditorBrowsable(EditorBrowsableState.Never)]
72 public static readonly BindableProperty ButtonFontFamilyProperty = BindableProperty.Create(nameof(ButtonFontFamily), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
74 var instance = (Popup)bindable;
77 instance.Style.Buttons.Text.FontFamily = (string)newValue;
78 instance.btGroup.ItemFontFamily = (string)newValue;
81 defaultValueCreator: (bindable) =>
83 var instance = (Popup)bindable;
84 return instance.Style?.Buttons?.Text?.FontFamily.All;
87 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public static readonly BindableProperty ButtonTextColorProperty = BindableProperty.Create(nameof(ButtonTextColor), typeof(Color), typeof(Popup), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) =>
91 var instance = (Popup)bindable;
94 if (instance.Style?.Buttons?.Text != null)
96 instance.Style.Buttons.Text.TextColor = (Color)newValue;
98 instance.btGroup.ItemTextColor = (Color)newValue;
101 defaultValueCreator: (bindable) =>
103 var instance = (Popup)bindable;
104 return instance.Style?.Buttons?.Text?.TextColor?.All;
107 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
108 [EditorBrowsable(EditorBrowsableState.Never)]
109 public static readonly BindableProperty ButtonOverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(ButtonOverLayBackgroundColorSelector), typeof(Selector<Color>), typeof(Popup), new Selector<Color>(), propertyChanged: (bindable, oldValue, newValue) =>
111 var instance = (Popup)bindable;
112 if (newValue != null)
114 instance.Style.Buttons.Overlay.BackgroundColor = (Selector<Color>)newValue;
115 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
118 defaultValueCreator: (bindable) =>
120 var instance = (Popup)bindable;
121 return instance.Style?.Buttons?.Overlay?.BackgroundColor;
124 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public static readonly BindableProperty ButtonTextAlignmentProperty = BindableProperty.Create(nameof(ButtonTextAlignment), typeof(HorizontalAlignment), typeof(Popup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) =>
128 var instance = (Popup)bindable;
129 if (newValue != null)
131 instance.Style.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
132 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
135 defaultValueCreator: (bindable) =>
137 var instance = (Popup)bindable;
138 return instance.Style?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
141 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public static readonly BindableProperty ButtonBackgroundProperty = BindableProperty.Create(nameof(ButtonBackground), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
145 var instance = (Popup)bindable;
146 if (newValue != null)
148 if (instance.Style.Buttons.BackgroundImage == null)
150 instance.Style.Buttons.BackgroundImage = new Selector<string>();
152 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
153 instance.Style.Buttons.BackgroundImage = (string)newValue;
156 defaultValueCreator: (bindable) =>
158 var instance = (Popup)bindable;
159 return instance.Style?.Buttons?.BackgroundImage?.All;
162 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public static readonly BindableProperty ButtonBackgroundBorderProperty = BindableProperty.Create(nameof(ButtonBackgroundBorder), typeof(Rectangle), typeof(Popup), new Rectangle(0, 0, 0, 0), propertyChanged: (bindable, oldValue, newValue) =>
166 var instance = (Popup)bindable;
167 if (newValue != null)
169 if (instance.Style.Buttons.BackgroundImageBorder == null)
171 instance.Style.Buttons.BackgroundImageBorder = new Selector<Rectangle>();
173 instance.Style.Buttons.BackgroundImageBorder = (Rectangle)newValue;
174 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
177 defaultValueCreator: (bindable) =>
179 var instance = (Popup)bindable;
180 return instance.Style?.Buttons?.BackgroundImageBorder?.All;
183 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
184 [EditorBrowsable(EditorBrowsableState.Never)]
185 public static readonly BindableProperty ButtonImageShadowProperty = BindableProperty.Create(nameof(ButtonImageShadow), typeof(ImageShadow), typeof(Popup), null, propertyChanged: (bindable, oldValue, newValue) =>
187 var instance = (Popup)bindable;
188 ImageShadow shadow = (ImageShadow)newValue;
189 instance.btGroup.ItemImageShadow = (ImageShadow)ImageShadow.Clone(shadow);
190 instance.Style.Buttons.ImageShadow = (ImageShadow)ImageShadow.Clone(shadow);
192 defaultValueCreator: (bindable) =>
194 var instance = (Popup)bindable;
195 return instance.Style?.Buttons?.ImageShadow?.All;
199 private TextLabel titleText;
200 private ButtonGroup btGroup = null;
201 private Window window = null;
202 private Layer container = new Layer();
206 /// Creates a new instance of a Popup.
208 /// <since_tizen> 6 </since_tizen>
209 public Popup() : base()
215 /// Creates a new instance of a Popup with style.
217 /// <param name="style">Create Popup by special style defined in UX.</param>
218 /// <since_tizen> 6 </since_tizen>
219 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public Popup(string style) : base(style)
227 /// Creates a new instance of a Popup with attributes.
229 /// <param name="attributes">Create Popup by attributes customized by user.</param>
230 /// <since_tizen> 6 </since_tizen>
231 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public Popup(PopupStyle attributes) : base(attributes)
238 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
239 [EditorBrowsable(EditorBrowsableState.Never)]
240 public virtual void Post(Window targetWindow)
242 if (targetWindow == null)
247 window = targetWindow;
248 window.AddLayer(container);
249 container.RaiseToTop();
253 /// Dismiss the dialog
255 [EditorBrowsable(EditorBrowsableState.Never)]
256 public virtual void Dismiss()
263 window.RemoveLayer(container);
267 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public void AddButton(string buttonText)
271 if (Style.Buttons != null)
273 Button btn = new Button(Style.Buttons);
274 btn.Style.Text.Text = buttonText;
275 btn.ClickEvent += ButtonClickEvent;
276 btGroup.AddItem(btn);
281 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public void AddButton(string buttonText, string style)
285 AddButton(buttonText);
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, ButtonStyle style)
292 if (Style.Buttons != null && style != null)
294 Style.Buttons.CopyFrom(style);
295 AddButton(buttonText);
299 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
300 [EditorBrowsable(EditorBrowsableState.Never)]
301 public Button GetButton(int index)
303 return btGroup.GetItem(index);
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 void RemoveButton(int index)
310 btGroup.RemoveItem(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 AddContentText(View childView)
317 if (null != ContentView)
319 ContentView.Add(childView);
325 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
327 /// <since_tizen> 6 </since_tizen>
328 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
330 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
331 [EditorBrowsable(EditorBrowsableState.Never)]
332 public new PopupStyle Style => ViewStyle as PopupStyle;
335 /// Title text string in Popup.
337 /// <since_tizen> 6 </since_tizen>
338 public string TitleText
342 return Style?.Title?.Text?.All;
348 if (Style?.Title != null)
350 Style.Title.Text = value;
357 /// Title text point size in Popup.
359 /// <since_tizen> 6 </since_tizen>
360 public float TitlePointSize
364 return Style?.Title?.PointSize?.All ?? 0;
368 if (Style?.Title != null)
370 Style.Title.PointSize = value;
376 /// Title text color in Popup.
378 /// <since_tizen> 6 </since_tizen>
379 public Color TitleTextColor
383 return Style?.Title?.TextColor?.All;
387 if (Style?.Title != null)
389 Style.Title.TextColor = value;
395 /// Title text horizontal alignment in Popup.
397 /// <since_tizen> 6 </since_tizen>
398 public HorizontalAlignment TitleTextHorizontalAlignment
402 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
406 Style.Title.HorizontalAlignment = value;
411 /// Title text's position in Popup.
413 /// <since_tizen> 6 </since_tizen>
414 public Position TitleTextPosition
418 return Style?.Title?.Position ?? new Position(0, 0, 0);
422 Style.Title.Position = value;
427 /// Title text's height in Popup.
429 /// <since_tizen> 6 </since_tizen>
430 public int TitleHeight
434 return (int)(Style?.Title?.Size?.Height ?? 0);
438 if (Style?.Title?.Size != null)
440 Style.Title.Size.Height = value;
446 /// Content view in Popup, only can be gotten.
448 /// <since_tizen> 6 </since_tizen>
449 public View ContentView
456 /// Button count in Popup.
458 /// <since_tizen> 6 </since_tizen>
459 public int ButtonCount
466 /// Button height in Popup.
468 /// <since_tizen> 6 </since_tizen>
469 public int ButtonHeight
473 return (int)GetValue(ButtonHeightProperty);
477 SetValue(ButtonHeightProperty, value);
482 /// Button text point size in Popup.
484 /// <since_tizen> 6 </since_tizen>
485 public float ButtonTextPointSize
489 return (float)GetValue(ButtonTextPointSizeProperty);
493 SetValue(ButtonTextPointSizeProperty, value);
498 /// Button text font family in Popup.
500 /// <since_tizen> 6 </since_tizen>
501 public string ButtonFontFamily
505 return (string)GetValue(ButtonFontFamilyProperty);
509 SetValue(ButtonFontFamilyProperty, value);
514 /// Button text color in Popup.
516 /// <since_tizen> 6 </since_tizen>
517 public Color ButtonTextColor
521 return (Color)GetValue(ButtonTextColorProperty);
525 SetValue(ButtonTextColorProperty, value);
530 /// Button overlay background color selector in Popup.
532 /// <since_tizen> 6 </since_tizen>
533 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
534 [EditorBrowsable(EditorBrowsableState.Never)]
535 public Selector<Color> ButtonOverLayBackgroundColorSelector
539 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
543 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
548 /// Button text horizontal alignment in Popup.
550 /// <since_tizen> 6 </since_tizen>
551 public HorizontalAlignment ButtonTextAlignment
555 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
559 SetValue(ButtonTextAlignmentProperty, value);
564 /// Button background image's resource url in Popup.
566 /// <since_tizen> 6 </since_tizen>
567 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
568 [EditorBrowsable(EditorBrowsableState.Never)]
569 public string ButtonBackground
573 return (string)GetValue(ButtonBackgroundProperty);
577 SetValue(ButtonBackgroundProperty, value);
582 /// Button background image's border 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 Rectangle ButtonBackgroundBorder
592 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
596 SetValue(ButtonBackgroundBorderProperty, value);
601 /// Button's image shadow 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 ImageShadow ButtonImageShadow
608 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
609 set => SetValue(ButtonImageShadowProperty, value);
614 /// Set button text by index.
616 /// <param name="index">Button index.</param>
617 /// <param name="text">Button text string.</param>
618 /// <since_tizen> 6 </since_tizen>
619 public void SetButtonText(int index, string text)
625 /// Dispose Popup and all children on it.
627 /// <param name="type">Dispose type.</param>
628 /// <since_tizen> 6 </since_tizen>
629 protected override void Dispose(DisposeTypes type)
636 if (type == DisposeTypes.Explicit)
638 if (titleText != null)
644 if (ContentView != null)
647 ContentView.Dispose();
662 /// Focus gained callback.
664 /// <since_tizen> 6 </since_tizen>
665 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
666 [EditorBrowsable(EditorBrowsableState.Never)]
667 public override void OnFocusGained()
669 base.OnFocusGained();
673 /// Focus lost callback.
675 /// <since_tizen> 6 </since_tizen>
676 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
677 [EditorBrowsable(EditorBrowsableState.Never)]
678 public override void OnFocusLost()
683 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
684 [EditorBrowsable(EditorBrowsableState.Never)]
685 public override void ApplyStyle(ViewStyle viewStyle)
687 base.ApplyStyle(viewStyle);
688 PopupStyle ppStyle = viewStyle as PopupStyle;
691 if (null == titleText)
693 titleText = new TextLabel();
696 titleText.RaiseToTop();
697 titleText.ApplyStyle(ppStyle.Title);
702 /// Get Popup attribues.
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 protected override ViewStyle GetViewStyle()
709 return new PopupStyle();
713 /// Theme change callback when theme is changed, this callback will be trigger.
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 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
720 PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
721 if (tempAttributes != null)
723 string strSaveTitleText = TitleText;
724 Style.CopyFrom(tempAttributes);
725 Style.Title.Text = strSaveTitleText;
730 private void Initialize()
733 LeaveRequired = true;
734 PropertyChanged += PopupAttributesPropertyChanged;
737 ContentView = new View()
739 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
740 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
741 PositionUsesPivotPoint = true
744 ContentView.RaiseToTop();
747 if (null == titleText)
749 titleText = new TextLabel();
750 titleText.RaiseToTop();
755 btGroup = new ButtonGroup(this);
758 private void UpdateView()
760 btGroup.UpdateButton(Style.Buttons);
765 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
767 if (PopupButtonClickEvent != null && btGroup.Count > 0)
769 Button button = sender as Button;
770 for (int i = 0; i < btGroup.Count; i++)
772 if (button == GetButton(i))
774 ButtonClickEventArgs args = new ButtonClickEventArgs();
775 args.ButtonIndex = i;
776 PopupButtonClickEvent(this, args);
782 private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
784 if (e.PropertyName.Equals("LayoutDirection"))
786 btGroup.UpdateButton(Style.Buttons);
790 private void UpdateContentView()
796 string strText = Style.Title.Text.All;
797 if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
799 titleH = (int)titleText.Size.Height;
802 if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
804 titleX = (int)Style.Title.Position.X;
805 titleY = (int)Style.Title.Position.Y;
808 if (btGroup.Count != 0 && Style?.Buttons?.Size != null )
810 buttonH = (int)Style.Buttons.Size.Height;
812 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
813 ContentView.Position = new Position(titleX, titleY + titleH);
814 ContentView.RaiseToTop();
817 private void UpdateTitle()
819 if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
821 titleText.RaiseToTop();
825 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
827 /// <since_tizen> 6 </since_tizen>
828 public class ButtonClickEventArgs : EventArgs
830 /// <summary> Button index which is clicked in Popup </summary>
831 /// <since_tizen> 6 </since_tizen>
832 public int ButtonIndex;