Change EvasObject's API visibility to protected from internal.
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Naviframe.cs
1 using System;
2 using System.Collections.Generic;
3
4 namespace ElmSharp
5 {
6     public class NaviframeEventArgs : EventArgs
7     {
8         public EvasObject Content { get; set; }
9     }
10     public class Naviframe : Widget
11     {
12         Interop.SmartEvent _transitionFinished;
13         readonly List<NaviItem> _itemStack = new List<NaviItem>();
14         public Naviframe(EvasObject parent) : base(parent)
15         {
16             _transitionFinished = new Interop.SmartEvent(this, Handle, "transition,finished");
17             _transitionFinished.On += (s, e) => AnimationFinished?.Invoke(this, EventArgs.Empty);
18         }
19
20         public event EventHandler<NaviframeEventArgs> Popped;
21         public event EventHandler AnimationFinished;
22         public IReadOnlyList<NaviItem> NavigationStack
23         {
24             get { return _itemStack; }
25         }
26
27         public bool PreserveContentOnPop
28         {
29             get
30             {
31                 return Interop.Elementary.elm_naviframe_content_preserve_on_pop_get(Handle);
32             }
33             set
34             {
35                 Interop.Elementary.elm_naviframe_content_preserve_on_pop_set(Handle, value);
36             }
37         }
38
39         public bool DefaultBackButtonEnabled
40         {
41             get
42             {
43                 return Interop.Elementary.elm_naviframe_prev_btn_auto_pushed_get(Handle);
44             }
45             set
46             {
47                 Interop.Elementary.elm_naviframe_prev_btn_auto_pushed_set(Handle, value);
48             }
49         }
50
51         public NaviItem Push(EvasObject content)
52         {
53             return Push(content, null);
54         }
55         public NaviItem Push(EvasObject content, string title)
56         {
57             IntPtr item = Interop.Elementary.elm_naviframe_item_push(Handle, title, IntPtr.Zero, IntPtr.Zero, content.Handle, null);
58             NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
59             _itemStack.Add(naviItem);
60             naviItem.Popped += (s, e) =>
61             {
62                 _itemStack.Remove(naviItem);
63                 Popped?.Invoke(this, new NaviframeEventArgs() { Content = naviItem.Content });
64             };
65             return naviItem;
66         }
67
68         public NaviItem InsertBefore(NaviItem before, EvasObject content)
69         {
70             return InsertBefore(before, content);
71         }
72         public NaviItem InsertBefore(NaviItem before, EvasObject content, string title)
73         {
74             IntPtr item = Interop.Elementary.elm_naviframe_item_insert_before(Handle, before, title, IntPtr.Zero, IntPtr.Zero, content, null);
75             NaviItem naviItem = NaviItem.FromNativeHandle(item, content);
76             int idx = _itemStack.IndexOf(before);
77             _itemStack.Insert(idx, naviItem);
78             return naviItem;
79         }
80
81         public void Pop()
82         {
83             Interop.Elementary.elm_naviframe_item_pop(Handle);
84         }
85
86         protected override IntPtr CreateHandle(EvasObject parent)
87         {
88             return Interop.Elementary.elm_naviframe_add(parent.Handle);
89         }
90     }
91 }