fixed plugin image size problem
[framework/uifw/elementary.git] / src / bin / test_bubble.c
1 #include "test.h"
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #include <Elementary.h>
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, *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_util_standard_add("bubble", "Bubble");
113    api->win = win;
114    elm_win_autodel_set(win, EINA_TRUE);
115    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
116
117    bxx = elm_box_add(win);
118    elm_win_resize_object_add(win, bxx);
119    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120    evas_object_show(bxx);
121
122    bx = elm_box_add(win);
123    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124    api->box = bx;
125    evas_object_show(bx);
126
127    bt = elm_button_add(win);
128    elm_object_text_set(bt, "Next API function");
129    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
130    elm_box_pack_end(bxx, bt);
131    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
132    evas_object_show(bt);
133
134    elm_box_pack_end(bxx, bx);
135
136    ic = elm_icon_add(win);
137    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
138    elm_icon_file_set(ic, buf, NULL);
139    elm_icon_resizable_set(ic, 0, 0);
140    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
141
142    bb = elm_bubble_add(win);
143    elm_object_text_set(bb, "Message 1");
144    elm_object_part_text_set(bb, "info", "Corner: bottom_right");
145    elm_object_part_content_set(bb, "icon", ic);
146    elm_bubble_pos_set(bb, ELM_BUBBLE_POS_BOTTOM_RIGHT);
147    evas_object_smart_callback_add(bb, "clicked", _print_clicked, NULL);
148    evas_object_show(ic);
149    evas_object_size_hint_weight_set(bb, EVAS_HINT_EXPAND, 0.0);
150    evas_object_size_hint_align_set(bb, EVAS_HINT_FILL, EVAS_HINT_FILL);
151
152    ct = elm_label_add(win);
153    elm_object_text_set(ct,
154                        "\"The future of the art: R or G or B?\",  by Rusty");
155    elm_object_content_set(bb, ct);
156
157    elm_box_pack_end(bx, bb);
158    evas_object_show(bb);
159
160    bb = elm_bubble_add(win);
161    elm_object_text_set(bb, "Message 2");
162    elm_object_part_text_set(bb, "info", "10:32 4/11/2008");
163    evas_object_smart_callback_add(bb, "clicked", _print_clicked, NULL);
164    evas_object_size_hint_weight_set(bb, EVAS_HINT_EXPAND, 0.0);
165    evas_object_size_hint_align_set(bb, EVAS_HINT_FILL, EVAS_HINT_FILL);
166
167    ct = elm_label_add(win);
168    elm_object_text_set(ct, "Corner: base (top-left) - no icon");
169    elm_object_content_set(bb, ct);
170
171    elm_box_pack_end(bx, bb);
172    evas_object_show(bb);
173
174    evas_object_show(win);
175 }
176 #endif