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