Merge "Add ThemeOverlay() API in Elementary." into devel/dotnet
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Toolbar.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 enum ToolbarSelectionMode
23     {
24         Default = 0,
25         Always,
26         None,
27         DisplayOnly,
28     }
29
30     public enum ToolbarShrinkMode
31     {
32         None = 0,
33         Hide,
34         Scroll,
35         Menu,
36         Expand
37     }
38
39     public class ToolbarItemEventArgs : EventArgs {
40         public ToolbarItem Item { get; private set; }
41
42         internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
43         {
44             ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem;
45             return new ToolbarItemEventArgs() { Item = item };
46         }
47     }
48
49     public class Toolbar : Widget
50     {
51         Interop.SmartEvent<ToolbarItemEventArgs> _clicked;
52         Interop.SmartEvent<ToolbarItemEventArgs> _selected;
53         Interop.SmartEvent<ToolbarItemEventArgs> _longpressed;
54         public Toolbar(EvasObject parent) : base(parent)
55         {
56             _selected = new Interop.SmartEvent<ToolbarItemEventArgs>(this, Handle, "selected", ToolbarItemEventArgs.CreateFromSmartEvent);
57             _selected.On += (s, e) =>
58             {
59                 if (e.Item != null)
60                 {
61                     Selected?.Invoke(this, e);
62                     e.Item.SendSelected();
63                 }
64             };
65             _longpressed = new Interop.SmartEvent<ToolbarItemEventArgs>(this, Handle, "longpressed", ToolbarItemEventArgs.CreateFromSmartEvent);
66             _longpressed.On += (s, e) =>
67             {
68                 e.Item?.SendLongPressed();
69             };
70             _clicked = new Interop.SmartEvent<ToolbarItemEventArgs>(this, Handle, "clicked", ToolbarItemEventArgs.CreateFromSmartEvent);
71             _clicked.On += (s, e) =>
72             {
73                 e.Item?.SendClicked();
74             };
75         }
76
77         public event EventHandler<ToolbarItemEventArgs> Selected;
78
79         public bool Homogeneous
80         {
81             get
82             {
83                 return Interop.Elementary.elm_toolbar_homogeneous_get(Handle);
84             }
85             set
86             {
87                 Interop.Elementary.elm_toolbar_homogeneous_set(Handle, value);
88             }
89         }
90
91         public ToolbarSelectionMode SelectionMode
92         {
93             get
94             {
95                 return (ToolbarSelectionMode)Interop.Elementary.elm_toolbar_select_mode_get(Handle);
96             }
97             set
98             {
99                 Interop.Elementary.elm_toolbar_select_mode_set(Handle, (int)value);
100             }
101         }
102
103         public ToolbarShrinkMode ShrinkMode
104         {
105             get
106             {
107                 return (ToolbarShrinkMode)Interop.Elementary.elm_toolbar_shrink_mode_get(Handle);
108             }
109             set
110             {
111                 Interop.Elementary.elm_toolbar_shrink_mode_set(Handle, (int)value);
112             }
113         }
114
115         public double ItemAlignment
116         {
117             get
118             {
119                 return Interop.Elementary.elm_toolbar_align_get(Handle);
120             }
121             set
122             {
123                 Interop.Elementary.elm_toolbar_align_set(Handle, value);
124             }
125         }
126
127         public bool TransverseExpansion
128         {
129             get
130             {
131                 return Interop.Elementary.elm_toolbar_transverse_expanded_get(Handle);
132             }
133             set
134             {
135                 Interop.Elementary.elm_toolbar_transverse_expanded_set(Handle, value);
136             }
137         }
138
139         public ToolbarItem Append(string label)
140         {
141             return Append(label, null);
142         }
143         public ToolbarItem Append(string label, string icon)
144         {
145             ToolbarItem item = new ToolbarItem(label, icon);
146             item.Handle = Interop.Elementary.elm_toolbar_item_append(Handle, icon, label, null, (IntPtr)item.Id);
147             return item;
148         }
149
150         public ToolbarItem Prepend(string label)
151         {
152             return Prepend(label, null);
153         }
154
155         public ToolbarItem Prepend(string label, string icon)
156         {
157             ToolbarItem item = new ToolbarItem(label, icon);
158             item.Handle = Interop.Elementary.elm_toolbar_item_prepend(Handle, icon, label, null, (IntPtr)item.Id);
159             return item;
160         }
161
162         public ToolbarItem InsertBefore(ToolbarItem before, string label)
163         {
164             return InsertBefore(before, label);
165         }
166
167         public ToolbarItem InsertBefore(ToolbarItem before, string label, string icon)
168         {
169             ToolbarItem item = new ToolbarItem(label, icon);
170             item.Handle = Interop.Elementary.elm_toolbar_item_insert_before(Handle, before, icon, label, null, (IntPtr)item.Id);
171             return item;
172         }
173
174         public ToolbarItem SelectedItem
175         {
176             get
177             {
178                 IntPtr handle = Interop.Elementary.elm_toolbar_selected_item_get(Handle);
179                 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
180             }
181         }
182
183         protected override IntPtr CreateHandle(EvasObject parent)
184         {
185             return Interop.Elementary.elm_toolbar_add(parent);
186         }
187     }
188 }