Initialize Tizen 2.3
[framework/uifw/elementary.git] / mobile / src / examples / calendar_example_06.c
1 /**
2  * Elementary's <b>calendar widget</b> example to add / del / clear marks.
3  *
4  * See stdout/stderr for output. Compile with:
5  *
6  * @verbatim
7  * gcc -o calendar_example_06 calendar_example_06.c -g `pkg-config --cflags --libs elementary`
8  * @endverbatim
9  */
10
11 #include <Elementary.h>
12
13 #define SECS_DAY 86400
14
15 static void
16 _btn_clear_cb(void *data, Evas_Object *btn, void *ev)
17 {
18    Evas_Object *cal = data;
19    elm_calendar_marks_clear(cal);
20    elm_calendar_marks_draw(cal);
21 }
22
23 EAPI_MAIN int
24 elm_main(int argc, char **argv)
25 {
26    Evas_Object *win, *bg, *bt, *bx, *cal;
27    Elm_Calendar_Mark *mark;
28    struct tm selected_time;
29    time_t current_time;
30    struct tm sunday = { 0, 0, 12, 7, 0, 0, 0, 0, -1, 0, NULL };
31    /* tm {sec, min, hour, mday, mon, year, wday, yday, isdst } */
32    /* weekdays since Sunday, range 0 to 6 */
33    struct tm christmas;
34    christmas.tm_mday = 25;
35    /* months since Jan, in the range 0 to 11 */
36    christmas.tm_mon = 11;
37
38    win = elm_win_add(NULL, "calendar", ELM_WIN_BASIC);
39    elm_win_title_set(win, "Calendar Marks Example");
40    elm_win_autodel_set(win, EINA_TRUE);
41    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
42
43    bg = elm_bg_add(win);
44    elm_win_resize_object_add(win, bg);
45    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
46    evas_object_show(bg);
47
48    bx = elm_box_add(win);
49    elm_win_resize_object_add(win, bx);
50    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
51    evas_object_show(bx);
52
53    cal = elm_calendar_add(win);
54    evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
55    evas_object_size_hint_align_set(cal, EVAS_HINT_FILL, EVAS_HINT_FILL);
56    elm_box_pack_end(bx, cal);
57    evas_object_show(cal);
58
59    /* check today - we'll remove it later */
60    current_time = time(NULL);
61    localtime_r(&current_time, &selected_time);
62    mark = elm_calendar_mark_add(cal, "checked", &selected_time,
63                                 ELM_CALENDAR_UNIQUE);
64
65    /* check tomorrow */
66    current_time = time(NULL) + 1 * SECS_DAY;
67    localtime_r(&current_time, &selected_time);
68    elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
69
70    /* mark christmas as holiday */
71    elm_calendar_mark_add(cal, "holiday", &christmas, ELM_CALENDAR_ANNUALLY);
72
73    /* mark Sundays as holidays */
74    elm_calendar_mark_add(cal, "holiday", &sunday, ELM_CALENDAR_WEEKLY);
75
76    /* ok, let's remove today's check */
77    elm_calendar_mark_del(mark);
78
79    elm_calendar_marks_draw(cal);
80
81    bt = elm_button_add(win);
82    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
83    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
84    elm_object_text_set(bt, "Clear marks");
85    evas_object_smart_callback_add(bt, "clicked", _btn_clear_cb, cal);
86    elm_box_pack_end(bx, bt);
87    evas_object_show(bt);
88
89    evas_object_show(win);
90
91    elm_run();
92    elm_shutdown();
93
94    return 0;
95 }
96 ELM_MAIN()