Merge "[Password]: New design based changes, a new style removed password mode contro...
[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(%p) %s\n", newfocus, type);
33    elm_object_focus(newfocus);
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, 1) %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
53    win = elm_win_add(NULL, "focus2", ELM_WIN_BASIC);
54    elm_win_title_set(win, "Focus2");
55    elm_win_autodel_set(win, 1);
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    bg = elm_bg_add(win);
66    elm_win_resize_object_add(win, bg);
67    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
68    evas_object_show(bg);
69
70    bx = elm_box_add(win);
71    elm_win_resize_object_add(win, bx);
72    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73    evas_object_show(bx);
74
75 #define PARENT bx /* this is broken, but should work */
76 //#define PARENT win
77
78    en = elm_scrolled_entry_add(PARENT);
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_scrolled_entry_scrollbar_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
82    elm_scrolled_entry_entry_set(en, "Scrolled Entry that should get focus");
83    elm_scrolled_entry_single_line_set(en, 1);
84    evas_object_show(en);
85    elm_box_pack_end(bx, en);
86
87    bt = elm_button_add(PARENT);
88    elm_button_label_set(bt, "Give focus to scrolled entry");
89    evas_object_smart_callback_add(bt, "clicked", _focus_obj, en);
90    elm_box_pack_end(bx, bt);
91    evas_object_show(bt);
92
93    ly = elm_layout_add(PARENT);
94    elm_layout_file_set(ly, PACKAGE_DATA_DIR"/objects/test.edj", "layout");
95    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
97    elm_box_pack_end(bx, ly);
98    evas_object_show(ly);
99
100    bt1 = bt = elm_button_add(ly);
101    elm_button_label_set(bt, "Button 1");
102    elm_layout_content_set(ly, "element1", bt);
103
104    en = elm_scrolled_entry_add(ly);
105    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
106    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
107    elm_scrolled_entry_scrollbar_policy_set(en, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
108    elm_scrolled_entry_entry_set(en, "Scrolled Entry that should get focus");
109    elm_scrolled_entry_single_line_set(en, 1);
110    elm_layout_content_set(ly, "element2", en);
111
112    bt = elm_button_add(ly);
113    elm_button_label_set(bt, "Button 2");
114    elm_layout_content_set(ly, "element3", bt);
115
116    bt = elm_button_add(PARENT);
117    elm_button_label_set(bt, "Give focus to layout");
118    evas_object_smart_callback_add(bt, "clicked", _focus_obj, ly);
119    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
120    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
121    elm_box_pack_end(bx, bt);
122    evas_object_show(bt);
123
124    bt = elm_button_add(PARENT);
125    elm_button_label_set(bt, "Give focus to layout part");
126    evas_object_smart_callback_add(bt, "clicked", _focus_layout_part, ly);
127    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
128    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
129    elm_box_pack_end(bx, bt);
130    evas_object_show(bt);
131
132    bt = elm_button_add(PARENT);
133    elm_button_label_set(bt, "Give focus to layout 'Button 1'");
134    evas_object_smart_callback_add(bt, "clicked", _focus_obj, bt1);
135    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
136    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
137    elm_box_pack_end(bx, bt);
138    evas_object_show(bt);
139
140    bt = elm_button_add(PARENT);
141    elm_button_label_set(bt, "Give focus to layout 'Entry'");
142    evas_object_smart_callback_add(bt, "clicked", _focus_obj, en);
143    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.0);
144    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
145    elm_box_pack_end(bx, bt);
146    evas_object_show(bt);
147
148    evas_object_resize(win, 400, 400);
149    evas_object_show(win);
150 }
151 #endif