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;
205 /// Creates a new instance of a Popup.
207 /// <since_tizen> 6 </since_tizen>
208 public Popup() : base()
214 /// Creates a new instance of a Popup with style.
216 /// <param name="style">Create Popup by special style defined in UX.</param>
217 /// <since_tizen> 6 </since_tizen>
218 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
219 [EditorBrowsable(EditorBrowsableState.Never)]
220 public Popup(string style) : base(style)
226 /// Creates a new instance of a Popup with attributes.
228 /// <param name="attributes">Create Popup by attributes customized by user.</param>
229 /// <since_tizen> 6 </since_tizen>
230 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
231 [EditorBrowsable(EditorBrowsableState.Never)]
232 public Popup(PopupStyle attributes) : base(attributes)
237 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
238 [EditorBrowsable(EditorBrowsableState.Never)]
239 public void Post(Window win)
241 if (null == win) return;
246 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
247 [EditorBrowsable(EditorBrowsableState.Never)]
248 public void AddButton(string buttonText)
250 if (Style.Buttons != null)
252 Button btn = new Button(Style.Buttons);
253 btn.Style.Text.Text = buttonText;
254 btn.ClickEvent += ButtonClickEvent;
255 btGroup.AddItem(btn);
260 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public void AddButton(string buttonText, string style)
264 AddButton(buttonText);
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, ButtonStyle style)
271 if (Style.Buttons != null && style != null)
273 Style.Buttons.CopyFrom(style);
274 AddButton(buttonText);
278 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 public Button GetButton(int index)
282 return btGroup.GetItem(index);
285 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
286 [EditorBrowsable(EditorBrowsableState.Never)]
287 public void RemoveButton(int index)
289 btGroup.RemoveItem(index);
292 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
293 [EditorBrowsable(EditorBrowsableState.Never)]
294 public void AddContentText(View childView)
296 if (null != ContentView)
298 ContentView.Add(childView);
304 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
306 /// <since_tizen> 6 </since_tizen>
307 public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
309 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 public new PopupStyle Style => ViewStyle as PopupStyle;
314 /// Title text string in Popup.
316 /// <since_tizen> 6 </since_tizen>
317 public string TitleText
321 return Style?.Title?.Text?.All;
327 if (Style?.Title != null)
329 Style.Title.Text = value;
336 /// Title text point size in Popup.
338 /// <since_tizen> 6 </since_tizen>
339 public float TitlePointSize
343 return Style?.Title?.PointSize?.All ?? 0;
347 if (Style?.Title != null)
349 Style.Title.PointSize = value;
355 /// Title text color in Popup.
357 /// <since_tizen> 6 </since_tizen>
358 public Color TitleTextColor
362 return Style?.Title?.TextColor?.All;
366 if (Style?.Title != null)
368 Style.Title.TextColor = value;
374 /// Title text horizontal alignment in Popup.
376 /// <since_tizen> 6 </since_tizen>
377 public HorizontalAlignment TitleTextHorizontalAlignment
381 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
385 Style.Title.HorizontalAlignment = value;
390 /// Title text's position in Popup.
392 /// <since_tizen> 6 </since_tizen>
393 public Position TitleTextPosition
397 return Style?.Title?.Position ?? new Position(0, 0, 0);
401 Style.Title.Position = value;
406 /// Title text's height in Popup.
408 /// <since_tizen> 6 </since_tizen>
409 public int TitleHeight
413 return (int)(Style?.Title?.Size?.Height ?? 0);
417 if (Style?.Title?.Size != null)
419 Style.Title.Size.Height = value;
425 /// Content view in Popup, only can be gotten.
427 /// <since_tizen> 6 </since_tizen>
428 public View ContentView
435 /// Button count in Popup.
437 /// <since_tizen> 6 </since_tizen>
438 public int ButtonCount
445 /// Button height in Popup.
447 /// <since_tizen> 6 </since_tizen>
448 public int ButtonHeight
452 return (int)GetValue(ButtonHeightProperty);
456 SetValue(ButtonHeightProperty, value);
461 /// Button text point size in Popup.
463 /// <since_tizen> 6 </since_tizen>
464 public float ButtonTextPointSize
468 return (float)GetValue(ButtonTextPointSizeProperty);
472 SetValue(ButtonTextPointSizeProperty, value);
477 /// Button text font family in Popup.
479 /// <since_tizen> 6 </since_tizen>
480 public string ButtonFontFamily
484 return (string)GetValue(ButtonFontFamilyProperty);
488 SetValue(ButtonFontFamilyProperty, value);
493 /// Button text color in Popup.
495 /// <since_tizen> 6 </since_tizen>
496 public Color ButtonTextColor
500 return (Color)GetValue(ButtonTextColorProperty);
504 SetValue(ButtonTextColorProperty, value);
509 /// Button overlay background color selector in Popup.
511 /// <since_tizen> 6 </since_tizen>
512 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
513 [EditorBrowsable(EditorBrowsableState.Never)]
514 public Selector<Color> ButtonOverLayBackgroundColorSelector
518 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
522 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
527 /// Button text horizontal alignment in Popup.
529 /// <since_tizen> 6 </since_tizen>
530 public HorizontalAlignment ButtonTextAlignment
534 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
538 SetValue(ButtonTextAlignmentProperty, value);
543 /// Button background image's resource url in Popup.
545 /// <since_tizen> 6 </since_tizen>
546 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
547 [EditorBrowsable(EditorBrowsableState.Never)]
548 public string ButtonBackground
552 return (string)GetValue(ButtonBackgroundProperty);
556 SetValue(ButtonBackgroundProperty, value);
561 /// Button background image's border in Popup.
563 /// <since_tizen> 6 </since_tizen>
564 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
565 [EditorBrowsable(EditorBrowsableState.Never)]
566 public Rectangle ButtonBackgroundBorder
571 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
575 SetValue(ButtonBackgroundBorderProperty, value);
580 /// Button's image shadow in Popup.
582 /// <since_tizen> 6 </since_tizen>
583 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
584 [EditorBrowsable(EditorBrowsableState.Never)]
585 public ImageShadow ButtonImageShadow
587 get => (ImageShadow)GetValue(ButtonImageShadowProperty);
588 set => SetValue(ButtonImageShadowProperty, value);
593 /// Set button text by index.
595 /// <param name="index">Button index.</param>
596 /// <param name="text">Button text string.</param>
597 /// <since_tizen> 6 </since_tizen>
598 public void SetButtonText(int index, string text)
604 /// Dispose Popup and all children on it.
606 /// <param name="type">Dispose type.</param>
607 /// <since_tizen> 6 </since_tizen>
608 protected override void Dispose(DisposeTypes type)
615 if (type == DisposeTypes.Explicit)
617 if (titleText != null)
623 if (ContentView != null)
626 ContentView.Dispose();
641 /// Focus gained callback.
643 /// <since_tizen> 6 </since_tizen>
644 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
645 [EditorBrowsable(EditorBrowsableState.Never)]
646 public override void OnFocusGained()
648 base.OnFocusGained();
652 /// Focus lost callback.
654 /// <since_tizen> 6 </since_tizen>
655 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
656 [EditorBrowsable(EditorBrowsableState.Never)]
657 public override void OnFocusLost()
662 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
663 [EditorBrowsable(EditorBrowsableState.Never)]
664 public override void ApplyStyle(ViewStyle viewStyle)
666 base.ApplyStyle(viewStyle);
667 PopupStyle ppStyle = viewStyle as PopupStyle;
670 if (null == titleText)
672 titleText = new TextLabel();
675 titleText.RaiseToTop();
676 titleText.ApplyStyle(ppStyle.Title);
681 /// Get Popup attribues.
683 /// <since_tizen> 6 </since_tizen>
684 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
685 [EditorBrowsable(EditorBrowsableState.Never)]
686 protected override ViewStyle GetViewStyle()
688 return new PopupStyle();
692 /// Theme change callback when theme is changed, this callback will be trigger.
694 /// <since_tizen> 6 </since_tizen>
695 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
696 [EditorBrowsable(EditorBrowsableState.Never)]
697 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
699 PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
700 if (tempAttributes != null)
702 string strSaveTitleText = TitleText;
703 Style.CopyFrom(tempAttributes);
704 Style.Title.Text = strSaveTitleText;
709 private void Initialize()
711 LeaveRequired = true;
712 PropertyChanged += PopupAttributesPropertyChanged;
715 ContentView = new View()
717 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
718 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
719 PositionUsesPivotPoint = true
722 ContentView.RaiseToTop();
725 if (null == titleText)
727 titleText = new TextLabel();
728 titleText.RaiseToTop();
733 btGroup = new ButtonGroup(this);
736 private void UpdateView()
738 btGroup.UpdateButton(Style.Buttons);
743 private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
745 if (PopupButtonClickEvent != null && btGroup.Count > 0)
747 Button button = sender as Button;
748 for (int i = 0; i < btGroup.Count; i++)
750 if (button == GetButton(i))
752 ButtonClickEventArgs args = new ButtonClickEventArgs();
753 args.ButtonIndex = i;
754 PopupButtonClickEvent(this, args);
760 private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
762 if (e.PropertyName.Equals("LayoutDirection"))
764 btGroup.UpdateButton(Style.Buttons);
768 private void UpdateContentView()
774 string strText = Style.Title.Text.All;
775 if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
777 titleH = (int)titleText.Size.Height;
780 if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
782 titleX = (int)Style.Title.Position.X;
783 titleY = (int)Style.Title.Position.Y;
786 if (btGroup.Count != 0 && Style?.Buttons?.Size != null )
788 buttonH = (int)Style.Buttons.Size.Height;
790 ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
791 ContentView.Position = new Position(titleX, titleY + titleH);
792 ContentView.RaiseToTop();
795 private void UpdateTitle()
797 if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
799 titleText.RaiseToTop();
803 /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
805 /// <since_tizen> 6 </since_tizen>
806 public class ButtonClickEventArgs : EventArgs
808 /// <summary> Button index which is clicked in Popup </summary>
809 /// <since_tizen> 6 </since_tizen>
810 public int ButtonIndex;