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