2 using System.Collections.Generic;
5 using System.Threading.Tasks;
9 public class ItemObject
11 private static Dictionary<int, ItemObject> s_IdToItemTable = new Dictionary<int, ItemObject>();
12 private static Dictionary<IntPtr, ItemObject> s_HandleToItemTable = new Dictionary<IntPtr, ItemObject>();
13 private static int s_globalId = 0;
15 readonly Dictionary<string, EvasObject> _partContents = new Dictionary<string, EvasObject>();
16 Interop.Evas.SmartCallback _deleteCallback;
17 IntPtr _handle = IntPtr.Zero;
19 protected ItemObject(IntPtr handle)
21 _deleteCallback = DeleteCallbackHandler;
23 s_IdToItemTable[Id] = this;
27 // C# Finalizer was called on GC thread
28 // So, We can't access to EFL object
29 // And When Finalizer was called, Field can be already released.
32 // if (Handle != IntPtr.Zero)
33 // Interop.Elementary.elm_object_item_del(Handle);
36 public int Id { get; private set; }
40 get { return !Interop.Elementary.elm_object_item_disabled_get(Handle); }
41 set { Interop.Elementary.elm_object_item_disabled_set(Handle, !value); }
44 internal IntPtr Handle
55 if (_handle != IntPtr.Zero)
57 UnsetDeleteCallback();
61 s_HandleToItemTable[Handle] = this;
65 public event EventHandler Deleted;
69 Interop.Elementary.elm_object_item_del(Handle);
70 _handle = IntPtr.Zero;
73 public void SetPartContent(string part, EvasObject content)
75 SetPartContent(part, content, false);
78 public void SetPartContent(string part, EvasObject content, bool preserveOldContent)
80 if (preserveOldContent)
82 Interop.Elementary.elm_object_item_part_content_unset(Handle, part);
84 Interop.Elementary.elm_object_item_part_content_set(Handle, part, content);
85 _partContents[part ?? "__default__"] = content;
88 public void SetPartText(string part, string text)
90 Interop.Elementary.elm_object_item_part_text_set(Handle, part, text);
93 public string GetPartText(string part)
95 return Interop.Elementary.elm_object_item_part_text_get(Handle, part);
98 public static implicit operator IntPtr(ItemObject obj)
105 protected virtual void OnInvalidate() { }
107 internal static ItemObject GetItemById(int id)
110 s_IdToItemTable.TryGetValue(id, out value);
114 internal static ItemObject GetItemByHandle(IntPtr handle)
117 s_HandleToItemTable.TryGetValue(handle, out value);
121 void DeleteCallbackHandler(IntPtr data, IntPtr obj, IntPtr info)
123 Deleted?.Invoke(this, EventArgs.Empty);
125 if (s_IdToItemTable.ContainsKey(Id))
127 s_IdToItemTable.Remove(Id);
129 if (s_HandleToItemTable.ContainsKey(_handle))
131 s_HandleToItemTable.Remove(_handle);
133 _partContents.Clear();
134 _handle = IntPtr.Zero;
137 void UnsetDeleteCallback()
139 Interop.Elementary.elm_object_item_del_cb_set(Handle, null);
142 void SetDeleteCallback()
144 if (Handle != IntPtr.Zero)
145 Interop.Elementary.elm_object_item_del_cb_set(Handle, _deleteCallback);
148 static int GetNextId()