Elementary migration revision 70341
[framework/uifw/elementary.git] / src / bin / test_focus.c
1 /* Test for Focus Chain Linear*/
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #include <Elementary.h>
6 #ifndef ELM_LIB_QUICKLAUNCH
7
8 static Eina_Bool
9 _event(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
10 {
11    if (type == EVAS_CALLBACK_KEY_DOWN)
12      printf ("Key Down:");
13    else if (type == EVAS_CALLBACK_KEY_UP)
14      printf ("Key Up:");
15    else
16      return EINA_FALSE;
17    Evas_Event_Key_Down *ev = event_info;
18    printf("%s\n", ev->key);
19
20    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
21    return EINA_TRUE;
22 }
23
24 static void
25 _on_key_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *einfo __UNUSED__)
26 {
27    //Evas_Event_Key_Down *event = einfo;
28    //printf("%s %p Key %s Parent %p\n", evas_object_type_get(obj),
29    //       obj, event->keyname, evas_object_smart_parent_get(obj));
30 }
31
32 static void
33 _disable(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
34 {
35    Evas_Object *bt = data;
36    elm_object_disabled_set(bt, EINA_TRUE);
37 }
38
39 static void
40 _enable(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
41 {
42    Evas_Object *bt = data;
43    elm_object_disabled_set(bt, EINA_FALSE);
44 }
45
46 static inline void
47 my_show(Evas_Object *obj)
48 {
49    evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
50                                   _on_key_down, NULL);
51    evas_object_show(obj);
52 }
53
54 void
55 test_focus(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
56 {
57    Evas_Object *win;
58    unsigned int i, j;
59
60    win = elm_win_util_standard_add("focus", "Focus");
61    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
62    evas_object_resize(win, 800, 600);
63    elm_object_event_callback_add(win, _event, NULL);
64    elm_win_autodel_set(win, EINA_TRUE);
65    my_show(win);
66
67    Evas_Object *mainbx = elm_box_add(win);
68    elm_box_horizontal_set(mainbx, EINA_TRUE);
69    elm_win_resize_object_add(win, mainbx);
70    evas_object_size_hint_weight_set(mainbx, EVAS_HINT_EXPAND,
71                                     EVAS_HINT_EXPAND);
72    my_show(mainbx);
73
74      { //First Col
75         Evas_Object *bx = elm_box_add(win);
76         evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
77                                          EVAS_HINT_EXPAND);
78         elm_box_pack_end(mainbx, bx);
79         my_show(bx);
80
81           {
82              Evas_Object *lb = elm_label_add(win);
83              elm_object_text_set(lb, "<b>Use Tab or Shift+Tab</b>");
84              evas_object_size_hint_weight_set(lb, 0.0, 0.0);
85              evas_object_size_hint_align_set(lb, EVAS_HINT_FILL,
86                                              EVAS_HINT_FILL);
87              elm_box_pack_end(bx, lb);
88              my_show(lb);
89           }
90
91           {
92              Evas_Object *tg = elm_check_add(win);
93              elm_object_style_set(tg, "toggle");
94              elm_object_part_text_set(tg, "on", "Yes");
95              elm_object_part_text_set(tg, "off", "No");
96              elm_box_pack_end(bx, tg);
97              my_show(tg);
98           }
99
100           {
101              Evas_Object *en = elm_entry_add(win);
102              elm_entry_scrollable_set(en, EINA_TRUE);
103              evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
104              evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
105              elm_object_text_set(en, "This is a single line");
106              elm_entry_single_line_set(en, EINA_TRUE);
107              elm_box_pack_end(bx, en);
108              my_show(en);
109           }
110
111           {
112              Evas_Object *bx2 = elm_box_add(win);
113              elm_box_horizontal_set(bx2, EINA_TRUE);
114              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
115                                              EVAS_HINT_FILL);
116              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
117              elm_box_pack_end(bx, bx2);
118
119              for (i = 2; i; i--)
120                {
121                   Evas_Object *bt;
122                   bt = elm_button_add(win);
123                   elm_object_text_set(bt, "Box");
124                   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
125                                                   EVAS_HINT_FILL);
126                   evas_object_size_hint_weight_set(bt, 0.0, 0.0);
127                   if (i%2)
128                     elm_object_disabled_set(bt, EINA_TRUE);
129                   elm_box_pack_end(bx2, bt);
130                   my_show(bt);
131                }
132
133                {
134                   Evas_Object *sc = elm_scroller_add(win);
135                   evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND,
136                                                    EVAS_HINT_EXPAND);
137                   evas_object_size_hint_align_set(sc, EVAS_HINT_FILL,
138                                                   EVAS_HINT_FILL);
139                   elm_scroller_bounce_set(sc, EINA_TRUE, EINA_TRUE);
140                   elm_scroller_content_min_limit(sc, 1, 1);
141                   elm_box_pack_end(bx2, sc);
142                   my_show(sc);
143
144                     {
145                        Evas_Object *bt;
146                        bt = elm_button_add(win);
147                        elm_object_text_set(bt, "Scroller");
148                        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
149                                                        EVAS_HINT_FILL);
150                        evas_object_size_hint_weight_set(bt, 0.0, 0.0);
151                        elm_object_event_callback_add(bt, _event, NULL);
152                        elm_object_content_set(sc, bt);
153                        my_show(bt);
154                        elm_object_event_callback_del(bt, _event, NULL);
155                     }
156                }
157
158              my_show(bx2);
159           }
160
161           {
162              Evas_Object *bt;
163              bt = elm_button_add(win);
164              elm_object_text_set(bt, "Box");
165              evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
166                                              EVAS_HINT_FILL);
167              evas_object_size_hint_weight_set(bt, 0.0, 0.0);
168              elm_box_pack_end(bx, bt);
169              my_show(bt);
170           }
171
172           {
173              Evas_Object *bx2 = elm_box_add(win);
174              elm_box_horizontal_set(bx2, EINA_TRUE);
175              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
176                                              EVAS_HINT_FILL);
177              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
178              elm_box_pack_end(bx, bx2);
179              my_show(bx2);
180
181              for (i = 2; i; i--)
182                {
183                   Evas_Object *bx3 = elm_box_add(win);
184                   evas_object_size_hint_align_set(bx3, EVAS_HINT_FILL,
185                                                   EVAS_HINT_FILL);
186                   evas_object_size_hint_weight_set(bx3, 0.0, 0.0);
187                   elm_box_pack_end(bx2, bx3);
188                   my_show(bx3);
189
190                   for (j = 3; j; j--)
191                     {
192                        Evas_Object *bt;
193                        bt = elm_button_add(win);
194                        elm_object_text_set(bt, "Box");
195                        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
196                                                        EVAS_HINT_FILL);
197                        evas_object_size_hint_weight_set(bt, 0.0, 0.0);
198                        elm_box_pack_end(bx3, bt);
199                        my_show(bt);
200                     }
201                }
202
203                {
204                   Evas_Object *sc = elm_scroller_add(win);
205                   evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND,
206                                                    EVAS_HINT_EXPAND);
207                   evas_object_size_hint_align_set(sc, EVAS_HINT_FILL,
208                                                   EVAS_HINT_FILL);
209                   elm_scroller_bounce_set(sc, EINA_FALSE, EINA_TRUE);
210                   elm_scroller_content_min_limit(sc, 1, 0);
211                   elm_box_pack_end(bx2, sc);
212                   my_show(sc);
213
214                   Evas_Object *bx3 = elm_box_add(win);
215                   evas_object_size_hint_align_set(bx3, EVAS_HINT_FILL,
216                                                   EVAS_HINT_FILL);
217                   evas_object_size_hint_weight_set(bx3, 0.0, 0.0);
218                   elm_object_content_set(sc, bx3);
219                   my_show(bx3);
220
221                   for (i = 5; i; i--)
222                     {
223                        Evas_Object *bt;
224                        bt = elm_button_add(win);
225                        elm_object_text_set(bt, "BX Scroller");
226                        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
227                                                        EVAS_HINT_FILL);
228                        evas_object_size_hint_weight_set(bt, 0.0, 0.0);
229                        elm_box_pack_end(bx3, bt);
230                        my_show(bt);
231                     }
232                }
233           }
234      }
235
236      {//Second Col
237         char buf[PATH_MAX];
238         Evas_Object *ly = elm_layout_add(win);
239         snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
240         elm_layout_file_set(ly, buf, "twolines");
241         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND,
242                                          EVAS_HINT_EXPAND);
243         elm_box_pack_end(mainbx, ly);
244         my_show(ly);
245
246           {
247              Evas_Object *bx2 = elm_box_add(win);
248              elm_box_horizontal_set(bx2, EINA_TRUE);
249              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
250                                              EVAS_HINT_FILL);
251              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
252              elm_object_part_content_set(ly, "element1", bx2);
253              my_show(bx2);
254
255              for (i = 3; i; i--)
256                {
257                   Evas_Object *bt;
258                   bt = elm_button_add(win);
259                   elm_object_text_set(bt, "Layout");
260                   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
261                                                   EVAS_HINT_FILL);
262                   evas_object_size_hint_weight_set(bt, 0.0, 0.0);
263                   elm_box_pack_end(bx2, bt);
264                   my_show(bt);
265                   elm_object_focus_custom_chain_prepend(bx2, bt, NULL);
266                }
267           }
268
269           {
270              Evas_Object *bx2 = elm_box_add(win);
271              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
272                                              EVAS_HINT_FILL);
273              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
274              elm_object_part_content_set(ly, "element2", bx2);
275              my_show(bx2);
276
277                {
278                   Evas_Object *bt;
279                   bt = elm_button_add(win);
280                   elm_object_text_set(bt, "Disable");
281                   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
282                                                   EVAS_HINT_FILL);
283                   evas_object_size_hint_weight_set(bt, 0.0, 0.0);
284                   elm_box_pack_end(bx2, bt);
285                   evas_object_smart_callback_add(bt, "clicked", _disable, bt);
286                   my_show(bt);
287                   elm_object_focus_custom_chain_prepend(bx2, bt, NULL);
288
289                   Evas_Object *bt2;
290                   bt2 = elm_button_add(win);
291                   elm_object_text_set(bt2, "Enable");
292                   evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL,
293                                                   EVAS_HINT_FILL);
294                   evas_object_size_hint_weight_set(bt2, 0.0, 0.0);
295                   elm_box_pack_end(bx2, bt2);
296                   evas_object_smart_callback_add(bt2, "clicked", _enable, bt);
297                   my_show(bt2);
298                   elm_object_focus_custom_chain_append(bx2, bt2, NULL);
299                }
300
301           }
302      }
303
304      {//Third Col
305         Evas_Object *bx = elm_box_add(win);
306         evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
307                                          EVAS_HINT_EXPAND);
308         elm_box_pack_end(mainbx, bx);
309         my_show(bx);
310
311           {
312              Evas_Object *fr = elm_frame_add(win);
313              elm_object_text_set(fr, "Frame");
314              elm_box_pack_end(bx, fr);
315              evas_object_show(fr);
316
317                {
318                   Evas_Object *tb = elm_table_add(win);
319                   evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
320                   elm_object_content_set(fr, tb);
321                   my_show(tb);
322                   for (j = 0; j < 1; j++)
323                     for (i = 0; i < 2; i++)
324                       {
325                          Evas_Object *bt;
326                          bt = elm_button_add(win);
327                          elm_object_text_set(bt, "Table");
328                          evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
329                                                          EVAS_HINT_FILL);
330                          evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
331                          elm_table_pack(tb, bt, i, j, 1, 1);
332                          my_show(bt);
333                       }
334                }
335           }
336
337           {
338              Evas_Object *fr = elm_bubble_add(win);
339              elm_object_text_set(fr, "Bubble");
340              evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
341              evas_object_size_hint_align_set(fr, EVAS_HINT_FILL,
342                                              EVAS_HINT_FILL);
343              elm_box_pack_end(bx, fr);
344              evas_object_show(fr);
345
346                {
347                   Evas_Object *tb = elm_table_add(win);
348                   evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
349                   elm_object_content_set(fr, tb);
350                   my_show(tb);
351                   for (j = 0; j < 2; j++)
352                     for (i = 0; i < 1; i++)
353                       {
354                          Evas_Object *bt;
355                          bt = elm_button_add(win);
356                          elm_object_text_set(bt, "Table");
357                          evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
358                                                          EVAS_HINT_FILL);
359                          evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
360                          elm_table_pack(tb, bt, i, j, 1, 1);
361                          my_show(bt);
362                       }
363                }
364           }
365      }
366 }
367 #endif