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_image_interface_init(AtkImageIface *iface);
32 static void atk_text_interface_init(AtkTextIface *iface);
35 * @brief Define EailCheck GObject type
37 G_DEFINE_TYPE_WITH_CODE(EailCheck,
39 EAIL_TYPE_ACTION_WIDGET,
40 G_IMPLEMENT_INTERFACE(ATK_TYPE_IMAGE,
41 atk_image_interface_init)
42 G_IMPLEMENT_INTERFACE(ATK_TYPE_TEXT,
43 atk_text_interface_init));
46 * @brief Implementation of get_image_position from AtkImage interface
48 * Gets the position of the image in the form of a point specifying the images top-left corner.
50 * @param image AtkImage instance
51 * @param [out] x horizontal coordinate or -1 if value cannot be obtained
52 * @param [out] y vertical coordinate or -1 if value cannot be obtained
53 * @param coord_type specifies whether the coordinates are relative to the screen
54 * or to the component's top level window
57 eail_check_get_image_position(AtkImage *image,
60 AtkCoordType coord_type)
62 Evas_Object *check_image;
66 widget = eail_widget_get_widget(EAIL_WIDGET(image));
74 check_image = elm_object_part_content_get(widget, "icon");
77 obj = eail_factory_get_accessible(check_image);
78 atk_image_get_image_position(ATK_IMAGE(obj), x, y, coord_type);
88 * @brief Gets the width and height in pixels for the specified image
90 * The values of width and height are returned as -1 if they
91 * cannot be obtained (for instance, if the object is not onscreen).
93 * Implementation of get_image_size from AtkImage interface.
95 * @param image AtkImage instance
96 * @param [out] width image width or -1 if value cannot be obtained
97 * @param [out] height image height or -1 if value cannot be obtained
100 eail_check_get_image_size(AtkImage *image,
105 Evas_Object *check_image;
108 widget = eail_widget_get_widget(EAIL_WIDGET(image));
116 check_image = elm_object_part_content_get(widget, "icon");
119 obj = eail_factory_get_accessible(check_image);
120 atk_image_get_image_size(ATK_IMAGE(obj), width, height);
130 * @brief AtkImage interface initializer
132 * @param iface AtkImageIface instance
135 atk_image_interface_init(AtkImageIface *iface)
137 iface->get_image_position = eail_check_get_image_position;
138 iface->get_image_size = eail_check_get_image_size;
142 * @brief Gets text bounded by start_offset and end_offset
144 * Use g_free() to free the returned string.
146 * @param text AtkText instance
147 * @param start_offset start position
148 * @param end_offset end position, -1 for the end of the string
149 * @return string containing text from start_offset up to,
150 * but not including end_offset
153 eail_check_get_text(AtkText *text,
157 gchar *string = NULL;
158 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
161 string = (gchar *)elm_object_text_get(widget);
163 return eail_get_substring(string, start_offset, end_offset);
167 * @brief Gets the character at offset
169 * @param text AtkText instance
170 * @param offset character offset
171 * @return char representing the character at offset
174 eail_check_get_character_at_offset(AtkText *text,
177 gunichar character = '\0';
178 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
181 character = g_utf8_get_char(
182 g_utf8_offset_to_pointer(elm_object_text_get(widget), offset));
188 * @brief Gets the text length
190 * @param text AtkText instance
191 * @return integer representing the text length
194 eail_check_get_character_count(AtkText *text)
197 const gchar *string_text = NULL;
199 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
201 if (!widget) return count;
203 string_text = elm_object_text_get(widget);
204 if (!string_text) return count;
206 count = g_utf8_strlen(string_text, -1);
212 * @brief AtkText interface initializer
214 * Function called upon instance creation. It initializes AtkText interface
215 * implementation i.e hooks method pointers in the interface structure
216 * to the implementing class's implementation.
218 * @param iface AtkTextIface instance
221 atk_text_interface_init(AtkTextIface *iface)
223 iface->get_text = eail_check_get_text;
224 iface->get_character_at_offset = eail_check_get_character_at_offset;
225 iface->get_character_count = eail_check_get_character_count;
230 * @brief Callback for on_changed event
232 * Called to notify AtkObject about an object's state change.
234 * @param data callback data
235 * @param obj source object
236 * @param event_info event info
239 eail_check_atk_notify_change(void *data, Evas_Object *obj, void *event_info)
241 Eina_Bool state = elm_check_state_get(obj);
242 atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_CHECKED,
243 state == EINA_TRUE ? TRUE : FALSE);
248 * @brief Action handler for 'click'
250 * @param action AtkAction instance (EailCheck)
251 * @param data additional data (unused here)
253 * @returns TRUE on success, FALSE otherwise
256 eail_check_action_click_cb(AtkAction *action, void *data)
261 widget = eail_widget_get_widget(EAIL_WIDGET(action));
262 if (!widget) return FALSE;
264 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
267 state = elm_check_state_get(widget);
268 elm_check_state_set(widget, !state);
270 evas_object_smart_callback_call(widget, "changed", NULL);
271 eail_check_atk_notify_change(action, widget, NULL);
277 * @brief Initializer for actions defined in EailCheck
279 * @param action_widget EailActionWidget implementation to be filled
282 eail_check_actions_init(EailActionWidget *action_widget)
284 eail_action_widget_action_append(action_widget, "click", NULL,
285 eail_check_action_click_cb);
289 * @brief Gets a reference to the state set of the accessible
291 * The caller must unreference it when it is no longer needed.
293 * Implementation of ref_state_set from AtkObject.
295 * @param obj AtkObject instance
297 * @returns AtkStateSet representing the state set
301 eail_check_ref_state_set(AtkObject *obj)
303 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(obj));
304 AtkStateSet *state_set =
305 ATK_OBJECT_CLASS(eail_check_parent_class)->ref_state_set(obj);
309 atk_state_set_add_state(state_set, ATK_STATE_DEFUNCT);
312 if (elm_check_state_get(widget))
314 atk_state_set_add_state(state_set, ATK_STATE_CHECKED);
321 * @brief Gets the accessible name of obj
323 * @param obj AtkObject instance
325 * @returns string representing the accessible name of obj
328 eail_check_get_name(AtkObject *obj)
331 const char *atk_name;
333 g_return_val_if_fail(EAIL_IS_CHECK(obj), NULL);
335 atk_name = ATK_OBJECT_CLASS(eail_check_parent_class)->get_name(obj);
339 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
340 if (!widget) return NULL;
342 return elm_object_text_get(widget);
346 * @brief Gets the list of widget's children
348 * @param widget EailWidget instance
350 * @return Eina_list representing the list of children
351 * or NULL if widget has no children
354 eail_check_get_widget_children(EailWidget *widget)
356 Eina_List *list = NULL;
357 Evas_Object *child, *obj;
359 obj = eail_widget_get_widget(EAIL_WIDGET(widget));
362 child = elm_object_part_content_get(obj, "icon");
363 if (child && elm_object_widget_check(child))
364 list = eina_list_append(list, child);
371 * @brief EailCheck instance initialization
373 * @param check AtkObject instance
376 eail_check_init(EailCheck *check)
381 * @brief EailCheck object initialization
383 * @param obj EailCheck instance
384 * @param data user set addtional initailization data
387 eail_check_initialize(AtkObject *obj, gpointer data)
389 ATK_OBJECT_CLASS(eail_check_parent_class)->initialize(obj, data);
390 obj->role = ATK_ROLE_CHECK_BOX;
392 evas_object_smart_callback_add((Evas_Object*) data, "changed",
393 eail_check_atk_notify_change,
396 eail_check_actions_init(EAIL_ACTION_WIDGET(obj));
400 * @brief GObject type initialization function
402 * @param klass EailCheckClass instance
405 eail_check_class_init(EailCheckClass *klass)
407 AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
408 EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
410 class->initialize = eail_check_initialize;
411 class->ref_state_set = eail_check_ref_state_set;
412 class->get_name = eail_check_get_name;
413 widget_class->get_widget_children = eail_check_get_widget_children;