move elementary to trunk base. out of TMP/st.
[framework/uifw/elementary.git] / src / bin / test_tooltip.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 typedef struct _Testitem
8 {
9    Elm_Gengrid_Item *item;
10    const char       *path;
11    int               mode;
12    int               onoff;
13 } Testitem;
14
15 static Elm_Gengrid_Item_Class gic;
16
17 char *
18 grdt_lbl_get(void            *data,
19              Evas_Object *obj __UNUSED__,
20              const char *part __UNUSED__)
21 {
22    const Testitem *ti = data;
23    char buf[256];
24    snprintf(buf, sizeof(buf), "Photo %s", ti->path);
25    return strdup(buf);
26 }
27
28 Evas_Object *
29 grdt_icon_get(void        *data,
30               Evas_Object *obj,
31               const char  *part)
32 {
33    const Testitem *ti = data;
34    if (!strcmp(part, "elm.swallow.icon"))
35      {
36         Evas_Object *icon = elm_bg_add(obj);
37         elm_bg_file_set(icon, ti->path, NULL);
38         evas_object_size_hint_aspect_set(icon,
39                                          EVAS_ASPECT_CONTROL_VERTICAL,
40                                          1, 1);
41         evas_object_show(icon);
42         return icon;
43      }
44    return NULL;
45 }
46
47 static Elm_Genlist_Item_Class itct;
48
49 static void
50 gltt_exp(void *data       __UNUSED__,
51          Evas_Object *obj __UNUSED__,
52          void            *event_info)
53 {
54    Elm_Genlist_Item *it = event_info;
55    Evas_Object *gl = elm_genlist_item_genlist_get(it);
56    int val = (int)(long)elm_genlist_item_data_get(it);
57    Elm_Genlist_Item *it1, *it2, *it3;
58
59    val *= 10;
60    it1 = elm_genlist_item_append(gl, &itct, (void *)(long)(val + 1), it,
61                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
62    it2 = elm_genlist_item_append(gl, &itct, (void *)(long)(val + 2), it,
63                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
64    it3 = elm_genlist_item_append(gl, &itct, (void *)(long)(val + 3), it,
65                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
66
67    elm_genlist_item_tooltip_text_set(it1, "Testing A");
68    elm_genlist_item_tooltip_text_set(it2, "Testing B");
69    elm_genlist_item_tooltip_text_set(it3, "Testing C");
70 }
71
72 static void
73 gltt_con(void *data       __UNUSED__,
74          Evas_Object *obj __UNUSED__,
75          void            *event_info)
76 {
77    Elm_Genlist_Item *it = event_info;
78    elm_genlist_item_subitems_clear(it);
79 }
80
81 static void
82 gltt_exp_req(void *data       __UNUSED__,
83              Evas_Object *obj __UNUSED__,
84              void            *event_info)
85 {
86    Elm_Genlist_Item *it = event_info;
87    elm_genlist_item_expanded_set(it, 1);
88 }
89
90 static void
91 gltt_con_req(void *data       __UNUSED__,
92              Evas_Object *obj __UNUSED__,
93              void            *event_info)
94 {
95    Elm_Genlist_Item *it = event_info;
96    elm_genlist_item_expanded_set(it, 0);
97 }
98
99 char *
100 gltt_label_get(void            *data,
101                Evas_Object *obj __UNUSED__,
102                const char *part __UNUSED__)
103 {
104    char buf[256];
105    snprintf(buf, sizeof(buf), "Item mode %i", (int)(long)data);
106    return strdup(buf);
107 }
108
109 static Evas_Object *
110 _tt_item_icon(void *data   __UNUSED__,
111               Evas_Object *obj,
112               void *item   __UNUSED__)
113 {
114    Evas_Object *ic = elm_icon_add(obj);
115    char buf[PATH_MAX];
116    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
117             PACKAGE_DATA_DIR);
118    elm_icon_file_set(ic, buf, NULL);
119    elm_icon_scale_set(ic, 0, 0);
120    evas_object_resize(ic, 64, 64);
121    return ic;
122 }
123
124 static void
125 _tt_item_icon_del(void            *data,
126                   Evas_Object *obj __UNUSED__,
127                   void            *event_info)
128 {
129    // test to check for del_cb behavior!
130    printf("_tt_icon_del: data=%ld (== 456?), event_info=%p\n",
131           (long)data, event_info);
132 }
133
134 static void
135 _tt_text_replace(void *data       __UNUSED__,
136                  Evas_Object     *obj,
137                  void *event_info __UNUSED__)
138 {
139    static int count = 0;
140    char buf[64];
141    snprintf(buf, sizeof(buf), "count=%d", count);
142    count++;
143    elm_object_tooltip_text_set(obj, buf);
144 }
145
146 static void
147 _tt_timer_del(void *data       __UNUSED__,
148               Evas *e          __UNUSED__,
149               Evas_Object     *obj,
150               void *event_info __UNUSED__)
151 {
152    Ecore_Timer *timer = evas_object_data_del(obj, "test-timer");
153    if (!timer) return;
154    ecore_timer_del(timer);
155 }
156
157 static Eina_Bool
158 _tt_text_replace_timer_cb(void *data)
159 {
160    _tt_text_replace(NULL, data, NULL);
161    return EINA_TRUE;
162 }
163
164 static void
165 _tt_text_replace_timed(void *data       __UNUSED__,
166                        Evas_Object     *obj,
167                        void *event_info __UNUSED__)
168 {
169    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
170    if (timer)
171      {
172         ecore_timer_del(timer);
173         evas_object_data_del(obj, "test-timer");
174         elm_button_label_set(obj, "Simple text tooltip, click to start"
175                                   " changed timed");
176         return;
177      }
178
179    timer = ecore_timer_add(1.5, _tt_text_replace_timer_cb, obj);
180    evas_object_data_set(obj, "test-timer", timer);
181    elm_button_label_set(obj, "Simple text tooltip, click to stop changed"
182                              " timed");
183 }
184
185 static Evas_Object *
186 _tt_icon(void *data   __UNUSED__,
187          Evas_Object *obj)
188 {
189    Evas_Object *ic = elm_icon_add(obj);
190    char buf[PATH_MAX];
191    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
192             PACKAGE_DATA_DIR);
193    elm_icon_file_set(ic, buf, NULL);
194    elm_icon_scale_set(ic, 0, 0);
195    evas_object_resize(ic, 64, 64);
196    return ic;
197 }
198
199 static Evas_Object *
200 _tt_icon2(void *data   __UNUSED__,
201           Evas_Object *obj)
202 {
203    Evas_Object *ic = elm_icon_add(obj);
204    char buf[PATH_MAX];
205    snprintf(buf, sizeof(buf), "%s/images/icon_00.png", PACKAGE_DATA_DIR);
206    elm_icon_file_set(ic, buf, NULL);
207    elm_icon_scale_set(ic, 0, 0);
208    evas_object_resize(ic, 64, 64);
209    return ic;
210 }
211
212 static void
213 _tt_icon_del(void            *data,
214              Evas_Object *obj __UNUSED__,
215              void            *event_info)
216 {
217    // test to check for del_cb behavior!
218    printf("_tt_icon_del: data=%ld (== 123?), event_info=%p\n",
219           (long)data, event_info);
220 }
221
222 static Eina_Bool
223 _tt_icon_replace_timer_cb(void *data)
224 {
225    static int current = 0;
226
227    elm_object_tooltip_content_cb_set
228      (data, current ? _tt_icon2 : _tt_icon, NULL, NULL);
229
230    current = !current;
231    return EINA_TRUE;
232 }
233
234 static void
235 _tt_icon_replace_timed(void *data       __UNUSED__,
236                        Evas_Object     *obj,
237                        void *event_info __UNUSED__)
238 {
239    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
240    if (timer)
241      {
242         ecore_timer_del(timer);
243         evas_object_data_del(obj, "test-timer");
244         elm_button_label_set(obj, "Icon tooltip, click to start changed"
245                                   " timed");
246         return;
247      }
248
249    timer = ecore_timer_add(1.5, _tt_icon_replace_timer_cb, obj);
250    evas_object_data_set(obj, "test-timer", timer);
251    elm_button_label_set(obj, "Icon tooltip, click to stop changed timed");
252 }
253
254 static Eina_Bool
255 _tt_style_replace_timer_cb(void *data)
256 {
257    static int current = 0;
258    elm_object_tooltip_style_set(data, current ? NULL : "transparent");
259    current = !current;
260    return EINA_TRUE;
261 }
262
263 static void
264 _tt_style_replace_timed(void *data       __UNUSED__,
265                         Evas_Object     *obj,
266                         void *event_info __UNUSED__)
267 {
268    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
269    if (timer)
270      {
271         ecore_timer_del(timer);
272         evas_object_data_del(obj, "test-timer");
273         elm_button_label_set(obj, "Icon tooltip style, click to start"
274                                   " changed timed");
275         return;
276      }
277
278    timer = ecore_timer_add(1.5, _tt_style_replace_timer_cb, obj);
279    evas_object_data_set(obj, "test-timer", timer);
280    elm_button_label_set(obj, "Icon tooltip style, click to stop changed"
281                              " timed");
282 }
283
284 static void
285 _tt_visible_lock_toggle(void *data       __UNUSED__,
286                         Evas_Object     *obj,
287                         void *event_info __UNUSED__)
288 {
289    static int locked = 0;
290
291    locked = !locked;
292    if (locked)
293      {
294         elm_button_label_set(obj, "Locked tooltip visibility");
295         elm_object_tooltip_text_set(obj, "This tooltip is locked"
296                                          " visible,<br> click the button"
297                                          " to unlock!");
298         elm_object_tooltip_show(obj);
299      }
300    else
301      {
302         elm_button_label_set(obj, "Unlocked tooltip visibility");
303         elm_object_tooltip_text_set(obj, "This tooltip is unlocked"
304                                          " visible,<br> click the button"
305                                          " to lock!");
306         elm_object_tooltip_hide(obj);
307      }
308 }
309
310 void
311 test_tooltip(void *data       __UNUSED__,
312              Evas_Object *obj __UNUSED__,
313              void *event_info __UNUSED__)
314 {
315    Evas_Object *win, *bg, *bx, *tb, *bt, *se, *lst;
316    Elm_Toolbar_Item *ti;
317    Elm_List_Item *li;
318
319    win = elm_win_add(NULL, "tooltip", ELM_WIN_BASIC);
320    elm_win_title_set(win, "Tooltip");
321    elm_win_autodel_set(win, 1);
322
323    bg = elm_bg_add(win);
324    elm_win_resize_object_add(win, bg);
325    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
326                                     EVAS_HINT_EXPAND);
327    evas_object_show(bg);
328
329    bx = elm_box_add(win);
330    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
331                                     EVAS_HINT_EXPAND);
332    elm_win_resize_object_add(win, bx);
333    evas_object_show(bx);
334
335    tb = elm_toolbar_add(win);
336    elm_toolbar_homogenous_set(tb, 0);
337    evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0);
338    evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, 0.0);
339    elm_box_pack_end(bx, tb);
340    evas_object_show(tb);
341
342    ti = elm_toolbar_item_append(tb, NULL, "Open", NULL, NULL);
343    elm_toolbar_item_tooltip_text_set(ti, "Opens a file");
344
345    ti = elm_toolbar_item_append(tb, NULL, "Icon", NULL, NULL);
346    elm_toolbar_item_tooltip_content_cb_set
347      (ti, _tt_item_icon, (void *)456L, _tt_item_icon_del);
348    elm_toolbar_item_tooltip_style_set(ti, "transparent");
349
350    bt = elm_button_add(win);
351    elm_button_label_set(bt, "Simple text tooltip");
352    elm_object_tooltip_text_set(bt, "Simple text tooltip");
353    elm_box_pack_end(bx, bt);
354    evas_object_show(bt);
355
356    bt = elm_button_add(win);
357    elm_button_label_set(bt, "Simple text tooltip, click to change");
358    elm_object_tooltip_text_set(bt, "Initial");
359    evas_object_smart_callback_add(bt, "clicked", _tt_text_replace, NULL);
360    elm_box_pack_end(bx, bt);
361    evas_object_show(bt);
362
363    bt = elm_button_add(win);
364    elm_button_label_set(bt, "Simple text tooltip, click to start"
365                             " changed timed");
366    elm_object_tooltip_text_set(bt, "Initial");
367    evas_object_smart_callback_add(bt, "clicked", _tt_text_replace_timed,
368                                   NULL);
369    elm_box_pack_end(bx, bt);
370    evas_object_show(bt);
371    evas_object_event_callback_add(bt, EVAS_CALLBACK_DEL, _tt_timer_del,
372                                   NULL);
373
374    bt = elm_button_add(win);
375    elm_button_label_set(bt, "Icon tooltip");
376    elm_object_tooltip_content_cb_set(bt, _tt_icon, (void *)123L,
377                                      _tt_icon_del);
378    elm_box_pack_end(bx, bt);
379    evas_object_show(bt);
380
381    bt = elm_button_add(win);
382    elm_button_label_set(bt, "Icon tooltip, click to start changed timed");
383    elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
384    evas_object_smart_callback_add(bt, "clicked", _tt_icon_replace_timed,
385                                   NULL);
386    elm_box_pack_end(bx, bt);
387    evas_object_show(bt);
388    evas_object_event_callback_add(bt, EVAS_CALLBACK_DEL, _tt_timer_del,
389                                   NULL);
390
391    bt = elm_button_add(win);
392    elm_button_label_set(bt, "Transparent Icon tooltip");
393    elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
394    elm_object_tooltip_style_set(bt, "transparent");
395    elm_box_pack_end(bx, bt);
396    evas_object_show(bt);
397
398    bt = elm_button_add(win);
399    elm_button_label_set(bt, "Icon tooltip style, click to start changed"
400                             " timed");
401    elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
402    evas_object_smart_callback_add(bt, "clicked", _tt_style_replace_timed,
403                                   NULL);
404    elm_box_pack_end(bx, bt);
405    evas_object_show(bt);
406    evas_object_event_callback_add(bt, EVAS_CALLBACK_DEL, _tt_timer_del,
407                                   NULL);
408
409    bt = elm_button_add(win);
410    elm_button_label_set(bt, "Unlocked tooltip visibility");
411    elm_object_tooltip_text_set(bt, "This tooltip is unlocked visible,<br>"
412                                    " click the button to lock!");
413    evas_object_smart_callback_add(bt, "clicked", _tt_visible_lock_toggle,
414                                   NULL);
415    elm_box_pack_end(bx, bt);
416    evas_object_show(bt);
417
418    se = elm_scrolled_entry_add(win);
419    evas_object_size_hint_weight_set(se, EVAS_HINT_EXPAND, 0.0);
420    evas_object_size_hint_align_set(se, EVAS_HINT_FILL, 0.5);
421    elm_scrolled_entry_scrollbar_policy_set(se, ELM_SCROLLER_POLICY_OFF,
422                                            ELM_SCROLLER_POLICY_OFF);
423    elm_scrolled_entry_entry_set(se, "Hello, some scrolled entry here!");
424    elm_object_tooltip_text_set(se, "Type something here!");
425    elm_scrolled_entry_single_line_set(se, 1);
426    elm_box_pack_end(bx, se);
427    evas_object_show(se);
428
429    lst = elm_list_add(win);
430    li = elm_list_item_append(lst, "Hello", NULL, NULL, NULL, NULL);
431    elm_list_item_tooltip_text_set(li, "Something useful here?");
432    li = elm_list_item_append(lst, "Icon Tooltip", NULL, NULL, NULL, NULL);
433    elm_list_item_tooltip_content_cb_set(li, _tt_item_icon, NULL, NULL);
434    evas_object_size_hint_weight_set(lst, EVAS_HINT_EXPAND,
435                                     EVAS_HINT_EXPAND);
436    evas_object_size_hint_align_set(lst, EVAS_HINT_FILL, EVAS_HINT_FILL);
437    evas_object_size_hint_min_set(lst, 100, 100);
438    elm_list_go(lst);
439    elm_box_pack_end(bx, lst);
440    evas_object_show(lst);
441
442    evas_object_resize(win, 320, 580);
443    evas_object_show(win);
444 }
445
446 void
447 test_tooltip2(void *data       __UNUSED__,
448               Evas_Object *obj __UNUSED__,
449               void *event_info __UNUSED__)
450 {
451    Evas_Object *win, *bg, *bx, *grid, *gl;
452    Elm_Genlist_Item *it1, *it2, *it3;
453    static Testitem ti[144];
454    int i, n;
455    char buf[PATH_MAX];
456    const char *img[9] =
457    {
458       "panel_01.jpg",
459       "plant_01.jpg",
460       "rock_01.jpg",
461       "rock_02.jpg",
462       "sky_01.jpg",
463       "sky_02.jpg",
464       "sky_03.jpg",
465       "sky_04.jpg",
466       "wood_01.jpg",
467    };
468
469    win = elm_win_add(NULL, "tooltip2", ELM_WIN_BASIC);
470    elm_win_title_set(win, "Tooltip 2");
471    elm_win_autodel_set(win, 1);
472
473    bg = elm_bg_add(win);
474    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
475                                     EVAS_HINT_EXPAND);
476    elm_win_resize_object_add(win, bg);
477    evas_object_show(bg);
478
479    bx = elm_box_add(win);
480    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
481                                     EVAS_HINT_EXPAND);
482    elm_win_resize_object_add(win, bx);
483    evas_object_show(bx);
484
485    grid = elm_gengrid_add(win);
486    elm_gengrid_item_size_set(grid, 100, 100);
487    elm_gengrid_horizontal_set(grid, EINA_FALSE);
488    elm_gengrid_multi_select_set(grid, EINA_TRUE);
489    evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
490    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
491                                     EVAS_HINT_EXPAND);
492
493    gic.item_style = "default";
494    gic.func.label_get = grdt_lbl_get;
495    gic.func.icon_get = grdt_icon_get;
496
497    n = 0;
498    for (i = 0; i < 9; i++)
499      {
500         snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR,
501                  img[n]);
502         n++;
503         ti[i].mode = i;
504         ti[i].path = eina_stringshare_add(buf);
505         ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), NULL,
506                                              NULL);
507         if (n % 2)
508           elm_gengrid_item_tooltip_text_set(ti[i].item, "Testing X");
509         else
510           elm_gengrid_item_tooltip_text_set(ti[i].item, "Testing Y");
511         if (!(i % 5))
512           elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
513      }
514
515    elm_box_pack_end(bx, grid);
516    evas_object_show(grid);
517
518    gl = elm_genlist_add(win);
519    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
520    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND,
521                                     EVAS_HINT_EXPAND);
522
523    itct.item_style = "default";
524    itct.func.label_get = gltt_label_get;
525
526    it1 = elm_genlist_item_append(gl, &itct, (void *)1, NULL,
527                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
528    it2 = elm_genlist_item_append(gl, &itct, (void *)2, NULL,
529                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
530    it3 = elm_genlist_item_append(gl, &itct, (void *)3, NULL,
531                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
532
533    elm_genlist_item_tooltip_text_set(it1, "Testing 1");
534    elm_genlist_item_tooltip_text_set(it2, "Testing 2");
535    elm_genlist_item_tooltip_text_set(it3, "Testing 3");
536
537    evas_object_smart_callback_add(gl, "expand,request", gltt_exp_req, gl);
538    evas_object_smart_callback_add(gl, "contract,request", gltt_con_req,
539                                   gl);
540    evas_object_smart_callback_add(gl, "expanded", gltt_exp, gl);
541    evas_object_smart_callback_add(gl, "contracted", gltt_con, gl);
542
543    elm_box_pack_end(bx, gl);
544    evas_object_show(gl);
545
546    evas_object_resize(win, 320, 480);
547    evas_object_show(win);
548 }
549
550 #endif