elementary: Updated test_inwin.c to do API testing
[framework/uifw/elementary.git] / src / bin / test_inwin.c
1 #include <Elementary.h>
2 #include "test.h"
3 #ifdef HAVE_CONFIG_H
4 # include "elementary_config.h"
5 #endif
6 #ifndef ELM_LIB_QUICKLAUNCH
7 struct _api_data
8 {
9    unsigned int state;  /* What state we are testing       */
10    void *inwin;
11 };
12 typedef struct _api_data api_data;
13
14 enum _api_state
15 {
16    CONTENT_UNSET,
17    API_STATE_LAST
18 };
19 typedef enum _api_state api_state;
20
21 static void
22 set_api_state(api_data *api)
23 {
24    Evas_Object *t;
25    switch(api->state)
26      {
27       case CONTENT_UNSET:
28          t = elm_win_inwin_content_unset(api->inwin);
29          evas_object_del(t);
30          t = elm_label_add(elm_object_parent_widget_get(api->inwin));
31          elm_object_text_set(t, "Content was unset.<br>DONE!");
32          elm_win_inwin_content_set(api->inwin, t);
33          evas_object_show(t);
34
35       default:
36          return;
37      }
38 }
39
40 static void
41 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
42 {  /* Will add here a SWITCH command containing code to modify test-object */
43    /* in accordance a->state value. */
44    api_data *a = data;
45    char str[128];
46
47    printf("clicked event on API Button: api_state=<%d>\n", a->state);
48    set_api_state(a);
49    a->state++;
50    sprintf(str, "Next API function (%u)", a->state);
51    elm_object_text_set(obj, str);
52    elm_object_disabled_set(obj, a->state == API_STATE_LAST);
53 }
54
55 static void
56 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
57 {
58    free(data);
59 }
60
61 void
62 test_inwin(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
63 {
64    Evas_Object *win, *bg, *inwin, *lb, *bxx, *bt;
65    api_data *api = calloc(1, sizeof(api_data));
66
67    win = elm_win_add(NULL, "inwin", ELM_WIN_BASIC);
68    elm_win_title_set(win, "Inwin");
69    elm_win_autodel_set(win, EINA_TRUE);
70    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
71
72    bg = elm_bg_add(win);
73    elm_win_resize_object_add(win, bg);
74    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75    evas_object_show(bg);
76
77    inwin = elm_win_inwin_add(win);
78    api->inwin = inwin;
79    evas_object_show(inwin);
80
81    bxx = elm_box_add(inwin);
82    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
83    evas_object_show(bxx);
84
85    bt = elm_button_add(inwin);
86    elm_object_text_set(bt, "Next API function");
87    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
88    elm_box_pack_end(bxx, bt);
89    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
90    evas_object_show(bt);
91
92    lb = elm_label_add(win);
93    elm_object_text_set(lb,
94                        "This is an \"inwin\" - a window in a<br/>"
95                        "window. This is handy for quick popups<br/>"
96                        "you want centered, taking over the window<br/>"
97                        "until dismissed somehow. Unlike hovers they<br/>"
98                        "don't hover over their target.");
99    elm_box_pack_end(bxx, lb);
100    elm_win_inwin_content_set(inwin, bxx);
101    evas_object_show(lb);
102
103    evas_object_resize(win, 320, 240);
104    evas_object_show(win);
105 }
106
107 void
108 test_inwin2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
109 {
110    Evas_Object *win, *bg, *inwin, *lb;
111
112    win = elm_win_add(NULL, "inwin2", ELM_WIN_BASIC);
113    elm_win_title_set(win, "Inwin 2");
114    elm_win_autodel_set(win, EINA_TRUE);
115
116    bg = elm_bg_add(win);
117    elm_win_resize_object_add(win, bg);
118    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
119    evas_object_show(bg);
120
121    inwin = elm_win_inwin_add(win);
122    elm_object_style_set(inwin, "minimal_vertical");
123    evas_object_show(inwin);
124
125    lb = elm_label_add(win);
126    elm_object_text_set(lb,
127                        "This is an \"inwin\" - a window in a<br/>"
128                        "window. This is handy for quick popups<br/>"
129                        "you want centered, taking over the window<br/>"
130                        "until dismissed somehow. Unlike hovers they<br/>"
131                        "don't hover over their target.<br/>"
132                        "<br/>"
133                        "This inwin style compacts itself vertically<br/>"
134                        "to the size of its contents minimum size.");
135    elm_win_inwin_content_set(inwin, lb);
136    evas_object_show(lb);
137
138    evas_object_resize(win, 320, 240);
139    evas_object_show(win);
140 }
141 #endif