elementary/index - removed some codes should not be pushed in
[framework/uifw/elementary.git] / src / bin / test_bubble.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
8 static void
9 _print_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
10 {
11    printf("bubble clicked\n");
12 }
13
14 struct _api_data
15 {
16    unsigned int state;  /* What state we are testing       */
17    Evas_Object *win;    /* Parent Window of widgets        */
18    void *box;           /* Use this to get box content     */
19 };
20 typedef struct _api_data api_data;
21
22 enum _api_state
23 {
24    BUBBLE_SET_CORNER_1,
25    BUBBLE_SET_CORNER_2,
26    BUBBLE_SET_ICON_CONTENT,
27    API_STATE_LAST
28 };
29 typedef enum _api_state api_state;
30
31 static void
32 set_api_state(api_data *api)
33 {
34    const Eina_List *items = elm_box_children_get(api->box);
35    if(!eina_list_count(items))
36      return;
37
38    switch(api->state)
39      { /* Put all api-changes under switch */
40       case BUBBLE_SET_CORNER_1:
41          elm_bubble_pos_set(eina_list_nth(items, 0), ELM_BUBBLE_POS_BOTTOM_LEFT);
42          elm_object_text_set(elm_object_content_get(eina_list_nth(items, 0)),
43                   "Corner: base (bottom-left) - with icon");
44          elm_bubble_pos_set(eina_list_nth(items, 1), ELM_BUBBLE_POS_TOP_RIGHT);
45          elm_object_text_set(elm_object_content_get(eina_list_nth(items, 1)),
46                   "Corner: base (top-right) - no icon");
47          break;
48
49       case BUBBLE_SET_CORNER_2:
50          elm_bubble_pos_set(eina_list_nth(items, 0), ELM_BUBBLE_POS_TOP_RIGHT);
51          elm_object_text_set(elm_object_content_get(eina_list_nth(items, 0)),
52                   "Corner: base (top-right) - with icon");
53          elm_bubble_pos_set(eina_list_nth(items, 1), ELM_BUBBLE_POS_BOTTOM_LEFT);
54          elm_object_text_set(elm_object_content_get(eina_list_nth(items, 1)),
55                   "Corner: base (bottom-left) - no icon");
56          break;
57
58       case BUBBLE_SET_ICON_CONTENT:
59            {
60               char buf[PATH_MAX];
61               Evas_Object *ct, *ic = elm_icon_add(api->win);
62
63               snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
64               elm_icon_file_set(ic, buf, NULL);
65               elm_icon_resizable_set(ic, 0, 0);
66               elm_object_content_set(eina_list_nth(items, 0), ic);
67               ct = elm_label_add(api->win);
68               elm_object_text_set(ct, "Using icon as top-bubble content");
69               elm_object_content_set(eina_list_nth(items, 1), ct);
70               evas_object_size_hint_align_set(ic, 0.5, 0.5);
71               evas_object_show(ic);
72            }
73          break;
74
75       case API_STATE_LAST:
76
77          break;
78       default:
79          return;
80      }
81 }
82
83 static void
84 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
85 {  /* Will add here a SWITCH command containing code to modify test-object */
86    /* in accordance a->state value. */
87    api_data *a = data;
88    char str[128];
89
90    printf("clicked event on API Button: api_state=<%d>\n", a->state);
91    set_api_state(a);
92    a->state++;
93    sprintf(str, "Next API function (%u)", a->state);
94    elm_object_text_set(obj, str);
95    elm_object_disabled_set(obj, a->state == API_STATE_LAST);
96 }
97
98 static void
99 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100 {
101    free(data);
102 }
103
104
105 void
106 test_bubble(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
107 {
108    Evas_Object *win, *bg, *bx, *ic, *bb, *ct, *bxx, *bt;
109    char buf[PATH_MAX];
110    api_data *api = calloc(1, sizeof(api_data));
111
112    win = elm_win_add(NULL, "box-vert", ELM_WIN_BASIC);
113    api->win = win;
114    elm_win_title_set(win, "Bubble");
115    elm_win_autodel_set(win, EINA_TRUE);
116    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
117
118    bg = elm_bg_add(win);
119    elm_win_resize_object_add(win, bg);
120    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
121    evas_object_show(bg);
122
123    bxx = elm_box_add(win);
124    elm_win_resize_object_add(win, bxx);
125    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
126    evas_object_show(bxx);
127
128    bx = elm_box_add(win);
129    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130    api->box = bx;
131    evas_object_show(bx);
132
133    bt = elm_button_add(win);
134    elm_object_text_set(bt, "Next API function");
135    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
136    elm_box_pack_end(bxx, bt);
137    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
138    evas_object_show(bt);
139
140    elm_box_pack_end(bxx, bx);
141
142    ic = elm_icon_add(win);
143    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
144    elm_icon_file_set(ic, buf, NULL);
145    elm_icon_resizable_set(ic, 0, 0);
146    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
147
148    bb = elm_bubble_add(win);
149    elm_object_text_set(bb, "Message 1");
150    elm_object_part_text_set(bb, "info", "Corner: bottom_right");
151    elm_object_part_content_set(bb, "icon", ic);
152    elm_bubble_pos_set(bb, ELM_BUBBLE_POS_BOTTOM_RIGHT);
153    evas_object_smart_callback_add(bb, "clicked", _print_clicked, NULL);
154    evas_object_show(ic);
155    evas_object_size_hint_weight_set(bb, EVAS_HINT_EXPAND, 0.0);
156    evas_object_size_hint_align_set(bb, EVAS_HINT_FILL, EVAS_HINT_FILL);
157
158    ct = elm_label_add(win);
159    elm_object_text_set(ct,
160                        "\"The future of the art: R or G or B?\",  by Rusty");
161    elm_object_content_set(bb, ct);
162
163    elm_box_pack_end(bx, bb);
164    evas_object_show(bb);
165
166    bb = elm_bubble_add(win);
167    elm_object_text_set(bb, "Message 2");
168    elm_object_part_text_set(bb, "info", "10:32 4/11/2008");
169    evas_object_smart_callback_add(bb, "clicked", _print_clicked, NULL);
170    evas_object_size_hint_weight_set(bb, EVAS_HINT_EXPAND, 0.0);
171    evas_object_size_hint_align_set(bb, EVAS_HINT_FILL, EVAS_HINT_FILL);
172
173    ct = elm_label_add(win);
174    elm_object_text_set(ct, "Corner: base (top-left) - no icon");
175    elm_object_content_set(bb, ct);
176
177    elm_box_pack_end(bx, bb);
178    evas_object_show(bb);
179
180    evas_object_show(win);
181 }
182 #endif