add test4 for table
[framework/uifw/elementary.git] / src / bin / test_calendar.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 /* A simple test, just displaying calendar in it's default state */
8 void
9 test_calendar(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
10 {
11    Evas_Object *win, *bg, *cal;
12
13    win = elm_win_add(NULL, "calendar", ELM_WIN_BASIC);
14    elm_win_title_set(win, "Calendar");
15    elm_win_autodel_set(win, 1);
16
17    bg = elm_bg_add(win);
18    elm_win_resize_object_add(win, bg);
19    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
20    evas_object_show(bg);
21
22    cal = elm_calendar_add(win);
23    elm_win_resize_object_add(win, cal);
24    evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
25    evas_object_show(cal);
26
27    evas_object_show(win);
28 }
29
30 void
31 _print_cal_info(Evas_Object *cal, Evas_Object *en)
32 {
33    char info[1024];
34    double interval;
35    int year_min, year_max;
36    Eina_Bool sel_enabled;
37    const char **wds;
38    struct tm stime;
39
40    if (!elm_calendar_selected_time_get(cal, &stime))
41      return;
42
43    interval = elm_calendar_interval_get(cal);
44    elm_calendar_min_max_year_get(cal, &year_min, &year_max);
45    sel_enabled = elm_calendar_day_selection_enabled_get(cal);
46    wds = elm_calendar_weekdays_names_get(cal);
47
48    snprintf(info, sizeof(info),
49          "  Day: %i, Mon: %i, Year %i, WeekDay: %i<br>"
50          "  Interval: %0.2f, Year_Min: %i, Year_Max %i, Sel Enabled : %i<br>"
51          "  Weekdays: %s, %s, %s, %s, %s, %s, %s<br>",
52          stime.tm_mday, stime.tm_mon, stime.tm_year + 1900, stime.tm_wday,
53          interval, year_min, year_max, sel_enabled,
54          wds[0], wds[1], wds[2], wds[3], wds[4], wds[5], wds[6]);
55
56    elm_entry_entry_set(en, info);
57 }
58
59 static void
60 _print_cal_info_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
61 {
62    _print_cal_info(obj, data);
63 }
64
65 static char *
66 _format_month_year(struct tm *stime)
67 {
68    char buf[32];
69    if (!strftime(buf, sizeof(buf), "%b %y", stime)) return NULL;
70    return strdup(buf);
71 }
72
73 /* A test intended to cover all the calendar api and much use cases as
74    possible */
75 void
76 test_calendar2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
77 {
78    Evas_Object *win, *bg, *bx, *bxh, *cal, *cal2, *cal3, *en;
79    Elm_Calendar_Mark *mark;
80    struct tm selected_time;
81    time_t current_time;
82    const char *weekdays[] =
83    {
84       "Sunday", "Monday", "Tuesday", "Wednesday",
85       "Thursday", "Friday", "Saturday"
86    };
87
88    win = elm_win_add(NULL, "calendar2", ELM_WIN_BASIC);
89    elm_win_title_set(win, "Calendar 2");
90    elm_win_autodel_set(win, 1);
91
92    bg = elm_bg_add(win);
93    elm_win_resize_object_add(win, bg);
94    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
95    evas_object_show(bg);
96
97    bx = elm_box_add(win);
98    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99    elm_win_resize_object_add(win, bx);
100    evas_object_show(bx);
101
102    bxh = elm_box_add(win);
103    elm_box_horizontal_set(bxh, EINA_TRUE);
104    evas_object_size_hint_weight_set(bxh, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
105    evas_object_size_hint_align_set(bxh, EVAS_HINT_FILL, EVAS_HINT_FILL);
106    evas_object_show(bxh);
107    elm_box_pack_end(bx, bxh);
108
109    cal = elm_calendar_add(win);
110    evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111    evas_object_size_hint_align_set(cal, EVAS_HINT_FILL, EVAS_HINT_FILL);
112    evas_object_show(cal);
113    elm_box_pack_end(bx, cal);
114
115    cal2 = elm_calendar_add(win);
116    evas_object_size_hint_weight_set(cal2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
117    evas_object_size_hint_align_set(cal2, EVAS_HINT_FILL, EVAS_HINT_FILL);
118    elm_calendar_day_selection_enabled_set(cal2, EINA_FALSE);
119    evas_object_show(cal2);
120    elm_box_pack_end(bxh, cal2);
121
122    cal3 = elm_calendar_add(win);
123    evas_object_size_hint_weight_set(cal3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124    evas_object_size_hint_align_set(cal3, EVAS_HINT_FILL, EVAS_HINT_FILL);
125    current_time = time(NULL) + 34 * 84600;
126    localtime_r(&current_time, &selected_time);
127    elm_calendar_selected_time_set(cal3, &selected_time);
128    current_time = time(NULL) + 1 * 84600;
129    localtime_r(&current_time, &selected_time);
130    elm_calendar_mark_add(cal3, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
131    elm_calendar_marks_clear(cal3);
132    current_time = time(NULL);
133    localtime_r(&current_time, &selected_time);
134    elm_calendar_mark_add(cal3, "checked", &selected_time, ELM_CALENDAR_DAILY);
135    elm_calendar_mark_add(cal3, "holiday", &selected_time, ELM_CALENDAR_DAILY);
136    elm_calendar_marks_draw(cal3);
137    evas_object_show(cal3);
138    elm_box_pack_end(bxh, cal3);
139
140    en = elm_entry_add(win);
141    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
142    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
143    evas_object_show(en);
144    elm_box_pack_end(bx, en);
145    elm_entry_editable_set(en, EINA_FALSE);
146    evas_object_show(win);
147
148    elm_calendar_min_max_year_set(cal3, -1, -1);
149
150    elm_calendar_weekdays_names_set(cal, weekdays);
151    elm_calendar_interval_set(cal, 0.4);
152    elm_calendar_format_function_set(cal, _format_month_year);
153    elm_calendar_min_max_year_set(cal, 2010, 2020);
154
155    current_time = time(NULL) + 4 * 84600;
156    localtime_r(&current_time, &selected_time);
157    elm_calendar_mark_add(cal, "holiday", &selected_time, ELM_CALENDAR_ANNUALLY);
158
159    current_time = time(NULL) + 1 * 84600;
160    localtime_r(&current_time, &selected_time);
161    elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
162
163    current_time = time(NULL) - 363 * 84600;
164    localtime_r(&current_time, &selected_time);
165    elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_MONTHLY);
166
167    current_time = time(NULL) - 5 * 84600;
168    localtime_r(&current_time, &selected_time);
169    mark = elm_calendar_mark_add(cal, "holiday", &selected_time,
170          ELM_CALENDAR_WEEKLY);
171
172    current_time = time(NULL) + 1 * 84600;
173    localtime_r(&current_time, &selected_time);
174    elm_calendar_mark_add(cal, "holiday", &selected_time, ELM_CALENDAR_WEEKLY);
175
176    elm_calendar_mark_del(mark);
177    elm_calendar_marks_draw(cal);
178
179    _print_cal_info(cal, en);
180    evas_object_smart_callback_add(cal, "changed", _print_cal_info_cb, en);
181 }
182
183 #endif