rename a whole host of config-related functions to be elm_config_*
[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_SUBITEMS, 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_SUBITEMS, NULL, NULL);
240    glit2 = elm_genlist_item_append(gl, &itct, (void *) 2, NULL,
241                                    ELM_GENLIST_ITEM_SUBITEMS, 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    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
316    elm_object_text_set(o, "hand1");
317    elm_box_pack_end(bx, o);
318    evas_object_show(o);
319
320    o = elm_button_add(win);
321    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
322    elm_object_text_set(o, "hand2 x");
323    elm_box_pack_end(bx, o);
324    evas_object_show(o);
325
326    o = elm_button_add(win);
327    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
328    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
329    elm_object_text_set(o, "hand2");
330    elm_box_pack_end(bx, o);
331    evas_object_show(o);
332
333    o = elm_button_add(win);
334    elm_object_cursor_set(o, "hand3");
335    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
336    elm_object_text_set(o, "hand3");
337    elm_box_pack_end(bx, o);
338    evas_object_show(o);
339
340    o = elm_button_add(win);
341    elm_object_cursor_set(o, "hand3");
342    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
343    elm_object_cursor_style_set(o, "transparent");
344    elm_object_text_set(o, "hand3 transparent");
345    elm_box_pack_end(bx, o);
346    evas_object_show(o);
347
348    o = elm_button_add(win);
349    elm_object_cursor_set(o, "hand3");
350    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
351    elm_object_cursor_unset(o);
352    elm_object_text_set(o, "unset");
353    elm_box_pack_end(bx, o);
354    evas_object_show(o);
355
356    o = elm_button_add(win);
357    elm_object_cursor_set(o, "hand4");
358    elm_object_text_set(o, "not existent");
359    elm_box_pack_end(bx, o);
360    evas_object_show(o);
361
362    elm_config_cursor_engine_only_set(EINA_FALSE);
363    o = elm_button_add(win);
364    elm_object_cursor_set(o, "hand2");
365    elm_object_text_set(o, "hand 2 engine only config false");
366    elm_box_pack_end(bx, o);
367    evas_object_show(o);
368
369    elm_config_cursor_engine_only_set(EINA_TRUE);
370    o = elm_button_add(win);
371    elm_object_cursor_set(o, "hand2");
372    elm_object_text_set(o, "hand 2 engine only config true");
373    elm_box_pack_end(bx, o);
374    evas_object_show(o);
375
376    o = elm_list_add(win);
377    elm_box_pack_end(bx, o);
378    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
379    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
380    lit = elm_list_item_append(o, "cursor hand2 x", NULL, NULL,  NULL, NULL);
381    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
382    lit = elm_list_item_append(o, "cursor hand2", NULL, NULL,  NULL, NULL);
383    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
384    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
385    lit = elm_list_item_append(o, "cursor hand3", NULL, NULL,  NULL, NULL);
386    elm_object_item_cursor_set(lit, "hand3");
387    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
388    lit = elm_list_item_append(o, "cursor hand3 transparent", NULL, NULL,
389                               NULL, NULL);
390    elm_object_item_cursor_set(lit, "hand3");
391    elm_object_item_cursor_style_set(lit, "transparent");
392    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
393    elm_list_go(o);
394    evas_object_show(o);
395
396    evas_object_resize(win, 320, 480);
397    evas_object_show(win);
398 }
399
400 void
401 test_cursor4(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
402 {
403    Evas_Object *win, *bg, *bx, *ly, *bt;
404    char buf[PATH_MAX];
405
406    win = elm_win_add(NULL, "cursor layout", ELM_WIN_BASIC);
407    elm_win_title_set(win, "Cursor Layout");
408    elm_win_autodel_set(win, EINA_TRUE);
409
410    snprintf(buf, sizeof(buf), "%s/objects/cursors.edj", elm_app_data_dir_get());
411
412    bg = elm_bg_add(win);
413    elm_win_resize_object_add(win, bg);
414    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
415    evas_object_show(bg);
416
417    bx = elm_box_add(win);
418    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
419    elm_win_resize_object_add(win, bx);
420    evas_object_show(bx);
421
422    ly = elm_layout_add(win);
423    elm_layout_file_set(ly, buf, "test/layout/events");
424    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
425    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
426    elm_object_cursor_set(ly, ELM_CURSOR_HAND1);
427    elm_box_pack_end(bx, ly);
428    evas_object_show(ly);
429
430    ly = elm_layout_add(win);
431    elm_layout_file_set(ly, buf, "test/layout/noevents");
432    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
433    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
434    elm_object_cursor_set(ly, ELM_CURSOR_XTERM);
435    elm_layout_part_cursor_set(ly, "top-left", ELM_CURSOR_CROSS);
436    elm_layout_part_cursor_set(ly, "bottom-left", ELM_CURSOR_PIRATE);
437    elm_box_pack_end(bx, ly);
438    evas_object_show(ly);
439
440    ly = elm_layout_add(win);
441    elm_layout_file_set(ly, buf, "test/layout/parts2");
442    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
443    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
444    elm_layout_part_cursor_set(ly, "top-left", ELM_CURSOR_CROSS);
445    elm_layout_part_cursor_set(ly, "bottom-left", ELM_CURSOR_PIRATE);
446    elm_box_pack_end(bx, ly);
447    evas_object_show(ly);
448
449    ly = elm_layout_add(win);
450    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
451    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
452    elm_layout_file_set(ly, buf, "test/layout/swallow");
453    bt = elm_button_add(win);
454    elm_object_text_set(bt, "Cursor over obj");
455    elm_object_part_content_set(ly, "swallow1", bt);
456    elm_object_cursor_set(bt, ELM_CURSOR_PIRATE);
457    bt = elm_button_add(win);
458    elm_object_text_set(bt, "Cursor over part");
459    elm_object_part_content_set(ly, "swallow2", bt);
460    elm_layout_part_cursor_set(ly, "swallow2", ELM_CURSOR_PIRATE);
461    elm_box_pack_end(bx, ly);
462    evas_object_show(ly);
463
464    evas_object_resize(win, 320, 480);
465    evas_object_show(win);
466 }
467
468 #endif