Revert "Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage""
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 14 Apr 2021 07:57:19 +0000 (16:57 +0900)
committerbshsqa <32317749+bshsqa@users.noreply.github.com>
Wed, 14 Apr 2021 11:53:58 +0000 (20:53 +0900)
This reverts commit 357f3d0b82bd7a184f02abf6286ebcd1eaddbf6f.

src/Tizen.NUI.Components/Controls/AlertDialog.cs
src/Tizen.NUI.Components/Controls/Dialog.cs
src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs [new file with mode: 0755]
src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/AlertDialogSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/DialogSample.cs

index 6e42b4c..988e95a 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 using System;
 using System.ComponentModel;
+using System.Collections.Generic;
 using Tizen.NUI.BaseComponents;
 
 namespace Tizen.NUI.Components
 {
     /// <summary>
-    /// Types of the action button of AlertDialog.
-    /// </summary>
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public enum AlertDialogActionButtonType
-    {
-        /// <summary>
-        /// Type of the positive action button.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        Positive,
-
-        /// <summary>
-        /// Type of the negative action button.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        Negative
-    }
-
-    /// <summary>
     /// AlertDialog class shows a dialog with title, message and action buttons.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class AlertDialog : Dialog
+    public class AlertDialog : Control
     {
         private string title = null;
         private string message = null;
 
-        private View popupTitle = null;
-        private View popupContent = null;
-        private View popupAction = null;
+        private View titleContent = null;
+        private View content = null;
+        private View actionContent = null;
+        private IEnumerable<View> actionContentViews = null;
 
         private View defaultTitleContent = null;
         private View defaultContent = null;
         private View defaultActionContent = null;
 
-        private Button positiveButton = null;
-        private Button negativeButton = null;
-
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="title">The title of AlertDialog.</param>
-        /// <param name="message">The message of AlertDialog.</param>
-        /// <param name="positiveButtonText">The positive button text in the action content of AlertDialog.</param>
-        /// <param name="positiveButtonClickedHandler">The clicked callback of the positive button in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonText">The negative button text in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonClickedHandler">The clicked callback of the negative button in the action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string title, string message, string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null) : base()
-        {
-            //Content is initialized to add TitleContent, BodyContent and ActionContent.
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            InitContent();
-
-            //Title setter calls TitleContent setter if TitleContent is null.
-            Title = title;
-
-            //Message setter calls BodyContent setter if BodyContent is null.
-            Message = message;
-
-            ActionContent = CreateActionContent(positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler);
-        }
-
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="message">The message of AlertDialog.</param>
-        /// <param name="positiveButtonText">The positive button text in the action content of AlertDialog.</param>
-        /// <param name="positiveButtonClickedHandler">The clicked callback of the positive button in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonText">The negative button text in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonClickedHandler">The clicked callback of the negative button in the action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string message, string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null) : this(null, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler)
-        {
-        }
-
         /// <summary>
         /// Creates a new instance of AlertDialog.
         /// </summary>
-        /// <param name="title">The title of AlertDialog.</param>
-        /// <param name="message">The message of AlertDialog.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string title, string message) : this(title, message, null, null, null, null)
+        public AlertDialog() : base()
         {
+            Initialize();
         }
 
         /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="message">The message of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(string message) : this(null, message)
-        {
-        }
-
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
+        /// Dispose AlertDialog and all children on it.
         /// </summary>
-        /// <param name="titleContent">The title content of AlertDialog.</param>
-        /// <param name="bodyContent">The content of AlertDialog.</param>
-        /// <param name="actionContent">The action content of AlertDialog.</param>
+        /// <param name="type">Dispose type.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(View titleContent, View bodyContent, View actionContent) : base()
+        protected override void Dispose(DisposeTypes type)
         {
-            //Content is initialized to add TitleContent, BodyContent and ActionContent.
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            InitContent();
+            if (disposed)
+            {
+                return;
+            }
 
-            TitleContent = titleContent;
+            if (type == DisposeTypes.Explicit)
+            {
+                if (titleContent != null)
+                {
+                    Utility.Dispose(titleContent);
+                }
 
-            BodyContent = bodyContent;
+                if (content != null)
+                {
+                    Utility.Dispose(content);
+                }
 
-            ActionContent = actionContent;
-        }
+                if (actionContent != null)
+                {
+                    Utility.Dispose(actionContent);
+                }
+            }
 
-        /// <summary>
-        /// Creates a new instance of AlertDialog.
-        /// </summary>
-        /// <param name="bodyContent">The content of AlertDialog.</param>
-        /// <param name="actionContent">The action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(View bodyContent, View actionContent) : this(null, bodyContent, actionContent)
-        {
+            base.Dispose(type);
         }
 
         /// <summary>
-        /// Creates a new instance of AlertDialog.
+        /// Title text of AlertDialog.
         /// </summary>
-        /// <param name="bodyContent">The content of AlertDialog.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public AlertDialog(View bodyContent = null) : this(bodyContent, null)
-        {
-        }
-
-        private void InitContent()
+        public string Title
         {
-            var content = new Control();
+            get
+            {
+                return title;
+            }
+            set
+            {
+                if (title == value)
+                {
+                    return;
+                }
 
-            var linearLayout = new LinearLayout();
-            linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
-            content.Layout = linearLayout;
+                title = value;
 
-            Content = content;
+                if (TitleContent is TextLabel textLabel)
+                {
+                    textLabel.Text = title;
+                }
+            }
         }
 
         /// <summary>
@@ -175,425 +116,369 @@ namespace Tizen.NUI.Components
         {
             get
             {
-                return popupTitle;
+                return titleContent;
             }
             set
             {
-                if (popupTitle == value)
+                if (titleContent == value)
                 {
                     return;
                 }
 
-                if (popupTitle != null)
+                if (titleContent != null)
                 {
-                    Remove(popupTitle);
+                    Remove(titleContent);
                 }
 
-                popupTitle = value;
-                if (popupTitle == null)
+                titleContent = value;
+                if (titleContent == null)
                 {
                     return;
                 }
 
+                if (titleContent is TextLabel textLabel)
+                {
+                    textLabel.Text = Title;
+                }
+
                 ResetContent();
             }
         }
 
         /// <summary>
-        /// BodyContent of AlertDialog. BodyContent is added to Children automatically.
+        /// Message text of AlertDialog.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View BodyContent
+        public string Message
         {
             get
             {
-                return popupContent;
+                return message;
             }
             set
             {
-                if (popupContent == value)
+                if (message == value)
                 {
                     return;
                 }
 
-                if (popupContent != null)
-                {
-                    Remove(popupContent);
-                }
+                message = value;
 
-                popupContent = value;
-                if (popupContent == null)
+                if (Content is TextLabel textLabel)
                 {
-                    return;
+                    textLabel.Text = message;
                 }
-
-                ResetContent();
             }
         }
 
         /// <summary>
-        /// Action content of AlertDialog. ActionContent is added to Children automatically.
+        /// Content of AlertDialog. Content is added to Children automatically.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View ActionContent
+        public View Content
         {
             get
             {
-                return popupAction;
+                return content;
             }
             set
             {
-                if (popupAction == value)
+                if (content == value)
                 {
                     return;
                 }
 
-                if (popupAction != null)
+                if (content != null)
                 {
-                    Remove(popupAction);
+                    Remove(content);
                 }
 
-                popupAction = value;
-                if (popupAction == null)
+                content = value;
+                if (content == null)
                 {
                     return;
                 }
 
-                ResetContent();
-            }
-        }
-
-        private void ResetContent()
-        {
-            if (Content == null)
-            {
-                return;
-            }
-
-            //To keep the order of TitleContent, BodyContent and ActionContent,
-            //the existing contents are removed and added again.
-            if (popupTitle != null)
-            {
-                Content.Remove(popupTitle);
-            }
-
-            if (popupContent != null)
-            {
-                Content.Remove(popupContent);
-            }
-
-            if (popupAction != null)
-            {
-                Content.Remove(popupAction);
-            }
-
-            if (popupTitle != null)
-            {
-                Content.Add(popupTitle);
-            }
-
-            if (popupContent != null)
-            {
-                Content.Add(popupContent);
-            }
+                if (content is TextLabel textLabel)
+                {
+                    textLabel.Text = message;
+                }
 
-            if (popupAction != null)
-            {
-                Content.Add(popupAction);
+                ResetContent();
             }
         }
 
         /// <summary>
-        /// Title text of AlertDialog.
+        /// Action views of AlertDialog.
+        /// Action views are added to ActionContent of AlertDialog.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public string Title
+        public IEnumerable<View> Actions
         {
             get
             {
-                return title;
+                return actionContentViews;
             }
             set
             {
-                if (title == value)
+                if (ActionContent == null)
                 {
+                    actionContentViews = value;
                     return;
                 }
 
-                title = value;
-                if (title == null)
+                if (actionContentViews != null)
                 {
-                    if (TitleContent != null)
+                    foreach (var oldAction in actionContentViews)
                     {
-                        //TitleContent setter calls Remove(popupTitle).
-                        TitleContent = null;
+                        if (ActionContent.Children?.Contains(oldAction) == true)
+                        {
+                            ActionContent.Children.Remove(oldAction);
+                        }
                     }
                 }
-                else
+
+                actionContentViews = value;
+
+                if (actionContentViews == null)
                 {
-                    if (TitleContent == null)
-                    {
-                        TitleContent = CreateTitleContent(title);
-                    }
-                    else if (TitleContent == defaultTitleContent)
-                    {
-                        //Sets text if TitleContent is not set by user.
-                        ((TextLabel)TitleContent).Text = title;
-                    }
+                    return;
+                }
+
+                foreach (var action in actionContentViews)
+                {
+                    ActionContent.Add(action);
                 }
             }
         }
 
         /// <summary>
-        /// Message text of AlertDialog.
+        /// Action content of AlertDialog. ActionContent is added to Children automatically.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public string Message
+        public View ActionContent
         {
-            get
-            {
-                return message;
-            }
-            set
-            {
-                if (message == value)
+             get
+             {
+                return actionContent;
+             }
+             set
+             {
+                if (actionContent == value)
+                 {
+                     return;
+                 }
+
+                var oldActionContent = actionContent;
+                actionContent = value;
+
+                // Add views first before remove previous action content
+                // not to cause Garbage Collector collects views.
+                if ((actionContent != null) && (Actions != null))
                 {
-                    return;
+                    foreach (var action in Actions)
+                    {
+                        actionContent.Add(action);
+                    }
                 }
 
-                message = value;
-                if (message == null)
+                if (oldActionContent != null)
                 {
-                    if (BodyContent != null)
-                    {
-                        //BodyContent setter calls Remove(popupContent).
-                        BodyContent = null;
-                    }
+                    Remove(oldActionContent);
                 }
-                else
+
+                if (actionContent == null)
                 {
-                    if (BodyContent == null)
-                    {
-                        BodyContent = CreateContent(message);
-                    }
-                    else if (BodyContent == defaultContent)
-                    {
-                        //Sets text if BodyContent is not set by user.
-                        ((TextLabel)BodyContent).Text = message;
-                    }
+                    return;
                 }
+
+                ResetContent();
             }
         }
 
         /// <summary>
-        /// Sets action button in the action content of AlertDialog.
+        /// AccessibilityGetName.
         /// </summary>
-        /// <param name="type">The type of action button.</param>
-        /// <param name="text">The text of action button in the action content of AlertDialog.</param>
-        /// <param name="clickedHandler">The clicked callback of the action button in the action content of AlertDialog.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void SetActionButton(AlertDialogActionButtonType type, string text, EventHandler<ClickedEventArgs> clickedHandler)
+        protected override string AccessibilityGetName()
         {
-            if (ActionContent == null)
+            if (!String.IsNullOrEmpty(Title))
             {
-                if (type == AlertDialogActionButtonType.Positive)
-                {
-                    ActionContent = CreateActionContent(text, clickedHandler, null, null);
-                }
-                else
-                {
-                    ActionContent = CreateActionContent(null, null, text, clickedHandler);
-                }
+                return Title;
             }
-            else if (ActionContent == defaultActionContent)
+            else
             {
-                //To keep the order of negativeButton and positiveButton,
-                //positiveButton is always removed.
-                if (positiveButton != null)
-                {
-                    ActionContent.Remove(positiveButton);
-                }
+                return Message;
+            }
+        }
 
-                if (type == AlertDialogActionButtonType.Negative)
+        /// <summary>
+        /// Default title content of AlertDialog.
+        /// If Title is set, then default title content is automatically displayed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View DefaultTitleContent
+        {
+            get
+            {
+                if (defaultTitleContent == null)
                 {
-                    if (negativeButton != null)
-                    {
-                        ActionContent.Remove(negativeButton);
-                    }
+                    defaultTitleContent = CreateDefaultTitleContent();
+                }
 
-                    negativeButton = CreateActionButton(text, clickedHandler);
-                    if (negativeButton != null)
-                    {
-                        ActionContent.Add(negativeButton);
+                return defaultTitleContent;
+            }
+        }
 
-                        if (positiveButton != null)
-                        {
-                            ActionContent.Add(positiveButton);
-                        }
-                    }
-                }
-                else
+        /// <summary>
+        /// Default content of AlertDialog.
+        /// If Message is set, then default content is automatically displayed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View DefaultContent
+        {
+            get
+            {
+                if (defaultContent == null)
                 {
-                    positiveButton = CreateActionButton(text, clickedHandler);
-                    if (positiveButton != null)
-                    {
-                        ActionContent.Add(positiveButton);
-                    }
+                    defaultContent = CreateDefaultContent();
                 }
+
+                return defaultContent;
             }
         }
 
-        private TextLabel CreateTitleContent(string text)
+        /// <summary>
+        /// Default action content of AlertDialog.
+        /// If Actions are set, then default action content is automatically displayed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View DefaultActionContent
         {
-            if (text == null)
+            get
             {
-                return null;
-            }
-
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var titleContent = new TextLabel(text);
-            titleContent.HorizontalAlignment = HorizontalAlignment.Center;
-            titleContent.VerticalAlignment = VerticalAlignment.Center;
-            titleContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
-            titleContent.Size = new Size(360, 80);
-
-            defaultTitleContent = titleContent;
+                if (defaultActionContent == null)
+                {
+                    defaultActionContent = CreateDefaultActionContent();
+                }
 
-            return titleContent;
+                return defaultActionContent;
+            }
         }
 
-        private TextLabel CreateContent(string message)
+        private void Initialize()
         {
-            if (message == null)
+            Layout = new LinearLayout()
             {
-                return null;
-            }
+                LinearOrientation = LinearLayout.Orientation.Vertical,
+            };
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var messageContent = new TextLabel(message);
-            messageContent.HorizontalAlignment = HorizontalAlignment.Center;
-            messageContent.VerticalAlignment = VerticalAlignment.Center;
-            messageContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
-            messageContent.Size = new Size(360, 200);
+            this.Relayout += OnRelayout;
+
+            TitleContent = DefaultTitleContent;
 
-            defaultContent = messageContent;
+            Content = DefaultContent;
 
-            return messageContent;
+            ActionContent = DefaultActionContent;
         }
 
