1 #include <Elementary.h>
3 # include "elementary_config.h"
5 #ifndef ELM_LIB_QUICKLAUNCH
6 typedef struct _Testitem
8 Elm_Gengrid_Item *item;
14 static const char *img[9] =
27 static Elm_Gengrid_Item_Class gic;
30 _horizontal_grid(void *data, Evas_Object *obj, void *event_info __UNUSED__)
32 Evas_Object *grid = data;
33 elm_gengrid_horizontal_set(grid, elm_check_state_get(obj));
37 grid_drag_up(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
39 printf("Drag up: %p\n", event_info);
43 grid_drag_right(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
45 printf("Drag right: %p\n", event_info);
49 grid_drag_down(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
51 printf("Drag down: %p\n", event_info);
55 grid_drag_left(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
57 printf("Drag left: %p\n", event_info);
61 grid_drag_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
63 printf("Drag stop: %p\n", event_info);
67 grid_selected(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
69 printf("Selected: %p\n", event_info);
73 grid_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
75 printf("Clicked: %p\n", event_info);
79 grid_longpress(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
81 printf("longpress %p\n", event_info);
85 grid_moved(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
87 printf("moved %p\n", event_info);
91 grid_item_check_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
94 ti->onoff = elm_check_state_get(obj);
95 printf("item %p onoff = %i\n", ti, ti->onoff);
99 grid_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
101 const Testitem *ti = data;
103 snprintf(buf, sizeof(buf), "Photo %s", ti->path);
108 grid_icon_get(void *data, Evas_Object *obj, const char *part)
110 const Testitem *ti = data;
111 if (!strcmp(part, "elm.swallow.icon"))
114 Evas_Object *icon = elm_bg_add(obj);
115 elm_bg_file_set(icon, ti->path, NULL);
116 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
117 evas_object_show(icon);
120 else if (!strcmp(part, "elm.swallow.end"))
123 ck = elm_check_add(obj);
124 evas_object_propagate_events_set(ck, 0);
125 elm_check_state_set(ck, ti->onoff);
126 evas_object_smart_callback_add(ck, "changed", grid_item_check_changed, data);
127 evas_object_show(ck);
134 grid_state_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
140 grid_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
145 grid_sel(void *data, Evas_Object *obj, void *event_info)
147 printf("sel item data [%p] on grid obj [%p], pointer [%p]\n", data, obj, event_info);
151 test_gengrid(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
153 Evas_Object *win, *bg, *grid;
154 static Testitem ti[144];
158 win = elm_win_add(NULL, "gengrid", ELM_WIN_BASIC);
159 elm_win_title_set(win, "GenGrid");
160 elm_win_autodel_set(win, 1);
162 bg = elm_bg_add(win);
163 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
164 elm_win_resize_object_add(win, bg);
165 evas_object_show(bg);
167 grid = elm_gengrid_add(win);
168 elm_gengrid_item_size_set(grid, 150, 150);
169 elm_gengrid_horizontal_set(grid, EINA_FALSE);
170 elm_gengrid_multi_select_set(grid, EINA_TRUE);
171 elm_gengrid_reorder_mode_set(grid, EINA_TRUE);
172 evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
173 evas_object_smart_callback_add(grid, "clicked", grid_clicked, NULL);
174 evas_object_smart_callback_add(grid, "longpressed", grid_longpress, NULL);
175 evas_object_smart_callback_add(grid, "moved", grid_moved, NULL);
176 evas_object_smart_callback_add(grid, "drag,start,up", grid_drag_up, NULL);
177 evas_object_smart_callback_add(grid, "drag,start,right", grid_drag_right, NULL);
178 evas_object_smart_callback_add(grid, "drag,start,down", grid_drag_down, NULL);
179 evas_object_smart_callback_add(grid, "drag,start,left", grid_drag_left, NULL);
180 evas_object_smart_callback_add(grid, "drag,stop", grid_drag_stop, NULL);
181 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
183 gic.item_style = "default";
184 gic.func.label_get = grid_label_get;
185 gic.func.icon_get = grid_icon_get;
186 gic.func.state_get = grid_state_get;
187 gic.func.del = grid_del;
190 for (i = 0; i < 12 * 12; i++)
192 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[n]);
195 ti[i].path = eina_stringshare_add(buf);
196 ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), grid_sel, NULL);
198 elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
201 evas_object_show(grid);
202 elm_win_resize_object_add(win, grid);
204 evas_object_resize(win, 600, 600);
205 evas_object_show(win);
209 _before_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
212 Evas_Object *grid = data;
213 Elm_Gengrid_Item *sel;
216 sel = elm_gengrid_selected_item_get(grid);
219 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
220 ti = malloc(sizeof(*ti));
222 ti->path = eina_stringshare_add(buf);
223 ti->item = elm_gengrid_item_insert_before(grid, &gic, ti, sel, grid_sel,
228 _after_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
231 Evas_Object *grid = data;
232 Elm_Gengrid_Item *sel;
235 sel = elm_gengrid_selected_item_get(grid);
238 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
239 ti = malloc(sizeof(*ti));
241 ti->path = eina_stringshare_add(buf);
242 ti->item = elm_gengrid_item_insert_after(grid, &gic, ti, sel, grid_sel,
247 _prepend_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
250 Evas_Object *grid = data;
253 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
254 ti = malloc(sizeof(*ti));
256 ti->path = eina_stringshare_add(buf);
257 ti->item = elm_gengrid_item_prepend(grid, &gic, ti, grid_sel, NULL);
261 _append_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
264 Evas_Object *grid = data;
267 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
268 ti = malloc(sizeof(*ti));
270 ti->path = eina_stringshare_add(buf);
271 ti->item = elm_gengrid_item_append(grid, &gic, ti, grid_sel, NULL);
275 _size_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
277 Evas_Object *grid = data;
278 int size = elm_spinner_value_get(obj);
279 elm_gengrid_item_size_set(grid, size, size);
283 test_gengrid2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
285 Evas_Object *win, *bg, *grid, *bx, *hbx, *bt, *ck;
287 win = elm_win_add(NULL, "gengrid2", ELM_WIN_BASIC);
288 elm_win_title_set(win, "GenGrid2");
289 elm_win_autodel_set(win, 1);
291 bg = elm_bg_add(win);
292 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
293 elm_win_resize_object_add(win, bg);
294 evas_object_show(bg);
296 bx = elm_box_add(win);
297 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
298 elm_win_resize_object_add(win, bx);
299 evas_object_show(bx);
301 grid = elm_gengrid_add(win);
302 elm_gengrid_item_size_set(grid, 150, 150);
303 elm_gengrid_horizontal_set(grid, EINA_FALSE);
304 elm_gengrid_multi_select_set(grid, EINA_FALSE);
305 evas_object_smart_callback_add(grid, "selected", grid_selected, NULL);
306 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
307 evas_object_size_hint_min_set(grid, 600, 500);
308 elm_box_pack_end(bx, grid);
309 evas_object_show(grid);
311 hbx = elm_box_add(win);
312 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
313 elm_box_horizontal_set(hbx, EINA_TRUE);
314 elm_box_pack_end(bx, hbx);
315 evas_object_show(hbx);
317 bt = elm_button_add(win);
318 elm_button_label_set(bt, "Append");
319 evas_object_smart_callback_add(bt, "clicked", _append_bt_clicked, grid);
320 elm_box_pack_end(hbx, bt);
321 evas_object_show(bt);
323 bt = elm_button_add(win);
324 elm_button_label_set(bt, "Prepend");
325 evas_object_smart_callback_add(bt, "clicked", _prepend_bt_clicked, grid);
326 elm_box_pack_end(hbx, bt);
327 evas_object_show(bt);
329 bt = elm_button_add(win);
330 elm_button_label_set(bt, "Insert before");
331 evas_object_smart_callback_add(bt, "clicked", _before_bt_clicked, grid);
332 elm_box_pack_end(hbx, bt);
333 evas_object_show(bt);
335 bt = elm_button_add(win);
336 elm_button_label_set(bt, "Insert after");
337 evas_object_smart_callback_add(bt, "clicked", _after_bt_clicked, grid);
338 elm_box_pack_end(hbx, bt);
339 evas_object_show(bt);
341 bt = elm_spinner_add(win);
342 elm_spinner_min_max_set(bt, 10, 1024);
343 elm_spinner_value_set(bt, 150);
344 elm_spinner_label_format_set(bt, "Item size: %.0f");
345 evas_object_smart_callback_add(bt, "changed", _size_changed, grid);
346 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
347 elm_box_pack_end(hbx, bt);
348 evas_object_show(bt);
350 ck = elm_check_add(win);
351 elm_check_label_set(ck, "Horizontal Mode");
352 evas_object_smart_callback_add(ck, "changed", _horizontal_grid, grid);
353 elm_box_pack_end(hbx, ck);
354 evas_object_show(ck);
356 gic.item_style = "default";
357 gic.func.label_get = grid_label_get;
358 gic.func.icon_get = grid_icon_get;
359 gic.func.state_get = grid_state_get;
360 gic.func.del = grid_del;
362 evas_object_resize(win, 600, 600);
363 evas_object_show(win);