[JungWooHyun] doing merge job ~
[framework/uifw/elementary.git] / src / bin / test_focus2.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
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, *bg, *bx, *ly, *bt, *en, *bt1;
52    char buf[PATH_MAX];
53
54    win = elm_win_add(NULL, "focus2", ELM_WIN_BASIC);
55    elm_win_title_set(win, "Focus2");
56    elm_win_autodel_set(win, EINA_TRUE);
57    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
58
59    evas_event_callback_add
60      (evas_object_evas_get(win), EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
61       _focus_in, NULL);
62    evas_event_callback_add
63      (evas_object_evas_get(win), EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
64       _focus_out, NULL);
65
66    bg = elm_bg_add(win);
67    elm_win_resize_object_add(win, bg);
68    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69    evas_object_show(bg);
70
71    bx = elm_box_add(win);
72    elm_win_resize_object_add(win, bx);
73    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74    evas_object_show(bx);
75
76 #define PARENT bx /* this is broken, but should work */
77 //#define PARENT win
78
79    en = elm_entry_add(PARENT);
80    elm_entry_scrollable_set(en, EINA_TRUE);
81    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
82    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
83    elm_entry_scrollbar_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
84    elm_object_text_set(en, "Scrolled Entry that should get focus");
85    elm_entry_single_line_set(en, EINA_TRUE);
86    evas_object_show(en);
87    elm_box_pack_end(bx, en);
88
89    bt = elm_button_add(PARENT);
90    elm_object_text_set(bt, "Give focus to scrolled entry");
91    evas_object_smart_callback_add(bt, "clicked", _focus_obj, en);
92    elm_box_pack_end(bx, bt);
93    evas_object_show(bt);
94
95    ly = elm_layout_add(PARENT);
96    snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
97    elm_layout_file_set(ly, buf, "layout");
98    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
100    elm_box_pack_end(bx, ly);
101    evas_object_show(ly);
102
103    bt1 = bt = elm_button_add(ly);
104    elm_object_text_set(bt, "Button 1");
105    elm_object_part_content_set(ly, "element1", bt);
106
107    en = elm_entry_add(ly);
108    elm_entry_scrollable_set(en, EINA_TRUE);
109    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
110    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
111    elm_entry_scrollbar_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
112    elm_object_text_set(en, "Scrolled Entry that should get focus");
113    elm_entry_single_line_set(en, EINA_TRUE);
114    elm_object_part_content_set(ly, "element2", en);
115
116    bt = elm_button_add(ly);
117    elm_object_text_set(bt, "Button 2");
118    elm_object_part_content_set(ly, "element3", bt);
119
120    bt = elm_button_add(PARENT);
121    elm_object_text_set(bt, "Give focus to layout");
122    evas_object_smart_callback_add(bt, "clicked", _focus_obj, ly);
123    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
124    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
125    elm_box_pack_end(bx, bt);
126    evas_object_show(bt);
127
128    bt = elm_button_add(PARENT);
129    elm_object_text_set(bt, "Give focus to layout part");
130    evas_object_smart_callback_add(bt, "clicked", _focus_layout_part, ly);
131    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
132    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
133    elm_box_pack_end(bx, bt);
134    evas_object_show(bt);
135
136    bt = elm_button_add(PARENT);
137    elm_object_text_set(bt, "Give focus to layout 'Button 1'");
138    evas_object_smart_callback_add(bt, "clicked", _focus_obj, bt1);
139    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
140    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
141    elm_box_pack_end(bx, bt);
142    evas_object_show(bt);
143
144    bt = elm_button_add(PARENT);
145    elm_object_text_set(bt, "Give focus to layout 'Entry'");
146    evas_object_smart_callback_add(bt, "clicked", _focus_obj, en);
147    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
148    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
149    elm_box_pack_end(bx, bt);
150    evas_object_show(bt);
151
152    evas_object_resize(win, 400, 400);
153    evas_object_show(win);
154 }
155 #endif