[NUI] Refactoring Theme and StyleManager (#1981)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Popup.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21 using System.ComponentModel;
22
23 namespace Tizen.NUI.Components
24 {
25     /// <summary>
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.
28     /// </summary>
29     /// <since_tizen> 6 </since_tizen>
30     [Obsolete("Deprecated in API8; Will be removed in API10")]
31     public class Popup : Control
32     {
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) =>
36         {
37             var instance = (Popup)bindable;
38             if (newValue != null && instance?.popupStyle?.Buttons?.Size != null )
39             {
40                 instance.popupStyle.Buttons.Size.Height = (int)newValue;
41                 instance.btGroup.Itemheight = (int)newValue;
42                 instance.UpdateView();
43             }
44         },
45         defaultValueCreator: (bindable) =>
46         {
47             var instance = (Popup)bindable;
48             return (int)(instance.popupStyle?.Buttons?.Size?.Height ?? 0);
49         });
50
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) =>
54         {
55             var instance = (Popup)bindable;
56             if (newValue != null)
57             {
58                 if (instance.popupStyle?.Buttons?.Text != null)
59                 {
60                     instance.popupStyle.Buttons.Text.PointSize = (float)newValue;
61                 }
62                 instance.btGroup.ItemPointSize = (float)newValue;
63             }
64         },
65         defaultValueCreator: (bindable) =>
66         {
67             var instance = (Popup)bindable;
68             return instance.popupStyle?.Buttons?.Text?.PointSize?.All ?? 0;
69         });
70
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) =>
74         {
75             var instance = (Popup)bindable;
76             if (newValue != null)
77             {
78                 instance.popupStyle.Buttons.Text.FontFamily = (string)newValue;
79                 instance.btGroup.ItemFontFamily = (string)newValue;
80             }
81         },
82         defaultValueCreator: (bindable) =>
83         {
84             var instance = (Popup)bindable;
85             return instance.popupStyle?.Buttons?.Text?.FontFamily.All;
86         });
87
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) =>
91         {
92             var instance = (Popup)bindable;
93             if (newValue != null)
94             {  
95                 if (instance.popupStyle?.Buttons?.Text != null)
96                 {
97                     instance.popupStyle.Buttons.Text.TextColor = (Color)newValue;
98                 }
99                 instance.btGroup.ItemTextColor = (Color)newValue;
100             }
101         },
102         defaultValueCreator: (bindable) =>
103         {
104             var instance = (Popup)bindable;
105             return instance.popupStyle?.Buttons?.Text?.TextColor?.All;
106         });
107
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) =>
111         {
112             var instance = (Popup)bindable;
113             if (newValue != null)
114             {
115                 instance.popupStyle.Buttons.Overlay.BackgroundColor = (Selector<Color>)newValue;
116                 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
117             }
118         },
119         defaultValueCreator: (bindable) =>
120         {
121             var instance = (Popup)bindable;
122             return instance.popupStyle?.Buttons?.Overlay?.BackgroundColor;
123         });
124
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) =>
128         {
129             var instance = (Popup)bindable;
130             if (newValue != null)
131             {
132                 instance.popupStyle.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
133                 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
134             }
135         },
136         defaultValueCreator: (bindable) =>
137         {
138             var instance = (Popup)bindable;
139             return instance.popupStyle?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
140         });
141
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) =>
145         {
146             var instance = (Popup)bindable;
147             if (newValue != null)
148             {
149                 if (instance.popupStyle.Buttons.BackgroundImage == null)
150                 {
151                     instance.popupStyle.Buttons.BackgroundImage = new Selector<string>();
152                 }
153                 instance.popupStyle.Buttons.BackgroundColor = new Selector<Color>();
154                 instance.popupStyle.Buttons.BackgroundImage = (string)newValue;
155                 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
156             }
157         },
158         defaultValueCreator: (bindable) =>
159         {
160             var instance = (Popup)bindable;
161             return instance.popupStyle?.Buttons?.BackgroundImage?.All;
162         });
163
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) =>
167         {
168             var instance = (Popup)bindable;
169             if (newValue != null)
170             {
171                 if (instance.popupStyle.Buttons.BackgroundImageBorder == null)
172                 {
173                     instance.popupStyle.Buttons.BackgroundImageBorder = new Selector<Rectangle>();
174                 }
175                 instance.popupStyle.Buttons.BackgroundImageBorder = (Rectangle)newValue;
176                 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
177             }
178         },
179         defaultValueCreator: (bindable) =>
180         {
181             var instance = (Popup)bindable;
182             return instance.popupStyle?.Buttons?.BackgroundImageBorder?.All;
183         });
184
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) =>
188         {
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);
193         },
194         defaultValueCreator: (bindable) =>
195         {
196             var instance = (Popup)bindable;
197             return instance.popupStyle?.Buttons?.ImageShadow?.All;
198         });
199
200
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();
206         static Popup() { }
207
208         /// <summary>
209         /// Creates a new instance of a Popup.
210         /// </summary>
211         /// <since_tizen> 6 </since_tizen>
212         [Obsolete("Deprecated in API8; Will be removed in API10")]
213         public Popup() : base()
214         {
215             Initialize();
216         }
217
218         /// <summary>
219         /// Creates a new instance of a Popup with style.
220         /// </summary>
221         /// <param name="style">Create Popup by special style defined in UX.</param>
222         [EditorBrowsable(EditorBrowsableState.Never)]
223         public Popup(string style) : base(style)
224         {
225             Initialize();
226         }
227
228         /// <summary>
229         /// Creates a new instance of a Popup with style.
230         /// </summary>
231         /// <param name="popupStyle">Create Popup by style customized by user.</param>
232         [EditorBrowsable(EditorBrowsableState.Never)]
233         public Popup(PopupStyle popupStyle) : base(popupStyle)
234         {
235             Initialize();
236         }
237
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)
241         {
242             if (targetWindow == null)
243             {
244                 return;
245             }
246
247             window = targetWindow;
248             window.AddLayer(container);
249             container.RaiseToTop();
250         }
251
252         /// <summary>
253         /// Dismiss the dialog
254         /// </summary>
255         [EditorBrowsable(EditorBrowsableState.Never)]
256         public virtual void Dismiss()
257         {
258             if (window == null)
259             {
260                 return;
261             }
262
263             window.RemoveLayer(container);
264             window = null;
265         }
266
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)
270         {
271             if (popupStyle.Buttons != null)
272             {
273                 Button btn = new Button(popupStyle.Buttons);
274                 btn.Text = buttonText;
275                 btn.ClickEvent += ButtonClickEvent;
276                 btGroup.AddItem(btn);
277                 UpdateView();
278             }
279         }
280
281         /// <summary>
282         /// Add button by style's name.
283         /// </summary>
284         [EditorBrowsable(EditorBrowsableState.Never)]
285         public void AddButton(string buttonText, string style)
286         {
287             AddButton(buttonText);
288         }
289
290         /// <summary>
291         /// Add button by style.
292         /// </summary>
293         [EditorBrowsable(EditorBrowsableState.Never)]
294         public void AddButton(string buttonText, ButtonStyle style)
295         {
296             if (popupStyle.Buttons != null && style != null)
297             {
298                 popupStyle.Buttons.CopyFrom(style);
299                 AddButton(buttonText);
300             }
301         }
302
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)
306         {
307             return btGroup.GetItem(index);
308         }
309
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)
313         {
314             btGroup.RemoveItem(index);
315         }
316
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)
320         {
321             if (null != ContentView)
322             {
323                 ContentView.Add(childView);
324             }
325             UpdateView();
326         }
327
328         /// <summary>
329         /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
330         /// </summary>
331         /// <since_tizen> 6 </since_tizen>
332         [Obsolete("Deprecated in API8; Will be removed in API10")]
333         public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
334
335         /// <summary>
336         /// Get style of popup.
337         /// </summary>
338         [EditorBrowsable(EditorBrowsableState.Never)]
339         public new PopupStyle Style
340         {
341             get
342             {
343                 var result = new PopupStyle(popupStyle);
344                 result.CopyPropertiesFromView(this);
345                 result.Title.CopyPropertiesFromView(titleText);
346                 return result;
347             }
348         }
349
350         /// <summary>
351         /// Popup Title.
352         /// </summary>
353         [EditorBrowsable(EditorBrowsableState.Never)]
354         public TextLabel Title
355         {
356             get
357             {
358                 if (null == titleText)
359                 {
360                     titleText = new TextLabel
361                     {
362                         PositionUsesPivotPoint = true,
363                         ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
364                         PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
365                         HorizontalAlignment = HorizontalAlignment.Begin,
366                         VerticalAlignment = VerticalAlignment.Bottom
367                     };
368                     Add(titleText);
369                 }
370                 return titleText;
371             }
372             internal set
373             {
374                 titleText = value;
375             }
376         }
377
378         /// <summary>
379         /// Title text string in Popup.
380         /// </summary>
381         /// <since_tizen> 6 </since_tizen>
382         [Obsolete("Deprecated in API8; Will be removed in API10")]
383         public string TitleText
384         {
385             get
386             {
387                 return popupStyle?.Title?.Text?.All;
388             }
389             set
390             {
391                 if (value != null)
392                 {
393                     if (popupStyle?.Title != null)
394                     {
395                         popupStyle.Title.Text = value;
396                     }
397                 }
398             }
399         }
400
401         /// <summary>
402         /// Title text point size in Popup.
403         /// </summary>
404         /// <since_tizen> 6 </since_tizen>
405         [Obsolete("Deprecated in API8; Will be removed in API10")]
406         public float TitlePointSize
407         {
408             get
409             {
410                 return popupStyle?.Title?.PointSize?.All ?? 0;
411             }
412             set
413             {
414                 if (popupStyle?.Title != null)
415                 {
416                     popupStyle.Title.PointSize = value;
417                 }
418             }
419         }
420
421         /// <summary>
422         /// Title text color in Popup.
423         /// </summary>
424         /// <since_tizen> 6 </since_tizen>
425         [Obsolete("Deprecated in API8; Will be removed in API10")]
426         public Color TitleTextColor
427         {
428             get
429             {
430                 return popupStyle?.Title?.TextColor?.All;
431             }
432             set
433             {
434                 if (popupStyle?.Title != null)
435                 {
436                     popupStyle.Title.TextColor = value;
437                 }
438             }
439         }
440
441         /// <summary>
442         /// Title text horizontal alignment in Popup.
443         /// </summary>
444         /// <since_tizen> 6 </since_tizen>
445         [Obsolete("Deprecated in API8; Will be removed in API10")]
446         public HorizontalAlignment TitleTextHorizontalAlignment
447         {
448             get
449             {
450                 return popupStyle?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
451             }
452             set
453             {
454                 popupStyle.Title.HorizontalAlignment = value;
455             }
456         }
457
458         /// <summary>
459         /// Title text's position in Popup.
460         /// </summary>
461         /// <since_tizen> 6 </since_tizen>
462         [Obsolete("Deprecated in API8; Will be removed in API10")]
463         public Position TitleTextPosition
464         {
465             get
466             {
467                 return popupStyle?.Title?.Position ?? new Position(0, 0, 0);
468             }
469             set
470             {
471                 popupStyle.Title.Position = value;
472             }
473         }
474
475         /// <summary>
476         /// Title text's height in Popup.
477         /// </summary>
478         /// <since_tizen> 6 </since_tizen>
479         [Obsolete("Deprecated in API8; Will be removed in API10")]
480         public int TitleHeight
481         {
482             get
483             {
484                 return (int)(popupStyle?.Title?.Size?.Height ?? 0);
485             }
486             set
487             {
488                 if (popupStyle?.Title?.Size != null)
489                 {
490                     popupStyle.Title.Size.Height = value;
491                 }
492             }
493         }
494
495         /// <summary>
496         /// Content view in Popup, only can be gotten.
497         /// </summary>
498         /// <since_tizen> 6 </since_tizen>
499         [Obsolete("Deprecated in API8; Will be removed in API10")]
500         public View ContentView
501         {
502             get;
503             private set;
504         }
505
506         /// <summary>
507         /// Button count in Popup.
508         /// </summary>
509         /// <since_tizen> 6 </since_tizen>
510         [Obsolete("Deprecated in API8; Will be removed in API10")]
511         public int ButtonCount
512         {
513             get;
514             set;
515         }
516
517         /// <summary>
518         /// Button height in Popup.
519         /// </summary>
520         /// <since_tizen> 6 </since_tizen>
521         [Obsolete("Deprecated in API8; Will be removed in API10")]
522         public int ButtonHeight
523         {
524             get
525             {
526                 return (int)GetValue(ButtonHeightProperty);
527             }
528             set
529             {
530                 SetValue(ButtonHeightProperty, value);
531             }
532         }
533
534         /// <summary>
535         /// Button text point size in Popup.
536         /// </summary>
537         /// <since_tizen> 6 </since_tizen>
538         [Obsolete("Deprecated in API8; Will be removed in API10")]
539         public float ButtonTextPointSize
540         {
541             get
542             {
543                 return (float)GetValue(ButtonTextPointSizeProperty);
544             }
545             set
546             {
547                 SetValue(ButtonTextPointSizeProperty, value);
548             }
549         }
550
551         /// <summary>
552         /// Button text font family in Popup.
553         /// </summary>
554         /// <since_tizen> 6 </since_tizen>
555         [Obsolete("Deprecated in API8; Will be removed in API10")]
556         public string ButtonFontFamily
557         {
558             get
559             {           
560                 return (string)GetValue(ButtonFontFamilyProperty);
561             }
562             set
563             {
564                 SetValue(ButtonFontFamilyProperty, value);
565             }
566         }
567
568         /// <summary>
569         /// Button text color in Popup.
570         /// </summary>
571         /// <since_tizen> 6 </since_tizen>
572         [Obsolete("Deprecated in API8; Will be removed in API10")]
573         public Color ButtonTextColor
574         {
575             get
576             {
577                 return (Color)GetValue(ButtonTextColorProperty);
578             }
579             set
580             {
581                 SetValue(ButtonTextColorProperty, value);
582             }
583         }
584
585         /// <summary>
586         /// Button overlay background color selector in Popup.
587         /// </summary>
588         /// <since_tizen> 6 </since_tizen>
589         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
590         [EditorBrowsable(EditorBrowsableState.Never)]
591         public Selector<Color> ButtonOverLayBackgroundColorSelector
592         {
593             get
594             {
595                 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
596             }
597             set
598             {
599                 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
600             }
601         }
602
603         /// <summary>
604         /// Button text horizontal alignment in Popup.
605         /// </summary>
606         /// <since_tizen> 6 </since_tizen>
607         [Obsolete("Deprecated in API8; Will be removed in API10")]
608         public HorizontalAlignment ButtonTextAlignment
609         {
610             get
611             {   
612                 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
613             }
614             set
615             {
616                 SetValue(ButtonTextAlignmentProperty, value);
617             }
618         }
619
620         /// <summary>
621         /// Button background image's resource url in Popup.
622         /// </summary>
623         /// <since_tizen> 6 </since_tizen>
624         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
625         [EditorBrowsable(EditorBrowsableState.Never)]
626         public string ButtonBackground
627         {
628             get
629             {     
630                 return (string)GetValue(ButtonBackgroundProperty);
631             }
632             set
633             {
634                 SetValue(ButtonBackgroundProperty, value);
635             }
636         }
637
638         /// <summary>
639         /// Button background image's border in Popup.
640         /// </summary>
641         /// <since_tizen> 6 </since_tizen>
642         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
643         [EditorBrowsable(EditorBrowsableState.Never)]
644         public Rectangle ButtonBackgroundBorder
645         {
646             get
647             {
648                 
649                 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
650             }
651             set
652             {
653                 SetValue(ButtonBackgroundBorderProperty, value);
654             }
655         }
656
657         /// <summary>
658         /// Button's image shadow in Popup.
659         /// </summary>
660         /// <since_tizen> 6 </since_tizen>
661         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
662         [EditorBrowsable(EditorBrowsableState.Never)]
663         public ImageShadow ButtonImageShadow
664         {
665             get => (ImageShadow)GetValue(ButtonImageShadowProperty);
666             set => SetValue(ButtonImageShadowProperty, value);
667         }
668
669
670         /// <summary>
671         /// Set button text by index.
672         /// </summary>
673         /// <param name="index">Button index.</param>
674         /// <param name="text">Button text string.</param>
675         /// <since_tizen> 6 </since_tizen>
676         [Obsolete("Deprecated in API8; Will be removed in API10")]
677         public void SetButtonText(int index, string text)
678         {
679             AddButton(text);
680         }
681
682         /// <summary>
683         /// Dispose Popup and all children on it.
684         /// </summary>
685         /// <param name="type">Dispose type.</param>
686         /// <since_tizen> 6 </since_tizen>
687         [Obsolete("Deprecated in API8; Will be removed in API10")]
688         protected override void Dispose(DisposeTypes type)
689         {
690             if (disposed)
691             {
692                 return;
693             }
694
695             if (type == DisposeTypes.Explicit)
696             {
697                 if (titleText != null)
698                 {
699                     Remove(titleText);
700                     titleText.Dispose();
701                     titleText = null;
702                 }
703                 if (ContentView != null)
704                 {
705                     Remove(ContentView);
706                     ContentView.Dispose();
707                     ContentView = null;
708                 }
709
710                 if (btGroup != null)
711                 {
712                     btGroup.Dispose();
713                     btGroup = null;
714                 }
715             }
716
717             base.Dispose(type);
718         }
719
720         /// <summary>
721         /// Focus gained callback.
722         /// </summary>
723         /// <since_tizen> 6 </since_tizen>
724         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
725         [EditorBrowsable(EditorBrowsableState.Never)]
726         public override void OnFocusGained()
727         {
728             base.OnFocusGained();
729         }
730
731         /// <summary>
732         /// Focus lost callback.
733         /// </summary>
734         /// <since_tizen> 6 </since_tizen>
735         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
736         [EditorBrowsable(EditorBrowsableState.Never)]
737         public override void OnFocusLost()
738         {
739             base.OnFocusLost();
740         }
741
742         /// <summary>
743         /// Apply style to popup.
744         /// </summary>
745         /// <param name="viewStyle">The style to apply.</param>
746         [EditorBrowsable(EditorBrowsableState.Never)]
747         public override void ApplyStyle(ViewStyle viewStyle)
748         {
749             base.ApplyStyle(viewStyle);
750             PopupStyle ppStyle = viewStyle as PopupStyle;
751             if (null != ppStyle)
752             {
753                 if (ppStyle.Buttons != null)
754                 {
755                     if (ppStyle.Buttons.PositionUsesPivotPoint == null) ppStyle.Buttons.PositionUsesPivotPoint = true;
756                     if (ppStyle.Buttons.ParentOrigin == null) ppStyle.Buttons.ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft;
757                     if (ppStyle.Buttons.PivotPoint == null) ppStyle.Buttons.PivotPoint = Tizen.NUI.PivotPoint.BottomLeft;
758                 }
759                 Title.ApplyStyle(ppStyle.Title);
760                 Title.RaiseToTop();
761             }
762         }
763
764         /// <summary>
765         /// Get Popup style.
766         /// </summary>
767         /// <returns>The default popup style.</returns>
768         [EditorBrowsable(EditorBrowsableState.Never)]
769         protected override ViewStyle CreateViewStyle()
770         {
771             return new PopupStyle();
772         }
773
774         /// <inheritdoc/>
775         [EditorBrowsable(EditorBrowsableState.Never)]
776         protected override void OnUpdate()
777         {
778             base.OnUpdate();
779             UpdateView();
780         }
781
782         private void Initialize()
783         {
784             container.Add(this);
785             container.SetTouchConsumed(true);
786             container.SetHoverConsumed(true);
787
788             LeaveRequired = true;
789             PropertyChanged += PopupStylePropertyChanged;
790
791             // ContentView
792             ContentView = new View()
793             {
794                 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
795                 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
796                 PositionUsesPivotPoint = true
797             };
798             Add(ContentView);
799             ContentView.RaiseToTop();
800
801             // Button
802             btGroup = new ButtonGroup(this);
803         }
804
805         private void UpdateView()
806         {
807             if (popupStyle == null) return;
808             btGroup.UpdateButton(popupStyle.Buttons);
809             UpdateContentView();
810             UpdateTitle();
811         }
812
813         private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
814         {
815             if (PopupButtonClickEvent != null && btGroup.Count > 0)
816             {
817                 Button button = sender as Button;
818                 for (int i = 0; i < btGroup.Count; i++)
819                 {
820                     if (button == GetButton(i))
821                     {
822                         ButtonClickEventArgs args = new ButtonClickEventArgs();
823                         args.ButtonIndex = i;
824                         PopupButtonClickEvent(this, args);
825                     }
826                 }
827             }
828         }
829
830         private void PopupStylePropertyChanged(object sender, PropertyChangedEventArgs e)
831         {
832             if (e.PropertyName.Equals("LayoutDirection"))
833             {
834                 btGroup.UpdateButton(popupStyle.Buttons);
835             }
836         }
837
838         private void UpdateContentView()
839         {
840             int titleX = 0;
841             int titleY = 0;
842             int titleH = 0;
843             int buttonH = 0;
844             string strText = Title.Text;
845             if (!string.IsNullOrEmpty(strText) && Title.Size != null)
846             {
847                 titleH = (int)titleText.Size.Height;
848             }
849
850             if (!string.IsNullOrEmpty(strText) && Title.Position != null)
851             {
852                 titleX = (int)Title.Position.X;
853                 titleY = (int)Title.Position.Y;
854             }
855
856             if (btGroup.Count != 0 && popupStyle?.Buttons?.Size != null )
857             {
858                 buttonH = (int)popupStyle.Buttons.Size.Height;
859             }
860             ContentView.Size = new Size(Size.Width - titleX * 2, Size.Height - titleY - titleH - buttonH);
861             ContentView.Position = new Position(titleX, titleY + titleH);
862             ContentView.RaiseToTop();
863         }
864
865         private void UpdateTitle()
866         {
867             if (titleText != null && string.IsNullOrEmpty(popupStyle.Title.Text.All) && popupStyle.Title.Size != null)
868             {
869                 titleText.RaiseToTop();
870             }
871         }
872         /// <summary>
873         /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
874         /// </summary>
875         /// <since_tizen> 6 </since_tizen>
876         [Obsolete("Deprecated in API8; Will be removed in API10")]
877         public class ButtonClickEventArgs : EventArgs
878         {
879             /// <summary> Button index which is clicked in Popup </summary>
880             /// <since_tizen> 6 </since_tizen>
881             [Obsolete("Deprecated in API8; Will be removed in API10")]
882             public int ButtonIndex;
883         }
884     }
885 }