Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_hover.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_hover.c
22  * @brief EailHover implementation.
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_hover.h"
28 #include "eail_factory.h"
29
30 static void atk_action_interface_init(AtkActionIface *iface);
31
32 /**
33  * @brief EailHover type definition
34  */
35 G_DEFINE_TYPE_WITH_CODE(EailHover,
36                         eail_hover,
37                         EAIL_TYPE_WIDGET,
38                         G_IMPLEMENT_INTERFACE(ATK_TYPE_ACTION,
39                                               atk_action_interface_init));
40
41 /**
42  * @brief EailHover initializer
43  *
44  * @param obj AtkObject instance
45  * @param data initialization data
46  */
47 static void
48 eail_hover_initialize(AtkObject *obj, gpointer data)
49 {
50    ATK_OBJECT_CLASS(eail_hover_parent_class)->initialize(obj, data);
51    obj->role = ATK_ROLE_GLASS_PANE;
52 }
53
54 /**
55  * @brief EailHover finalizer.
56  *
57  * Destroys the object and allocated resources.
58  *
59  * @param obj GObject instance
60  */
61 static void
62 eail_hover_finalize(GObject *obj)
63 {
64     EailHover *hover = EAIL_HOVER(obj);
65
66     if (hover->click_description) free(hover->click_description);
67
68     G_OBJECT_CLASS(eail_hover_parent_class)->finalize(obj);
69 }
70
71 /**
72  * @brief EailHover instance initializer
73  *
74  * @param hover EailHover instance
75  */
76 static void
77 eail_hover_init(EailHover *hover)
78 {
79    hover->click_description = NULL;
80 }
81
82 /**
83  * @brief EailHover class initializer.
84  *
85  * @param klass EailHoverClass instance
86  */
87 static void
88 eail_hover_class_init(EailHoverClass *klass)
89 {
90    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
91    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
92
93    atk_class->initialize = eail_hover_initialize;
94
95    gobject_class->finalize = eail_hover_finalize;
96 }
97
98 /**
99  * @brief Performs the specified action on the object.
100  *
101  * @param action AtkAction instance
102  * @param i index of an action to be performed
103  * @return TRUE on success, FALSE otherwise
104  */
105 static gboolean
106 eail_hover_action_do_action(AtkAction *action,
107                             gint i)
108 {
109    Evas_Object *widget = NULL;
110    const char *action_name = NULL;
111
112    widget = eail_widget_get_widget(EAIL_WIDGET(action));
113    if (!widget) return FALSE;
114
115    if ((elm_object_disabled_get(widget)) || (!evas_object_visible_get(widget)))
116      return FALSE;
117
118    action_name = atk_action_get_name(action, i);
119    if (!action_name) return FALSE;
120
121    evas_object_smart_callback_call(widget, "clicked", NULL);
122
123    return TRUE;
124 }
125
126 /**
127  * @brief Gets number of actions available on the object.
128  *
129  * If there are more than one, the first one is considered the "default" action of the object.
130  *
131  * Implementation of get_n_actions from AtkAction interface.
132  *
133  * @param action AtkAction instance
134  * @return integer containing the number of implemented actions
135  */
136 static gint
137 eail_hover_action_get_n_actions(AtkAction *action)
138 {
139    return 1;
140 }
141
142 /**
143  * @brief Gets the description of the specified action of the object.
144  *
145  * Implementation of get_description from AtkAction interface.
146  *
147  * @param action AtkAction instance
148  * @param i action number
149  * @return string representing the description of the specified action
150  */
151 static const gchar *
152 eail_hover_action_get_description(AtkAction *action,
153                                   gint i)
154 {
155    const char *action_description = NULL;
156    EailHover *hover;
157
158    hover = EAIL_HOVER(action);
159    if (!hover) return NULL;
160
161    switch (i)
162      {
163       case 0:
164          action_description = hover->click_description;
165          break;
166
167       default:
168          action_description = NULL;
169          break;
170      }
171
172    return action_description;
173 }
174
175 /**
176  * @brief Gets the name of the specified action of the object.
177  *
178  * Implementation of get_name from AtkAction interface.
179  *
180  * @param action AtkAction instance
181  * @param i action number
182  * @return string containing the name of the specified action
183  */
184 static const gchar *
185 eail_hover_action_get_name(AtkAction *action,
186                            gint i)
187 {
188    const char* action_name = NULL;
189
190    switch (i)
191      {
192       case 0:
193          action_name = "click";
194          break;
195
196       default:
197          action_name = NULL;
198          break;
199      }
200
201    return action_name;
202 }
203
204 /**
205  * @brief Sets a description of the specified action of the object.
206  *
207  * Implementation of set_description from AtkAction interface.
208  *
209  * @param action AtkAction instance
210  * @param i action number
211  * @param desc action description
212  * @return TRUE if description was set successfully, FALSE otherwise
213  */
214 static gboolean
215 eail_hover_action_set_description(AtkAction *action,
216                                   gint i,
217                                   const gchar *desc)
218 {
219    EailHover *hover = NULL;
220    char **value = NULL;
221
222    hover = EAIL_HOVER(action);
223    if (!hover) return FALSE;
224
225    switch (i)
226      {
227       case 0:
228          value = &hover->click_description;
229          break;
230
231       default:
232          value = NULL;
233          break;
234      }
235
236    if (value)
237      {
238         free(*value);
239         *value = g_strdup(desc);
240
241         return TRUE;
242      }
243
244    return FALSE;
245 }
246
247 /**
248  * @brief AtkAction interface initializer
249  *
250  * @param iface AtkActionIface instance
251  */
252 static void
253 atk_action_interface_init(AtkActionIface *iface)
254 {
255    g_return_if_fail(iface != NULL);
256
257    iface->do_action          = eail_hover_action_do_action;
258    iface->get_n_actions      = eail_hover_action_get_n_actions;
259    iface->get_description    = eail_hover_action_get_description;
260    iface->get_name           = eail_hover_action_get_name;
261    iface->set_description    = eail_hover_action_set_description;
262 }