[Entry] Fix scrolling issue with cnp, magnifier
[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_scroller_bounce_set(grid, EINA_TRUE, EINA_FALSE);
78          break;
79
80       case GRID_PAGE_RELATIVE: /* 4 */
81          elm_scroller_bounce_set(grid, EINA_TRUE, EINA_TRUE);
82          elm_scroller_page_relative_set(grid, 0.5, 0.5);
83          break;
84
85       case GRID_PAGE_SIZE: /* 5 */
86          elm_scroller_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 static void
470 _btn_bring_in_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
471 {
472    if (!data) return;
473    Elm_Object_Item *it = elm_gengrid_selected_item_get(data);
474    if (!it) return;
475    elm_gengrid_item_bring_in(it, ELM_GENGRID_ITEM_SCROLLTO_IN);
476 }
477
478 static void
479 _btn_show_clicked_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
480 {
481    if (!data) return;
482    Elm_Object_Item *it = elm_gengrid_selected_item_get(data);
483    if (!it) return;
484    elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_IN);
485 }
486
487 void
488 test_gengrid(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
489 {
490    Evas_Object *win, *bt, *content_box, *bxx, *bx, *tg;
491    api_data *api = calloc(1, sizeof(api_data));
492
493    win = elm_win_util_standard_add("gengrid", "GenGrid");
494    elm_win_autodel_set(win, EINA_TRUE);
495    evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
496
497    bxx = elm_box_add(win);
498    api->box = bxx;
499    elm_win_resize_object_add(win, bxx);
500    evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
501    evas_object_show(bxx);
502
503    content_box = elm_box_add(win);
504    api->box = content_box;
505    evas_object_size_hint_weight_set(content_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
506    evas_object_size_hint_align_set(content_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
507    evas_object_show(content_box);
508
509    /* Create GenGrid */
510    api->grid = create_gengrid(win, (12 * 12));
511
512    bt = elm_button_add(win);
513    elm_object_text_set(bt, "Next API function");
514    evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked,
515                                   (void *)api);
516    elm_box_pack_end(bxx, bt);
517    elm_object_disabled_set(bt, api->state == API_STATE_LAST);
518    evas_object_show(bt);
519
520    elm_box_pack_end(content_box, api->grid);
521    elm_box_pack_end(bxx, content_box);
522    evas_object_show(api->grid);
523
524    bx = elm_box_add(win);
525    elm_box_horizontal_set(bx, EINA_TRUE);
526    elm_box_pack_end(bxx, bx);
527    evas_object_show(bx);
528
529    /* Gengrid Always Select Mode Test */
530    tg = elm_check_add(win);
531    evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
532    evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, EVAS_HINT_FILL);
533    elm_object_text_set(tg, "Always Select Mode");
534    evas_object_smart_callback_add(tg, "changed", always_select_mode_cb,
535                                   (void *)api);
536    elm_box_pack_end(bx, tg);
537    evas_object_show(tg);
538
539    tg = elm_check_add(win);
540    evas_object_size_hint_weight_set(tg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
541    evas_object_size_hint_align_set(tg, EVAS_HINT_FILL, EVAS_HINT_FILL);
542    elm_object_text_set(tg, "Multi Select Mode");
543    elm_check_state_set(tg, EINA_TRUE);
544    evas_object_smart_callback_add(tg, "changed", multi_select_cb,
545                                   (void *)api);
546    elm_box_pack_end(bx, tg);
547    evas_object_show(tg);
548
549    /* Gengrid Clear Test */
550    bt = elm_button_add(win);
551    elm_object_text_set(bt, "Clear");
552    evas_object_smart_callback_add(bt, "clicked", clear_bt_clicked,
553                                   (void *)api);
554    elm_box_pack_end(bx, bt);
555    evas_object_show(bt);
556
557    bt = elm_button_add(win);
558    elm_object_text_set(bt, "Restore");
559    evas_object_smart_callback_add(bt, "clicked", restore_bt_clicked,
560                                   (void *) api);
561    elm_box_pack_end(bx, bt);
562    evas_object_show(bt);
563
564    /* Gengrid Filled Test */
565    bt = elm_button_add(win);
566    elm_object_text_set(bt, "Check Filled");
567    evas_object_smart_callback_add(bt, "clicked", filled_bt_clicked, NULL);
568    elm_box_pack_end(bx, bt);
569    evas_object_show(bt);
570
571    /* Item Cursor Test */
572    bt = elm_button_add(win);
573    elm_object_text_set(bt, "Check Cursor");
574    evas_object_smart_callback_add(bt, "clicked", cursor_bt_clicked,
575                                   (void *) api);
576    elm_box_pack_end(bx, bt);
577    evas_object_show(bt);
578
579    bt = elm_button_add(win);
580    elm_object_text_set(bt, "Bring in");
581    evas_object_smart_callback_add(bt, "clicked", _btn_bring_in_clicked_cb, api->grid);
582    elm_box_pack_end(bx, bt);
583    evas_object_show(bt);
584
585    bt = elm_button_add(win);
586    elm_object_text_set(bt, "Show");
587    evas_object_smart_callback_add(bt, "clicked", _btn_show_clicked_cb, api->grid);
588    elm_box_pack_end(bx, bt);
589    evas_object_show(bt);
590
591    evas_object_resize(win, 600, 600);
592    evas_object_show(win);
593 }
594
595 static void
596 _before_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
597 {
598    Testitem *ti;
599    Evas_Object *grid = data;
600    Elm_Object_Item *sel;
601    char buf[PATH_MAX];
602
603    sel = elm_gengrid_selected_item_get(grid);
604    if (!sel)
605        return;
606    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
607    n_current_pic = ((n_current_pic +1) % 9);
608    ti = calloc(1, sizeof(*ti));
609    ti->mode = 0;
610    ti->path = eina_stringshare_add(buf);
611    ti->item = elm_gengrid_item_insert_before(grid, gic, ti, sel, grid_sel,
612                                              NULL);
613 }
614
615 static int
616 compare_cb(const void *data1, const void *data2)
617 {
618    Testitem *ti1 = (Testitem *)data1;
619    Testitem *ti2 = (Testitem *)data2;
620    return strlen(ti1->path) - strlen(ti2->path);
621 }
622
623 static void
624 _sorted_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
625 {
626    Testitem *ti;
627    Evas_Object *grid = data;
628    char buf[PATH_MAX];
629
630    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
631    n_current_pic = ((n_current_pic +1) % 9);
632    ti = calloc(1, sizeof(*ti));
633    ti->mode = 0;
634    ti->path = eina_stringshare_add(buf);
635    ti->item = elm_gengrid_item_sorted_insert(grid, gic, ti, compare_cb, grid_sel,
636                                              NULL);
637 }
638
639 static void
640 _after_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
641 {
642    Testitem *ti;
643    Evas_Object *grid = data;
644    Elm_Object_Item *sel;
645    char buf[PATH_MAX];
646
647    sel = elm_gengrid_selected_item_get(grid);
648    if (!sel)
649        return;
650    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
651    n_current_pic = ((n_current_pic +1) % 9);
652    ti = calloc(1, sizeof(*ti));
653    ti->mode = 0;
654    ti->path = eina_stringshare_add(buf);
655    ti->item = elm_gengrid_item_insert_after(grid, gic, ti, sel, grid_sel,
656                                             NULL);
657 }
658
659 static void
660 _delete_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
661 {
662    Evas_Object *grid = data;
663    Eina_List *l, *l2, *l3;
664    Elm_Object_Item *gg_it;
665
666    l = (Eina_List*)elm_gengrid_selected_items_get(grid);
667    if (!l) return;
668    EINA_LIST_FOREACH_SAFE(l, l2, l3, gg_it)
669      elm_object_item_del(gg_it);
670 }
671
672 static void
673 _prepend_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
674 {
675    Testitem *ti;
676    Evas_Object *grid = data;
677    char buf[PATH_MAX];
678
679    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
680    n_current_pic = ((n_current_pic +1) % 9);
681    ti = calloc(1, sizeof(*ti));
682    ti->mode = 0;
683    ti->path = eina_stringshare_add(buf);
684    ti->item = elm_gengrid_item_prepend(grid, gic, ti, grid_sel, NULL);
685 }
686
687 static void
688 _append_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
689 {
690    Testitem *ti;
691    Evas_Object *grid = data;
692    char buf[PATH_MAX];
693
694    snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n_current_pic]);
695    n_current_pic = ((n_current_pic +1) % 9);
696    ti = calloc(1, sizeof(*ti));
697    ti->mode = 0;
698    ti->path = eina_stringshare_add(buf);
699    ti->item = elm_gengrid_item_append(grid, gic, ti, grid_sel, NULL);
700 }
701
702 static void
703 _size_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
704 {
705    Evas_Object *grid = data;
706    int size = elm_spinner_value_get(obj);
707    elm_gengrid_item_size_set(grid, size, size);
708 }
709
710 void
711 test_gengrid2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
712 {
713    Evas_Object *win, *grid, *bx, *hbx, *bt, *ck;
714
715    win = elm_win_util_standard_add("gengrid2", "GenGrid 2");
716    elm_win_autodel_set(win, EINA_TRUE);
717
718    bx = elm_box_add(win);
719    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
720    elm_win_resize_object_add(win, bx);
721    evas_object_show(bx);
722
723    grid = elm_gengrid_add(win);
724    elm_gengrid_item_size_set(grid, 150, 150);
725    elm_gengrid_horizontal_set(grid, EINA_FALSE);
726    elm_gengrid_multi_select_set(grid, EINA_FALSE);
727    evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
728    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
729    evas_object_size_hint_min_set(grid, 600, 500);
730    elm_box_pack_end(bx, grid);
731    evas_object_show(grid);
732
733    hbx = elm_box_add(win);
734    evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
735    elm_box_horizontal_set(hbx, EINA_TRUE);
736    elm_box_pack_end(bx, hbx);
737    evas_object_show(hbx);
738
739    bt = elm_button_add(win);
740    elm_object_text_set(bt, "Append");
741    evas_object_smart_callback_add(bt, "clicked", _append_bt_clicked, grid);
742    elm_box_pack_end(hbx, bt);
743    evas_object_show(bt);
744
745    bt = elm_button_add(win);
746    elm_object_text_set(bt, "Prepend");
747    evas_object_smart_callback_add(bt, "clicked", _prepend_bt_clicked, grid);
748    elm_box_pack_end(hbx, bt);
749    evas_object_show(bt);
750
751    bt = elm_button_add(win);
752    elm_object_text_set(bt, "Insert before");
753    evas_object_smart_callback_add(bt, "clicked", _before_bt_clicked, grid);
754    elm_box_pack_end(hbx, bt);
755    evas_object_show(bt);
756
757    bt = elm_button_add(win);
758    elm_object_text_set(bt, "Insert after");
759    evas_object_smart_callback_add(bt, "clicked", _after_bt_clicked, grid);
760    elm_box_pack_end(hbx, bt);
761    evas_object_show(bt);
762
763    bt = elm_button_add(win);
764    elm_object_text_set(bt, "Sorted insert");
765    evas_object_smart_callback_add(bt, "clicked", _sorted_bt_clicked, grid);
766    elm_box_pack_end(hbx, bt);
767    evas_object_show(bt);
768
769    bt = elm_button_add(win);
770    elm_object_text_set(bt, "Delete");
771    evas_object_smart_callback_add(bt, "clicked", _delete_bt_clicked, grid);
772    elm_box_pack_end(hbx, bt);
773    evas_object_show(bt);
774
775    bt = elm_spinner_add(win);
776    elm_spinner_min_max_set(bt, 10, 1024);
777    elm_spinner_value_set(bt, 150);
778    elm_spinner_label_format_set(bt, "Item size: %.0f");
779    evas_object_smart_callback_add(bt, "changed", _size_changed, grid);
780    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
781    elm_box_pack_end(hbx, bt);
782    evas_object_show(bt);
783
784    ck = elm_check_add(win);
785    elm_object_text_set(ck, "Horizontal Mode");
786    evas_object_smart_callback_add(ck, "changed", _horizontal_grid, grid);
787    elm_box_pack_end(hbx, ck);
788    evas_object_show(ck);
789
790    gic = elm_gengrid_item_class_new();
791
792    gic->item_style = "default";
793    gic->func.text_get = grid_text_get;
794    gic->func.content_get = grid_content_get;
795    gic->func.state_get = grid_state_get;
796    gic->func.del = grid_del;
797
798    /* item_class_ref is needed for gic. some items can be added in callbacks */
799    elm_gengrid_item_class_ref(gic);
800    elm_gengrid_item_class_free(gic);
801
802    evas_object_resize(win, 600, 600);
803    evas_object_show(win);
804 }
805
806 void
807 test_gengrid3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
808 {
809    Evas_Object *win, *grid;
810    static Testitem ti[144];
811    int i, n;
812    char buf[PATH_MAX];
813
814    win = elm_win_util_standard_add("gengrid_group", "GenGrid Group");
815    elm_win_autodel_set(win, EINA_TRUE);
816
817    grid = elm_gengrid_add(win);
818    elm_gengrid_item_size_set(grid, 150, 150);
819    elm_gengrid_group_item_size_set(grid, 31, 31);
820    //elm_gengrid_horizontal_set(grid, EINA_TRUE);
821    elm_gengrid_horizontal_set(grid, EINA_FALSE);
822    elm_gengrid_multi_select_set(grid, EINA_TRUE);
823    elm_gengrid_reorder_mode_set(grid, EINA_TRUE);
824    evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
825    evas_object_smart_callback_add(grid, "clicked,double", grid_double_clicked, NULL);
826    evas_object_smart_callback_add(grid, "longpressed", grid_longpress, NULL);
827    evas_object_smart_callback_add(grid, "moved", grid_moved, NULL);
828    evas_object_smart_callback_add(grid, "drag,start,up", grid_drag_up, NULL);
829    evas_object_smart_callback_add(grid, "drag,start,right", grid_drag_right, NULL);
830    evas_object_smart_callback_add(grid, "drag,start,down", grid_drag_down, NULL);
831    evas_object_smart_callback_add(grid, "drag,start,left", grid_drag_left, NULL);
832    evas_object_smart_callback_add(grid, "drag,stop", grid_drag_stop, NULL);
833    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
834
835    gic = elm_gengrid_item_class_new();
836    gic->item_style = "default";
837    gic->func.text_get = grid_text_get;
838    gic->func.content_get = grid_content_get;
839    gic->func.state_get = grid_state_get;
840    gic->func.del = grid_del;
841
842    ggic.item_style = "group_index";
843    ggic.func.text_get = grid_text_get;
844    ggic.func.content_get = NULL;
845    ggic.func.state_get = NULL;
846    ggic.func.del = NULL;
847
848    n = 0;
849    for (i = 0; i < 12 * 12; i++)
850      {
851         snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n]);
852         n = (n + 1) % 9;
853         ti[i].mode = i;
854         ti[i].path = eina_stringshare_add(buf);
855         if (i == 0 || i == 18 || i == 53 || i == 100)
856           //if (i == 0 || i == 18)
857           ti[i].item = elm_gengrid_item_append(grid, &ggic, &(ti[i]), grid_sel, NULL);
858         else
859           ti[i].item = elm_gengrid_item_append(grid, gic, &(ti[i]), grid_sel, NULL);
860         if (!(i % 5))
861           elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
862      }
863    elm_gengrid_item_class_free(gic);
864
865    evas_object_show(grid);
866    elm_win_resize_object_add(win, grid);
867
868    evas_object_resize(win, 600, 600);
869    evas_object_show(win);
870 }
871
872 #endif