/* * 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; using System.Collections.Generic; namespace ElmSharp { /// /// Enumeration of ContextPopup direction type. /// public enum ContextPopupDirection { /// /// ContextPopup show appear below clicked area /// /// Down, /// /// ContextPopup show appear to the right of the clicked area /// Right, /// /// ContextPopup show appear to the left of the clicked area /// Left, /// /// ContextPopup show appear above the clicked area /// Up, /// /// ContextPopup does not determine it's direction yet /// Unknown } /// /// It inherits . /// The ContextPopup is a widget that when it shown, pops up a list of items. /// public class ContextPopup : Layout { HashSet _children = new HashSet(); SmartEvent _dismissed; Interop.Evas.SmartCallback _onSelected; /// /// Creates and initializes a new instance of the ContextPopup class. /// /// The parent is a given container which will be attached by ContextPopup /// as a child.It's type. public ContextPopup(EvasObject parent) : base(parent) { _dismissed = new SmartEvent(this, this.RealHandle, "dismissed"); _dismissed.On += (sender, e) => { Dismissed?.Invoke(this, EventArgs.Empty); }; _onSelected = (data, obj, info) => { ContextPopupItem item = ItemObject.GetItemById((int)data) as ContextPopupItem; item?.SendSelected(); }; } /// /// Dismissed is raised when the ContextPopup item is dismissed. /// /// /// Outside of ContextPopup was clicked or it's parent area is changed or the language is changed. and then ContextPopup is dismissed. /// public event EventHandler Dismissed; /// /// Gets the current direction of a ContextPopup. /// /// /// Once the ContextPopup showed up, the direction would be determined. /// public ContextPopupDirection Direction { get { return (ContextPopupDirection)Interop.Elementary.elm_ctxpopup_direction_get(RealHandle); } } /// /// Gets or sets the value of current ContextPopup object's orientation. /// True for horizontal mode, False for vertical mode (or errors) /// public bool IsHorizontal { get { return Interop.Elementary.elm_ctxpopup_horizontal_get(RealHandle); } set { Interop.Elementary.elm_ctxpopup_horizontal_set(RealHandle, value); } } /// /// Gets or sets whether ContextPopup hide automatically /// or not when parent of ContextPopup is resized. /// /// /// Default value of AutoHide is False. /// public bool AutoHide { get { return !Interop.Elementary.elm_ctxpopup_auto_hide_disabled_get(RealHandle); } set { Interop.Elementary.elm_ctxpopup_auto_hide_disabled_set(RealHandle, !value); } } /// /// Clears all items in the given ContextPopup object. /// public void Clear() { Interop.Elementary.elm_ctxpopup_clear(Handle); } /// /// Sets the direction priority of a ContextPopup. /// /// 1st priority of direction /// 2nd priority of direction /// 3th priority of direction /// 4th priority of direction public void SetDirectionPriorty(ContextPopupDirection first, ContextPopupDirection second, ContextPopupDirection third, ContextPopupDirection fourth) { Interop.Elementary.elm_ctxpopup_direction_priority_set(RealHandle, (int)first, (int)second, (int)third, (int)fourth); } /// /// Gets the direction priority of a ContextPopup. /// /// 1st priority of direction to be returned /// 2nd priority of direction to be returned /// 2nd priority of direction to be returned /// 4th priority of direction to be returned public void GetDirectionPriority(out ContextPopupDirection first, out ContextPopupDirection second, out ContextPopupDirection third, out ContextPopupDirection fourth) { int firstOut, secondOut, thirdOut, fourthOut; Interop.Elementary.elm_ctxpopup_direction_priority_get(Handle, out firstOut, out secondOut, out thirdOut, out fourthOut); first = (ContextPopupDirection)firstOut; second = (ContextPopupDirection)secondOut; third = (ContextPopupDirection)thirdOut; fourth = (ContextPopupDirection)fourthOut; } /// /// Adds a new item to a ContextPopup object with label. /// /// The Label of the new item /// /// A ContextPopupItem added or NULL, on errors /// public ContextPopupItem Append(string label) { return Append(label, null); } /// /// Adds a new item to a ContextPopup object with label and icon. /// /// The Label of the new item /// Icon to be set on new item /// A ContextPopupItem added or NULL, on errors public ContextPopupItem Append(string label, EvasObject icon) { ContextPopupItem item = new ContextPopupItem(label, icon); item.Handle = Interop.Elementary.elm_ctxpopup_item_append(RealHandle, label, icon, _onSelected, (IntPtr)item.Id); AddInternal(item); return item; } /// /// Dismiss a ContextPopup object. The ContextPopup will be hidden and the "clicked" signal will be emitted. /// public void Dismiss() { Interop.Elementary.elm_ctxpopup_dismiss(RealHandle); } /// /// Gets the possibility that the direction would be available /// /// A direction user wants to check /// /// Get false if you cannot put it in the direction. Gets true if it's possible. /// public bool IsAvailableDirection(ContextPopupDirection direction) { return Interop.Elementary.elm_ctxpopup_direction_available_get(RealHandle, (int)direction); } /// /// Gets Alpha of a default Color Class. /// public override int Opacity { get { return Color.Default.A; } set { Console.WriteLine("ContextPopup instance doesn't support to set Opacity."); } } protected override IntPtr CreateHandle(EvasObject parent) { return Interop.Elementary.elm_ctxpopup_add(parent.Handle); } void AddInternal(ContextPopupItem item) { _children.Add(item); item.Deleted += Item_Deleted; } void Item_Deleted(object sender, EventArgs e) { _children.Remove((ContextPopupItem)sender); } } }