faeb91db0e751be139ddf3f1a03b27b6150c68d7
[platform/core/uifw/eail.git] / eail / 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 an AtkObject
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 object and allocated resources.
58  *
59  * @param obj a GObject
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 an EailHover
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 an EailHoverClass
86  */
87 static void
88 eail_hover_class_init(EailHoverClass *klass)
89 {
90    AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
91    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
92
93    class->initialize = eail_hover_initialize;
94
95    gobject_class->finalize = eail_hover_finalize;
96 }
97
98 /**
99  * @brief Performs i-th action.
100  *
101  * @param action an AtkAction
102  * @param i the action index corresponding to the 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  * @param action an AtkAction
130  * @return actions number
131  */
132 static gint
133 eail_hover_action_get_n_actions(AtkAction *action)
134 {
135    return 1;
136 }
137
138 /**
139  * @brief Gets i-th action description.
140  *
141  * @param action an AtkAction
142  * @param i action number
143  * @return action description string
144  */
145 static const gchar *
146 eail_hover_action_get_description(AtkAction *action,
147                                   gint i)
148 {
149    const char *action_description = NULL;
150    EailHover *hover;
151
152    hover = EAIL_HOVER(action);
153    if (!hover) return NULL;
154
155    switch (i)
156      {
157       case 0:
158          action_description = hover->click_description;
159          break;
160
161       default:
162          action_description = NULL;
163          break;
164      }
165
166    return action_description;
167 }
168
169 /**
170  * @brief Gets i-th action name.
171  *
172  * @param action an AtkAction
173  * @param i action number
174  * @return action description string
175  */
176 static const gchar *
177 eail_hover_action_get_name(AtkAction *action,
178                            gint i)
179 {
180    const char* action_name = NULL;
181
182    switch (i)
183      {
184       case 0:
185          action_name = "click";
186          break;
187
188       default:
189          action_name = NULL;
190          break;
191      }
192
193    return action_name;
194 }
195
196 /**
197  * @brief Sets i-th action description.
198  *
199  * @param action an AtkAction
200  * @param i action number
201  * @param desc action description
202  * @return TRUE if description is set successfully, FALSE otherwise
203  */
204 static gboolean
205 eail_hover_action_set_description(AtkAction *action,
206                                   gint i,
207                                   const gchar *desc)
208 {
209    EailHover *hover = NULL;
210    char **value = NULL;
211
212    hover = EAIL_HOVER(action);
213    if (!hover) return FALSE;
214
215    switch (i)
216      {
217       case 0:
218          value = &hover->click_description;
219          break;
220
221       default:
222          value = NULL;
223          break;
224      }
225
226    if (value)
227      {
228         free(*value);
229         *value = g_strdup(desc);
230
231         return TRUE;
232      }
233
234    return FALSE;
235 }
236
237 /**
238  * @brief AtkAction interface initializer
239  *
240  * @param iface an AtkActionIface
241  */
242 static void
243 atk_action_interface_init(AtkActionIface *iface)
244 {
245    g_return_if_fail(iface != NULL);
246
247    iface->do_action          = eail_hover_action_do_action;
248    iface->get_n_actions      = eail_hover_action_get_n_actions;
249    iface->get_description    = eail_hover_action_get_description;
250    iface->get_name           = eail_hover_action_get_name;
251    iface->set_description    = eail_hover_action_set_description;
252 }