The elm_toolbar_iteams_count have to return only the number of manually added items.
[framework/uifw/elementary.git] / src / examples / hoversel_example_01.c
1 //Compile with:
2 //gcc -o hoversel_example_01 hoversel_example_01.c -g `pkg-config --cflags --libs elementary`
3
4 #include <Elementary.h>
5
6 static void _print_items(void *data, Evas_Object *obj, void *event_info);
7 static void _rm_items(void *data, Evas_Object *obj, void *event_info);
8 static void _sel(void *data, Evas_Object *obj, void *event_info);
9 static void _free(void *data, Evas_Object *obj, void *event_info);
10 static void _add_item(void *data, Evas_Object *obj, void *event_info);
11
12 EAPI_MAIN int
13 elm_main(int argc, char **argv)
14 {
15    Evas_Object *win, *bg, *rect, *hoversel;
16    Elm_Object_Item *hoversel_it;
17
18    win = elm_win_add(NULL, "hoversel", ELM_WIN_BASIC);
19    elm_win_title_set(win, "Hoversel");
20    elm_win_autodel_set(win, EINA_TRUE);
21    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
22    evas_object_resize(win, 200, 300);
23    evas_object_show(win);
24
25    bg = elm_bg_add(win);
26    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
27    elm_win_resize_object_add(win, bg);
28    evas_object_show(bg);
29
30    rect = evas_object_rectangle_add(evas_object_evas_get(win));
31    evas_object_color_set(rect, 255, 0, 0, 255);
32    evas_object_show(rect);
33
34    hoversel = elm_hoversel_add(win);
35    elm_hoversel_hover_parent_set(hoversel, win);
36    elm_hoversel_horizontal_set(hoversel, EINA_FALSE);
37    elm_object_text_set(hoversel, "Hoversel");
38    elm_object_part_content_set(hoversel, "icon", rect);
39    elm_hoversel_item_add(hoversel, "Print items", NULL, ELM_ICON_NONE,
40                          _print_items, NULL);
41    elm_hoversel_item_add(hoversel, "Option 2", "home", ELM_ICON_STANDARD, NULL,
42                          NULL);
43    hoversel_it = elm_hoversel_item_add(hoversel, "Clear all items", "close",
44                                        ELM_ICON_STANDARD, _rm_items, NULL);
45    evas_object_smart_callback_add(hoversel, "selected", _sel, hoversel_it);
46    evas_object_smart_callback_add(hoversel, "clicked", _add_item, NULL);
47
48    evas_object_resize(hoversel, 180, 30);
49    evas_object_move(hoversel, 10, 10);
50    evas_object_show(hoversel);
51
52
53    elm_run();
54    elm_shutdown();
55
56    return 0;
57 }
58 ELM_MAIN()
59
60 static void
61 _print_items(void *data, Evas_Object *obj, void *event_info)
62 {
63    const Eina_List *items = elm_hoversel_items_get(obj);
64    const Eina_List *l;
65    Elm_Object_Item *hoversel_it;
66
67    EINA_LIST_FOREACH(items, l, hoversel_it)
68      printf("%s\n", elm_object_item_text_get(hoversel_it));
69 }
70
71 static void
72 _rm_items(void *data, Evas_Object *obj, void *event_info)
73 {
74    if (!elm_hoversel_expanded_get(obj))
75      elm_hoversel_clear(obj);
76 }
77
78 static void
79 _sel(void *data, Evas_Object *obj, void *event_info)
80 {
81    if (!elm_hoversel_expanded_get(obj) && event_info != data)
82      elm_object_item_del(event_info);
83 }
84
85 static void
86 _add_item(void *data, Evas_Object *obj, void *event_info)
87 {
88    static int num = 0;
89    char *str = malloc(sizeof(char) * 10);
90    Elm_Object_Item *hoversel_it;
91
92    snprintf(str, 10, "item %d", ++num);
93
94    hoversel_it = elm_hoversel_item_add(obj, str, NULL, ELM_ICON_NONE, NULL,
95                                        str);
96    elm_object_item_del_cb_set(hoversel_it, _free);
97 }
98
99 static void
100 _free(void *data, Evas_Object *obj, void *event_info)
101 {
102    free(data);
103 }