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 EailButton implementation
25 #include <Elementary.h>
26 #include "eail_button.h"
27 #include "eail_factory.h"
28 #include "eail_priv.h"
29 #include "eail_utils.h"
31 static void atk_text_interface_init(AtkTextIface *iface);
34 * @brief Define EailButton GObject type
36 G_DEFINE_TYPE_WITH_CODE(EailButton,
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
51 * @return string containing the text from start_offset up to,
52 * but not including end_offset
55 eail_button_get_text(AtkText *text,
60 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
63 string = (gchar *)elm_object_text_get(widget);
65 return eail_get_substring(string, start_offset, end_offset);
69 * @brief Gets the character at offset
71 * @param text AtkText instance
72 * @param offset character offset
73 * @returns char representing the character at offset
76 eail_button_get_character_at_offset(AtkText *text,
79 gunichar character = '\0';
80 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
83 character = g_utf8_get_char(
84 g_utf8_offset_to_pointer(elm_object_text_get(widget), offset));
90 * @brief Gets the text length
92 * @param text AtkText instance
93 * @returns integer representing the text length
96 eail_button_get_character_count(AtkText *text)
99 const gchar *string_text = NULL;
101 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
103 if (!widget) return count;
105 string_text = elm_object_text_get(widget);
106 if (!string_text) return count;
108 count = g_utf8_strlen(string_text, -1);
114 * @brief AtkText interface initializer
116 * @param iface AtkTextIface instance
119 atk_text_interface_init(AtkTextIface *iface)
121 iface->get_text = eail_button_get_text;
122 iface->get_character_at_offset = eail_button_get_character_at_offset;
123 iface->get_character_count = eail_button_get_character_count;
127 * @brief Notifies ATK about button press event
129 * @param data data passed to event
130 * @param obj Evas_Object instance that received event
131 * @param event_info additional event info
134 eail_button_atk_notify_press(void *data, Evas_Object *obj, void *event_info)
136 atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_PRESSED, TRUE);
140 * @brief Notifies ATK about button release event
142 * @param data passed to callback
143 * @param obj Evas_Object instance that raised event
144 * @param event_info additional event info
147 eail_button_atk_notify_release(void *data, Evas_Object *obj, void *event_info)
149 atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_PRESSED, FALSE);
150 eail_notify_child_focus_changes();
154 * @brief 'click' action callback
156 * @param action AtkAction instance
157 * @param data user data passed to callback
159 * @returns TRUE if action was successfull, FALSE otherwise
162 eail_button_action_click_cb(AtkAction *action, void *data)
166 widget = eail_widget_get_widget(EAIL_WIDGET(action));
167 if (!widget) return FALSE;
169 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
172 evas_object_smart_callback_call(widget, "clicked", NULL);
173 eail_button_atk_notify_press(action, NULL, NULL);
179 * @brief 'press' action callback
181 * @param action AtkAction instance
182 * @param data user data passed to callback
184 * @returns TRUE if action was successfull, FALSE otherwise
187 eail_button_action_press_cb(AtkAction *action, void *data)
191 widget = eail_widget_get_widget(EAIL_WIDGET(action));
192 if (!widget) return FALSE;
194 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
197 evas_object_smart_callback_call(widget, "pressed", NULL);
198 eail_button_atk_notify_press(action, NULL, NULL);
204 * @brief 'release' action callback
206 * @param action AtkAction instance
207 * @param data user data passed to callback
209 * @returns TRUE if action was successfull, FALSE otherwise
212 eail_button_action_release_cb(AtkAction *action, void *data)
216 widget = eail_widget_get_widget(EAIL_WIDGET(action));
217 if (!widget) return FALSE;
219 if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
222 evas_object_smart_callback_call(widget, "unpressed", NULL);
223 eail_button_atk_notify_release(action, NULL, NULL);
229 * @brief Sets EailButton actions
231 * @param action_widget EailActionWidget instance
234 eail_button_actions_init(EailActionWidget *action_widget)
236 eail_action_widget_action_append(action_widget,
238 eail_button_action_click_cb);
239 eail_action_widget_action_append(action_widget,
241 eail_button_action_press_cb);
242 eail_action_widget_action_append(action_widget,
244 eail_button_action_release_cb);
248 * @brief EailButton object initialization
250 * @param obj AtkObject instance
251 * @param data user set additional initialization data
254 eail_button_initialize(AtkObject *obj, gpointer data)
256 ATK_OBJECT_CLASS(eail_button_parent_class)->initialize(obj, data);
257 obj->role = ATK_ROLE_PUSH_BUTTON;
259 evas_object_smart_callback_add((Evas_Object*) data, "pressed",
260 eail_button_atk_notify_press, obj);
261 evas_object_smart_callback_add((Evas_Object*) data, "unpressed",
262 eail_button_atk_notify_release, obj);
264 eail_button_actions_init(EAIL_ACTION_WIDGET(obj));
268 * @brief Gets the list of widget's children
270 * @param widget EailWidget instance
272 * @returns Eina_list representing the list of children
273 * or NULL if widget has no children
276 eail_button_get_widget_children(EailWidget *widget)
278 Eina_List *list = NULL;
279 Evas_Object *child, *obj;
281 obj = eail_widget_get_widget(EAIL_WIDGET(widget));
284 child = elm_object_part_content_get(obj, "icon");
285 if (child && elm_object_widget_check(child))
286 list = eina_list_append(list, child);
293 * @brief Gets the accessible name of obj
295 * @param obj AtkObject instance
297 * @returns string representing the accessible name of obj
300 eail_button_get_name(AtkObject *obj)
303 const char *atk_name;
305 g_return_val_if_fail(EAIL_IS_BUTTON(obj), NULL);
307 atk_name = ATK_OBJECT_CLASS(eail_button_parent_class)->get_name(obj);
311 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
312 if (!widget) return NULL;
314 return elm_object_text_get(widget);
318 * @brief GObject type initialization function
320 * @param klass EailButtonClass instance
323 eail_button_class_init(EailButtonClass *klass)
325 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
326 EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
328 atk_class->initialize = eail_button_initialize;
329 atk_class->get_name = eail_button_get_name;
330 widget_class->get_widget_children = eail_button_get_widget_children;
334 * @brief EailButton instance initializer
336 * @param button EailButton instance
339 eail_button_init(EailButton *button)