[focus] When an object has focus_chain manager, it should return its own next object...
[framework/uifw/elementary.git] / src / examples / general_funcs_example.c
1 /* Compile with:
2  * gcc -g general_funcs_example.c -o general_funcs_example `pkg-config --cflags --libs elementary`
3  */
4
5 #include <Elementary.h>
6
7 #define BIN_DIR  "/usr/bin"
8 #define LIB_DIR  "/usr/lib"
9 #define DATA_DIR "/usr/local/share/elementary"
10
11 #define WIDTH             300
12 #define HEIGHT            300
13
14 struct test_data
15 {
16    Evas_Object *btn;
17    Eina_Bool    btn_enabled;
18    Eina_Bool    btn_gets_focus;
19 };
20
21 struct test_data d = {NULL, EINA_TRUE, EINA_TRUE};
22
23 static void
24 _btn_enabled_cb(void        *data,
25                 Evas_Object *obj,
26                 void        *event)
27 {
28    elm_object_disabled_set(d.btn, !d.btn_enabled);
29 }
30
31 static void
32 /* focus callback */
33 _btn_focus_cb(void        *data,
34               Evas_Object *obj,
35               void        *event)
36 {
37    elm_object_focus_set(d.btn, EINA_TRUE);
38 }
39
40 static void
41 /* unfocus callback */
42 _btn_unfocus_cb(void        *data,
43               Evas_Object *obj,
44               void        *event)
45 {
46    elm_object_focus_set(d.btn, EINA_FALSE);
47 }
48
49 static void
50 /* focus allow callback */
51 _btn_focus_allow_cb(void        *data,
52                     Evas_Object *obj,
53                     void        *event)
54 {
55    elm_object_focus_allow_set(d.btn, d.btn_gets_focus);
56 }
57
58 static void /* scaling callback */
59 _btn_scale_cb(void        *data,
60               Evas_Object *obj,
61               void        *event)
62 {
63    elm_object_scale_set(d.btn, elm_slider_value_get(obj));
64 }
65
66 EAPI_MAIN int
67 elm_main(int    argc,
68          char **argv)
69 {
70    Evas_Object *win, *bg, *box, *frame, *check, *b, *slider;
71
72    /* tell elm about our app so it can figure out where to get files */
73    elm_app_compile_bin_dir_set(BIN_DIR);
74    elm_app_compile_data_dir_set(DATA_DIR);
75    elm_app_compile_lib_dir_set(LIB_DIR);
76    elm_app_info_set(elm_main, "elementary", "images/logo.png");
77
78    fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get());
79    fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get());
80    fprintf(stdout, "library directory is: %s\n", elm_app_lib_dir_get());
81    fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get());
82
83    win = elm_win_add(NULL, "top-level-funcs-example", ELM_WIN_BASIC);
84    elm_win_title_set(win, "Elementary Top-level Functions Example");
85
86    /* by using this policy value, we avoid having to
87     * evas_object_smart_callback_add(win, "delete,request", _on_exit, NULL),
88     * calling elm_exit() on that callback ourselves.
89     */
90    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
91    elm_win_autodel_set(win, EINA_TRUE);
92
93    bg = elm_bg_add(win);
94    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
95    elm_win_resize_object_add(win, bg);
96    evas_object_show(bg);
97
98    /* outer box */
99    box = elm_box_add(win);
100    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
102    elm_win_resize_object_add(win, box);
103    evas_object_show(box);
104
105    frame = elm_frame_add(win);
106    elm_object_text_set(frame, "Button");
107    evas_object_size_hint_align_set(frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
108    evas_object_show(frame);
109    elm_box_pack_end(box, frame);
110
111    d.btn = elm_button_add(win);
112    elm_object_text_set(d.btn, "Click me");
113    elm_object_content_set(frame, d.btn);
114    fprintf(stdout, "Elementary's finger size is set to %d pixels\n.",
115            elm_config_finger_size_get());
116    evas_object_show(d.btn);
117
118    b = elm_box_add(win);
119    elm_box_horizontal_set(b, EINA_FALSE);
120    evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
121    evas_object_size_hint_align_set(b, EVAS_HINT_FILL, EVAS_HINT_FILL);
122    elm_win_resize_object_add(win, b);
123    elm_box_pack_end(box, b);
124    evas_object_show(b);
125
126    check = elm_check_add(win);
127    evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128    evas_object_size_hint_align_set(check, 0.0, 0.0);
129    elm_object_text_set(check, "Button enabled");
130    elm_check_state_pointer_set(check, &d.btn_enabled);
131    evas_object_smart_callback_add(check, "changed", _btn_enabled_cb, NULL);
132    elm_box_pack_end(box, check);
133    evas_object_show(check);
134
135    b = elm_button_add(win);
136    evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
137    evas_object_size_hint_align_set(b, 0.0, 0.0);
138    elm_object_text_set(b, "Focus top button");
139    evas_object_smart_callback_add(b, "clicked", _btn_focus_cb, NULL);
140    elm_box_pack_end(box, b);
141    evas_object_show(b);
142
143    b = elm_button_add(win);
144    evas_object_size_hint_weight_set(b, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
145    evas_object_size_hint_align_set(b, 0.0, 0.0);
146    elm_object_text_set(b, "Unfocus top button");
147    evas_object_smart_callback_add(b, "clicked", _btn_unfocus_cb, NULL);
148    elm_box_pack_end(box, b);
149    evas_object_show(b);
150
151    check = elm_check_add(win);
152    evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
153    evas_object_size_hint_align_set(check, 0.0, 0.0);
154    elm_object_text_set(check, "Button gets focus");
155    elm_check_state_pointer_set(check, &d.btn_gets_focus);
156    evas_object_smart_callback_add(check, "changed", _btn_focus_allow_cb, NULL);
157    elm_box_pack_end(box, check);
158    evas_object_show(check);
159
160    slider = elm_slider_add(win);
161    elm_slider_min_max_set(slider, 0, 4);
162    elm_slider_unit_format_set(slider, "%1.1f");
163    elm_slider_indicator_format_set(slider, "%1.1f");
164    evas_object_size_hint_weight_set(
165      slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
166    evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL);
167    evas_object_smart_callback_add(slider, "changed", _btn_scale_cb, NULL);
168    elm_box_pack_end(box, slider);
169    evas_object_show(slider);
170
171    evas_object_resize(win, WIDTH, HEIGHT);
172    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
173    evas_object_show(win);
174
175    elm_run(); /* and run the program now, starting to handle all
176                * events, etc. */
177    elm_shutdown(); /* clean up and shut down */
178
179    /* exit code */
180    return 0;
181 }
182 ELM_MAIN()