/* * 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 { /// /// The HoverselItemEventArgs is an HoverselItem's EventArgs /// public class HoverselItemEventArgs : EventArgs { /// /// Hoversel's Item /// public HoverselItem Item { get; set; } internal static HoverselItemEventArgs CreateFromSmartEvent(IntPtr data, IntPtr obj, IntPtr info) { HoverselItem item = ItemObject.GetItemByHandle(info) as HoverselItem; return new HoverselItemEventArgs() { Item = item }; } } /// /// The hoversel is a button that pops up a list of items. /// public class Hoversel : Layout { SmartEvent _clicked; SmartEvent _expanded; SmartEvent _dismissed; SmartEvent _selected; Interop.Evas.SmartCallback _onItemSelected; /// /// Creates and initializes a new instance of the Hoversel class. /// /// The parent is a given container which will be attached by Hoversel as a child. It's type. public Hoversel(EvasObject parent) : base(parent) { _clicked = new SmartEvent(this, "clicked"); _clicked.On += (sender, e) => { Clicked?.Invoke(this, EventArgs.Empty); }; _expanded = new SmartEvent(this, "expanded"); _expanded.On += (sender, e) => { Expanded?.Invoke(this, EventArgs.Empty); }; _dismissed = new SmartEvent(this, "dismissed"); _dismissed.On += (sender, e) => { Dismissed?.Invoke(this, EventArgs.Empty); }; _selected = new SmartEvent(this, RealHandle, "selected", HoverselItemEventArgs.CreateFromSmartEvent); _selected.On += (s, e) => { if (e.Item != null) ItemSelected?.Invoke(this, e); }; _onItemSelected = (data, obj, info) => { HoverselItem item = ItemObject.GetItemById((int)data) as HoverselItem; item?.SendItemSelected(); }; } /// /// Clicked will be triggered when Hoversel is clicked /// public event EventHandler Clicked; /// /// Expanded will be triggered when Hoversel is activated by clicking the hoversel or by a function /// public event EventHandler Expanded; /// /// Dismissed will be triggered when Hoversel Dismissed /// public event EventHandler Dismissed; /// /// ItemSelected will be triggered when Hoversel's Item Selected /// public event EventHandler ItemSelected; /// /// Gets or sets the status to control whether the hoversel should expand horizontally. /// public bool IsHorizontal { get { return Interop.Elementary.elm_hoversel_horizontal_get(RealHandle); } set { Interop.Elementary.elm_hoversel_horizontal_set(RealHandle, value); } } /// /// Gets or sets the hover parent. /// public IntPtr HoverParent { get { return Interop.Elementary.elm_hoversel_hover_parent_get(RealHandle); } set { Interop.Elementary.elm_hoversel_hover_parent_set(RealHandle, value); } } /// /// Gets the flag of whether the hoversel is expanded. /// public bool IsExpanded { get { return Interop.Elementary.elm_hoversel_expanded_get(RealHandle); } } /// /// Gets or sets the status of whether update icon and text of hoversel same to those of selected item automatically. /// public bool AutoUpdate { get { return Interop.Elementary.elm_hoversel_auto_update_get(RealHandle); } set { Interop.Elementary.elm_hoversel_auto_update_set(RealHandle, value); } } /// /// This triggers the hoversel popup from code, the same as if the user had clicked the button. /// public void HoverBegin() { Interop.Elementary.elm_hoversel_hover_begin(RealHandle); } /// /// This dismisses the hoversel popup as if the user had clicked outside the hover. /// public void HoverEnd() { Interop.Elementary.elm_hoversel_hover_end(RealHandle); } /// /// This will remove all the children items from the hoversel. /// public void Clear() { Interop.Elementary.elm_hoversel_clear(RealHandle); } /// /// Add an item to the hoversel button. /// This adds an item to the hoversel to show when it is clicked. /// /// Item's label /// A handle to the added item. public HoverselItem AddItem(string label) { HoverselItem item = new HoverselItem(); item.Label = label; item.Handle = Interop.Elementary.elm_hoversel_item_add(RealHandle, label, null, 0, _onItemSelected, (IntPtr)item.Id); return item; } protected override IntPtr CreateHandle(EvasObject parent) { IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle); Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default"); RealHandle = Interop.Elementary.elm_hoversel_add(handle); Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle); return handle; } } }