938b0807ddb72c444e2bd576677e5c6714df7a17
[platform/core/uifw/eail.git] / eail / eail / eail_bubble.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_bubble.c
22  * @brief Implementation of EailBubble
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_bubble.h"
28
29 static void atk_action_interface_init(AtkActionIface *iface);
30
31 /**
32  * @brief Definition of EailBubble type
33  */
34 G_DEFINE_TYPE_WITH_CODE(EailBubble,
35                         eail_bubble,
36                         EAIL_TYPE_TEXT,
37                         G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
38                                               atk_action_interface_init));
39
40 /*
41  * Implementation of the *AtkObject* interface
42  */
43
44 /**
45  * @brief EailBubble object initialization
46  *
47  * @param obj EailBubble object
48  * @param data user set additional initialization data
49  */
50 static void
51 eail_bubble_initialize(AtkObject *obj, gpointer data)
52 {
53    ATK_OBJECT_CLASS(eail_bubble_parent_class)->initialize(obj, data);
54
55    obj->role = ATK_ROLE_FILLER;
56 }
57
58 /**
59  * @brief Class destructor
60  *
61  * @param object object instance
62  */
63 static void
64 eail_bubble_finalize(GObject *object)
65 {
66    EailBubble *bubble = EAIL_BUBBLE(object);
67
68    if (bubble->click_description) free(bubble->click_description);
69
70    G_OBJECT_CLASS(eail_bubble_parent_class)->finalize(object);
71 }
72
73 /**
74  * @brief EailBubble instance initialization
75  *
76  * @param bubble EailBubble instance
77  */
78 static void
79 eail_bubble_init(EailBubble *bubble)
80 {
81    bubble->click_description = NULL;
82 }
83
84 /**
85  * @brief Gets list of child widget
86  *
87  * @param widget EailWidget object
88  *
89  * @return list of child, NULL if no children
90  */
91 static Eina_List *
92 eail_bubble_get_widget_children(EailWidget *widget)
93 {
94    Eina_List *list = NULL;
95    Evas_Object *child, *obj;
96
97    obj = eail_widget_get_widget(EAIL_WIDGET(widget));
98
99    if (obj)
100      {
101         child = elm_object_part_content_get(obj, "default");
102         if (child && elm_object_widget_check(child))
103           list = eina_list_append(list, child);
104
105         child = elm_object_part_content_get(obj, "icon");
106         if (child && elm_object_widget_check(child))
107           list = eina_list_append(list, child);
108      }
109
110    return list;
111 }
112
113 /**
114  * @brief GObject type initialization function
115  *
116  * @param klass EailBubble class
117  */
118 static void
119 eail_bubble_class_init(EailBubbleClass *klass)
120 {
121    AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
122    EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
123    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
124
125    class->initialize = eail_bubble_initialize;
126    widget_class->get_widget_children = eail_bubble_get_widget_children;
127    gobject_class->finalize = eail_bubble_finalize;
128 }
129
130 /*
131  * Implementation of the *AtkAction* interface
132  */
133
134 /**
135  * @brief Implementation of get_n_actions from AtkAction interface
136  *
137  * @param action EailBubble instance
138  *
139  * @returns number of actions
140  */
141 static int
142 eail_bubble_n_actions_get(AtkAction *action)
143 {
144    return 1;
145 }
146
147 /**
148  * @brief Implementation of get_description from AtkAction interface
149  *
150  * @param action EailBubble instance
151  * @param i action index
152  *
153  * @return action description
154  */
155 static const char*
156 eail_bubble_description_get(AtkAction *action,
157                             gint i)
158 {
159    EailBubble *bubble;
160    const char *action_description;
161
162    bubble = EAIL_BUBBLE(action);
163    if (!bubble) return NULL;
164
165    switch (i)
166      {
167       case 0:
168          action_description = bubble->click_description;
169          break;
170       default:
171          action_description = NULL;
172          break;
173      }
174
175    return action_description;
176 }
177
178 /**
179  * @brief Implementation of set_descritpion from AtkAction interface
180  *
181  * @param action EailBubble instance
182  * @param i action index
183  * @param description action description
184  *
185  * @return TRUE on success, FALSE otherwise
186  */
187 static gboolean
188 eail_bubble_description_set(AtkAction *action,
189                             gint i,
190                             const char *description)
191 {
192    EailBubble *bubble;
193    char **value;
194
195    bubble = EAIL_BUBBLE(action);
196    if (!bubble) return FALSE;
197
198    switch (i)
199      {
200       case 0:
201          value = &bubble->click_description;
202          break;
203       default:
204          value = NULL;
205          break;
206      }
207
208    if (value)
209      {
210         free(*value);
211         *value = g_strdup(description);
212         return TRUE;
213      }
214
215    return FALSE;
216 }
217
218 /**
219  * @brief Implementation of get_name from AtkAction interface
220  *
221  * @param action EailBubble instance
222  * @param i action index
223  *
224  * @return action name
225  */
226 static const char*
227 eail_bubble_action_name_get(AtkAction *action,
228                             int i)
229 {
230    const char* action_name;
231
232    switch (i)
233      {
234       case 0:
235          action_name = "click";
236          break;
237       default:
238          action_name = NULL;
239          break;
240      }
241
242    return action_name;
243 }
244
245 /**
246  * @brief Implementation of do_action from AtkAction interface
247  *
248  * @param action EailBubble instance
249  * @param i action index
250  *
251  * @return TRUE on success, FALSE otherwise
252  */
253 static gboolean
254 eail_bubble_do_action(AtkAction *action,
255                       int i)
256 {
257    Evas_Object *widget;
258
259    widget = eail_widget_get_widget(EAIL_WIDGET(action));
260    if (!widget) return FALSE;
261
262    if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
263      return FALSE;
264
265    const char *action_name = atk_action_get_name(action, i);
266    if (!action_name) return FALSE;
267
268    evas_object_smart_callback_call(widget, "clicked", NULL);
269
270    return TRUE;
271 }
272
273 /**
274  * @brief AtkAction interface initializer
275  *
276  * @param iface action interface to be filled
277  **/
278 static void
279 atk_action_interface_init(AtkActionIface *iface)
280 {
281    g_return_if_fail(iface != NULL);
282
283    iface->get_n_actions   = eail_bubble_n_actions_get;
284    iface->get_description = eail_bubble_description_get;
285    iface->set_description = eail_bubble_description_set;
286    iface->get_name        = eail_bubble_action_name_get;
287    iface->do_action       = eail_bubble_do_action;
288 }