-        private Button CreateActionButton(string text, EventHandler<ClickedEventArgs> clickedHandler)
+        private void ResetContent()
         {
-            if (text == null)
+            //To keep the order of TitleContent, Content and ActionContent,
+            //the existing contents are removed and added again.
+            if (titleContent != null)
             {
-                return null;
+                Remove(titleContent);
             }
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var actionButton = new Button();
-            actionButton.Text = text;
-            actionButton.Size = new Size(120, 80);
-
-            if (clickedHandler != null)
+            if (content != null)
             {
-                actionButton.Clicked += clickedHandler;
+                Remove(content);
             }
 
-            return actionButton;
-        }
-
-        private View CreateActionContent(string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText, EventHandler<ClickedEventArgs> negativeButtonClickedHandler)
-        {
-            if ((negativeButtonText == null) && (positiveButtonText == null))
+            if (actionContent != null)
             {
-                return null;
+                Remove(actionContent);
             }
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var actionContent = new Control();
-            actionContent.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
-            actionContent.Size = new Size(360, 80);
-
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var actionLayout = new LinearLayout();
-            actionLayout.LinearOrientation = LinearLayout.Orientation.Horizontal;
-            actionLayout.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;
-            actionLayout.CellPadding = new Size2D(10, 0);
-            actionContent.Layout = actionLayout;
-
-            negativeButton = CreateActionButton(negativeButtonText, negativeButtonClickedHandler);
-            if (negativeButton != null)
+            if (titleContent != null)
             {
-                actionContent.Add(negativeButton);
+                Add(titleContent);
             }
 
-            positiveButton = CreateActionButton(positiveButtonText, positiveButtonClickedHandler);
-            if (positiveButton != null)
+            if (content != null)
             {
-                actionContent.Add(positiveButton);
+                Add(content);
             }
 
-            defaultActionContent = actionContent;
-
-            return actionContent;
+            if (actionContent != null)
+            {
+                Add(actionContent);
+            }
         }
 
