2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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;
23 /// The NaviframeEventArgs is a event args class for navi frame.
24 /// Inherits EventArgs
26 /// <since_tizen> preview </since_tizen>
27 public class NaviframeEventArgs : EventArgs
30 /// Sets or gets the content object. The name of content part is "elm.swallow.content".
32 /// <since_tizen> preview </since_tizen>
33 public EvasObject Content { get; set; }
36 /// Naviframe is a widget to stands for navigation frame. It's a views manager for applications.
39 /// <since_tizen> preview </since_tizen>
40 public class Naviframe : Widget
42 SmartEvent _transitionFinished;
43 readonly List<NaviItem> _itemStack = new List<NaviItem>();
46 /// Creates and initializes a new instance of Naviframe class.
48 /// <param name="parent">The parent is a given container which will be attached by Naviframe as a child. It's <see cref="EvasObject"/> type.</param>
49 /// <since_tizen> preview </since_tizen>
50 public Naviframe(EvasObject parent) : base(parent)
52 _transitionFinished = new SmartEvent(this, this.RealHandle, "transition,finished");
53 _transitionFinished.On += (s, e) => AnimationFinished?.Invoke(this, EventArgs.Empty);
57 /// Popped will be triggered when NaviItem is removed.
60 /// It is always called when NaviItem was removed.
61 /// (even if removed by NaviItem.Delete())
62 /// This event will be invoked in progress of Pop/Delete operation.
63 /// After called Popped event, Pop/Delete method will be returned
65 /// <since_tizen> preview </since_tizen>
66 public event EventHandler<NaviframeEventArgs> Popped;
69 /// AnimationFinished will be triggered when animation is finished.
71 /// <since_tizen> preview </since_tizen>
72 public event EventHandler AnimationFinished;
75 /// Gets the list of navi item
77 /// <since_tizen> preview </since_tizen>
78 public IReadOnlyList<NaviItem> NavigationStack
80 get { return _itemStack; }
84 /// Sets or gets the the preserve content objects when items are popped.
86 /// <since_tizen> preview </since_tizen>
87 public bool PreserveContentOnPop
91 return Interop.Elementary.elm_naviframe_content_preserve_on_pop_get(RealHandle);
95 Interop.Elementary.elm_naviframe_content_preserve_on_pop_set(RealHandle, value);
100 /// Sets or gets whether the default back button is enabled
102 /// <since_tizen> preview </since_tizen>
103 public bool DefaultBackButtonEnabled
107 return Interop.Elementary.elm_naviframe_prev_btn_auto_pushed_get(RealHandle);
111 Interop.Elementary.elm_naviframe_prev_btn_auto_pushed_set(RealHandle, value);
116 /// Push a new item to the top of the naviframe stack and show it.
117 /// The title and style are null.
119 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
120 /// <returns>The created item or null upon failure.</returns>
121 /// <since_tizen> preview </since_tizen>
122 public NaviItem Push(EvasObject content)
124 return Push(content, null);
128 /// Push a new item to the top of the naviframe stack and show it.
129 /// The style are null.
131 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
132 /// <param name="title">The current item title. null would be default.</param>
133 /// <returns></returns>
134 /// <since_tizen> preview </since_tizen>
135 public NaviItem Push(EvasObject content, string title)
137 return Push(content, title, null);
141 /// Push a new item to the top of the naviframe stack and show it.
143 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
144 /// <param name="title">The current item title. null would be default.</param>
145 /// <param name="style">The current item style name. null would be default.</param>
146 /// <returns>The created item or null upon failure.</returns>
147 /// <since_tizen> preview </since_tizen>
148 public NaviItem Push(EvasObject content, string title, string style)
150 IntPtr item = Interop.Elementary.elm_naviframe_item_push(RealHandle, title, IntPtr.Zero, IntPtr.Zero, content.Handle, style);
151 NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
152 _itemStack.Add(naviItem);
153 naviItem.Popped += ItemPoppedHandler;
158 /// Insert a new item into the naviframe before item.
159 /// The title is "" and the style is null.
161 /// <param name="before">The item which the new item is inserted before.</param>
162 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
163 /// <returns>The created item or null upon failure.</returns>
164 /// <since_tizen> preview </since_tizen>
165 public NaviItem InsertBefore(NaviItem before, EvasObject content)
167 return InsertBefore(before, content, "");
171 /// Insert a new item into the naviframe before item.
172 /// The style is null.
174 /// <param name="before">The item which the new item is inserted before.</param>
175 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
176 /// <param name="title">The current item title. null would be default.</param>
177 /// <returns>The created item or null upon failure.</returns>
178 /// <since_tizen> preview </since_tizen>
179 public NaviItem InsertBefore(NaviItem before, EvasObject content, string title)
181 return InsertBefore(before, content, title, null);
185 /// Insert a new item into the naviframe before item.
187 /// <param name="before">The item which the new item is inserted before.</param>
188 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
189 /// <param name="title">The current item title. null would be default.</param>
190 /// <param name="style">The current item style name. null would be default.</param>
191 /// <returns>The created item or null upon failure.</returns>
192 /// <since_tizen> preview </since_tizen>
193 public NaviItem InsertBefore(NaviItem before, EvasObject content, string title, string style)
195 IntPtr item = Interop.Elementary.elm_naviframe_item_insert_before(RealHandle, before, title, IntPtr.Zero, IntPtr.Zero, content, null);
196 NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
197 int idx = _itemStack.IndexOf(before);
198 _itemStack.Insert(idx, naviItem);
199 naviItem.Popped += ItemPoppedHandler;
204 /// Insert a new item into the naviframe after item.
205 /// The title is "" and the style is null.
207 /// <param name="after">The item which the new item is inserted after.</param>
208 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
209 /// <returns>The created item or null upon failure.</returns>
210 /// <since_tizen> preview </since_tizen>
211 public NaviItem InsertAfter(NaviItem after, EvasObject content)
213 return InsertAfter(after, content, "");
217 /// Insert a new item into the naviframe after item.
218 /// The style is null.
220 /// <param name="after">The item which the new item is inserted after.</param>
221 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
222 /// <param name="title">The current item title. null would be default.</param>
223 /// <returns>The created item or null upon failure.</returns>
224 /// <since_tizen> preview </since_tizen>
225 public NaviItem InsertAfter(NaviItem after, EvasObject content, string title)
227 return InsertAfter(after, content, title, null);
231 /// Insert a new item into the naviframe after item.
233 /// <param name="after">The item which the new item is inserted after.</param>
234 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
235 /// <param name="title">The current item title. null would be default.</param>
236 /// <param name="style">The current item style name. null would be default.</param>
237 /// <returns>The created item or null upon failure.</returns>
238 /// <since_tizen> preview </since_tizen>
239 public NaviItem InsertAfter(NaviItem after, EvasObject content, string title, string style)
241 IntPtr item = Interop.Elementary.elm_naviframe_item_insert_after(RealHandle, after, title, IntPtr.Zero, IntPtr.Zero, content, null);
242 NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
243 int idx = _itemStack.IndexOf(after);
244 _itemStack.Insert(idx + 1, naviItem);
245 naviItem.Popped += ItemPoppedHandler;
250 /// Pop an item that is on top of the stack.
252 /// <since_tizen> preview </since_tizen>
255 Interop.Elementary.elm_naviframe_item_pop(RealHandle);
259 /// Creates a widget handle.
261 /// <param name="parent">Parent EvasObject</param>
262 /// <returns>Handle IntPtr</returns>
263 /// <since_tizen> preview </since_tizen>
264 protected override IntPtr CreateHandle(EvasObject parent)
266 IntPtr handle = Interop.Elementary.elm_layout_add(parent);
267 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
269 RealHandle = Interop.Elementary.elm_naviframe_add(handle);
270 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
275 void ItemPoppedHandler(object sender, EventArgs e)
277 NaviItem item = sender as NaviItem;
280 _itemStack.Remove(item);
281 Popped?.Invoke(this, new NaviframeEventArgs() { Content = item.Content });