Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_panel.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_panel.c
22  * @brief EailPanel implementation
23  */
24
25 #include <atk/atk.h>
26 #include <Elementary.h>
27 #include "eail_panel.h"
28
29 /**
30  * @brief EailPanel 'toggle' action name
31  */
32 #define EAIL_PANEL_TOGGLE_ACTION "toggle"
33
34 /**
35  * @brief Definition of EailPanel as GObject
36  *
37  * EailFileselectorEntry is extended EAIL_TYPE_WIDGET with ATK_TYPE_ACTION
38  * interface implemented
39  */
40 G_DEFINE_TYPE(EailPanel, eail_panel, EAIL_TYPE_ACTION_WIDGET);
41
42 /**
43  * @brief Gets a reference to the state set of the accessible
44  *
45  * The caller must unreference it when it is no longer needed.
46  *
47  * Implementation of AtkObject->ref_state_set callback.
48  *
49  * @param obj AtkObject instance
50  *
51  * @returns AtkStateSet representing the state set of the
52  * accessible
53  */
54 static AtkStateSet*
55 eail_panel_ref_state_set(AtkObject *obj)
56 {
57    Evas_Object *widget;
58    Eina_Bool hidden;
59    AtkStateSet *state_set;
60
61    g_return_val_if_fail(EAIL_IS_PANEL(obj), NULL);
62
63    state_set = ATK_OBJECT_CLASS(eail_panel_parent_class)->ref_state_set(obj);
64    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
65    hidden = elm_panel_hidden_get(widget);
66    if (!hidden)
67      atk_state_set_add_state(state_set, ATK_STATE_VISIBLE);
68
69    return state_set;
70 }
71
72 /**
73  * @brief Gets accessible children of a panel
74  *
75  * Implementation of eail_widget_get_widget_children callback from
76  * EailWidget.
77  *
78  * @param widget EailWidget instance
79  *
80  * @returns Eina_List representing a list of the panel widget's children
81  */
82 static Eina_List*
83 eail_panel_children_get(EailWidget *widget)
84 {
85    Evas_Object *obj, *child;
86    Eina_List *list;
87
88    g_return_val_if_fail(EAIL_IS_PANEL(widget), NULL);
89
90    obj = eail_widget_get_widget(widget);
91    if (obj == NULL) return NULL;
92    child = elm_object_part_content_get(obj, "default");
93    if (child == NULL) return NULL;
94
95    list = NULL;
96    list = eina_list_append(list, child);
97
98    return list;
99 }
100
101 /**
102  * @brief Initializes the Action interface for panel
103  *
104  * @param action AtkAction instance
105  * @param data data passed to callback
106  * @returns TRUE on success, FALSE otherwise
107  */
108 static gboolean
109 eail_panel_action_toggle(AtkAction *action, void *data)
110 {
111    Evas_Object *widget;
112
113    g_return_val_if_fail(EAIL_IS_PANEL(action), FALSE);
114
115    widget = eail_widget_get_widget(EAIL_WIDGET(action));
116    if (!widget) return FALSE;
117
118    elm_panel_toggle(widget);
119
120    return TRUE;
121 }
122
123 /**
124  * @brief Hooks EailPanel actions callbacks
125  *
126  * @param action_widget EailActionWidget instance
127  */
128 static void
129 eail_panel_actions_init(EailActionWidget *action_widget)
130 {
131    eail_action_widget_action_append(action_widget,
132                                     EAIL_PANEL_TOGGLE_ACTION, NULL,
133                                     eail_panel_action_toggle);
134 }
135
136 /**
137  * @brief Initializer for AtkObjectClass
138  *
139  * @param obj AtkObject instance
140  * @param data initialization data
141  */
142 static void
143 eail_panel_initialize(AtkObject *obj, gpointer data)
144 {
145    ATK_OBJECT_CLASS(eail_panel_parent_class)->initialize(obj, data);
146    obj->role = ATK_ROLE_PANEL;
147
148    eail_panel_actions_init(EAIL_ACTION_WIDGET(obj));
149 }
150
151 /**
152  * @brief Initializer for GObject class
153  *
154  * @param panel EailPanel instance
155  */
156 static void
157 eail_panel_init(EailPanel *panel)
158 {
159    panel->toggle_description = NULL;
160 }
161
162 /**
163  * @brief Destructor for panel object
164  *
165  * @param g_object GObject instance to be finalized
166  */
167 static void eail_panel_finalize(GObject *g_object)
168 {
169    EailPanel *panel = EAIL_PANEL(g_object);
170    if (panel->toggle_description)
171      {
172         free(panel->toggle_description);
173         panel->toggle_description = NULL;
174      }
175    G_OBJECT_CLASS(g_object)->finalize(g_object);
176 }
177
178 /**
179  * @brief Initializer for GObject panel class
180  *
181  * Defines callbacks for base AtkObject.
182  *
183  * @param klass EailPanelClass instance
184  */
185 static void
186 eail_panel_class_init(EailPanelClass *klass)
187 {
188    AtkObjectClass *class = ATK_OBJECT_CLASS(klass);
189    EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
190    GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
191
192    g_object_class->finalize = eail_panel_finalize;
193
194    widget_class->get_widget_children = eail_panel_children_get;
195
196    class->initialize = eail_panel_initialize;
197    class->ref_state_set = eail_panel_ref_state_set;
198 }