/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace ElmSharp { /// /// Enumeration for the selection mode of Toolbar. /// public enum ToolbarSelectionMode { /// /// Default select mode. /// Default = 0, /// /// Always select mode. /// Always, /// /// No select mode. /// None, /// /// No select mode with no finger size rule. /// DisplayOnly, } /// /// Enumeration that sets the toolbar items display behavior, it can be scrollable, can show a menu with exceeding items, or simply hide them. /// public enum ToolbarShrinkMode { /// /// Sets minimum toolbar size to fit all the items. /// None = 0, /// /// Hides exceeding items. /// Hide, /// /// Allows accessing exceeding items through a scroller. /// Scroll, /// /// Inserts a button to pop up a menu with exceeding items. /// Menu, /// /// Expands all items according to the size of the toolbar. /// Expand } /// /// Event arguments for events of . /// /// /// Inherits EventArgs. /// public class ToolbarItemEventArgs : EventArgs { /// /// Gets the ToolbarItem. /// public ToolbarItem Item { get; private set; } internal static ToolbarItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info) { ToolbarItem item = ItemObject.GetItemByHandle(info) as ToolbarItem; return new ToolbarItemEventArgs() { Item = item }; } } /// /// The Toolbar is a widget that displays a list of items inside a box. /// public class Toolbar : Widget { SmartEvent _clicked; SmartEvent _selected; SmartEvent _longpressed; /// /// Creates and initializes a new instance of the Toolbar class. /// /// /// A EvasObject to which the new Table instance will be attached. /// public Toolbar(EvasObject parent) : base(parent) { _selected = new SmartEvent(this, this.RealHandle, "selected", ToolbarItemEventArgs.CreateFromSmartEvent); _selected.On += (s, e) => { if (e.Item != null) { Selected?.Invoke(this, e); e.Item.SendSelected(); } }; _longpressed = new SmartEvent(this, this.RealHandle, "longpressed", ToolbarItemEventArgs.CreateFromSmartEvent); _longpressed.On += (s, e) => { e.Item?.SendLongPressed(); }; _clicked = new SmartEvent(this, this.RealHandle, "clicked", ToolbarItemEventArgs.CreateFromSmartEvent); _clicked.On += (s, e) => { e.Item?.SendClicked(); }; } /// /// Selected will be triggered when toolbar have been selected. /// public event EventHandler Selected; /// /// Sets or gets whether the layout of this toolbar is homogeneous. /// /// True for homogeneous, False for no homogeneous public bool Homogeneous { get { return Interop.Elementary.elm_toolbar_homogeneous_get(RealHandle); } set { Interop.Elementary.elm_toolbar_homogeneous_set(RealHandle, value); } } /// /// Sets or gets the slection mode of a given Toolbar widget. /// public ToolbarSelectionMode SelectionMode { get { return (ToolbarSelectionMode)Interop.Elementary.elm_toolbar_select_mode_get(RealHandle); } set { Interop.Elementary.elm_toolbar_select_mode_set(RealHandle, (int)value); } } /// /// Sets or gets the shrink mode of a given Toolbar widget. /// public ToolbarShrinkMode ShrinkMode { get { return (ToolbarShrinkMode)Interop.Elementary.elm_toolbar_shrink_mode_get(RealHandle); } set { Interop.Elementary.elm_toolbar_shrink_mode_set(RealHandle, (int)value); } } /// /// Sets or gets the alignment of the items. /// /// The toolbar items alignment, a float between 0.0 and 1.0 public double ItemAlignment { get { return Interop.Elementary.elm_toolbar_align_get(RealHandle); } set { Interop.Elementary.elm_toolbar_align_set(RealHandle, value); } } /// /// Sets or gets the item's transverse expansion of a given toolbar widget. /// /// /// The transverse expansion of the item, true for on and false for off. /// By default it's false. /// public bool TransverseExpansion { get { return Interop.Elementary.elm_toolbar_transverse_expanded_get(RealHandle); } set { Interop.Elementary.elm_toolbar_transverse_expanded_set(RealHandle, value); } } /// /// Appends ToolbarItem which just contains label to the toolbar. /// /// The label of the item /// The new ToolbarItem which appended to the toolbar /// /// public ToolbarItem Append(string label) { return Append(label, null); } /// /// Appends ToolbarItem which contains label and icon to the toolbar. /// /// The label of the item /// A string with the icon name or the absolute path of an image file /// The new ToolbarItem which appended to the toolbar /// /// /// public ToolbarItem Append(string label, string icon) { ToolbarItem item = new ToolbarItem(label, icon); item.Handle = Interop.Elementary.elm_toolbar_item_append(RealHandle, icon, label, null, (IntPtr)item.Id); return item; } /// /// Prepends ToolbarItem which just contains label to the toolbar. /// /// The label of the item /// The new ToolbarItem which prepended to the toolbar /// /// /// public ToolbarItem Prepend(string label) { return Prepend(label, null); } /// /// Prepends ToolbarItem which contains label and icon to the toolbar. /// /// The label of the item /// A string with the icon name or the absolute path of an image file /// The new which prepended to the toolbar /// /// /// public ToolbarItem Prepend(string label, string icon) { ToolbarItem item = new ToolbarItem(label, icon); item.Handle = Interop.Elementary.elm_toolbar_item_prepend(RealHandle, icon, label, null, (IntPtr)item.Id); return item; } /// /// Inserts a new item which just contains label into the toolbar object before item . /// /// The toolbar item to insert before /// The label of the item /// The new which insert into the toolbar /// public ToolbarItem InsertBefore(ToolbarItem before, string label) { return InsertBefore(before, label); } /// /// Inserts a new item which contains label and icon into the toolbar object before item . /// /// The toolbar item to insert before /// The label of the item /// A string with the icon name or the absolute path of an image file /// The new which insert into the toolbar /// public ToolbarItem InsertBefore(ToolbarItem before, string label, string icon) { ToolbarItem item = new ToolbarItem(label, icon); item.Handle = Interop.Elementary.elm_toolbar_item_insert_before(RealHandle, before, icon, label, null, (IntPtr)item.Id); return item; } /// /// Gets the selected ToolbarItemItem of the toolbar. /// public ToolbarItem SelectedItem { get { IntPtr handle = Interop.Elementary.elm_toolbar_selected_item_get(RealHandle); return ItemObject.GetItemByHandle(handle) as ToolbarItem; } } protected override IntPtr CreateHandle(EvasObject parent) { IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle); Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default"); RealHandle = Interop.Elementary.elm_toolbar_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); return handle; } } }