b17c8f9712a19a24ccd80dcfe2201dca9f9cb242
[framework/uifw/elementary.git] / src / bin / test_gengrid.c
1 #include <Elementary_Cursor.h>
2 #include "test.h"
3 #ifdef HAVE_CONFIG_H
4 # include "elementary_config.h"
5 #endif
6 #include <Elementary.h>
7 #ifndef ELM_LIB_QUICKLAUNCH
8
9 static Elm_Gengrid_Item_Class *gic;
10 static Elm_Gengrid_Item_Class ggic;
11
12 Evas_Object *grid_content_get(void *data, Evas_Object *obj, const char *part);
13 char *grid_text_get(void *data, Evas_Object *obj __UNUSED__,
14                     const char *part __UNUSED__);
15 Eina_Bool grid_state_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
16                          const char *part __UNUSED__);
17 void grid_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__);
18
19 typedef struct _Testitem
20 {
21    Elm_Object_Item *item;
22    const char *path;
23    int mode;
24    int onoff;
25 } Testitem;
26
27 struct _api_data
28 {
29    unsigned int state;  /* What state we are testing       */
30    Evas_Object *box;           /* Use this to get box content     */
31    Evas_Object *grid;
32 };
33 typedef struct _api_data api_data;
34
35 enum _api_state
36 {
37    GRID_ALIGN_SET,
38    GRID_BRING_IN,
39    GRID_NO_SELECT_MODE,
40    GRID_NO_BOUNCE,
41    GRID_PAGE_RELATIVE,
42    GRID_PAGE_SIZE,
43    GRID_TOOLTIP_SET_TEXT,
44    GRID_TOOLTIP_UNSET,
45    GRID_ITEM_CLASS_SET,
46    GRID_ITEM_UPDATE_SET,
47    GRID_PAGE_BRING_IN,
48    GRID_PAGE_SHOW,
49    GRID_TOOLTIP_CONTENT_CB,
50    GRID_TOOLTIP_STYLE_SET,
51    GRID_TOOLTIP_WINDOW_MODE_SET,
52    API_STATE_LAST
53 };
54 typedef enum _api_state api_state;
55
56 static void
57 set_api_state(api_data *api)
58 {
59    Evas_Object *grid = api->grid;
60
61    /* use elm_box_children_get() to get list of children */
62    switch(api->state)
63      { /* Put all api-changes under switch */
64       case GRID_ALIGN_SET: /* 0 */
65          elm_gengrid_align_set(grid, 0.2, 0.8);
66          break;
67
68       case GRID_BRING_IN: /* 1 */
69          elm_gengrid_item_bring_in(elm_gengrid_first_item_get(grid), ELM_GENGRID_ITEM_SCROLLTO_IN);
70          break;
71
72       case GRID_NO_SELECT_MODE: /* 2 */
73          elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_NONE);
74          break;
75
76       case GRID_NO_BOUNCE: /* 3 */
77          elm_gengrid_bounce_set(grid, EINA_TRUE, EINA_FALSE);
78          break;
79
80       case GRID_PAGE_RELATIVE: /* 4 */
81          elm_gengrid_bounce_set(grid, EINA_TRUE, EINA_TRUE);
82          elm_gengrid_page_relative_set(grid, 0.5, 0.5);
83          break;
84
85       case GRID_PAGE_SIZE: /* 5 */
86          elm_gengrid_page_size_set(grid, 50, 25);
87          break;
88
89       case GRID_TOOLTIP_SET_TEXT: /* 6 */
90            {
91               Elm_Object_Item *item = elm_gengrid_first_item_get(grid);
92               elm_gengrid_item_tooltip_text_set(item, "This is the first item");
93            }
94          break;
95
96       case GRID_TOOLTIP_UNSET: /* 7 */
97            {
98               Elm_Object_Item *item = elm_gengrid_first_item_get(grid);
99               elm_gengrid_item_tooltip_unset(item);
100            }
101          break;
102
103       case API_STATE_LAST:
104          break;
105
106       default:
107          return;
108      }
109 }
110
111 static void
112 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
113 {  /* Will add here a SWITCH command containing code to modify test-object */
114    /* in accordance a->state value. */
115    api_data *a = data;
116    char str[128];
117
118    printf("clicked event on API Button: api_state=<%d>\n", a->state);
119    set_api_state(a);
120    a->state++;
121    sprintf(str, "Next API function (%u)", a->state);
122    elm_object_text_set(obj, str);
123    elm_object_disabled_set(obj, a->state == API_STATE_LAST);
124 }
125
126 static const char *img[9] =
127 {
128    "panel_01.jpg",
129    "plant_01.jpg",
130    "rock_01.jpg",
131    "rock_02.jpg",
132    "sky_01.jpg",
133    "sky_02.jpg",
134    "sky_03.jpg",
135    "sky_04.jpg",
136    "wood_01.jpg",
137 };
138
139 static const char *cur[4] =
140 {
141    ELM_CURSOR_CIRCLE,
142    ELM_CURSOR_CLOCK,
143    ELM_CURSOR_COFFEE_MUG,
144    ELM_CURSOR_CROSS,
145 };
146
147 static int n_current_pic = 0;
148 static void
149 _horizontal_grid(void *data, Evas_Object *obj, void *event_info __UNUSED__)
150 {
151    Evas_Object *grid = data;
152    elm_gengrid_horizontal_set(grid, elm_check_state_get(obj));
153 }
154
155 static void
156 grid_drag_up(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
157 {
158    printf("Drag up: %p\n", event_info);
159 }
160
161 static void
162 grid_drag_right(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
163 {
164    printf("Drag right: %p\n", event_info);
165 }
166
167 static void
168 grid_drag_down(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
169 {
170    printf("Drag down: %p\n", event_info);
171 }
172
173 static void
174 grid_drag_left(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
175 {
176    printf("Drag left: %p\n", event_info);
177 }
178
179 static void
180 grid_drag_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
181 {
182    printf("Drag stop: %p\n", event_info);
183 }
184
185 static void
186 grid_selected(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
187 {
188    printf("Selected: %p\n", event_info);
189 }
190
191 static void
192 grid_double_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
193 {
194    printf("Double clicked: %p\n", event_info);
195 }
196
197 static void
198 grid_longpress(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
199 {
200    printf("longpress %p\n", event_info);
201 }
202
203 static void
204 grid_moved(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
205 {
206    printf("moved %p\n", event_info);
207 }
208
209 static void
210 grid_item_check_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
211 {
212    Testitem *ti = data;
213    ti->onoff = elm_check_state_get(obj);
214    printf("item %p onoff = %i\n", ti, ti->onoff);
215 }
216
217 char *
218 grid_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
219 {
220    const Testitem *ti = data;
221    char buf[256];
222    snprintf(buf, sizeof(buf), "Photo %s", ti->path);
223    return strdup(buf);
224 }
225
226 Evas_Object *
227 grid_content_get(void *data, Evas_Object *obj, const char *part)
228 {
229    const Testitem *ti = data;
230    if (!strcmp(part, "elm.swallow.icon"))
231      {
232         Evas_Object *icon = elm_bg_add(obj);
233         elm_bg_file_set(icon, ti->path, NULL);
234         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
235         evas_object_show(icon);
236         return icon;
237      }
238    else if (!strcmp(part, "elm.swallow.end"))
239      {
240         Evas_Object *ck;
241         ck = elm_check_add(obj);
242         evas_object_propagate_events_set(ck, 0);
243         elm_check_state_set(ck, ti->onoff);
244         evas_object_smart_callback_add(ck, "changed", grid_item_check_changed, data);
245         evas_object_show(ck);
246         return ck;
247      }
248    return NULL;
249 }
250
251 Eina_Bool
252 grid_state_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
253 {
254    return EINA_FALSE;
255 }
256
257 void
258 grid_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
259 {
260 }
261
262 static void
263 grid_sel(void *data, Evas_Object *obj, void *event_info)
264 {
265    printf("sel item data [%p] on grid obj [%p], pointer [%p]\n", data, obj, event_info);
266 }
267
268 static void
269 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
270 {
271    free(data);
272 }
273
274 static void
275 always_select_mode_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
276 {
277    api_data *api = data;
278    if (elm_check_state_get(obj))
279      elm_gengrid_select_mode_set(api->grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
280    else
281      elm_gengrid_select_mode_set(api->grid, ELM_OBJECT_SELECT_MODE_DEFAULT);
282 }
283
284 static void
285 multi_select_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
286 {
287    api_data *api = data;
288    elm_gengrid_multi_select_set(api->grid, elm_check_state_get(obj));
289 }
290
291 static void
292 clear_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
293 {
294    api_data *api = data;
295    elm_gengrid_clear(api->grid);
296 }
297
298 static Evas_Object *
299 create_gengrid(Evas_Object *obj, int items)
300 {
301    Evas_Object *grid = NULL;
302    static Testitem ti[144];
303    int i, n;
304    char buf[PATH_MAX];
305
306    grid = elm_gengrid_add(obj);
307    elm_gengrid_item_size_set(grid, 150, 150);
308    elm_gengrid_horizontal_set(grid, EINA_FALSE);
309    elm_gengrid_multi_select_set(grid, EINA_TRUE);
310    elm_gengrid_reorder_mode_set(grid, EINA_TRUE);
311    evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
312    evas_object_smart_callback_add(grid, "clicked,double", grid_double_clicked, NULL);
313    evas_object_smart_callback_add(grid, "longpressed", grid_longpress, NULL);
314    evas_object_smart_callback_add(grid, "moved", grid_moved, NULL);
315    evas_object_smart_callback_add(grid, "drag,start,up", grid_drag_up, NULL);
316    evas_object_smart_callback_add(grid, "drag,start,right", grid_drag_right, NULL);
317    evas_object_smart_callback_add(grid, "drag,start,down", grid_drag_down, NULL);
318    evas_object_smart_callback_add(grid, "drag,start,left", grid_drag_left, NULL);
319    evas_object_smart_callback_add(grid, "drag,stop", grid_drag_stop, NULL);
320    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
321    evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
322
323    gic = elm_gengrid_item_class_new();
324    gic->item_style = "default";
325    gic->func.text_get = grid_text_get;
326    gic->func.content_get = grid_content_get;
327    gic->func.state_get = grid_state_get;
328    gic->func.del = grid_del;
329
330    n = 0;
331    for (i = 0; i < items; i++)
332      {
333         snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n]);
334         n = (n + 1) % 9;
335         ti[i].mode = i;
336         ti[i].path = eina_stringshare_add(buf);
337         ti[i].item = elm_gengrid_item_append(grid, gic, &(ti[i]), grid_sel, NULL);
338         if (!(i % 5))
339           elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
340      }
341    elm_gengrid_item_class_free(gic);
342
343    return grid;
344 }
345
346 static void
347 restore_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
348 {
349    api_data *api = data;
350    elm_box_clear(api->box);
351    api->grid = create_gengrid(obj, (12 * 12));
352    elm_box_pack_end(api->box, api->grid);
353    evas_object_show(api->grid);
354 }
355
356 static void
357 filled_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
358 {
359    Evas_Object *box = (Evas_Object *)data;
360    Evas_Object *grid;
361
362    elm_box_clear(box);
363    grid = create_gengrid(box, 1);
364    elm_gengrid_filled_set(grid, elm_check_state_get(obj));
365    elm_box_pack_end(box, grid);
366    evas_object_show(grid);
367 }
368
369 static void
370 filled_bt_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
371 {
372    Evas_Object *win, *box, *content_box, *grid, *tg;
373
374    win = elm_win_util_standard_add("test filled", "Test Filled");
375    elm_win_autodel_set(win, EINA_TRUE);
376
377    box = elm_box_add(win);
378    elm_win_resize_object_add(win, box);
379    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
380    evas_object_show(box);
381
382    content_box = elm_box_add(win);
383    elm_win_resize_object_add(win, content_box);
384    evas_object_size_hint_weight_set(content_box, EVAS_HINT_EXPAND,
385                                     EVAS_HINT_EXPAND);
386    evas_object_size_hint_align_set(content_box, EVAS_HINT_FILL,
387                                    EVAS_HINT_FILL);
388    elm_box_pack_end(box, content_box);
389    evas_object_show(content_box);
390
391    grid = create_gengrid(win, 1);
392    elm_box_pack_end(content_box, grid);
393    evas_object_show(grid);
394
395    tg = elm_check_add(win);
396    elm_object_text_set(tg, "Filled");
397    evas_object_smart_callback_add(tg, "changed", filled_cb, content_box);
398    elm_box_pack_end(box, tg);
399    evas_object_show(tg);
400
401    evas_object_resize(win, 450, 200);
402    evas_object_show(win);
403 }
404
405 static void
406 cursor_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
407 {
408    Evas_Object *grid = (Evas_Object *)data;
409    Elm_Object_Item *item = NULL;
410    int i = 0;
411
412    for ((item = elm_gengrid_first_item_get(grid)); item;
413         (item = elm_gengrid_item_next_get(item)))
414      {
415         if (!elm_check_state_get(obj))
416           {
417              elm_gengrid_item_cursor_unset(item);
418              continue;
419           }
420
421         elm_gengrid_item_cursor_set(item, cur[i]);
422         elm_gengrid_item_cursor_engine_only_set(item, EINA_FALSE);
423         i++;
424      }
425 }
426
427 static void
428 cursor_bt_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
429 {
430    Evas_Object *win, *box, *content_box, *hbox, *grid, *tg;
431
432    win = elm_win_util_standard_add("test cursor", "Test Cursor");
433    elm_win_autodel_set(win, EINA_TRUE);
434
435    box = elm_box_add(win);
436    elm_win_resize_object_add(win, box);
437    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
438    evas_object_show(box);
439
440    content_box = elm_box_add(win);
441    elm_win_resize_object_add(win, content_box);
442    evas_object_size_hint_weight_set(content_box, EVAS_HINT_EXPAND,
443                                     EVAS_HINT_EXPAND);
444    evas_object_size_hint_align_set(content_box, EVAS_HINT_FILL,
445                                    EVAS_HINT_FILL);
446    elm_box_pack_end(box, content_box);
447    evas_object_show(content_box);
448
449    grid = create_gengrid(win, 4);
450    elm_box_pack_end(content_box, grid);
451    evas_object_show(grid);
452
453    hbox = elm_box_add(win);
454    elm_box_horizontal_set(hbox, EINA_TRUE);
455
456    tg = elm_check_add(win);
457    elm_object_text_set(tg, "Cursor");
458    evas_object_smart_callback_add(tg, "changed", cursor_cb, grid);
459    elm_box_pack_end(hbox, tg);
460    evas_object_show(tg);
461
462    elm_box_pack_end(box, hbox);
463    evas_object_show(hbox);
464
465    evas_object_resize(win, 450, 450);
466    evas_object_show(win);
467 }
468
469 void
470 test_gengrid(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
471 {
472    Evas_Object *win, *bt, *content_box, *bxx, *bx, *tg;
473    api_data *api = calloc(1, sizeof(api_data));
474
475    win = elm_win_util_standard_add("gengrid", "GenGrid");
476    elm_win_autodel_set(win, EINA_TRUE);
477    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
478
479    bxx = elm_box_add(win);
480    api->box = bxx;
481    elm_win_resize_object_add(win, bxx);
482    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
483    evas_object_show(bxx);
484
485    content_box = elm_box_add(win);
486    api->box = content_box;
487    evas_object_size_hint_weight_set(content_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
488    evas_object_size_hint_align_set(content_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
489    evas_object_show(content_box);
490
491    /* Create GenGrid */
492    api->grid = create_gengrid(win, (12 * 12));
493
494    bt = elm_button_add(win);
495    elm_object_text_set(bt, "Next API function");
496    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked,
497                                   (void *)api);
498    elm_box_pack_end(bxx, bt);
499    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
500    evas_object_show(bt);
501
502    elm_box_pack_end(content_box, api->grid);
503    elm_box_pack_end(bxx, content_box);
504    evas_object_show(api->grid);
505
506    bx = elm_box_add(win);
507    elm_box_horizontal_set(bx, EINA_TRUE);
508    elm_box_pack_end(bxx, bx);
509    evas_object_show(bx);
510
511    /* Gengrid Always Select Mode Test */
512    tg = elm_check_add(win);
513    evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
514    evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, EVAS_HINT_FILL);
515    elm_object_text_set(tg, "Always Select Mode");
516    evas_object_smart_callback_add(tg, "changed", always_select_mode_cb,
517                                   (void *)api);
518    elm_box_pack_end(bx, tg);
519    evas_object_show(tg);
520
521    tg = elm_check_add(win);
522    evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
523    evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, EVAS_HINT_FILL);
524    elm_object_text_set(tg, "Multi Select Mode");
525    elm_check_state_set(tg, EINA_TRUE);
526    evas_object_smart_callback_add(tg, "changed", multi_select_cb,
527                                   (void *)api);
528    elm_box_pack_end(bx, tg);
529    evas_object_show(tg);
530
531    /* Gengrid Clear Test */
532    bt = elm_button_add(win);
533    elm_object_text_set(bt, "Clear");
534    evas_object_smart_callback_add(bt, "clicked", clear_bt_clicked,
535                                   (void *)api);
536    elm_box_pack_end(bx, bt);
537    evas_object_show(bt);
538
539    bt = elm_button_add(win);
540    elm_object_text_set(bt, "Restore");
541    evas_object_smart_callback_add(bt, "clicked", restore_bt_clicked,
542                                   (void *) api);
543    elm_box_pack_end(bx, bt);
544    evas_object_show(bt);
545
546    /* Gengrid Filled Test */
547    bt = elm_button_add(win);
548    elm_object_text_set(bt, "Check Filled");
549    evas_object_smart_callback_add(bt, "clicked", filled_bt_clicked, NULL);
550    elm_box_pack_end(bx, bt);
551    evas_object_show(bt);
552
553    /* Item Cursor Test */
554    bt = elm_button_add(win);
555    elm_object_text_set(bt, "Check Cursor");
556    evas_object_smart_callback_add(bt, "clicked", cursor_bt_clicked,
557                                   (void *) api);
558    elm_box_pack_end(bx, bt);
559    evas_object_show(bt);
560
561    evas_object_resize(win, 600, 600);
562    evas_object_show(win);
563 }
564
565 static void
566 _before_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
567 {
568    Testitem *ti;
569    Evas_Object *grid = data;
570    Elm_Object_Item *sel;
571    char buf[PATH_MAX];
572
573    sel = elm_gengrid_selected_item_get(grid);
574    if (!sel)
575        return;
576    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
577    n_current_pic = ((n_current_pic +1) % 9);
578    ti = calloc(1, sizeof(*ti));
579    ti->mode = 0;
580    ti->path = eina_stringshare_add(buf);
581    ti->item = elm_gengrid_item_insert_before(grid, gic, ti, sel, grid_sel,
582                                              NULL);
583 }
584
585 static int
586 compare_cb(const void *data1, const void *data2)
587 {
588    Testitem *ti1 = (Testitem *)data1;
589    Testitem *ti2 = (Testitem *)data2;
590    return strlen(ti1->path) - strlen(ti2->path);
591 }
592
593 static void
594 _sorted_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
595 {
596    Testitem *ti;
597    Evas_Object *grid = data;
598    char buf[PATH_MAX];
599
600    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
601    n_current_pic = ((n_current_pic +1) % 9);
602    ti = calloc(1, sizeof(*ti));
603    ti->mode = 0;
604    ti->path = eina_stringshare_add(buf);
605    ti->item = elm_gengrid_item_sorted_insert(grid, gic, ti, compare_cb, grid_sel,
606                                              NULL);
607 }
608
609 static void
610 _after_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
611 {
612    Testitem *ti;
613    Evas_Object *grid = data;
614    Elm_Object_Item *sel;
615    char buf[PATH_MAX];
616
617    sel = elm_gengrid_selected_item_get(grid);
618    if (!sel)
619        return;
620    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
621    n_current_pic = ((n_current_pic +1) % 9);
622    ti = calloc(1, sizeof(*ti));
623    ti->mode = 0;
624    ti->path = eina_stringshare_add(buf);
625    ti->item = elm_gengrid_item_insert_after(grid, gic, ti, sel, grid_sel,
626                                             NULL);
627 }
628
629 static void
630 _delete_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
631 {
632    Evas_Object *grid = data;
633    Eina_List *l, *l2, *l3;
634    Elm_Object_Item *gg_it;
635
636    l = (Eina_List*)elm_gengrid_selected_items_get(grid);
637    if (!l) return;
638    EINA_LIST_FOREACH_SAFE(l, l2, l3, gg_it)
639      elm_object_item_del(gg_it);
640 }
641
642 static void
643 _prepend_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
644 {
645    Testitem *ti;
646    Evas_Object *grid = data;
647    char buf[PATH_MAX];
648
649    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
650    n_current_pic = ((n_current_pic +1) % 9);
651    ti = calloc(1, sizeof(*ti));
652    ti->mode = 0;
653    ti->path = eina_stringshare_add(buf);
654    ti->item = elm_gengrid_item_prepend(grid, gic, ti, grid_sel, NULL);
655 }
656
657 static void
658 _append_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
659 {
660    Testitem *ti;
661    Evas_Object *grid = data;
662    char buf[PATH_MAX];
663
664    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
665    n_current_pic = ((n_current_pic +1) % 9);
666    ti = calloc(1, sizeof(*ti));
667    ti->mode = 0;
668    ti->path = eina_stringshare_add(buf);
669    ti->item = elm_gengrid_item_append(grid, gic, ti, grid_sel, NULL);
670 }
671
672 static void
673 _size_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
674 {
675    Evas_Object *grid = data;
676    int size = elm_spinner_value_get(obj);
677    elm_gengrid_item_size_set(grid, size, size);
678 }
679
680 void
681 test_gengrid2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
682 {
683    Evas_Object *win, *grid, *bx, *hbx, *bt, *ck;
684
685    win = elm_win_util_standard_add("gengrid2", "GenGrid 2");
686    elm_win_autodel_set(win, EINA_TRUE);
687
688    bx = elm_box_add(win);
689    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
690    elm_win_resize_object_add(win, bx);
691    evas_object_show(bx);
692
693    grid = elm_gengrid_add(win);
694    elm_gengrid_item_size_set(grid, 150, 150);
695    elm_gengrid_horizontal_set(grid, EINA_FALSE);
696    elm_gengrid_multi_select_set(grid, EINA_FALSE);
697    evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
698    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
699    evas_object_size_hint_min_set(grid, 600, 500);
700    elm_box_pack_end(bx, grid);
701    evas_object_show(grid);
702
703    hbx = elm_box_add(win);
704    evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
705    elm_box_horizontal_set(hbx, EINA_TRUE);
706    elm_box_pack_end(bx, hbx);
707    evas_object_show(hbx);
708
709    bt = elm_button_add(win);
710    elm_object_text_set(bt, "Append");
711    evas_object_smart_callback_add(bt, "clicked", _append_bt_clicked, grid);
712    elm_box_pack_end(hbx, bt);
713    evas_object_show(bt);
714
715    bt = elm_button_add(win);
716    elm_object_text_set(bt, "Prepend");
717    evas_object_smart_callback_add(bt, "clicked", _prepend_bt_clicked, grid);
718    elm_box_pack_end(hbx, bt);
719    evas_object_show(bt);
720
721    bt = elm_button_add(win);
722    elm_object_text_set(bt, "Insert before");
723    evas_object_smart_callback_add(bt, "clicked", _before_bt_clicked, grid);
724    elm_box_pack_end(hbx, bt);
725    evas_object_show(bt);
726
727    bt = elm_button_add(win);
728    elm_object_text_set(bt, "Insert after");
729    evas_object_smart_callback_add(bt, "clicked", _after_bt_clicked, grid);
730    elm_box_pack_end(hbx, bt);
731    evas_object_show(bt);
732
733    bt = elm_button_add(win);
734    elm_object_text_set(bt, "Sorted insert");
735    evas_object_smart_callback_add(bt, "clicked", _sorted_bt_clicked, grid);
736    elm_box_pack_end(hbx, bt);
737    evas_object_show(bt);
738
739    bt = elm_button_add(win);
740    elm_object_text_set(bt, "Delete");
741    evas_object_smart_callback_add(bt, "clicked", _delete_bt_clicked, grid);
742    elm_box_pack_end(hbx, bt);
743    evas_object_show(bt);
744
745    bt = elm_spinner_add(win);
746    elm_spinner_min_max_set(bt, 10, 1024);
747    elm_spinner_value_set(bt, 150);
748    elm_spinner_label_format_set(bt, "Item size: %.0f");
749    evas_object_smart_callback_add(bt, "changed", _size_changed, grid);
750    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
751    elm_box_pack_end(hbx, bt);
752    evas_object_show(bt);
753
754    ck = elm_check_add(win);
755    elm_object_text_set(ck, "Horizontal Mode");
756    evas_object_smart_callback_add(ck, "changed", _horizontal_grid, grid);
757    elm_box_pack_end(hbx, ck);
758    evas_object_show(ck);
759
760    gic = elm_gengrid_item_class_new();
761
762    gic->item_style = "default";
763    gic->func.text_get = grid_text_get;
764    gic->func.content_get = grid_content_get;
765    gic->func.state_get = grid_state_get;
766    gic->func.del = grid_del;
767
768    /* item_class_ref is needed for gic. some items can be added in callbacks */
769    elm_gengrid_item_class_ref(gic);
770    elm_gengrid_item_class_free(gic);
771
772    evas_object_resize(win, 600, 600);
773    evas_object_show(win);
774 }
775
776 void
777 test_gengrid3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
778 {
779    Evas_Object *win, *grid;
780    static Testitem ti[144];
781    int i, n;
782    char buf[PATH_MAX];
783
784    win = elm_win_util_standard_add("gengrid_group", "GenGrid Group");
785    elm_win_autodel_set(win, EINA_TRUE);
786
787    grid = elm_gengrid_add(win);
788    elm_gengrid_item_size_set(grid, 150, 150);
789    elm_gengrid_group_item_size_set(grid, 31, 31);
790    //elm_gengrid_horizontal_set(grid, EINA_TRUE);
791    elm_gengrid_horizontal_set(grid, EINA_FALSE);
792    elm_gengrid_multi_select_set(grid, EINA_TRUE);
793    elm_gengrid_reorder_mode_set(grid, EINA_TRUE);
794    evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
795    evas_object_smart_callback_add(grid, "clicked,double", grid_double_clicked, NULL);
796    evas_object_smart_callback_add(grid, "longpressed", grid_longpress, NULL);
797    evas_object_smart_callback_add(grid, "moved", grid_moved, NULL);
798    evas_object_smart_callback_add(grid, "drag,start,up", grid_drag_up, NULL);
799    evas_object_smart_callback_add(grid, "drag,start,right", grid_drag_right, NULL);
800    evas_object_smart_callback_add(grid, "drag,start,down", grid_drag_down, NULL);
801    evas_object_smart_callback_add(grid, "drag,start,left", grid_drag_left, NULL);
802    evas_object_smart_callback_add(grid, "drag,stop", grid_drag_stop, NULL);
803    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
804
805    gic = elm_gengrid_item_class_new();
806    gic->item_style = "default";
807    gic->func.text_get = grid_text_get;
808    gic->func.content_get = grid_content_get;
809    gic->func.state_get = grid_state_get;
810    gic->func.del = grid_del;
811
812    ggic.item_style = "group_index";
813    ggic.func.text_get = grid_text_get;
814    ggic.func.content_get = NULL;
815    ggic.func.state_get = NULL;
816    ggic.func.del = NULL;
817
818    n = 0;
819    for (i = 0; i < 12 * 12; i++)
820      {
821         snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n]);
822         n = (n + 1) % 9;
823         ti[i].mode = i;
824         ti[i].path = eina_stringshare_add(buf);
825         if (i == 0 || i == 18 || i == 53 || i == 100)
826           //if (i == 0 || i == 18)
827           ti[i].item = elm_gengrid_item_append(grid, &ggic, &(ti[i]), grid_sel, NULL);
828         else
829           ti[i].item = elm_gengrid_item_append(grid, gic, &(ti[i]), grid_sel, NULL);
830         if (!(i % 5))
831           elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
832      }
833    elm_gengrid_item_class_free(gic);
834
835    evas_object_show(grid);
836    elm_win_resize_object_add(win, grid);
837
838    evas_object_resize(win, 600, 600);
839    evas_object_show(win);
840 }
841
842 #endif