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