-        /// <summary>
-        /// Dispose AlertDialog and all children on it.
-        /// </summary>
-        /// <param name="type">Dispose type.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
+        private TextLabel CreateDefaultTitleContent()
         {
-            if (disposed)
+            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            return new TextLabel()
             {
-                return;
-            }
+                HorizontalAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Center,
+                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
+                Size = new Size(360, 80),
+            };
+        }
 
-            if (type == DisposeTypes.Explicit)
+        private TextLabel CreateDefaultContent()
+        {
+            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            return new TextLabel()
             {
-                if (popupTitle != null)
-                {
-                    Utility.Dispose(popupTitle);
-                }
-
-                if (popupContent != null)
-                {
-                    Utility.Dispose(popupContent);
-                }
+                HorizontalAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Center,
+                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
+                Size = new Size(360, 200),
+            };
+        }
 
-                if (popupAction != null)
+        private View CreateDefaultActionContent()
+        {
+            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            return new Control()
+            {
+                BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
+                Size = new Size(360, 80),
+                Layout = new LinearLayout()
                 {
-                    if (positiveButton != null)
-                    {
-                        Utility.Dispose(positiveButton);
-                    }
-
-                    if (negativeButton != null)
-                    {
-                        Utility.Dispose(negativeButton);
-                    }
-
-                    Utility.Dispose(popupAction);
-                }
-            }
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                    LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
+                    CellPadding = new Size2D(10, 0),
+                },
+            };
+        }
 
