[ElmSharp] Fix XML documentation warnings.
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / EdjeObject.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections;
19 using System.Collections.Generic;
20
21 namespace ElmSharp
22 {
23     /// <summary>
24     /// The EdjeObject is a class that evas object exist in
25     /// </summary>
26     public class EdjeObject
27     {
28         IntPtr _edjeHandle;
29         Dictionary<SignalData, Interop.Elementary.Edje_Signal_Cb> _signalDatas = new Dictionary<SignalData, Interop.Elementary.Edje_Signal_Cb>();
30
31         internal EdjeObject(IntPtr handle)
32         {
33             _edjeHandle = handle;
34         }
35
36         /// <summary>
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
39         /// </summary>
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]
44         {
45             get
46             {
47                 if (Interop.Elementary.edje_object_part_exists(_edjeHandle, part))
48                 {
49                     return new EdjeTextPartObject(_edjeHandle, part);
50                 }
51                 return null;
52             }
53         }
54
55         /// <summary>
56         /// Sends/emits an edje signal to a given edje object.
57         /// </summary>
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)
61         {
62             Interop.Elementary.edje_object_signal_emit(_edjeHandle, emission, source);
63         }
64
65         /// <summary>
66         /// Deletes the object color class.
67         /// This function deletes any values at the object level for the specified object and color class.
68         /// </summary>
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)
72         {
73             Interop.Elementary.edje_object_color_class_del(_edjeHandle, part);
74         }
75
76         /// <summary>
77         /// Sets the object color class.
78         /// </summary>
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)
95         {
96             return Interop.Elementary.edje_object_color_class_set(_edjeHandle, colorClass, red, green, blue, alpha, outlineRed, outlineGreen, outlineBlue, outlineAlpha,
97                 shadowRed, shadowGreen, shadowBlue, shadowAlpha);
98         }
99
100         /// <summary>
101         /// Gets the object color class.
102         /// </summary>
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)
119         {
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);
122         }
123
124         /// <summary>
125         /// Sets Edje text class.
126         /// </summary>
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)
132         {
133             return Interop.Elementary.edje_object_text_class_set(_edjeHandle, textClass, font, fontSize);
134         }
135
136         /// <summary>
137         /// Gets Edje text class.
138         /// </summary>
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)
144         {
145             return Interop.Elementary.edje_object_text_class_get(_edjeHandle, textClass, out font, out fontSize);
146         }
147
148         /// <summary>
149         /// Adds Action for an arriving edje signal, emitted by a given Ejde object.
150         /// </summary>
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)
155         {
156             if (emission != null && source != null && action != null)
157             {
158                 var signalData = new SignalData(emission, source, action);
159                 if (!_signalDatas.ContainsKey(signalData))
160                 {
161                     var signalCallback = new Interop.Elementary.Edje_Signal_Cb((d, o, e, s) =>
162                     {
163                         action(e, s);
164                     });
165
166                     Interop.Elementary.edje_object_signal_callback_add(_edjeHandle, emission, source, signalCallback, IntPtr.Zero);
167                     _signalDatas.Add(signalData, signalCallback);
168                 }
169             }
170         }
171
172         /// <summary>
173         /// Deletes a signal-triggered action from an object.
174         /// </summary>
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)
179         {
180             if (emission != null && source != null && action != null)
181             {
182                 var signalData = new SignalData(emission, source, action);
183
184                 Interop.Elementary.Edje_Signal_Cb signalCallback = null;
185                 _signalDatas.TryGetValue(signalData, out signalCallback);
186
187                 if (signalCallback != null)
188                 {
189                     Interop.Elementary.edje_object_signal_callback_del(_edjeHandle, emission, source, signalCallback);
190                     _signalDatas.Remove(signalData);
191                 }
192             }
193         }
194
195         class SignalData
196         {
197             public string Emission { get; set; }
198             public string Source { get; set; }
199
200             public Action<string, string> Action { get; set; }
201
202             public SignalData(string emission, string source, Action<string, string> action)
203             {
204                 Emission = emission;
205                 Source = source;
206                 Action = action;
207             }
208
209             /// <summary>
210             /// Indicates whether this instance and a specified object are equal.
211             /// </summary>
212             /// <param name="obj">The object to compare with the current instance.</param>
213             /// <returns>
214             /// true if obj and this instance are the same type and represent the same value.
215             /// otherwise, false.
216             /// </returns>
217             public override bool Equals(object obj)
218             {
219                 SignalData s = obj as SignalData;
220                 if (s == null)
221                 {
222                     return false;
223                 }
224                 return (Emission == s.Emission) && (Source == s.Source) && (Action == s.Action);
225             }
226
227             public override int GetHashCode()
228             {
229                 int hashCode = Emission.GetHashCode();
230                 hashCode ^= Source.GetHashCode();
231                 hashCode ^= Action.GetHashCode();
232                 return hashCode;
233             }
234         }
235     }
236
237     /// <summary>
238     /// An EdjeTextPartObject is a class dealing with parts of type text.
239     /// </summary>
240     public class EdjeTextPartObject
241     {
242         string _part;
243         IntPtr _edjeHandle;
244
245         internal EdjeTextPartObject(IntPtr edjeHandle, string part)
246         {
247             _edjeHandle = edjeHandle;
248             _part = part;
249         }
250
251         /// <summary>
252         /// Gets the name of the EdjeTextPartObject
253         /// </summary>
254         public string Name { get { return _part; } }
255
256         /// <summary>
257         /// Gets or sets the text for an object part.
258         /// </summary>
259         public string Text
260         {
261             get
262             {
263                 return Interop.Elementary.edje_object_part_text_get(_edjeHandle, _part);
264             }
265             set
266             {
267                 Interop.Elementary.edje_object_part_text_set(_edjeHandle, _part, value);
268             }
269         }
270
271         /// <summary>
272         /// Sets or gets the style of the object part.
273         /// </summary>
274         public string TextStyle
275         {
276             get
277             {
278                 return Interop.Elementary.edje_object_part_text_style_user_peek(_edjeHandle, _part);
279             }
280             set
281             {
282                 if (value == null)
283                 {
284                     Interop.Elementary.edje_object_part_text_style_user_pop(_edjeHandle, _part);
285                 }
286                 else
287                 {
288                     Interop.Elementary.edje_object_part_text_style_user_push(_edjeHandle, _part, value);
289                 }
290             }
291         }
292
293         /// <summary>
294         /// Gets the geometry of a given edje part, in a given edje object's group definition, relative to the object's area.
295         /// </summary>
296         public Rect Geometry
297         {
298             get
299             {
300                 int x, y, w, h;
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);
303             }
304         }
305
306         /// <summary>
307         /// Gets the native width and height.
308         /// </summary>
309         public Size TextBlockNativeSize
310         {
311             get
312             {
313                 int w;
314                 int h;
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);
318             }
319         }
320
321         /// <summary>
322         /// Gets the formatted width and height.
323         /// </summary>
324         public Size TextBlockFormattedSize
325         {
326             get
327             {
328                 int w;
329                 int h;
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);
333             }
334         }
335     }
336 }