[NUI] Clean shadow related properties from Control and sample (#1297)
[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     public class Popup : Control
31     {
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) =>
35         {
36             var instance = (Popup)bindable;
37             if (newValue != null)
38             {
39                 instance.Style.Buttons.Size.Height = (int)newValue;
40                 instance.btGroup.Itemheight = (int)newValue;
41                 instance.UpdateView();
42             }
43         },
44         defaultValueCreator: (bindable) =>
45         {
46             var instance = (Popup)bindable;
47             return (int)(instance.Style?.Buttons?.Size?.Height ?? 0);
48         });
49
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) =>
53         {
54             var instance = (Popup)bindable;
55             if (newValue != null)
56             {
57                 if (instance.Style.Buttons.Text.PointSize == null)
58                 {
59                     instance.Style.Buttons.Text.PointSize = new Selector<float?>();
60                 }
61                 instance.Style.Buttons.Text.PointSize.All = (float)newValue;
62                 instance.btGroup.ItemPointSize = (float)newValue;
63             }
64         },
65         defaultValueCreator: (bindable) =>
66         {
67             var instance = (Popup)bindable;
68             return instance.Style?.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.Style.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.Style?.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.Style.Buttons.Text.TextColor == null)
96                 {
97                     instance.Style.Buttons.Text.TextColor = new Selector<Color>();
98                 }
99                 instance.Style.Buttons.Text.TextColor.All = (Color)newValue;
100                 instance.btGroup.ItemTextColor = (Color)newValue;
101             }
102         },
103         defaultValueCreator: (bindable) =>
104         {
105             var instance = (Popup)bindable;
106             return instance.Style?.Buttons?.Text?.TextColor?.All;
107         });
108
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) =>
112         {
113             var instance = (Popup)bindable;
114             if (newValue != null)
115             {
116                 instance.Style.Buttons.Overlay.BackgroundColor = (Selector<Color>)newValue;
117                 instance.btGroup.OverLayBackgroundColorSelector = (Selector<Color>)newValue;
118             }
119         },
120         defaultValueCreator: (bindable) =>
121         {
122             var instance = (Popup)bindable;
123             return instance.Style?.Buttons?.Overlay?.BackgroundColor;
124         });
125
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) =>
129         {
130             var instance = (Popup)bindable;
131             if (newValue != null)
132             {
133                 instance.Style.Buttons.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
134                 instance.btGroup.ItemTextAlignment = (HorizontalAlignment)newValue;
135             }
136         },
137         defaultValueCreator: (bindable) =>
138         {
139             var instance = (Popup)bindable;
140             return instance.Style?.Buttons?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
141         });
142
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) =>
146         {
147             var instance = (Popup)bindable;
148             if (newValue != null)
149             {
150                 if (instance.Style.Buttons.BackgroundImage == null)
151                 {
152                     instance.Style.Buttons.BackgroundImage = new Selector<string>();
153                 }
154                 instance.btGroup.ItemBackgroundImageUrl = (string)newValue;
155                 instance.Style.Buttons.BackgroundImage = (string)newValue;
156             }
157         },
158         defaultValueCreator: (bindable) =>
159         {
160             var instance = (Popup)bindable;
161             return instance.Style?.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.Style.Buttons.BackgroundImageBorder == null)
172                 {
173                     instance.Style.Buttons.BackgroundImageBorder = new Selector<Rectangle>();
174                 }
175                 instance.Style.Buttons.BackgroundImageBorder = (Rectangle)newValue;
176                 instance.btGroup.ItemBackgroundBorder = (Rectangle)newValue;
177             }
178         },
179         defaultValueCreator: (bindable) =>
180         {
181             var instance = (Popup)bindable;
182             return instance.Style?.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 = (ImageShadow)ImageShadow.Clone(shadow);
192             instance.Style.Buttons.ImageShadow = (ImageShadow)ImageShadow.Clone(shadow);
193         },
194         defaultValueCreator: (bindable) =>
195         {
196             var instance = (Popup)bindable;
197             return instance.Style?.Buttons?.ImageShadow?.All;
198         });
199
200
201         private TextLabel titleText;
202         private ButtonGroup btGroup = null;
203         private Window window = null;
204         static Popup() { }
205
206         /// <summary>
207         /// Creates a new instance of a Popup.
208         /// </summary>
209         /// <since_tizen> 6 </since_tizen>
210         public Popup() : base()
211         {
212             Initialize();
213         }
214
215         /// <summary>
216         /// Creates a new instance of a Popup with style.
217         /// </summary>
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)
223         {
224             Initialize();
225         }
226
227         /// <summary>
228         /// Creates a new instance of a Popup with attributes.
229         /// </summary>
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)
235         {
236             Initialize();
237         }
238
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)
242         {
243             if (null == win) return;
244             window = win;
245             window.Add(this);
246         }
247
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)
251         {
252             if (Style.Buttons != null)
253             {
254                 Button btn = new Button(Style.Buttons);
255                 btn.Style.Text.Text = buttonText;
256                 btn.ClickEvent += ButtonClickEvent;
257                 btGroup.AddItem(btn);
258                 UpdateView();
259             }
260         }
261
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)
265         {
266             AddButton(buttonText);
267         }
268
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)
272         {
273             if (Style.Buttons != null && style != null)
274             {
275                 Style.Buttons.CopyFrom(style);
276                 AddButton(buttonText);
277             }
278         }
279
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)
283         {
284             return btGroup.GetItem(index);
285         }
286
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)
290         {
291             btGroup.RemoveItem(index);
292         }
293
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)
297         {
298             if (null != ContentView)
299             {
300                 ContentView.Add(childView);
301             }
302             UpdateView();
303         }
304
305         /// <summary>
306         /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
307         /// </summary>
308         /// <since_tizen> 6 </since_tizen>
309         public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
310
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;
314
315         /// <summary>
316         /// Title text string in Popup.
317         /// </summary>
318         /// <since_tizen> 6 </since_tizen>
319         public string TitleText
320         {
321             get
322             {
323                 return Style?.Title?.Text?.All;
324             }
325             set
326             {
327                 if (value != null)
328                 {
329                     if (Style.Title.Text == null)
330                     {
331                         Style.Title.Text = new Selector<string>();
332                     }
333                     Style.Title.Text.All = value;
334                 }
335             }
336         }
337
338         /// <summary>
339         /// Title text point size in Popup.
340         /// </summary>
341         /// <since_tizen> 6 </since_tizen>
342         public float TitlePointSize
343         {
344             get
345             {
346                 return Style?.Title?.PointSize?.All ?? 0;
347             }
348             set
349             {
350                 if (Style.Title.PointSize == null)
351                 {
352                     Style.Title.PointSize = new Selector<float?>();
353                 }
354                 Style.Title.PointSize.All = value;
355             }
356         }
357
358         /// <summary>
359         /// Title text color in Popup.
360         /// </summary>
361         /// <since_tizen> 6 </since_tizen>
362         public Color TitleTextColor
363         {
364             get
365             {
366                 return Style?.Title?.TextColor?.All;
367             }
368             set
369             {
370                 if (Style.Title.TextColor == null)
371                 {
372                     Style.Title.TextColor = new Selector<Color>();
373                 }
374                 Style.Title.TextColor.All = value;
375             }
376         }
377
378         /// <summary>
379         /// Title text horizontal alignment in Popup.
380         /// </summary>
381         /// <since_tizen> 6 </since_tizen>
382         public HorizontalAlignment TitleTextHorizontalAlignment
383         {
384             get
385             {
386                 return Style?.Title?.HorizontalAlignment ?? HorizontalAlignment.Center;
387             }
388             set
389             {
390                 Style.Title.HorizontalAlignment = value;
391             }
392         }
393
394         /// <summary>
395         /// Title text's position in Popup.
396         /// </summary>
397         /// <since_tizen> 6 </since_tizen>
398         public Position TitleTextPosition
399         {
400             get
401             {
402                 return Style?.Title?.Position ?? new Position(0, 0, 0);
403             }
404             set
405             {
406                 Style.Title.Position = value;
407             }
408         }
409
410         /// <summary>
411         /// Title text's height in Popup.
412         /// </summary>
413         /// <since_tizen> 6 </since_tizen>
414         public int TitleHeight
415         {
416             get
417             {
418                 return (int)(Style?.Title?.Size?.Height ?? 0);
419             }
420             set
421             {
422                 Style.Title.Size.Height = value;
423             }
424         }
425
426         /// <summary>
427         /// Content view in Popup, only can be gotten.
428         /// </summary>
429         /// <since_tizen> 6 </since_tizen>
430         public View ContentView
431         {
432             get;
433             private set;
434         }
435
436         /// <summary>
437         /// Button count in Popup.
438         /// </summary>
439         /// <since_tizen> 6 </since_tizen>
440         public int ButtonCount
441         {
442             get;
443             set;
444         }
445
446         /// <summary>
447         /// Button height in Popup.
448         /// </summary>
449         /// <since_tizen> 6 </since_tizen>
450         public int ButtonHeight
451         {
452             get
453             {
454                 return (int)GetValue(ButtonHeightProperty);
455             }
456             set
457             {
458                 SetValue(ButtonHeightProperty, value);
459             }
460         }
461
462         /// <summary>
463         /// Button text point size in Popup.
464         /// </summary>
465         /// <since_tizen> 6 </since_tizen>
466         public float ButtonTextPointSize
467         {
468             get
469             {
470                 return (float)GetValue(ButtonTextPointSizeProperty);
471             }
472             set
473             {
474                 SetValue(ButtonTextPointSizeProperty, value);
475             }
476         }
477
478         /// <summary>
479         /// Button text font family in Popup.
480         /// </summary>
481         /// <since_tizen> 6 </since_tizen>
482         public string ButtonFontFamily
483         {
484             get
485             {           
486                 return (string)GetValue(ButtonFontFamilyProperty);
487             }
488             set
489             {
490                 SetValue(ButtonFontFamilyProperty, value);
491             }
492         }
493
494         /// <summary>
495         /// Button text color in Popup.
496         /// </summary>
497         /// <since_tizen> 6 </since_tizen>
498         public Color ButtonTextColor
499         {
500             get
501             {
502                 return (Color)GetValue(ButtonTextColorProperty);
503             }
504             set
505             {
506                 SetValue(ButtonTextColorProperty, value);
507             }
508         }
509
510         /// <summary>
511         /// Button overlay background color selector in Popup.
512         /// </summary>
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
517         {
518             get
519             {
520                 return (Selector<Color>)GetValue(ButtonOverLayBackgroundColorSelectorProperty);
521             }
522             set
523             {
524                 SetValue(ButtonOverLayBackgroundColorSelectorProperty, value);
525             }
526         }
527
528         /// <summary>
529         /// Button text horizontal alignment in Popup.
530         /// </summary>
531         /// <since_tizen> 6 </since_tizen>
532         public HorizontalAlignment ButtonTextAlignment
533         {
534             get
535             {   
536                 return (HorizontalAlignment)GetValue(ButtonTextAlignmentProperty);
537             }
538             set
539             {
540                 SetValue(ButtonTextAlignmentProperty, value);
541             }
542         }
543
544         /// <summary>
545         /// Button background image's resource url in Popup.
546         /// </summary>
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
551         {
552             get
553             {     
554                 return (string)GetValue(ButtonBackgroundProperty);
555             }
556             set
557             {
558                 SetValue(ButtonBackgroundProperty, value);
559             }
560         }
561
562         /// <summary>
563         /// Button background image's border in Popup.
564         /// </summary>
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
569         {
570             get
571             {
572                 
573                 return (Rectangle)GetValue(ButtonBackgroundBorderProperty);
574             }
575             set
576             {
577                 SetValue(ButtonBackgroundBorderProperty, value);
578             }
579         }
580
581         /// <summary>
582         /// Button's image shadow in Popup.
583         /// </summary>
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
588         {
589             get => (ImageShadow)GetValue(ButtonImageShadowProperty);
590             set => SetValue(ButtonImageShadowProperty, value);
591         }
592
593
594         /// <summary>
595         /// Set button text by index.
596         /// </summary>
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)
601         {
602             AddButton(text);
603         }
604
605         /// <summary>
606         /// Dispose Popup and all children on it.
607         /// </summary>
608         /// <param name="type">Dispose type.</param>
609         /// <since_tizen> 6 </since_tizen>
610         protected override void Dispose(DisposeTypes type)
611         {
612             if (disposed)
613             {
614                 return;
615             }
616
617             if (type == DisposeTypes.Explicit)
618             {
619                 if (titleText != null)
620                 {
621                     Remove(titleText);
622                     titleText.Dispose();
623                     titleText = null;
624                 }
625                 if (ContentView != null)
626                 {
627                     Remove(ContentView);
628                     ContentView.Dispose();
629                     ContentView = null;
630                 }
631
632                 if (btGroup != null)
633                 {
634                     btGroup.Dispose();
635                     btGroup = null;
636                 }
637             }
638
639             base.Dispose(type);
640         }
641
642         /// <summary>
643         /// Focus gained callback.
644         /// </summary>
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()
649         {
650             base.OnFocusGained();
651         }
652
653         /// <summary>
654         /// Focus lost callback.
655         /// </summary>
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()
660         {
661             base.OnFocusLost();
662         }
663
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)
667         {
668             base.ApplyStyle(viewStyle);
669             PopupStyle ppStyle = viewStyle as PopupStyle;
670             if (null != ppStyle)
671             {
672                 if (null == titleText)
673                 {
674                     titleText = new TextLabel();
675                     Add(titleText);
676                 }
677                 titleText.RaiseToTop();
678                 titleText.ApplyStyle(ppStyle.Title);
679             }
680         }
681
682         /// <summary>
683         /// Get Popup attribues.
684         /// </summary>
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()
689         {
690             return new PopupStyle();
691         }
692
693         /// <summary>
694         /// Theme change callback when theme is changed, this callback will be trigger.
695         /// </summary>
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)
700         {
701             PopupStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as PopupStyle;
702             if (tempAttributes != null)
703             {
704                 string strSaveTitleText = TitleText;
705                 Style.CopyFrom(tempAttributes);
706                 Style.Title.Text = strSaveTitleText;
707                 UpdateView();
708             }
709         }
710
711         private void Initialize()
712         {
713             LeaveRequired = true;
714             PropertyChanged += PopupAttributesPropertyChanged;
715
716             // ContentView
717             ContentView = new View()
718             {
719                 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
720                 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
721                 PositionUsesPivotPoint = true
722             };
723             Add(ContentView);
724             ContentView.RaiseToTop();
725
726             // Title
727             if (null == titleText)
728             {
729                 titleText = new TextLabel();
730                 titleText.RaiseToTop();
731                 Add(titleText);
732             }
733
734             // Button
735             btGroup = new ButtonGroup(this);
736         }
737
738         private void UpdateView()
739         {
740             btGroup.UpdateButton(Style.Buttons);
741             UpdateContentView();
742             UpdateTitle();
743         }
744
745         private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
746         {
747             if (PopupButtonClickEvent != null && btGroup.Count > 0)
748             {
749                 Button button = sender as Button;
750                 for (int i = 0; i < btGroup.Count; i++)
751                 {
752                     if (button == GetButton(i))
753                     {
754                         ButtonClickEventArgs args = new ButtonClickEventArgs();
755                         args.ButtonIndex = i;
756                         PopupButtonClickEvent(this, args);
757                     }
758                 }
759             }
760         }
761
762         private void PopupAttributesPropertyChanged(object sender, PropertyChangedEventArgs e)
763         {
764             if (e.PropertyName.Equals("LayoutDirection"))
765             {
766                 btGroup.UpdateButton(Style.Buttons);
767             }
768         }
769
770         private void UpdateContentView()
771         {
772             int titleX = 0;
773             int titleY = 0;
774             int titleH = 0;
775             int buttonH = 0;
776             string strText = Style.Title.Text.All;
777             if (!string.IsNullOrEmpty(strText) && Style.Title.Size != null)
778             {
779                 titleH = (int)titleText.Size.Height;
780             }
781
782             if (!string.IsNullOrEmpty(strText) && Style.Title.Position != null)
783             {
784                 titleX = (int)Style.Title.Position.X;
785                 titleY = (int)Style.Title.Position.Y;
786             }
787
788             if (btGroup.Count != 0)
789             {
790                 buttonH = (int)Style.Buttons.Size.Height;
791             }
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();
795         }
796
797         private void UpdateTitle()
798         {
799             if (titleText != null && string.IsNullOrEmpty(Style.Title.Text.All) && Style.Title.Size != null)
800             {
801                 titleText.RaiseToTop();
802             }
803         }
804         /// <summary>
805         /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
806         /// </summary>
807         /// <since_tizen> 6 </since_tizen>
808         public class ButtonClickEventArgs : EventArgs
809         {
810             /// <summary> Button index which is clicked in Popup </summary>
811             /// <since_tizen> 6 </since_tizen>
812             public int ButtonIndex;
813         }
814     }
815 }