-            base.Dispose(type);
+        private void OnRelayout(object sender, EventArgs e)
+        {
+            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            CalculatePosition();
         }
 
-        /// <summary>
-        /// AccessibilityGetName.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override string AccessibilityGetName()
+        private void CalculatePosition()
         {
-            if (!String.IsNullOrEmpty(Title))
+            var size = Size2D;
+            var parent = GetParent();
+            Size2D parentSize;
+
+            if ((parent != null) && (parent is View))
             {
-                return Title;
+                parentSize = ((View)parent).Size;
             }
             else
             {
-                return Message;
+                parentSize = NUIApplication.GetDefaultWindow().Size;
             }
+
+            Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
         }
     }
 }
index e430044..5abe7eb 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,217 +27,77 @@ namespace Tizen.NUI.Components
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class Dialog : Control
     {
-        private View popupContent = null;
-        private View scrim = null;
-        private bool enableScrim = true;
+        private View content = null;
 
         /// <summary>
         /// Creates a new instance of Dialog.
         /// </summary>
-        /// <param name="content">The content to set to Content of Dialog.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public Dialog(View content = null) : base()
+        public Dialog() : base()
         {
-            EnableScrim = true;
-            EnableDismissOnScrim = true;
+            Layout = new AbsoluteLayout();
 
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            var scrim = new VisualView();
-            scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);
-            //FIXME: Needs to set proper size to Scrim.
-            scrim.Size = NUIApplication.GetDefaultWindow().Size;
-            scrim.TouchEvent += (object source, TouchEventArgs e) =>
-            {
-                if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up))
-                {
-                    //TODO: To show hide animation.
-                    this.Hide();
-                    this.Dispose();
-                }
-                return true;
-            };
-
-            Scrim = scrim;
-
-            if (content != null)
-            {
-                content.RaiseAbove(scrim);
-                Content = content;
-            }
+            this.Relayout += OnRelayout;
         }
 
         /// <summary>
