Merge "[Password]: New design based changes, a new style removed password mode contro...
[framework/uifw/elementary.git] / src / bin / test_gengrid.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6 typedef struct _Testitem
7 {
8    Elm_Gengrid_Item *item;
9    const char *path;
10    int mode;
11    int onoff;
12 } Testitem;
13
14 static const char *img[9] =
15 {
16    "panel_01.jpg",
17    "plant_01.jpg",
18    "rock_01.jpg",
19    "rock_02.jpg",
20    "sky_01.jpg",
21    "sky_02.jpg",
22    "sky_03.jpg",
23    "sky_04.jpg",
24    "wood_01.jpg",
25 };
26
27 static Elm_Gengrid_Item_Class gic;
28
29 static void
30 _horizontal_grid(void *data, Evas_Object *obj, void *event_info __UNUSED__)
31 {
32    Evas_Object *grid = data;
33    elm_gengrid_horizontal_set(grid, elm_check_state_get(obj));
34 }
35
36 static void
37 grid_drag_up(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
38 {
39    printf("Drag up: %p\n", event_info);
40 }
41
42 static void
43 grid_drag_right(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
44 {
45    printf("Drag right: %p\n", event_info);
46 }
47
48 static void
49 grid_drag_down(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
50 {
51    printf("Drag down: %p\n", event_info);
52 }
53
54 static void
55 grid_drag_left(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
56 {
57    printf("Drag left: %p\n", event_info);
58 }
59
60 static void
61 grid_drag_stop(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
62 {
63    printf("Drag stop: %p\n", event_info);
64 }
65
66 static void
67 grid_selected(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
68 {
69    printf("Selected: %p\n", event_info);
70 }
71
72 static void
73 grid_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
74 {
75    printf("Clicked: %p\n", event_info);
76 }
77
78 static void
79 grid_longpress(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
80 {
81    printf("longpress %p\n", event_info);
82 }
83
84 static void
85 grid_moved(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
86 {
87    printf("moved %p\n", event_info);
88 }
89
90 static void
91 grid_item_check_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
92 {
93    Testitem *ti = data;
94    ti->onoff = elm_check_state_get(obj);
95    printf("item %p onoff = %i\n", ti, ti->onoff);
96 }
97
98 char *
99 grid_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
100 {
101    const Testitem *ti = data;
102    char buf[256];
103    snprintf(buf, sizeof(buf), "Photo %s", ti->path);
104    return strdup(buf);
105 }
106
107 Evas_Object *
108 grid_icon_get(void *data, Evas_Object *obj, const char *part)
109 {
110    const Testitem *ti = data;
111    if (!strcmp(part, "elm.swallow.icon"))
112      {
113
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);
118         return icon;
119      }
120    else if (!strcmp(part, "elm.swallow.end"))
121      {
122         Evas_Object *ck;
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);
128         return ck;
129      }
130    return NULL;
131 }
132
133 Eina_Bool
134 grid_state_get(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
135 {
136    return EINA_FALSE;
137 }
138
139 void
140 grid_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
141 {
142 }
143
144 static void
145 grid_sel(void *data, Evas_Object *obj, void *event_info)
146 {
147    printf("sel item data [%p] on grid obj [%p], pointer [%p]\n", data, obj, event_info);
148 }
149
150 void
151 test_gengrid(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
152 {
153    Evas_Object *win, *bg, *grid;
154    static Testitem ti[144];
155    int i, n;
156    char buf[PATH_MAX];
157
158    win = elm_win_add(NULL, "gengrid", ELM_WIN_BASIC);
159    elm_win_title_set(win, "GenGrid");
160    elm_win_autodel_set(win, 1);
161
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);
166
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);
182
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;
188
189    n = 0;
190    for (i = 0; i < 12 * 12; i++)
191      {
192         snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[n]);
193         n = (n + 1) % 9;
194         ti[i].mode = i;
195         ti[i].path = eina_stringshare_add(buf);
196         ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), grid_sel, NULL);
197         if (!(i % 5))
198           elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
199      }
200
201    evas_object_show(grid);
202    elm_win_resize_object_add(win, grid);
203
204    evas_object_resize(win, 600, 600);
205    evas_object_show(win);
206 }
207
208 static void
209 _before_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
210 {
211    Testitem *ti;
212    Evas_Object *grid = data;
213    Elm_Gengrid_Item *sel;
214    char buf[PATH_MAX];
215
216    sel = elm_gengrid_selected_item_get(grid);
217    if (!sel)
218        return;
219    snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
220    ti = malloc(sizeof(*ti));
221    ti->mode = 0;
222    ti->path = eina_stringshare_add(buf);
223    ti->item = elm_gengrid_item_insert_before(grid, &gic, ti, sel, grid_sel,
224                                              NULL);
225 }
226
227 static void
228 _after_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
229 {
230    Testitem *ti;
231    Evas_Object *grid = data;
232    Elm_Gengrid_Item *sel;
233    char buf[PATH_MAX];
234
235    sel = elm_gengrid_selected_item_get(grid);
236    if (!sel)
237        return;
238    snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
239    ti = malloc(sizeof(*ti));
240    ti->mode = 0;
241    ti->path = eina_stringshare_add(buf);
242    ti->item = elm_gengrid_item_insert_after(grid, &gic, ti, sel, grid_sel,
243                                             NULL);
244 }
245
246 static void
247 _prepend_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
248 {
249    Testitem *ti;
250    Evas_Object *grid = data;
251    char buf[PATH_MAX];
252
253    snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
254    ti = malloc(sizeof(*ti));
255    ti->mode = 0;
256    ti->path = eina_stringshare_add(buf);
257    ti->item = elm_gengrid_item_prepend(grid, &gic, ti, grid_sel, NULL);
258 }
259
260 static void
261 _append_bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
262 {
263    Testitem *ti;
264    Evas_Object *grid = data;
265    char buf[PATH_MAX];
266
267    snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[rand() % 9]);
268    ti = malloc(sizeof(*ti));
269    ti->mode = 0;
270    ti->path = eina_stringshare_add(buf);
271    ti->item = elm_gengrid_item_append(grid, &gic, ti, grid_sel, NULL);
272 }
273
274 static void
275 _size_changed(void *data, Evas_Object *obj, void *event_info __UNUSED__)
276 {
277    Evas_Object *grid = data;
278    int size = elm_spinner_value_get(obj);
279    elm_gengrid_item_size_set(grid, size, size);
280 }
281
282 void
283 test_gengrid2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
284 {
285    Evas_Object *win, *bg, *grid, *bx, *hbx, *bt, *ck;
286
287    win = elm_win_add(NULL, "gengrid2", ELM_WIN_BASIC);
288    elm_win_title_set(win, "GenGrid2");
289    elm_win_autodel_set(win, 1);
290
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);
295
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);
300
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);
310
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);
316
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);
322
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);
328
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);
334
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);
340
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);
349
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);
355
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;
361
362    evas_object_resize(win, 600, 600);
363    evas_object_show(win);
364 }
365 #endif