37470536d3d42f19233f509bd728db385eb04976
[platform/core/uifw/eail.git] / eail / 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  *
30  * @returns GType for initialized interface
31  */
32 GType
33 eail_item_parent_get_type(void)
34 {
35    static volatile GType type_id__volatile = 0;
36
37    if (g_once_init_enter(&type_id__volatile))
38      {
39         GType type_id = g_type_register_static_simple(
40                                     G_TYPE_INTERFACE,
41                                     "EailItemParent",
42                                     sizeof(EailItemParentIface),
43                                     NULL,
44                                     0,
45                                     NULL,
46                                     0);
47
48         g_once_init_leave(&type_id__volatile, type_id);
49      }
50
51    return type_id__volatile;
52 }
53
54 /**
55  * @param parent object that holds EailItem in its content
56  * @param item an EailItem object
57  *
58  * @return gchar* representing name of item or NULL if not available
59  */
60 const gchar *
61 eail_item_parent_get_item_name(EailItemParent   *parent,
62                                EailItem         *item)
63 {
64    EailItemParentIface *iface;
65
66    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
67
68    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
69
70    if (iface->get_item_name)
71      return iface->get_item_name(parent, item);
72
73    return NULL;
74 }
75
76 /**
77  * @param parent object that holds EailItem in its content
78  * @param item an EailItem object
79  *
80  * @returns ATK role for given EailItem
81  */
82 AtkRole
83 eail_item_parent_get_item_role(EailItemParent   *parent,
84                                EailItem         *item)
85 {
86    EailItemParentIface *iface;
87
88    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), ATK_ROLE_INVALID);
89
90    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
91
92    if (iface->get_item_role)
93      return iface->get_item_role(parent, item);
94
95    return ATK_OBJECT(item)->role;
96 }
97
98 /**
99  * @param parent object that holds EailItem in its content
100  * @param item an EailItem object
101  *
102  * @returns gint representing index of item in parent object
103  */
104 gint
105 eail_item_parent_get_item_index_in_parent(EailItemParent    *parent,
106                                           EailItem          *item)
107 {
108    EailItemParentIface *iface;
109
110    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), -1);
111
112    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
113
114    if (iface->get_item_index_in_parent)
115      return iface->get_item_index_in_parent(parent, item);
116
117    return -1;
118 }
119
120 /**
121  * @param parent object that holds EailItem in its content
122  * @param item an EailItem object
123  *
124  * @returns gint representing index of item in parent object or -1 if
125  * not implemented
126  */
127 gint
128 eail_item_parent_get_n_children(EailItemParent    *parent,
129                                 EailItem          *item)
130 {
131    EailItemParentIface *iface;
132
133    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), -1);
134
135    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
136
137    if (iface->get_n_children)
138      return iface->get_n_children(parent, item);
139
140    return -1;
141 }
142
143 /**
144  * @param parent object that holds EailItem in its content
145  * @param item an EailItem object
146  * @param index gint representing index of child to ref
147  *
148  * @returns AtkObject * for given index or NULL if not implemented
149  */
150 AtkObject *
151 eail_item_parent_ref_n_child(EailItemParent    *parent,
152                              EailItem          *item,
153                              gint index)
154 {
155    EailItemParentIface *iface;
156
157    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
158
159    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
160
161    if (iface->ref_n_child)
162      return iface->ref_n_child(parent, item, index);
163
164    return NULL;
165 }
166
167 /**
168  * @param parent object that holds EailItem in its content
169  * @param item an EailItem object
170  * @param state_set current state_set
171  *
172  * @returns AtkStateSet representing state set of given EailItem
173  */
174 AtkStateSet *
175 eail_item_parent_ref_item_state_set(EailItemParent  *parent,
176                                     EailItem        *item,
177                                     AtkStateSet     *state_set)
178 {
179    EailItemParentIface *iface;
180
181    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
182
183    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
184
185    if (iface->ref_item_state_set)
186      return iface->ref_item_state_set(parent, item, state_set);
187
188    return state_set;
189 }
190
191 /**
192  * @param parent object that holds EailItem in its content
193  * @param item an EailItem object
194  *
195  * @returns TRUE if operation was successfull, FALSE otherwise
196  */
197 gboolean
198 eail_item_parent_grab_item_focus(EailItemParent *parent,
199                                  EailItem       *item)
200 {
201    EailItemParentIface *iface;
202
203    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), FALSE);
204
205    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
206
207    if (iface->grab_item_focus)
208      return iface->grab_item_focus(parent, item);
209
210    return FALSE;
211 }
212
213 /**
214  * ATK doc says:
215  * Gets the rectangle which gives the extent of the component.
216  *
217  * @param parent object that holds EailItem in its content
218  * @param item an EailItem object
219  * @param x address of gint to put x coordinate
220  * @param y address of gint to put y coordinate
221  * @param width addrress of gint to put width
222  * @param height address of gint to put height
223  * @param coord_type specifies whether the coordinates are relative to the
224  * screen or to the components top level window
225  */
226 void
227 eail_item_parent_get_item_extents(EailItemParent    *parent,
228                                   EailItem          *item,
229                                   gint                *x,
230                                   gint                *y,
231                                   gint                *width,
232                                   gint                *height,
233                                   AtkCoordType         coord_type)
234 {
235    EailItemParentIface *iface;
236
237    g_return_if_fail(EAIL_IS_ITEM_PARENT(parent));
238
239    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
240
241    if (iface->get_item_extents)
242      iface->get_item_extents(parent, item, x, y, width, height, coord_type);
243 }
244
245 /**
246  * @param parent object that holds EailItem in its content
247  * @param item an EailItem object
248  *
249  * @returns nested Evas_Object for given EailItem
250  */
251 Evas_Object * eail_item_parent_get_evas_obj(EailItemParent   *parent,
252                                             EailItem         *item)
253 {
254    EailItemParentIface *iface;
255
256    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), NULL);
257
258    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
259
260    if (iface->get_evas_obj)
261      return iface->get_evas_obj(parent, item);
262
263    return NULL;
264 }
265
266 /**
267  * @param parent object that holds EailItem in its content
268  * @param item an EailItem object
269  *
270  * @returns filled gint representing supported actions
271  */
272 gint
273 eail_item_parent_get_actions_supported(EailItemParent *parent,
274                                        EailItem       *item)
275 {
276    EailItemParentIface *iface;
277
278    g_return_val_if_fail(EAIL_IS_ITEM_PARENT(parent), FALSE);
279
280    iface = EAIL_ITEM_PARENT_GET_IFACE(parent);
281
282    if (iface->get_actions_supported)
283      return iface->get_actions_supported(parent, item);
284
285    return EAIL_ACTION_SUPPORTED_NONE;
286 }
287
288 /**
289  * @param parent object that holds EailItem in its content
290  * @param item an EailItem object
291  *
292  * @returns TRUE if content get is supported, FALSE otherwise. Default
293  * implementation returns TRUE (used if no redefinition in EailItemParent
294  * interface implementation is defined)
295  */
296 gboolean
297 eail_item_parent_is_is_content_get_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->is_content_get_supported)
307      return iface->is_content_get_supported(parent, item);
308
309    return TRUE;
310 }