-        /// Popup content of Dialog. Content is added to Children automatically.
+        /// Dispose Dialog and all children on it.
         /// </summary>
+        /// <param name="type">Dispose type.</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View Content
-        {
-            get
-            {
-                return popupContent;
-            }
-            set
-            {
-                if (popupContent == value)
-                {
-                    return;
-                }
-
-                if (popupContent != null)
-                {
-                    Remove(popupContent);
-                }
-
-                popupContent = value;
-                if (popupContent == null)
-                {
-                    return;
-                }
-
-                popupContent.Relayout += PopupContentRelayout;
-
-                //FIXME: Needs to separate GUI implementation codes to style cs file.
-                CalculateContentPosition();
-
-                Add(popupContent);
-
-                if (Scrim != null)
-                {
-                    popupContent.RaiseAbove(Scrim);
-                }
-            }
-        }
-
-        private void PopupContentRelayout(object sender, EventArgs e)
-        {
-            //FIXME: Needs to separate GUI implementation codes to style cs file.
-            CalculateContentPosition();
-        }
-
-        private void CalculateContentPosition()
+        protected override void Dispose(DisposeTypes type)
         {
-            var size = popupContent.Size2D;
-            var parent = GetParent();
-            Size2D parentSize;
-
-            if ((parent != null) && (parent is View))
-            {
-                parentSize = ((View)parent).Size;
-            }
-            else
+            if (disposed)
             {
-                parentSize = NUIApplication.GetDefaultWindow().Size;
+                return;
             }
 
-            popupContent.Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
-        }
-
-        /// <summary>
-        /// Indicates to show scrim behind popup content.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool EnableScrim
-        {
-            get
-            {
-                return enableScrim;
-            }
-            set
+            if (type == DisposeTypes.Explicit)
             {
-                if (enableScrim == value)
-                {
-                    return;
-                }
+                this.Relayout -= OnRelayout;
 
-                enableScrim = value;
-
-                if ((Scrim != null) && (enableScrim != Scrim.Visibility))
+                if (content != null)
                 {
-                    if (enableScrim)
-                    {
-                        Scrim.Show();
-                    }
-                    else
-                    {
-                        Scrim.Hide();
-                    }
+                    Utility.Dispose(content);
                 }
             }
-        }
 
-        /// <summary>
-        /// Indicates to dismiss popup content by touching on scrim.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool EnableDismissOnScrim { get; set; }
+            base.Dispose(type);
+        }
 
         /// <summary>
