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 public class NaviframeEventArgs : EventArgs
29 /// Sets or gets the content object. The name of content part is "elm.swallow.content".
31 public EvasObject Content { get; set; }
34 /// Naviframe is a widget to stands for navigation frame. It's a views manager for applications.
37 public class Naviframe : Widget
39 SmartEvent _transitionFinished;
40 readonly List<NaviItem> _itemStack = new List<NaviItem>();
43 /// Creates and initializes a new instance of Naviframe class.
45 /// <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>
46 public Naviframe(EvasObject parent) : base(parent)
48 _transitionFinished = new SmartEvent(this, this.RealHandle, "transition,finished");
49 _transitionFinished.On += (s, e) => AnimationFinished?.Invoke(this, EventArgs.Empty);
53 /// Popped will be triggered when NaviItem is removed.
56 /// It is always called when NaviItem was removed.
57 /// (even if removed by NaviItem.Delete())
58 /// This event will be invoked in progress of Pop/Delete operation.
59 /// After called Popped event, Pop/Delete method will be returned
61 public event EventHandler<NaviframeEventArgs> Popped;
64 /// AnimationFinished will be triggered when animation is finished.
66 public event EventHandler AnimationFinished;
69 /// Gets the list of navi item
71 public IReadOnlyList<NaviItem> NavigationStack
73 get { return _itemStack; }
77 /// Sets or gets the the preserve content objects when items are popped.
79 public bool PreserveContentOnPop
83 return Interop.Elementary.elm_naviframe_content_preserve_on_pop_get(RealHandle);
87 Interop.Elementary.elm_naviframe_content_preserve_on_pop_set(RealHandle, value);
92 /// Sets or gets whether the default back button is enabled
94 public bool DefaultBackButtonEnabled
98 return Interop.Elementary.elm_naviframe_prev_btn_auto_pushed_get(RealHandle);
102 Interop.Elementary.elm_naviframe_prev_btn_auto_pushed_set(RealHandle, value);
107 /// Push a new item to the top of the naviframe stack and show it.
108 /// The title and style are null.
110 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
111 /// <returns>The created item or null upon failure.</returns>
112 public NaviItem Push(EvasObject content)
114 return Push(content, null);
118 /// Push a new item to the top of the naviframe stack and show it.
119 /// The style are null.
121 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
122 /// <param name="title">The current item title. null would be default.</param>
123 /// <returns></returns>
124 public NaviItem Push(EvasObject content, string title)
126 return Push(content, title, null);
130 /// Push a new item to the top of the naviframe stack and show it.
132 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
133 /// <param name="title">The current item title. null would be default.</param>
134 /// <param name="style">The current item style name. null would be default.</param>
135 /// <returns>The created item or null upon failure.</returns>
136 public NaviItem Push(EvasObject content, string title, string style)
138 IntPtr item = Interop.Elementary.elm_naviframe_item_push(RealHandle, title, IntPtr.Zero, IntPtr.Zero, content.Handle, style);
139 NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
140 _itemStack.Add(naviItem);
141 naviItem.Popped += ItemPoppedHandler;
146 /// Insert a new item into the naviframe before item.
147 /// The title is "" and the style is null.
149 /// <param name="before">The item which the new item is inserted before.</param>
150 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
151 /// <returns>The created item or null upon failure.</returns>
152 public NaviItem InsertBefore(NaviItem before, EvasObject content)
154 return InsertBefore(before, content, "");
158 /// Insert a new item into the naviframe before item.
159 /// 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 /// <param name="title">The current item title. null would be default.</param>
164 /// <returns>The created item or null upon failure.</returns>
165 public NaviItem InsertBefore(NaviItem before, EvasObject content, string title)
167 return InsertBefore(before, content, title, null);
171 /// Insert a new item into the naviframe before item.
173 /// <param name="before">The item which the new item is inserted before.</param>
174 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
175 /// <param name="title">The current item title. null would be default.</param>
176 /// <param name="style">The current item style name. null would be default.</param>
177 /// <returns>The created item or null upon failure.</returns>
178 public NaviItem InsertBefore(NaviItem before, EvasObject content, string title, string style)
180 IntPtr item = Interop.Elementary.elm_naviframe_item_insert_before(RealHandle, before, title, IntPtr.Zero, IntPtr.Zero, content, null);
181 NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
182 int idx = _itemStack.IndexOf(before);
183 _itemStack.Insert(idx, naviItem);
184 naviItem.Popped += ItemPoppedHandler;
189 /// Insert a new item into the naviframe after item.
190 /// The title is "" and the style is null.
192 /// <param name="after">The item which the new item is inserted after.</param>
193 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
194 /// <returns>The created item or null upon failure.</returns>
195 public NaviItem InsertAfter(NaviItem after, EvasObject content)
197 return InsertAfter(after, content, "");
201 /// Insert a new item into the naviframe after item.
202 /// The style is null.
204 /// <param name="after">The item which the new item is inserted after.</param>
205 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
206 /// <param name="title">The current item title. null would be default.</param>
207 /// <returns>The created item or null upon failure.</returns>
208 public NaviItem InsertAfter(NaviItem after, EvasObject content, string title)
210 return InsertAfter(after, content, title, null);
214 /// Insert a new item into the naviframe after item.
216 /// <param name="after">The item which the new item is inserted after.</param>
217 /// <param name="content">The main content object. The name of content part is "elm.swallow.content".</param>
218 /// <param name="title">The current item title. null would be default.</param>
219 /// <param name="style">The current item style name. null would be default.</param>
220 /// <returns>The created item or null upon failure.</returns>
221 public NaviItem InsertAfter(NaviItem after, EvasObject content, string title, string style)
223 IntPtr item = Interop.Elementary.elm_naviframe_item_insert_after(RealHandle, after, title, IntPtr.Zero, IntPtr.Zero, content, null);
224 NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
225 int idx = _itemStack.IndexOf(after);
226 _itemStack.Insert(idx + 1, naviItem);
227 naviItem.Popped += ItemPoppedHandler;
232 /// Pop an item that is on top of the stack.
236 Interop.Elementary.elm_naviframe_item_pop(RealHandle);
239 protected override IntPtr CreateHandle(EvasObject parent)
241 IntPtr handle = Interop.Elementary.elm_layout_add(parent);
242 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
244 RealHandle = Interop.Elementary.elm_naviframe_add(handle);
245 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
250 void ItemPoppedHandler(object sender, EventArgs e)
252 NaviItem item = sender as NaviItem;
255 _itemStack.Remove(item);
256 Popped?.Invoke(this, new NaviframeEventArgs() { Content = item.Content });