From bd2388111936807e873809d8784063a36a511b3e Mon Sep 17 00:00:00 2001 From: Seunghyun Choi Date: Fri, 26 May 2017 11:17:17 +0900 Subject: [PATCH] Enhance Tooltip Widget Change-Id: Id17e0f275729fc46ae7476bfc0fa464f6b8adc6d Signed-off-by: Seunghyun Choi --- src/ElmSharp/ElmSharp/EvasObject.cs | 158 ++++++++++++++++++++++++++++- src/ElmSharp/Interop/Interop.Elementary.cs | 29 +++++- 2 files changed, 182 insertions(+), 5 deletions(-) mode change 100755 => 100644 src/ElmSharp/Interop/Interop.Elementary.cs diff --git a/src/ElmSharp/ElmSharp/EvasObject.cs b/src/ElmSharp/ElmSharp/EvasObject.cs index 00a8471..5bc3f7c 100644 --- a/src/ElmSharp/ElmSharp/EvasObject.cs +++ b/src/ElmSharp/ElmSharp/EvasObject.cs @@ -20,19 +20,37 @@ using System.Diagnostics; namespace ElmSharp { + public enum TooltipOrientation + { + None, + TopLeft, + Top, + TopRight, + Left, + Center, + Right, + BottomLeft, + Bottom, + BottomRight, + } + /// /// The EcasObject is a base class for other widget class /// public abstract class EvasObject { private IntPtr _realHandle = IntPtr.Zero; + private event EventHandler _backButtonPressed; + private event EventHandler _moreButtonPressed; + private Interop.Eext.EextEventCallback _backButtonHandler; private Interop.Eext.EextEventCallback _moreButtonHandler; public IntPtr Handle { get; protected set; } public EvasObject Parent { get; private set; } + public IntPtr RealHandle { get @@ -52,6 +70,9 @@ namespace ElmSharp EvasObjectEvent _resized; EventHandler _renderPost; Interop.Evas.EvasCallback _renderPostCallback = null; + Interop.Elementary.Elm_Tooltip_Content_Cb _tooltipContentCallback = null; + + GetTooltipContentDelegate _tooltipContentDelegate = null; readonly HashSet _eventStore = new HashSet(); @@ -74,6 +95,11 @@ namespace ElmSharp _moreButtonHandler = new Interop.Eext.EextEventCallback((d, o, i) => { _moreButtonPressed?.Invoke(this, EventArgs.Empty); }); OnInstantiated(); + + _tooltipContentCallback = (d, o, t) => + { + return _tooltipContentDelegate?.Invoke(); + }; } // C# Finalizer was called on GC thread @@ -88,10 +114,12 @@ namespace ElmSharp /// Deleted will be triggered when widght is deleted /// public event EventHandler Deleted; + /// /// KeyUp will be triggered when key is loose /// public event EventHandler KeyUp; + /// /// KeyDown will be triggered when key is preesd down /// @@ -143,7 +171,6 @@ namespace ElmSharp } } - /// /// Moved will be triggered when widght is moved /// @@ -152,6 +179,7 @@ namespace ElmSharp add { _moved.On += value; } remove { _moved.On -= value; } } + /// /// Current widget's size Resized Event Handler /// @@ -187,6 +215,12 @@ namespace ElmSharp } /// + /// Called back when a widget's tooltip is activated and needs content. + /// + /// + public delegate EvasObject GetTooltipContentDelegate(); + + /// /// Get widget's status of Realized or not. /// public bool IsRealized { get { return Handle != IntPtr.Zero; } } @@ -421,6 +455,86 @@ namespace ElmSharp } /// + /// Sets or Gets style for this object tooltip. + /// + public string TooltipStyle + { + get + { + return Interop.Elementary.elm_object_tooltip_style_get(RealHandle); + } + set + { + Interop.Elementary.elm_object_tooltip_style_set(RealHandle, value); + } + } + + /// + /// Sets or gets the orientation of Tooltip. + /// + public TooltipOrientation TooltipOrientation + { + get + { + return (TooltipOrientation)Interop.Elementary.elm_object_tooltip_orient_get(RealHandle); + } + set + { + Interop.Elementary.elm_object_tooltip_orient_set(RealHandle, (int)value); + } + } + + /// + /// Sets or gets size restriction state of an object's tooltip. + /// + public bool TooltipWindowMode + { + get + { + return Interop.Elementary.elm_object_tooltip_window_mode_get(RealHandle); + } + set + { + Interop.Elementary.elm_object_tooltip_window_mode_set(RealHandle, value); + } + } + + /// + /// Sets the content to be shown in the tooltip object. + /// + public GetTooltipContentDelegate TooltipContentDelegate + { + get + { + return _tooltipContentDelegate; + } + set + { + _tooltipContentDelegate = value; + if (value != null) + { + Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, _tooltipContentCallback, IntPtr.Zero, null); + } + else + { + Interop.Elementary.elm_object_tooltip_content_cb_set(RealHandle, null, IntPtr.Zero, null); + } + } + } + + /// + /// Gets the movement freeze by 1 + /// This gets the movement freeze count by one. + /// + public int TooltipMoveFreezeCount + { + get + { + return Interop.Elementary.elm_object_tooltip_move_freeze_get(RealHandle); + } + } + + /// /// Clips one object to another. /// /// The object to clip object by @@ -467,6 +581,39 @@ namespace ElmSharp } /// + /// This increments the tooltip movement freeze count by one. + /// If the count is more than 0, the tooltip position will be fixed. + /// + public void PushTooltipMoveFreeze() + { + Interop.Elementary.elm_object_tooltip_move_freeze_push(RealHandle); + } + + /// + /// This decrements the tooltip freeze count by one. + /// + public void PopTooltipMoveFreeze() + { + Interop.Elementary.elm_object_tooltip_move_freeze_pop(RealHandle); + } + + /// + /// Force hide tooltip of object. + /// + public void HideTooltip() + { + Interop.Elementary.elm_object_tooltip_hide(RealHandle); + } + + /// + /// Force show tooltip of object. + /// + public void ShowTooltip() + { + Interop.Elementary.elm_object_tooltip_show(RealHandle); + } + + /// /// Makes the current object visible. /// public void Show() @@ -562,18 +709,21 @@ namespace ElmSharp protected virtual void OnInstantiated() { } + /// /// The callback of Realized Event /// protected virtual void OnRealized() { } + /// /// The callback of Unrealize Event /// protected virtual void OnUnrealize() { } + /// /// Creates a widget handle. /// @@ -615,7 +765,7 @@ namespace ElmSharp { if (IsRealized) { - if(_renderPostCallback != null) + if (_renderPostCallback != null) { Interop.Evas.evas_event_callback_del(Interop.Evas.evas_object_evas_get(Handle), Interop.Evas.ObjectCallbackType.RenderPost, _renderPostCallback); _renderPostCallback = null; @@ -655,6 +805,7 @@ namespace ElmSharp } _eventStore.Clear(); } + private void MakeInvalidateEvent() { foreach (var evt in _eventStore) @@ -668,6 +819,5 @@ namespace ElmSharp { _eventStore.Add(item); } - } -} +} \ No newline at end of file diff --git a/src/ElmSharp/Interop/Interop.Elementary.cs b/src/ElmSharp/Interop/Interop.Elementary.cs old mode 100755 new mode 100644 index c865f12..e592713 --- a/src/ElmSharp/Interop/Interop.Elementary.cs +++ b/src/ElmSharp/Interop/Interop.Elementary.cs @@ -171,9 +171,27 @@ internal static partial class Interop internal static extern void elm_object_tooltip_unset(IntPtr obj); [DllImport(Libraries.Elementary)] + internal static extern string elm_object_tooltip_style_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] internal static extern void elm_object_tooltip_style_set(IntPtr obj, string style); [DllImport(Libraries.Elementary)] + internal static extern bool elm_object_tooltip_window_mode_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_object_tooltip_window_mode_set(IntPtr obj, bool disable); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_tooltip_move_freeze_push(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_tooltip_move_freeze_pop(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_object_tooltip_move_freeze_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] internal static extern void elm_object_tooltip_show(IntPtr obj); [DllImport(Libraries.Elementary)] @@ -182,6 +200,15 @@ internal static partial class Interop [DllImport(Libraries.Elementary)] internal static extern void elm_object_tooltip_orient_set(IntPtr obj, int orient); + [DllImport(Libraries.Elementary)] + internal static extern int elm_object_tooltip_orient_get(IntPtr obj); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate IntPtr Elm_Tooltip_Content_Cb(IntPtr data, IntPtr obj, IntPtr tooltip); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_object_tooltip_content_cb_set(IntPtr obj, Elm_Tooltip_Content_Cb func, IntPtr data, Interop.Evas.SmartCallback del); + internal static string elm_object_part_text_get(IntPtr obj, string part) { var text = _elm_object_part_text_get(obj, part); @@ -727,4 +754,4 @@ internal static partial class Interop [DllImport(Libraries.Elementary)] internal static extern int elm_layout_thaw(IntPtr obj); } -} +} \ No newline at end of file -- 2.7.4