fixed plugin image size problem
[framework/uifw/elementary.git] / src / bin / test_cursor.c
1 #include <Elementary_Cursor.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #include <Elementary.h>
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, *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_util_standard_add("cursor2", "Cursor 2");
189    elm_win_autodel_set(win, EINA_TRUE);
190
191    bx = elm_box_add(win);
192    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
193    elm_win_resize_object_add(win, bx);
194    evas_object_show(bx);
195
196    o = elm_toolbar_add(win);
197    elm_toolbar_homogeneous_set(o, 0);
198    evas_object_size_hint_weight_set(o, 0.0, 0.0);
199    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
200    tb_it = elm_toolbar_item_append(o, NULL, "Bogosity", NULL, NULL);
201    elm_object_item_cursor_set(tb_it, ELM_CURSOR_BOGOSITY);
202    tb_it = elm_toolbar_item_append(o, NULL, "Unset", NULL, NULL);
203    elm_object_item_cursor_set(tb_it, ELM_CURSOR_BOGOSITY);
204    elm_object_item_cursor_unset(tb_it);
205    tb_it = elm_toolbar_item_append(o, NULL, "Xterm", NULL, NULL);
206    elm_object_item_cursor_set(tb_it, ELM_CURSOR_XTERM);
207    elm_box_pack_end(bx, o);
208    evas_object_show(o);
209
210    o = elm_list_add(win);
211    elm_box_pack_end(bx, o);
212    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
214    lit = elm_list_item_append(o, "cursor bogosity", NULL, NULL,  NULL, NULL);
215    elm_object_item_cursor_set(lit, ELM_CURSOR_BOGOSITY);
216    lit = elm_list_item_append(o, "cursor unset", NULL, NULL,  NULL, NULL);
217    elm_object_item_cursor_set(lit, ELM_CURSOR_BOGOSITY);
218    elm_object_item_cursor_unset(lit);
219    lit = elm_list_item_append(o, "cursor xterm", NULL, NULL,  NULL, NULL);
220    elm_object_item_cursor_set(lit, ELM_CURSOR_XTERM);
221    elm_list_go(o);
222    evas_object_show(o);
223
224    gl = elm_genlist_add(win);
225    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
226    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227    evas_object_show(gl);
228
229    itct.item_style     = "default";
230    itct.func.text_get = glt_text_get;
231
232    glit1 = elm_genlist_item_append(gl, &itct, (void *) 1, NULL,
233                                    ELM_GENLIST_ITEM_TREE, NULL, NULL);
234    glit2 = elm_genlist_item_append(gl, &itct, (void *) 2, NULL,
235                                    ELM_GENLIST_ITEM_TREE, NULL, NULL);
236    glit3 = elm_genlist_item_append(gl, &itct, (void *) 3, NULL,
237                                    ELM_GENLIST_ITEM_NONE, NULL, NULL);
238
239    elm_genlist_item_cursor_set(glit1, ELM_CURSOR_HAND1);
240    elm_genlist_item_cursor_set(glit2, ELM_CURSOR_HAND1);
241    elm_genlist_item_cursor_set(glit3, ELM_CURSOR_CROSS);
242
243    evas_object_smart_callback_add(gl, "expand,request", glt_exp_req, gl);
244    evas_object_smart_callback_add(gl, "contract,request", glt_con_req, gl);
245    evas_object_smart_callback_add(gl, "expanded", glt_exp, gl);
246    evas_object_smart_callback_add(gl, "contracted", glt_con, gl);
247
248    elm_box_pack_end(bx, gl);
249
250    grid = elm_gengrid_add(win);
251    elm_gengrid_item_size_set(grid, 130, 130);
252    elm_gengrid_horizontal_set(grid, EINA_FALSE);
253    elm_gengrid_multi_select_set(grid, EINA_TRUE);
254    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
255    evas_object_size_hint_fill_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
256
257    gic.item_style = "default";
258    gic.func.text_get = grd_lbl_get;
259    gic.func.content_get = grd_content_get;
260
261    n = 0;
262    for (i = 0; i < 3 * 3; i++)
263      {
264         snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n]);
265         n = (n + 1) % 9;
266         ti[i].mode = i;
267         ti[i].path = eina_stringshare_add(buf);
268         ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), NULL, NULL);
269         if (n % 2)
270            elm_gengrid_item_cursor_set(ti[i].item, ELM_CURSOR_HAND1);
271         else
272            elm_gengrid_item_cursor_set(ti[i].item, ELM_CURSOR_CLOCK);
273         if (!(i % 5))
274            elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
275      }
276    elm_box_pack_end(bx, grid);
277    evas_object_show(grid);
278
279    evas_object_resize(win, 320, 480);
280    evas_object_show(win);
281 }
282
283 void
284 test_cursor3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
285 {
286    Evas_Object *win, *bx, *o;
287    Elm_Object_Item *lit;
288    char buf[PATH_MAX];
289
290    win = elm_win_util_standard_add("cursor3", "Cursor 3");
291    elm_win_autodel_set(win, EINA_TRUE);
292
293    snprintf(buf, sizeof(buf), "%s/objects/cursors.edj", elm_app_data_dir_get());
294    elm_theme_extension_add(NULL, buf);
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    o = elm_button_add(win);
302    elm_object_cursor_set(o, ELM_CURSOR_HAND1);
303    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
304    elm_object_text_set(o, "hand1");
305    elm_box_pack_end(bx, o);
306    evas_object_show(o);
307
308    o = elm_button_add(win);
309    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
310    elm_object_text_set(o, "hand2 x");
311    elm_box_pack_end(bx, o);
312    evas_object_show(o);
313
314    o = elm_button_add(win);
315    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
316    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
317    elm_object_text_set(o, "hand2");
318    elm_box_pack_end(bx, o);
319    evas_object_show(o);
320
321    o = elm_button_add(win);
322    elm_object_cursor_set(o, "hand3");
323    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
324    elm_object_text_set(o, "hand3");
325    elm_box_pack_end(bx, o);
326    evas_object_show(o);
327
328    o = elm_button_add(win);
329    elm_object_cursor_set(o, "hand3");
330    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
331    elm_object_cursor_style_set(o, "transparent");
332    elm_object_text_set(o, "hand3 transparent");
333    elm_box_pack_end(bx, o);
334    evas_object_show(o);
335
336    o = elm_button_add(win);
337    elm_object_cursor_set(o, "hand3");
338    elm_object_cursor_theme_search_enabled_set(o, EINA_FALSE);
339    elm_object_cursor_unset(o);
340    elm_object_text_set(o, "unset");
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, "hand4");
346    elm_object_text_set(o, "not existent");
347    elm_box_pack_end(bx, o);
348    evas_object_show(o);
349
350    elm_config_cursor_engine_only_set(EINA_FALSE);
351    o = elm_button_add(win);
352    elm_object_cursor_set(o, "hand2");
353    elm_object_text_set(o, "hand 2 engine only config false");
354    elm_box_pack_end(bx, o);
355    evas_object_show(o);
356
357    elm_config_cursor_engine_only_set(EINA_TRUE);
358    o = elm_button_add(win);
359    elm_object_cursor_set(o, "hand2");
360    elm_object_text_set(o, "hand 2 engine only config true");
361    elm_box_pack_end(bx, o);
362    evas_object_show(o);
363
364    o = elm_list_add(win);
365    elm_box_pack_end(bx, o);
366    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
367    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
368    lit = elm_list_item_append(o, "cursor hand2 x", NULL, NULL,  NULL, NULL);
369    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
370    lit = elm_list_item_append(o, "cursor hand2", NULL, NULL,  NULL, NULL);
371    elm_object_item_cursor_set(lit, ELM_CURSOR_HAND2);
372    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
373    lit = elm_list_item_append(o, "cursor hand3", NULL, NULL,  NULL, NULL);
374    elm_object_item_cursor_set(lit, "hand3");
375    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
376    lit = elm_list_item_append(o, "cursor hand3 transparent", NULL, NULL,
377                               NULL, NULL);
378    elm_object_item_cursor_set(lit, "hand3");
379    elm_object_item_cursor_style_set(lit, "transparent");
380    elm_object_item_cursor_engine_only_set(lit, EINA_FALSE);
381    elm_list_go(o);
382    evas_object_show(o);
383
384    evas_object_resize(win, 320, 480);
385    evas_object_show(win);
386 }
387
388 void
389 test_cursor4(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
390 {
391    Evas_Object *win, *bx, *ly, *bt;
392    char buf[PATH_MAX];
393
394    win = elm_win_util_standard_add("cursor layout", "Cursor Layout");
395    elm_win_autodel_set(win, EINA_TRUE);
396
397    snprintf(buf, sizeof(buf), "%s/objects/cursors.edj", elm_app_data_dir_get());
398
399    bx = elm_box_add(win);
400    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
401    elm_win_resize_object_add(win, bx);
402    evas_object_show(bx);
403
404    ly = elm_layout_add(win);
405    elm_layout_file_set(ly, buf, "test/layout/events");
406    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
407    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
408    elm_object_cursor_set(ly, ELM_CURSOR_HAND1);
409    elm_box_pack_end(bx, ly);
410    evas_object_show(ly);
411
412    ly = elm_layout_add(win);
413    elm_layout_file_set(ly, buf, "test/layout/noevents");
414    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
415    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
416    elm_object_cursor_set(ly, ELM_CURSOR_XTERM);
417    elm_layout_part_cursor_set(ly, "top-left", ELM_CURSOR_CROSS);
418    elm_layout_part_cursor_set(ly, "bottom-left", ELM_CURSOR_PIRATE);
419    elm_box_pack_end(bx, ly);
420    evas_object_show(ly);
421
422    ly = elm_layout_add(win);
423    elm_layout_file_set(ly, buf, "test/layout/parts2");
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_layout_part_cursor_set(ly, "top-left", ELM_CURSOR_CROSS);
427    elm_layout_part_cursor_set(ly, "bottom-left", ELM_CURSOR_PIRATE);
428    elm_box_pack_end(bx, ly);
429    evas_object_show(ly);
430
431    ly = elm_layout_add(win);
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_layout_file_set(ly, buf, "test/layout/swallow");
435    bt = elm_button_add(win);
436    elm_object_text_set(bt, "Cursor over obj");
437    elm_object_part_content_set(ly, "swallow1", bt);
438    elm_object_cursor_set(bt, ELM_CURSOR_PIRATE);
439    bt = elm_button_add(win);
440    elm_object_text_set(bt, "Cursor over part");
441    elm_object_part_content_set(ly, "swallow2", bt);
442    elm_layout_part_cursor_set(ly, "swallow2", ELM_CURSOR_PIRATE);
443    elm_box_pack_end(bx, ly);
444    evas_object_show(ly);
445
446    evas_object_resize(win, 320, 480);
447    evas_object_show(win);
448 }
449
450 #endif