[JungWooHyun] doing merge job ~
[framework/uifw/elementary.git] / src / examples / dayselector_example.c
1 /**
2  * Simple Elementary's <b>dayselector widget</b> example, illustrating its
3  * usage and API.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g `pkg-config --cflags --libs elementary` dayselector_example.c -o dayselector_example
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #else
16 # define __UNUSED__
17 #endif
18
19 static void
20 _on_done(void *data __UNUSED__,
21         Evas_Object *obj __UNUSED__,
22         void *event_info __UNUSED__)
23 {
24    elm_exit();
25 }
26
27 /* Callback function when a day is clicked. */
28 static void _changed_cb(void* data __UNUSED__, Evas_Object* obj, void* event_info)
29 {
30    char buf[256];
31    Elm_Dayselector_Day day;
32    Eina_Bool selected;
33
34    /* get which day's state is changed */
35    day = (Elm_Dayselector_Day) event_info;
36    /* get the state of corresponding day's check object */
37    selected = elm_dayselector_day_selected_get(obj, day);
38    switch(day)
39      {
40       case ELM_DAYSELECTOR_SUN: snprintf(buf, sizeof(buf), "%s", "Sun");   break;
41       case ELM_DAYSELECTOR_MON: snprintf(buf, sizeof(buf), "%s", "Mon");   break;
42       case ELM_DAYSELECTOR_TUE: snprintf(buf, sizeof(buf), "%s", "Tue");   break;
43       case ELM_DAYSELECTOR_WED: snprintf(buf, sizeof(buf), "%s", "Wed");   break;
44       case ELM_DAYSELECTOR_THU: snprintf(buf, sizeof(buf), "%s", "Thu");   break;
45       case ELM_DAYSELECTOR_FRI: snprintf(buf, sizeof(buf), "%s", "Fri");   break;
46       case ELM_DAYSELECTOR_SAT: snprintf(buf, sizeof(buf), "%s", "Sat");   break;
47       default: snprintf(buf, sizeof(buf), "%s", "???"); break;
48      }
49    fprintf(stderr, "%s state is %d\n", buf, selected);
50 }
51 /* End of clicked callback */
52
53 int
54 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
55 {
56    Evas_Object *win, *bg, *bx, *dayselector;
57
58    win = elm_win_add(NULL, "dayselector", ELM_WIN_BASIC);
59    elm_win_title_set(win, "Dayselector Example");
60    evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
61
62    bg = elm_bg_add(win);
63    elm_win_resize_object_add(win, bg);
64    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
65    evas_object_show(bg);
66
67    bx = elm_box_add(win);
68    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69    elm_win_resize_object_add(win, bx);
70    evas_object_show(bx);
71
72    /* add a dayselector widget showing weekdays starting from Sunday */
73    dayselector = elm_dayselector_add(win);
74    evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75    evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
76    evas_object_smart_callback_add(dayselector, "dayselector,changed", _changed_cb, NULL);
77    elm_box_pack_end(bx, dayselector);
78    evas_object_show(dayselector);
79
80    /* add a dayselector widget showing weekdays starting from Monday */
81    dayselector = elm_dayselector_add(win);
82    evas_object_size_hint_weight_set(dayselector, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
83    evas_object_size_hint_align_set(dayselector, EVAS_HINT_FILL, 0.5);
84    evas_object_smart_callback_add(dayselector, "dayselector,changed", _changed_cb, NULL);
85    elm_object_style_set(dayselector, "mon_first");
86    elm_box_pack_end(bx, dayselector);
87    evas_object_show(dayselector);
88
89    evas_object_resize(win, 350, 120);
90    evas_object_show(win);
91
92    elm_run();
93    return 0;
94 }
95 ELM_MAIN()