-        /// Scrim covers background behind popup content.
+        /// Popup content of Dialog. Content is added to Children automatically.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected internal View Scrim
+        public View Content
         {
             get
             {
-                return scrim;
+                return content;
             }
             set
             {
-                if (scrim == value)
+                if (content == value)
                 {
                     return;
                 }
 
-                if (scrim != null)
+                if (content != null)
                 {
-                    Remove(scrim);
+                    Remove(content);
                 }
 
-                scrim = value;
-                if (scrim == null)
+                content = value;
+                if (content == null)
                 {
                     return;
                 }
 
-                Add(scrim);
-
-                if (Content != null)
-                {
-                    Content.RaiseAbove(scrim);
-                }
+                Add(content);
             }
         }
 
         /// <summary>
-        /// Dispose Dialog and all children on it.
-        /// </summary>
-        /// <param name="type">Dispose type.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
-        {
-            if (disposed)
-            {
-                return;
-            }
-
-            if (type == DisposeTypes.Explicit)
-            {
-                if (popupContent != null)
-                {
-                    popupContent.Relayout -= PopupContentRelayout;
-                    Utility.Dispose(popupContent);
-                }
-
-                if (scrim != null)
-                {
-                    Utility.Dispose(scrim);
-                }
-            }
-
-            base.Dispose(type);
-        }
-
-        /// <summary>
         /// Initialize AT-SPI object.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -259,5 +119,29 @@ namespace Tizen.NUI.Components
             states.Set(AccessibilityState.Modal, true);
             return states;
         }
+
+        private void OnRelayout(object sender, EventArgs e)
+        {
+            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            CalculateContentPosition();
+        }
+
+        private void CalculateContentPosition()
+        {
+            var size = Size2D;
+            var parent = GetParent();
+            Size2D parentSize;
+
+            if ((parent != null) && (parent is View))
+            {
+                parentSize = ((View)parent).Size;
+            }
+            else
+            {
+                parentSize = NUIApplication.GetDefaultWindow().Size;
+            }
+
+            Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
+        }
     }
 }
