e48a9e8b9bd59f2ae3a17f31d8e368ce6683daeb
[framework/uifw/elementary.git] / src / examples / calendar_example_05.c
1 /**
2  * Elementary's <b>calendar widget</b> example, illustrating smart callback
3  * registry and getters usage.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g `pkg-config --cflags --libs elementary` calendar_example_05.c -o calendar_example_05
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #else
16 # define __UNUSED__
17 #endif
18
19 static void
20 _print_cal_info_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
21 {
22    int year_min, year_max;
23    Eina_Bool sel_enabled;
24    const char **wds;
25    struct tm stime;
26    double interval;
27
28    if (!elm_calendar_selected_time_get(obj, &stime))
29      return;
30
31    interval = elm_calendar_interval_get(obj);
32    elm_calendar_min_max_year_get(obj, &year_min, &year_max);
33    sel_enabled = !elm_calendar_day_selection_disabled_get(obj);
34    wds = elm_calendar_weekdays_names_get(obj);
35
36    printf("Day: %i, Mon: %i, Year %i, WeekDay: %i<br>\n"
37           "Interval: %0.2f, Year_Min: %i, Year_Max %i, Sel Enabled : %i<br>\n"
38           "Weekdays: %s, %s, %s, %s, %s, %s, %s<br>\n\n",
39           stime.tm_mday, stime.tm_mon, stime.tm_year + 1900, stime.tm_wday,
40           interval, year_min, year_max, sel_enabled,
41           wds[0], wds[1], wds[2], wds[3], wds[4], wds[5], wds[6]);
42 }
43
44 EAPI_MAIN int
45 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
46 {
47    Evas_Object *win, *bg, *cal;
48
49    win = elm_win_add(NULL, "calendar", ELM_WIN_BASIC);
50    elm_win_title_set(win, "Calendar Getters Example");
51    elm_win_autodel_set(win, EINA_TRUE);
52
53    bg = elm_bg_add(win);
54    elm_win_resize_object_add(win, bg);
55    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
56    evas_object_show(bg);
57
58    cal = elm_calendar_add(win);
59    elm_win_resize_object_add(win, cal);
60    evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61    /* Add callback to display calendar information every time user
62     * selects a new date */
63    evas_object_smart_callback_add(cal, "changed", _print_cal_info_cb, NULL);
64    evas_object_show(cal);
65
66    evas_object_show(win);
67
68    elm_run();
69    return 0;
70 }
71 ELM_MAIN()