From: Seunghyun Choi Date: Thu, 22 Jun 2017 02:03:18 +0000 (+0900) Subject: Enhance ItemObejct X-Git-Tag: submit/trunk/20170823.075128~110^2~38^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=776bfeb9dfe43a12a5446a6da8772801da01e195;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Enhance ItemObejct Change-Id: Ie7fa2cb2cde51442618fe2c1a448a53883555fa9 --- diff --git a/src/ElmSharp/ElmSharp/GenGrid.cs b/src/ElmSharp/ElmSharp/GenGrid.cs old mode 100755 new mode 100644 index be8c5ec..2b1a6ee --- a/src/ElmSharp/ElmSharp/GenGrid.cs +++ b/src/ElmSharp/ElmSharp/GenGrid.cs @@ -473,17 +473,17 @@ namespace ElmSharp /// The item data. /// User defined comparison function that defines the sort order based on gengrid item and its data. /// Return a gengrid item that contains data and itemClass. - public GenGridItem InsertSorted(GenItemClass itemClass, object data, Comparison comparison) + public GenGridItem InsertSorted(GenItemClass itemClass, object data, Comparison comparison) { + GenGridItem item = new GenGridItem(data, itemClass); + Interop.Elementary.Eina_Compare_Cb compareCallback = (handle1, handle2) => { - GenGridItem item1 = ItemObject.GetItemByHandle(handle1) as GenGridItem; - GenGridItem item2 = ItemObject.GetItemByHandle(handle2) as GenGridItem; - return comparison(item1, item2); + GenGridItem first = (ItemObject.GetItemByHandle(handle1) as GenGridItem) ?? item; + GenGridItem second = (ItemObject.GetItemByHandle(handle2) as GenGridItem) ?? item; + return comparison(first.Data, second.Data); }; - GenGridItem item = new GenGridItem(data, itemClass); - IntPtr handle = Interop.Elementary.elm_gengrid_item_sorted_insert(RealHandle, itemClass.UnmanagedPtr, (IntPtr)item.Id, compareCallback, null, (IntPtr)item.Id); item.Handle = handle; AddInternal(item); diff --git a/src/ElmSharp/ElmSharp/GenList.cs b/src/ElmSharp/ElmSharp/GenList.cs index 74b7202..ff52588 100644 --- a/src/ElmSharp/ElmSharp/GenList.cs +++ b/src/ElmSharp/ElmSharp/GenList.cs @@ -609,17 +609,17 @@ namespace ElmSharp /// The genlist item type. /// The parent item, otherwise null if there is no parent item. /// Return a genlist item that contains data and itemClass. - public GenListItem InsertSorted(GenItemClass itemClass, object data, Comparison comparison, GenListItemType type, GenListItem parent) + public GenListItem InsertSorted(GenItemClass itemClass, object data, Comparison comparison, GenListItemType type, GenListItem parent) { + GenListItem item = new GenListItem(data, itemClass); + Interop.Elementary.Eina_Compare_Cb compareCallback = (handle1, handle2) => { - GenListItem item1 = ItemObject.GetItemByHandle(handle1) as GenListItem; - GenListItem item2 = ItemObject.GetItemByHandle(handle2) as GenListItem; - return comparison(item1, item2); + GenListItem first = (ItemObject.GetItemByHandle(handle1) as GenListItem) ?? item; + GenListItem second = (ItemObject.GetItemByHandle(handle2) as GenListItem) ?? item; + return comparison(first.Data, second.Data); }; - GenListItem item = new GenListItem(data, itemClass); - IntPtr handle = Interop.Elementary.elm_genlist_item_sorted_insert( RealHandle, // genlist handle itemClass.UnmanagedPtr, // item clas diff --git a/src/ElmSharp/ElmSharp/ItemObject.cs b/src/ElmSharp/ElmSharp/ItemObject.cs old mode 100755 new mode 100644 index e9edb74..f009396 --- a/src/ElmSharp/ElmSharp/ItemObject.cs +++ b/src/ElmSharp/ElmSharp/ItemObject.cs @@ -31,6 +31,8 @@ namespace ElmSharp readonly Dictionary _partContents = new Dictionary(); Interop.Evas.SmartCallback _deleteCallback; IntPtr _handle = IntPtr.Zero; + Dictionary _signalDatas = new Dictionary(); + EvasObject _trackObject = null; /// /// Creates and initializes a new instance of ItemObject class. @@ -67,6 +69,19 @@ namespace ElmSharp set { Interop.Elementary.elm_object_item_disabled_set(Handle, !value); } } + /// + /// Gets track object of the item. + /// + public EvasObject TrackObject + { + get + { + if (_trackObject == null) + _trackObject = new ItemEvasObject(Handle); + return _trackObject; + } + } + internal IntPtr Handle { get @@ -184,6 +199,61 @@ namespace ElmSharp } /// + /// Add a function for a signal emitted by object item edje. + /// + /// The signal's name. + /// The signal's source. + /// The function to be executed when the signal is emitted. + public void AddSignalHandler(string emission, string source, Func func) + { + if (emission != null && source != null && func != null) + { + var signalData = new SignalData(emission, source, func); + if (!_signalDatas.ContainsKey(signalData)) + { + var signalCallback = new Interop.Elementary.Elm_Object_Item_Signal_Cb((d, o, e, s) => + { + return func(e, s); + }); + Interop.Elementary.elm_object_item_signal_callback_add(Handle, emission, source, signalCallback, IntPtr.Zero); + } + } + } + + /// + /// Remove a signal-triggered function from a object item edje object. + /// + /// The signal's name. + /// The signal's source. + /// The function to be executed when the signal is emitted. + public void RemoveSignalHandler(string emission, string source, Func func) + { + if (emission != null && source != null && func != null) + { + var signalData = new SignalData(emission, source, func); + + Interop.Elementary.Elm_Object_Item_Signal_Cb signalCallback = null; + _signalDatas.TryGetValue(signalData, out signalCallback); + + if (signalCallback != null) + { + Interop.Elementary.elm_object_item_signal_callback_del(Handle, emission, source, signalCallback); + _signalDatas.Remove(signalData); + } + } + } + + /// + /// Send a signal to the edje object of the widget item. + /// + /// The signal's name. + /// The signal's source. + public void EmitSignal(string emission, string source) + { + Interop.Elementary.elm_object_item_signal_emit(Handle, emission, source); + } + + /// /// Gets the handle of object item /// /// ItemObject @@ -244,5 +314,53 @@ namespace ElmSharp { return s_globalId++; } + + class SignalData + { + public string Emission { get; set; } + public string Source { get; set; } + public Func Func { get; set; } + + public SignalData(string emission, string source, Func func) + { + Emission = emission; + Source = source; + Func = func; + } + + public override bool Equals(object obj) + { + SignalData s = obj as SignalData; + if (s == null) + { + return false; + } + return (Emission == s.Emission) && (Source == s.Source) && (Func == s.Func); + } + + public override int GetHashCode() + { + int hashCode = Emission.GetHashCode(); + hashCode ^= Source.GetHashCode(); + hashCode ^= Func.GetHashCode(); + return hashCode; + } + } + + class ItemEvasObject : EvasObject + { + IntPtr _parent = IntPtr.Zero; + + public ItemEvasObject(IntPtr parent) : base() + { + _parent = parent; + Realize(null); + } + + protected override IntPtr CreateHandle(EvasObject parent) + { + return Interop.Elementary.elm_object_item_track(_parent); + } + } } } \ No newline at end of file diff --git a/src/ElmSharp/Interop/Interop.Elementary.Item.cs b/src/ElmSharp/Interop/Interop.Elementary.Item.cs index 063fc4b..0d516ec 100644 --- a/src/ElmSharp/Interop/Interop.Elementary.Item.cs +++ b/src/ElmSharp/Interop/Interop.Elementary.Item.cs @@ -97,7 +97,7 @@ internal static partial class Interop internal static extern void elm_object_item_signal_callback_add(IntPtr obj, string emission, string source, Elm_Object_Item_Signal_Cb func, IntPtr data); [DllImport(Libraries.Elementary)] - internal static extern IntPtr elm_object_item_signal_callback_del(IntPtr obj, string emission, string source, Elm_Object_Item_Signal_Cb func, IntPtr data); + internal static extern IntPtr elm_object_item_signal_callback_del(IntPtr obj, string emission, string source, Elm_Object_Item_Signal_Cb func); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate bool Elm_Object_Item_Signal_Cb(IntPtr data, IntPtr item, string emission, string source);