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 EailText implementation
25 #include <Elementary.h>
27 #include "eail_text.h"
28 #include "eail_factory.h"
29 #include "eail_utils.h"
32 * Implementation of the *AtkObject* interface
35 static void atk_text_interface_init(AtkTextIface *iface);
38 * @brief EailText type definition
40 G_DEFINE_TYPE_WITH_CODE(EailText,
43 G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
44 atk_text_interface_init));
47 * @brief EailText initializer
49 * @param obj AtkObject instance
50 * @param data initialization data
53 eail_text_initialize(AtkObject *obj, gpointer data)
55 ATK_OBJECT_CLASS(eail_text_parent_class)->initialize(obj, data);
57 obj->role = ATK_ROLE_TEXT;
61 * @brief Gets the accessible name of obj
63 * Returns obj accessible name if assigned, obj text content otherwise
65 * @param obj AtkObject instance
66 * @returns string representing the accessible name of obj if assigned,
67 * obj text content otherwise
70 eail_text_get_name(AtkObject *obj)
75 name = ATK_OBJECT_CLASS(eail_text_parent_class)->get_name(obj);
79 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
81 name = (const gchar*)elm_object_text_get(widget);
87 * @brief EailText instance initializer
89 * @param text EailText instance
92 eail_text_init(EailText *text)
97 * @brief EailText class initializer
99 * @param klass EailTextClass instance
102 eail_text_class_init(EailTextClass *klass)
104 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
106 atk_class->initialize = eail_text_initialize;
107 atk_class->get_name = eail_text_get_name;
111 * Implementation of the *AtkText* interface
115 * @brief Gets text bounded by start_offset and end_offset
117 * Use g_free() to free the returned string
119 * @param text AtkText instance
120 * @param start_offset start position
121 * @param end_offset end position, -1 for the end of the string
122 * @return string containing text from start_offset up to, but not including
126 eail_text_get_text(AtkText *text,
130 gchar *string = NULL;
131 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
134 string = (gchar *)elm_object_text_get(widget);
136 return eail_get_substring(string, start_offset, end_offset);
140 * @brief Gets the character at offset
142 * @param text AtkText instance
143 * @param offset character offset
144 * @return char representing the character at offset
147 eail_text_get_character_at_offset(AtkText *text,
150 gunichar character = '\0';
151 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
154 character = g_utf8_get_char(
155 g_utf8_offset_to_pointer(elm_object_text_get(widget), offset));
161 * @brief Gets the text's length
163 * @param text AtkText instance
164 * @return integer representing the text length
167 eail_text_get_character_count(AtkText *text)
170 const gchar *string_text = NULL;
172 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
174 if (!widget) return count;
176 string_text = elm_object_text_get(widget);
177 if (!string_text) return count;
179 count = g_utf8_strlen(string_text, -1);
185 * @brief Creates an AtkAttributeSet which consists of the default values of
186 * attributes for the text.
188 * This AtkAttributeSet should be freed by a call to
189 * atk_attribute_set_free()
191 * @param text AtkText instance
193 * @returns AtkAttributeSet containing default values of attributes
196 static AtkAttributeSet *
197 eail_text_get_default_attributes(AtkText *text)
199 AtkAttributeSet *at_set = NULL;
201 at_set = eail_utils_text_add_attribute
202 (at_set, ATK_TEXT_ATTR_WRAP_MODE,
203 atk_text_attribute_get_value(ATK_TEXT_ATTR_WRAP_MODE, 0));
205 at_set = eail_utils_text_add_attribute
206 (at_set, ATK_TEXT_ATTR_EDITABLE,
207 atk_text_attribute_get_value
208 (ATK_TEXT_ATTR_EDITABLE, FALSE));
214 * @brief Creates an AtkAttributeSet which consists of the attributes
215 * explicitly set at the position offset in the text.
217 * start_offset and end_offset are set to the start and end of the range around offset
218 * where the attributes are invariant.
220 * Note that end_offset is the offset of the first character after the range.
222 * This AtkAttributeSet should be freed by a call to
223 * atk_attribute_set_free()
225 * @param text AtkText instance
226 * @param offset the offset at which to get the attributes
227 * @param [out] start_offset start offset of the range
228 * @param [out] end_offset end offset of the range
230 * @returns an AtkAttributeSet which contains the attributes explicitly set at
233 static AtkAttributeSet *
234 eail_text_get_run_attributes(AtkText *text,
239 AtkAttributeSet *at_set = NULL;
240 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
241 gint len = eail_text_get_character_count(ATK_TEXT(text));
243 if (!widget || offset >= len)
254 /* NOTE: Elm_Wrap_Type value is in 100% compatible with ATK wrap modes, so
255 * no additional conversion is needed*/
256 Elm_Wrap_Type wrap_type = ELM_WRAP_NONE;
257 at_set = eail_utils_text_add_attribute
258 (at_set, ATK_TEXT_ATTR_WRAP_MODE,
259 atk_text_attribute_get_value
260 (ATK_TEXT_ATTR_WRAP_MODE, wrap_type));
263 at_set = eail_utils_text_add_attribute
264 (at_set, ATK_TEXT_ATTR_EDITABLE,
265 atk_text_attribute_get_value
266 (ATK_TEXT_ATTR_EDITABLE, FALSE));
271 * @brief AtkText interface initializer
273 * @param iface AtkTextIface instance
276 atk_text_interface_init(AtkTextIface *iface)
278 iface->get_text = eail_text_get_text;
279 iface->get_character_at_offset = eail_text_get_character_at_offset;
280 iface->get_character_count = eail_text_get_character_count;
281 iface->get_default_attributes = eail_text_get_default_attributes;
282 iface->get_run_attributes = eail_text_get_run_attributes;