Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_custom_widget.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_custom_widget.c
22  * @brief EailCustomWidget implementation
23  */
24
25 #include <Ecore.h>
26 #include <Ecore_Evas.h>
27 #include <Elementary.h>
28
29 #include "eail_custom_widget.h"
30 #include "eail_factory.h"
31 #include "eail_utils.h"
32 #include "eail_priv.h"
33
34 /**
35  * @brief EailCustomWidget type definition
36  */
37
38 G_DEFINE_TYPE(EailCustomWidget, eail_custom_widget, EAIL_TYPE_WIDGET);
39
40 AtkObject *
41 eail_custom_widget_create(Evas_Object *widget)
42 {
43     AtkObject *accessible = NULL;
44     if (!widget)
45       {
46          ERR("Cannot create accessible for NULL-widget");
47          return NULL;
48       }
49     accessible = g_object_new(EAIL_TYPE_CUSTOM_WIDGET, NULL);
50     if (accessible) {
51        atk_object_initialize(accessible, widget);
52
53        return accessible;
54     }
55
56     DBG("No atk obj created");
57     return accessible;
58 }
59
60 /**
61  * @brief Destroyed event handler for customwidget
62  *
63  * @param data passed to callback
64  * @param obj object that raised event
65  * @param event_info additional event info
66  */
67
68 void
69 eail_custom_widget_handle_delete_event(void *data, Evas *e, Evas_Object *obj, void *event_info)
70 {
71    g_return_if_fail(ATK_IS_OBJECT(data));
72    AtkObject *parent = atk_object_get_parent(ATK_OBJECT(data));
73    EailWidget *widget = EAIL_WIDGET(parent);
74    g_return_if_fail(EAIL_IS_WIDGET(data));
75
76    widget->custom_children = eina_list_remove(widget->custom_children, ATK_OBJECT(data));
77
78    DBG("delete event\n");
79    atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_DEFUNCT, TRUE);
80    eail_emit_atk_signal(ATK_OBJECT(data), "visible-data-changed", EAIL_TYPE_CUSTOM_WIDGET);
81 }
82
83 void
84 eail_custom_widget_on_focused_in(void *data, Evas *e, Evas_Object *obj, void *event_info)
85 {
86    g_return_if_fail(ATK_IS_OBJECT(data));
87    DBG("focus in on custom widget\n");
88    atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_FOCUSED, TRUE);
89 }
90
91 void
92 eail_custom_widget_on_focused_out(void *data, Evas *e, Evas_Object *obj, void *event_info)
93 {
94    g_return_if_fail(ATK_IS_OBJECT(data));
95    DBG("focus out from custom widget\n");
96    atk_object_notify_state_change(ATK_OBJECT(data), ATK_STATE_FOCUSED, FALSE);
97 }
98
99 static void
100 eail_custom_widget_initialize(AtkObject *obj, gpointer data)
101 {
102     ATK_OBJECT_CLASS(eail_custom_widget_parent_class)->initialize(obj, data);
103
104     if (!data) {
105         ERR("No evas object inside EailCustomWidget was found");
106         return;
107     }
108
109     evas_object_event_callback_add ((Evas_Object *)data, EVAS_CALLBACK_DEL, eail_custom_widget_handle_delete_event, obj);
110     evas_object_event_callback_add ((Evas_Object *)data, EVAS_CALLBACK_FOCUS_IN , eail_custom_widget_on_focused_in, obj);
111     evas_object_event_callback_add ((Evas_Object *)data, EVAS_CALLBACK_FOCUS_OUT, eail_custom_widget_on_focused_out, obj);
112
113 }
114
115 /**
116  * @brief EailCustomWidget instance initializer
117  *
118  * @param widget EailCustomWidget instance
119  */
120 static void
121 eail_custom_widget_init(EailCustomWidget *widget)
122 {
123 }
124
125 /**
126  * @brief EailCustomWidget class initializer
127  *
128  * Function called upon instance creation. It initializes AtkObject class
129  * callbacks for EailCustomWidget.
130  *
131  * @param klass EailCustomWidgetClass instance
132  */
133 static void
134 eail_custom_widget_class_init(EailCustomWidgetClass *klass)
135 {
136     AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
137     atk_class->initialize = eail_custom_widget_initialize;
138 }
139