revert to the migration tempoary
[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_content_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 __UNUSED__,
112               Evas_Object *tt,
113               void *item   __UNUSED__)
114 {
115    Evas_Object *ic = elm_icon_add(tt);
116    char buf[PATH_MAX];
117    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
118             elm_app_data_dir_get());
119    elm_icon_file_set(ic, buf, NULL);
120    elm_icon_scale_set(ic, 0, 0);
121    evas_object_resize(ic, 64, 64);
122    return ic;
123 }
124
125 static Evas_Object *
126 _tt_item_icon2(void *data   __UNUSED__,
127               Evas_Object *obj __UNUSED__,
128               Evas_Object *tt,
129               void *item   __UNUSED__)
130 {
131    Evas_Object *ic = elm_icon_add(tt);
132    char buf[PATH_MAX];
133    snprintf(buf, sizeof(buf), "%s/images/logo.png", elm_app_data_dir_get());
134    elm_icon_file_set(ic, buf, NULL);
135    elm_icon_scale_set(ic, 0, 0);
136    return ic;
137 }
138
139 static Evas_Object *
140 _tt_item_icon3(void *data   __UNUSED__,
141               Evas_Object *obj __UNUSED__,
142               Evas_Object *tt,
143               void *item   __UNUSED__)
144 {
145    Evas_Object *ic = elm_icon_add(tt);
146    char buf[PATH_MAX];
147    snprintf(buf, sizeof(buf), "%s/images/insanely_huge_test_image.jpg", elm_app_data_dir_get());
148    elm_icon_file_set(ic, buf, NULL);
149    elm_icon_scale_set(ic, 0, 0);
150    return ic;
151 }
152
153 static Evas_Object *
154 _tt_item_label(void *data   __UNUSED__,
155               Evas_Object *obj __UNUSED__,
156               Evas_Object *tt,
157               void *item   __UNUSED__)
158 {
159    Evas_Object *l = elm_label_add(tt);
160    elm_object_text_set(l, "Something useful here?<ps>"
161                           "No probably not, but this is a super long label<ps>"
162                           "which probably breaks on your system, now doesn't it?<ps>"
163                           "Yeah, I thought so.");
164    elm_label_line_wrap_set(l, ELM_WRAP_MIXED);
165    return l;
166 }
167
168 static void
169 _tt_item_icon_del(void            *data,
170                   Evas_Object *obj __UNUSED__,
171                   void            *event_info)
172 {
173    // test to check for del_cb behavior!
174    printf("_tt_icon_del: data=%ld (== 456?), event_info=%p\n",
175           (long)data, event_info);
176 }
177
178 static void
179 _tt_text_replace(void *data       __UNUSED__,
180                  Evas_Object     *obj,
181                  void *event_info __UNUSED__)
182 {
183    static int count = 0;
184    char buf[64];
185    snprintf(buf, sizeof(buf), "count=%d", count);
186    count++;
187    elm_object_tooltip_text_set(obj, buf);
188 }
189
190 static void
191 _tt_timer_del(void *data       __UNUSED__,
192               Evas *e          __UNUSED__,
193               Evas_Object     *obj,
194               void *event_info __UNUSED__)
195 {
196    Ecore_Timer *timer = evas_object_data_del(obj, "test-timer");
197    if (!timer) return;
198    ecore_timer_del(timer);
199 }
200
201 static Eina_Bool
202 _tt_text_replace_timer_cb(void *data)
203 {
204    _tt_text_replace(NULL, data, NULL);
205    return EINA_TRUE;
206 }
207
208 static void
209 _tt_text_replace_timed(void *data       __UNUSED__,
210                        Evas_Object     *obj,
211                        void *event_info __UNUSED__)
212 {
213    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
214    if (timer)
215      {
216         ecore_timer_del(timer);
217         evas_object_data_del(obj, "test-timer");
218         elm_object_text_set(obj, "Simple text tooltip, click to start"
219                                   " changed timed");
220         return;
221      }
222
223    timer = ecore_timer_add(1.5, _tt_text_replace_timer_cb, obj);
224    evas_object_data_set(obj, "test-timer", timer);
225    elm_object_text_set(obj, "Simple text tooltip, click to stop changed"
226                              " timed");
227 }
228
229 static Evas_Object *
230 _tt_icon(void *data   __UNUSED__,
231          Evas_Object *obj __UNUSED__,
232          Evas_Object *tt)
233 {
234    Evas_Object *ic = elm_icon_add(tt);
235    char buf[PATH_MAX];
236    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
237             elm_app_data_dir_get());
238    elm_icon_file_set(ic, buf, NULL);
239    elm_icon_scale_set(ic, 0, 0);
240    evas_object_resize(ic, 64, 64);
241    return ic;
242 }
243
244 static Evas_Object *
245 _tt_icon2(void *data   __UNUSED__,
246           Evas_Object *obj __UNUSED__,
247           Evas_Object *tt)
248 {
249    Evas_Object *ic = elm_icon_add(tt);
250    char buf[PATH_MAX];
251    snprintf(buf, sizeof(buf), "%s/images/icon_00.png", elm_app_data_dir_get());
252    elm_icon_file_set(ic, buf, NULL);
253    elm_icon_scale_set(ic, 0, 0);
254    evas_object_resize(ic, 64, 64);
255    return ic;
256 }
257
258 static void
259 _tt_icon_del(void            *data,
260              Evas_Object *obj __UNUSED__,
261              void            *event_info)
262 {
263    // test to check for del_cb behavior!
264    printf("_tt_icon_del: data=%ld (== 123?), event_info=%p\n",
265           (long)data, event_info);
266 }
267
268 static Eina_Bool
269 _tt_icon_replace_timer_cb(void *data)
270 {
271    static int current = 0;
272
273    elm_object_tooltip_content_cb_set
274      (data, current ? _tt_icon2 : _tt_icon, NULL, NULL);
275
276    current = !current;
277    return EINA_TRUE;
278 }
279
280 static void
281 _tt_icon_replace_timed(void *data       __UNUSED__,
282                        Evas_Object     *obj,
283                        void *event_info __UNUSED__)
284 {
285    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
286    if (timer)
287      {
288         ecore_timer_del(timer);
289         evas_object_data_del(obj, "test-timer");
290         elm_object_text_set(obj, "Icon tooltip, click to start changed"
291                                   " timed");
292         return;
293      }
294
295    timer = ecore_timer_add(1.5, _tt_icon_replace_timer_cb, obj);
296    evas_object_data_set(obj, "test-timer", timer);
297    elm_object_text_set(obj, "Icon tooltip, click to stop changed timed");
298 }
299
300 static Eina_Bool
301 _tt_style_replace_timer_cb(void *data)
302 {
303    static int current = 0;
304    elm_object_tooltip_style_set(data, current ? NULL : "transparent");
305    current = !current;
306    return EINA_TRUE;
307 }
308
309 static void
310 _tt_style_replace_timed(void *data       __UNUSED__,
311                         Evas_Object     *obj,
312                         void *event_info __UNUSED__)
313 {
314    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
315    if (timer)
316      {
317         ecore_timer_del(timer);
318         evas_object_data_del(obj, "test-timer");
319         elm_object_text_set(obj, "Icon tooltip style, click to start"
320                                   " changed timed");
321         return;
322      }
323
324    timer = ecore_timer_add(1.5, _tt_style_replace_timer_cb, obj);
325    evas_object_data_set(obj, "test-timer", timer);
326    elm_object_text_set(obj, "Icon tooltip style, click to stop changed"
327                              " timed");
328 }
329
330 static void
331 _tt_visible_lock_toggle(void *data       __UNUSED__,
332                         Evas_Object     *obj,
333                         void *event_info __UNUSED__)
334 {
335    static int locked = 0;
336
337    locked = !locked;
338    if (locked)
339      {
340         elm_object_text_set(obj, "Locked tooltip visibility");
341         elm_object_tooltip_text_set(obj, "This tooltip is locked"
342                                          " visible,<br> click the button"
343                                          " to unlock!");
344         elm_object_tooltip_show(obj);
345      }
346    else
347      {
348         elm_object_text_set(obj, "Unlocked tooltip visibility");
349         elm_object_tooltip_text_set(obj, "This tooltip is unlocked"
350                                          " visible,<br> click the button"
351                                          " to lock!");
352         elm_object_tooltip_hide(obj);
353      }
354 }
355
356 void
357 test_tooltip(void *data       __UNUSED__,
358              Evas_Object *obj __UNUSED__,
359              void *event_info __UNUSED__)
360 {
361    Evas_Object *win, *bg, *bx, *tb, *bt, *se, *lst;
362    Elm_Toolbar_Item *ti;
363    Elm_List_Item *li;
364
365    win = elm_win_add(NULL, "tooltip", ELM_WIN_BASIC);
366    elm_win_title_set(win, "Tooltip");
367    elm_win_autodel_set(win, EINA_TRUE);
368
369    bg = elm_bg_add(win);
370    elm_win_resize_object_add(win, bg);
371    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
372                                     EVAS_HINT_EXPAND);
373    evas_object_show(bg);
374
375    bx = elm_box_add(win);
376    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
377                                     EVAS_HINT_EXPAND);
378    elm_win_resize_object_add(win, bx);
379    evas_object_show(bx);
380
381    tb = elm_toolbar_add(win);
382    elm_toolbar_homogeneous_set(tb, 0);
383    evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0);
384    evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, 0.0);
385    elm_box_pack_end(bx, tb);
386    evas_object_show(tb);
387
388    ti = elm_toolbar_item_append(tb, NULL, "Open", NULL, NULL);
389    elm_toolbar_item_tooltip_text_set(ti, "Opens a file");
390
391    ti = elm_toolbar_item_append(tb, NULL, "Icon", NULL, NULL);
392    elm_toolbar_item_tooltip_content_cb_set
393      (ti, _tt_item_icon, (void *)456L, _tt_item_icon_del);
394    elm_toolbar_item_tooltip_style_set(ti, "transparent");
395
396    bt = elm_button_add(win);
397    elm_object_text_set(bt, "Simple text tooltip");
398    elm_object_tooltip_text_set(bt, "Simple text tooltip");
399    elm_box_pack_end(bx, bt);
400    evas_object_show(bt);
401
402    bt = elm_button_add(win);
403    elm_object_text_set(bt, "Simple text tooltip, click to change");
404    elm_object_tooltip_text_set(bt, "Initial");
405    evas_object_smart_callback_add(bt, "clicked", _tt_text_replace, NULL);
406    elm_box_pack_end(bx, bt);
407    evas_object_show(bt);
408
409    bt = elm_button_add(win);
410    elm_object_text_set(bt, "Simple text tooltip, click to start"
411                             " changed timed");
412    elm_object_tooltip_text_set(bt, "Initial");
413    evas_object_smart_callback_add(bt, "clicked", _tt_text_replace_timed,
414                                   NULL);
415    elm_box_pack_end(bx, bt);
416    evas_object_show(bt);
417    evas_object_event_callback_add(bt, EVAS_CALLBACK_DEL, _tt_timer_del,
418                                   NULL);
419
420    bt = elm_button_add(win);
421    elm_object_text_set(bt, "Icon tooltip");
422    elm_object_tooltip_content_cb_set(bt, _tt_icon, (void *)123L,
423                                      _tt_icon_del);
424    elm_box_pack_end(bx, bt);
425    evas_object_show(bt);
426
427    bt = elm_button_add(win);
428    elm_object_text_set(bt, "Icon tooltip, click to start changed timed");
429    elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
430    evas_object_smart_callback_add(bt, "clicked", _tt_icon_replace_timed,
431                                   NULL);
432    elm_box_pack_end(bx, bt);
433    evas_object_show(bt);
434    evas_object_event_callback_add(bt, EVAS_CALLBACK_DEL, _tt_timer_del,
435                                   NULL);
436
437    bt = elm_button_add(win);
438    elm_object_text_set(bt, "Transparent Icon tooltip");
439    elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
440    elm_object_tooltip_style_set(bt, "transparent");
441    elm_box_pack_end(bx, bt);
442    evas_object_show(bt);
443
444    bt = elm_button_add(win);
445    elm_object_text_set(bt, "Icon tooltip style, click to start changed"
446                             " timed");
447    elm_object_tooltip_content_cb_set(bt, _tt_icon, NULL, NULL);
448    evas_object_smart_callback_add(bt, "clicked", _tt_style_replace_timed,
449                                   NULL);
450    elm_box_pack_end(bx, bt);
451    evas_object_show(bt);
452    evas_object_event_callback_add(bt, EVAS_CALLBACK_DEL, _tt_timer_del,
453                                   NULL);
454
455    bt = elm_button_add(win);
456    elm_object_text_set(bt, "Unlocked tooltip visibility");
457    elm_object_tooltip_text_set(bt, "This tooltip is unlocked visible,<br>"
458                                    " click the button to lock!");
459    evas_object_smart_callback_add(bt, "clicked", _tt_visible_lock_toggle,
460                                   NULL);
461    elm_box_pack_end(bx, bt);
462    evas_object_show(bt);
463
464    se = elm_entry_add(win);
465    elm_entry_scrollable_set(se, EINA_TRUE);
466    evas_object_size_hint_weight_set(se, EVAS_HINT_EXPAND, 0.0);
467    evas_object_size_hint_align_set(se, EVAS_HINT_FILL, 0.5);
468    elm_entry_scrollbar_policy_set(se, ELM_SCROLLER_POLICY_OFF,
469                                            ELM_SCROLLER_POLICY_OFF);
470    elm_entry_entry_set(se, "Hello, some scrolled entry here!");
471    elm_object_tooltip_text_set(se, "Type something here!");
472    elm_entry_single_line_set(se, 1);
473    elm_box_pack_end(bx, se);
474    evas_object_show(se);
475
476    lst = elm_list_add(win);
477    li = elm_list_item_append(lst, "Hello", NULL, NULL, NULL, NULL);
478    elm_list_item_tooltip_text_set(li, "Something useful here?");
479    li = elm_list_item_append(lst, "Icon Tooltip", NULL, NULL, NULL, NULL);
480    elm_list_item_tooltip_content_cb_set(li, _tt_item_icon, NULL, NULL);
481    li = elm_list_item_append(lst, "Big Icon Tooltip", NULL, NULL, NULL, NULL);
482    elm_list_item_tooltip_content_cb_set(li, _tt_item_icon2, NULL, NULL);
483    elm_list_item_tooltip_size_restrict_disable(li, EINA_TRUE);
484    evas_object_size_hint_weight_set(lst, EVAS_HINT_EXPAND,
485                                     EVAS_HINT_EXPAND);
486    evas_object_size_hint_align_set(lst, EVAS_HINT_FILL, EVAS_HINT_FILL);
487    evas_object_size_hint_min_set(lst, 100, 100);
488    elm_list_go(lst);
489    elm_box_pack_end(bx, lst);
490    evas_object_show(lst);
491
492    evas_object_resize(win, 320, 580);
493    evas_object_show(win);
494 }
495
496 void
497 test_tooltip2(void *data       __UNUSED__,
498               Evas_Object *obj __UNUSED__,
499               void *event_info __UNUSED__)
500 {
501    Evas_Object *win, *bg, *bx, *grid, *gl;
502    Elm_Genlist_Item *it1, *it2, *it3;
503    static Testitem ti[144];
504    int i, n;
505    char buf[PATH_MAX];
506    const char *img[9] =
507    {
508       "panel_01.jpg",
509       "plant_01.jpg",
510       "rock_01.jpg",
511       "rock_02.jpg",
512       "sky_01.jpg",
513       "sky_02.jpg",
514       "sky_03.jpg",
515       "sky_04.jpg",
516       "wood_01.jpg",
517    };
518
519    win = elm_win_add(NULL, "tooltip2", ELM_WIN_BASIC);
520    elm_win_title_set(win, "Tooltip 2");
521    elm_win_autodel_set(win, EINA_TRUE);
522
523    bg = elm_bg_add(win);
524    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
525                                     EVAS_HINT_EXPAND);
526    elm_win_resize_object_add(win, bg);
527    evas_object_show(bg);
528
529    bx = elm_box_add(win);
530    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND,
531                                     EVAS_HINT_EXPAND);
532    elm_win_resize_object_add(win, bx);
533    evas_object_show(bx);
534
535    grid = elm_gengrid_add(win);
536    elm_gengrid_item_size_set(grid, 100, 100);
537    elm_gengrid_horizontal_set(grid, EINA_FALSE);
538    elm_gengrid_multi_select_set(grid, EINA_TRUE);
539    evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
540    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
541                                     EVAS_HINT_EXPAND);
542
543    gic.item_style = "default";
544    gic.func.label_get = grdt_lbl_get;
545    gic.func.content_get = grdt_content_get;
546
547    n = 0;
548    for (i = 0; i < 9; i++)
549      {
550         snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(),
551                  img[n]);
552         n++;
553         ti[i].mode = i;
554         ti[i].path = eina_stringshare_add(buf);
555         ti[i].item = elm_gengrid_item_append(grid, &gic, &(ti[i]), NULL,
556                                              NULL);
557         if (n % 2)
558           elm_gengrid_item_tooltip_text_set(ti[i].item, "Testing X");
559         else
560           elm_gengrid_item_tooltip_text_set(ti[i].item, "Testing Y");
561         if (!(i % 5))
562           elm_gengrid_item_selected_set(ti[i].item, EINA_TRUE);
563      }
564
565    elm_box_pack_end(bx, grid);
566    evas_object_show(grid);
567
568    gl = elm_genlist_add(win);
569    evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
570    evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND,
571                                     EVAS_HINT_EXPAND);
572
573    itct.item_style = "default";
574    itct.func.label_get = gltt_label_get;
575
576    it1 = elm_genlist_item_append(gl, &itct, (void *)1, NULL,
577                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
578    it2 = elm_genlist_item_append(gl, &itct, (void *)2, NULL,
579                                  ELM_GENLIST_ITEM_SUBITEMS, NULL, NULL);
580    it3 = elm_genlist_item_append(gl, &itct, (void *)3, NULL,
581                                  ELM_GENLIST_ITEM_NONE, NULL, NULL);
582
583    elm_genlist_item_tooltip_text_set(it1, "Testing 1");
584    elm_genlist_item_tooltip_text_set(it2, "Testing 2");
585    elm_genlist_item_tooltip_text_set(it3, "Testing 3");
586
587    evas_object_smart_callback_add(gl, "expand,request", gltt_exp_req, gl);
588    evas_object_smart_callback_add(gl, "contract,request", gltt_con_req,
589                                   gl);
590    evas_object_smart_callback_add(gl, "expanded", gltt_exp, gl);
591    evas_object_smart_callback_add(gl, "contracted", gltt_con, gl);
592
593    elm_box_pack_end(bx, gl);
594    evas_object_show(gl);
595
596    evas_object_resize(win, 320, 480);
597    evas_object_show(win);
598 }
599
600 #endif