875421277e6ee8085ac649999fc291b2ef816292
[framework/uifw/elementary.git] / src / examples / calendar_example_04.c
1 /**
2  * Elementary's <b>calendar widget</b> example, regarding date selection.
3  * Shows how to disable day selection by user and how to select a date.
4  * It selects two days from current day.
5  *
6  * See stdout/stderr for output. Compile with:
7  *
8  * @verbatim
9  * gcc -g `pkg-config --cflags --libs elementary` calendar_example_04.c -o calendar_example_04
10  * @endverbatim
11  */
12
13 #include <Elementary.h>
14 #ifdef HAVE_CONFIG_H
15 # include "elementary_config.h"
16 #else
17 # define __UNUSED__
18 #endif
19
20 #define SECS_DAY 86400
21
22 EAPI_MAIN int
23 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
24 {
25    Evas_Object *win, *bg, *bx, *cal, *cal2;
26    struct tm selected_time;
27    time_t current_time;
28
29    win = elm_win_add(NULL, "calendar", ELM_WIN_BASIC);
30    elm_win_title_set(win, "Calendar Day Selection Example");
31    elm_win_autodel_set(win, EINA_TRUE);
32
33    bg = elm_bg_add(win);
34    elm_win_resize_object_add(win, bg);
35    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
36    evas_object_show(bg);
37
38    bx = elm_box_add(win);
39    elm_win_resize_object_add(win, bx);
40    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
41    evas_object_show(bx);
42
43    cal = elm_calendar_add(win);
44    evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45    evas_object_size_hint_align_set(cal, EVAS_HINT_FILL, EVAS_HINT_FILL);
46    elm_calendar_day_selection_enabled_set(cal, EINA_FALSE);
47    evas_object_show(cal);
48    elm_box_pack_end(bx, cal);
49
50    cal2 = elm_calendar_add(win);
51    evas_object_size_hint_weight_set(cal2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
52    evas_object_size_hint_align_set(cal2, EVAS_HINT_FILL, EVAS_HINT_FILL);
53    current_time = time(NULL) + 2 * SECS_DAY;
54    localtime_r(&current_time, &selected_time);
55    elm_calendar_selected_time_set(cal2, &selected_time);
56    evas_object_show(cal2);
57    elm_box_pack_end(bx, cal2);
58
59    evas_object_show(win);
60
61    elm_run();
62    return 0;
63 }
64 ELM_MAIN()