Revert "[NUI] Add ContentPage class"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Navigation / Page.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20
21 namespace Tizen.NUI.Components
22 {
23     /// <summary>
24     /// PageAppearingEventArgs is a class to record page appearing event arguments which will be sent to user.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class PageAppearingEventArgs : EventArgs
28     {
29     }
30
31     /// <summary>
32     /// PageDisappearingEventArgs is a class to record page disappearing event arguments which will be sent to user.
33     /// </summary>
34     [EditorBrowsable(EditorBrowsableState.Never)]
35     public class PageDisappearingEventArgs : EventArgs
36     {
37     }
38
39     /// <summary>
40     /// The Page class is a class which is an element of navigation.
41     /// </summary>
42     [EditorBrowsable(EditorBrowsableState.Never)]
43     public class Page : Control
44     {
45         private AppBar appBar = null;
46         private View content = null;
47
48         /// <summary>
49         /// Creates a new instance of a Page.
50         /// </summary>
51         /// <param name="content">The content to set to Content of Page.</param>
52         [EditorBrowsable(EditorBrowsableState.Never)]
53         public Page(View content = null) : this(null, content)
54         {
55         }
56
57         /// <summary>
58         /// Creates a new instance of a Page.
59         /// </summary>
60         /// <param name="appBar">The content to set to AppBar of Page.</param>
61         /// <param name="content">The content to set to Content of Page.</param>
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public Page(AppBar appBar, View content = null) : base()
64         {
65             //AppBar and Content are located vertically.
66             var linearLayout = new LinearLayout();
67             linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
68             Layout = linearLayout;
69
70             //Page fills to parent by default.
71             WidthResizePolicy = ResizePolicyType.FillToParent;
72             HeightResizePolicy = ResizePolicyType.FillToParent;
73
74             if (appBar)
75             {
76                 AppBar = appBar;
77             }
78
79             if (content)
80             {
81                 Content = content;
82             }
83         }
84
85         /// <summary>
86         /// Dispose Page and all children on it.
87         /// </summary>
88         /// <param name="type">Dispose type.</param>
89         [EditorBrowsable(EditorBrowsableState.Never)]
90         protected override void Dispose(DisposeTypes type)
91         {
92             if (disposed)
93             {
94                 return;
95             }
96
97             if (type == DisposeTypes.Explicit)
98             {
99                 if (appBar != null)
100                 {
101                     Utility.Dispose(appBar);
102                 }
103
104                 if (content != null)
105                 {
106                     Utility.Dispose(content);
107                 }
108             }
109
110             base.Dispose(type);
111         }
112
113         /// <summary>
114         /// AppBar of Page. AppBar is added to Children automatically.
115         /// </summary>
116         [EditorBrowsable(EditorBrowsableState.Never)]
117         public AppBar AppBar
118         {
119             get
120             {
121                 return appBar;
122             }
123             set
124             {
125                 if (appBar == value)
126                 {
127                     return;
128                 }
129
130                 if (appBar != null)
131                 {
132                     Remove(appBar);
133                 }
134
135                 appBar = value;
136                 if (appBar == null)
137                 {
138                     return;
139                 }
140
141                 appBar.Weight = 0.0f;
142
143                 ResetContent();
144             }
145         }
146
147         /// <summary>
148         /// Content of Page. Content is added to Children automatically.
149         /// </summary>
150         [EditorBrowsable(EditorBrowsableState.Never)]
151         public View Content
152         {
153             get
154             {
155                 return content;
156             }
157             set
158             {
159                 if (content == value)
160                 {
161                     return;
162                 }
163
164                 if (content != null)
165                 {
166                     Remove(content);
167                 }
168
169                 content = value;
170                 if (content == null)
171                 {
172                     return;
173                 }
174
175                 content.Weight = 1.0f;
176
177                 ResetContent();
178             }
179         }
180
181         private void ResetContent()
182         {
183             //To keep the order of AppBar and Content, the existing contents are
184             //removed and added again.
185             if ((appBar != null) && Children.Contains(appBar))
186             {
187                 Remove(appBar);
188             }
189
190             if ((content != null) && Children.Contains(content))
191             {
192                 Remove(content);
193             }
194
195             if (appBar != null)
196             {
197                 Add(appBar);
198             }
199
200             if (content != null)
201             {
202                 Add(content);
203             }
204         }
205
206         /// <summary>
207         /// An event for the page appearing signal which can be used to subscribe or unsubscribe the event handler provided by the user.
208         /// </summary>
209         [EditorBrowsable(EditorBrowsableState.Never)]
210         public event EventHandler<PageAppearingEventArgs> Appearing;
211
212         /// <summary>
213         /// An event for the page disappearing signal which can be used to subscribe or unsubscribe the event handler provided by the user.
214         /// </summary>
215         [EditorBrowsable(EditorBrowsableState.Never)]
216         public event EventHandler<PageDisappearingEventArgs> Disappearing;
217
218         internal void InvokeAppearing()
219         {
220             Appearing?.Invoke(this, new PageAppearingEventArgs());
221         }
222
223         internal void InvokeDisappearing()
224         {
225             Disappearing?.Invoke(this, new PageDisappearingEventArgs());
226         }
227     }
228 }