Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_item_parent.c
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /**
21  * @file eail_item_parent.c
22  * @brief Implementation of interface that is used by EailItem implementation
23  * to allow special behavior of wide range item-objects
24 */
25
26 #include "eail_item_parent.h"
27
28 /**
29  * @brief Gets GType for initialized interface
30  *
31  * @returns GType for initialized interface
32  */
33 GType
34 eail_item_parent_get_type(void)
35 {
36    static volatile GType type_id__volatile = 0;
37
38    if (g_once_init_enter(&type_id__volatile))
39      {
40         GType type_id = g_type_register_static_simple(
41                                     G_TYPE_INTERFACE,
42                                     "EailItemParent",
43                                     sizeof(EailItemParentIface),
44                                     NULL,
45                                     0,
46                                     NULL,
47                                     0);
48
49         g_once_init_leave(&type_id__volatile, type_id);
50      }
51
52    return type_id__volatile;
53 }
54
55 /**
56  * @brief Gets the name of item
57  *
58  * @param parent object that holds EailItem in its content
59  * @param item EailItem instance
60  *
61  * @return string representing the name of item or NULL if the name is not available
62  */
63 const gchar *
64 eail_item_parent_get_item_name(EailItemParent   *parent,
65                                EailItem         *item)
66 {
67    EailItemParentIface *iface;
68
69    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
70
71    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
72
73    if (iface->get_item_name)
74      return iface->get_item_name(parent, item);
75
76    return NULL;
77 }
78
79 /**
80  * @brief Gets the role of item
81  *
82  * @param parent object that holds EailItem in its content
83  * @param item EailItem object
84  *
85  * @returns AtkRole representing the role of the specified EailItem
86  */
87 AtkRole
88 eail_item_parent_get_item_role(EailItemParent   *parent,
89                                EailItem         *item)
90 {
91    EailItemParentIface *iface;
92
93    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), ATK_ROLE_INVALID);
94
95    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
96
97    if (iface->get_item_role)
98      return iface->get_item_role(parent, item);
99
100    return ATK_OBJECT(item)->role;
101 }
102
103 /**
104  * @brief Gets the index of item in parent object
105  *
106  * @param parent object that holds EailItem in its content
107  * @param item EailItem instance
108  *
109  * @returns integer representing the index of item in parent object
110  */
111 gint
112 eail_item_parent_get_item_index_in_parent(EailItemParent    *parent,
113                                           EailItem          *item)
114 {
115    EailItemParentIface *iface;
116
117    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), -1);
118
119    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
120
121    if (iface->get_item_index_in_parent)
122      return iface->get_item_index_in_parent(parent, item);
123
124    return -1;
125 }
126
127 /**
128  * @brief Gets the number of accessible children
129  *
130  * @param parent object that holds EailItem in its content
131  * @param item EailItem instance
132  *
133  * @returns integer representing the number of accessible children or -1 if
134  * not implemented
135  */
136 gint
137 eail_item_parent_get_n_children(EailItemParent    *parent,
138                                 EailItem          *item)
139 {
140    EailItemParentIface *iface;
141
142    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), -1);
143
144    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
145
146    if (iface->get_n_children)
147      return iface->get_n_children(parent, item);
148
149    return -1;
150 }
151
152 /**
153  * @brief Gets a reference to the specified accessible child of the object.
154  *
155  * The accessible children are 0-based so the first accessible child
156  * is at index 0, the second at index 1 and so on.
157  *
158  * @param parent object that holds EailItem in its content
159  * @param item EailItem instance
160  * @param index gint representing index of child to ref
161  *
162  * @returns AtkObject representing the specified accessible child
163  * or NULL if not implemented
164  */
165 AtkObject *
166 eail_item_parent_ref_n_child(EailItemParent    *parent,
167                              EailItem          *item,
168                              gint index)
169 {
170    EailItemParentIface *iface;
171
172    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
173
174    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
175
176    if (iface->ref_n_child)
177      return iface->ref_n_child(parent, item, index);
178
179    return NULL;
180 }
181
182 /**
183  * @brief Gets a reference to the state set of EailItem
184  *
185  * @param parent object that holds EailItem in its content
186  * @param item EailItem instance
187  * @param state_set current state set
188  *
189  * @returns AtkStateSet representing the state set of given EailItem
190  */
191 AtkStateSet *
192 eail_item_parent_ref_item_state_set(EailItemParent  *parent,
193                                     EailItem        *item,
194                                     AtkStateSet     *state_set)
195 {
196    EailItemParentIface *iface;
197
198    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
199
200    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
201
202    if (iface->ref_item_state_set)
203      return iface->ref_item_state_set(parent, item, state_set);
204
205    return state_set;
206 }
207
208 /**
209  * @brief Grabs focus of EailItem
210  *
211  * @param parent object that holds EailItem in its content
212  * @param item EailItem instance
213  *
214  * @returns TRUE on success, FALSE otherwise
215  */
216 gboolean
217 eail_item_parent_grab_item_focus(EailItemParent *parent,
218                                  EailItem       *item)
219 {
220    EailItemParentIface *iface;
221
222    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), FALSE);
223
224    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
225
226    if (iface->grab_item_focus)
227      return iface->grab_item_focus(parent, item);
228
229    return FALSE;
230 }
231
232 /**
233  * @brief Gets the rectangle which gives the extent of the component
234  *
235  * Implementation of atk_component_get_extents.
236  *
237  * @param parent object that holds EailItem in its content
238  * @param item EailItem object
239  * @param [out] x x coordinate
240  * @param [out] y y coordinate
241  * @param [out] width width of the rectangle
242  * @param [out] height height of the rectangle
243  * @param coord_type specifies whether the coordinates are relative to the
244  * screen or to the components top level window
245  */
246 void
247 eail_item_parent_get_item_extents(EailItemParent    *parent,
248                                   EailItem          *item,
249                                   gint                *x,
250                                   gint                *y,
251                                   gint                *width,
252                                   gint                *height,
253                                   AtkCoordType         coord_type)
254 {
255    EailItemParentIface *iface;
256
257    g_return_if_fail(EAIL_IS_ITEM_PARENT(parent));
258
259    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
260
261    if (iface->get_item_extents)
262      iface->get_item_extents(parent, item, x, y, width, height, coord_type);
263 }
264
265 /**
266  * @brief Gets nested Evas_Object of given EailItem
267  *
268  * @param parent object that holds EailItem in its content
269  * @param item EailItem instance
270  *
271  * @returns nested Evas_Object representing the given EailItem
272  */
273 Evas_Object * eail_item_parent_get_evas_obj(EailItemParent   *parent,
274                                             EailItem         *item)
275 {
276    EailItemParentIface *iface;
277
278    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
279
280    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
281
282    if (iface->get_evas_obj)
283      return iface->get_evas_obj(parent, item);
284
285    return NULL;
286 }
287
288 /**
289  * @brief Gets supported actions
290  *
291  * @param parent object that holds EailItem in its content
292  * @param item EailItem instance
293  *
294  * @returns integer representing supported actions
295  */
296 gint
297 eail_item_parent_get_actions_supported(EailItemParent *parent,
298                                        EailItem       *item)
299 {
300    EailItemParentIface *iface;
301
302    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), FALSE);
303
304    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
305
306    if (iface->get_actions_supported)
307      return iface->get_actions_supported(parent, item);
308
309    return EAIL_ACTION_SUPPORTED_NONE;
310 }
311
312 /**
313  * @brief Checks if content get is supported
314  *
315  * @param parent object that holds EailItem in its content
316  * @param item EailItem instance
317  *
318  * @returns TRUE if content get is supported, FALSE otherwise. Default
319  * implementation returns TRUE (used if no redefinition in EailItemParent
320  * interface implementation is defined)
321  */
322 gboolean
323 eail_item_parent_is_is_content_get_supported(EailItemParent *parent,
324                                              EailItem       *item)
325 {
326    EailItemParentIface *iface;
327
328    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), FALSE);
329
330    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
331
332    if (iface->is_content_get_supported)
333      return iface->is_content_get_supported(parent, item);
334
335    return TRUE;
336 }