[NUI] Open public apis of NUI.Components for TCSACR-248 (#1061)
[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 System.ComponentModel;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// Popup is one kind of common component, it can be used as popup window.
26     /// User can handle Popup button count, head title and content area.
27     /// </summary>
28     /// <since_tizen> 6 </since_tizen>
29     public class Popup : Control
30     {
31         private ImageView backgroundImage;
32         private ImageView shadowImage;
33         private TextLabel titleText;
34         private List<Button> buttonList;
35         private List<string> buttonTextList = new List<string>();
36
37         private PopupAttributes popupAttributes;
38         private int buttonCount = 0;
39
40         /// <summary>
41         /// Creates a new instance of a Popup.
42         /// </summary>
43         /// <since_tizen> 6 </since_tizen>
44         public Popup() : base()
45         {
46             Initialize();
47         }
48
49         /// <summary>
50         /// Creates a new instance of a Popup with style.
51         /// </summary>
52         /// <param name="style">Create Popup by special style defined in UX.</param>
53         /// <since_tizen> 6 </since_tizen>
54         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public Popup(string style) : base(style)
57         {
58             Initialize();
59         }
60
61         /// <summary>
62         /// Creates a new instance of a Popup with attributes.
63         /// </summary>
64         /// <param name="attributes">Create Popup by attributes customized by user.</param>
65         /// <since_tizen> 6 </since_tizen>
66         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public Popup(PopupAttributes attributes) : base(attributes)
69         {
70             Initialize();
71         }
72
73         /// <summary>
74         /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
75         /// </summary>
76         /// <since_tizen> 6 </since_tizen>
77         public event EventHandler<ButtonClickEventArgs> PopupButtonClickEvent;
78
79         /// <summary>
80         /// Title text string in Popup.
81         /// </summary>
82         /// <since_tizen> 6 </since_tizen>
83         public string TitleText
84         {
85             get
86             {
87                 return popupAttributes?.TitleTextAttributes?.Text?.All;
88             }
89             set
90             {
91                 if (value != null)
92                 {
93                     CreateTitleTextAttributes();
94                     if (popupAttributes.TitleTextAttributes.Text == null)
95                     {
96                         popupAttributes.TitleTextAttributes.Text = new StringSelector();
97                     }
98                     popupAttributes.TitleTextAttributes.Text.All = value;
99
100                     RelayoutRequest();
101                 }
102             }
103         }
104
105         /// <summary>
106         /// Button count in Popup.
107         /// </summary>
108         /// <since_tizen> 6 </since_tizen>
109         public int ButtonCount
110         {
111             get
112             {
113                 return buttonCount;
114             }
115             set
116             {
117                 if (buttonCount != value)
118                 {
119                     buttonCount = value;
120                     RelayoutRequest();
121                 }
122             }
123         }
124
125         /// <summary>
126         /// Content view in Popup, only can be gotten.
127         /// </summary>
128         /// <since_tizen> 6 </since_tizen>
129         public View ContentView
130         {
131             get;
132             private set;
133         }
134
135         /// <summary>
136         /// Shadow image's resource url in Popup.
137         /// </summary>
138         /// <since_tizen> 6 </since_tizen>
139         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public string ShadowImageURL
142         {
143             get
144             {
145                 return popupAttributes?.ShadowImageAttributes?.ResourceURL?.All;
146             }
147             set
148             {
149                 if (value != null)
150                 {
151                     CreateShadowAttributes();
152                     if (popupAttributes.ShadowImageAttributes.ResourceURL == null)
153                     {
154                         popupAttributes.ShadowImageAttributes.ResourceURL = new StringSelector();
155                     }
156                     popupAttributes.ShadowImageAttributes.ResourceURL.All = value;
157                     RelayoutRequest();
158                 }
159             }
160         }
161
162         /// <summary>
163         /// Shadow image's border in Popup.
164         /// </summary>
165         /// <since_tizen> 6 </since_tizen>
166         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
167         [EditorBrowsable(EditorBrowsableState.Never)]
168         public Rectangle ShadowImageBorder
169         {
170             get
171             {
172                 return popupAttributes?.ShadowImageAttributes?.Border?.All;
173             }
174             set
175             {
176                 if (value != null)
177                 {
178                     CreateShadowAttributes();
179                     if (popupAttributes.ShadowImageAttributes.Border == null)
180                     {
181                         popupAttributes.ShadowImageAttributes.Border = new RectangleSelector();
182                     }
183                     popupAttributes.ShadowImageAttributes.Border.All = value;
184                     RelayoutRequest();
185                 }
186             }
187         }
188
189         /// <summary>
190         /// Background image's resource url in Popup.
191         /// </summary>
192         /// <since_tizen> 6 </since_tizen>
193         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
194         [EditorBrowsable(EditorBrowsableState.Never)]
195         public string BackgroundImageURL
196         {
197             get
198             {
199                 return popupAttributes?.BackgroundImageAttributes?.ResourceURL?.All;
200             }
201             set
202             {
203                 if (value != null)
204                 {
205                     CreateBackgroundAttributes();
206                     if (popupAttributes.BackgroundImageAttributes.ResourceURL == null)
207                     {
208                         popupAttributes.BackgroundImageAttributes.ResourceURL = new StringSelector();
209                     }
210                     popupAttributes.BackgroundImageAttributes.ResourceURL.All = value;
211                     RelayoutRequest();
212                 }
213             }
214         }
215
216         /// <summary>
217         /// Background image's border in Popup.
218         /// </summary>
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 Rectangle BackgroundImageBorder
223         {
224             get
225             {
226                 return popupAttributes?.BackgroundImageAttributes?.Border?.All;
227             }
228             set
229             {
230                 if (value != null)
231                 {
232                     CreateBackgroundAttributes();
233                     if (popupAttributes.BackgroundImageAttributes.Border == null)
234                     {
235                         popupAttributes.BackgroundImageAttributes.Border = new RectangleSelector();
236                     }
237                     popupAttributes.BackgroundImageAttributes.Border.All = value;
238                     RelayoutRequest();
239                 }
240             }
241         }
242
243         /// <summary>
244         /// Title text point size in Popup.
245         /// </summary>
246         /// <since_tizen> 6 </since_tizen>
247         public float TitlePointSize
248         {
249             get
250             {
251                 return popupAttributes?.TitleTextAttributes?.PointSize?.All ?? 0;
252             }
253             set
254             {
255                 CreateTitleTextAttributes();
256                 if (popupAttributes.TitleTextAttributes.PointSize == null)
257                 {
258                     popupAttributes.TitleTextAttributes.PointSize = new FloatSelector();
259                 }
260                 popupAttributes.TitleTextAttributes.PointSize.All = value;
261                 RelayoutRequest();
262             }
263         }
264
265         /// <summary>
266         /// Title text font family in Popup.
267         /// </summary>
268         /// <since_tizen> 6 </since_tizen>
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 string TitleFontFamily
272         {
273             get
274             {
275                 return popupAttributes?.TitleTextAttributes?.FontFamily;
276             }
277             set
278             {
279                 CreateTitleTextAttributes();
280                 popupAttributes.TitleTextAttributes.FontFamily = value;
281                 RelayoutRequest();
282             }
283         }
284
285         /// <summary>
286         /// Title text color in Popup.
287         /// </summary>
288         /// <since_tizen> 6 </since_tizen>
289         public Color TitleTextColor
290         {
291             get
292             {
293                 return popupAttributes?.TitleTextAttributes?.TextColor?.All;
294             }
295             set
296             {
297                 CreateTitleTextAttributes();
298                 if (popupAttributes.TitleTextAttributes.TextColor == null)
299                 {
300                     popupAttributes.TitleTextAttributes.TextColor = new ColorSelector();
301                 }
302                 popupAttributes.TitleTextAttributes.TextColor.All = value;
303                 RelayoutRequest();
304             }
305         }
306
307         /// <summary>
308         /// Title text horizontal alignment in Popup.
309         /// </summary>
310         /// <since_tizen> 6 </since_tizen>
311         public HorizontalAlignment TitleTextHorizontalAlignment
312         {
313             get
314             {
315                 return popupAttributes?.TitleTextAttributes?.HorizontalAlignment ?? HorizontalAlignment.Center;
316             }
317             set
318             {
319                 CreateTitleTextAttributes();
320                 popupAttributes.TitleTextAttributes.HorizontalAlignment = value;
321                 RelayoutRequest();
322             }
323         }
324
325         /// <summary>
326         /// Title text's position in Popup.
327         /// </summary>
328         /// <since_tizen> 6 </since_tizen>
329         public Position TitleTextPosition
330         {
331             get
332             {
333                 return popupAttributes?.TitleTextAttributes?.Position ?? new Position(0, 0, 0);
334             }
335             set
336             {
337                 CreateTitleTextAttributes();
338                 popupAttributes.TitleTextAttributes.Position = value;
339                 RelayoutRequest();
340             }
341         }
342
343         /// <summary>
344         /// Title text's height in Popup.
345         /// </summary>
346         /// <since_tizen> 6 </since_tizen>
347         public int TitleHeight
348         {
349             get
350             {
351                 return (int)(popupAttributes?.TitleTextAttributes?.Size?.Height ?? 0);
352             }
353             set
354             {
355                 CreateTitleTextAttributes();
356                 popupAttributes.TitleTextAttributes.Size.Height = value;
357                 RelayoutRequest();
358             }
359         }
360
361         /// <summary>
362         /// Shadow offset in Popup, including left, right, up and bottom offset.
363         /// </summary>
364         /// <since_tizen> 6 </since_tizen>
365         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
366         [EditorBrowsable(EditorBrowsableState.Never)]
367         public Vector4 ShadowOffset
368         {
369             get
370             {
371                 return popupAttributes?.ShadowOffset;
372             }
373             set
374             {
375                 if (value != null)
376                 {
377                     if (popupAttributes.ShadowOffset == null)
378                     {
379                         popupAttributes.ShadowOffset = new Vector4(0, 0, 0, 0);
380                     }
381                     popupAttributes.ShadowOffset = value;
382                     RelayoutRequest();
383                 }
384             }
385         }
386
387         /// <summary>
388         /// Button height in Popup.
389         /// </summary>
390         /// <since_tizen> 6 </since_tizen>
391         public int ButtonHeight
392         {
393             get
394             {
395                 return (int)(popupAttributes?.ButtonAttributes?.Size?.Height ?? 0);
396             }
397             set
398             {
399                 CreateButtonAttributes();
400                 popupAttributes.ButtonAttributes.Size.Height = value;
401                 RelayoutRequest();
402             }
403         }
404
405         /// <summary>
406         /// Button text point size in Popup.
407         /// </summary>
408         /// <since_tizen> 6 </since_tizen>
409         public float ButtonTextPointSize
410         {
411             get
412             {
413                 return popupAttributes?.ButtonAttributes?.TextAttributes?.PointSize?.All ?? 0;
414             }
415             set
416             {
417                 CreateButtonAttributes();
418                 if (popupAttributes.ButtonAttributes.TextAttributes.PointSize == null)
419                 {
420                     popupAttributes.ButtonAttributes.TextAttributes.PointSize = new FloatSelector();
421                 }
422                 popupAttributes.ButtonAttributes.TextAttributes.PointSize.All = value;
423                 RelayoutRequest();
424             }
425         }
426
427         /// <summary>
428         /// Button text font family in Popup.
429         /// </summary>
430         /// <since_tizen> 6 </since_tizen>
431         public string ButtonFontFamily
432         {
433             get
434             {
435                 return popupAttributes?.ButtonAttributes?.TextAttributes?.FontFamily;
436             }
437             set
438             {
439                 CreateButtonAttributes();
440                 popupAttributes.ButtonAttributes.TextAttributes.FontFamily = value;
441                 RelayoutRequest();
442             }
443         }
444
445         /// <summary>
446         /// Button text color in Popup.
447         /// </summary>
448         /// <since_tizen> 6 </since_tizen>
449         public Color ButtonTextColor
450         {
451             get
452             {
453                 return popupAttributes?.ButtonAttributes?.TextAttributes?.TextColor?.All;
454             }
455             set
456             {
457                 CreateButtonAttributes();
458                 if (popupAttributes.ButtonAttributes.TextAttributes.TextColor == null)
459                 {
460                     popupAttributes.ButtonAttributes.TextAttributes.TextColor = new ColorSelector();
461                 }
462                 popupAttributes.ButtonAttributes.TextAttributes.TextColor.All = value;
463                 RelayoutRequest();
464             }
465         }
466
467         /// <summary>
468         /// Button overlay background color selector in Popup.
469         /// </summary>
470         /// <since_tizen> 6 </since_tizen>
471         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
472         [EditorBrowsable(EditorBrowsableState.Never)]
473         public ColorSelector ButtonOverLayBackgroundColorSelector
474         {
475             get
476             {
477                 return popupAttributes?.ButtonAttributes?.OverlayImageAttributes?.BackgroundColor;
478             }
479             set
480             {
481                 if (value != null)
482                 {
483                     CreateButtonAttributes();
484                     popupAttributes.ButtonAttributes.OverlayImageAttributes.BackgroundColor = value.Clone() as ColorSelector;
485                     RelayoutRequest();
486                 }
487             }
488         }
489
490         /// <summary>
491         /// Button text horizontal alignment in Popup.
492         /// </summary>
493         /// <since_tizen> 6 </since_tizen>
494         public HorizontalAlignment ButtonTextAlignment
495         {
496             get
497             {
498                 return popupAttributes?.ButtonAttributes?.TextAttributes?.HorizontalAlignment ?? HorizontalAlignment.Center;
499             }
500             set
501             {
502                 CreateButtonAttributes();
503                 popupAttributes.ButtonAttributes.TextAttributes.HorizontalAlignment = value;
504                 RelayoutRequest();
505             }
506         }
507
508         /// <summary>
509         /// Button background image's resource url in Popup.
510         /// </summary>
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 string ButtonBackgroundImageURL
515         {
516             get
517             {
518                 return popupAttributes?.ButtonAttributes?.BackgroundImageAttributes?.ResourceURL?.All;
519             }
520             set
521             {
522                 if (value != null)
523                 {
524                     CreateButtonAttributes();
525                     if (popupAttributes.ButtonAttributes.BackgroundImageAttributes.ResourceURL == null)
526                     {
527                         popupAttributes.ButtonAttributes.BackgroundImageAttributes.ResourceURL = new StringSelector();
528                     }
529                     popupAttributes.ButtonAttributes.BackgroundImageAttributes.ResourceURL.All = value;
530                     RelayoutRequest();
531                 }
532             }
533         }
534
535         /// <summary>
536         /// Button background image's border in Popup.
537         /// </summary>
538         /// <since_tizen> 6 </since_tizen>
539         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
540         [EditorBrowsable(EditorBrowsableState.Never)]
541         public Rectangle ButtonBackgroundImageBorder
542         {
543             get
544             {
545                 return popupAttributes?.ButtonAttributes?.BackgroundImageAttributes?.Border?.All;
546             }
547             set
548             {
549                 if (value != null)
550                 {
551                     CreateButtonAttributes();
552                     if (popupAttributes.ButtonAttributes.BackgroundImageAttributes.Border == null)
553                     {
554                         popupAttributes.ButtonAttributes.BackgroundImageAttributes.Border = new RectangleSelector();
555                     }
556                     popupAttributes.ButtonAttributes.BackgroundImageAttributes.Border.All = value;
557                     RelayoutRequest();
558                 }
559             }
560         }
561
562         /// <summary>
563         /// Set button text by index.
564         /// </summary>
565         /// <param name="index">Button index.</param>
566         /// <param name="text">Button text string.</param>
567         /// <since_tizen> 6 </since_tizen>
568         public void SetButtonText(int index, string text)
569         {
570             if(index < 0 && index >= buttonCount)
571             {
572                 return;
573             }
574             if(buttonTextList.Count < index + 1)
575             {
576                 for (int i = buttonTextList.Count; i < index + 1; i++)
577                 {
578                     buttonTextList.Add("");
579                 }
580             }
581             buttonTextList[index] = text;
582             RelayoutRequest();
583         }
584
585         /// <summary>
586         /// Dispose Popup and all children on it.
587         /// </summary>
588         /// <param name="type">Dispose type.</param>
589         /// <since_tizen> 6 </since_tizen>
590         protected override void Dispose(DisposeTypes type)
591         {
592             if (disposed)
593             {
594                 return;
595             }
596
597             if (type == DisposeTypes.Explicit)
598             {
599                 if (titleText != null)
600                 {
601                     Remove(titleText);
602                     titleText.Dispose();
603                     titleText = null;
604                 }
605                 if (backgroundImage != null)
606                 {
607                     Remove(backgroundImage);
608                     backgroundImage.Dispose();
609                     backgroundImage = null;
610                 }
611                 if (shadowImage != null)
612                 {
613                     Remove(shadowImage);
614                     shadowImage.Dispose();
615                     shadowImage = null;
616                 }
617                 if (ContentView != null)
618                 {
619                     Remove(ContentView);
620                     ContentView.Dispose();
621                     ContentView = null;
622                 }
623                 if (buttonList != null)
624                 {
625                     foreach(Button btn in buttonList)
626                     {
627                         Remove(btn);
628                         btn.Dispose();
629                     }
630                 }
631             }
632
633             base.Dispose(type);
634         }
635
636         /// <summary>
637         /// Focus gained callback.
638         /// </summary>
639         /// <since_tizen> 6 </since_tizen>
640         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
641         [EditorBrowsable(EditorBrowsableState.Never)]
642         public override void OnFocusGained()
643         {
644             base.OnFocusGained();
645         }
646
647         /// <summary>
648         /// Focus lost callback.
649         /// </summary>
650         /// <since_tizen> 6 </since_tizen>
651         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
652         [EditorBrowsable(EditorBrowsableState.Never)]
653         public override void OnFocusLost()
654         {
655             base.OnFocusLost();
656         }
657
658         /// <summary>
659         /// Get Popup attribues.
660         /// </summary>
661         /// <since_tizen> 6 </since_tizen>
662         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
663         [EditorBrowsable(EditorBrowsableState.Never)]
664         protected override Attributes GetAttributes()
665         {
666             return new PopupAttributes();
667         }
668
669         /// <summary>
670         /// Update Popup by attributes.
671         /// </summary>
672         /// <since_tizen> 6 </since_tizen>
673         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
674         [EditorBrowsable(EditorBrowsableState.Never)]
675         protected override void OnUpdate()
676         {
677             int w = 0;
678             int h = 0;
679             int titleX = 0;
680             int titleY = 0;
681             int titleH = 0;
682             int buttonH = 0;
683
684             if (popupAttributes.ShadowImageAttributes != null)
685             {
686                 if (shadowImage == null)
687                 {
688                     shadowImage = new ImageView();
689                     Add(shadowImage);
690                 }
691                 ApplyAttributes(shadowImage, popupAttributes.ShadowImageAttributes);
692                 w = Size2D.Width;
693                 h = Size2D.Height;
694                 if (popupAttributes.ShadowOffset != null)
695                 {
696                     w = (int)(Size2D.Width + popupAttributes.ShadowOffset.W + popupAttributes.ShadowOffset.X);
697                     h = (int)(Size2D.Height + popupAttributes.ShadowOffset.Y + popupAttributes.ShadowOffset.Z);
698                 }
699
700                 shadowImage.Size2D = new Size2D(w, h);
701             }
702
703             if (popupAttributes.BackgroundImageAttributes != null)
704             {
705                 if (backgroundImage == null)
706                 {
707                     backgroundImage = new ImageView()
708                     {
709                         WidthResizePolicy = ResizePolicyType.FillToParent,
710                         HeightResizePolicy = ResizePolicyType.FillToParent
711                     };
712                     Add(backgroundImage);
713                 }
714                 ApplyAttributes(backgroundImage, popupAttributes.BackgroundImageAttributes);
715             }
716
717             if (popupAttributes.TitleTextAttributes != null)
718             {
719                 if (titleText == null)
720                 {
721                     titleText = new TextLabel();
722                     Add(titleText);
723                 }
724
725                 ApplyAttributes(titleText, popupAttributes.TitleTextAttributes);
726
727                 if (titleText.Text != null && titleText.Text != "")
728                 {
729                     popupAttributes.TitleTextAttributes.Text = new StringSelector { All = titleText.Text };
730                     w = (int)(Size2D.Width - titleText.PositionX * 2);
731
732                     if (popupAttributes.TitleTextAttributes.Size != null)
733                     {
734                         titleH = (int)titleText.Size.Height;
735                     }
736                     titleText.Size2D = new Size2D(w, titleH);
737
738                     if (popupAttributes.TitleTextAttributes.Position != null)
739                     {
740                         titleX = (int)popupAttributes.TitleTextAttributes.Position.X;
741                         titleY = (int)popupAttributes.TitleTextAttributes.Position.Y;
742                     }
743                 }
744                 else
745                 {
746                     titleText.Size2D = new Size2D(0, 0);
747                 }
748
749                
750             }
751             ContentView.RaiseToTop();
752
753             UpdateButton(buttonCount);
754            
755             if (buttonList != null && popupAttributes.ButtonAttributes != null && popupAttributes.ButtonAttributes.Size != null)
756             {
757                 buttonH = (int)popupAttributes.ButtonAttributes.Size.Height;
758             }
759             ContentView.Size2D = new Size2D(Size2D.Width - titleX * 2, Size2D.Height - titleY - titleH - buttonH);
760             ContentView.Position2D = new Position2D(titleX, titleY + titleH);
761
762             LayoutChild();
763         }
764
765         /// <summary>
766         /// Layout child in Popup and it can be override by user.
767         /// </summary>
768         /// <since_tizen> 6 </since_tizen>
769         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
770         [EditorBrowsable(EditorBrowsableState.Never)]
771         protected virtual void LayoutChild()
772         {
773             if (popupAttributes == null)
774             {
775                 return;
776             }
777
778             if(titleText != null)
779             {
780                 if(LayoutDirection == ViewLayoutDirectionType.RTL)
781                 {
782                     if (popupAttributes.TitleTextAttributes != null)
783                     {
784                         popupAttributes.TitleTextAttributes.HorizontalAlignment = HorizontalAlignment.End;
785                     }
786                     titleText.HorizontalAlignment = HorizontalAlignment.End;
787                 }
788                 else if(LayoutDirection == ViewLayoutDirectionType.LTR)
789                 {
790                     if (popupAttributes.TitleTextAttributes != null)
791                     {
792                         popupAttributes.TitleTextAttributes.HorizontalAlignment = HorizontalAlignment.Begin;
793                     }
794                     titleText.HorizontalAlignment = HorizontalAlignment.Begin;
795                 }
796             }
797
798             if(buttonList != null && buttonList.Count > 0)
799             {
800                 int pos = 0;
801                 if (LayoutDirection == ViewLayoutDirectionType.RTL)
802                 {                   
803                     for (int i = buttonList.Count - 1; i >= 0; i--)
804                     {
805                         buttonList[i].PositionX = pos;
806                         pos += buttonList[i].Size2D.Width;
807                     }
808                 }
809                 else
810                 {
811                     for (int i = 0; i < buttonList.Count; i++)
812                     {
813                         buttonList[i].PositionX = pos;
814                         pos += buttonList[i].Size2D.Width;
815                     }
816                 }
817             }
818         }
819
820         /// <summary>
821         /// Theme change callback when theme is changed, this callback will be trigger.
822         /// </summary>
823         /// <since_tizen> 6 </since_tizen>
824         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
825         [EditorBrowsable(EditorBrowsableState.Never)]
826         protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
827         {
828             PopupAttributes tempAttributes = StyleManager.Instance.GetAttributes(style) as PopupAttributes;
829             if (tempAttributes != null)
830             {
831                 attributes = popupAttributes = tempAttributes;
832                 RelayoutRequest();
833             }
834         }
835
836         private void Initialize()
837         {
838             popupAttributes = attributes as PopupAttributes;
839             if (popupAttributes == null)
840             {
841                 throw new Exception("Popup attribute parse error.");
842             }
843
844             ApplyAttributes(this, popupAttributes);
845             LeaveRequired = true;
846
847             ContentView = new View()
848             {
849                 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
850                 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
851                 PositionUsesPivotPoint = true
852             };
853             Add(ContentView);
854             ContentView.RaiseToTop();
855         }
856
857         private void CreateShadowAttributes()
858         {
859             if (popupAttributes.ShadowImageAttributes == null)
860             {
861                 popupAttributes.ShadowImageAttributes = new ImageAttributes()
862                 {
863                     PositionUsesPivotPoint = true,
864                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
865                     PivotPoint = Tizen.NUI.PivotPoint.Center,
866                 };
867             }
868         }
869
870         private void CreateBackgroundAttributes()
871         {
872             if (popupAttributes.BackgroundImageAttributes == null)
873             {
874                 popupAttributes.BackgroundImageAttributes = new ImageAttributes()
875                 {
876                     PositionUsesPivotPoint = true,
877                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
878                     PivotPoint = Tizen.NUI.PivotPoint.Center, 
879                     WidthResizePolicy = ResizePolicyType.FillToParent,
880                     HeightResizePolicy = ResizePolicyType.FillToParent
881                 };
882             }
883         }
884
885         private void CreateTitleTextAttributes()
886         {
887             if (popupAttributes.TitleTextAttributes == null)
888             {
889                 popupAttributes.TitleTextAttributes = new TextAttributes()
890                 {
891                     Size =  new Size(0, 0),
892                     PositionUsesPivotPoint = true,
893                     ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
894                     PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
895                     HorizontalAlignment = HorizontalAlignment.Begin,
896                     VerticalAlignment = VerticalAlignment.Bottom
897                 };
898             }
899         }
900
901         private void CreateButtonAttributes()
902         {
903             if (popupAttributes.ButtonAttributes == null)
904             {
905                 popupAttributes.ButtonAttributes = new ButtonAttributes()
906                 {
907                     Size =  new Size(0, 0),
908                     PositionUsesPivotPoint = true,
909                     ParentOrigin =  Tizen.NUI.ParentOrigin.BottomLeft,
910                     PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
911                     TextAttributes = new TextAttributes
912                     {
913                         PositionUsesPivotPoint = true,
914                         ParentOrigin = Tizen.NUI.ParentOrigin.Center,
915                         PivotPoint = Tizen.NUI.PivotPoint.Center,
916                         HorizontalAlignment =  HorizontalAlignment.Center,
917                         VerticalAlignment = VerticalAlignment.Center
918                     },
919                     BackgroundImageAttributes = new ImageAttributes
920                     {
921                         PositionUsesPivotPoint = true,
922                         ParentOrigin =  Tizen.NUI.ParentOrigin.Center,
923                         PivotPoint = Tizen.NUI.PivotPoint.Center,
924                         WidthResizePolicy = ResizePolicyType.FillToParent,
925                         HeightResizePolicy = ResizePolicyType.FillToParent,
926                         Border = new RectangleSelector { All = new Rectangle(0, 0, 0, 0) },
927                     },
928                     OverlayImageAttributes = new ImageAttributes
929                     {
930                         PositionUsesPivotPoint = true,
931                         ParentOrigin = Tizen.NUI.ParentOrigin.Center,
932                         PivotPoint = Tizen.NUI.PivotPoint.Center,
933                         WidthResizePolicy = ResizePolicyType.FillToParent,
934                         HeightResizePolicy = ResizePolicyType.FillToParent,
935                         Border = new RectangleSelector { All = new Rectangle(0, 0, 0, 0) },
936                     },
937                 };
938             }
939         }
940
941         private void UpdateButton(int count)
942         {
943             if(buttonList != null && buttonCount == buttonList.Count)
944             {
945                 for (int i = 0; i < count; i++)
946                 {
947                     buttonList[i].TextColor = popupAttributes.ButtonAttributes.TextAttributes.TextColor.All;
948                 }
949                 return;
950             }
951            
952             if (buttonList != null)
953             {
954                 foreach (Button btn in buttonList)
955                 {
956                     btn.ClickEvent -= ButtonClickEvent;
957                     this.Remove(btn);
958                     btn.Dispose();
959                 }
960                 buttonList.Clear();
961                 buttonList = null;
962             }
963             if(count <= 0)
964             {
965                 return;
966             }
967             int buttonWidth = Size2D.Width / count;
968             int buttonHeight = (int)popupAttributes.ButtonAttributes.Size.Height;
969             int pos = 0;
970             buttonList = new List<Button>();
971             for (int i = 0; i < count; i++)
972             {
973                 Button btn = null;
974                 popupAttributes.ButtonAttributes.Size.Width = buttonWidth;
975                 btn = new Button(popupAttributes.ButtonAttributes);
976                 btn.Position2D = new Position2D(pos, 0);
977
978                 if (i >= buttonTextList.Count)
979                 {
980                     buttonTextList.Add("");
981                 }
982                 btn.Text = buttonTextList[i];
983                 btn.ClickEvent += ButtonClickEvent;
984                 pos += buttonWidth;
985                 this.Add(btn);
986                 buttonList.Add(btn);
987             }
988         }
989
990         private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
991         {
992             if (PopupButtonClickEvent != null && buttonList != null)
993             {
994                 Button button = sender as Button;
995                 for (int i = 0; i < buttonList.Count; i++)
996                 {
997                     if(button == buttonList[i])
998                     {
999                         ButtonClickEventArgs args = new ButtonClickEventArgs();
1000                         args.ButtonIndex = i;
1001                         PopupButtonClickEvent(this, args);
1002                     }
1003                 }
1004             }
1005         }
1006
1007         /// <summary>
1008         /// ButtonClickEventArgs is a class to record button click event arguments which will sent to user.
1009         /// </summary>
1010         /// <since_tizen> 6 </since_tizen>
1011         public class ButtonClickEventArgs : EventArgs
1012         {
1013             /// <summary> Button index which is clicked in Popup </summary>
1014             /// <since_tizen> 6 </since_tizen>
1015             public int ButtonIndex;
1016         }
1017     }
1018 }