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;
19 using System.Collections.Generic;
24 /// The EdjeObject is a class that evas object exist in
26 public class EdjeObject
29 Dictionary<SignalData, Interop.Elementary.Edje_Signal_Cb> _signalDatas = new Dictionary<SignalData, Interop.Elementary.Edje_Signal_Cb>();
31 internal EdjeObject(IntPtr handle)
37 /// Checks whether an edje part exists in a given edje object's group definition.
38 /// This function returns if a given part exists in the edje group bound to object obj
40 /// <remarks>This call is useful, for example, when one could expect a given GUI element, depending on the theme applied to obj.</remarks>
41 /// <param name="part">The part's name to check for existence in obj's group</param>
42 /// <returns>TRUE, if the edje part exists in obj's group, otherwise FALSE</returns>
43 public EdjeTextPartObject this[string part]
47 if (Interop.Elementary.edje_object_part_exists(_edjeHandle, part))
49 return new EdjeTextPartObject(_edjeHandle, part);
56 /// Sends/emits an edje signal to a given edje object.
58 /// <param name="emission">The signal's "emission" string</param>
59 /// <param name="source">The signal's "source" string</param>
60 public void EmitSignal(string emission, string source)
62 Interop.Elementary.edje_object_signal_emit(_edjeHandle, emission, source);
66 /// Deletes the object color class.
67 /// This function deletes any values at the object level for the specified object and color class.
69 /// <remarks>Deleting the color class defined in the theme file.</remarks>
70 /// <param name="part">The color class to be deleted</param>
71 public void DeleteColorClass(string part)
73 Interop.Elementary.edje_object_color_class_del(_edjeHandle, part);
77 /// Sets the object color class.
79 /// <param name="colorClass">The color class name.</param>
80 /// <param name="red">The object Red value.</param>
81 /// <param name="green">The object Green value.</param>
82 /// <param name="blue">The object Blue value.</param>
83 /// <param name="alpha">The object Alpha value.</param>
84 /// <param name="outlineRed">The outline Red value.</param>
85 /// <param name="outlineGreen">The outline Green value.</param>
86 /// <param name="outlineBlue">The outline Blue value.</param>
87 /// <param name="outlineAlpha">The outline Alpha value.</param>
88 /// <param name="shadowRed">The shadow Red value.</param>
89 /// <param name="shadowGreen">The shadow Green value.</param>
90 /// <param name="shadowBlue">The shadow Blue value.</param>
91 /// <param name="shadowAlpha">The shadow Alpha value.</param>
92 /// <returns>True if succeed, otherwise False</returns>
93 public bool SetColorClass(string colorClass, int red, int green, int blue, int alpha, int outlineRed, int outlineGreen, int outlineBlue, int outlineAlpha,
94 int shadowRed, int shadowGreen, int shadowBlue, int shadowAlpha)
96 return Interop.Elementary.edje_object_color_class_set(_edjeHandle, colorClass, red, green, blue, alpha, outlineRed, outlineGreen, outlineBlue, outlineAlpha,
97 shadowRed, shadowGreen, shadowBlue, shadowAlpha);
101 /// Gets the object color class.
103 /// <param name="colorClass">The color class name.</param>
104 /// <param name="red">The object Red value.</param>
105 /// <param name="green">The object Green value.</param>
106 /// <param name="blue">The object Blue value.</param>
107 /// <param name="alpha">The object Alpha value.</param>
108 /// <param name="outlineRed">The outline Red value.</param>
109 /// <param name="outlineGreen">The outline Green value.</param>
110 /// <param name="outlineBlue">The outline Blue value.</param>
111 /// <param name="outlineAlpha">The outline Alpha value.</param>
112 /// <param name="shadowRed">The shadow Red value.</param>
113 /// <param name="shadowGreen">The shadow Green value.</param>
114 /// <param name="shadowBlue">The shadow Blue value.</param>
115 /// <param name="shadowAlpha">The shadow Alpha value.</param>
116 /// <returns>True if succeed, otherwise False</returns>
117 public bool GetColorClass(string colorClass, out int red, out int green, out int blue, out int alpha, out int outlineRed, out int outlineGreen, out int outlineBlue, out int outlineAlpha,
118 out int shadowRed, out int shadowGreen, out int shadowBlue, out int shadowAlpha)
120 return Interop.Elementary.edje_object_color_class_get(_edjeHandle, colorClass, out red, out green, out blue, out alpha, out outlineRed, out outlineGreen, out outlineBlue, out outlineAlpha,
121 out shadowRed, out shadowGreen, out shadowBlue, out shadowAlpha);
125 /// Sets Edje text class.
127 /// <param name="textClass">The text class name.</param>
128 /// <param name="font"> Font name.</param>
129 /// <param name="fontSize">Font size.</param>
130 /// <returns>True if succeed, otherwise False</returns>
131 public bool SetTextClass(string textClass, string font, int fontSize)
133 return Interop.Elementary.edje_object_text_class_set(_edjeHandle, textClass, font, fontSize);
137 /// Gets Edje text class.
139 /// <param name="textClass">The text class name.</param>
140 /// <param name="font">Font name.</param>
141 /// <param name="fontSize">Font size.</param>
142 /// <returns>True if succeed, otherwise False</returns>
143 public bool GetTextClass(string textClass, out string font, out int fontSize)
145 return Interop.Elementary.edje_object_text_class_get(_edjeHandle, textClass, out font, out fontSize);
149 /// Adds Action for an arriving edje signal, emitted by a given Ejde object.
151 /// <param name="emission">The signal's "emission" string</param>
152 /// <param name="source">The signal's "source" string</param>
153 /// <param name="action">The action to be executed when the signal is emitted</param>
154 public void AddSignalAction(string emission, string source, Action<string, string> action)
156 if (emission != null && source != null && action != null)
158 var signalData = new SignalData(emission, source, action);
159 if (!_signalDatas.ContainsKey(signalData))
161 var signalCallback = new Interop.Elementary.Edje_Signal_Cb((d, o, e, s) =>
166 Interop.Elementary.edje_object_signal_callback_add(_edjeHandle, emission, source, signalCallback, IntPtr.Zero);
167 _signalDatas.Add(signalData, signalCallback);
173 /// Deletes a signal-triggered action from an object.
175 /// <param name="emission">The signal's "emission" string</param>
176 /// <param name="source">The signal's "source" string</param>
177 /// <param name="action">The action to be executed when the signal is emitted</param>
178 public void DeleteSignalAction(string emission, string source, Action<string, string> action)
180 if (emission != null && source != null && action != null)
182 var signalData = new SignalData(emission, source, action);
184 Interop.Elementary.Edje_Signal_Cb signalCallback = null;
185 _signalDatas.TryGetValue(signalData, out signalCallback);
187 if (signalCallback != null)
189 Interop.Elementary.edje_object_signal_callback_del(_edjeHandle, emission, source, signalCallback);
190 _signalDatas.Remove(signalData);
197 public string Emission { get; set; }
198 public string Source { get; set; }
200 public Action<string, string> Action { get; set; }
202 public SignalData(string emission, string source, Action<string, string> action)
210 /// Indicates whether this instance and a specified object are equal.
212 /// <param name="obj">The object to compare with the current instance.</param>
214 /// true if obj and this instance are the same type and represent the same value.
215 /// otherwise, false.
217 public override bool Equals(object obj)
219 SignalData s = obj as SignalData;
224 return (Emission == s.Emission) && (Source == s.Source) && (Action == s.Action);
227 public override int GetHashCode()
229 int hashCode = Emission.GetHashCode();
230 hashCode ^= Source.GetHashCode();
231 hashCode ^= Action.GetHashCode();
238 /// An EdjeTextPartObject is a class dealing with parts of type text.
240 public class EdjeTextPartObject
245 internal EdjeTextPartObject(IntPtr edjeHandle, string part)
247 _edjeHandle = edjeHandle;
252 /// Gets the name of the EdjeTextPartObject
254 public string Name { get { return _part; } }
257 /// Gets or sets the text for an object part.
263 return Interop.Elementary.edje_object_part_text_get(_edjeHandle, _part);
267 Interop.Elementary.edje_object_part_text_set(_edjeHandle, _part, value);
272 /// Sets or gets the style of the object part.
274 public string TextStyle
278 return Interop.Elementary.edje_object_part_text_style_user_peek(_edjeHandle, _part);
284 Interop.Elementary.edje_object_part_text_style_user_pop(_edjeHandle, _part);
288 Interop.Elementary.edje_object_part_text_style_user_push(_edjeHandle, _part, value);
294 /// Gets the geometry of a given edje part, in a given edje object's group definition, relative to the object's area.
301 Interop.Elementary.edje_object_part_geometry_get(_edjeHandle, _part, out x, out y, out w, out h);
302 return new Rect(x, y, w, h);
307 /// Gets the native width and height.
309 public Size TextBlockNativeSize
315 IntPtr part = Interop.Elementary.edje_object_part_object_get(_edjeHandle, _part);
316 Interop.Evas.evas_object_textblock_size_native_get(part, out w, out h);
317 return new Size(w, h);
322 /// Gets the formatted width and height.
324 public Size TextBlockFormattedSize
330 IntPtr part = Interop.Elementary.edje_object_part_object_get(_edjeHandle, _part);
331 Interop.Evas.evas_object_textblock_size_formatted_get(part, out w, out h);
332 return new Size(w, h);