Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_box.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_box.c
22  * @brief EailBox implementation
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_box.h"
28 #include "eail_priv.h"
29 #include "eail_utils.h"
30 #include "eail_factory.h"
31
32 /**
33  * @brief EailBox type definition
34  */
35 G_DEFINE_TYPE(EailBox, eail_box, EAIL_TYPE_WIDGET);
36
37 /**
38  * Implementation of the *AtkObject* interface
39  */
40
41 /**
42  * @brief Handler for realized event, used to notify about box content
43  * changes
44  *
45  * @param data passed to callback
46  * @param obj object that raised event
47  * @param event_info additional event info (reference toobject added to box)
48  */
49 void
50 eail_box_children_add_event(void *data,
51                             Evas_Object *obj,
52                             void *event_info)
53 {
54    AtkObject *atk_parent = NULL;
55
56    atk_parent = ATK_OBJECT(data);
57    if (!atk_parent) return;
58
59    eail_emit_children_changed_obj(TRUE, atk_parent, NULL);
60 }
61
62 /**
63  * @brief Handler for realized event, used to notify about box content
64  * changes
65  *
66  * @param data passed to callback
67  * @param obj object that raised event
68  * @param event_info additional event info (reference toobject added to box)
69  */
70 void
71 eail_box_children_rm_event(void *data,
72                             Evas_Object *obj,
73                             void *event_info)
74 {
75    AtkObject *atk_parent = NULL;
76
77    atk_parent = ATK_OBJECT(data);
78    if (!atk_parent) return;
79
80    eail_emit_children_changed_obj(FALSE, atk_parent, NULL);
81 }
82
83 /**
84  * @brief EailBox initializer
85  *
86  * @param obj AtkObject instance
87  * @param data initialization data
88  */
89 static void
90 eail_box_initialize(AtkObject *obj, gpointer data)
91 {
92    Evas_Object *nested_widget = NULL;
93    ATK_OBJECT_CLASS(eail_box_parent_class)->initialize(obj, data);
94
95    obj->role = ATK_ROLE_FILLER;
96    g_return_if_fail(EAIL_IS_WIDGET(obj));
97
98    nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
99    if (!nested_widget)
100      {
101         ERR("No evas object inside EailWidget was found");
102         return;
103    }
104
105    evas_object_smart_callback_add(nested_widget, "child,added",
106                                   eail_box_children_add_event, obj);
107    evas_object_smart_callback_add(nested_widget, "child,removed",
108                                   eail_box_children_rm_event, obj);
109 }
110
111 /**
112  * @brief Gets widget's children
113  *
114  * @param widget EailWidget instance
115  * @return Eina_List containing widget's children
116  */
117 static Eina_List *
118 eail_box_get_widget_children(EailWidget *widget)
119 {
120    Eina_List *list = NULL;
121    Evas_Object *obj = eail_widget_get_widget(widget);
122
123    if (obj)
124      list = elm_box_children_get(obj);
125
126    return list;
127 }
128
129 /**
130  * @brief EailBox instance initializer
131  *
132  * @param box EailBox instance
133  */
134 static void
135 eail_box_init(EailBox *box)
136 {
137 }
138
139 /**
140  * @brief EailBox class initializer
141  *
142  * @param klass EailBoxClass instance
143  */
144 static void
145 eail_box_class_init(EailBoxClass *klass)
146 {
147    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
148    EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
149
150    widget_class->get_widget_children = eail_box_get_widget_children;
151
152    atk_class->initialize = eail_box_initialize;
153 }