931f72909317d66dfad3e5c76b83129ae176ae85
[framework/uifw/elementary.git] / src / bin / test_focus.c
1 /* Test for Focus Chain Linear*/
2 #include <Elementary.h>
3 #ifdef HAVE_CONFIG_H
4 # include "elementary_config.h"
5 #endif
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_add(NULL, "focus", ELM_WIN_BASIC);
61    elm_win_title_set(win, "Focus");
62    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
63    evas_object_resize(win, 800, 600);
64    elm_object_event_callback_add(win, _event, NULL);
65    elm_win_autodel_set(win, EINA_TRUE);
66    my_show(win);
67
68      {
69         Evas_Object *bg;
70         bg = elm_bg_add(win);
71         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
72                                          EVAS_HINT_EXPAND);
73         elm_win_resize_object_add(win, bg);
74         my_show(bg);
75      }
76
77    Evas_Object *mainbx = elm_box_add(win);
78    elm_box_horizontal_set(mainbx, EINA_TRUE);
79    elm_win_resize_object_add(win, mainbx);
80    evas_object_size_hint_weight_set(mainbx, EVAS_HINT_EXPAND,
81                                     EVAS_HINT_EXPAND);
82    my_show(mainbx);
83
84      { //First Col
85         Evas_Object *bx = elm_box_add(win);
86         evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
87                                          EVAS_HINT_EXPAND);
88         elm_box_pack_end(mainbx, bx);
89         my_show(bx);
90
91           {
92              Evas_Object *lb = elm_label_add(win);
93              elm_object_text_set(lb,
94                                  "<b>Use Tab and Shift+Tab</b>"
95                                 );
96              evas_object_size_hint_weight_set(lb, 0.0, 0.0);
97              evas_object_size_hint_align_set(lb, EVAS_HINT_FILL,
98                                              EVAS_HINT_FILL);
99              elm_box_pack_end(bx, lb);
100              my_show(lb);
101           }
102
103           {
104              Evas_Object *tg = elm_toggle_add(win);
105              elm_toggle_states_labels_set(tg, "Yes", "No");
106              elm_box_pack_end(bx, tg);
107              my_show(tg);
108           }
109
110           {
111              Evas_Object *en = elm_entry_add(win);
112              elm_entry_scrollable_set(en, EINA_TRUE);
113              evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
114              evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
115              elm_entry_entry_set(en, "This is a single line");
116              elm_entry_single_line_set(en, 1);
117              elm_box_pack_end(bx, en);
118              my_show(en);
119           }
120
121           {
122              Evas_Object *bx2 = elm_box_add(win);
123              elm_box_horizontal_set(bx2, EINA_TRUE);
124              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
125                                              EVAS_HINT_FILL);
126              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
127              elm_box_pack_end(bx, bx2);
128
129              for (i = 2; i; i--)
130                {
131                   Evas_Object *bt;
132                   bt = elm_button_add(win);
133                   elm_object_text_set(bt, "Box");
134                   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
135                                                   EVAS_HINT_FILL);
136                   evas_object_size_hint_weight_set(bt, 0.0, 0.0);
137                   if (i%2)
138                     elm_object_disabled_set(bt, EINA_TRUE);
139                   elm_box_pack_end(bx2, bt);
140                   my_show(bt);
141                }
142
143                {
144                   Evas_Object *sc = elm_scroller_add(win);
145                   evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND,
146                                                    EVAS_HINT_EXPAND);
147                   evas_object_size_hint_align_set(sc, EVAS_HINT_FILL,
148                                                   EVAS_HINT_FILL);
149                   elm_scroller_bounce_set(sc, 1, 1);
150                   elm_scroller_content_min_limit(sc, 1, 1);
151                   elm_box_pack_end(bx2, sc);
152                   my_show(sc);
153
154                     {
155                        Evas_Object *bt;
156                        bt = elm_button_add(win);
157                        elm_object_text_set(bt, "Scroller");
158                        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
159                                                        EVAS_HINT_FILL);
160                        evas_object_size_hint_weight_set(bt, 0.0, 0.0);
161                        elm_object_event_callback_add(bt, _event, NULL);
162                        elm_scroller_content_set(sc, bt);
163                        my_show(bt);
164                        elm_object_event_callback_del(bt, _event, NULL);
165                     }
166                }
167
168              my_show(bx2);
169           }
170
171           {
172              Evas_Object *bt;
173              bt = elm_button_add(win);
174              elm_object_text_set(bt, "Box");
175              evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
176                                              EVAS_HINT_FILL);
177              evas_object_size_hint_weight_set(bt, 0.0, 0.0);
178              elm_box_pack_end(bx, bt);
179              my_show(bt);
180           }
181
182           {
183              Evas_Object *bx2 = elm_box_add(win);
184              elm_box_horizontal_set(bx2, EINA_TRUE);
185              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
186                                              EVAS_HINT_FILL);
187              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
188              elm_box_pack_end(bx, bx2);
189              my_show(bx2);
190
191              for (i = 2; i; i--)
192                {
193                   Evas_Object *bx3 = elm_box_add(win);
194                   evas_object_size_hint_align_set(bx3, EVAS_HINT_FILL,
195                                                   EVAS_HINT_FILL);
196                   evas_object_size_hint_weight_set(bx3, 0.0, 0.0);
197                   elm_box_pack_end(bx2, bx3);
198                   my_show(bx3);
199
200                   for (j = 3; j; j--)
201                     {
202                        Evas_Object *bt;
203                        bt = elm_button_add(win);
204                        elm_object_text_set(bt, "Box");
205                        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
206                                                        EVAS_HINT_FILL);
207                        evas_object_size_hint_weight_set(bt, 0.0, 0.0);
208                        elm_box_pack_end(bx3, bt);
209                        my_show(bt);
210                     }
211                }
212
213                {
214                   Evas_Object *sc = elm_scroller_add(win);
215                   evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND,
216                                                    EVAS_HINT_EXPAND);
217                   evas_object_size_hint_align_set(sc, EVAS_HINT_FILL,
218                                                   EVAS_HINT_FILL);
219                   elm_scroller_bounce_set(sc, 0, 1);
220                   elm_scroller_content_min_limit(sc, 1, 0);
221                   elm_box_pack_end(bx2, sc);
222                   my_show(sc);
223
224                   Evas_Object *bx3 = elm_box_add(win);
225                   evas_object_size_hint_align_set(bx3, EVAS_HINT_FILL,
226                                                   EVAS_HINT_FILL);
227                   evas_object_size_hint_weight_set(bx3, 0.0, 0.0);
228                   elm_scroller_content_set(sc, bx3);
229                   my_show(bx3);
230
231                   for (i = 5; i; i--)
232                     {
233                        Evas_Object *bt;
234                        bt = elm_button_add(win);
235                        elm_object_text_set(bt, "BX Scroller");
236                        evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
237                                                        EVAS_HINT_FILL);
238                        evas_object_size_hint_weight_set(bt, 0.0, 0.0);
239                        elm_box_pack_end(bx3, bt);
240                        my_show(bt);
241                     }
242                }
243           }
244      }
245
246      {//Second Col
247         char buf[PATH_MAX];
248         Evas_Object *ly = elm_layout_add(win);
249         snprintf(buf, sizeof(buf), "%s/objects/test.edj", PACKAGE_DATA_DIR);
250         elm_layout_file_set(ly, buf, "twolines");
251         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND,
252                                          EVAS_HINT_EXPAND);
253         elm_box_pack_end(mainbx, ly);
254         my_show(ly);
255
256           {
257              Evas_Object *bx2 = elm_box_add(win);
258              elm_box_horizontal_set(bx2, EINA_TRUE);
259              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
260                                              EVAS_HINT_FILL);
261              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
262              elm_layout_content_set(ly, "element1", bx2);
263              my_show(bx2);
264
265              for (i = 3; i; i--)
266                {
267                   Evas_Object *bt;
268                   bt = elm_button_add(win);
269                   elm_object_text_set(bt, "Layout");
270                   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
271                                                   EVAS_HINT_FILL);
272                   evas_object_size_hint_weight_set(bt, 0.0, 0.0);
273                   elm_box_pack_end(bx2, bt);
274                   my_show(bt);
275                   elm_object_focus_custom_chain_prepend(bx2, bt, NULL);
276                }
277           }
278
279           {
280              Evas_Object *bx2 = elm_box_add(win);
281              evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL,
282                                              EVAS_HINT_FILL);
283              evas_object_size_hint_weight_set(bx2, 0.0, 0.0);
284              elm_layout_content_set(ly, "element2", bx2);
285              my_show(bx2);
286
287                {
288                   Evas_Object *bt;
289                   bt = elm_button_add(win);
290                   elm_object_text_set(bt, "Disable");
291                   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
292                                                   EVAS_HINT_FILL);
293                   evas_object_size_hint_weight_set(bt, 0.0, 0.0);
294                   elm_box_pack_end(bx2, bt);
295                   evas_object_smart_callback_add(bt, "clicked", _disable, bt);
296                   my_show(bt);
297                   elm_object_focus_custom_chain_prepend(bx2, bt, NULL);
298
299                   Evas_Object *bt2;
300                   bt2 = elm_button_add(win);
301                   elm_object_text_set(bt2, "Enable");
302                   evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL,
303                                                   EVAS_HINT_FILL);
304                   evas_object_size_hint_weight_set(bt2, 0.0, 0.0);
305                   elm_box_pack_end(bx2, bt2);
306                   evas_object_smart_callback_add(bt2, "clicked", _enable, bt);
307                   my_show(bt2);
308                   elm_object_focus_custom_chain_append(bx2, bt2, NULL);
309                }
310
311           }
312      }
313
314      {//Third Col
315         Evas_Object *bx = elm_box_add(win);
316         evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
317                                          EVAS_HINT_EXPAND);
318         elm_box_pack_end(mainbx, bx);
319         my_show(bx);
320
321           {
322              Evas_Object *fr = elm_frame_add(win);
323              elm_object_text_set(fr, "Frame");
324              elm_box_pack_end(bx, fr);
325              evas_object_show(fr);
326
327                {
328                   Evas_Object *tb = elm_table_add(win);
329                   evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330                   elm_frame_content_set(fr, tb);
331                   my_show(tb);
332                   for (j = 0; j < 1; j++)
333                     for (i = 0; i < 2; i++)
334                       {
335                          Evas_Object *bt;
336                          bt = elm_button_add(win);
337                          elm_object_text_set(bt, "Table");
338                          evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
339                                                          EVAS_HINT_FILL);
340                          evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
341                          elm_table_pack(tb, bt, i, j, 1, 1);
342                          my_show(bt);
343                       }
344                }
345           }
346
347           {
348              Evas_Object *fr = elm_bubble_add(win);
349              elm_bubble_label_set(fr, "Bubble");
350              evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
351              evas_object_size_hint_align_set(fr, EVAS_HINT_FILL,
352                                              EVAS_HINT_FILL);
353              elm_box_pack_end(bx, fr);
354              evas_object_show(fr);
355
356                {
357                   Evas_Object *tb = elm_table_add(win);
358                   evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
359                   elm_bubble_content_set(fr, tb);
360                   my_show(tb);
361                   for (j = 0; j < 2; j++)
362                     for (i = 0; i < 1; i++)
363                       {
364                          Evas_Object *bt;
365                          bt = elm_button_add(win);
366                          elm_object_text_set(bt, "Table");
367                          evas_object_size_hint_align_set(bt, EVAS_HINT_FILL,
368                                                          EVAS_HINT_FILL);
369                          evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
370                          elm_table_pack(tb, bt, i, j, 1, 1);
371                          my_show(bt);
372                       }
373                }
374           }
375      }
376 }
377 #endif