elm: Fixed formatting. Added a space after 'if/while/for'
[framework/uifw/elementary.git] / src / bin / test_list.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 *list;
12 };
13 typedef struct _api_data api_data;
14
15 enum _api_state
16 {
17    ITEM_PREPEND,        /* 0 */
18    ITEM_INSERT_BEFORE,  /* 1 */
19    ITEM_INSERT_AFTER,   /* 2 */
20    ITEM_SEPARATOR_SET,  /* 3 */
21    LIST_ITEM_DEL,       /* 4 */
22    SCROLLER_POLICY_SET_ON,
23    SCROLLER_POLICY_SET_OFF, /* Back to AUTO next */
24    TOOLTIP_TEXT_SET,    /* 7 */
25    TOOLTIP_UNSET,       /* 8 */
26    ITEM_CURSOR_SET,     /* 9 */
27    ITEM_CURSOR_STYLE_SET,
28    DISABLED_SET,        /* 11 */
29    MODE_SET_COMPRESS,   /* 12 */
30    MODE_SET_LIMIT,      /* 13 */
31    MODE_SET_EXPAND,     /* 14 */
32    HORIZONTAL_SET,      /* 15 */
33    BOUNCE_SET,          /* 16 */
34    LIST_CLEAR,          /* 17 */
35    API_STATE_LAST
36 };
37 typedef enum _api_state api_state;
38
39 static void
40 set_api_state(api_data *api)
41 {
42 /** HOW TO TEST ************************
43 0 ITEM PREPEND
44 Scroll to end
45 1 INSERT BEFORE
46 Scroll to end
47 2 INSERT AFTER
48 3 INSERT SEPERATOR
49 Scroll to end
50 4 ITEM DEL
51 5 POLICY ON, BOUNCE_SET(TRUE, TRUE)
52 6 POLICY OFF
53 Scroll to end
54 7 TOOLTIP last-item
55 8 Cancel tootip
56 9 Curosr set on last item
57 10 Cursor style set last item
58 11 DISABLE last item
59 12 MODE COMPRESS
60 13 MODE LIMIT
61 14 MODE EXPAND
62 15 HORIZ SET
63 16 VERT MODE, BOUNCE(TRUE, FALSE) try to bounce on Y-axis
64 17 List clear
65 *** HOW TO TEST ***********************/
66    Evas_Object *li = api->list;
67
68    switch(api->state)
69      { /* Put all api-changes under switch */
70       case ITEM_PREPEND: /* 0 */
71            {
72               const Eina_List *items = elm_list_items_get(li);
73               elm_list_item_prepend(li, "PREPEND", NULL, NULL, NULL, NULL);
74               elm_list_go(li);
75               elm_list_item_bring_in(eina_list_nth(items, 0));
76            }
77          break;
78
79       case ITEM_INSERT_BEFORE: /* 1 */
80            {
81               const Eina_List *items = elm_list_items_get(li);
82               if (eina_list_count(items))
83                 {
84                   elm_list_item_insert_before(li,
85                         eina_list_nth(items, eina_list_count(items)-1),
86                         "1-before-last", NULL, NULL, NULL, NULL);
87                   elm_list_go(li);
88                   elm_list_item_bring_in(eina_list_data_get(eina_list_last(items)));
89                 }
90            }
91          break;
92
93       case ITEM_INSERT_AFTER: /* 2 */
94            {
95               const Eina_List *items = elm_list_items_get(li);
96               if (eina_list_count(items))
97                 {
98                   elm_list_item_insert_after(li,
99                         eina_list_nth(items, eina_list_count(items)-2),
100                         "insert-after", NULL, NULL, NULL, NULL);
101                   elm_list_go(li);
102                   elm_list_item_bring_in(eina_list_data_get(eina_list_last(items)));
103                 }
104            }
105          break;
106
107       case ITEM_SEPARATOR_SET: /* 3 */
108            {
109               const Eina_List *items = elm_list_items_get(li);
110               if (eina_list_count(items))
111                 {
112                   elm_list_item_separator_set(eina_list_nth(items, eina_list_count(items)-3), EINA_TRUE);
113                   elm_list_item_bring_in(eina_list_nth(items, eina_list_count(items)-3));
114                   elm_list_go(li);
115                 }
116            }
117          break;
118
119       case LIST_ITEM_DEL: /* 4 */
120            {
121               const Eina_List *items = elm_list_items_get(li);
122               if (eina_list_count(items))
123                 {
124                   elm_object_item_del(eina_list_data_get(eina_list_last(items)));
125                 }
126            }
127          break;
128
129       case SCROLLER_POLICY_SET_ON: /* 5 */
130          elm_list_bounce_set(li, EINA_TRUE, EINA_TRUE);
131          elm_list_scroller_policy_set(li, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_ON);
132          break;
133
134       case SCROLLER_POLICY_SET_OFF: /* Back to AUTO next (6) */
135          elm_list_scroller_policy_set(li, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
136          break;
137
138       case TOOLTIP_TEXT_SET: /* 7 */
139            {
140               const Eina_List *items = elm_list_items_get(li);
141               if (eina_list_count(items))
142                 {
143                   elm_object_item_tooltip_text_set(eina_list_data_get(eina_list_last(items)), "Tooltip set from API");
144                 }
145               elm_list_scroller_policy_set(li, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_AUTO);
146            }
147          break;
148
149       case TOOLTIP_UNSET: /* 8 */
150            {
151               const Eina_List *items = elm_list_items_get(li);
152               if (eina_list_count(items))
153                 {
154                   elm_object_item_tooltip_unset(eina_list_data_get(eina_list_last(items)));
155                 }
156            }
157          break;
158
159       case ITEM_CURSOR_SET: /* 9 */
160            {
161               const Eina_List *items = elm_list_items_get(li);
162               if (eina_list_count(items))
163                 {
164                   elm_object_item_cursor_set(eina_list_data_get(eina_list_last(items)), ELM_CURSOR_HAND2);
165                 }
166            }
167          break;
168
169       case ITEM_CURSOR_STYLE_SET: /* 10 */
170            {
171               const Eina_List *items = elm_list_items_get(li);
172               if (eina_list_count(items))
173                 {
174                   elm_object_item_cursor_style_set(eina_list_data_get(eina_list_last(items)), "transparent");
175                 }
176            }
177          break;
178
179       case DISABLED_SET: /* 11 */
180            {
181               const Eina_List *items = elm_list_items_get(li);
182               if (eina_list_count(items))
183                 {
184                   elm_object_item_disabled_set(eina_list_data_get(eina_list_last(items)), EINA_TRUE);
185                 }
186            }
187          break;
188
189       case MODE_SET_COMPRESS: /* 12 */
190          elm_list_mode_set(li, ELM_LIST_COMPRESS);
191          break;
192
193       case MODE_SET_LIMIT: /* 13 */
194          elm_list_mode_set(li, ELM_LIST_LIMIT);
195          break;
196
197       case MODE_SET_EXPAND: /* 14 */
198          elm_list_mode_set(li, ELM_LIST_EXPAND);
199          break;
200
201       case HORIZONTAL_SET: /* 15 */
202          elm_list_mode_set(li, ELM_LIST_SCROLL); /* return to default mode */
203          elm_list_horizontal_set(li, EINA_TRUE);
204          break;
205
206       case BOUNCE_SET: /* 16 */
207          elm_list_horizontal_set(li, EINA_FALSE);
208          elm_list_bounce_set(li, EINA_TRUE, EINA_FALSE);
209          break;
210
211       case LIST_CLEAR: /* 17 */
212          elm_list_clear(li);
213          break;
214
215       case API_STATE_LAST:
216          break;
217
218       default:
219          return;
220      }
221 }
222
223 static void
224 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
225 {  /* Will add here a SWITCH command containing code to modify test-object */
226    /* in accordance a->state value. */
227    api_data *a = data;
228    char str[128];
229
230    printf("clicked event on API Button: api_state=<%d>\n", a->state);
231    set_api_state(a);
232    a->state++;
233    sprintf(str, "Next API function (%u)", a->state);
234    elm_object_text_set(obj, str);
235    elm_object_disabled_set(obj, a->state == API_STATE_LAST);
236 }
237
238 static void
239 my_show_it(void        *data,
240            Evas_Object *obj __UNUSED__,
241            void        *event_info __UNUSED__)
242 {
243    elm_list_item_show(data);
244 }
245
246 static void
247 scroll_top(void        *data __UNUSED__,
248            Evas_Object *obj __UNUSED__,
249            void        *event_info __UNUSED__)
250 {
251    printf("Top edge!\n");
252 }
253
254 static void
255 scroll_bottom(void        *data __UNUSED__,
256               Evas_Object *obj __UNUSED__,
257               void        *event_info __UNUSED__)
258 {
259    printf("Bottom edge!\n");
260 }
261
262 static void
263 scroll_left(void        *data __UNUSED__,
264             Evas_Object *obj __UNUSED__,
265             void        *event_info __UNUSED__)
266 {
267    printf("Left edge!\n");
268 }
269
270 static void
271 scroll_right(void        *data __UNUSED__,
272              Evas_Object *obj __UNUSED__,
273              void        *event_info __UNUSED__)
274 {
275    printf("Right edge!\n");
276 }
277
278 static void
279 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
280 {
281    free(data);
282 }
283
284 void
285 test_list(void        *data __UNUSED__,
286           Evas_Object *obj __UNUSED__,
287           void        *event_info __UNUSED__)
288 {
289    Evas_Object *win, *li, *ic, *ic2, *bx, *tb2, *bt, *bxx;
290    char buf[PATH_MAX];
291    Elm_Object_Item *list_it1, *list_it2, *list_it3, *list_it4, *list_it5;
292    api_data *api = calloc(1, sizeof(api_data));
293
294    win = elm_win_util_standard_add("list", "List");
295    elm_win_autodel_set(win, EINA_TRUE);
296    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
297
298    bxx = elm_box_add(win);
299    elm_win_resize_object_add(win, bxx);
300    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
301    evas_object_show(bxx);
302
303    li = elm_list_add(win);
304    elm_list_mode_set(li, ELM_LIST_LIMIT);
305    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
306    evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
307    api->list = li;
308
309    bt = elm_button_add(win);
310    elm_object_text_set(bt, "Next API function");
311    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
312    elm_box_pack_end(bxx, bt);
313    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
314    evas_object_show(bt);
315
316    elm_box_pack_end(bxx, li);
317
318    ic = elm_icon_add(win);
319    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
320    elm_icon_file_set(ic, buf, NULL);
321    elm_icon_resizable_set(ic, 1, 1);
322    list_it1 = elm_list_item_append(li, "Hello", ic, NULL, NULL, NULL);
323    ic = elm_icon_add(win);
324    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
325    elm_icon_resizable_set(ic, 0, 0);
326    elm_icon_file_set(ic, buf, NULL);
327    elm_list_item_append(li, "world", ic, NULL, NULL, NULL);
328    ic = elm_icon_add(win);
329    elm_icon_standard_set(ic, "edit");
330    elm_icon_resizable_set(ic, 0, 0);
331    elm_list_item_append(li, ".", ic, NULL, NULL, NULL);
332
333    ic = elm_icon_add(win);
334    elm_icon_standard_set(ic, "delete");
335    elm_icon_resizable_set(ic, 0, 0);
336    ic2 = elm_icon_add(win);
337    elm_icon_standard_set(ic2, "clock");
338    elm_icon_resizable_set(ic2, 0, 0);
339    list_it2 = elm_list_item_append(li, "How", ic, ic2, NULL, NULL);
340
341    bx = elm_box_add(win);
342    elm_box_horizontal_set(bx, EINA_TRUE);
343
344    ic = elm_icon_add(win);
345    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
346    elm_icon_file_set(ic, buf, NULL);
347    elm_icon_resizable_set(ic, 0, 0);
348    evas_object_size_hint_align_set(ic, 0.5, 0.5);
349    elm_box_pack_end(bx, ic);
350    evas_object_show(ic);
351
352    ic = elm_icon_add(win);
353    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
354    elm_icon_file_set(ic, buf, NULL);
355    elm_icon_resizable_set(ic, 0, 0);
356    evas_object_size_hint_align_set(ic, 0.5, 0.0);
357    elm_box_pack_end(bx, ic);
358    evas_object_show(ic);
359
360    ic = elm_icon_add(win);
361    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
362    elm_icon_file_set(ic, buf, NULL);
363    elm_icon_resizable_set(ic, 0, 0);
364    evas_object_size_hint_align_set(ic, 0.0, EVAS_HINT_EXPAND);
365    elm_box_pack_end(bx, ic);
366    evas_object_show(ic);
367    elm_list_item_append(li, "are", bx, NULL, NULL, NULL);
368
369    elm_list_item_append(li, "you", NULL, NULL, NULL, NULL);
370    list_it3 = elm_list_item_append(li, "doing", NULL, NULL, NULL, NULL);
371    elm_list_item_append(li, "out", NULL, NULL, NULL, NULL);
372    elm_list_item_append(li, "there", NULL, NULL, NULL, NULL);
373    elm_list_item_append(li, "today", NULL, NULL, NULL, NULL);
374    elm_list_item_append(li, "?", NULL, NULL, NULL, NULL);
375    list_it4 = elm_list_item_append(li, "Here", NULL, NULL, NULL, NULL);
376    elm_list_item_append(li, "are", NULL, NULL, NULL, NULL);
377    elm_list_item_append(li, "some", NULL, NULL, NULL, NULL);
378    elm_list_item_append(li, "more", NULL, NULL, NULL, NULL);
379    elm_list_item_append(li, "items", NULL, NULL, NULL, NULL);
380    elm_list_item_append(li, "Is this label long enough?", NULL, NULL, NULL, NULL);
381    list_it5 = elm_list_item_append(li, "Maybe this one is even longer so we can test long long items.", NULL, NULL, NULL, NULL);
382
383    elm_list_go(li);
384
385    evas_object_show(li);
386
387    tb2 = elm_table_add(win);
388    evas_object_size_hint_weight_set(tb2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
389    elm_win_resize_object_add(win, tb2);
390
391    bt = elm_button_add(win);
392    elm_object_text_set(bt, "Hello");
393    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it1);
394    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
395    evas_object_size_hint_align_set(bt, 0.9, 0.5);
396    elm_table_pack(tb2, bt, 0, 0, 1, 1);
397    evas_object_show(bt);
398
399    bt = elm_button_add(win);
400    elm_object_text_set(bt, "How");
401    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it2);
402    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
403    evas_object_size_hint_align_set(bt, 0.9, 0.5);
404    elm_table_pack(tb2, bt, 0, 1, 1, 1);
405    evas_object_show(bt);
406
407    bt = elm_button_add(win);
408    elm_object_text_set(bt, "doing");
409    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it3);
410    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
411    evas_object_size_hint_align_set(bt, 0.9, 0.5);
412    elm_table_pack(tb2, bt, 0, 2, 1, 1);
413    evas_object_show(bt);
414
415    bt = elm_button_add(win);
416    elm_object_text_set(bt, "Here");
417    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it4);
418    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
419    evas_object_size_hint_align_set(bt, 0.9, 0.5);
420    elm_table_pack(tb2, bt, 0, 3, 1, 1);
421    evas_object_show(bt);
422
423    bt = elm_button_add(win);
424    elm_object_text_set(bt, "Maybe this...");
425    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it5);
426    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
427    evas_object_size_hint_align_set(bt, 0.9, 0.5);
428    elm_table_pack(tb2, bt, 0, 4, 1, 1);
429    evas_object_show(bt);
430
431    evas_object_show(tb2);
432
433    evas_object_resize(win, 320, 300);
434    evas_object_show(win);
435
436    evas_object_smart_callback_add(li, "scroll,edge,top", scroll_top, NULL);
437    evas_object_smart_callback_add(li, "scroll,edge,bottom", scroll_bottom, NULL);
438    evas_object_smart_callback_add(li, "scroll,edge,left", scroll_left, NULL);
439    evas_object_smart_callback_add(li, "scroll,edge,right", scroll_right, NULL);
440 }
441
442 void
443 test_list_horizontal(void        *data __UNUSED__,
444                      Evas_Object *obj __UNUSED__,
445                      void        *event_info __UNUSED__)
446 {
447    Evas_Object *win, *li, *ic, *ic2, *bx, *tb2, *bt;
448    char buf[PATH_MAX];
449    Elm_Object_Item *list_it1, *list_it2, *list_it3, *list_it4;
450
451    win = elm_win_util_standard_add("list-horizontal", "List Horizontal");
452    elm_win_autodel_set(win, EINA_TRUE);
453
454    li = elm_list_add(win);
455    elm_list_horizontal_set(li, EINA_TRUE);
456    elm_list_mode_set(li, ELM_LIST_LIMIT);
457    elm_win_resize_object_add(win, li);
458    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
459
460    ic = elm_icon_add(win);
461    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
462    elm_icon_file_set(ic, buf, NULL);
463    elm_icon_resizable_set(ic, 1, 1);
464    list_it1 = elm_list_item_append(li, "Hello", ic, NULL, NULL, NULL);
465    ic = elm_icon_add(win);
466    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
467    elm_icon_resizable_set(ic, 0, 0);
468    elm_icon_file_set(ic, buf, NULL);
469    elm_list_item_append(li, "world", ic, NULL, NULL, NULL);
470    ic = elm_icon_add(win);
471    elm_icon_standard_set(ic, "edit");
472    elm_icon_resizable_set(ic, 0, 0);
473    elm_list_item_append(li, ".", ic, NULL, NULL, NULL);
474
475    ic = elm_icon_add(win);
476    elm_icon_standard_set(ic, "delete");
477    elm_icon_resizable_set(ic, 0, 0);
478    ic2 = elm_icon_add(win);
479    elm_icon_standard_set(ic2, "clock");
480    elm_icon_resizable_set(ic2, 0, 0);
481    list_it2 = elm_list_item_append(li, "How", ic, ic2, NULL, NULL);
482
483    bx = elm_box_add(win);
484
485    ic = elm_icon_add(win);
486    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
487    elm_icon_file_set(ic, buf, NULL);
488    elm_icon_resizable_set(ic, 0, 0);
489    evas_object_size_hint_align_set(ic, 0.5, 0.5);
490    elm_box_pack_end(bx, ic);
491    evas_object_show(ic);
492
493    ic = elm_icon_add(win);
494    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
495    elm_icon_file_set(ic, buf, NULL);
496    elm_icon_resizable_set(ic, 0, 0);
497    evas_object_size_hint_align_set(ic, 0.5, 0.0);
498    elm_box_pack_end(bx, ic);
499    evas_object_show(ic);
500
501    elm_list_item_append(li, "are", bx, NULL, NULL, NULL);
502
503    elm_list_item_append(li, "you", NULL, NULL, NULL, NULL);
504    list_it3 = elm_list_item_append(li, "doing", NULL, NULL, NULL, NULL);
505    elm_list_item_append(li, "out", NULL, NULL, NULL, NULL);
506    elm_list_item_append(li, "there", NULL, NULL, NULL, NULL);
507    elm_list_item_append(li, "today", NULL, NULL, NULL, NULL);
508    elm_list_item_append(li, "?", NULL, NULL, NULL, NULL);
509
510    list_it4 = elm_list_item_append(li, "And", NULL, NULL, NULL, NULL);
511    elm_list_item_append(li, "here", NULL, NULL, NULL, NULL);
512    elm_list_item_append(li, "we", NULL, NULL, NULL, NULL);
513    elm_list_item_append(li, "are", NULL, NULL, NULL, NULL);
514    elm_list_item_append(li, "done", NULL, NULL, NULL, NULL);
515    elm_list_item_append(li, "with", NULL, NULL, NULL, NULL);
516    elm_list_item_append(li, "items.", NULL, NULL, NULL, NULL);
517
518    elm_list_go(li);
519
520    evas_object_show(li);
521
522    tb2 = elm_table_add(win);
523    evas_object_size_hint_weight_set(tb2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
524    elm_win_resize_object_add(win, tb2);
525
526    bt = elm_button_add(win);
527    elm_object_text_set(bt, "Hello");
528    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it1);
529    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
530    evas_object_size_hint_align_set(bt, 0.5, 0.9);
531    elm_table_pack(tb2, bt, 0, 0, 1, 1);
532    evas_object_show(bt);
533
534    bt = elm_button_add(win);
535    elm_object_text_set(bt, "How");
536    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it2);
537    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
538    evas_object_size_hint_align_set(bt, 0.5, 0.9);
539    elm_table_pack(tb2, bt, 1, 0, 1, 1);
540    evas_object_show(bt);
541
542    bt = elm_button_add(win);
543    elm_object_text_set(bt, "doing");
544    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it3);
545    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
546    evas_object_size_hint_align_set(bt, 0.5, 0.9);
547    elm_table_pack(tb2, bt, 2, 0, 1, 1);
548    evas_object_show(bt);
549
550    bt = elm_button_add(win);
551    elm_object_text_set(bt, "And");
552    evas_object_smart_callback_add(bt, "clicked", my_show_it, list_it4);
553    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
554    evas_object_size_hint_align_set(bt, 0.5, 0.9);
555    elm_table_pack(tb2, bt, 3, 0, 1, 1);
556    evas_object_show(bt);
557
558    evas_object_show(tb2);
559
560    evas_object_resize(win, 320, 300);
561    evas_object_show(win);
562 }
563
564 /***********/
565
566 static void
567 my_li2_clear(void        *data,
568              Evas_Object *obj __UNUSED__,
569              void        *event_info __UNUSED__)
570 {
571    elm_list_clear(data);
572 }
573
574 static void
575 my_li2_sel(void        *data __UNUSED__,
576            Evas_Object *obj,
577            void        *event_info __UNUSED__)
578 {
579    Elm_Object_Item *list_it = elm_list_selected_item_get(obj);
580    elm_list_item_selected_set(list_it, 0);
581 }
582
583 void
584 test_list2(void        *data __UNUSED__,
585            Evas_Object *obj __UNUSED__,
586            void        *event_info __UNUSED__)
587 {
588    Evas_Object *win, *bg, *li, *ic, *ic2, *bx, *bx2, *bt;
589    char buf[PATH_MAX];
590    Elm_Object_Item *list_it;
591
592    win = elm_win_add(NULL, "list2", ELM_WIN_BASIC);
593    elm_win_title_set(win, "List 2");
594    elm_win_autodel_set(win, EINA_TRUE);
595
596    bg = elm_bg_add(win);
597    snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
598    elm_bg_file_set(bg, buf, NULL);
599    elm_win_resize_object_add(win, bg);
600    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
601    evas_object_show(bg);
602
603    bx = elm_box_add(win);
604    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
605    elm_win_resize_object_add(win, bx);
606    evas_object_show(bx);
607
608    li = elm_list_add(win);
609    evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
610    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
611    elm_list_mode_set(li, ELM_LIST_LIMIT);
612 //   elm_list_multi_select_set(li, 1);
613
614    ic = elm_icon_add(win);
615    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
616    elm_icon_file_set(ic, buf, NULL);
617    list_it = elm_list_item_append(li, "Hello", ic, NULL, my_li2_sel, NULL);
618    elm_list_item_selected_set(list_it, EINA_TRUE);
619    ic = elm_icon_add(win);
620    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
621    elm_icon_resizable_set(ic, 0, 0);
622    elm_icon_file_set(ic, buf, NULL);
623    elm_list_item_append(li, "world", ic, NULL, NULL, NULL);
624    ic = elm_icon_add(win);
625    elm_icon_standard_set(ic, "edit");
626    elm_icon_resizable_set(ic, 0, 0);
627    elm_list_item_append(li, ".", ic, NULL, NULL, NULL);
628
629    ic = elm_icon_add(win);
630    elm_icon_standard_set(ic, "delete");
631    elm_icon_resizable_set(ic, 0, 0);
632    ic2 = elm_icon_add(win);
633    elm_icon_standard_set(ic2, "clock");
634    elm_icon_resizable_set(ic2, 0, 0);
635    elm_list_item_append(li, "How", ic, ic2, NULL, NULL);
636
637    bx2 = elm_box_add(win);
638    elm_box_horizontal_set(bx2, EINA_TRUE);
639
640    ic = elm_icon_add(win);
641    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
642    elm_icon_file_set(ic, buf, NULL);
643    elm_icon_resizable_set(ic, 0, 0);
644    evas_object_size_hint_align_set(ic, 0.5, 0.5);
645    elm_box_pack_end(bx2, ic);
646    evas_object_show(ic);
647
648    ic = elm_icon_add(win);
649    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
650    elm_icon_file_set(ic, buf, NULL);
651    elm_icon_resizable_set(ic, 0, 0);
652    evas_object_size_hint_align_set(ic, 0.5, 0.0);
653    elm_box_pack_end(bx2, ic);
654    evas_object_show(ic);
655    elm_list_item_append(li, "are", bx2, NULL, NULL, NULL);
656
657    elm_list_item_append(li, "you", NULL, NULL, NULL, NULL);
658    elm_list_item_append(li, "doing", NULL, NULL, NULL, NULL);
659    elm_list_item_append(li, "out", NULL, NULL, NULL, NULL);
660    elm_list_item_append(li, "there", NULL, NULL, NULL, NULL);
661    elm_list_item_append(li, "today", NULL, NULL, NULL, NULL);
662    elm_list_item_append(li, "?", NULL, NULL, NULL, NULL);
663    elm_list_item_append(li, "Here", NULL, NULL, NULL, NULL);
664    elm_list_item_append(li, "are", NULL, NULL, NULL, NULL);
665    elm_list_item_append(li, "some", NULL, NULL, NULL, NULL);
666    elm_list_item_append(li, "more", NULL, NULL, NULL, NULL);
667    elm_list_item_append(li, "items", NULL, NULL, NULL, NULL);
668    elm_list_item_append(li, "Longer label.", NULL, NULL, NULL, NULL);
669
670    elm_list_go(li);
671
672    elm_box_pack_end(bx, li);
673    evas_object_show(li);
674
675    bx2 = elm_box_add(win);
676    elm_box_horizontal_set(bx2, EINA_TRUE);
677    elm_box_homogeneous_set(bx2, EINA_TRUE);
678    evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0.0);
679    evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, EVAS_HINT_FILL);
680
681    bt = elm_button_add(win);
682    elm_object_text_set(bt, "Clear");
683    evas_object_smart_callback_add(bt, "clicked", my_li2_clear, li);
684    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
685    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
686    elm_box_pack_end(bx2, bt);
687    evas_object_show(bt);
688
689    elm_box_pack_end(bx, bx2);
690    evas_object_show(bx2);
691
692    evas_object_resize(win, 320, 300);
693    evas_object_show(win);
694 }
695
696 /***********/
697
698 static void
699 _bt_clicked(void        *data __UNUSED__,
700             Evas_Object *obj __UNUSED__,
701             void        *event_info __UNUSED__)
702 {
703    printf("button was clicked\n");
704 }
705
706 static void
707 _it_clicked(void        *data __UNUSED__,
708             Evas_Object *obj __UNUSED__,
709             void        *event_info __UNUSED__)
710 {
711    printf("item was clicked\n");
712 }
713
714 void
715 test_list3(void        *data __UNUSED__,
716            Evas_Object *obj __UNUSED__,
717            void        *event_info __UNUSED__)
718 {
719    Evas_Object *win, *li, *ic, *ic2, *bx;
720    char buf[PATH_MAX];
721
722    win = elm_win_util_standard_add("list3", "List 3");
723    elm_win_autodel_set(win, EINA_TRUE);
724
725    li = elm_list_add(win);
726    elm_win_resize_object_add(win, li);
727    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
728    elm_list_mode_set(li, ELM_LIST_COMPRESS);
729
730    ic = elm_icon_add(win);
731    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
732    elm_icon_resizable_set(ic, 0, 0);
733    elm_icon_file_set(ic, buf, NULL);
734    ic2 = elm_button_add(win);
735    elm_object_text_set(ic2, "Click me");
736    evas_object_smart_callback_add(ic2, "clicked", _bt_clicked, NULL);
737    evas_object_propagate_events_set(ic2, 0);
738    elm_list_item_append(li, "Hello", ic, ic2, _it_clicked, NULL);
739
740    ic = elm_icon_add(win);
741    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
742    elm_icon_resizable_set(ic, 0, 0);
743    elm_icon_file_set(ic, buf, NULL);
744    ic2 = elm_button_add(win);
745    elm_object_text_set(ic2, "Click me");
746    evas_object_smart_callback_add(ic2, "clicked", _bt_clicked, NULL);
747    elm_list_item_append(li, "world", ic, ic2, _it_clicked, NULL);
748
749    ic = elm_icon_add(win);
750    elm_icon_standard_set(ic, "edit");
751    elm_icon_resizable_set(ic, 0, 0);
752    elm_list_item_append(li, ".", ic, NULL, NULL, NULL);
753
754    ic = elm_icon_add(win);
755    elm_icon_standard_set(ic, "delete");
756    elm_icon_resizable_set(ic, 0, 0);
757    ic2 = elm_icon_add(win);
758    elm_icon_standard_set(ic2, "clock");
759    elm_icon_resizable_set(ic2, 0, 0);
760    elm_list_item_append(li, "How", ic, ic2, NULL, NULL);
761
762    bx = elm_box_add(win);
763    elm_box_horizontal_set(bx, EINA_TRUE);
764
765    ic = elm_icon_add(win);
766    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
767    elm_icon_file_set(ic, buf, NULL);
768    elm_icon_resizable_set(ic, 0, 0);
769    evas_object_size_hint_align_set(ic, 0.5, 0.5);
770    elm_box_pack_end(bx, ic);
771    evas_object_show(ic);
772
773    ic = elm_icon_add(win);
774    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
775    elm_icon_file_set(ic, buf, NULL);
776    elm_icon_resizable_set(ic, 0, 0);
777    evas_object_size_hint_align_set(ic, 0.5, 0.0);
778    elm_box_pack_end(bx, ic);
779    evas_object_show(ic);
780
781    ic = elm_icon_add(win);
782    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
783    elm_icon_file_set(ic, buf, NULL);
784    elm_icon_resizable_set(ic, 0, 0);
785    evas_object_size_hint_align_set(ic, 0.0, EVAS_HINT_EXPAND);
786    elm_box_pack_end(bx, ic);
787    evas_object_show(ic);
788
789    elm_list_item_append(li, "are", bx, NULL, NULL, NULL);
790    elm_list_item_append(li, "you", NULL, NULL, NULL, NULL);
791    elm_list_item_append(li, "doing", NULL, NULL, NULL, NULL);
792    elm_list_item_append(li, "out", NULL, NULL, NULL, NULL);
793    elm_list_item_append(li, "there", NULL, NULL, NULL, NULL);
794    elm_list_item_append(li, "today", NULL, NULL, NULL, NULL);
795    elm_list_item_append(li, "?", NULL, NULL, NULL, NULL);
796    elm_list_item_append(li, "Here", NULL, NULL, NULL, NULL);
797    elm_list_item_append(li, "are", NULL, NULL, NULL, NULL);
798    elm_list_item_append(li, "some", NULL, NULL, NULL, NULL);
799    elm_list_item_append(li, "more", NULL, NULL, NULL, NULL);
800    elm_list_item_append(li, "items", NULL, NULL, NULL, NULL);
801    elm_list_item_append(li, "Is this label long enough?", NULL, NULL, NULL, NULL);
802    elm_list_item_append(li, "Maybe this one is even longer so we can test long long items.", NULL, NULL, NULL, NULL);
803
804    elm_list_go(li);
805
806    evas_object_show(li);
807
808    evas_object_resize(win, 320, 300);
809    evas_object_show(win);
810 }
811
812 ///////////////////////////////////////////////////////////////////////////////////////
813
814 struct Pginfo
815 {
816    Evas_Object *naviframe, *win;
817 };
818
819 static void
820 test_list4_back_cb(void        *data,
821                    Evas_Object *obj __UNUSED__,
822                    void        *event_info __UNUSED__)
823 {
824    struct Pginfo *info = data;
825    if (!info) return;
826
827    elm_naviframe_item_pop(info->naviframe);
828 }
829
830 static void
831 test_list4_swipe(void        *data,
832                  Evas_Object *obj __UNUSED__,
833                  void        *event_info)
834 {
835    Evas_Object *box, *entry, *button;
836    struct Pginfo *info = data;
837    char *item_data;
838    if ((!event_info) || (!data)) return;
839
840    item_data = elm_object_item_data_get(event_info);
841
842    box = elm_box_add(info->win);
843    elm_box_horizontal_set(box, EINA_FALSE);
844    elm_box_homogeneous_set(box, EINA_FALSE);
845    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
846    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
847    evas_object_show(box);
848
849    entry = elm_entry_add(info->win);
850    elm_entry_scrollable_set(entry, EINA_TRUE);
851    elm_entry_editable_set(entry, EINA_FALSE);
852    elm_object_text_set(entry, item_data);
853    evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
854    evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
855    evas_object_show(entry);
856
857    button = elm_button_add(info->win);
858    elm_object_text_set(button, "back");
859    evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, 0);
860    evas_object_size_hint_align_set(button, EVAS_HINT_FILL, 0);
861    evas_object_smart_callback_add(button, "clicked", test_list4_back_cb, info);
862    evas_object_show(button);
863
864    elm_box_pack_start(box, entry);
865    elm_box_pack_end(box, button);
866
867    elm_naviframe_item_simple_push(info->naviframe, box);
868 }
869
870 void
871 test_list4(void        *data __UNUSED__,
872            Evas_Object *obj __UNUSED__,
873            void        *event_info __UNUSED__)
874 {
875    Evas_Object *win, *li, *ic, *ic2, *naviframe;
876    static struct Pginfo info = {NULL, NULL};
877    char buf[PATH_MAX];
878
879    win = elm_win_util_standard_add("list4", "List 4");
880    elm_win_autodel_set(win, EINA_TRUE);
881    info.win = win;
882
883    naviframe = elm_naviframe_add(win);
884    elm_win_resize_object_add(win, naviframe);
885    evas_object_size_hint_weight_set(naviframe, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
886    evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL);
887    evas_object_show(naviframe);
888    info.naviframe = naviframe;
889
890    li = elm_list_add(win);
891    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
892    elm_list_mode_set(li, ELM_LIST_COMPRESS);
893    evas_object_smart_callback_add(li, "swipe", test_list4_swipe, &info);
894    elm_naviframe_item_simple_push(naviframe, li);
895
896    static char pf_data[] = "Pink Floyd were formed in 1965, and originally consisted of university"                       \
897                            "students Roger Waters, Nick Mason, Richard Wright, and Syd Barrett. The group were a popular" \
898                            "fixture on London's underground music scene, and under Barrett's leadership released two "    \
899                            "charting singles, \"Arnold Layne\" and \"See Emily Play\", and a successful debut album, "    \
900                            "ThePiper at the Gates of Dawn. In 1968, guitarist and singer David Gilmour joined the "       \
901                            "line-up. Barrett was soon removed, due to his increasingly erratic behaviour. Following "     \
902                            "Barrett's departure, bass player and singer Roger Waters became the band's lyricist and "     \
903                            "conceptual leader, with Gilmour assuming lead guitar and much of the vocals. With this "      \
904                            "line-up, Floyd went on to achieve worldwide critical and commercial success with the "        \
905                            "conceptalbums The Dark Side of the Moon, Wish You Were Here, Animals, and The Wall.";
906    ic = elm_icon_add(win);
907    snprintf(buf, sizeof(buf), "%s/images/mystrale.jpg", elm_app_data_dir_get());
908    elm_icon_resizable_set(ic, 0, 0);
909    elm_icon_file_set(ic, buf, NULL);
910    elm_list_item_append(li, "Pink Floyd", ic, NULL, NULL, &pf_data);
911
912    static char ds_data[] = "Dire Straits were a British rock band, formed by Mark Knopfler "                          \
913                            "(lead vocals and lead guitar), his younger brother David Knopfler (rhythm guitar and "    \
914                            "backing vocals), John Illsley (bass guitar and backing vocals), and Pick Withers (drums " \
915                            "and percussion), and managed by Ed Bicknell, active between 1977 and 1995. Although the " \
916                            "band was formed in an era when punk rock was at the forefront, Dire Straits played a more "
917                            "bluesy style, albeit with a stripped-down sound that appealed to audiences weary of the "   \
918                            "overproduced stadium rock of the 1970s.[citation needed] In their early days, Mark and "    \
919                            "David requested that pub owners turn down their sound so that patrons could converse "      \
920                            "while the band played, an indication of their unassuming demeanor. Despite this oddly "     \
921                            "self-effacing approach to rock and roll, Dire Straits soon became hugely successful, with " \
922                            "their first album going multi-platinum globally.";
923    ic = elm_icon_add(win);
924    snprintf(buf, sizeof(buf), "%s/images/mystrale_2.jpg", elm_app_data_dir_get());
925    elm_icon_resizable_set(ic, 0, 0);
926    elm_icon_file_set(ic, buf, NULL);
927    elm_list_item_append(li, "Dire Straits", ic, NULL, NULL, &ds_data);
928
929    static char uh_data[] = "Uriah Heep are an English hard rock band. The band released several "                       \
930                            "commercially successful albums in the 1970s such as Uriah Heep Live (1973), but their "     \
931                            "audience declined by the 1980s, to the point where they became essentially a cult band in " \
932                            "the United States and United Kingdom. Uriah Heep maintain a significant following in "      \
933                            "Germany, the Netherlands, Scandinavia, the Balkans, Japan and Russia, where they still "    \
934                            "perform at stadium-sized venues.";
935    ic = elm_icon_add(win);
936    snprintf(buf, sizeof(buf), "%s/images/icon_17.png", elm_app_data_dir_get());
937    elm_icon_resizable_set(ic, 1, 1);
938    elm_icon_file_set(ic, buf, NULL);
939    elm_list_item_append(li, "Uriah Heep", ic, NULL, NULL, &uh_data);
940
941    static char r_data[] = "Rush is a Canadian rock band formed in August 1968, in the Willowdale "                       \
942                           "neighbourhood of Toronto, Ontario. The band is composed of bassist, keyboardist, and lead "   \
943                           "vocalist Geddy Lee, guitarist Alex Lifeson, and drummer and lyricist Neil Peart. The band "   \
944                           "and its membership went through a number of re-configurations between 1968 and 1974, "        \
945                           "achieving their current form when Peart replaced original drummer John Rutsey in July 1974, " \
946                           "two weeks before the group's first United States tour.";
947    ic = elm_icon_add(win);
948    snprintf(buf, sizeof(buf), "%s/images/icon_21.png", elm_app_data_dir_get());
949    elm_icon_resizable_set(ic, 0, 0);
950    elm_icon_file_set(ic, buf, NULL);
951    ic2 = elm_icon_add(win);
952    elm_icon_standard_set(ic2, "clock");
953    elm_icon_resizable_set(ic2, 0, 0);
954    elm_list_item_append(li, "Rush", ic, ic2, NULL, &r_data);
955
956    elm_list_go(li);
957
958    evas_object_show(li);
959    evas_object_resize(win, 320, 300);
960    evas_object_show(win);
961 }
962
963 /////////////////////////////////////////////////////////////////////////////////////////
964 struct list5_data_cb
965 {
966    Evas_Object *win, *list;
967 };
968
969 static void
970 test_list5_item_del(void        *data,
971                     Evas_Object *obj __UNUSED__,
972                     void        *event_info __UNUSED__)
973 {
974    elm_object_item_del(data);
975 }
976
977 static void
978 test_list5_swipe(void        *data __UNUSED__,
979                  Evas_Object *obj __UNUSED__,
980                  void        *event_info)
981 {
982    Evas_Object *button;
983    struct list5_data_cb *info = elm_object_item_data_get(event_info);
984
985    if (elm_object_item_part_content_get(event_info, "end")) return;
986
987    button = elm_button_add(info->win);
988    elm_object_text_set(button, "delete");
989    evas_object_propagate_events_set(button, 0);
990    evas_object_smart_callback_add(button, "clicked", test_list5_item_del,
991                                   event_info);
992    elm_object_item_part_content_set(event_info, "end", button);
993 }
994
995 void
996 test_list5(void        *data __UNUSED__,
997            Evas_Object *obj __UNUSED__,
998            void        *event_info __UNUSED__)
999 {
1000    Evas_Object *win, *li;
1001    static struct list5_data_cb info;
1002
1003    win = elm_win_util_standard_add("list5", "List 5");
1004    elm_win_autodel_set(win, EINA_TRUE);
1005    info.win = win;
1006
1007    li = elm_list_add(win);
1008    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1009    elm_list_mode_set(li, ELM_LIST_COMPRESS);
1010    evas_object_smart_callback_add(li, "swipe", test_list5_swipe, NULL);
1011    elm_win_resize_object_add(win, li);
1012    evas_object_show(li);
1013    info.list = li;
1014
1015    elm_list_item_append(li, "Network", NULL, NULL, NULL, &info);
1016    elm_list_item_append(li, "Audio", NULL, NULL, NULL, &info);
1017
1018    elm_list_go(li);
1019    evas_object_resize(win, 320, 300);
1020    evas_object_show(win);
1021 }
1022
1023 #endif