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 /// A list of content views.
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 protected IList<View> Views
78 /// Gets the count of views.
80 /// <since_tizen> 9 </since_tizen>
81 public int ViewCount => Views.Count;
84 [EditorBrowsable(EditorBrowsableState.Never)]
85 public override void OnInitialize()
89 AccessibilityRole = Role.PageTabList;
93 /// Adds a view to TabContent.
95 /// <param name="view">A view to be added to TabContent.</param>
96 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
97 [EditorBrowsable(EditorBrowsableState.Never)]
98 protected virtual void AddView(View view)
102 throw new ArgumentNullException(nameof(view), "view should not be null.");
107 if (SelectedIndex == -1)
114 /// Adds a view to TabContent.
116 /// <param name="view">A view to be added to TabContent.</param>
117 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
118 internal void AddContentView(View view)
124 /// Removes a view from TabContent.
126 /// <param name="view">A view to be removed from TabContent.</param>
127 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
128 /// <exception cref="ArgumentException">Thrown when the argument view does not exist in TabContent.</exception>
129 [EditorBrowsable(EditorBrowsableState.Never)]
130 protected virtual void RemoveView(View view)
134 throw new ArgumentNullException(nameof(view), "view should not be null.");
137 if (Views.Contains(view) == false)
139 throw new ArgumentException("view does not exist in TabContent.", nameof(view));
142 int index = Views.IndexOf(view);
146 if (index == SelectedIndex)
148 if (Views.Count == 0)
152 else if (SelectedIndex == Views.Count)
154 SelectView(SelectedIndex - 1);
160 /// Removes a view from TabContent.
162 /// <param name="view">A view to be removed from TabContent.</param>
163 /// <exception cref="ArgumentNullException">Thrown when the argument view is null.</exception>
164 /// <exception cref="ArgumentException">Thrown when the argument view does not exist in TabContent.</exception>
165 internal void RemoveContentView(View view)
171 /// Selects a view at the specified index of TabContent.
172 /// The indices of views in TabContent are basically the order of adding to TabContent by <see cref="TabView.AddTab"/>.
173 /// So a view's index in TabContent can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
175 /// <param name="index">The index of a view in TabContent where the view will be selected.</param>
176 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than -1, or greater than or equal to the number of views.</exception>
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 protected virtual void SelectView(int index)
180 if ((index < -1) || (index >= Views.Count))
182 throw new ArgumentOutOfRangeException(nameof(index), "index should not be greater than or equal to -1, and less than the number of views.");
185 if (SelectedIndex != -1)
187 Remove(Views[SelectedIndex]);
195 SelectedIndex = index;
199 /// Selects a view at the specified index of TabContent.
200 /// The indices of views in TabContent are basically the order of adding to TabContent by <see cref="TabView.AddTab"/>.
201 /// So a view's index in TabContent can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
203 /// <param name="index">The index of a view in TabContent where the view will be selected.</param>
204 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than -1, or greater than or equal to the number of views.</exception>
205 internal void SelectContentView(int index)
211 /// Gets the view at the specified index of TabContent.
212 /// The indices of views in TabContent are basically the order of adding to TabContent by <see cref="TabView.AddTab"/>.
213 /// So a view's index in TabContent can be changed whenever <see cref="TabView.AddTab"/> or <see cref="TabView.RemoveTab"/> is called.
215 /// <param name="index">The index of a view in TabContent where the specified view exists.</param>
216 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than 0, or greater than or equal to the number of views.</exception>
217 /// <since_tizen> 9 </since_tizen>
218 public View GetView(int index)
220 if ((index < 0) || (index >= Views.Count))
222 throw new ArgumentOutOfRangeException(nameof(index), "index should not be greater than or equal to 0, and less than the number of views.");
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 protected override void Dispose(DisposeTypes type)
237 if (type == DisposeTypes.Explicit)
241 foreach (View view in Views)
243 Utility.Dispose(view);