[migration] fixed conflicts in files
[framework/uifw/elementary.git] / src / bin / test_cursor.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #ifdef HAVE_CONFIG_H
4 # include "elementary_config.h"
5 #endif
6 #ifndef ELM_LIB_QUICKLAUNCH
7
8 // XXX: show all type of cursors in the elementary_test. this needs to be the first test
9
10 typedef struct _Testitem
11 {
12    Elm_Object_Item *item;
13    const char *path;
14    int mode;
15    int onoff;
16 } Testitem;
17
18 static Elm_Gengrid_Item_Class gic;
19
20 char *
21 grd_lbl_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
22 {
23    const Testitem *ti = data;
24    char buf[256];
25    snprintf(buf, sizeof(buf), "Photo %s", ti->path);
26    return strdup(buf);
27 }
28
29 Evas_Object *
30 grd_content_get(void *data, Evas_Object *obj, const char *part)
31 {
32    const Testitem *ti = data;
33    if (!strcmp(part, "elm.swallow.icon"))
34      {
35         Evas_Object *icon = elm_bg_add(obj);
36         elm_bg_file_set(icon, ti->path, NULL);
37         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL,
38                                          1, 1);
39         evas_object_show(icon);
40         return icon;
41      }
42    return NULL;
43 }
44
45 static Elm_Genlist_Item_Class itct;
46
47 static void
48 glt_exp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
49 {
50    Elm_Object_Item *glit = event_info;
51    Evas_Object *gl = elm_object_item_widget_get(glit);
52    int val = (int)(long) elm_object_item_data_get(glit);
53    Elm_Object_Item *glit1, *glit2, *glit3;
54
55    val *= 10;
56    glit1 = elm_genlist_item_append(gl, &itct, (void *)(long) (val + 1), glit,
57                                    ELM_GENLIST_ITEM_NONE, NULL, NULL);
58    glit2 = elm_genlist_item_append(gl, &itct, (void *)(long) (val + 2), glit,
59                                    ELM_GENLIST_ITEM_NONE, NULL, NULL);
60    glit3 = elm_genlist_item_append(gl, &itct, (void *)(long) (val + 3), glit,
61                                    ELM_GENLIST_ITEM_TREE, NULL, NULL);
62
63    elm_genlist_item_cursor_set(glit1, ELM_CURSOR_HAND2);
64    elm_genlist_item_cursor_set(glit2, ELM_CURSOR_HAND2);
65    elm_genlist_item_cursor_set(glit3, ELM_CURSOR_HAND1);
66
67 }
68
69 static void
70 glt_con(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
71 {
72    Elm_Object_Item *glit = event_info;
73    elm_genlist_item_subitems_clear(glit);
74 }
75
76 static void
77 glt_exp_req(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
78 {
79    Elm_Object_Item *glit = event_info;
80    elm_genlist_item_expanded_set(glit, EINA_TRUE);
81 }
82
83 static void
84 glt_con_req(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
85 {
86    Elm_Object_Item *glit = event_info;
87    elm_genlist_item_expanded_set(glit, EINA_FALSE);
88 }
89
90 char *
91 glt_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
92 {
93    char buf[256];
94    snprintf(buf, sizeof(buf), "Item mode %i", (int)(long)data);
95    return strdup(buf);
96 }
97
98 void
99 test_cursor(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100 {
101    Evas_Object *win, *bg, *bx, *bt, *list, *entry, *ck;
102    Elm_Object_Item *lit;
103
104    win = elm_win_add(NULL, "cursor", ELM_WIN_BASIC);
105    elm_win_title_set(win, "Cursor");
106    elm_win_autodel_set(win, EINA_TRUE);
107
108    bg = elm_bg_add(win);
109    elm_win_resize_object_add(win, bg);
110    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111    evas_object_show(bg);
112    elm_object_cursor_set(bg, ELM_CURSOR_CIRCLE);
113
114    bx = elm_box_add(win);
115    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
116    elm_win_resize_object_add(win, bx);
117    evas_object_show(bx);
118
119    ck = elm_clock_add(win);
120    elm_object_cursor_set(ck, ELM_CURSOR_CLOCK);
121    elm_box_pack_end(bx, ck);
122    evas_object_show(ck);
123
124    bt = elm_button_add(win);
125    elm_object_cursor_set(bt, ELM_CURSOR_COFFEE_MUG);
126    elm_object_text_set(bt, "Coffee Mug");
127    elm_box_pack_end(bx, bt);
128    evas_object_show(bt);
129
130    bt = elm_button_add(win);
131    elm_object_cursor_set(bt, ELM_CURSOR_CLOCK);
132    elm_object_text_set(bt, "Cursor unset");
133    elm_object_cursor_unset(bt);
134    elm_box_pack_end(bx, bt);
135    evas_object_show(bt);
136
137    list = elm_list_add(win);
138    elm_box_pack_end(bx, list);
139    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
140    evas_object_size_hint_fill_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
141    elm_object_cursor_set(list, ELM_CURSOR_WATCH);
142    lit = elm_list_item_append(list, "watch over list | hand1", NULL, NULL, NULL,
143                         NULL);
144    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND1);
145    lit = elm_list_item_append(list, "watch over list | hand2", NULL, NULL, NULL,
146                         NULL);
147    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
148    elm_list_go(list);
149    evas_object_show(list);
150
151    entry = elm_entry_add(win);
152    elm_entry_scrollable_set(entry, EINA_TRUE);
153    elm_object_text_set(entry, "Xterm cursor");
154    elm_entry_single_line_set(entry, EINA_TRUE);
155    evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0);
156    evas_object_size_hint_fill_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
157    elm_box_pack_end(bx, entry);
158    evas_object_show(entry);
159    elm_object_cursor_set(entry, ELM_CURSOR_XTERM);
160
161    evas_object_resize(win, 320, 480);
162    evas_object_show(win);
163 }
164
165 void
166 test_cursor2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
167 {
168    Evas_Object *win, *bg, *bx, *o, *grid, *gl;
169    Elm_Object_Item *glit1, *glit2, *glit3;
170    Elm_Object_Item *tb_it;
171    Elm_Object_Item *lit;
172    char buf[PATH_MAX];
173    static Testitem ti[144];
174    int i, n;
175    const char *img[9] =
176      {
177         "panel_01.jpg",
178         "plant_01.jpg",
179         "rock_01.jpg",
180         "rock_02.jpg",
181         "sky_01.jpg",
182         "sky_02.jpg",
183         "sky_03.jpg",
184         "sky_04.jpg",
185         "wood_01.jpg",
186      };
187
188    win = elm_win_add(NULL, "cursor2", ELM_WIN_BASIC);
189    elm_win_title_set(win, "Cursor 2");
190    elm_win_autodel_set(win, EINA_TRUE);
191
192    bg = elm_bg_add(win);
193    elm_win_resize_object_add(win, bg);
194    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
195    evas_object_show(bg);
196
197    bx = elm_box_add(win);
198    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
199    elm_win_resize_object_add(win, bx);
200    evas_object_show(bx);
201
202    o = elm_toolbar_add(win);
203    elm_toolbar_homogeneous_set(o, 0);
204    evas_object_size_hint_weight_set(o, 0.0, 0.0);
205    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
206    tb_it = elm_toolbar_item_append(o, NULL, "Bogosity", NULL, NULL);
207    elm_object_item_cursor_set(tb_it, ELM_CURSOR_BOGOSITY);
208    tb_it = elm_toolbar_item_append(o, NULL, "Unset", NULL, NULL);
209    elm_object_item_cursor_set(tb_it, ELM_CURSOR_BOGOSITY);
210    elm_object_item_cursor_unset(tb_it);
211    tb_it = elm_toolbar_item_append(o, NULL, "Xterm", NULL, NULL);
212    elm_object_item_cursor_set(tb_it, ELM_CURSOR_XTERM);
213    elm_box_pack_end(bx, o);
214    evas_object_show(o);
215
216    o = elm_list_add(win);
217    elm_box_pack_end(bx, o);
218    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
220    lit = elm_list_item_append(o, "cursor bogosity", NULL, NULL,  NULL, NULL);
221    elm_object_item_cursor_set(lit, ELM_CURSOR_BOGOSITY);
222    lit = elm_list_item_append(o, "cursor unset", NULL, NULL,  NULL, NULL);
223    elm_object_item_cursor_set(lit, ELM_CURSOR_BOGOSITY);
224    elm_object_item_cursor_unset(lit);
225    lit = elm_list_item_append(o, "cursor xterm", NULL, NULL,  NULL, NULL);
226    elm_object_item_cursor_set(lit, ELM_CURSOR_XTERM);
227    elm_list_go(o);
228    evas_object_show(o);
229
230    gl = elm_genlist_add(win);
231    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
232    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
233    evas_object_show(gl);
234
235    itct.item_style     = "default";
236    itct.func.text_get = glt_text_get;
237
238    glit1 = elm_genlist_item_append(gl, &itct, (void *) 1, NULL,
239                                    ELM_GENLIST_ITEM_TREE, NULL, NULL);
240    glit2 = elm_genlist_item_append(gl, &itct, (void *) 2, NULL,
241                                    ELM_GENLIST_ITEM_TREE, NULL, NULL);
242    glit3 = elm_genlist_item_append(gl, &itct, (void *) 3, NULL,
243                                    ELM_GENLIST_ITEM_NONE, NULL, NULL);
244
245    elm_genlist_item_cursor_set(glit1, ELM_CURSOR_HAND1);
246    elm_genlist_item_cursor_set(glit2, ELM_CURSOR_HAND1);
247    elm_genlist_item_cursor_set(glit3, ELM_CURSOR_CROSS);
248
249    evas_object_smart_callback_add(gl, "expand,request", glt_exp_req, gl);
250    evas_object_smart_callback_add(gl, "contract,request", glt_con_req, gl);
251    evas_object_smart_callback_add(gl, "expanded", glt_exp, gl);
252    evas_object_smart_callback_add(gl, "contracted", glt_con, gl);
253
254    elm_box_pack_end(bx, gl);
255
256    grid = elm_gengrid_add(win);
257    elm_gengrid_item_size_set(grid, 130, 130);
258    elm_gengrid_horizontal_set(grid, EINA_FALSE);
259    elm_gengrid_multi_select_set(grid, EINA_TRUE);
260    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
261    evas_object_size_hint_fill_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
262
263    gic.item_style = "default";
264    gic.func.text_get = grd_lbl_get;
265    gic.func.content_get = grd_content_get;
266
267    n = 0;
268    for (i = 0; i < 3 * 3; i++)
269      {
270         snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n]);
271         n = (n + 1) % 9;
272         ti[i].mode = i;
273         ti[i].path = eina_stringshare_add(buf);
274         ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), NULL, NULL);
275         if (n % 2)
276            elm_gengrid_item_cursor_set(ti[i].item, ELM_CURSOR_HAND1);
277         else
278            elm_gengrid_item_cursor_set(ti[i].item, ELM_CURSOR_CLOCK);
279         if (!(i % 5))
280            elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
281      }
282    elm_box_pack_end(bx, grid);
283    evas_object_show(grid);
284
285    evas_object_resize(win, 320, 480);
286    evas_object_show(win);
287 }
288
289 void
290 test_cursor3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
291 {
292    Evas_Object *win, *bg, *bx, *o;
293    Elm_Object_Item *lit;
294    char buf[PATH_MAX];
295
296    win = elm_win_add(NULL, "cursor3", ELM_WIN_BASIC);
297    elm_win_title_set(win, "Cursor 3");
298    elm_win_autodel_set(win, EINA_TRUE);
299
300    snprintf(buf, sizeof(buf), "%s/objects/cursors.edj", elm_app_data_dir_get());
301    elm_theme_extension_add(NULL, buf);
302
303    bg = elm_bg_add(win);
304    elm_win_resize_object_add(win, bg);
305    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
306    evas_object_show(bg);
307
308    bx = elm_box_add(win);
309    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
310    elm_win_resize_object_add(win, bx);
311    evas_object_show(bx);
312
313    o = elm_button_add(win);
314    elm_object_cursor_set(o, ELM_CURSOR_HAND1);
315 <<<<<<< HEAD
316    elm_object_cursor_engine_only_set(o, EINA_FALSE);
317 =======
318    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
319 >>>>>>> remotes/origin/upstream
320    elm_object_text_set(o, "hand1");
321    elm_box_pack_end(bx, o);
322    evas_object_show(o);
323
324    o = elm_button_add(win);
325    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
326    elm_object_text_set(o, "hand2 x");
327    elm_box_pack_end(bx, o);
328    evas_object_show(o);
329
330    o = elm_button_add(win);
331    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
332    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
333    elm_object_text_set(o, "hand2");
334    elm_box_pack_end(bx, o);
335    evas_object_show(o);
336
337    o = elm_button_add(win);
338    elm_object_cursor_set(o, "hand3");
339    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
340    elm_object_text_set(o, "hand3");
341    elm_box_pack_end(bx, o);
342    evas_object_show(o);
343
344    o = elm_button_add(win);
345    elm_object_cursor_set(o, "hand3");
346    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
347    elm_object_cursor_style_set(o, "transparent");
348    elm_object_text_set(o, "hand3 transparent");
349    elm_box_pack_end(bx, o);
350    evas_object_show(o);
351
352    o = elm_button_add(win);
353    elm_object_cursor_set(o, "hand3");
354    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
355    elm_object_cursor_unset(o);
356    elm_object_text_set(o, "unset");
357    elm_box_pack_end(bx, o);
358    evas_object_show(o);
359
360    o = elm_button_add(win);
361    elm_object_cursor_set(o, "hand4");
362    elm_object_text_set(o, "not existent");
363    elm_box_pack_end(bx, o);
364    evas_object_show(o);
365
366    elm_config_cursor_engine_only_set(EINA_FALSE);
367    o = elm_button_add(win);
368    elm_object_cursor_set(o, "hand2");
369    elm_object_text_set(o, "hand 2 engine only config false");
370    elm_box_pack_end(bx, o);
371    evas_object_show(o);
372
373    elm_config_cursor_engine_only_set(EINA_TRUE);
374    o = elm_button_add(win);
375    elm_object_cursor_set(o, "hand2");
376    elm_object_text_set(o, "hand 2 engine only config true");
377    elm_box_pack_end(bx, o);
378    evas_object_show(o);
379
380    o = elm_list_add(win);
381    elm_box_pack_end(bx, o);
382    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
383    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
384    lit = elm_list_item_append(o, "cursor hand2 x", NULL, NULL,  NULL, NULL);
385    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
386    lit = elm_list_item_append(o, "cursor hand2", NULL, NULL,  NULL, NULL);
387    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
388    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
389    lit = elm_list_item_append(o, "cursor hand3", NULL, NULL,  NULL, NULL);
390    elm_object_item_cursor_set(lit, "hand3");
391    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
392    lit = elm_list_item_append(o, "cursor hand3 transparent", NULL, NULL,
393                               NULL, NULL);
394    elm_object_item_cursor_set(lit, "hand3");
395    elm_object_item_cursor_style_set(lit, "transparent");
396    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
397    elm_list_go(o);
398    evas_object_show(o);
399
400    evas_object_resize(win, 320, 480);
401    evas_object_show(win);
402 }
403
404 void
405 test_cursor4(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
406 {
407    Evas_Object *win, *bg, *bx, *ly, *bt;
408    char buf[PATH_MAX];
409
410    win = elm_win_add(NULL, "cursor layout", ELM_WIN_BASIC);
411    elm_win_title_set(win, "Cursor Layout");
412    elm_win_autodel_set(win, EINA_TRUE);
413
414    snprintf(buf, sizeof(buf), "%s/objects/cursors.edj", elm_app_data_dir_get());
415
416    bg = elm_bg_add(win);
417    elm_win_resize_object_add(win, bg);
418    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
419    evas_object_show(bg);
420
421    bx = elm_box_add(win);
422    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
423    elm_win_resize_object_add(win, bx);
424    evas_object_show(bx);
425
426    ly = elm_layout_add(win);
427    elm_layout_file_set(ly, buf, "test/layout/events");
428    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
429    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
430    elm_object_cursor_set(ly, ELM_CURSOR_HAND1);
431    elm_box_pack_end(bx, ly);
432    evas_object_show(ly);
433
434    ly = elm_layout_add(win);
435    elm_layout_file_set(ly, buf, "test/layout/noevents");
436    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
437    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
438    elm_object_cursor_set(ly, ELM_CURSOR_XTERM);
439    elm_layout_part_cursor_set(ly, "top-left", ELM_CURSOR_CROSS);
440    elm_layout_part_cursor_set(ly, "bottom-left", ELM_CURSOR_PIRATE);
441    elm_box_pack_end(bx, ly);
442    evas_object_show(ly);
443
444    ly = elm_layout_add(win);
445    elm_layout_file_set(ly, buf, "test/layout/parts2");
446    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
447    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
448    elm_layout_part_cursor_set(ly, "top-left", ELM_CURSOR_CROSS);
449    elm_layout_part_cursor_set(ly, "bottom-left", ELM_CURSOR_PIRATE);
450    elm_box_pack_end(bx, ly);
451    evas_object_show(ly);
452
453    ly = elm_layout_add(win);
454    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
455    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
456    elm_layout_file_set(ly, buf, "test/layout/swallow");
457    bt = elm_button_add(win);
458    elm_object_text_set(bt, "Cursor over obj");
459    elm_object_part_content_set(ly, "swallow1", bt);
460    elm_object_cursor_set(bt, ELM_CURSOR_PIRATE);
461    bt = elm_button_add(win);
462    elm_object_text_set(bt, "Cursor over part");
463    elm_object_part_content_set(ly, "swallow2", bt);
464    elm_layout_part_cursor_set(ly, "swallow2", ELM_CURSOR_PIRATE);
465    elm_box_pack_end(bx, ly);
466    evas_object_show(ly);
467
468    evas_object_resize(win, 320, 480);
469    evas_object_show(win);
470 }
471
472 #endif