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 ButtonImageShadowProperty = BindableProperty.Create(nameof(ButtonImageShadow), typeof(ImageShadow), typeof(Popup), null, propertyChanged: (bindable, oldValue, newValue) =>
189 var instance = (Popup)bindable;
190 ImageShadow shadow = (ImageShadow)newValue;
191 instance.btGroup.ItemImageShadow = (ImageShadow)ImageShadow.Clone(shadow);
192 instance.Style.Buttons.ImageShadow = (ImageShadow)ImageShadow.Clone(shadow);
194 defaultValueCreator: (bindable) =>
196 var instance = (Popup)bindable;
197 return instance.Style?.Buttons?.ImageShadow?.All;
201 private TextLabel titleText;
202 private ButtonGroup btGroup = null;
203 private Window window = null;
207 /// Creates a new instance of a Popup.
209 /// <since_tizen> 6 </since_tizen>
210 public Popup() : base()
216 /// Creates a new instance of a Popup with style.
218 /// <param name="style">Create Popup by special style defined in UX.</param>
219 /// <since_tizen> 6 </since_tizen>
220 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
221 [EditorBrowsable(EditorBrowsableState.Never)]
222 public Popup(string style) : base(style)
228 /// Creates a new instance of a Popup with attributes.
230 /// <param name="attributes">Create Popup by attributes customized by user.</param>
231 /// <since_tizen> 6 </since_tizen>
232 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
233 [EditorBrowsable(EditorBrowsableState.Never)]
234 public Popup(PopupStyle attributes) : base(attributes)
239 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
240 [EditorBrowsable(EditorBrowsableState.Never)]
241 public void Post(Window win)
243 if (null == win) return;
248 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 public void AddButton(string buttonText)
252 if (Style.Buttons != null)
254 Button btn = new Button(Style.Buttons);
255 btn.Style.Text.Text = buttonText;
256 btn.ClickEvent += ButtonClickEvent;
257 btGroup.AddItem(btn);
262 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
263 [EditorBrowsable(EditorBrowsableState.Never)]
264 public void AddButton(string buttonText, string style)
266 AddButton(buttonText);
269 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
270 [EditorBrowsable(EditorBrowsableState.Never)]
271 public void AddButton(string buttonText, ButtonStyle style)
273 if (Style.Buttons != null && style != null)
275 Style.Buttons.CopyFrom(style);
276 AddButton(buttonText);
280 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 public Button GetButton(int index)
284 return btGroup.GetItem(index);
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 RemoveButton(int index)
291 btGroup.RemoveItem(index);
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 AddContentText(View childView)
298 if (null != ContentView)
300 ContentView.Add(childView);
306 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
308 /// <since_tizen> 6 </since_tizen>
309 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
311 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
312 [EditorBrowsable(EditorBrowsableState.Never)]
313 public new PopupStyle Style => ViewStyle as PopupStyle;
316 /// Title text string in Popup.
318 /// <since_tizen> 6 </since_tizen>
319 public string TitleText
323 return Style?.Title?.Text?.All;
329 if (Style.Title.Text == null)
331 Style.Title.Text = new Selector<string>();
333 Style.Title.Text.All = value;
339 /// Title text point size in Popup.
341 /// <since_tizen> 6 </since_tizen>
342 public float TitlePointSize
346 return Style?.Title?.PointSize?.All ?? 0;
350 if (Style.Title.PointSize == null)
352 Style.Title.PointSize = new Selector<float?>();
354 Style.Title.PointSize.All = value;
359 /// Title text color in Popup.
361 /// <since_tizen> 6 </since_tizen>
362 public Color TitleTextColor
366 return Style?.Title?.TextColor?.All;
370 if (Style.Title.TextColor == null)
372 Style.Title.TextColor = new Selector<Color>();
374 Style.Title.TextColor.All = value;
379 /// Title text horizontal alignment in Popup.
381 /// <since_tizen> 6 </since_tizen>
382 public HorizontalAlignment TitleTextHorizontalAlignment
386 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
390 Style.Title.HorizontalAlignment = value;
395 /// Title text's position in Popup.
397 /// <since_tizen> 6 </since_tizen>
398 public Position TitleTextPosition
402 return Style?.Title?.Position ?? new Position(0, 0, 0);
406 Style.Title.Position = value;
411 /// Title text's height in Popup.
413 /// <since_tizen> 6 </since_tizen>
414 public int TitleHeight
418 return (int)(Style?.Title?.Size?.Height ?? 0);
422 Style.Title.Size.Height = value;
427 /// Content view in Popup, only can be gotten.
429 /// <since_tizen> 6 </since_tizen>
430 public View ContentView
437 /// Button count in Popup.
439 /// <since_tizen> 6 </since_tizen>
440 public int ButtonCount
447 /// Button height in Popup.
449 /// <since_tizen> 6 </since_tizen>
450 public int ButtonHeight
454 return (int)GetValue(ButtonHeightProperty);
458 SetValue(ButtonHeightProperty, value);
463 /// Button text point size in Popup.
465 /// <since_tizen> 6 </since_tizen>
466 public float ButtonTextPointSize
470 return (float)GetValue(ButtonTextPointSizeProperty);
474 SetValue(ButtonTextPointSizeProperty, value);
479 /// Button text font family in Popup.
481 /// <since_tizen> 6 </since_tizen>
482 public string ButtonFontFamily
486 return (string)GetValue(ButtonFontFamilyProperty);
490 SetValue(ButtonFontFamilyProperty, value);
495 /// Button text color in Popup.
497 /// <since_tizen> 6 </since_tizen>
498 public Color ButtonTextColor
502 return (Color)GetValue(ButtonTextColorProperty);
506 SetValue(ButtonTextColorProperty, value);
511 /// Button overlay background color selector in Popup.
513 /// <since_tizen> 6 </since_tizen>
514 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
515 [EditorBrowsable(EditorBrowsableState.Never)]
516 public Selector<Color> ButtonOverLayBackgroundColorSelector
520 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
524 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
529 /// Button text horizontal alignment in Popup.
531 /// <since_tizen> 6 </since_tizen>
532 public HorizontalAlignment ButtonTextAlignment
536 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
540 SetValue(ButtonTextAlignmentProperty, value);
545 /// Button background image's resource url in Popup.
547 /// <since_tizen> 6 </since_tizen>
548 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
549 [EditorBrowsable(EditorBrowsableState.Never)]
550 public string ButtonBackground
554 return (string)GetValue(ButtonBackgroundProperty);
558 SetValue(ButtonBackgroundProperty, value);
563 /// Button background image's border in Popup.
565 /// <since_tizen> 6 </since_tizen>
566 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
567 [EditorBrowsable(EditorBrowsableState.Never)]
568 public Rectangle ButtonBackgroundBorder
573 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
577 SetValue(ButtonBackgroundBorderProperty, value);
582 /// Button's image shadow 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 ImageShadow ButtonImageShadow
589 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
590 set => SetValue(ButtonImageShadowProperty, value);
595 /// Set button text by index.
597 /// <param name="index">Button index.</param>
598 /// <param name="text">Button text string.</param>
599 /// <since_tizen> 6 </since_tizen>
600 public void SetButtonText(int index, string text)
606 /// Dispose Popup and all children on it.
608 /// <param name="type">Dispose type.</param>
609 /// <since_tizen> 6 </since_tizen>
610 protected override void Dispose(DisposeTypes type)
617 if (type == DisposeTypes.Explicit)
619 if (titleText != null)
625 if (ContentView != null)
628 ContentView.Dispose();
643 /// Focus gained callback.
645 /// <since_tizen> 6 </since_tizen>
646 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
647 [EditorBrowsable(EditorBrowsableState.Never)]
648 public override void OnFocusGained()
650 base.OnFocusGained();
654 /// Focus lost callback.
656 /// <since_tizen> 6 </since_tizen>
657 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
658 [EditorBrowsable(EditorBrowsableState.Never)]
659 public override void OnFocusLost()
664 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
665 [EditorBrowsable(EditorBrowsableState.Never)]
666 public override void ApplyStyle(ViewStyle viewStyle)
668 base.ApplyStyle(viewStyle);
669 PopupStyle ppStyle = viewStyle as PopupStyle;
672 if (null == titleText)
674 titleText = new TextLabel();
677 titleText.RaiseToTop();
678 titleText.ApplyStyle(ppStyle.Title);
683 /// Get Popup attribues.
685 /// <since_tizen> 6 </since_tizen>
686 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
687 [EditorBrowsable(EditorBrowsableState.Never)]
688 protected override ViewStyle GetViewStyle()
690 return new PopupStyle();
694 /// Theme change callback when theme is changed, this callback will be trigger.
696 /// <since_tizen> 6 </since_tizen>
697 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
698 [EditorBrowsable(EditorBrowsableState.Never)]
699 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
701 PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
702 if (tempAttributes != null)
704 string strSaveTitleText = TitleText;
705 Style.CopyFrom(tempAttributes);
706 Style.Title.Text = strSaveTitleText;
711 private void Initialize()
713 LeaveRequired = true;
714 PropertyChanged += PopupAttributesPropertyChanged;
717 ContentView = new View()
719 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
720 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
721 PositionUsesPivotPoint = true
724 ContentView.RaiseToTop();
727 if (null == titleText)
729 titleText = new TextLabel();
730 titleText.RaiseToTop();
735 btGroup = new ButtonGroup(this);
738 private void UpdateView()
740 btGroup.UpdateButton(Style.Buttons);
745 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
747 if (PopupButtonClickEvent != null && btGroup.Count > 0)
749 Button button = sender as Button;
750 for (int i = 0; i < btGroup.Count; i++)
752 if (button == GetButton(i))
754 ButtonClickEventArgs args = new ButtonClickEventArgs();
755 args.ButtonIndex = i;
756 PopupButtonClickEvent(this, args);
762 private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
764 if (e.PropertyName.Equals("LayoutDirection"))
766 btGroup.UpdateButton(Style.Buttons);
770 private void UpdateContentView()
776 string strText = Style.Title.Text.All;
777 if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
779 titleH = (int)titleText.Size.Height;
782 if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
784 titleX = (int)Style.Title.Position.X;
785 titleY = (int)Style.Title.Position.Y;
788 if (btGroup.Count != 0)
790 buttonH = (int)Style.Buttons.Size.Height;
792 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
793 ContentView.Position = new Position(titleX, titleY + titleH);
794 ContentView.RaiseToTop();
797 private void UpdateTitle()
799 if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
801 titleText.RaiseToTop();
805 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
807 /// <since_tizen> 6 </since_tizen>
808 public class ButtonClickEventArgs : EventArgs
810 /// <summary> Button index which is clicked in Popup </summary>
811 /// <since_tizen> 6 </since_tizen>
812 public int ButtonIndex;