summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeunghyun Choi <sh4682.choi@samsung.com>2017-06-22 11:03:18 +0900
committerSeunghyun Choi <sh4682.choi@samsung.com>2017-06-23 11:29:05 +0900
commit52187a256aeb10b5d5b0c80af68c911e5e96761b (patch)
tree96d8ab26ef7607e735038c9d7e63d7a9fb4364e1
parentd22827d873427c028e7a3a3408b8c1fca936c12e (diff)
downloadelm-sharp-52187a256aeb10b5d5b0c80af68c911e5e96761b.tar.gz
elm-sharp-52187a256aeb10b5d5b0c80af68c911e5e96761b.tar.bz2
elm-sharp-52187a256aeb10b5d5b0c80af68c911e5e96761b.zip
Enhance ItemObejct
Change-Id: Ie7fa2cb2cde51442618fe2c1a448a53883555fa9
-rw-r--r--[-rwxr-xr-x]ElmSharp/ElmSharp/GenGrid.cs12
-rw-r--r--ElmSharp/ElmSharp/GenList.cs12
-rw-r--r--[-rwxr-xr-x]ElmSharp/ElmSharp/ItemObject.cs118
-rw-r--r--ElmSharp/Interop/Interop.Elementary.Item.cs2
4 files changed, 131 insertions, 13 deletions
diff --git a/ElmSharp/ElmSharp/GenGrid.cs b/ElmSharp/ElmSharp/GenGrid.cs
index be8c5ec..2b1a6ee 100755..100644
--- a/ElmSharp/ElmSharp/GenGrid.cs
+++ b/ElmSharp/ElmSharp/GenGrid.cs
@@ -473,17 +473,17 @@ namespace ElmSharp
/// <param name="data">The item data.</param>
/// <param name="func">User defined comparison function that defines the sort order based on gengrid item and its data.</param>
/// <returns>Return a gengrid item that contains data and itemClass.</returns>
- public GenGridItem InsertSorted(GenItemClass itemClass, object data, Comparison<GenGridItem> comparison)
+ public GenGridItem InsertSorted(GenItemClass itemClass, object data, Comparison<object> 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/ElmSharp/ElmSharp/GenList.cs b/ElmSharp/ElmSharp/GenList.cs
index 74b7202..ff52588 100644
--- a/ElmSharp/ElmSharp/GenList.cs
+++ b/ElmSharp/ElmSharp/GenList.cs
@@ -609,17 +609,17 @@ namespace ElmSharp
/// <param name="type">The genlist item type.</param>
/// <param name="parent">The parent item, otherwise null if there is no parent item.</param>
/// <returns>Return a genlist item that contains data and itemClass.</returns>
- public GenListItem InsertSorted(GenItemClass itemClass, object data, Comparison<GenListItem> comparison, GenListItemType type, GenListItem parent)
+ public GenListItem InsertSorted(GenItemClass itemClass, object data, Comparison<object> 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/ElmSharp/ElmSharp/ItemObject.cs b/ElmSharp/ElmSharp/ItemObject.cs
index e9edb74..f009396 100755..100644
--- a/ElmSharp/ElmSharp/ItemObject.cs
+++ b/ElmSharp/ElmSharp/ItemObject.cs
@@ -31,6 +31,8 @@ namespace ElmSharp
readonly Dictionary<string, EvasObject> _partContents = new Dictionary<string, EvasObject>();
Interop.Evas.SmartCallback _deleteCallback;
IntPtr _handle = IntPtr.Zero;
+ Dictionary<SignalData, Interop.Elementary.Elm_Object_Item_Signal_Cb> _signalDatas = new Dictionary<SignalData, Interop.Elementary.Elm_Object_Item_Signal_Cb>();
+ EvasObject _trackObject = null;
/// <summary>
/// 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); }
}
+ /// <summary>
+ /// Gets track object of the item.
+ /// </summary>
+ public EvasObject TrackObject
+ {
+ get
+ {
+ if (_trackObject == null)
+ _trackObject = new ItemEvasObject(Handle);
+ return _trackObject;
+ }
+ }
+
internal IntPtr Handle
{
get
@@ -184,6 +199,61 @@ namespace ElmSharp
}
/// <summary>
+ /// Add a function for a signal emitted by object item edje.
+ /// </summary>
+ /// <param name="emission">The signal's name.</param>
+ /// <param name="source">The signal's source.</param>
+ /// <param name="func">The function to be executed when the signal is emitted.</param>
+ public void AddSignalHandler(string emission, string source, Func<string, string, bool> 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);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Remove a signal-triggered function from a object item edje object.
+ /// </summary>
+ /// <param name="emission">The signal's name.</param>
+ /// <param name="source">The signal's source.</param>
+ /// <param name="func">The function to be executed when the signal is emitted.</param>
+ public void RemoveSignalHandler(string emission, string source, Func<string, string, bool> 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);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Send a signal to the edje object of the widget item.
+ /// </summary>
+ /// <param name="emission">The signal's name.</param>
+ /// <param name="source">The signal's source.</param>
+ public void EmitSignal(string emission, string source)
+ {
+ Interop.Elementary.elm_object_item_signal_emit(Handle, emission, source);
+ }
+
+ /// <summary>
/// Gets the handle of object item
/// </summary>
/// <param name="obj">ItemObject</param>
@@ -244,5 +314,53 @@ namespace ElmSharp
{
return s_globalId++;
}
+
+ class SignalData
+ {
+ public string Emission { get; set; }
+ public string Source { get; set; }
+ public Func<string, string, bool> Func { get; set; }
+
+ public SignalData(string emission, string source, Func<string, string, bool> 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/ElmSharp/Interop/Interop.Elementary.Item.cs b/ElmSharp/Interop/Interop.Elementary.Item.cs
index 063fc4b..0d516ec 100644
--- a/ElmSharp/Interop/Interop.Elementary.Item.cs
+++ b/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);