add opacity layout for layout inherited wiegets
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Index.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 using System.Collections.Generic;
19
20 namespace ElmSharp
21 {
22     public class Index : Layout
23     {
24         HashSet<IndexItem> _children = new HashSet<IndexItem>();
25         SmartEvent _delayedChanged;
26
27         public Index(EvasObject parent) : base(parent)
28         {
29             _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
30             _delayedChanged.On += _delayedChanged_On;
31         }
32
33         public event EventHandler Changed;
34
35         public bool AutoHide
36         {
37             get
38             {
39                 return !Interop.Elementary.elm_index_autohide_disabled_get(RealHandle);
40             }
41             set
42             {
43                 Interop.Elementary.elm_index_autohide_disabled_set(RealHandle, !value);
44             }
45         }
46
47         public bool IsHorizontal
48         {
49             get
50             {
51                 return Interop.Elementary.elm_index_horizontal_get(RealHandle);
52             }
53             set
54             {
55                 Interop.Elementary.elm_index_horizontal_set(RealHandle, value);
56             }
57         }
58
59         public bool IndicatorVisible
60         {
61             get
62             {
63                 return !Interop.Elementary.elm_index_indicator_disabled_get(RealHandle);
64             }
65             set
66             {
67                 Interop.Elementary.elm_index_indicator_disabled_set(RealHandle, !value);
68             }
69         }
70
71         public bool OmitEnabled
72         {
73             get
74             {
75                 return Interop.Elementary.elm_index_omit_enabled_get(RealHandle);
76             }
77             set
78             {
79                 Interop.Elementary.elm_index_omit_enabled_set(RealHandle, value);
80             }
81         }
82
83         public IndexItem SelectedItem
84         {
85             get
86             {
87                 IntPtr handle = Interop.Elementary.elm_index_selected_item_get(RealHandle, 0);
88                 return ItemObject.GetItemByHandle(handle) as IndexItem;
89             }
90         }
91
92         public IndexItem Append(string label)
93         {
94             IndexItem item = new IndexItem(label);
95             item.Handle = Interop.Elementary.elm_index_item_append(RealHandle, label, null, (IntPtr)item.Id);
96             return item;
97         }
98
99         public IndexItem Prepend(string label)
100         {
101             IndexItem item = new IndexItem(label);
102             item.Handle = Interop.Elementary.elm_index_item_prepend(RealHandle, label, null, (IntPtr)item.Id);
103             return item;
104         }
105
106         public IndexItem InsertBefore(string label, IndexItem before)
107         {
108             IndexItem item = new IndexItem(label);
109             item.Handle = Interop.Elementary.elm_index_item_insert_before(RealHandle, before, label, null, (IntPtr)item.Id);
110             return item;
111         }
112
113         public void Update(int level)
114         {
115             Interop.Elementary.elm_index_level_go(RealHandle, level);
116         }
117
118         protected override IntPtr CreateHandle(EvasObject parent)
119         {
120             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
121             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
122
123             RealHandle = Interop.Elementary.elm_index_add(handle);
124             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
125
126             return handle;
127         }
128
129         void _delayedChanged_On(object sender, EventArgs e)
130         {
131             SelectedItem?.SendSelected();
132             Changed?.Invoke(this, e);
133         }
134
135         void AddInternal(IndexItem item)
136         {
137             _children.Add(item);
138             item.Deleted += Item_Deleted;
139         }
140
141         void Item_Deleted(object sender, EventArgs e)
142         {
143             _children.Remove((IndexItem)sender);
144         }
145     }
146 }