/*
- * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2020 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 : Control
+ public class AlertDialog : Dialog
{
private string title = null;
private string message = null;
- private View titleContent = null;
- private View content = null;
- private View actionContent = null;
- private IEnumerable<View> actionContentViews = null;
+ private View popupTitle = null;
+ private View popupContent = null;
+ private View popupAction = 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() : base()
+ public AlertDialog(string title, string message, string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null) : base()
{
- Initialize();
+ //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>
- /// Dispose AlertDialog and all children on it.
+ /// Creates a new instance of AlertDialog.
/// </summary>
- /// <param name="type">Dispose type.</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)]
- protected override void Dispose(DisposeTypes type)
+ public AlertDialog(string message, string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText = null, EventHandler<ClickedEventArgs> negativeButtonClickedHandler = null) : this(null, message, positiveButtonText, positiveButtonClickedHandler, negativeButtonText, negativeButtonClickedHandler)
{
- if (disposed)
- {
- return;
- }
+ }
- if (type == DisposeTypes.Explicit)
- {
- if (titleContent != null)
- {
- Utility.Dispose(titleContent);
- }
+ /// <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)
+ {
+ }
- if (content != null)
- {
- Utility.Dispose(content);
- }
+ /// <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)
+ {
+ }
- if (actionContent != null)
- {
- Utility.Dispose(actionContent);
- }
- }
+ /// <summary>
+ /// Creates a new instance of AlertDialog.
+ /// </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>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public AlertDialog(View titleContent, View bodyContent, View actionContent) : base()
+ {
+ //Content is initialized to add TitleContent, BodyContent and ActionContent.
+ //FIXME: Needs to separate GUI implementation codes to style cs file.
+ InitContent();
- base.Dispose(type);
+ TitleContent = titleContent;
+
+ BodyContent = bodyContent;
+
+ ActionContent = actionContent;
}
/// <summary>
- /// Title text of AlertDialog.
+ /// 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 string Title
+ public AlertDialog(View bodyContent, View actionContent) : this(null, bodyContent, actionContent)
{
- get
- {
- return title;
- }
- set
- {
- if (title == value)
- {
- return;
- }
+ }
- title = value;
+ /// <summary>
+ /// Creates a new instance of AlertDialog.
+ /// </summary>
+ /// <param name="bodyContent">The content of AlertDialog.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public AlertDialog(View bodyContent = null) : this(bodyContent, null)
+ {
+ }
- if (TitleContent is TextLabel textLabel)
- {
- textLabel.Text = title;
- }
- }
+ private void InitContent()
+ {
+ var content = new Control();
+
+ var linearLayout = new LinearLayout();
+ linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
+ content.Layout = linearLayout;
+
+ Content = content;
}
/// <summary>
{
get
{
- return titleContent;
+ return popupTitle;
}
set
{
- if (titleContent == value)
+ if (popupTitle == value)
{
return;
}
- if (titleContent != null)
+ if (popupTitle != null)
{
- Remove(titleContent);
+ Remove(popupTitle);
}
- titleContent = value;
- if (titleContent == null)
+ popupTitle = value;
+ if (popupTitle == null)
{
return;
}
- if (titleContent is TextLabel textLabel)
- {
- textLabel.Text = Title;
- }
-
ResetContent();
}
}
/// <summary>
- /// Message text of AlertDialog.
+ /// BodyContent of AlertDialog. BodyContent is added to Children automatically.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public string Message
+ public View BodyContent
{
get
{
- return message;
+ return popupContent;
}
set
{
- if (message == value)
+ if (popupContent == value)
{
return;
}
- message = value;
+ if (popupContent != null)
+ {
+ Remove(popupContent);
+ }
- if (Content is TextLabel textLabel)
+ popupContent = value;
+ if (popupContent == null)
{
- textLabel.Text = message;
+ return;
}
+
+ ResetContent();
}
}
/// <summary>
- /// Content of AlertDialog. Content is added to Children automatically.
+ /// Action content of AlertDialog. ActionContent is added to Children automatically.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public View Content
+ public View ActionContent
{
get
{
- return content;
+ return popupAction;
}
set
{
- if (content == value)
+ if (popupAction == value)
{
return;
}
- if (content != null)
+ if (popupAction != null)
{
- Remove(content);
+ Remove(popupAction);
}
- content = value;
- if (content == null)
+ popupAction = value;
+ if (popupAction == null)
{
return;
}
- if (content is TextLabel textLabel)
- {
- textLabel.Text = message;
- }
-
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 (popupAction != null)
+ {
+ Content.Add(popupAction);
+ }
+ }
+
/// <summary>
- /// Action views of AlertDialog.
- /// Action views are added to ActionContent of AlertDialog.
+ /// Title text of AlertDialog.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public IEnumerable<View> Actions
+ public string Title
{
get
{
- return actionContentViews;
+ return title;
}
set
{
- if (ActionContent == null)
+ if (title == value)
{
- actionContentViews = value;
return;
}
- if (actionContentViews != null)
+ title = value;
+ if (title == null)
{
- foreach (var oldAction in actionContentViews)
+ if (TitleContent != null)
{
- if (ActionContent.Children?.Contains(oldAction) == true)
- {
- ActionContent.Children.Remove(oldAction);
- }
+ //TitleContent setter calls Remove(popupTitle).
+ TitleContent = null;
}
}
-
- actionContentViews = value;
-
- if (actionContentViews == null)
- {
- return;
- }
-
- foreach (var action in actionContentViews)
+ else
{
- ActionContent.Add(action);
+ if (TitleContent == null)
+ {
+ TitleContent = CreateTitleContent(title);
+ }
+ else if (TitleContent == defaultTitleContent)
+ {
+ //Sets text if TitleContent is not set by user.
+ ((TextLabel)TitleContent).Text = title;
+ }
}
}
}
/// <summary>
- /// Action content of AlertDialog. ActionContent is added to Children automatically.
+ /// Message text of AlertDialog.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public View ActionContent
+ public string Message
{
- 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))
+ get
+ {
+ return message;
+ }
+ set
+ {
+ if (message == value)
{
- foreach (var action in Actions)
- {
- actionContent.Add(action);
- }
+ return;
}
- if (oldActionContent != null)
+ message = value;
+ if (message == null)
{
- Remove(oldActionContent);
+ if (BodyContent != null)
+ {
+ //BodyContent setter calls Remove(popupContent).
+ BodyContent = null;
+ }
}
-
- if (actionContent == null)
+ else
{
- return;
+ if (BodyContent == null)
+ {
+ BodyContent = CreateContent(message);
+ }
+ else if (BodyContent == defaultContent)
+ {
+ //Sets text if BodyContent is not set by user.
+ ((TextLabel)BodyContent).Text = message;
+ }
}
-
- ResetContent();
}
}
/// <summary>
- /// AccessibilityGetName.
+ /// Sets action button in the action content of AlertDialog.
/// </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)]
- protected override string AccessibilityGetName()
+ public void SetActionButton(AlertDialogActionButtonType type, string text, EventHandler<ClickedEventArgs> clickedHandler)
{
- if (!String.IsNullOrEmpty(Title))
- {
- return Title;
- }
- else
+ if (ActionContent == null)
{
- return Message;
+ if (type == AlertDialogActionButtonType.Positive)
+ {
+ ActionContent = CreateActionContent(text, clickedHandler, null, null);
+ }
+ else
+ {
+ ActionContent = CreateActionContent(null, null, text, clickedHandler);
+ }
}
- }
-
- /// <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
+ else if (ActionContent == defaultActionContent)
{
- if (defaultTitleContent == null)
+ //To keep the order of negativeButton and positiveButton,
+ //positiveButton is always removed.
+ if (positiveButton != null)
{
- defaultTitleContent = CreateDefaultTitleContent();
+ ActionContent.Remove(positiveButton);
}
- return defaultTitleContent;
- }
- }
+ if (type == AlertDialogActionButtonType.Negative)
+ {
+ if (negativeButton != null)
+ {
+ ActionContent.Remove(negativeButton);
+ }
- /// <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)
+ negativeButton = CreateActionButton(text, clickedHandler);
+ if (negativeButton != null)
+ {
+ ActionContent.Add(negativeButton);
+
+ if (positiveButton != null)
+ {
+ ActionContent.Add(positiveButton);
+ }
+ }
+ }
+ else
{
- defaultContent = CreateDefaultContent();
+ positiveButton = CreateActionButton(text, clickedHandler);
+ if (positiveButton != null)
+ {
+ ActionContent.Add(positiveButton);
+ }
}
-
- return defaultContent;
}
}
- /// <summary>
- /// Default action content of AlertDialog.
- /// If Actions are set, then default action content is automatically displayed.
- /// </summary>
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected View DefaultActionContent
+ private TextLabel CreateTitleContent(string text)
{
- get
+ if (text == null)
{
- if (defaultActionContent == null)
- {
- defaultActionContent = CreateDefaultActionContent();
- }
-
- return defaultActionContent;
+ 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;
+
+ return titleContent;
}
- private void Initialize()
+ private TextLabel CreateContent(string message)
{
- Layout = new LinearLayout()
+ if (message == null)
{
- LinearOrientation = LinearLayout.Orientation.Vertical,
- };
-
- this.Relayout += OnRelayout;
+ return null;
+ }
- TitleContent = DefaultTitleContent;
+ //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);
- Content = DefaultContent;
+ defaultContent = messageContent;
- ActionContent = DefaultActionContent;
+ return messageContent;
}
- private void ResetContent()
+ private Button CreateActionButton(string text, EventHandler<ClickedEventArgs> clickedHandler)
{
- //To keep the order of TitleContent, Content and ActionContent,
- //the existing contents are removed and added again.
- if (titleContent != null)
+ if (text == null)
{
- Remove(titleContent);
+ return null;
}
- if (content != null)
- {
- Remove(content);
- }
+ //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 (actionContent != null)
+ if (clickedHandler != null)
{
- Remove(actionContent);
+ actionButton.Clicked += clickedHandler;
}
- if (titleContent != null)
+ return actionButton;
+ }
+
+ private View CreateActionContent(string positiveButtonText, EventHandler<ClickedEventArgs> positiveButtonClickedHandler, string negativeButtonText, EventHandler<ClickedEventArgs> negativeButtonClickedHandler)
+ {
+ if ((negativeButtonText == null) && (positiveButtonText == null))
{
- Add(titleContent);
+ return null;
}
- if (content != null)
+ //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)
{
- Add(content);
+ actionContent.Add(negativeButton);
}
- if (actionContent != null)
+ positiveButton = CreateActionButton(positiveButtonText, positiveButtonClickedHandler);
+ if (positiveButton != null)
{
- Add(actionContent);
+ actionContent.Add(positiveButton);
}
- }
- private TextLabel CreateDefaultTitleContent()
- {
- //FIXME: Needs to separate GUI implementation codes to style cs file.
- return new TextLabel()
- {
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
- Size = new Size(360, 80),
- };
+ defaultActionContent = actionContent;
+
+ return actionContent;
}
- private TextLabel CreateDefaultContent()
+ /// <summary>
+ /// Dispose AlertDialog and all children on it.
+ /// </summary>
+ /// <param name="type">Dispose type.</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void Dispose(DisposeTypes type)
{
- //FIXME: Needs to separate GUI implementation codes to style cs file.
- return new TextLabel()
+ if (disposed)
{
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
- Size = new Size(360, 200),
- };
- }
+ return;
+ }
- private View CreateDefaultActionContent()
- {
- //FIXME: Needs to separate GUI implementation codes to style cs file.
- return new Control()
+ if (type == DisposeTypes.Explicit)
{
- BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
- Size = new Size(360, 80),
- Layout = new LinearLayout()
+ if (popupTitle != null)
{
- LinearOrientation = LinearLayout.Orientation.Horizontal,
- LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
- CellPadding = new Size2D(10, 0),
- },
- };
- }
+ Utility.Dispose(popupTitle);
+ }
- private void OnRelayout(object sender, EventArgs e)
- {
- //FIXME: Needs to separate GUI implementation codes to style cs file.
- CalculatePosition();
+ if (popupContent != null)
+ {
+ Utility.Dispose(popupContent);
+ }
+
+ if (popupAction != null)
+ {
+ if (positiveButton != null)
+ {
+ Utility.Dispose(positiveButton);
+ }
+
+ if (negativeButton != null)
+ {
+ Utility.Dispose(negativeButton);
+ }
+
+ Utility.Dispose(popupAction);
+ }
+ }
+
+ base.Dispose(type);
}
- private void CalculatePosition()
+ /// <summary>
+ /// AccessibilityGetName.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override string AccessibilityGetName()
{
- var size = Size2D;
- var parent = GetParent();
- Size2D parentSize;
-
- if ((parent != null) && (parent is View))
+ if (!String.IsNullOrEmpty(Title))
{
- parentSize = ((View)parent).Size;
+ return Title;
}
else
{
- parentSize = NUIApplication.GetDefaultWindow().Size;
+ return Message;
}
-
- Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
}
}
}
/*
- * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2020 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.
[EditorBrowsable(EditorBrowsableState.Never)]
public class Dialog : Control
{
- private View content = null;
+ private View popupContent = null;
+ private View scrim = null;
+ private bool enableScrim = true;
/// <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() : base()
+ public Dialog(View content = null) : base()
{
- Layout = new AbsoluteLayout();
+ EnableScrim = true;
+ EnableDismissOnScrim = true;
- this.Relayout += OnRelayout;
+ //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;
+ }
}
/// <summary>
- /// Dispose Dialog and all children on it.
+ /// Popup content of Dialog. Content is added to Children automatically.
/// </summary>
- /// <param name="type">Dispose type.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
- protected override void Dispose(DisposeTypes type)
+ public View Content
{
- if (disposed)
+ get
{
- return;
+ return popupContent;
}
-
- if (type == DisposeTypes.Explicit)
+ set
{
- this.Relayout -= OnRelayout;
+ 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 (content != null)
+ if (Scrim != null)
{
- Utility.Dispose(content);
+ popupContent.RaiseAbove(Scrim);
}
}
+ }
- base.Dispose(type);
+ private void PopupContentRelayout(object sender, EventArgs e)
+ {
+ //FIXME: Needs to separate GUI implementation codes to style cs file.
+ CalculateContentPosition();
+ }
+
+ private void CalculateContentPosition()
+ {
+ var size = popupContent.Size2D;
+ var parent = GetParent();
+ Size2D parentSize;
+
+ if ((parent != null) && (parent is View))
+ {
+ parentSize = ((View)parent).Size;
+ }
+ else
+ {
+ parentSize = NUIApplication.GetDefaultWindow().Size;
+ }
+
+ popupContent.Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
}
/// <summary>
- /// Popup content of Dialog. Content is added to Children automatically.
+ /// Indicates to show scrim behind popup content.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public View Content
+ public bool EnableScrim
+ {
+ get
+ {
+ return enableScrim;
+ }
+ set
+ {
+ if (enableScrim == value)
+ {
+ return;
+ }
+
+ enableScrim = value;
+
+ if ((Scrim != null) && (enableScrim != Scrim.Visibility))
+ {
+ if (enableScrim)
+ {
+ Scrim.Show();
+ }
+ else
+ {
+ Scrim.Hide();
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Indicates to dismiss popup content by touching on scrim.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool EnableDismissOnScrim { get; set; }
+
+ /// <summary>
+ /// Scrim covers background behind popup content.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected internal View Scrim
{
get
{
- return content;
+ return scrim;
}
set
{
- if (content == value)
+ if (scrim == value)
{
return;
}
- if (content != null)
+ if (scrim != null)
{
- Remove(content);
+ Remove(scrim);
}
- content = value;
- if (content == null)
+ scrim = value;
+ if (scrim == null)
{
return;
}
- Add(content);
+ Add(scrim);
+
+ if (Content != null)
+ {
+ Content.RaiseAbove(scrim);
+ }
}
}
/// <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)]
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);
- }
}
}
+++ /dev/null
-/*
- * 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);
- }
- }
-}