2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
23 /// Enumeration for the selection mode of Toolbar.
25 public enum ToolbarSelectionMode
28 /// Default select mode.
33 /// Always select mode.
43 /// No select mode with no finger size rule.
49 /// Enumeration that sets the toolbar items display behavior, it can be scrollable, can show a menu with exceeding items, or simply hide them.
51 public enum ToolbarShrinkMode
54 /// Sets minimum toolbar size to fit all the items.
59 /// Hides exceeding items.
64 /// Allows accessing exceeding items through a scroller.
69 /// Inserts a button to pop up a menu with exceeding items.
74 /// Expands all items according to the size of the toolbar.
80 /// Enumeration for the icon lookup order of Toolbar.
82 public enum ToolbarIconLookupOrder
85 /// Icon look up order: freedesktop, theme.
90 /// Icon look up order: theme, freedesktop.
95 /// Icon look up order: freedesktop.
100 /// Icon look up order: theme.
106 /// Event arguments for events of <see cref="ToolbarItem"/>.
109 /// Inherits EventArgs.
111 public class ToolbarItemEventArgs : EventArgs
114 /// Gets the ToolbarItem.
116 public ToolbarItem Item { get; private set; }
118 internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info)
120 ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem;
121 return new ToolbarItemEventArgs() { Item = item };
126 /// The Toolbar is a widget that displays a list of items inside a box.
128 public class Toolbar : Widget
130 SmartEvent<ToolbarItemEventArgs> _clicked;
131 SmartEvent<ToolbarItemEventArgs> _selected;
132 SmartEvent<ToolbarItemEventArgs> _longpressed;
135 /// Creates and initializes a new instance of the Toolbar class.
137 /// <param name="parent">
138 /// A EvasObject to which the new Table instance will be attached.
140 public Toolbar(EvasObject parent) : base(parent)
142 _selected = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "selected", ToolbarItemEventArgs.CreateFromSmartEvent);
143 _selected.On += (s, e) =>
147 Selected?.Invoke(this, e);
148 e.Item.SendSelected();
151 _longpressed = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "longpressed", ToolbarItemEventArgs.CreateFromSmartEvent);
152 _longpressed.On += (s, e) =>
154 e.Item?.SendLongPressed();
156 _clicked = new SmartEvent<ToolbarItemEventArgs>(this, this.RealHandle, "clicked", ToolbarItemEventArgs.CreateFromSmartEvent);
157 _clicked.On += (s, e) =>
159 e.Item?.SendClicked();
164 /// Selected will be triggered when toolbar have been selected.
166 public event EventHandler<ToolbarItemEventArgs> Selected;
169 /// Sets or gets whether the layout of this toolbar is homogeneous.
171 /// <remarks>True for homogeneous, False for no homogeneous</remarks>
172 public bool Homogeneous
176 return Interop.Elementary.elm_toolbar_homogeneous_get(RealHandle);
180 Interop.Elementary.elm_toolbar_homogeneous_set(RealHandle, value);
185 /// Sets or gets the slection mode of a given Toolbar widget.
187 public ToolbarSelectionMode SelectionMode
191 return (ToolbarSelectionMode)Interop.Elementary.elm_toolbar_select_mode_get(RealHandle);
195 Interop.Elementary.elm_toolbar_select_mode_set(RealHandle, (int)value);
200 /// Sets or gets the shrink mode of a given Toolbar widget.
202 public ToolbarShrinkMode ShrinkMode
206 return (ToolbarShrinkMode)Interop.Elementary.elm_toolbar_shrink_mode_get(RealHandle);
210 Interop.Elementary.elm_toolbar_shrink_mode_set(RealHandle, (int)value);
215 /// Sets or gets toolbar's current orientation.
217 [EditorBrowsable(EditorBrowsableState.Never)]
218 public bool IsHorizontal
222 return Interop.Elementary.elm_toolbar_horizontal_get(RealHandle);
226 Interop.Elementary.elm_toolbar_horizontal_set(RealHandle, value);
231 /// Sets or gets the icon lookup order, for toolbar items' icons.
232 /// The default lookup order is ToolbarIocnLookupOrder.ThemeFreedesktop.
233 /// Icons added before calling this function will not be affected.
235 public ToolbarIconLookupOrder IconLookupOrder
239 return (ToolbarIconLookupOrder)Interop.Elementary.elm_toolbar_icon_order_lookup_get(RealHandle);
243 Interop.Elementary.elm_toolbar_icon_order_lookup_set(RealHandle, (int)value);
248 /// Sets or gets the icon size of a given toolbar widget.
249 /// Default value is 32 pixels, to be used by toolbar items.
255 return Interop.Elementary.elm_toolbar_icon_size_get(RealHandle);
259 Interop.Elementary.elm_toolbar_icon_size_set(RealHandle, value);
264 /// Gets the number of items in a toolbar widget.
266 public int ItemsCount
270 return Interop.Elementary.elm_toolbar_items_count(RealHandle);
275 /// Sets or gets the alignment of the items.
277 /// <remarks>The toolbar items alignment, a float between 0.0 and 1.0</remarks>
278 public double ItemAlignment
282 return Interop.Elementary.elm_toolbar_align_get(RealHandle);
286 Interop.Elementary.elm_toolbar_align_set(RealHandle, value);
291 /// Sets or gets the item's transverse expansion of a given toolbar widget.
294 /// The transverse expansion of the item, true for on and false for off.
295 /// By default it's false.
297 public bool TransverseExpansion
301 return Interop.Elementary.elm_toolbar_transverse_expanded_get(RealHandle);
305 Interop.Elementary.elm_toolbar_transverse_expanded_set(RealHandle, value);
310 /// Appends ToolbarItem which just contains label to the toolbar.
312 /// <param name="label">The label of the item</param>
313 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
314 /// <seealso cref="Append(string, string)"/>
315 /// <seealso cref="Prepend(string)"/>
316 public ToolbarItem Append(string label)
318 return Append(label, null);
322 /// Appends ToolbarItem which contains label and icon to the toolbar.
324 /// <param name="label">The label of the item</param>
325 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
326 /// <returns>The new ToolbarItem which appended to the toolbar</returns>
327 /// <seealso cref="Append(string)"/>
328 /// <seealso cref="Prepend(string)"/>
329 /// <seealso cref="Prepend(string, string)"/>
330 public ToolbarItem Append(string label, string icon)
332 ToolbarItem item = new ToolbarItem(label, icon);
333 item.Handle = Interop.Elementary.elm_toolbar_item_append(RealHandle, icon, label, null, (IntPtr)item.Id);
338 /// Prepends ToolbarItem which just contains label to the toolbar.
340 /// <param name="label">The label of the item</param>
341 /// <returns>The new ToolbarItem which prepended to the toolbar</returns>
342 /// <seealso cref="Append(string)"/>
343 /// <seealso cref="Append(string, string)"/>
344 /// <seealso cref="Prepend(string, string)"/>
345 public ToolbarItem Prepend(string label)
347 return Prepend(label, null);
351 /// Prepends ToolbarItem which contains label and icon to the toolbar.
353 /// <param name="label">The label of the item</param>
354 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
355 /// <returns>The new <see cref="ToolbarItem"/> which prepended to the toolbar</returns>
356 /// <seealso cref="Append(string)"/>
357 /// <seealso cref="Append(string, string)"/>
358 /// <seealso cref="Prepend(string)"/>
359 public ToolbarItem Prepend(string label, string icon)
361 ToolbarItem item = new ToolbarItem(label, icon);
362 item.Handle = Interop.Elementary.elm_toolbar_item_prepend(RealHandle, icon, label, null, (IntPtr)item.Id);
367 /// Inserts a new item which just contains label into the toolbar object before item <paramref name="before"/>.
369 /// <param name="before">The toolbar item to insert before</param>
370 /// <param name="label">The label of the item</param>
371 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
372 /// <seealso cref="InsertBefore(ToolbarItem, string, string)"/>
373 public ToolbarItem InsertBefore(ToolbarItem before, string label)
375 return InsertBefore(before, label, string.Empty);
379 /// Inserts a new item which contains label and icon into the toolbar object before item <paramref name="before"/>.
381 /// <param name="before">The toolbar item to insert before</param>
382 /// <param name="label">The label of the item</param>
383 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
384 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
385 /// <seealso cref="InsertBefore(ToolbarItem, string)"/>
386 public ToolbarItem InsertBefore(ToolbarItem before, string label, string icon)
388 ToolbarItem item = new ToolbarItem(label, icon);
389 item.Handle = Interop.Elementary.elm_toolbar_item_insert_before(RealHandle, before, icon, label, null, (IntPtr)item.Id);
394 /// Inserts a new item which contains label and icon into the toolbar object after item <paramref name="after"/>.
396 /// <param name="after">The toolbar item to insert after</param>
397 /// <param name="label">The label of the item</param>
398 /// <param name="icon">A string with the icon name or the absolute path of an image file</param>
399 /// <returns>The new <see cref="ToolbarItem"/> which insert into the toolbar</returns>
400 public ToolbarItem InsertAfter(ToolbarItem after, string label, string icon)
402 ToolbarItem item = new ToolbarItem(label, icon);
403 item.Handle = Interop.Elementary.elm_toolbar_item_insert_after(RealHandle, after, icon, label, null, (IntPtr)item.Id);
408 /// Find the item with that label in the toolbar.
410 /// <param name="label">The label of the item</param>
411 /// <returns>The <see cref="ToolbarItem"/> into the toolbar</returns>
412 public ToolbarItem FindItemByLabel(string label)
414 IntPtr handle = Interop.Elementary.elm_toolbar_item_find_by_label(RealHandle, label);
415 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
419 /// Gets the selected ToolbarItemItem of the toolbar.
421 public ToolbarItem SelectedItem
425 IntPtr handle = Interop.Elementary.elm_toolbar_selected_item_get(RealHandle);
426 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
431 /// Gets the first ToolbarItemItem of the toolbar.
433 public ToolbarItem FirstItem
437 IntPtr handle = Interop.Elementary.elm_toolbar_first_item_get(RealHandle);
438 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
443 /// Gets the last ToolbarItemItem of the toolbar.
445 public ToolbarItem LastItem
449 IntPtr handle = Interop.Elementary.elm_toolbar_last_item_get(RealHandle);
450 return ItemObject.GetItemByHandle(handle) as ToolbarItem;
455 /// Creates a widget handle.
457 /// <param name="parent">Parent EvasObject</param>
458 /// <returns>Handle IntPtr</returns>
459 protected override IntPtr CreateHandle(EvasObject parent)
461 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
462 Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
464 RealHandle = Interop.Elementary.elm_toolbar_add(handle);
465 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);