diff --git a/src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs b/src/Tizen.NUI.Components/Controls/Navigation/DialogPage.cs
new file mode 100755 (executable)
index 0000000..268b69f
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System.ComponentModel;
+using Tizen.NUI.BaseComponents;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Tizen.NUI.Components
+{
+    /// <summary>
+    /// The DialogPage class is a class which shows a dialog on the page.
+    /// DialogPage contains dialog and dimmed scrim behind the dialog.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class DialogPage : Page
+    {
+        private View content = null;
+        private View scrim = null;
+        private bool enableScrim = true;
+
+        /// <summary>
+        /// Creates a new instance of a DialogPage.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public DialogPage() : base()
+        {
+            Layout = new AbsoluteLayout();
+
+            // DialogPage fills to parent by default.
+            WidthResizePolicy = ResizePolicyType.FillToParent;
+            HeightResizePolicy = ResizePolicyType.FillToParent;
+
+            Scrim = CreateDefaultScrim();
+        }
+
+        /// <summary>
+        /// Dispose DialogPage and all children on it.
+        /// </summary>
+        /// <param name="type">Dispose type.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                if (content != null)
+                {
+                    Utility.Dispose(content);
+                }
+
+                if (scrim != null)
+                {
+                    Utility.Dispose(scrim);
+                }
+            }
+
+            base.Dispose(type);
+        }
+
+        /// <summary>
+        /// Content of DialogPage. Content is added to Children automatically.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public View Content
+        {
+            get
+            {
+                return content;
+            }
+            set
+            {
+                if (content == value)
+                {
+                    return;
+                }
+
+                if (content != null)
+                {
+                    Remove(content);
+                }
+
+                content = value;
+                if (content == null)
+                {
+                    return;
+                }
+
+                Add(content);
+
+                if (Scrim != null)
+                {
+                    content.RaiseAbove(Scrim);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Scrim of DialogPage. Scrim is added to Children automatically.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected View Scrim
+        {
+            get
+            {
+                return scrim;
+            }
+            set
+            {
+                if (scrim == value)
+                {
+                    return;
+                }
+
+                if (scrim != null)
+                {
+                    Remove(scrim);
+                }
+
+                scrim = value;
+                if (scrim == null)
+                {
+                    return;
+                }
+
+                Add(scrim);
+
+                if (Content != null)
+                {
+                    Content.RaiseAbove(scrim);
+                }
+
+                if (EnableScrim != Scrim.Visibility)
+                {
+                    if (EnableScrim == true)
+                    {
+                        scrim.Show();
+                    }
+                    else
+                    {
+                        scrim.Hide();
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// Indicates to show scrim behind dialog.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool EnableScrim
+        {
+            get
+            {
+                return enableScrim;
+            }
+            set
+            {
+                if (enableScrim == value)
+                {
+                    return;
+                }
+
+                enableScrim = value;
+
+                if ((Scrim != null) && (enableScrim != Scrim.Visibility))
+                {
+                    if (enableScrim == true)
+                    {
+                        Scrim.Show();
+                    }
+                    else
+                    {
+                        Scrim.Hide();
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// Indicates to dismiss dialog by touching on scrim.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool EnableDismissOnScrim { get; set; }
+
+        private View CreateDefaultScrim()
+        {
+            //FIXME: Needs to separate GUI implementation codes to style cs file.
+            var scrim = new VisualView();
+            scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);
+            //FIXME: Needs to set proper size to Scrim.
+            scrim.Size = NUIApplication.GetDefaultWindow().Size;
+            scrim.TouchEvent += (object source, TouchEventArgs e) =>
+            {
+                if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up))
+                {
+                    this.Navigator.Pop();
+                }
+                return true;
+            };
+
+            return scrim;
+        }
+
+        /// <summary>
+        /// Shows a dialog by pushing a dialog page containing dialog to default navigator.
+        /// </summary>
+        /// <param name="content">The content of Dialog.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        [SuppressMessage("Microsoft.Reliability",
+                         "CA2000:DisposeObjectsBeforeLosingScope",
+                         Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
+        public static void ShowDialog(View content)
+        {
+            var dialogPage = new DialogPage()
+            {
+                Content = new Dialog()
+                {
+                    Content = content,
+                },
+            };
+
+            NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);
+        }
+
+        /// <summary>
+        /// Shows an alert dialog by pushing a page containing the alert dialog
+        /// to default navigator.
+        /// </summary>
+        /// <param name="title">The title of AlertDialog.</param>
+        /// <param name="message">The message of AlertDialog.</param>
+        /// <param name="actions">The action views of AlertDialog.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        [SuppressMessage("Microsoft.Reliability",
+                         "CA2000:DisposeObjectsBeforeLosingScope",
+                         Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
+        public static void ShowAlertDialog(string title, string message, params View[] actions)
+        {
+            var dialogPage = new DialogPage()
+            {
+                Content = new AlertDialog()
+                {
+                    Title = title,
+                    Message = message,
+                    Actions =  actions,
+                },
+            };
+
+            NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(dialogPage);
+        }
+    }
+}
index 65105bd..97a4bb1 100755 (executable)
@@ -18,8 +18,6 @@
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
-using Tizen.NUI.BaseComponents;
 
 namespace Tizen.NUI.Components
 {
@@ -531,87 +529,6 @@ namespace Tizen.NUI.Components
         }
 
         /// <summary>
-        /// Shows a dialog by pushing a page containing dialog to default navigator.
-        /// </summary>
-        /// <param name="content">The content of Dialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        [SuppressMessage("Microsoft.Reliability",
-                         "CA2000:DisposeObjectsBeforeLosingScope",
-                         Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
-        public static void ShowDialog(View content = null)
-        {
-            var window = NUIApplication.GetDefaultWindow();
-            var defaultNavigator = window.GetDefaultNavigator();
-
-            var dialog = new Dialog(content);
-            SetDialogScrim(dialog);
-
-            // FIXME: Needs to use DialogPage.
-            var dialogPage = new ContentPage()
-            {
-                Content = dialog,
-            };
-            defaultNavigator.Push(dialogPage);
-        }
-
-        /// <summary>
-        /// Shows an alert dialog by pushing a page containing the alert dialog
-        /// to default navigator.
-        /// </summary>
-        /// <param name="titleContent">The title content of AlertDialog.</param>
-        /// <param name="content">The content of AlertDialog.</param>
-        /// <param name="actionContent">The action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        [SuppressMessage("Microsoft.Reliability",
-                         "CA2000:DisposeObjectsBeforeLosingScope",
-                         Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
-        public static void ShowAlertDialog(View titleContent, View content, View actionContent)
-        {
-            var window = NUIApplication.GetDefaultWindow();
-            var defaultNavigator = window.GetDefaultNavigator();
-
-            var dialog = new AlertDialog(titleContent, content, actionContent);
-            SetDialogScrim(dialog);
-
-            // FIXME: Needs to use DialogPage.
-            var dialogPage = new ContentPage()
-            {
-                Content = dialog,
-            };
-            defaultNavigator.Push(dialogPage);
-        }
-
-        /// <summary>
-        /// Shows an alert dialog by pushing a page containing the alert dialog
-        /// to default navigator.
-        /// </summary>
-        /// <param name="title">The title of AlertDialog.</param>
-        /// <param name="message">The message of AlertDialog.</param>
-        /// <param name="positiveButtonText">The positive button text in the action content of AlertDialog.</param>
-        /// <param name="positiveButtonClickedHandler">The clicked callback of the positive button in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonText">The negative button text in the action content of AlertDialog.</param>
-        /// <param name="negativeButtonClickedHandler">The clicked callback of the negative button in the action content of AlertDialog.</param>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        [SuppressMessage("Microsoft.Reliability",
-                         "CA2000:DisposeObjectsBeforeLosingScope",
-                         Justification = "The pushed views are added to NavigationPages and are disposed in Navigator.Dispose().")]
-        public static void ShowAlertDialog(string title = null, string message = null, string positiveButtonText = null, EventHandler<ClickedEventArgs> positiveButtonClickedHandler = null, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null)
-        {
-            var window = NUIApplication.GetDefaultWindow();
-            var defaultNavigator = window.GetDefaultNavigator();
-
-            var dialog = new AlertDialog(title, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler);
-            SetDialogScrim(dialog);
-
-            // FIXME: Needs to use DialogPage.
-            var dialogPage = new ContentPage()
-            {
-                Content = dialog,
-            };
-            defaultNavigator.Push(dialogPage);
-        }
-
-        /// <summary>
         /// Create Transition between currentTopPage and newTopPage
         /// </summary>
         /// <param name="currentTopPage">The top page of Navigator.</param>
@@ -684,35 +601,6 @@ namespace Tizen.NUI.Components
             return newTransitionSet;
         }
 
-        private static void SetDialogScrim(Dialog dialog)
-        {
-            if (dialog == null)
-            {
-                return;
-            }
-
-            var window = NUIApplication.GetDefaultWindow();
-            var defaultNavigator = window.GetDefaultNavigator();
-            var defaultScrim = dialog.Scrim;
-
-            //Copies default scrim's GUI properties.
-            var scrim = new VisualView();
-            scrim.BackgroundColor = defaultScrim.BackgroundColor;
-            scrim.Size = defaultScrim.Size;
-            scrim.TouchEvent += (object source, View.TouchEventArgs e) =>
-            {
-                if (e.Touch.GetState(0) == PointStateType.Up)
-                {
-                    defaultNavigator.Pop();
-                }
-
-                return true;
-            };
-
-            dialog.Scrim = scrim;
-        }
-
-
         /// <summary>
         /// Retrieve Tagged Views in the view tree.
         /// </summary>
@@ -746,4 +634,4 @@ namespace Tizen.NUI.Components
             TransitionFinished?.Invoke(this, new EventArgs());
         }
     }
