2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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.
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.
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.
21 * @file eail_calendar.c
22 * @brief EailCalendar implementation
25 #include <Elementary.h>
27 #include "eail_calendar.h"
28 #include "eail_utils.h"
30 static void atk_value_interface_init(AtkValueIface *iface);
33 * @brief Define EailCalendar GObject type
35 G_DEFINE_TYPE_WITH_CODE(EailCalendar,
38 G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
39 atk_value_interface_init));
42 * @brief handler for changed event
44 * @param data passed to callback
45 * @param obj object that raised event
46 * @param event_info additional event info
50 _eail_calendar_handle_changed_event(void *data,
55 (ATK_OBJECT(data), "visible-data-changed", ATK_TYPE_OBJECT);
58 * @brief EailCalendar object initialization
60 * Sets role of AtkObject.
62 * @param obj AtkObject instance
63 * @param data initialization data
65 static void eail_calendar_initialize(AtkObject *obj, gpointer data)
67 Evas_Object *nested_widget = NULL;
68 ATK_OBJECT_CLASS(eail_calendar_parent_class)->initialize(obj, data);
70 obj->role = ATK_ROLE_CALENDAR;
71 g_return_if_fail(EAIL_IS_WIDGET(obj));
73 nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
74 evas_object_smart_callback_add(nested_widget, "changed",
75 _eail_calendar_handle_changed_event, obj);
79 * @brief EailCalendar instance initialization
81 * EailCalendar does not have any fields to initialize in struct EailCalendar
82 * thus this function is empty but still it has to be defined.
84 * @param calendar EailCalendar instance
87 eail_calendar_init(EailCalendar *calendar)
92 * @brief EailCalendar class initialization function
94 * Unitializes AtkObjectClass method pointers
95 * with class's implementations.
97 * @param klass EailCalendarClass instance
100 eail_calendar_class_init(EailCalendarClass *klass)
102 AtkObjectClass *atk_class;
104 atk_class = ATK_OBJECT_CLASS(klass);
105 atk_class->initialize = eail_calendar_initialize;
109 * @brief Gets the current value of obj
111 * Gets calendar date.
115 * AtkObject *obj; // AtkObject representing EailCalendar
116 * GValue value = G_VALUE_INIT;
117 * eail_calendar_get_current_value(ATK_VALUE(obj), &value);
120 * @param obj AtkValue instance
121 * @param [out] value obj's current value for date
124 eail_calendar_get_current_value(AtkValue *obj,
130 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
133 elm_calendar_selected_time_get(widget, ¤t);
135 memset(value, 0, sizeof(GValue));
136 g_value_init(value, G_TYPE_INT);
137 g_value_set_int(value, mktime(¤t));
141 * @brief Gets the maxiumum value of obj
143 * Gets the maximum date that can be set for calendar.
147 * AtkObject *obj; //AtkObject representing EailCalendar
148 * GValue value = G_VALUE_INIT;
149 * eail_calendar_get_maximum_value(ATK_VALUE(obj), &value);
152 * @param obj AtkValue instance
153 * @param [out] value obj's maxiumum value
156 eail_calendar_get_maximum_value(AtkValue *obj,
163 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
166 elm_calendar_min_max_year_get(widget, &min, &max);
168 memset(&maximum, 0, sizeof(maximum));
172 maximum.tm_year = max - 1900;
174 maximum.tm_mday = 31;
175 maximum.tm_hour = 23;
180 memset(value, 0, sizeof(GValue));
181 g_value_init(value, G_TYPE_INT);
182 g_value_set_int(value, mktime(&maximum));
186 * @brief Gets the minimum value of obj
188 * Gets the minimum date than can be set for calendar.
192 * AtkObject *obj; //AtkObject representing EailCalendar
193 * GValue value = G_VALUE_INIT;
194 * eail_calendar_get_minimum_value(ATK_VALUE(obj), &value);
197 * @param obj AtkObject instance
198 * @param [out] value obj's minimum value
201 eail_calendar_get_minimum_value(AtkValue *obj,
208 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
211 elm_calendar_min_max_year_get(widget, &min, &max);
213 memset(&minimum, 0, sizeof(minimum));
217 minimum.tm_year = min - 1900;
225 memset(value, 0, sizeof(GValue));
226 g_value_init(value, G_TYPE_INT);
227 g_value_set_int(value, mktime(&minimum));
231 * @brief Sets the value of obj
233 * Sets calendar date.
237 * AtkObject *obj; // AtkObject representing EailCalendar
238 * GValue value = G_VALUE_INIT;
241 * memset(&tm, 0, sizeof(time));
242 * time.tm_year = 120; // years since 1900
249 * g_value_set_int(&value, mktime(&time));
251 * eail_calendar_set_current_value(ATK_VALUE(obj), &value);
254 * @param obj AtkValue instance
255 * @param value obj's new value
256 * @return TRUE if new value was set successfully, FALSE otherwise
259 eail_calendar_set_current_value(AtkValue *obj,
263 struct tm minimum, maximum, current_set;
267 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
268 if (!widget) return FALSE;
270 elm_calendar_min_max_year_get(widget, &min, &max);
272 memset(&minimum, 0, sizeof(minimum));
273 minimum.tm_year = min - 1900;
280 memset(&maximum, 0, sizeof(maximum));
281 maximum.tm_year = max - 1900;
283 maximum.tm_mday = 31;
284 maximum.tm_hour = 23;
288 time = g_value_get_int(value);
290 if ((min < max) && (mktime(&minimum) > time || mktime(&maximum) < time))
293 localtime_r(&time, ¤t_set);
294 elm_calendar_selected_time_set(widget, ¤t_set);
300 * @brief Gets the minimum increment of obj
302 * Gets the minimum calendar increment i.e one second.
308 * GValue value = G_VALUE_INIT;
309 * eail_calendar_get_minimum_increment(ATK_VALUE(obj), &value);
312 * @param obj AtkValue instance
313 * @param [out] value obj's minimum increment
316 eail_calendar_get_minimum_increment(AtkValue *obj,
321 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
324 memset(value, 0, sizeof(GValue));
325 g_value_init(value, G_TYPE_INT);
326 g_value_set_int(value, 1);
330 * @brief Initialization of AtkValue interface
332 * Function called upon instance creation. It initializes AtkValue interface
333 * implementation i.e hooks method pointers in the interface structure
334 * to the implementing class's implementation.
336 * @param iface AtkObject instance than implements AtkValueInterface
339 atk_value_interface_init(AtkValueIface *iface)
341 iface->get_current_value = eail_calendar_get_current_value;
342 iface->get_maximum_value = eail_calendar_get_maximum_value;
343 iface->get_minimum_value = eail_calendar_get_minimum_value;
344 iface->set_current_value = eail_calendar_set_current_value;
345 iface->get_minimum_increment = eail_calendar_get_minimum_increment;