2 # include "elementary_config.h"
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
8 unsigned int state; /* What state we are testing */
9 void *box; /* box used in set_api_state */
11 typedef struct _api_data api_data;
17 STATE_SUNDAY_HIGHLIGHT,
18 STATE_SELECT_DATE_DISABLED_WITH_MARKS,
19 STATE_SELECT_DATE_DISABLED_NO_MARKS,
22 typedef enum _api_state api_state;
25 set_api_state(api_data *api)
27 const Eina_List *items = elm_box_children_get(api->box);
28 static Elm_Calendar_Mark *m = NULL;
29 if (!eina_list_count(items))
33 { /* Put all api-changes under switch */
34 case STATE_MARK_MONTHLY:
36 Evas_Object *cal = eina_list_nth(items, 0);
37 time_t sec_per_day = (60*60*24);
38 time_t sec_per_year = sec_per_day * 365;
39 time_t the_time = (sec_per_year * 41) + (sec_per_day * 9); /* Set date to DEC 31, 2010 */
40 elm_calendar_min_max_year_set(cal, 2010, 2011);
41 m = elm_calendar_mark_add(cal, "checked", gmtime(&the_time), ELM_CALENDAR_MONTHLY);
42 elm_calendar_selected_time_set(cal, gmtime(&the_time));
45 case STATE_MARK_WEEKLY:
47 Evas_Object *cal = eina_list_nth(items, 0);
48 time_t sec_per_day = (60*60*24);
49 time_t sec_per_year = sec_per_day * 365;
50 time_t the_time = (sec_per_year * 41) + (sec_per_day * 4); /* Set date to DEC 26, 2010 */
51 elm_calendar_mark_del(m);
52 m = elm_calendar_mark_add(cal, "checked", gmtime(&the_time), ELM_CALENDAR_WEEKLY);
53 elm_calendar_selected_time_set(cal, gmtime(&the_time));
56 case STATE_SUNDAY_HIGHLIGHT:
58 Evas_Object *cal = eina_list_nth(items, 0);
59 time_t sec_per_day = (60*60*24);
60 time_t sec_per_year = sec_per_day * 365;
61 time_t the_time = (sec_per_year * 41) + (sec_per_day * 3); /* Set date to DEC 25, 2010 */
62 /* elm_calendar_mark_del(m); */
63 m = elm_calendar_mark_add(cal, "holiday", gmtime(&the_time), ELM_CALENDAR_WEEKLY);
64 elm_calendar_selected_time_set(cal, gmtime(&the_time));
67 case STATE_SELECT_DATE_DISABLED_WITH_MARKS:
69 Evas_Object *cal = eina_list_nth(items, 0);
70 time_t sec_per_day = (60*60*24);
71 time_t sec_per_year = sec_per_day * 365;
72 time_t the_time = (sec_per_year * 41) + (sec_per_day * 10); /* Set date to JAN 01, 2011 */
73 elm_calendar_day_selection_disabled_set(cal, EINA_TRUE);
74 elm_calendar_selected_time_set(cal, gmtime(&the_time));
77 case STATE_SELECT_DATE_DISABLED_NO_MARKS:
79 Evas_Object *cal = eina_list_nth(items, 0);
80 time_t sec_per_day = (60*60*24);
81 time_t sec_per_year = sec_per_day * 365;
82 time_t the_time = (sec_per_year * 41) + (sec_per_day * 40); /* Set date to FEB 01, 2011 */
83 elm_calendar_marks_clear(cal);
84 elm_calendar_day_selection_disabled_set(cal, EINA_TRUE);
85 elm_calendar_selected_time_set(cal, gmtime(&the_time));
96 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
97 { /* Will add here a SWITCH command containing code to modify test-object */
98 /* in accordance a->state value. */
102 printf("clicked event on API Button: api_state=<%d>\n", a->state);
105 sprintf(str, "Next API function (%u)", a->state);
106 elm_object_text_set(obj, str);
107 elm_object_disabled_set(obj, a->state == API_STATE_LAST);
111 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
116 /* A simple test, just displaying calendar in it's default state */
118 test_calendar(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
120 Evas_Object *win, *cal, *bx, *bxx, *bt;
121 api_data *api = calloc(1, sizeof(api_data));
123 win = elm_win_util_standard_add("calendar", "Calendar");
124 elm_win_autodel_set(win, EINA_TRUE);
125 evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
127 bxx = elm_box_add(win);
128 elm_win_resize_object_add(win, bxx);
129 evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130 evas_object_show(bxx);
132 bx = elm_box_add(win);
133 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135 evas_object_show(bx);
137 bt = elm_button_add(win);
138 elm_object_text_set(bt, "Next API function");
139 evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
140 elm_box_pack_end(bxx, bt);
141 elm_object_disabled_set(bt, api->state == API_STATE_LAST);
142 evas_object_show(bt);
144 elm_box_pack_end(bxx, bx);
146 cal = elm_calendar_add(win);
147 elm_calendar_first_day_of_week_set(cal, ELM_DAY_MONDAY);
148 evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
149 elm_box_pack_end(bx, cal);
151 time_t sec_per_day = (60*60*24);
152 time_t sec_per_year = sec_per_day * 365;
153 time_t the_time = (sec_per_year * 41) + (sec_per_day * 9); /* Set date to DEC 31, 2010 */
154 elm_calendar_selected_time_set(cal, gmtime(&the_time));
155 elm_calendar_min_max_year_set(cal, 2010, 2012);
157 evas_object_show(cal);
159 evas_object_show(win);
163 _print_cal_info(Evas_Object *cal, Evas_Object *en)
167 int year_min, year_max;
168 Eina_Bool sel_enabled;
172 if (!elm_calendar_selected_time_get(cal, &stm))
175 interval = elm_calendar_interval_get(cal);
176 elm_calendar_min_max_year_get(cal, &year_min, &year_max);
177 sel_enabled = !elm_calendar_day_selection_disabled_get(cal);
178 wds = elm_calendar_weekdays_names_get(cal);
180 snprintf(info, sizeof(info),
181 " Day: %i, Mon: %i, Year %i, WeekDay: %i<br/>"
182 " Interval: %0.2f, Year_Min: %i, Year_Max %i, Sel Enabled : %i<br/>"
183 " Weekdays: %s, %s, %s, %s, %s, %s, %s<br/>",
184 stm.tm_mday, stm.tm_mon, stm.tm_year + 1900, stm.tm_wday,
185 interval, year_min, year_max, sel_enabled,
186 wds[0], wds[1], wds[2], wds[3], wds[4], wds[5], wds[6]);
188 elm_object_text_set(en, info);
192 _print_cal_info_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
194 _print_cal_info(obj, data);
198 _format_month_year(struct tm *stm)
201 if (!strftime(buf, sizeof(buf), "%b %y", stm)) return NULL;
205 /* A test intended to cover all the calendar api and much use cases as
208 test_calendar2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
210 Evas_Object *win, *bx, *bxh, *cal, *cal2, *cal3, *en;
211 Elm_Calendar_Mark *mark;
212 struct tm selected_time;
214 const char *weekdays[] =
216 "Sunday", "Monday", "Tuesday", "Wednesday",
217 "Thursday", "Friday", "Saturday"
220 win = elm_win_util_standard_add("calendar2", "Calendar 2");
221 elm_win_autodel_set(win, EINA_TRUE);
223 bx = elm_box_add(win);
224 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
225 elm_win_resize_object_add(win, bx);
226 evas_object_show(bx);
228 bxh = elm_box_add(win);
229 elm_box_horizontal_set(bxh, EINA_TRUE);
230 evas_object_size_hint_weight_set(bxh, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
231 evas_object_size_hint_align_set(bxh, EVAS_HINT_FILL, EVAS_HINT_FILL);
232 evas_object_show(bxh);
233 elm_box_pack_end(bx, bxh);
235 cal = elm_calendar_add(win);
236 evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
237 evas_object_size_hint_align_set(cal, EVAS_HINT_FILL, EVAS_HINT_FILL);
238 evas_object_show(cal);
239 elm_box_pack_end(bx, cal);
241 cal2 = elm_calendar_add(win);
242 evas_object_size_hint_weight_set(cal2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
243 evas_object_size_hint_align_set(cal2, EVAS_HINT_FILL, EVAS_HINT_FILL);
244 elm_calendar_day_selection_disabled_set(cal2, EINA_TRUE);
245 evas_object_show(cal2);
246 elm_box_pack_end(bxh, cal2);
248 cal3 = elm_calendar_add(win);
249 evas_object_size_hint_weight_set(cal3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
250 evas_object_size_hint_align_set(cal3, EVAS_HINT_FILL, EVAS_HINT_FILL);
251 current_time = time(NULL) + 34 * 84600;
252 localtime_r(¤t_time, &selected_time);
253 elm_calendar_selected_time_set(cal3, &selected_time);
254 current_time = time(NULL) + 1 * 84600;
255 localtime_r(¤t_time, &selected_time);
256 elm_calendar_mark_add(cal3, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
257 elm_calendar_marks_clear(cal3);
258 current_time = time(NULL);
259 localtime_r(¤t_time, &selected_time);
260 elm_calendar_mark_add(cal3, "checked", &selected_time, ELM_CALENDAR_DAILY);
261 elm_calendar_mark_add(cal3, "holiday", &selected_time, ELM_CALENDAR_DAILY);
262 elm_calendar_marks_draw(cal3);
263 evas_object_show(cal3);
264 elm_box_pack_end(bxh, cal3);
266 en = elm_entry_add(win);
267 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
268 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
269 evas_object_show(en);
270 elm_box_pack_end(bx, en);
271 elm_entry_editable_set(en, EINA_FALSE);
272 evas_object_show(win);
274 elm_calendar_min_max_year_set(cal3, -1, -1);
276 elm_calendar_weekdays_names_set(cal, weekdays);
277 elm_calendar_first_day_of_week_set(cal, ELM_DAY_SATURDAY);
278 elm_calendar_interval_set(cal, 0.4);
279 elm_calendar_format_function_set(cal, _format_month_year);
280 elm_calendar_min_max_year_set(cal, 2010, 2020);
282 current_time = time(NULL) + 4 * 84600;
283 localtime_r(¤t_time, &selected_time);
284 elm_calendar_mark_add(cal, "holiday", &selected_time, ELM_CALENDAR_ANNUALLY);
286 current_time = time(NULL) + 1 * 84600;
287 localtime_r(¤t_time, &selected_time);
288 elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
290 current_time = time(NULL) - 363 * 84600;
291 localtime_r(¤t_time, &selected_time);
292 elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_MONTHLY);
294 current_time = time(NULL) - 5 * 84600;
295 localtime_r(¤t_time, &selected_time);
296 mark = elm_calendar_mark_add(cal, "holiday", &selected_time,
297 ELM_CALENDAR_WEEKLY);
299 current_time = time(NULL) + 1 * 84600;
300 localtime_r(¤t_time, &selected_time);
301 elm_calendar_mark_add(cal, "holiday", &selected_time, ELM_CALENDAR_WEEKLY);
303 elm_calendar_mark_del(mark);
304 elm_calendar_marks_draw(cal);
306 _print_cal_info(cal, en);
307 evas_object_smart_callback_add(cal, "changed", _print_cal_info_cb, en);