Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_dayselector.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_dayselector.c
22  * @brief EailDayselector implementation
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_dayselector.h"
28 #include "eail_check.h"
29
30 /** @brief Number of days displayed in dayselector widget */
31 #define EAIL_DAYSELECTOR_NUM_OF_DAYS 7
32 /** @brief Content part name definition for dayselector widget */
33 #define EAIL_CONTENT_PART_FORMAT "day%d"
34
35 /**
36  * @brief GObject definition for EailDayselector widget
37  *
38  * It extends EAIL_TYPE_WIDGET
39  */
40 G_DEFINE_TYPE(EailDayselector, eail_dayselector, EAIL_TYPE_WIDGET);
41
42 /**
43  * @brief Initializer for AtkObjectClass
44  *
45  * @param obj AtkObject instance
46  * @param data initialization data
47  */
48 static void
49 eail_dayselector_initialize(AtkObject *obj, gpointer data)
50 {
51    ATK_OBJECT_CLASS(eail_dayselector_parent_class)->initialize(obj, data);
52    obj->role = ATK_ROLE_PANEL;
53 }
54
55 /**
56  * @brief GObject-initializer for EailDayselector
57  *
58  * @param button EailDayselector instance
59  */
60 static void
61 eail_dayselector_init(EailDayselector *button)
62 {
63 }
64
65 /**
66  * @brief Gets the number of accessible children of the accessible.
67  *
68  * Implementation of AtkObject->get_n_children callback.
69  *
70  * @param obj AtkObject instance
71  *
72  * @returns integer representing the number of accessible children of
73  * the accessible
74  */
75 static gint
76 eail_dayselector_get_n_children(AtkObject *obj)
77 {
78    return EAIL_DAYSELECTOR_NUM_OF_DAYS;
79 }
80
81 /**
82  * @brief Helper function for generating content string name for given day number
83  * @param day_num integer which represents a particular day of the week
84  *
85  * @returns Eina_Strbuf object filled with content day-name
86  */
87 static Eina_Strbuf *
88 _eail_dayselector_gen_day_str(int day_num)
89 {
90    Eina_Strbuf *str_buf = NULL;
91
92    str_buf = eina_strbuf_new();
93    eina_strbuf_append_printf(str_buf, EAIL_CONTENT_PART_FORMAT, day_num);
94
95    return str_buf;
96 }
97
98 /**
99  * @brief Helper function for creating the content of dayselector's child
100  *
101  * Unref it when it is no longer needed.
102  *
103  * @param day_check_widget check widget that represents a day in dayselector
104  * widget
105  *
106  * @returns AtkObject representing a given day in dayselector.
107  */
108 static AtkObject *
109 _eail_create_dayselector_child(Evas_Object *day_check_widget)
110 {
111    AtkObject *child = NULL;
112    child = g_object_new(EAIL_TYPE_CHECK, NULL);
113    atk_object_initialize(child, day_check_widget);
114    g_object_ref(child);
115
116    return child;
117 }
118
119 /**
120  * @brief Gets a reference to the specified accessible child of the object.
121  *
122  * The accessible children are 0-based so the first accessible child is at index 0,
123  * the second at index 1 and so on.
124  *
125  * Implementation of AtkObject->ref_child callback.
126  *
127  * @param obj AtkObject instance
128  * @param i child index
129  *
130  * @returns AtkObject representing the specified accessible child of the
131  * accessible
132  */
133 static AtkObject *
134 eail_dayselector_ref_child(AtkObject *obj, gint i)
135 {
136    AtkObject *child = NULL;
137    Eina_Strbuf *part_name = NULL;
138    Evas_Object *ds_widget = NULL, *day_check = NULL;
139
140    g_return_val_if_fail (EAIL_IS_WIDGET(obj), NULL);
141
142    ds_widget = eail_widget_get_widget(EAIL_WIDGET(obj) );
143    part_name = _eail_dayselector_gen_day_str(i);
144    day_check = elm_object_part_content_get
145                   (ds_widget, eina_strbuf_string_get(part_name));
146
147    /* dayselector consists of objects with type CHECK-widget */
148    child = _eail_create_dayselector_child(day_check);
149
150    eina_strbuf_free(part_name);
151    return child;
152 }
153
154 /**
155  * @brief Destructor for GObject Dayselector implementation
156  *
157  * @param object GObject object to be finalized
158  */
159 static void
160 eail_dayselector_finalize(GObject *object)
161 {
162    G_OBJECT_CLASS(eail_dayselector_parent_class)->finalize(object);
163 }
164
165 /**
166  * @brief Initializer for GObject EailDayselectorClass class
167  *
168  * Defines callbacks for base AtkObject.
169  *
170  * @param klass EailDayselectorClass instance
171  */
172 static void
173 eail_dayselector_class_init(EailDayselectorClass *klass)
174 {
175    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
176    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
177    atk_class->initialize = eail_dayselector_initialize;
178    atk_class->get_n_children = eail_dayselector_get_n_children;
179    atk_class->ref_child = eail_dayselector_ref_child;
180    gobject_class->finalize = eail_dayselector_finalize;
181 }