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 EailCheck implementation
25 #include <Elementary.h>
27 #include "eail_check.h"
28 #include "eail_utils.h"
29 #include "eail_factory.h"
31 static void atk_text_interface_init(AtkTextIface *iface);
34 * @brief Define EailCheck GObject type
36 G_DEFINE_TYPE_WITH_CODE(EailCheck,
38 EAIL_TYPE_ACTION_WIDGET,
39 G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
40 atk_text_interface_init));
43 * @brief Gets text bounded by start_offset and end_offset
45 * Use g_free() to free the returned string.
47 * @param text AtkText instance
48 * @param start_offset start position
49 * @param end_offset end position, -1 for the end of the string
50 * @return string containing text from start_offset up to,
51 * but not including end_offset
54 eail_check_get_text(AtkText *text,
59 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
62 string = (gchar *)elm_object_text_get(widget);
64 return eail_get_substring(string, start_offset, end_offset);
68 * @brief Gets the character at offset
70 * @param text AtkText instance
71 * @param offset character offset
72 * @return char representing the character at offset
75 eail_check_get_character_at_offset(AtkText *text,
78 gunichar character = '\0';
79 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
82 character = g_utf8_get_char(
83 g_utf8_offset_to_pointer(elm_object_text_get(widget), offset));
89 * @brief Gets the text length
91 * @param text AtkText instance
92 * @return integer representing the text length
95 eail_check_get_character_count(AtkText *text)
98 const gchar *string_text = NULL;
100 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
102 if (!widget) return count;
104 string_text = elm_object_text_get(widget);
105 if (!string_text) return count;
107 count = g_utf8_strlen(string_text, -1);
113 * @brief AtkText interface initializer
115 * Function called upon instance creation. It initializes AtkText interface
116 * implementation i.e hooks method pointers in the interface structure
117 * to the implementing class's implementation.
119 * @param iface AtkTextIface instance
122 atk_text_interface_init(AtkTextIface *iface)
124 iface->get_text = eail_check_get_text;
125 iface->get_character_at_offset = eail_check_get_character_at_offset;
126 iface->get_character_count = eail_check_get_character_count;
131 * @brief Callback for on_changed event
133 * Called to notify AtkObject about an object's state change.
135 * @param data callback data
136 * @param obj source object
137 * @param event_info event info
140 eail_check_atk_notify_change(void *data, Evas_Object *obj, void *event_info)
142 Eina_Bool state = elm_check_state_get(obj);
143 atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_CHECKED,
144 state == EINA_TRUE ? TRUE : FALSE);
149 * @brief Action handler for 'click'
151 * @param action AtkAction instance (EailCheck)
152 * @param data additional data (unused here)
154 * @returns TRUE on success, FALSE otherwise
157 eail_check_action_click_cb(AtkAction *action, void *data)
162 widget = eail_widget_get_widget(EAIL_WIDGET(action));
163 if (!widget) return FALSE;
165 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
168 state = elm_check_state_get(widget);
169 elm_check_state_set(widget, !state);
171 evas_object_smart_callback_call(widget, "changed", NULL);
172 eail_check_atk_notify_change(action, widget, NULL);
178 * @brief Initializer for actions defined in EailCheck
180 * @param action_widget EailActionWidget implementation to be filled
183 eail_check_actions_init(EailActionWidget *action_widget)
185 eail_action_widget_action_append(action_widget, "click", NULL,
186 eail_check_action_click_cb);
190 * @brief Gets a reference to the state set of the accessible
192 * The caller must unreference it when it is no longer needed.
194 * Implementation of ref_state_set from AtkObject.
196 * @param obj AtkObject instance
198 * @returns AtkStateSet representing the state set
202 eail_check_ref_state_set(AtkObject *obj)
204 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(obj));
205 AtkStateSet *state_set =
206 ATK_OBJECT_CLASS(eail_check_parent_class)->ref_state_set(obj);
210 atk_state_set_add_state(state_set, ATK_STATE_DEFUNCT);
213 if (elm_check_state_get(widget))
215 atk_state_set_add_state(state_set, ATK_STATE_CHECKED);
222 * @brief Gets the accessible name of obj
224 * @param obj AtkObject instance
226 * @returns string representing the accessible name of obj
229 eail_check_get_name(AtkObject *obj)
232 const char *atk_name;
234 g_return_val_if_fail(EAIL_IS_CHECK(obj), NULL);
236 atk_name = ATK_OBJECT_CLASS(eail_check_parent_class)->get_name(obj);
240 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
241 if (!widget) return NULL;
243 return elm_object_text_get(widget);
247 * @brief Gets the list of widget's children
249 * @param widget EailWidget instance
251 * @return Eina_list representing the list of children
252 * or NULL if widget has no children
255 eail_check_get_widget_children(EailWidget *widget)
257 Eina_List *list = NULL;
258 Evas_Object *child, *obj;
260 obj = eail_widget_get_widget(EAIL_WIDGET(widget));
263 child = elm_object_part_content_get(obj, "icon");
264 if (child && elm_object_widget_check(child))
265 list = eina_list_append(list, child);
272 * @brief EailCheck instance initialization
274 * @param check AtkObject instance
277 eail_check_init(EailCheck *check)
282 * @brief EailCheck object initialization
284 * @param obj EailCheck instance
285 * @param data user set addtional initailization data
288 eail_check_initialize(AtkObject *obj, gpointer data)
290 ATK_OBJECT_CLASS(eail_check_parent_class)->initialize(obj, data);
291 obj->role = ATK_ROLE_CHECK_BOX;
293 evas_object_smart_callback_add((Evas_Object*) data, "changed",
294 eail_check_atk_notify_change,
297 eail_check_actions_init(EAIL_ACTION_WIDGET(obj));
301 * @brief GObject type initialization function
303 * @param klass EailCheckClass instance
306 eail_check_class_init(EailCheckClass *klass)
308 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
309 EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
311 atk_class->initialize = eail_check_initialize;
312 atk_class->ref_state_set = eail_check_ref_state_set;
313 atk_class->get_name = eail_check_get_name;
314 widget_class->get_widget_children = eail_check_get_widget_children;