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.
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
22 namespace Tizen.NUI.Components
25 /// TabContent is a class which contains a set of Views and has one of them selected.
27 /// <since_tizen> 9 </since_tizen>
28 public class TabContent : Control
30 private IList<View> views;
32 private void Initialize()
35 views = new List<View>();
39 /// Creates a new instance of TabContent.
41 /// <since_tizen> 9 </since_tizen>
48 /// Creates a new instance of a TabContent with style.
50 /// <param name="style">A style applied to the newly created TabContent.</param>
51 [EditorBrowsable(EditorBrowsableState.Never)]
52 public TabContent(ControlStyle style) : base(style)
58 /// The index of the selected view.
59 /// The indices of views in TabContent are basically the order of adding to TabContent by <see cref="TabView.AddTab"/>.
60 /// So a view's index in TabContent can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 protected int SelectedIndex { get; set; }
66 /// Gets the count of views.
68 /// <since_tizen> 9 </since_tizen>
69 public int ViewCount => views.Count;
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public override void OnInitialize()
77 AccessibilityRole = Role.PageTabList;
81 /// Adds a view to TabContent.
83 /// <param name="view">A view to be added to TabContent.</param>
84 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 protected internal void AddView(View view)
90 throw new ArgumentNullException(nameof(view), "view should not be null.");
95 if (SelectedIndex == -1)
102 /// Removes a view from TabContent.
104 /// <param name="view">A view to be removed from TabContent.</param>
105 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
106 /// <exception cref="ArgumentException">Thrown when the argument view does not exist in TabContent.</exception>
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 protected internal void RemoveView(View view)
112 throw new ArgumentNullException(nameof(view), "view should not be null.");
115 if (views.Contains(view) == false)
117 throw new ArgumentException("view does not exist in TabContent.", nameof(view));
120 int index = views.IndexOf(view);
124 if (index == SelectedIndex)
126 if (views.Count == 0)
130 else if (SelectedIndex == views.Count)
132 Select(SelectedIndex - 1);
138 /// Selects a view at the specified index of TabContent.
139 /// The indices of views in TabContent are basically the order of adding to TabContent by <see cref="TabView.AddTab"/>.
140 /// So a view's index in TabContent can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
142 /// <param name="index">The index of a view in TabContent where the view will be selected.</param>
143 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than -1, or greater than or equal to the number of views.</exception>
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 protected internal void Select(int index)
147 if ((index < -1) || (index >= views.Count))
149 throw new ArgumentOutOfRangeException(nameof(index), "index should not be greater than or equal to -1, and less than the number of views.");
152 if (SelectedIndex != -1)
154 Remove(views[SelectedIndex]);
162 SelectedIndex = index;
166 /// Gets the view at the specified index of TabContent.
167 /// The indices of views in TabContent are basically the order of adding to TabContent by <see cref="TabView.AddTab"/>.
168 /// So a view's index in TabContent can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
170 /// <param name="index">The index of a view in TabContent where the specified view exists.</param>
171 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than 0, or greater than or equal to the number of views.</exception>
172 /// <since_tizen> 9 </since_tizen>
173 public View GetView(int index)
175 if ((index < 0) || (index >= views.Count))
177 throw new ArgumentOutOfRangeException(nameof(index), "index should not be greater than or equal to 0, and less than the number of views.");
184 [EditorBrowsable(EditorBrowsableState.Never)]
185 protected override void Dispose(DisposeTypes type)
192 if (type == DisposeTypes.Explicit)
196 foreach (View view in views)
198 Utility.Dispose(view);