2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.Components
26 /// Dialog class shows a dialog with content.
28 /// <since_tizen> 9 </since_tizen>
29 public class Dialog : Control
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(Dialog), null, propertyChanged: (bindable, oldValue, newValue) =>
37 var instance = (Dialog)bindable;
40 instance.InternalContent = newValue as View;
43 defaultValueCreator: (bindable) =>
45 var instance = (Dialog)bindable;
46 return instance.InternalContent;
49 private View content = null;
52 /// Creates a new instance of Dialog.
54 /// <since_tizen> 9 </since_tizen>
55 public Dialog() : base()
57 Layout = new AbsoluteLayout();
59 this.Relayout += OnRelayout;
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 protected override void Dispose(DisposeTypes type)
71 if (type == DisposeTypes.Explicit)
73 this.Relayout -= OnRelayout;
77 Utility.Dispose(content);
85 /// Popup content of Dialog.
86 /// Content is added as a child of Dialog automatically.
88 /// <since_tizen> 9 </since_tizen>
93 return GetValue(ContentProperty) as View;
97 SetValue(ContentProperty, value);
98 NotifyPropertyChanged();
101 private View InternalContent
109 if (content == value)
130 /// Initialize AT-SPI object.
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public override void OnInitialize()
136 AccessibilityRole = Role.Dialog;
137 Show(); // calls RegisterDefaultLabel(); Hide() will call UnregisterDefaultLabel()
141 /// Informs AT-SPI bridge about the set of AT-SPI states associated with this object.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 protected override AccessibilityStates AccessibilityCalculateStates()
146 var states = base.AccessibilityCalculateStates();
148 states[AccessibilityState.Modal] = true;
153 private void OnRelayout(object sender, EventArgs e)
155 //FIXME: Needs to separate GUI implementation codes to style cs file.
156 CalculateContentPosition();
159 private void CalculateContentPosition()
162 var parent = GetParent();
165 if ((parent != null) && (parent is View))
167 parentSize = ((View)parent).Size;
171 parentSize = NUIApplication.GetDefaultWindow().Size;
174 Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);