fixed plugin image size problem
[framework/uifw/elementary.git] / src / bin / test_hoversel.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 struct _api_data
8 {
9    unsigned int state;  /* What state we are testing       */
10    void *box;           /* Use this to get box content     */
11 };
12 typedef struct _api_data api_data;
13
14 enum _api_state
15 {
16    HOVERSEL_HORIZ,
17    HOVERSEL_END,
18    HOVERSEL_LABAL_SET,
19    HOVERSEL_ICON_UNSET,
20    HOVERSEL_CLEAR_OPEN,
21    HOVERSEL_CLEAR,
22    API_STATE_LAST
23 };
24 typedef enum _api_state api_state;
25
26 static void
27 set_api_state(api_data *api)
28 {
29    const Eina_List *items = elm_box_children_get(api->box);
30    if (!eina_list_count(items))
31      return;
32
33    /* use elm_box_children_get() to get list of children */
34    switch(api->state)
35      { /* Put all api-changes under switch */
36       case HOVERSEL_HORIZ:  /* Make first hover horiz (0) */
37          elm_hoversel_horizontal_set(eina_list_nth(items, 0), EINA_TRUE);
38          elm_hoversel_hover_begin(eina_list_nth(items, 0));
39          break;
40
41       case HOVERSEL_END:  /* Make first hover horiz (1) */
42          elm_hoversel_hover_begin(eina_list_nth(items, 1));
43          elm_hoversel_hover_end(eina_list_nth(items, 1));
44          break;
45
46       case HOVERSEL_LABAL_SET: /* set second hover label (2) */
47          elm_object_text_set(eina_list_nth(items, 1), "Label from API");
48          break;
49
50       case HOVERSEL_ICON_UNSET: /* 3 */
51          elm_object_text_set(eina_list_nth(items, 5), "Label only");
52          elm_object_part_content_unset(eina_list_nth(items, 5), "icon");
53          break;
54
55       case HOVERSEL_CLEAR_OPEN: /* 4 */
56          elm_hoversel_hover_begin(eina_list_nth(items, 1));
57          elm_hoversel_clear(eina_list_nth(items, 1));
58          break;
59
60       case HOVERSEL_CLEAR: /* 5 */
61          elm_hoversel_clear(eina_list_nth(items, 0));
62          break;
63
64       case API_STATE_LAST:
65          break;
66
67       default:
68          return;
69      }
70 }
71
72 static void
73 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
74 {  /* Will add here a SWITCH command containing code to modify test-object */
75    /* in accordance a->state value. */
76    api_data *a = data;
77    char str[128];
78
79    printf("clicked event on API Button: api_state=<%d>\n", a->state);
80    set_api_state(a);
81    a->state++;
82    sprintf(str, "Next API function (%u)", a->state);
83    elm_object_text_set(obj, str);
84    elm_object_disabled_set(obj, a->state == API_STATE_LAST);
85 }
86
87 static void
88 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
89 {
90    free(data);
91 }
92
93 void
94 test_hoversel(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
95 {
96    Evas_Object *win, *bx, *bt, *ic, *bxx;
97    char buf[PATH_MAX];
98    api_data *api = calloc(1, sizeof(api_data));
99
100    win = elm_win_util_standard_add("hoversel", "HoverSel");
101    elm_win_autodel_set(win, EINA_TRUE);
102    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
103
104    bxx = elm_box_add(win);
105    elm_win_resize_object_add(win, bxx);
106    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107    evas_object_show(bxx);
108
109    bx = elm_box_add(win);
110    elm_win_resize_object_add(win, bx);
111    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112    api->box = bx;
113    evas_object_show(bx);
114
115    bt = elm_button_add(win);
116    elm_object_text_set(bt, "Next API function");
117    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
118    elm_box_pack_end(bxx, bt);
119    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
120    evas_object_show(bt);
121
122    elm_box_pack_end(bxx, bx);
123
124    bt = elm_hoversel_add(win);
125 // FIXME: need to add horizontal hoversel theme to default some day
126 //   elm_hoversel_horizontal_set(bt, 1);
127    elm_hoversel_hover_parent_set(bt, win);
128    elm_object_text_set(bt, "Labels");
129    elm_hoversel_item_add(bt, "Item 1", NULL, ELM_ICON_NONE, NULL, NULL);
130    elm_hoversel_item_add(bt, "Item 2", NULL, ELM_ICON_NONE, NULL, NULL);
131    elm_hoversel_item_add(bt, "Item 3", NULL, ELM_ICON_NONE, NULL, NULL);
132    elm_hoversel_item_add(bt, "Item 4 - Long Label Here", NULL, ELM_ICON_NONE, NULL, NULL);
133    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
134    evas_object_size_hint_align_set(bt, 0.5, 0.5);
135    elm_box_pack_end(bx, bt);
136    evas_object_show(bt);
137
138    bt = elm_hoversel_add(win);
139    elm_hoversel_hover_parent_set(bt, win);
140    elm_object_text_set(bt, "Some Icons");
141    elm_hoversel_item_add(bt, "Item 1", NULL, ELM_ICON_NONE, NULL, NULL);
142    elm_hoversel_item_add(bt, "Item 2", NULL, ELM_ICON_NONE, NULL, NULL);
143    elm_hoversel_item_add(bt, "Item 3", "home", ELM_ICON_STANDARD, NULL, NULL);
144    elm_hoversel_item_add(bt, "Item 4", "close", ELM_ICON_STANDARD, NULL, NULL);
145    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
146    evas_object_size_hint_align_set(bt, 0.5, 0.5);
147    elm_box_pack_end(bx, bt);
148    evas_object_show(bt);
149
150    bt = elm_hoversel_add(win);
151    elm_hoversel_hover_parent_set(bt, win);
152    elm_object_text_set(bt, "All Icons");
153    elm_hoversel_item_add(bt, "Item 1", "apps", ELM_ICON_STANDARD, NULL, NULL);
154    elm_hoversel_item_add(bt, "Item 2", "arrow_down", ELM_ICON_STANDARD, NULL, NULL);
155    elm_hoversel_item_add(bt, "Item 3", "home", ELM_ICON_STANDARD, NULL, NULL);
156    elm_hoversel_item_add(bt, "Item 4", "close", ELM_ICON_STANDARD, NULL, NULL);
157    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
158    evas_object_size_hint_align_set(bt, 0.5, 0.5);
159    elm_box_pack_end(bx, bt);
160    evas_object_show(bt);
161
162    bt = elm_hoversel_add(win);
163    elm_hoversel_hover_parent_set(bt, win);
164    elm_object_text_set(bt, "All Icons");
165    elm_hoversel_item_add(bt, "Item 1", "apps", ELM_ICON_STANDARD, NULL, NULL);
166    snprintf(buf, sizeof(buf), "%s/images/sky_02.jpg", elm_app_data_dir_get());
167    elm_hoversel_item_add(bt, "Item 2", buf, ELM_ICON_FILE, NULL, NULL);
168    elm_hoversel_item_add(bt, "Item 3", "home", ELM_ICON_STANDARD, NULL, NULL);
169    elm_hoversel_item_add(bt, "Item 4", "close", ELM_ICON_STANDARD, NULL, NULL);
170    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
171    evas_object_size_hint_align_set(bt, 0.5, 0.5);
172    elm_box_pack_end(bx, bt);
173    evas_object_show(bt);
174
175    bt = elm_hoversel_add(win);
176    elm_hoversel_hover_parent_set(bt, win);
177    elm_object_text_set(bt, "Disabled Hoversel");
178    elm_hoversel_item_add(bt, "Item 1", "apps", ELM_ICON_STANDARD, NULL, NULL);
179    elm_hoversel_item_add(bt, "Item 2", "close", ELM_ICON_STANDARD, NULL, NULL);
180    elm_object_disabled_set(bt, 1);
181    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
182    evas_object_size_hint_align_set(bt, 0.5, 0.5);
183    elm_box_pack_end(bx, bt);
184    evas_object_show(bt);
185
186    bt = elm_hoversel_add(win);
187    elm_hoversel_hover_parent_set(bt, win);
188    elm_object_text_set(bt, "Icon + Label");
189
190    ic = elm_icon_add(win);
191    snprintf(buf, sizeof(buf), "%s/images/sky_03.jpg", elm_app_data_dir_get());
192    elm_icon_file_set(ic, buf, NULL);
193    elm_object_part_content_set(bt, "icon", ic);
194    evas_object_show(ic);
195
196    elm_hoversel_item_add(bt, "Item 1", "apps", ELM_ICON_STANDARD, NULL, NULL);
197    elm_hoversel_item_add(bt, "Item 2", "arrow_down", ELM_ICON_STANDARD, NULL, NULL);
198    elm_hoversel_item_add(bt, "Item 3", "home", ELM_ICON_STANDARD, NULL, NULL);
199    elm_hoversel_item_add(bt, "Item 4", "close", ELM_ICON_STANDARD, NULL, NULL);
200    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
201    evas_object_size_hint_align_set(bt, 0.5, 0.5);
202    elm_box_pack_end(bx, bt);
203    evas_object_show(bt);
204
205    evas_object_resize(win, 320, 300);
206
207    evas_object_show(win);
208 }
209 #endif