1 /* Test for Focus Chain Linear*/
2 #include <Elementary.h>
4 # include "elementary_config.h"
6 #ifndef ELM_LIB_QUICKLAUNCH
8 static Evas_Object *foc = NULL;
11 _foc(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
14 printf("foc -> %p\n", foc);
18 _unfoc(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
21 printf("foc -> %p\n", foc);
25 _add(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
27 Evas_Object *bx = data, *en;
29 en = elm_entry_add(elm_object_top_widget_get(bx));
30 elm_entry_scrollable_set(en, EINA_TRUE);
31 elm_object_text_set(en, "An entry");
32 evas_object_smart_callback_add(en, "focused", _foc, NULL);
33 evas_object_smart_callback_add(en, "unfocused", _unfoc, NULL);
34 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
35 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
36 elm_entry_single_line_set(en, EINA_TRUE);
37 elm_box_pack_start(bx, en);
42 _del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
44 if (foc) evas_object_del(foc);
48 _hide(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
50 if (foc) evas_object_hide(foc);
54 test_focus3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
56 Evas_Object *win, *bg, *bx, *bt, *en;
58 win = elm_win_add(NULL, "focus3", ELM_WIN_BASIC);
59 elm_win_title_set(win, "Focus 3");
60 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
61 evas_object_resize(win, 320, 480);
62 elm_win_autodel_set(win, EINA_TRUE);
65 elm_win_resize_object_add(win, bg);
66 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69 bx = elm_box_add(win);
70 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
71 elm_win_resize_object_add(win, bx);
74 en = elm_entry_add(win);
75 elm_entry_scrollable_set(en, EINA_TRUE);
76 elm_object_text_set(en, "An entry");
77 evas_object_smart_callback_add(en, "focused", _foc, NULL);
78 evas_object_smart_callback_add(en, "unfocused", _unfoc, NULL);
79 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
80 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
81 elm_entry_single_line_set(en, EINA_TRUE);
82 elm_box_pack_end(bx, en);
85 bt = elm_button_add(win);
86 elm_object_focus_allow_set(bt, 0);
87 elm_object_text_set(bt, "Add");
88 evas_object_smart_callback_add(bt, "clicked", _add, bx);
89 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
90 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
91 elm_box_pack_end(bx, bt);
94 bt = elm_button_add(win);
95 elm_object_focus_allow_set(bt, 0);
96 elm_object_text_set(bt, "Del");
97 evas_object_smart_callback_add(bt, "clicked", _del, NULL);
98 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
99 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
100 elm_box_pack_end(bx, bt);
101 evas_object_show(bt);
103 bt = elm_button_add(win);
104 elm_object_focus_allow_set(bt, 0);
105 elm_object_text_set(bt, "Hide");
106 evas_object_smart_callback_add(bt, "clicked", _hide, NULL);
107 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
108 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0.5);
109 elm_box_pack_end(bx, bt);
110 evas_object_show(bt);
112 evas_object_show(win);
116 highlight_enabled_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
118 elm_focus_highlight_enabled_set(elm_check_state_get(obj));
122 highlight_animate_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
124 elm_focus_highlight_animate_set(elm_check_state_get(obj));
128 custom_chain_unset_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
130 Evas_Object *c, *child = NULL;
131 Evas_Object *bx = (Evas_Object *)data;
132 Eina_List *l, *children = NULL, *custom_chain = NULL;
135 if (elm_check_state_get(obj))
137 children = elm_box_children_get(bx);
138 EINA_LIST_FOREACH(children, l, c)
143 custom_chain = eina_list_append(custom_chain, c);
144 elm_object_focus_custom_chain_set(bx, custom_chain);
146 else if (i == 1) elm_object_focus_custom_chain_prepend(bx, c, child);
149 elm_object_focus_custom_chain_append(bx, c, child);
152 else if (i == 3) elm_object_focus_custom_chain_prepend(bx, c, child);
158 if (!elm_object_focus_custom_chain_get(bx)) return;
159 elm_object_focus_custom_chain_unset(bx);
164 create_win_bt_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
166 Evas_Object *win, *gd, *bt;
168 win = elm_win_util_standard_add("test focus", "Test Focus");
169 elm_win_autodel_set(win, EINA_TRUE);
171 gd = elm_grid_add(win);
172 elm_grid_size_set(gd, 100, 100);
173 evas_object_size_hint_weight_set(gd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174 elm_win_resize_object_add(win, gd);
175 evas_object_show(gd);
177 bt = elm_button_add(win);
178 elm_object_text_set(bt, "Button 1");
179 elm_grid_pack(gd, bt, 10, 10, 80, 20);
180 evas_object_show(bt);
182 bt = elm_button_add(win);
183 elm_object_text_set(bt, "Button 2");
184 elm_grid_pack(gd, bt, 10, 30, 80, 20);
185 evas_object_show(bt);
187 bt = elm_button_add(win);
188 elm_object_text_set(bt, "Button 3");
189 elm_grid_pack(gd, bt, 10, 50, 80, 20);
190 evas_object_show(bt);
192 bt = elm_button_add(win);
193 elm_object_text_set(bt, "Button 4");
194 elm_grid_pack(gd, bt, 10, 70, 80, 20);
195 evas_object_show(bt);
197 evas_object_resize(win, 160, 160);
198 evas_object_show(win);
202 test_focus4(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
204 Evas_Object *win, *gd, *tg, *bt;
205 Evas_Object *lb, *bt1, *bt2, *bt3, *bt4, *bx;
206 Eina_List *custom_chain = NULL;
208 win = elm_win_util_standard_add("focus4", "Focus 4");
209 elm_win_autodel_set(win, EINA_TRUE);
210 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
211 elm_focus_highlight_enabled_set(EINA_TRUE);
212 elm_focus_highlight_animate_set(EINA_TRUE);
214 /* First Example - Using Focus Highlight */
215 gd = elm_grid_add(win);
216 elm_grid_size_set(gd, 100, 100);
217 evas_object_size_hint_weight_set(gd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
218 elm_win_resize_object_add(win, gd);
219 evas_object_show(gd);
221 tg = elm_check_add(win);
222 evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
223 evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, EVAS_HINT_FILL);
224 elm_object_text_set(tg, "Focus Highlight Enabled");
225 elm_check_state_set(tg, EINA_TRUE);
226 evas_object_smart_callback_add(tg, "changed", highlight_enabled_cb, NULL);
227 elm_grid_pack(gd, tg, 10, 10, 50, 10);
228 evas_object_show(tg);
230 tg = elm_check_add(win);
231 evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
232 evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, EVAS_HINT_FILL);
233 elm_object_text_set(tg, "Focus Highlight Animate");
234 elm_check_state_set(tg, EINA_TRUE);
235 evas_object_smart_callback_add(tg, "changed", highlight_animate_cb, NULL);
236 elm_grid_pack(gd, tg, 10, 20, 50, 10);
237 evas_object_show(tg);
239 bt = elm_button_add(win);
240 elm_object_text_set(bt, "Create Window");
241 elm_grid_pack(gd, bt, 10, 30, 80, 10);
242 evas_object_smart_callback_add(bt, "clicked", create_win_bt_clicked, NULL);
243 evas_object_show(bt);
245 /* Second Example - Using Custom Chain */
246 lb = elm_label_add(win);
247 elm_object_text_set(lb, "Custom Chain: Please use tab key to check");
248 evas_object_size_hint_weight_set(lb, 0.0, 0.0);
249 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
250 elm_grid_pack(gd, lb, 10, 45, 80, 5);
251 evas_object_show(lb);
253 bx = elm_box_add(win);
254 elm_box_horizontal_set(bx, EINA_TRUE);
255 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
256 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
258 bt1 = elm_button_add(win);
259 elm_object_text_set(bt1, "Button 1");
260 evas_object_size_hint_weight_set(bt1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
261 evas_object_size_hint_align_set(bt1, EVAS_HINT_FILL, EVAS_HINT_FILL);
262 elm_box_pack_end(bx, bt1);
263 evas_object_show(bt1);
265 bt2 = elm_button_add(win);
266 elm_object_text_set(bt2, "Button 2");
267 evas_object_size_hint_weight_set(bt2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
268 evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
269 elm_box_pack_end(bx, bt2);
270 evas_object_show(bt2);
272 bt3 = elm_button_add(win);
273 elm_object_text_set(bt3, "Button 3");
274 evas_object_size_hint_weight_set(bt3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
275 evas_object_size_hint_align_set(bt3, EVAS_HINT_FILL, EVAS_HINT_FILL);
276 elm_box_pack_end(bx, bt3);
277 evas_object_show(bt3);
279 bt4 = elm_button_add(win);
280 elm_object_text_set(bt4, "Button 4");
281 evas_object_size_hint_weight_set(bt4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
282 evas_object_size_hint_align_set(bt4, EVAS_HINT_FILL, EVAS_HINT_FILL);
283 elm_box_pack_end(bx, bt4);
284 evas_object_show(bt4);
286 custom_chain = eina_list_append(custom_chain, bt2);
287 custom_chain = eina_list_append(custom_chain, bt1);
288 custom_chain = eina_list_append(custom_chain, bt4);
289 custom_chain = eina_list_append(custom_chain, bt3);
290 elm_object_focus_custom_chain_set(bx, custom_chain);
292 elm_grid_pack(gd, bx, 10, 50, 80, 30);
293 evas_object_show(bx);
295 tg = elm_check_add(win);
296 elm_object_text_set(tg, "Custom Chain");
297 elm_check_state_set(tg, EINA_TRUE);
298 evas_object_smart_callback_add(tg, "changed", custom_chain_unset_cb, bx);
299 elm_grid_pack(gd, tg, 10, 80, 40, 10);
300 evas_object_show(tg);
302 evas_object_resize(win, 320, 320);
303 evas_object_show(win);