-} //namespace Tizen.NUI
+}
index a29559b..4e1c57c 100755 (executable)
@@ -20,18 +20,28 @@ namespace Tizen.NUI.Samples
                 HeightResizePolicy = ResizePolicyType.FillToParent
             };
 
+            var positiveButton = new Button()
+            {
+                Text = "Yes",
+            };
+            positiveButton.Clicked += (object sender, ClickedEventArgs e) => { window.GetDefaultNavigator().Pop(); };
+
+            var negativeButton = new Button()
+            {
+                Text = "No",
+            };
+            negativeButton.Clicked += (object sender, ClickedEventArgs e) => { window.GetDefaultNavigator().Pop(); };
+
             button.Clicked += (object sender, ClickedEventArgs e) =>
             {
-                Navigator.ShowAlertDialog("Title", "Message",
-                    "Yes", (object sender2, ClickedEventArgs e2) => { window.GetDefaultNavigator().Pop(); },
-                    "No", (object sender2, ClickedEventArgs e2) => { window.GetDefaultNavigator().Pop(); });
+                DialogPage.ShowAlertDialog("Title", "Message", positiveButton, negativeButton);
             };
 
-            var dialogPage = new ContentPage()
+            var page = new ContentPage()
             {
                 Content = button,
             };
-            window.GetDefaultNavigator().Push(dialogPage);
+            window.GetDefaultNavigator().Push(page);
         }
 
         public void Deactivate()
index 4cc24b6..8d191c1 100755 (executable)
@@ -27,17 +27,17 @@ namespace Tizen.NUI.Samples
                     BackgroundColor = Color.White,
                     Size = new Size(180, 180),
                     HorizontalAlignment = HorizontalAlignment.Center,
-                    VerticalAlignment = VerticalAlignment.Center
+                    VerticalAlignment = VerticalAlignment.Center,
                 };
 
-                Navigator.ShowDialog(textLabel);
+                DialogPage.ShowDialog(textLabel);
             };
 
-            var dialogPage = new ContentPage()
+            var page = new ContentPage()
             {
                 Content = button,
             };
-            window.GetDefaultNavigator().Push(dialogPage);
+            window.GetDefaultNavigator().Push(page);
         }
 
         public void Deactivate()