Initialize Tizen 2.3
[framework/uifw/elementary.git] / wearable / src / bin / test_focus2.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static void
8 _focus_in(void *data __UNUSED__, Evas *e __UNUSED__, void *event_info)
9 {
10    const char *type = evas_object_type_get(event_info);
11    if ((type) && (!strcmp(type, "elm_widget")))
12      type = elm_object_widget_type_get(event_info);
13    printf("Evas_Object focus in: %p %s\n", event_info, type);
14 }
15
16 static void
17 _focus_out(void *data __UNUSED__, Evas *e __UNUSED__, void *event_info)
18 {
19    const char *type = evas_object_type_get(event_info);
20    if ((type) && (!strcmp(type, "elm_widget")))
21      type = elm_object_widget_type_get(event_info);
22    printf("Evas_Object focus out: %p %s\n", event_info, type);
23 }
24
25 static void
26 _focus_obj(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
27 {
28    Evas_Object *newfocus = data;
29    const char *type = evas_object_type_get(newfocus);
30    if ((type) && (!strcmp(type, "elm_widget")))
31      type = elm_object_widget_type_get(newfocus);
32    printf("elm_object_focus_set(%p, EINA_TRUE) %s\n", newfocus, type);
33    elm_object_focus_set(newfocus, EINA_TRUE);
34 }
35
36 static void
37 _focus_layout_part(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
38 {
39    Evas_Object *ed = elm_layout_edje_get(data);
40
41    Evas_Object *newfocus = (Evas_Object *)edje_object_part_object_get(ed, "sky");
42    const char *type = evas_object_type_get(newfocus);
43    printf("evas_object_focus_set(%p, EINA_TRUE) %s\n", newfocus, type);
44    evas_object_focus_set(newfocus, EINA_TRUE);;
45 }
46
47
48 void
49 test_focus2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
50 {
51    Evas_Object *win, *bx, *ly, *bt, *en, *bt1;
52    char buf[PATH_MAX];
53
54    win = elm_win_util_standard_add("focus2", "Focus 2");
55    elm_win_autodel_set(win, EINA_TRUE);
56    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
57
58    evas_event_callback_add
59      (evas_object_evas_get(win), EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
60       _focus_in, NULL);
61    evas_event_callback_add
62      (evas_object_evas_get(win), EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
63       _focus_out, NULL);
64
65    bx = elm_box_add(win);
66    elm_win_resize_object_add(win, bx);
67    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68    evas_object_show(bx);
69
70 #define PARENT bx /* this is broken, but should work */
71 //#define PARENT win
72
73    en = elm_entry_add(PARENT);
74    elm_entry_scrollable_set(en, EINA_TRUE);
75    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
76    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
77    elm_scroller_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
78    elm_object_text_set(en, "Entry that should get focus");
79    elm_entry_single_line_set(en, EINA_TRUE);
80    evas_object_show(en);
81    elm_box_pack_end(bx, en);
82
83    bt = elm_button_add(PARENT);
84    elm_object_text_set(bt, "Give focus to entry");
85    evas_object_smart_callback_add(bt, "clicked", _focus_obj, en);
86    elm_box_pack_end(bx, bt);
87    evas_object_show(bt);
88
89    ly = elm_layout_add(PARENT);
90    snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
91    elm_layout_file_set(ly, buf, "layout");
92    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
93    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
94    elm_box_pack_end(bx, ly);
95    evas_object_show(ly);
96
97    bt1 = bt = elm_button_add(ly);
98    elm_object_text_set(bt, "Button 1");
99    elm_object_part_content_set(ly, "element1", bt);
100
101    en = elm_entry_add(ly);
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_scroller_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
106    elm_object_text_set(en, "Scrolled Entry that should get focus");
107    elm_entry_single_line_set(en, EINA_TRUE);
108    elm_object_part_content_set(ly, "element2", en);
109
110    bt = elm_button_add(ly);
111    elm_object_text_set(bt, "Button 2");
112    elm_object_part_content_set(ly, "element3", bt);
113
114    bt = elm_button_add(PARENT);
115    elm_object_text_set(bt, "Give focus to layout");
116    evas_object_smart_callback_add(bt, "clicked", _focus_obj, ly);
117    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
118    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
119    elm_box_pack_end(bx, bt);
120    evas_object_show(bt);
121
122    bt = elm_button_add(PARENT);
123    elm_object_text_set(bt, "Give focus to layout part");
124    evas_object_smart_callback_add(bt, "clicked", _focus_layout_part, ly);
125    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
126    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
127    elm_box_pack_end(bx, bt);
128    evas_object_show(bt);
129
130    bt = elm_button_add(PARENT);
131    elm_object_text_set(bt, "Give focus to layout 'Button 1'");
132    evas_object_smart_callback_add(bt, "clicked", _focus_obj, bt1);
133    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
134    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
135    elm_box_pack_end(bx, bt);
136    evas_object_show(bt);
137
138    bt = elm_button_add(PARENT);
139    elm_object_text_set(bt, "Give focus to layout 'Entry'");
140    evas_object_smart_callback_add(bt, "clicked", _focus_obj, en);
141    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
142    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
143    elm_box_pack_end(bx, bt);
144    evas_object_show(bt);
145
146    evas_object_resize(win, 400, 400);
147    evas_object_show(win);
148 }
149 #endif