[SLP Merge] 2011/7/14 12:00PM
[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 typedef struct _Testitem
9 {
10    Elm_Gengrid_Item *item;
11    const char *path;
12    int mode;
13    int onoff;
14 } Testitem;
15
16 static Elm_Gengrid_Item_Class gic;
17
18 char *
19 grd_lbl_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
20 {
21    const Testitem *ti = data;
22    char buf[256];
23    snprintf(buf, sizeof(buf), "Photo %s", ti->path);
24    return strdup(buf);
25 }
26
27 Evas_Object *
28 grd_icon_get(void *data, Evas_Object *obj, const char *part)
29 {
30    const Testitem *ti = data;
31    if (!strcmp(part, "elm.swallow.icon"))
32      {
33         Evas_Object *icon = elm_bg_add(obj);
34         elm_bg_file_set(icon, ti->path, NULL);
35         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL,
36                                          1, 1);
37         evas_object_show(icon);
38         return icon;
39      }
40    return NULL;
41 }
42
43 static Elm_Genlist_Item_Class itct;
44
45 static void
46 glt_exp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
47 {
48    Elm_Genlist_Item *it = event_info;
49    Evas_Object *gl = elm_genlist_item_genlist_get(it);
50    int val = (int)(long)elm_genlist_item_data_get(it);
51    Elm_Genlist_Item *it1, *it2, *it3;
52
53    val *= 10;
54    it1 = elm_genlist_item_append(gl, &itct, (void *)(long)(val + 1), it,
55                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
56    it2 = elm_genlist_item_append(gl, &itct, (void *)(long)(val + 2), it,
57                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
58    it3 = elm_genlist_item_append(gl, &itct, (void *)(long)(val + 3), it,
59                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
60
61    elm_genlist_item_cursor_set(it1, ELM_CURSOR_HAND2);
62    elm_genlist_item_cursor_set(it2, ELM_CURSOR_HAND2);
63    elm_genlist_item_cursor_set(it3, ELM_CURSOR_HAND1);
64
65 }
66
67 static void
68 glt_con(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
69 {
70    Elm_Genlist_Item *it = event_info;
71    elm_genlist_item_subitems_clear(it);
72 }
73
74 static void
75 glt_exp_req(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
76 {
77    Elm_Genlist_Item *it = event_info;
78    elm_genlist_item_expanded_set(it, 1);
79 }
80
81 static void
82 glt_con_req(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
83 {
84    Elm_Genlist_Item *it = event_info;
85    elm_genlist_item_expanded_set(it, 0);
86 }
87
88 char *
89 glt_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
90 {
91    char buf[256];
92    snprintf(buf, sizeof(buf), "Item mode %i", (int)(long)data);
93    return strdup(buf);
94 }
95
96 void
97 test_cursor(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
98 {
99    Evas_Object *win, *bg, *bx, *bt, *list, *entry, *ck;
100    Elm_List_Item *lit;
101
102    win = elm_win_add(NULL, "cursor", ELM_WIN_BASIC);
103    elm_win_title_set(win, "Cursor");
104    elm_win_autodel_set(win, 1);
105
106    bg = elm_bg_add(win);
107    elm_win_resize_object_add(win, bg);
108    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
109    evas_object_show(bg);
110    elm_object_cursor_set(bg, ELM_CURSOR_CIRCLE);
111
112    bx = elm_box_add(win);
113    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114    elm_win_resize_object_add(win, bx);
115    evas_object_show(bx);
116
117    ck = elm_clock_add(win);
118    elm_object_cursor_set(ck, ELM_CURSOR_CLOCK);
119    elm_box_pack_end(bx, ck);
120    evas_object_show(ck);
121
122    bt = elm_button_add(win);
123    elm_object_cursor_set(bt, ELM_CURSOR_COFFEE_MUG);
124    elm_object_text_set(bt, "Coffee Mug");
125    elm_box_pack_end(bx, bt);
126    evas_object_show(bt);
127
128    bt = elm_button_add(win);
129    elm_object_cursor_set(bt, ELM_CURSOR_CLOCK);
130    elm_object_text_set(bt, "Cursor unset");
131    elm_object_cursor_unset(bt);
132    elm_box_pack_end(bx, bt);
133    evas_object_show(bt);
134
135    list = elm_list_add(win);
136    elm_box_pack_end(bx, list);
137    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
138    evas_object_size_hint_fill_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
139    elm_object_cursor_set(list, ELM_CURSOR_WATCH);
140    lit = elm_list_item_append(list, "watch over list | hand1", NULL, NULL, NULL,
141                         NULL);
142    elm_list_item_cursor_set(lit, ELM_CURSOR_HAND1);
143    lit = elm_list_item_append(list, "watch over list | hand2", NULL, NULL, NULL,
144                         NULL);
145    elm_list_item_cursor_set(lit, ELM_CURSOR_HAND2);
146    elm_list_go(list);
147    evas_object_show(list);
148
149    entry = elm_entry_add(win);
150    elm_entry_scrollable_set(entry, EINA_TRUE);
151    elm_entry_entry_set(entry, "Xterm cursor");
152    elm_entry_single_line_set(entry, EINA_TRUE);
153    evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0);
154    evas_object_size_hint_fill_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
155    elm_box_pack_end(bx, entry);
156    evas_object_show(entry);
157    elm_object_cursor_set(entry, ELM_CURSOR_XTERM);
158
159    evas_object_resize(win, 320, 480);
160    evas_object_show(win);
161 }
162
163 void
164 test_cursor2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
165 {
166    Evas_Object *win, *bg, *bx, *o, *grid, *gl;
167    Elm_Genlist_Item *it1, *it2, *it3;
168    Elm_Toolbar_Item *tit;
169    Elm_List_Item *lit;
170    char buf[PATH_MAX];
171    static Testitem ti[144];
172    int i, n;
173    const char *img[9] =
174      {
175         "panel_01.jpg",
176         "plant_01.jpg",
177         "rock_01.jpg",
178         "rock_02.jpg",
179         "sky_01.jpg",
180         "sky_02.jpg",
181         "sky_03.jpg",
182         "sky_04.jpg",
183         "wood_01.jpg",
184      };
185
186    win = elm_win_add(NULL, "cursor2", ELM_WIN_BASIC);
187    elm_win_title_set(win, "Cursor 2");
188    elm_win_autodel_set(win, 1);
189
190    bg = elm_bg_add(win);
191    elm_win_resize_object_add(win, bg);
192    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
193    evas_object_show(bg);
194
195    bx = elm_box_add(win);
196    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197    elm_win_resize_object_add(win, bx);
198    evas_object_show(bx);
199
200    o = elm_toolbar_add(win);
201    elm_toolbar_homogeneous_set(o, 0);
202    evas_object_size_hint_weight_set(o, 0.0, 0.0);
203    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
204    tit = elm_toolbar_item_append(o, NULL, "Bogosity", NULL, NULL);
205    elm_toolbar_item_cursor_set(tit, ELM_CURSOR_BOGOSITY);
206    tit = elm_toolbar_item_append(o, NULL, "Unset", NULL, NULL);
207    elm_toolbar_item_cursor_set(tit, ELM_CURSOR_BOGOSITY);
208    elm_toolbar_item_cursor_unset(tit);
209    tit = elm_toolbar_item_append(o, NULL, "Xterm", NULL, NULL);
210    elm_toolbar_item_cursor_set(tit, ELM_CURSOR_XTERM);
211    elm_box_pack_end(bx, o);
212    evas_object_show(o);
213
214    o = elm_list_add(win);
215    elm_box_pack_end(bx, o);
216    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
218    lit = elm_list_item_append(o, "cursor bogosity", NULL, NULL,  NULL, NULL);
219    elm_list_item_cursor_set(lit, ELM_CURSOR_BOGOSITY);
220    lit = elm_list_item_append(o, "cursor unset", NULL, NULL,  NULL, NULL);
221    elm_list_item_cursor_set(lit, ELM_CURSOR_BOGOSITY);
222    elm_list_item_cursor_unset(lit);
223    lit = elm_list_item_append(o, "cursor xterm", NULL, NULL,  NULL, NULL);
224    elm_list_item_cursor_set(lit, ELM_CURSOR_XTERM);
225    elm_list_go(o);
226    evas_object_show(o);
227
228    gl = elm_genlist_add(win);
229    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
230    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
231    evas_object_show(gl);
232
233    itct.item_style     = "default";
234    itct.func.label_get = glt_label_get;
235
236    it1 = elm_genlist_item_append(gl, &itct, (void *) 1, NULL,
237                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
238    it2 = elm_genlist_item_append(gl, &itct, (void *) 2, NULL,
239                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
240    it3 = elm_genlist_item_append(gl, &itct, (void *) 3, NULL,
241                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
242
243    elm_genlist_item_cursor_set(it1, ELM_CURSOR_HAND1);
244    elm_genlist_item_cursor_set(it2, ELM_CURSOR_HAND1);
245    elm_genlist_item_cursor_set(it3, ELM_CURSOR_CROSS);
246
247    evas_object_smart_callback_add(gl, "expand,request", glt_exp_req, gl);
248    evas_object_smart_callback_add(gl, "contract,request", glt_con_req, gl);
249    evas_object_smart_callback_add(gl, "expanded", glt_exp, gl);
250    evas_object_smart_callback_add(gl, "contracted", glt_con, gl);
251
252    elm_box_pack_end(bx, gl);
253
254    grid = elm_gengrid_add(win);
255    elm_gengrid_item_size_set(grid, 130, 130);
256    elm_gengrid_horizontal_set(grid, EINA_FALSE);
257    elm_gengrid_multi_select_set(grid, EINA_TRUE);
258    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
259    evas_object_size_hint_fill_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
260
261    gic.item_style = "default";
262    gic.func.label_get = grd_lbl_get;
263    gic.func.icon_get = grd_icon_get;
264
265    n = 0;
266    for (i = 0; i < 3 * 3; i++)
267      {
268         snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR, img[n]);
269         n = (n + 1) % 9;
270         ti[i].mode = i;
271         ti[i].path = eina_stringshare_add(buf);
272         ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), NULL, NULL);
273         if (n % 2)
274            elm_gengrid_item_cursor_set(ti[i].item, ELM_CURSOR_HAND1);
275         else
276            elm_gengrid_item_cursor_set(ti[i].item, ELM_CURSOR_CLOCK);
277         if (!(i % 5))
278            elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
279      }
280    elm_box_pack_end(bx, grid);
281    evas_object_show(grid);
282
283    evas_object_resize(win, 320, 480);
284    evas_object_show(win);
285 }
286
287 void
288 test_cursor3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
289 {
290    Evas_Object *win, *bg, *bx, *o;
291    Elm_List_Item *lit;
292    char buf[PATH_MAX];
293
294    win = elm_win_add(NULL, "cursor3", ELM_WIN_BASIC);
295    elm_win_title_set(win, "Cursor 3");
296    elm_win_autodel_set(win, 1);
297
298    snprintf(buf, sizeof(buf), "%s/objects/cursors.edj", PACKAGE_DATA_DIR);
299    elm_theme_extension_add(NULL, buf);
300
301    bg = elm_bg_add(win);
302    elm_win_resize_object_add(win, bg);
303    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
304    evas_object_show(bg);
305
306    bx = elm_box_add(win);
307    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
308    elm_win_resize_object_add(win, bx);
309    evas_object_show(bx);
310
311    o = elm_button_add(win);
312    elm_object_cursor_set(o, ELM_CURSOR_HAND1);
313    elm_object_cursor_engine_only_set(o, EINA_FALSE);
314    elm_object_text_set(o, "hand1");
315    elm_box_pack_end(bx, o);
316    evas_object_show(o);
317
318    o = elm_button_add(win);
319    elm_object_cursor_set(o, ELM_CURSOR_HAND2);
320    elm_object_text_set(o, "hand2 x");
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_cursor_engine_only_set(o, EINA_FALSE);
327    elm_object_text_set(o, "hand2");
328    elm_box_pack_end(bx, o);
329    evas_object_show(o);
330
331    o = elm_button_add(win);
332    elm_object_cursor_set(o, "hand3");
333    elm_object_cursor_engine_only_set(o, EINA_FALSE);
334    elm_object_text_set(o, "hand3");
335    elm_box_pack_end(bx, o);
336    evas_object_show(o);
337
338    o = elm_button_add(win);
339    elm_object_cursor_set(o, "hand3");
340    elm_object_cursor_engine_only_set(o, EINA_FALSE);
341    elm_object_cursor_style_set(o, "transparent");
342    elm_object_text_set(o, "hand3 transparent");
343    elm_box_pack_end(bx, o);
344    evas_object_show(o);
345
346    o = elm_button_add(win);
347    elm_object_cursor_set(o, "hand3");
348    elm_object_cursor_engine_only_set(o, EINA_FALSE);
349    elm_object_cursor_unset(o);
350    elm_object_text_set(o, "unset");
351    elm_box_pack_end(bx, o);
352    evas_object_show(o);
353
354    o = elm_button_add(win);
355    elm_object_cursor_set(o, "hand4");
356    elm_object_text_set(o, "not existent");
357    elm_box_pack_end(bx, o);
358    evas_object_show(o);
359
360    elm_cursor_engine_only_set(0);
361    o = elm_button_add(win);
362    elm_object_cursor_set(o, "hand2");
363    elm_object_text_set(o, "hand 2 engine only config false");
364    elm_box_pack_end(bx, o);
365    evas_object_show(o);
366
367    elm_cursor_engine_only_set(1);
368    o = elm_button_add(win);
369    elm_object_cursor_set(o, "hand2");
370    elm_object_text_set(o, "hand 2 engine only config true");
371    elm_box_pack_end(bx, o);
372    evas_object_show(o);
373
374    o = elm_list_add(win);
375    elm_box_pack_end(bx, o);
376    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
377    evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
378    lit = elm_list_item_append(o, "cursor hand2 x", NULL, NULL,  NULL, NULL);
379    elm_list_item_cursor_set(lit, ELM_CURSOR_HAND2);
380    lit = elm_list_item_append(o, "cursor hand2", NULL, NULL,  NULL, NULL);
381    elm_list_item_cursor_set(lit, ELM_CURSOR_HAND2);
382    elm_list_item_cursor_engine_only_set(lit, EINA_FALSE);
383    lit = elm_list_item_append(o, "cursor hand3", NULL, NULL,  NULL, NULL);
384    elm_list_item_cursor_set(lit, "hand3");
385    elm_list_item_cursor_engine_only_set(lit, EINA_FALSE);
386    lit = elm_list_item_append(o, "cursor hand3 transparent", NULL, NULL,
387                               NULL, NULL);
388    elm_list_item_cursor_set(lit, "hand3");
389    elm_list_item_cursor_style_set(lit, "transparent");
390    elm_list_item_cursor_engine_only_set(lit, EINA_FALSE);
391    elm_list_go(o);
392    evas_object_show(o);
393
394    evas_object_resize(win, 320, 480);
395    evas_object_show(win);
396 }
397
398 #endif