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.
21 * @file eail_radio_button.c
22 * @brief EailRadioButton implementation
26 #include <Elementary.h>
28 #include "eail_radio_button.h"
29 #include "eail_priv.h"
31 static void atk_action_interface_init(AtkActionIface *iface);
34 * @brief Definition of EailRadioButton type
36 G_DEFINE_TYPE_WITH_CODE(EailRadioButton,
39 G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
40 atk_action_interface_init));
43 * @brief Callback for 'on_change' event
45 * Called to notify AtkObject about state change.
47 * @param data user data passed to callback
48 * @param obj source object
49 * @param event_info event info
52 _on_change(void *data, Evas_Object *obj, void *event_info)
54 EailRadioButton *button = EAIL_RADIO_BUTTON(data);
55 button->state = elm_radio_state_value_get(obj) ? EINA_TRUE : EINA_FALSE;
57 atk_object_notify_state_change(ATK_OBJECT(button), ATK_STATE_CHECKED,
58 button->state == EINA_TRUE ? TRUE : FALSE);
62 * @brief Gets a reference to the state set of the accessible
64 * The caller must unreference it when it is no longer needed.
66 * Implementation of ref_state_set from AtkObject interface.
68 * @param obj AtkObject instance
70 * @returns AtkStateSet representing the state set of the accessible
73 eail_radio_button_ref_state_set(AtkObject *obj)
75 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(obj));
76 AtkStateSet *state_set =
77 ATK_OBJECT_CLASS(eail_radio_button_parent_class)->ref_state_set(obj);
80 atk_state_set_add_state(state_set, ATK_STATE_DEFUNCT);
85 int selected_value = elm_radio_value_get(widget);
86 int widget_value = elm_radio_state_value_get(widget);
88 if (selected_value == widget_value)
90 atk_state_set_add_state(state_set, ATK_STATE_CHECKED);
97 * @brief Initialize EailRadionButton as AtkObject
99 * @param obj AtkObject instance
100 * @param data user data passed to initialization
103 eail_radio_button_initialize(AtkObject *obj, gpointer data)
105 ATK_OBJECT_CLASS(eail_radio_button_parent_class)->initialize(obj, data);
106 Evas_Object *widget = (Evas_Object *) data;
107 EailRadioButton *radio = EAIL_RADIO_BUTTON(obj);
108 int value = elm_radio_state_value_get(widget);
109 int selected = elm_radio_value_get(widget);
110 if (selected == value)
112 radio->state = EINA_TRUE;
114 evas_object_smart_callback_add(widget, "changed", _on_change, obj);
116 obj->role = ATK_ROLE_RADIO_BUTTON;
120 * @brief Initialize EailRadioButton object
122 * @param radio_button EailRadioButton instance
125 eail_radio_button_init(EailRadioButton *radio_button)
127 radio_button->click_description = NULL;
128 radio_button->state = EINA_FALSE;
132 * @brief EailRadioButton finalize function
134 * @param object GObject instance
137 eail_radio_button_finalize(GObject *object)
139 EailRadioButton *button = EAIL_RADIO_BUTTON(object);
140 if (button->click_description) free(button->click_description);
141 G_OBJECT_CLASS(eail_radio_button_parent_class)->finalize(object);
145 * @brief Object class initialization
147 * @param klass EailRadioButtonClass instance
150 eail_radio_button_class_init(EailRadioButtonClass *klass)
152 AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
153 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
154 class->initialize = eail_radio_button_initialize;
155 class->ref_state_set = eail_radio_button_ref_state_set;
156 gobject_class->finalize = eail_radio_button_finalize;
160 * @brief Gets the number of accessible actions available on the object
162 * If there are more than one, the first one is considered
163 * the "default" action of the object.
165 * Implementation of get_n_actions from AtkAction interface.
167 * @param action AtkAction instance
169 * @returns integer representing the number of available actions
172 eail_radio_button_n_action_get(AtkAction *action)
178 * @brief Gets the name of the specified action of the object
180 * Implementation of get_action_name from AtkAction interface.
182 * @param action AtkAction instance
183 * @param i index of action
185 * @returns string representing the name of the specified action
188 eail_radio_button_action_name_get(AtkAction *action, int i)
190 const char *action_name;
194 /*click - This is called whenever the user changes the state of one of*/
195 /*the radio objects within the group of radio objects that work together. */
196 action_name = "click";
206 * @brief Sets a description of the specified action of the object
208 * Implementation of set_description from AtkAction.
210 * @param action AtkAction instance
211 * @param i action index
212 * @param description action's description to set
214 * @returns TRUE on success, FALSE otherwise
217 eail_radio_button_description_set(AtkAction *action, gint i, const char *description)
219 if (i != 0) return FALSE;
221 EailRadioButton *button = EAIL_RADIO_BUTTON(action);
222 if (button->click_description) free(button->click_description);
223 button->click_description = g_strdup(description);
228 * @brief Gets the description of the specified action of the object
230 * Implementation of get_description from AtkAction interface.
232 * @param action AtkAction instance
233 * @param i index of action
235 * @returns string representing the description of the specified action
238 eail_radio_button_description_get(AtkAction *action, gint i)
240 if (i != 0) return NULL;
242 EailRadioButton *button = EAIL_RADIO_BUTTON(action);
243 return button->click_description;
247 * @brief Performs the specified action on the object
249 * Implementation of do_action from AtkAction interface.
251 * @param action AtkAction instance
252 * @param i action index
254 * @returns TRUE on success, FALSE otherwise
257 eail_radio_button_do_action(AtkAction *action, int i)
259 Evas_Object *obj = eail_widget_get_widget(EAIL_WIDGET(action));
260 EailRadioButton *button = EAIL_RADIO_BUTTON(action);
261 if (button->state == EINA_TRUE) return FALSE;
262 if ((elm_object_disabled_get(obj)) || (!evas_object_visible_get(obj)))
264 const char *action_name = atk_action_get_name(action, i);
265 if (action_name == NULL) return FALSE;
266 int state_value = elm_radio_state_value_get(obj);
267 elm_radio_value_set(obj, state_value);
268 button->state = EINA_TRUE;
270 if (!g_strcmp0(action_name, "click"))
271 evas_object_smart_callback_call(obj, "changed", NULL);
277 * @brief AtkAction interface initialization
279 * @param iface AtkActionIface instance
282 atk_action_interface_init(AtkActionIface *iface)
284 g_return_if_fail(iface != NULL);
286 iface->do_action = eail_radio_button_do_action;
287 iface->get_n_actions = eail_radio_button_n_action_get;
288 iface->get_description = eail_radio_button_description_get;
289 iface->get_name = eail_radio_button_action_name_get;
290 iface->set_description = eail_radio_button_description_set;