2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
23 /// The ItemObject is used to manage the item object.
25 /// <since_tizen> preview </since_tizen>
26 [Obsolete("This has been deprecated in API12")]
27 public class ItemObject
29 private static Dictionary<int, ItemObject> s_IdToItemTable = new Dictionary<int, ItemObject>();
30 private static Dictionary<IntPtr, ItemObject> s_HandleToItemTable = new Dictionary<IntPtr, ItemObject>();
31 private static int s_globalId = 0;
33 readonly Dictionary<string, EvasObject> _partContents = new Dictionary<string, EvasObject>();
34 Interop.Evas.SmartCallback _deleteCallback;
35 IntPtr _handle = IntPtr.Zero;
36 Dictionary<SignalData, Interop.Elementary.Elm_Object_Item_Signal_Cb> _signalDatas = new Dictionary<SignalData, Interop.Elementary.Elm_Object_Item_Signal_Cb>();
37 EvasObject _trackObject = null;
40 /// Gets the parent object for ItemObject.
42 /// <since_tizen> preview </since_tizen>
43 [Obsolete("This has been deprecated in API12")]
44 public EvasObject Parent { get; internal set; }
47 /// Creates and initializes a new instance of the ItemObject class.
49 /// <param name="handle">IntPtr</param>
50 /// <since_tizen> preview </since_tizen>
51 [Obsolete("This has been deprecated in API12")]
52 protected ItemObject(IntPtr handle)
54 _deleteCallback = DeleteCallbackHandler;
56 s_IdToItemTable[Id] = this;
62 /// Creates and initializes a new instance of the ItemObject class with parent object.
64 /// <param name="handle">IntPtr</param>
65 /// <param name="parent">Parent EvasObject</param>
66 /// <since_tizen> preview </since_tizen>
67 [Obsolete("This has been deprecated in API12")]
68 protected ItemObject(IntPtr handle, EvasObject parent)
70 _deleteCallback = DeleteCallbackHandler;
72 s_IdToItemTable[Id] = this;
77 // C# Finalizer was called on GC thread
78 // So, We can't access to EFL object
79 // And When Finalizer was called, Field can be already released.
82 // if (Handle != IntPtr.Zero)
83 // Interop.Elementary.elm_object_item_del(Handle);
87 /// Gets the ID of the item object.
89 /// <since_tizen> preview </since_tizen>
90 [Obsolete("This has been deprecated in API12")]
91 public int Id { get; private set; }
94 /// Sets or gets whether the item object is enabled.
96 /// <since_tizen> preview </since_tizen>
97 [Obsolete("This has been deprecated in API12")]
100 get { return !Interop.Elementary.elm_object_item_disabled_get(Handle); }
101 set { Interop.Elementary.elm_object_item_disabled_set(Handle, !value); }
105 /// Gets the track object of the item.
107 /// <since_tizen> preview </since_tizen>
108 [Obsolete("This has been deprecated in API12")]
109 public EvasObject TrackObject
113 if (_trackObject == null || Interop.Elementary.elm_object_item_track_get(Handle) == 0)
115 _trackObject = new ItemEvasObject(Handle);
122 /// Sets or gets the style of the item.
124 /// <since_tizen> preview </since_tizen>
125 [Obsolete("This has been deprecated in API12")]
126 public virtual string Style
130 return Interop.Elementary.elm_object_item_style_get(Handle);
134 Interop.Elementary.elm_object_item_style_set(Handle, value);
138 internal IntPtr Handle
146 if (_handle == value)
149 if (_handle != IntPtr.Zero)
151 UnsetDeleteCallback();
155 s_HandleToItemTable[Handle] = this;
156 if (_handle != IntPtr.Zero)
158 Elementary.SendItemObjectRealized(this);
164 /// Deleted will be triggered when the item object is deleted.
166 /// <since_tizen> preview </since_tizen>
167 [Obsolete("This has been deprecated in API12")]
168 public event EventHandler Deleted;
171 /// Deletes the item object.
173 /// <since_tizen> preview </since_tizen>
174 [Obsolete("This has been deprecated in API12")]
177 Interop.Elementary.elm_object_item_del(Handle);
178 _handle = IntPtr.Zero;
182 /// Sets a content of an object item and deletes the old content.
184 /// <param name="part">The content part name (null for the default content).</param>
185 /// <param name="content">The content of the object item.</param>
186 /// <since_tizen> preview </since_tizen>
187 [Obsolete("This has been deprecated in API12")]
188 public void SetPartContent(string part, EvasObject content)
190 SetPartContent(part, content, false);
194 /// Sets a content of the object item.
196 /// <param name="part">The content part name (null for the default content)</param>
197 /// <param name="content">The content of the object item.</param>
198 /// <param name="preserveOldContent">Judge whether to delete the old content.</param>
199 /// <since_tizen> preview </since_tizen>
200 [Obsolete("This has been deprecated in API12")]
201 public void SetPartContent(string part, EvasObject content, bool preserveOldContent)
203 IntPtr oldContent = Interop.Elementary.elm_object_item_part_content_unset(Handle, part);
204 if (oldContent != IntPtr.Zero && !preserveOldContent)
206 Interop.Evas.evas_object_del(oldContent);
208 Interop.Elementary.elm_object_item_part_content_set(Handle, part, content);
209 _partContents[part ?? "__default__"] = content;
213 /// Sets the label of the object item.
215 /// <param name="part">The text part name (null for the default label).</param>
216 /// <param name="text">Text of the label.</param>
217 /// <since_tizen> preview </since_tizen>
218 [Obsolete("This has been deprecated in API12")]
219 public void SetPartText(string part, string text)
221 Interop.Elementary.elm_object_item_part_text_set(Handle, part, text);
225 /// Gets the label of the object item.
227 /// <param name="part">The text part name (null for the default label).</param>
228 /// <returns></returns>
229 /// <since_tizen> preview </since_tizen>
230 [Obsolete("This has been deprecated in API12")]
231 public string GetPartText(string part)
233 return Interop.Elementary.elm_object_item_part_text_get(Handle, part);
237 /// Sets the color of the object item.
239 /// <param name="part">The text part name (null for the default label).</param>
240 /// <param name="color">The color.</param>
241 /// <since_tizen> preview </since_tizen>
242 [Obsolete("This has been deprecated in API12")]
243 public void SetPartColor(string part, Color color)
245 Interop.Elementary.elm_object_item_color_class_color_set(Handle, part, color.R * color.A / 255,
246 color.G * color.A / 255,
247 color.B * color.A / 255,
252 /// Gets the color of the object item.
254 /// <param name="part">The text part name (null for the default label).</param>
255 /// <returns>The color of an object item.</returns>
256 /// <since_tizen> preview </since_tizen>
257 [Obsolete("This has been deprecated in API12")]
258 public Color GetPartColor(string part)
261 Interop.Elementary.elm_object_item_color_class_color_get(Handle, part, out r, out g, out b, out a);
262 return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
266 /// Deletes the color of the object item.
268 /// <param name="part">The text part name.</param>
269 /// <since_tizen> preview </since_tizen>
270 [Obsolete("This has been deprecated in API12")]
271 public void DeletePartColor(string part)
273 Interop.Elementary.elm_object_item_color_class_del(Handle, part);
277 /// Adds a function for a signal emitted by the object item edje.
279 /// <param name="emission">The signal's name.</param>
280 /// <param name="source">The signal's source.</param>
281 /// <param name="func">The function to be executed when the signal is emitted.</param>
282 /// <since_tizen> preview </since_tizen>
283 [Obsolete("This has been deprecated in API12")]
284 public void AddSignalHandler(string emission, string source, Func<string, string, bool> func)
286 if (emission != null && source != null && func != null)
288 var signalData = new SignalData(emission, source, func);
289 if (!_signalDatas.ContainsKey(signalData))
291 var signalCallback = new Interop.Elementary.Elm_Object_Item_Signal_Cb((d, o, e, s) =>
295 Interop.Elementary.elm_object_item_signal_callback_add(Handle, emission, source, signalCallback, IntPtr.Zero);
301 /// Removes a signal-triggered function from the object item edje object.
303 /// <param name="emission">The signal's name.</param>
304 /// <param name="source">The signal's source.</param>
305 /// <param name="func">The function to be executed when the signal is emitted.</param>
306 /// <since_tizen> preview </since_tizen>
307 [Obsolete("This has been deprecated in API12")]
308 public void RemoveSignalHandler(string emission, string source, Func<string, string, bool> func)
310 if (emission != null && source != null && func != null)
312 var signalData = new SignalData(emission, source, func);
314 Interop.Elementary.Elm_Object_Item_Signal_Cb signalCallback = null;
315 _signalDatas.TryGetValue(signalData, out signalCallback);
317 if (signalCallback != null)
319 Interop.Elementary.elm_object_item_signal_callback_del(Handle, emission, source, signalCallback);
320 _signalDatas.Remove(signalData);
326 /// Send a signal to the edje object of the widget item.
328 /// <param name="emission">The signal's name.</param>
329 /// <param name="source">The signal's source.</param>
330 /// <since_tizen> preview </since_tizen>
331 [Obsolete("This has been deprecated in API12")]
332 public void EmitSignal(string emission, string source)
334 Interop.Elementary.elm_object_item_signal_emit(Handle, emission, source);
338 /// Gets the handle of the object item.
340 /// <param name="obj">ItemObject</param>
341 /// <since_tizen> preview </since_tizen>
342 [Obsolete("This has been deprecated in API12")]
343 public static implicit operator IntPtr(ItemObject obj)
351 /// OnInvalidate of the object item.
353 /// <since_tizen> preview </since_tizen>
354 [Obsolete("This has been deprecated in API12")]
355 protected virtual void OnInvalidate() { }
357 internal static ItemObject GetItemById(int id)
360 s_IdToItemTable.TryGetValue(id, out value);
364 internal static ItemObject GetItemByHandle(IntPtr handle)
367 s_HandleToItemTable.TryGetValue(handle, out value);
371 void DeleteCallbackHandler(IntPtr data, IntPtr obj, IntPtr info)
373 Deleted?.Invoke(this, EventArgs.Empty);
376 if (s_IdToItemTable.ContainsKey(Id))
378 s_IdToItemTable.Remove(Id);
380 if (s_HandleToItemTable.ContainsKey(_handle))
382 s_HandleToItemTable.Remove(_handle);
384 _partContents.Clear();
385 _handle = IntPtr.Zero;
388 void UnsetDeleteCallback()
390 Interop.Elementary.elm_object_item_del_cb_set(Handle, null);
393 void SetDeleteCallback()
395 if (Handle != IntPtr.Zero)
396 Interop.Elementary.elm_object_item_del_cb_set(Handle, _deleteCallback);
399 static int GetNextId()
404 class SignalData : IEquatable<SignalData>
406 public string Emission { get; set; }
407 public string Source { get; set; }
408 public Func<string, string, bool> Func { get; set; }
410 public SignalData(string emission, string source, Func<string, string, bool> func)
417 public override bool Equals(object other)
419 return Equals(other as SignalData);
422 public bool Equals(SignalData other)
428 return (Emission == other.Emission) && (Source == other.Source) && (Func == other.Func);
431 public override int GetHashCode()
433 int hashCode = Emission.GetHashCode();
434 hashCode ^= Source.GetHashCode();
435 hashCode ^= Func.GetHashCode();
440 class ItemEvasObject : EvasObject
442 IntPtr _trackHandle = IntPtr.Zero;
444 public ItemEvasObject(IntPtr parent)
446 _trackHandle = Interop.Elementary.elm_object_item_track(parent);
447 if (_trackHandle != IntPtr.Zero)
453 protected override IntPtr CreateHandle(EvasObject parent)