elementary_test: change deprecated APIs
[framework/uifw/elementary.git] / src / bin / test_diskselector.c
1 #include <Elementary.h>
2 #include "test.h"
3 #include <Elementary_Cursor.h>
4 #ifdef HAVE_CONFIG_H
5 # include "elementary_config.h"
6 #endif
7 #ifndef ELM_LIB_QUICKLAUNCH
8 struct _api_data
9 {
10    unsigned int state;  /* What state we are testing       */
11    void *box;           /* Use this to get box content     */
12 };
13 typedef struct _api_data api_data;
14
15 enum _api_state
16 {
17    SCROLLER_POLICY_SET_ON,
18    SCROLLER_POLICY_SET_OFF,
19    BOUNCE_SET,
20    ITEM_LABEL_SET,
21    TOOLTIP_TEXT_SET,
22    ITEM_TOOLTIP_UNSET,
23    ITEM_CURSOR_SET,
24    ITEM_CURSOR_UNSET,
25    ITEM_ICON_SET,
26    SELECTED_SET,
27    ITEM_PREV_GET,
28    ITEM_DEL_NOT_SELECTED,
29    ITEM_DEL, /* delete when selected */
30    CLEAR,
31    API_STATE_LAST
32 };
33 typedef enum _api_state api_state;
34
35 static void
36 set_api_state(api_data *api)
37 {
38    const Eina_List *disks = elm_box_children_get(api->box);
39    if(!eina_list_count(disks))
40      return;
41
42    switch(api->state)
43      { /* Put all api-changes under switch */
44       case SCROLLER_POLICY_SET_ON: /* 0 */
45            {  /* Get first disk */
46               Evas_Object *disk = eina_list_nth(disks, 0);
47               elm_diskselector_scroller_policy_set(disk, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_ON);
48            }
49          break;
50
51       case SCROLLER_POLICY_SET_OFF: /* 1 */
52            {  /* Get first disk */
53               Evas_Object *disk = eina_list_nth(disks, 0);
54               elm_diskselector_scroller_policy_set(disk, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
55            }
56          break;
57
58       case BOUNCE_SET: /* 2 */
59            {  /* Get second disk, cancel bounce */
60               Evas_Object *disk = eina_list_nth(disks, 1);
61               elm_diskselector_bounce_set(disk, EINA_FALSE, EINA_FALSE);
62            }
63          break;
64
65       case ITEM_LABEL_SET: /* 3 */
66          elm_object_item_text_set(elm_diskselector_selected_item_get(eina_list_nth(disks, 0)), "Label from API");
67          break;
68
69       case TOOLTIP_TEXT_SET: /* 4 */
70          elm_object_item_tooltip_text_set(elm_diskselector_selected_item_get(eina_list_nth(disks, 0)), "Tooltip from API");
71          break;
72
73       case ITEM_TOOLTIP_UNSET: /* 5 */
74          elm_object_item_tooltip_unset(elm_diskselector_selected_item_get(eina_list_nth(disks, 0)));
75          break;
76
77       case ITEM_CURSOR_SET: /* 6 */
78          elm_object_item_cursor_set(elm_diskselector_selected_item_get(eina_list_nth(disks, 0)), ELM_CURSOR_HAND2);
79          break;
80
81       case ITEM_CURSOR_UNSET: /* 7 */
82          elm_object_item_cursor_unset(elm_diskselector_selected_item_get(eina_list_nth(disks, 0)));
83          break;
84
85       case ITEM_ICON_SET: /* 8 */
86            {  /* Set icon of selected item in first disk */
87               char buf[PATH_MAX];
88               Evas_Object *ic = elm_icon_add(elm_object_parent_widget_get(eina_list_nth(disks, 0)));
89               snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
90               elm_icon_file_set(ic, buf, NULL);
91               elm_object_item_part_content_set(elm_diskselector_selected_item_get(eina_list_nth(disks, 0)), NULL, ic);
92               evas_object_show(ic);
93            }
94          break;
95
96       case SELECTED_SET: /* 9 */
97            {  /* Select NEXT item of third disk */
98               elm_diskselector_item_selected_set(elm_diskselector_last_item_get(eina_list_nth(disks, 1)), EINA_TRUE);
99               elm_diskselector_item_selected_set(elm_diskselector_item_next_get(elm_diskselector_selected_item_get(eina_list_nth(disks, 2))), EINA_TRUE);
100            }
101          break;
102
103       case ITEM_PREV_GET: /* 10 */
104            {  /* Select PREV item of third disk */
105               elm_diskselector_item_selected_set(elm_diskselector_item_prev_get(elm_diskselector_selected_item_get(eina_list_nth(disks, 2))), EINA_TRUE);
106            }
107          break;
108
109       case ITEM_DEL_NOT_SELECTED: /* 11 */
110            {  /* Remove selected item of third disk */
111               elm_object_item_del(elm_diskselector_item_prev_get(elm_diskselector_selected_item_get(eina_list_nth(disks, 2))));
112            }
113          break;
114
115       case ITEM_DEL: /* 12 */
116            {  /* Remove selected item of first disk */
117               elm_object_item_del(elm_diskselector_selected_item_get(eina_list_nth(disks, 1)));
118            }
119          break;
120
121       case CLEAR: /* 13 */
122          elm_diskselector_clear(eina_list_nth(disks, 0));
123          break;
124
125       default:
126          return;
127      }
128 }
129
130 static void
131 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
132 {  /* Will add here a SWITCH command containing code to modify test-object */
133    /* in accordance a->state value. */
134    api_data *a = data;
135    char str[128];
136
137    printf("clicked event on API Button: api_state=<%d>\n", a->state);
138    set_api_state(a);
139    a->state++;
140    sprintf(str, "Next API function (%u)", a->state);
141    elm_object_text_set(obj, str);
142    elm_object_disabled_set(obj, a->state == API_STATE_LAST);
143 }
144
145 static void
146 _disk_sel(void *data __UNUSED__, Evas_Object * obj __UNUSED__, void *event_info)
147 {
148    Elm_Object_Item *ds_it = event_info;
149    printf("Equinox: %s\n", elm_object_item_text_get(ds_it));
150 }
151
152 static void
153 _disk_next(void *data __UNUSED__, Evas_Object * obj __UNUSED__, void *event_info)
154 {
155    Elm_Object_Item *next_ds_it, *prev_ds_it, *ds_it = event_info;
156    prev_ds_it = elm_diskselector_item_prev_get(ds_it);
157    next_ds_it = elm_diskselector_item_next_get(ds_it);
158    printf("Prev: %s, Next: %s\n", elm_object_item_text_get(prev_ds_it),
159           elm_object_item_text_get(next_ds_it));
160 }
161
162 static void
163 _print_disk_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
164 {
165    Elm_Object_Item *ds_it = event_info;
166    printf("Selected label: %s\n", elm_object_item_text_get(ds_it));
167 }
168
169 static Evas_Object *
170 _disk_create(Evas_Object *win, Eina_Bool round)
171 {
172    Elm_Object_Item *ds_it;
173    Evas_Object *di;
174
175    di = elm_diskselector_add(win);
176
177    elm_diskselector_item_append(di, "January", NULL, NULL, NULL);
178    elm_diskselector_item_append(di, "February", NULL, _disk_next, NULL);
179    elm_diskselector_item_append(di, "March", NULL, _disk_sel, NULL);
180    elm_diskselector_item_append(di, "April", NULL, NULL, NULL);
181    elm_diskselector_item_append(di, "May", NULL, NULL, NULL);
182    elm_diskselector_item_append(di, "June", NULL, NULL, NULL);
183    elm_diskselector_item_append(di, "July", NULL, NULL, NULL);
184    ds_it = elm_diskselector_item_append(di, "August", NULL, NULL, NULL);
185    elm_diskselector_item_append(di, "September", NULL, _disk_sel, NULL);
186    elm_diskselector_item_append(di, "October", NULL, NULL, NULL);
187    elm_diskselector_item_append(di, "November", NULL, NULL, NULL);
188    elm_diskselector_item_append(di, "December", NULL, NULL, NULL);
189
190    elm_diskselector_item_selected_set(ds_it, EINA_TRUE);
191    elm_diskselector_round_set(di, round);
192
193    return di;
194 }
195
196 static void
197 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
198 {
199    free(data);
200 }
201
202 void
203 test_diskselector(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
204 {
205    Evas_Object *win, *bg, *bx, *disk, *ic, *bxx, *bt;
206    Elm_Object_Item *ds_it;
207    char buf[PATH_MAX];
208    api_data *api = calloc(1, sizeof(api_data));
209    int idx = 0;
210
211    char *month_list[] = {
212       "Jan", "Feb", "Mar",
213       "Apr", "May", "Jun",
214       "Jul", "Aug", "Sep",
215       "Oct", "Nov", "Dec"
216    };
217    char date[3];
218
219    win = elm_win_add(NULL, "diskselector", ELM_WIN_BASIC);
220    elm_win_title_set(win, "Disk Selector");
221    elm_win_autodel_set(win, EINA_TRUE);
222    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
223
224    bg = elm_bg_add(win);
225    elm_win_resize_object_add(win, bg);
226    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227    evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
228    evas_object_show(bg);
229
230    bxx = elm_box_add(win);
231    elm_win_resize_object_add(win, bxx);
232    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
233    evas_object_show(bxx);
234
235    bx = elm_box_add(win);
236    elm_win_resize_object_add(win, bx);
237    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
238    evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
239    api->box = bx;
240    evas_object_show(bx);
241
242    bt = elm_button_add(win);
243    elm_object_text_set(bt, "Next API function");
244    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
245    elm_box_pack_end(bxx, bt);
246    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
247    evas_object_show(bt);
248
249    elm_box_pack_end(bxx, bx);
250
251    disk = _disk_create(win, EINA_TRUE);
252    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
253    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
254    elm_box_pack_end(bx, disk);
255    evas_object_show(disk);
256    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
257    ds_it = elm_diskselector_selected_item_get(disk);
258    elm_diskselector_item_selected_set(ds_it, EINA_FALSE);
259
260    disk = _disk_create(win, EINA_FALSE);
261    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
262    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
263    elm_box_pack_end(bx, disk);
264    evas_object_show(disk);
265    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
266    ds_it = elm_diskselector_first_item_get(disk);
267    ds_it = elm_diskselector_item_next_get(ds_it);
268    elm_diskselector_item_selected_set(ds_it, EINA_TRUE);
269
270    disk = _disk_create(win, EINA_FALSE);
271    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
272    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
273    elm_box_pack_end(bx, disk);
274    evas_object_show(disk);
275    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
276    elm_diskselector_side_label_length_set(disk, 4);
277
278    disk = elm_diskselector_add(win);
279    ic = elm_icon_add(win);
280    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
281    elm_icon_file_set(ic, buf, NULL);
282    elm_icon_scale_set(ic, 1, 1);
283    elm_diskselector_item_append(disk, "Sunday", ic, NULL, NULL);
284    elm_diskselector_item_append(disk, "Monday", NULL, NULL, NULL);
285    elm_diskselector_item_append(disk, "Tuesday", NULL, NULL, NULL);
286    elm_diskselector_item_append(disk, "Wednesday", NULL, NULL, NULL);
287    elm_diskselector_item_append(disk, "Thursday", NULL, NULL, NULL);
288    elm_diskselector_item_append(disk, "Friday", NULL, NULL, NULL);
289    elm_diskselector_item_append(disk, "Saturday", NULL, NULL, NULL);
290    elm_diskselector_round_set(disk, EINA_TRUE);
291    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
292    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
293    elm_box_pack_end(bx, disk);
294    evas_object_show(disk);
295    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
296
297    disk = elm_diskselector_add(win);
298    ic = elm_icon_add(win);
299    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
300    elm_icon_file_set(ic, buf, NULL);
301    elm_icon_scale_set(ic, 1, 1);
302    elm_diskselector_item_append(disk, "머리스타일", ic, NULL, NULL);
303    elm_diskselector_item_append(disk, "プロが伝授する", NULL, NULL, NULL);
304    elm_diskselector_item_append(disk, "生上访要求政府", NULL, NULL, NULL);
305    elm_diskselector_item_append(disk, "English", NULL, NULL, NULL);
306    elm_diskselector_item_append(disk, "والشريعة", NULL, NULL, NULL);
307    elm_diskselector_item_append(disk, "עִבְרִית", NULL, NULL, NULL);
308    elm_diskselector_item_append(disk, "Grüßen", NULL, NULL, NULL);
309    elm_diskselector_round_set(disk, EINA_TRUE);
310    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
311    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
312    elm_box_pack_end(bx, disk);
313    evas_object_show(disk);
314    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
315
316    // displayed item number setting example
317    disk = elm_diskselector_add(win);
318    elm_diskselector_display_item_num_set(disk, 5);
319    printf("Number of Items in DiskSelector : %d\n",
320           elm_diskselector_display_item_num_get(disk));
321
322    for (idx = 0; idx < (int)(sizeof(month_list) / sizeof(month_list[0])); idx++)
323      {
324         ds_it = elm_diskselector_item_append(disk, month_list[idx], NULL, NULL,
325                                              NULL);
326      }
327
328    elm_diskselector_item_selected_set(ds_it, EINA_TRUE);
329    elm_diskselector_round_set(disk, EINA_TRUE);
330    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
331    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
332    elm_box_pack_end(bx, disk);
333    evas_object_show(disk);
334    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
335
336    // displayed item number setting example
337    disk = elm_diskselector_add(win);
338    elm_diskselector_display_item_num_set(disk, 7);
339    printf("Number of Items in DiskSelector : %d\n",
340           elm_diskselector_display_item_num_get(disk));
341
342    for (idx = 1; idx < 31; idx++)
343      {
344         snprintf(date, sizeof(date), "%d", idx);
345         ds_it = elm_diskselector_item_append(disk, date, NULL, NULL, NULL);
346      }
347
348    elm_diskselector_item_selected_set(ds_it, EINA_TRUE);
349    elm_diskselector_round_set(disk, EINA_TRUE);
350    evas_object_size_hint_weight_set(disk, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
351    evas_object_size_hint_align_set(disk, EVAS_HINT_FILL, 0.5);
352    elm_box_pack_end(bx, disk);
353    evas_object_show(disk);
354    evas_object_smart_callback_add(disk, "selected", _print_disk_info_cb, NULL);
355
356    evas_object_resize(win, 320, 480);
357    evas_object_show(win);
358 }
359
360 #endif