/*
* 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 for the popup orientation type.
///
public enum PopupOrientation
{
///
/// Appears in the top of parent, default.
///
Top,
///
/// Appears in the center of parent.
///
Center,
///
/// Appears in the bottom of parent.
///
Bottom,
///
/// Appears in the left of parent.
///
Left,
///
/// Appears in the right of parent.
///
Right,
///
/// Appears in the top left of parent.
///
TopLeft,
///
/// Appears in the top right of parent.
///
TopRight,
///
/// Appears in the bottom left of parent.
///
BottomLeft,
///
/// Appears in the bottom right of parent.
///
BottomRight
}
///
/// The Popup is a widget that is an enhancement of Notify.
/// In addition to content area, there are two optional sections, namely title area and action area.
///
public class Popup : Layout
{
HashSet _children = new HashSet();
SmartEvent _dismissed;
SmartEvent _blockClicked;
SmartEvent _timeout;
SmartEvent _showFinished;
///
/// Creates and initializes a new instance of the Popup class.
///
/// The EvasObject to which the new Popup will be attached as a child.
public Popup(EvasObject parent) : base(parent)
{
_dismissed = new SmartEvent(this, "dismissed");
_dismissed.On += (sender, e) =>
{
Dismissed?.Invoke(this, EventArgs.Empty);
};
_blockClicked = new SmartEvent(this, "block,clicked");
_blockClicked.On += (sender, e) =>
{
OutsideClicked?.Invoke(this, EventArgs.Empty);
};
_timeout = new SmartEvent(this, "timeout");
_timeout.On += (sender, e) =>
{
TimedOut?.Invoke(this, EventArgs.Empty);
};
_showFinished = new SmartEvent(this, "show,finished");
_showFinished.On += (sender, e) =>
{
ShowAnimationFinished?.Invoke(this, EventArgs.Empty);
};
}
///
/// Dismissed will be triggered when Popup have been dismissed.
///
public event EventHandler Dismissed;
///
/// OutsideClicked will be triggered when users taps on the outside of Popup.
///
public event EventHandler OutsideClicked;
///
/// OutsideClicked will be triggered when Popup is closed as a result of timeout.
///
public event EventHandler TimedOut;
///
/// OutsideClicked will be triggered when the Popup transition is finished in showing.
///
public event EventHandler ShowAnimationFinished;
///
/// Sets or gets the position in which Popup will appear in its parent.
///
public PopupOrientation Orientation
{
get
{
return (PopupOrientation)Interop.Elementary.elm_popup_orient_get(Handle);
}
set
{
Interop.Elementary.elm_popup_orient_set(Handle, (int)value);
}
}
///
/// Sets or gets the wrapping type of content text packed in content area of Popup widget.
///
public WrapType ContentTextWrapType
{
get
{
return (WrapType)Interop.Elementary.elm_popup_content_text_wrap_type_get(Handle);
}
set
{
Interop.Elementary.elm_popup_content_text_wrap_type_set(Handle, (int)value);
}
}
///
/// Sets or gets the timeout value set to the Popup(in seconds).
///
///
/// Since calling Show() on a popup restarts the timer controlling when it is hidden,
/// setting this before the popup is shown will in effect mean starting the timer when the popup is shown.
/// TimedOut is called afterwards which can be handled if needed.
/// Set a value <= 0.0 to disable a running timer.If the value > 0.0 and the popup is previously visible,
/// the timer will be started with this value, canceling any running timer.
///
public double Timeout
{
get
{
return Interop.Elementary.elm_popup_timeout_get(Handle);
}
set
{
Interop.Elementary.elm_popup_timeout_set(Handle, value);
}
}
///
/// Sets or gets whether events should be passed to event blocked area by a click outside.
///
///
/// The visible region of popup is surrounded by a translucent region called Blocked Event area.
///
public bool AllowEvents
{
get
{
return Interop.Elementary.elm_popup_allow_events_get(Handle);
}
set
{
Interop.Elementary.elm_popup_allow_events_set(Handle, value);
}
}
///
/// Sets or gets the AlignmentX in which the popup will appear in its parent.
///
public override double AlignmentX
{
get
{
return Interop.Elementary.GetPopupAlignX(Handle);
}
set
{
Interop.Elementary.SetPopupAlignX(Handle, value);
}
}
///
/// Sets or gets the AlignmentY in which the popup will appear in its parent.
///
public override double AlignmentY
{
get
{
return Interop.Elementary.GetPopupAlignY(Handle);
}
set
{
Interop.Elementary.SetPopupAlignY(Handle, value);
}
}
///
/// Gets the Opacity value of the Popup.
///
public override int Opacity
{
get
{
return Color.Default.A;
}
set
{
Console.WriteLine("Popup instance doesn't support to set Opacity.");
}
}
///
/// Adds label to a Popup widget.
///
///
/// The new PopupItem which contains label .
public PopupItem Append(string label)
{
return Append(label, null);
}
///
/// Adds Label and icon to a Popup widget.
///
/// The Label which will be added into a new PopupItem.
/// The icon which will be added into a new PopupItem.
/// The new PopupItem which contains label and icon.
public PopupItem Append(string label, EvasObject icon)
{
PopupItem item = new PopupItem(label, icon);
item.Handle = Interop.Elementary.elm_popup_item_append(Handle, label, icon, null, (IntPtr)item.Id);
AddInternal(item);
return item;
}
///
/// Uses this function to dismiss the popup in hide effect.
/// when the Popup is dismissed, the "dismissed" signal will be emitted.
///
public void Dismiss()
{
Interop.Elementary.elm_popup_dismiss(Handle);
}
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Elementary.elm_popup_add(parent.Handle);
}
void AddInternal(PopupItem item)
{
_children.Add(item);
item.Deleted += Item_Deleted;
}
void Item_Deleted(object sender, EventArgs e)
{
_children.Remove((PopupItem)sender);
}
}
}