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 [Obsolete("Deprecated in API8; Will be removed in API10")]
31 public class Popup : Control
33 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ButtonHeightProperty = BindableProperty.Create(nameof(ButtonHeight), typeof(int), typeof(Popup), default(int), propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (Popup)bindable;
38 if (newValue != null && instance?.popupStyle?.Buttons?.Size != null )
40 instance.popupStyle.Buttons.Size.Height = (int)newValue;
41 instance.btGroup.Itemheight = (int)newValue;
42 instance.UpdateView();
45 defaultValueCreator: (bindable) =>
47 var instance = (Popup)bindable;
48 return (int)(instance.popupStyle?.Buttons?.Size?.Height ?? 0);
51 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public static readonly BindableProperty ButtonTextPointSizeProperty = BindableProperty.Create(nameof(ButtonTextPointSize), typeof(float), typeof(Popup), default(float), propertyChanged: (bindable, oldValue, newValue) =>
55 var instance = (Popup)bindable;
58 if (instance.popupStyle?.Buttons?.Text != null)
60 instance.popupStyle.Buttons.Text.PointSize = (float)newValue;
62 instance.btGroup.ItemPointSize = (float)newValue;
65 defaultValueCreator: (bindable) =>
67 var instance = (Popup)bindable;
68 return instance.popupStyle?.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.popupStyle.Buttons.Text.FontFamily = (string)newValue;
79 instance.btGroup.ItemFontFamily = (string)newValue;
82 defaultValueCreator: (bindable) =>
84 var instance = (Popup)bindable;
85 return instance.popupStyle?.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.popupStyle?.Buttons?.Text != null)
97 instance.popupStyle.Buttons.Text.TextColor = (Color)newValue;
99 instance.btGroup.ItemTextColor = (Color)newValue;
102 defaultValueCreator: (bindable) =>
104 var instance = (Popup)bindable;
105 return instance.popupStyle?.Buttons?.Text?.TextColor?.All;
108 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public static readonly BindableProperty ButtonOverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(ButtonOverLayBackgroundColorSelector), typeof(Selector<Color>), typeof(Popup), new Selector<Color>(), propertyChanged: (bindable, oldValue, newValue) =>
112 var instance = (Popup)bindable;
113 if (newValue != null)
115 instance.popupStyle.Buttons.Overlay.BackgroundColor = (Selector<Color>)newValue;
116 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
119 defaultValueCreator: (bindable) =>
121 var instance = (Popup)bindable;
122 return instance.popupStyle?.Buttons?.Overlay?.BackgroundColor;
125 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public static readonly BindableProperty ButtonTextAlignmentProperty = BindableProperty.Create(nameof(ButtonTextAlignment), typeof(HorizontalAlignment), typeof(Popup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) =>
129 var instance = (Popup)bindable;
130 if (newValue != null)
132 instance.popupStyle.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
133 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
136 defaultValueCreator: (bindable) =>
138 var instance = (Popup)bindable;
139 return instance.popupStyle?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
142 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public static readonly BindableProperty ButtonBackgroundProperty = BindableProperty.Create(nameof(ButtonBackground), typeof(string), typeof(Popup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
146 var instance = (Popup)bindable;
147 if (newValue != null)
149 if (instance.popupStyle.Buttons.BackgroundImage == null)
151 instance.popupStyle.Buttons.BackgroundImage = new Selector<string>();
153 instance.popupStyle.Buttons.BackgroundColor = new Selector<Color>();
154 instance.popupStyle.Buttons.BackgroundImage = (string)newValue;
155 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
158 defaultValueCreator: (bindable) =>
160 var instance = (Popup)bindable;
161 return instance.popupStyle?.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.popupStyle.Buttons.BackgroundImageBorder == null)
173 instance.popupStyle.Buttons.BackgroundImageBorder = new Selector<Rectangle>();
175 instance.popupStyle.Buttons.BackgroundImageBorder = (Rectangle)newValue;
176 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
179 defaultValueCreator: (bindable) =>
181 var instance = (Popup)bindable;
182 return instance.popupStyle?.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 = new ImageShadow(shadow);
192 instance.popupStyle.Buttons.ImageShadow = new ImageShadow(shadow);
194 defaultValueCreator: (bindable) =>
196 var instance = (Popup)bindable;
197 return instance.popupStyle?.Buttons?.ImageShadow?.All;
201 private PopupStyle popupStyle => ViewStyle as PopupStyle;
202 private TextLabel titleText;
203 private ButtonGroup btGroup = null;
204 private Window window = null;
205 private Layer container = new Layer();
209 /// Creates a new instance of a Popup.
211 /// <since_tizen> 6 </since_tizen>
212 [Obsolete("Deprecated in API8; Will be removed in API10")]
213 public Popup() : base()
219 /// Creates a new instance of a Popup with style.
221 /// <param name="style">Create Popup by special style defined in UX.</param>
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public Popup(string style) : base(style)
229 /// Creates a new instance of a Popup with style.
231 /// <param name="popupStyle">Create Popup by style customized by user.</param>
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public Popup(PopupStyle popupStyle) : base(popupStyle)
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 (popupStyle.Buttons != null)
273 Button btn = new Button(popupStyle.Buttons);
274 btn.Text = buttonText;
275 btn.ClickEvent += ButtonClickEvent;
276 btGroup.AddItem(btn);
282 /// Add button by style's name.
284 [EditorBrowsable(EditorBrowsableState.Never)]
285 public void AddButton(string buttonText, string style)
287 AddButton(buttonText);
291 /// Add button by style.
293 [EditorBrowsable(EditorBrowsableState.Never)]
294 public void AddButton(string buttonText, ButtonStyle style)
296 if (popupStyle.Buttons != null && style != null)
298 popupStyle.Buttons.CopyFrom(style);
299 AddButton(buttonText);
303 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 public Button GetButton(int index)
307 return btGroup.GetItem(index);
310 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
311 [EditorBrowsable(EditorBrowsableState.Never)]
312 public void RemoveButton(int index)
314 btGroup.RemoveItem(index);
317 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public void AddContentText(View childView)
321 if (null != ContentView)
323 ContentView.Add(childView);
329 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
331 /// <since_tizen> 6 </since_tizen>
332 [Obsolete("Deprecated in API8; Will be removed in API10")]
333 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
336 /// Get style of popup.
338 [EditorBrowsable(EditorBrowsableState.Never)]
339 public new PopupStyle Style
343 var result = new PopupStyle(popupStyle);
344 result.CopyPropertiesFromView(this);
345 result.Title.CopyPropertiesFromView(titleText);
353 [EditorBrowsable(EditorBrowsableState.Never)]
354 public TextLabel Title
358 if (null == titleText)
360 titleText = new TextLabel();
372 /// Title text string in Popup.
374 /// <since_tizen> 6 </since_tizen>
375 [Obsolete("Deprecated in API8; Will be removed in API10")]
376 public string TitleText
380 return popupStyle?.Title?.Text?.All;
386 if (popupStyle?.Title != null)
388 popupStyle.Title.Text = value;
395 /// Title text point size in Popup.
397 /// <since_tizen> 6 </since_tizen>
398 [Obsolete("Deprecated in API8; Will be removed in API10")]
399 public float TitlePointSize
403 return popupStyle?.Title?.PointSize?.All ?? 0;
407 if (popupStyle?.Title != null)
409 popupStyle.Title.PointSize = value;
415 /// Title text color in Popup.
417 /// <since_tizen> 6 </since_tizen>
418 [Obsolete("Deprecated in API8; Will be removed in API10")]
419 public Color TitleTextColor
423 return popupStyle?.Title?.TextColor?.All;
427 if (popupStyle?.Title != null)
429 popupStyle.Title.TextColor = value;
435 /// Title text horizontal alignment in Popup.
437 /// <since_tizen> 6 </since_tizen>
438 [Obsolete("Deprecated in API8; Will be removed in API10")]
439 public HorizontalAlignment TitleTextHorizontalAlignment
443 return popupStyle?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
447 popupStyle.Title.HorizontalAlignment = value;
452 /// Title text's position in Popup.
454 /// <since_tizen> 6 </since_tizen>
455 [Obsolete("Deprecated in API8; Will be removed in API10")]
456 public Position TitleTextPosition
460 return popupStyle?.Title?.Position ?? new Position(0, 0, 0);
464 popupStyle.Title.Position = value;
469 /// Title text's height in Popup.
471 /// <since_tizen> 6 </since_tizen>
472 [Obsolete("Deprecated in API8; Will be removed in API10")]
473 public int TitleHeight
477 return (int)(popupStyle?.Title?.Size?.Height ?? 0);
481 if (popupStyle?.Title?.Size != null)
483 popupStyle.Title.Size.Height = value;
489 /// Content view in Popup, only can be gotten.
491 /// <since_tizen> 6 </since_tizen>
492 [Obsolete("Deprecated in API8; Will be removed in API10")]
493 public View ContentView
500 /// Button count in Popup.
502 /// <since_tizen> 6 </since_tizen>
503 [Obsolete("Deprecated in API8; Will be removed in API10")]
504 public int ButtonCount
511 /// Button height in Popup.
513 /// <since_tizen> 6 </since_tizen>
514 [Obsolete("Deprecated in API8; Will be removed in API10")]
515 public int ButtonHeight
519 return (int)GetValue(ButtonHeightProperty);
523 SetValue(ButtonHeightProperty, value);
528 /// Button text point size in Popup.
530 /// <since_tizen> 6 </since_tizen>
531 [Obsolete("Deprecated in API8; Will be removed in API10")]
532 public float ButtonTextPointSize
536 return (float)GetValue(ButtonTextPointSizeProperty);
540 SetValue(ButtonTextPointSizeProperty, value);
545 /// Button text font family in Popup.
547 /// <since_tizen> 6 </since_tizen>
548 [Obsolete("Deprecated in API8; Will be removed in API10")]
549 public string ButtonFontFamily
553 return (string)GetValue(ButtonFontFamilyProperty);
557 SetValue(ButtonFontFamilyProperty, value);
562 /// Button text color in Popup.
564 /// <since_tizen> 6 </since_tizen>
565 [Obsolete("Deprecated in API8; Will be removed in API10")]
566 public Color ButtonTextColor
570 return (Color)GetValue(ButtonTextColorProperty);
574 SetValue(ButtonTextColorProperty, value);
579 /// Button overlay background color selector in Popup.
581 /// <since_tizen> 6 </since_tizen>
582 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
583 [EditorBrowsable(EditorBrowsableState.Never)]
584 public Selector<Color> ButtonOverLayBackgroundColorSelector
588 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
592 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
597 /// Button text horizontal alignment in Popup.
599 /// <since_tizen> 6 </since_tizen>
600 [Obsolete("Deprecated in API8; Will be removed in API10")]
601 public HorizontalAlignment ButtonTextAlignment
605 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
609 SetValue(ButtonTextAlignmentProperty, value);
614 /// Button background image's resource url in Popup.
616 /// <since_tizen> 6 </since_tizen>
617 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
618 [EditorBrowsable(EditorBrowsableState.Never)]
619 public string ButtonBackground
623 return (string)GetValue(ButtonBackgroundProperty);
627 SetValue(ButtonBackgroundProperty, value);
632 /// Button background image's border in Popup.
634 /// <since_tizen> 6 </since_tizen>
635 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
636 [EditorBrowsable(EditorBrowsableState.Never)]
637 public Rectangle ButtonBackgroundBorder
642 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
646 SetValue(ButtonBackgroundBorderProperty, value);
651 /// Button's image shadow in Popup.
653 /// <since_tizen> 6 </since_tizen>
654 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
655 [EditorBrowsable(EditorBrowsableState.Never)]
656 public ImageShadow ButtonImageShadow
658 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
659 set => SetValue(ButtonImageShadowProperty, value);
664 /// Set button text by index.
666 /// <param name="index">Button index.</param>
667 /// <param name="text">Button text string.</param>
668 /// <since_tizen> 6 </since_tizen>
669 [Obsolete("Deprecated in API8; Will be removed in API10")]
670 public void SetButtonText(int index, string text)
676 /// Dispose Popup and all children on it.
678 /// <param name="type">Dispose type.</param>
679 /// <since_tizen> 6 </since_tizen>
680 [Obsolete("Deprecated in API8; Will be removed in API10")]
681 protected override void Dispose(DisposeTypes type)
688 if (type == DisposeTypes.Explicit)
690 if (titleText != null)
696 if (ContentView != null)
699 ContentView.Dispose();
714 /// Focus gained 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 OnFocusGained()
721 base.OnFocusGained();
725 /// Focus lost callback.
727 /// <since_tizen> 6 </since_tizen>
728 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
729 [EditorBrowsable(EditorBrowsableState.Never)]
730 public override void OnFocusLost()
736 /// Apply style to popup.
738 /// <param name="viewStyle">The style to apply.</param>
739 [EditorBrowsable(EditorBrowsableState.Never)]
740 public override void ApplyStyle(ViewStyle viewStyle)
742 base.ApplyStyle(viewStyle);
743 PopupStyle ppStyle = viewStyle as PopupStyle;
746 Title.ApplyStyle(ppStyle.Title);
754 /// <returns>The default popup style.</returns>
755 [EditorBrowsable(EditorBrowsableState.Never)]
756 protected override ViewStyle CreateViewStyle()
758 return new PopupStyle();
762 /// Theme change callback when theme is changed, this callback will be trigger.
764 /// <param name="sender">The sender</param>
765 /// <param name="e">The event data</param>
766 [EditorBrowsable(EditorBrowsableState.Never)]
767 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
769 PopupStyle ppStyle = StyleManager.Instance.GetViewStyle(StyleName) as PopupStyle;
777 private void Initialize()
780 container.SetTouchConsumed(true);
781 container.SetHoverConsumed(true);
783 LeaveRequired = true;
784 PropertyChanged += PopupStylePropertyChanged;
787 ContentView = new View()
789 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
790 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
791 PositionUsesPivotPoint = true
794 ContentView.RaiseToTop();
797 btGroup = new ButtonGroup(this);
800 private void UpdateView()
802 btGroup.UpdateButton(popupStyle.Buttons);
807 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
809 if (PopupButtonClickEvent != null && btGroup.Count > 0)
811 Button button = sender as Button;
812 for (int i = 0; i < btGroup.Count; i++)
814 if (button == GetButton(i))
816 ButtonClickEventArgs args = new ButtonClickEventArgs();
817 args.ButtonIndex = i;
818 PopupButtonClickEvent(this, args);
824 private void PopupStylePropertyChanged(object sender, PropertyChangedEventArgs e)
826 if (e.PropertyName.Equals("LayoutDirection"))
828 btGroup.UpdateButton(popupStyle.Buttons);
832 private void UpdateContentView()
838 string strText = Title.Text;
839 if (!string.IsNullOrEmpty(strText) && Title.Size != null)
841 titleH = (int)titleText.Size.Height;
844 if (!string.IsNullOrEmpty(strText) && Title.Position != null)
846 titleX = (int)Title.Position.X;
847 titleY = (int)Title.Position.Y;
850 if (btGroup.Count != 0 && popupStyle?.Buttons?.Size != null )
852 buttonH = (int)popupStyle.Buttons.Size.Height;
854 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
855 ContentView.Position = new Position(titleX, titleY + titleH);
856 ContentView.RaiseToTop();
859 private void UpdateTitle()
861 if (titleText != null && string.IsNullOrEmpty(popupStyle.Title.Text.All) && popupStyle.Title.Size != null)
863 titleText.RaiseToTop();
867 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
869 /// <since_tizen> 6 </since_tizen>
870 [Obsolete("Deprecated in API8; Will be removed in API10")]
871 public class ButtonClickEventArgs : EventArgs
873 /// <summary> Button index which is clicked in Popup </summary>
874 /// <since_tizen> 6 </since_tizen>
875 [Obsolete("Deprecated in API8; Will be removed in API10")]
876 public int ButtonIndex;