2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @brief EailLabel implementation.
25 #include <Elementary.h>
27 #include "eail_label.h"
28 #include "eail_utils.h"
30 static void atk_text_interface_init(AtkTextIface *iface);
33 * @brief EailLabel type definition
35 G_DEFINE_TYPE_WITH_CODE(EailLabel,
38 G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
39 atk_text_interface_init));
42 * @brief EailLabel initializer.
44 * @param obj EailLabel instance
45 * @param data initialization data
48 eail_label_initialize(AtkObject *obj, gpointer data)
50 ATK_OBJECT_CLASS(eail_label_parent_class)->initialize(obj, data);
51 obj->role = ATK_ROLE_LABEL;
55 * @brief EailLabel interface intializer.
57 * @param label EailLabel instance
60 eail_label_init(EailLabel *label)
65 * @brief Gets the state set of the accessible.
67 * The caller must unreference it when it is no longer needed.
69 * @param accessible AtkObject instance
70 * @return AtkStateSet containing the state set of the accessible
73 eail_label_ref_state_set(AtkObject *accessible)
75 AtkStateSet *state_set;
79 ATK_OBJECT_CLASS(eail_label_parent_class)->ref_state_set(accessible);
81 widget = eail_widget_get_widget(EAIL_WIDGET(accessible));
82 if (!widget) return state_set;
84 atk_state_set_add_state(state_set, ATK_STATE_MULTI_LINE);
90 * @brief Gets obj's name
92 * @param obj AtkObject instance
93 * @returns string containing obj's name or its text content if the name is not set
96 eail_label_get_name(AtkObject *obj)
101 name = ATK_OBJECT_CLASS(eail_label_parent_class)->get_name(obj);
105 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
106 if (!widget) return NULL;
108 name = (const gchar*)elm_object_text_get(widget);
109 if (!name) return NULL;
115 * @brief EailLabel class initializer.
117 * @param klass EailLabelClass instance
120 eail_label_class_init(EailLabelClass *klass)
122 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
124 atk_class->initialize = eail_label_initialize;
125 atk_class->ref_state_set = eail_label_ref_state_set;
126 atk_class->get_name = eail_label_get_name;
130 * @brief Gets text bounded by start_offset and end_offset
132 * Use g_free() to free the returned string
134 * @param text an AtkText
135 * @param start_offset start position
136 * @param end_offset end position, -1 for the end of the string
137 * @return string containing text from start_offset up to, but not including
141 eail_label_get_text(AtkText *text,
145 gchar *string = NULL;
146 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
149 string = (gchar *)elm_object_text_get(widget);
154 return eail_get_substring(string, start_offset, end_offset);
158 * @brief Gets the character at offset
160 * @param text AtkText instance
161 * @param offset character offset
162 * @return char located at the given offset
165 eail_label_get_character_at_offset(AtkText *text,
168 gunichar character = '\0';
169 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
172 character = g_utf8_get_char(
173 g_utf8_offset_to_pointer(elm_object_text_get(widget), offset));
179 * @brief Gets the length of text
181 * @param text AtkText instance
182 * @return integer representing the length of text
185 eail_label_get_character_count(AtkText *text)
190 widget = eail_widget_get_widget(EAIL_WIDGET(text));
194 str = elm_object_text_get(widget);
197 return g_utf8_strlen(str, -1);
201 * @brief Adds attribute to attribute set
203 * @param attrib_set AtkAttributeSet to add the attribute to
204 * @param attr AtkTextAttrribute to be added
205 * @param value attribute value
207 * Creates an AtkAttribute from attr and value, and adds it
210 * @returns AtkAttributeSet containing set with added attribute
213 _eail_label_add_attribute(AtkAttributeSet *attrib_set,
214 AtkTextAttribute attr,
217 AtkAttributeSet *return_set;
218 AtkAttribute *at = g_malloc (sizeof (AtkAttribute));
219 at->name = g_strdup (atk_text_attribute_get_name (attr));
221 return_set = g_slist_prepend(attrib_set, at);
226 * @brief Creates an AtkAttributeSet which consists of the default values of
227 * attributes for the text.
229 * This AtkAttributeSet should be freed by a call to
230 * atk_attribute_set_free()
232 * @param text AtkText instance
234 * @returns AtkAttributeSet containing default values of attributes
238 eail_label_get_default_attributes(AtkText *text)
240 AtkAttributeSet *at_set = NULL;
242 at_set = _eail_label_add_attribute
243 (at_set, ATK_TEXT_ATTR_WRAP_MODE,
245 (atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0)));
247 at_set = _eail_label_add_attribute
248 (at_set, ATK_TEXT_ATTR_EDITABLE,
250 (atk_text_attribute_get_value
251 (ATK_TEXT_ATTR_EDITABLE, FALSE)));
257 * @brief Creates an AtkAttributeSet which consists of the attributes
258 * explicitly set at the position offset in the text.
260 * start_offset and end_offset are set to the start and end of the range around offset
261 * where the attributes are invariant.
263 * Note that end_offset is the offset of the first character after the range.
265 * This AtkAttributeSet should be freed by a call to
266 * atk_attribute_set_free()
268 * @param text AtkText instance
269 * @param offset the offset at which to get the attributes
270 * @param [out] start_offset start offset of the range
271 * @param [out] end_offset end offset of the range
273 * @returns an AtkAttributeSet which contains the attributes explicitly set at
277 eail_label_get_run_attributes(AtkText *text,
282 AtkAttributeSet *at_set = NULL;
283 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
284 gint len = eail_label_get_character_count(ATK_TEXT(text));
286 if (!widget || offset >= len)
297 /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
298 * no additional conversion is needed*/
299 Elm_Wrap_Type wrap_type = elm_label_line_wrap_get(widget);
300 at_set = _eail_label_add_attribute
301 (at_set, ATK_TEXT_ATTR_WRAP_MODE,
303 (atk_text_attribute_get_value
304 (ATK_TEXT_ATTR_WRAP_MODE, wrap_type)));
306 at_set = _eail_label_add_attribute
307 (at_set, ATK_TEXT_ATTR_EDITABLE,
309 (atk_text_attribute_get_value
310 (ATK_TEXT_ATTR_EDITABLE, FALSE)));
316 * @brief Initializes AtkTextIface interface
318 * @param iface AtkTextIface instance
321 atk_text_interface_init(AtkTextIface *iface)
323 iface->get_character_count = eail_label_get_character_count;
324 iface->get_character_at_offset = eail_label_get_character_at_offset;
325 iface->get_text = eail_label_get_text;
326 iface->get_run_attributes = eail_label_get_run_attributes;
327 iface->get_default_attributes = eail_label_get_default_attributes;