602c6be552806c171454a51efcfa30d729d25bd7
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / NaviItem.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The NaviItem is a widget to contain the contents to show in Naviframe.
23     /// Inherits ItemObject
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     public class NaviItem : ItemObject
27     {
28         EvasObject _content;
29         bool _isPopped;
30         Color _barBackgroundColor = Color.Default;
31         Interop.Elementary.Elm_Naviframe_Item_Pop_Cb _popped;
32
33         NaviItem(IntPtr handle, EvasObject content) : base(handle)
34         {
35             _isPopped = false;
36             _content = content;
37             _popped = (d, i) =>
38             {
39                 _isPopped = true;
40                 Popped?.Invoke(this, EventArgs.Empty);
41                 return true;
42             };
43             Interop.Elementary.elm_naviframe_item_pop_cb_set(handle, _popped, IntPtr.Zero);
44         }
45
46         /// <summary>
47         /// Popped will be triggered when NaviItem is removed.
48         /// </summary>
49         /// <since_tizen> preview </since_tizen>
50         public event EventHandler Popped;
51
52         /// <summary>
53         /// Gets the content object. The name of content part is "elm.swallow.content".
54         /// </summary>
55         /// <since_tizen> preview </since_tizen>
56         public EvasObject Content
57         {
58             get { return _content; }
59         }
60
61         /// <summary>
62         /// Sets or gets a value whether title area is enabled or not.
63         /// </summary>
64         /// <since_tizen> preview </since_tizen>
65         public bool TitleBarVisible
66         {
67             get
68             {
69                 return Interop.Elementary.elm_naviframe_item_title_enabled_get(Handle);
70             }
71             set
72             {
73                 Interop.Elementary.elm_naviframe_item_title_enabled_set(Handle, value, false);
74             }
75         }
76
77         /// <summary>
78         ///  Sets or gets the title bar background color
79         /// </summary>
80         /// <since_tizen> preview </since_tizen>
81         public Color TitleBarBackgroundColor
82         {
83             get
84             {
85                 return _barBackgroundColor;
86             }
87             set
88             {
89                 if (value.IsDefault)
90                 {
91                     Interop.Elementary.elm_object_item_color_class_del(Handle, "bg_title");
92                 }
93                 else
94                 {
95                     SetPartColor("bg_title", value);
96                     _barBackgroundColor = value;
97                 }
98             }
99         }
100
101         /// <summary>
102         /// Sets or gets an item style.
103         /// </summary>
104         /// <since_tizen> preview </since_tizen>
105         public override string Style
106         {
107             get
108             {
109                 return Interop.Elementary.elm_naviframe_item_style_get(Handle);
110             }
111             set
112             {
113                 Interop.Elementary.elm_naviframe_item_style_set(Handle, value);
114             }
115         }
116
117         /// <summary>
118         /// Invalidate the EventArgs if _isPopped is false.
119         /// The method should be overridden in children class.
120         /// </summary>
121         /// <since_tizen> preview </since_tizen>
122         protected override void OnInvalidate()
123         {
124             if (!_isPopped)
125                 Popped?.Invoke(this, EventArgs.Empty);
126         }
127
128         internal static NaviItem FromNativeHandle(IntPtr handle, EvasObject content)
129         {
130             return new NaviItem(handle, content);
131         }
132     }
133 }