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_segment_control.c
22 * @brief EailSegmentControl implementation
26 #include <Elementary.h>
28 #include "eail_segment_control.h"
29 #include "eail_factory.h"
30 #include "eail_item_parent.h"
32 static void atk_selection_interface_init(AtkSelectionIface *iface);
33 static void eail_item_parent_interface_init(EailItemParentIface *iface);
36 * @brief Definition of EailSegmentControl as GObject
38 * EailSegmentControl is extended EAIL_TYPE_WIDGET with ATK_TYPE_SELECTION and
39 * EAIL_TYPE_ITEM_PARENT interfaces implemented
41 G_DEFINE_TYPE_WITH_CODE(EailSegmentControl, eail_segment_control, EAIL_TYPE_WIDGET,
42 G_IMPLEMENT_INTERFACE(ATK_TYPE_SELECTION,
43 atk_selection_interface_init)
44 G_IMPLEMENT_INTERFACE(EAIL_TYPE_ITEM_PARENT,
45 eail_item_parent_interface_init));
48 * @brief Initializer for AtkObjectClass
50 * @param obj AtkObject instance
51 * @param data additional initialization data
54 eail_segment_control_initialize(AtkObject *obj, gpointer data)
56 ATK_OBJECT_CLASS(eail_segment_control_parent_class)->initialize(obj, data);
57 obj->role = ATK_ROLE_LIST;
61 * @brief Initializer for GObject class
63 * @param segment_control EailSegmentControl instance
66 eail_segment_control_init(EailSegmentControl *segment_control)
71 * @brief Gets the number of accessible children of the accessible
73 * Implementation of AtkObject->get_n_children callback.
75 * @param obj AtkObject instance
77 * @returns integer representing the number of accessible children of
81 eail_segment_control_get_n_children(AtkObject *obj)
85 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(obj));
86 n_items = elm_segment_control_item_count_get(widget);
92 * @brief Gets a reference to the specified accessible child of the object.
94 * The accessible children are 0-based so the first accessible child is
95 * at index 0, the second at index 1 and so on.
97 * Implementation AtkObject->ref_child callback.
99 * @param obj AtkObject instance
100 * @param i child index
102 * @returns AtkObject representing the specified accessible child of the
106 eail_segment_control_ref_child(AtkObject *obj, gint i)
108 AtkObject *child = NULL;
109 Evas_Object *widget = NULL;
111 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
112 if (!widget) return NULL;
114 if (elm_segment_control_item_count_get(widget) > i)
116 child = eail_factory_get_item_atk_obj
117 (elm_segment_control_item_get(widget, i), ATK_ROLE_LIST_ITEM, obj);
126 * @brief Destructor for Segment Control object
127 * @param object GObject instance
130 eail_segment_control_finalize(GObject *object)
132 G_OBJECT_CLASS(eail_segment_control_parent_class)->finalize(object);
136 * @brief Initializer for GObject EailSegmentControl class
138 * Defines callbacks for base AtkObject.
140 * @param klass EailSegmentControlClass instance
143 eail_segment_control_class_init(EailSegmentControlClass *klass)
145 AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
146 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
147 class->initialize = eail_segment_control_initialize;
148 class->get_n_children = eail_segment_control_get_n_children;
149 class->ref_child = eail_segment_control_ref_child;
150 gobject_class->finalize = eail_segment_control_finalize;
154 * @brief Adds the specified accessible child of the object to the object's selection
156 * Implementation of AtkSelection->add_selection callback.
158 * @param selection AtkSelection instance
159 * @param i index of object
161 * @returns TRUE on success, FALSE otherwise
164 eail_selection_add_selection(AtkSelection *selection,
167 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
168 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
169 Elm_Object_Item *item = elm_segment_control_item_get(object, i);
170 if (!item) return FALSE;
171 elm_segment_control_item_selected_set(item, EINA_TRUE);
176 * @brief Clears the selection in the object so that no children in the object are
179 * Implementation of AtkSelection->clear_selection callback.
181 * @param selection AtkSelection instance
183 * @returns TRUE on success, FALSE otherwise
186 eail_selection_clear_selection(AtkSelection *selection)
188 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
189 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
190 Elm_Object_Item *item = elm_segment_control_item_selected_get(object);
191 elm_segment_control_item_selected_set(item, EINA_FALSE);
196 * @brief Gets a reference to the accessible object representing the specified selected
197 * child of the object.
199 * Note: callers should not rely on NULL or on a zero value
200 * for indication of whether AtkSelectionIface is implemented, they should use
201 * type checking/interface checking macros or the atk_get_accessible_value()
202 * convenience method.
204 * Implementation of AtkSelection->ref_selection callback.
206 * @param selection AtkSelection instance
207 * @param i index of object
209 * @returns AtkObject representing the selected accessible or NULL if
210 * selection does not implement this interface
213 eail_selection_ref_selection(AtkSelection *selection,
216 g_return_val_if_fail(EAIL_IS_WIDGET(selection), NULL);
218 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
219 Elm_Object_Item *item = elm_segment_control_item_get(object, i);
220 if (!item) return NULL;
222 return eail_segment_control_ref_child(ATK_OBJECT(selection), i);
226 * @brief Gets the number of accessible children currently selected.
228 * Note: callers should not rely on NULL or on a zero value for indication
229 * of whether AtkSelectionIface is implemented, they should use type
230 * checking/interface checking macros or the atk_get_accessible_value()
231 * convenience method.
233 * Implementation of AtkSelection->get_selection_count callback.
235 * @param selection AtkSelection instance
237 * @returns integer representing the number of selected elements
240 eail_selection_get_selection_count(AtkSelection *selection)
242 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
243 Elm_Object_Item *item = elm_segment_control_item_selected_get(object);
249 * @brief Determines if the current child of this object is selected.
251 * Note: callers should not rely on NULL or on a zero value for indication
252 * of whether AtkSelectionIface is implemented, they should use type
253 * checking/interface checking macros or the atk_get_accessible_value()
254 * convenience method.
256 * Implementation of AtkSelection->is_child_selected callback.
258 * @param selection AtkSelection instance
259 * @param i index of object
261 * @returns gboolean representing whether the specified child is selected or
262 * FALSE if selection does not implement this interface
265 eail_selection_is_child_selected(AtkSelection *selection,
268 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
269 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
270 Elm_Object_Item *selected_item = elm_segment_control_item_selected_get(object);
271 Elm_Object_Item *item = elm_segment_control_item_get(object, i);
272 return (selected_item == item);
276 * @brief Removes the specified child of the object from the object's selection
278 * Implementation of AtkSelection->remove_selection callback.
280 * @param selection AtkSelection instance
281 * @param i selection index
283 * @returns TRUE on success, FALSE otherwise
286 eail_selection_remove_selection(AtkSelection *selection,
289 g_return_val_if_fail(EAIL_IS_WIDGET(selection), FALSE);
290 Evas_Object *object = eail_widget_get_widget(EAIL_WIDGET(selection));
291 Elm_Object_Item *item = elm_segment_control_item_get(object, i);
292 if (!item) return FALSE;
293 elm_segment_control_item_selected_set(item, EINA_FALSE);
298 * @brief Causes every child of the object to be selected if the object supports
299 * multiple selections
301 * Implementation of AtkSelection->select_all_selection callback.
303 * @param selection AtkSelection instance
305 * @returns TRUE on success, FALSE otherwise
308 eail_selection_select_all_selection(AtkSelection *selection)
314 * @brief Initializer of AtkSelectionIface interface
316 * @param iface AtkSelection interface
318 static void atk_selection_interface_init(AtkSelectionIface *iface)
320 iface->add_selection = eail_selection_add_selection;
321 iface->clear_selection = eail_selection_clear_selection;
322 iface->ref_selection = eail_selection_ref_selection;
323 iface->get_selection_count = eail_selection_get_selection_count;
324 iface->is_child_selected = eail_selection_is_child_selected;
325 iface->remove_selection = eail_selection_remove_selection;
326 iface->select_all_selection = eail_selection_select_all_selection;
330 * @brief Get the name of a segment control's child
332 * @param parent EailIemParent instance
333 * @param item EailItem instance
335 * @returns string representing the name of the child
338 eail_segment_control_item_name_get(EailItemParent *parent, EailItem *item)
340 Elm_Object_Item *it = eail_item_get_item(item);
341 if (!it) return NULL;
343 return elm_object_item_part_text_get(it, NULL);
347 * @brief Initialization of EailItemParentIface interface
349 * @param iface EailItemParent interface
352 eail_item_parent_interface_init(EailItemParentIface *iface)
354 iface->get_item_name = eail_segment_control_item_name_get;