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