When the separators exist in toolbar and the toolbar shrinks by resizing window,
[framework/uifw/elementary.git] / src / examples / ctxpopup_example_01.c
1 //Compile with:
2 //gcc -o ctxpopup_example_01 ctxpopup_example_01.c -g `pkg-config --cflags --libs elementary`
3
4 #include <Elementary.h>
5
6 static void
7 _ctxpopup_item_cb(void *data, Evas_Object *obj, void *event_info)
8 {
9    printf("ctxpopup item selected: %s\n", elm_object_item_text_get(event_info));
10 }
11
12 Elm_Object_Item *item_new(Evas_Object *ctxpopup, const char * label, const char *icon)
13 {
14    Evas_Object *ic = elm_icon_add(ctxpopup);
15    elm_icon_standard_set(ic, icon);
16    elm_icon_resizable_set(ic, EINA_FALSE, EINA_FALSE);
17    return elm_ctxpopup_item_append(ctxpopup, label, ic, _ctxpopup_item_cb, NULL);
18 }
19
20 static void
21 _list_item_cb(void *data, Evas_Object *obj, void *event_info)
22 {
23    Evas_Object *ctxpopup;
24    Elm_Object_Item *it;
25    Evas_Coord x,y;
26
27    ctxpopup = elm_ctxpopup_add(obj);
28
29    item_new(ctxpopup, "Go to home folder", "home");
30    item_new(ctxpopup, "Save file", "file");
31    item_new(ctxpopup, "Delete file", "delete");
32    it = item_new(ctxpopup, "Navigate to folder", "folder");
33    elm_object_item_disabled_set(it, EINA_TRUE);
34    item_new(ctxpopup, "Edit entry", "edit");
35    it = item_new(ctxpopup, "Set date and time", "clock");
36    elm_object_item_disabled_set(it, EINA_TRUE);
37
38    evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
39    evas_object_size_hint_max_set(ctxpopup, 240, 240);
40    evas_object_move(ctxpopup, x, y);
41    evas_object_show(ctxpopup);
42
43    elm_list_item_selected_set(event_info, EINA_FALSE);
44 }
45
46 static void
47 _list_item_cb2(void *data, Evas_Object *obj, void *event_info)
48 {
49    Evas_Object *ctxpopup;
50    Elm_Object_Item *it;
51    Evas_Coord x,y;
52
53    ctxpopup = elm_ctxpopup_add(obj);
54    elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE);
55
56    item_new(ctxpopup, NULL, "home");
57    item_new(ctxpopup, NULL, "file");
58    item_new(ctxpopup, NULL, "delete");
59    item_new(ctxpopup, NULL, "folder");
60    it = item_new(ctxpopup, NULL, "edit");
61    elm_object_item_disabled_set(it, EINA_TRUE);
62    item_new(ctxpopup, NULL, "clock");
63
64    evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
65    evas_object_size_hint_max_set(ctxpopup, 380, 40);
66    evas_object_move(ctxpopup, x, y);
67    evas_object_show(ctxpopup);
68
69    elm_list_item_selected_set(event_info, EINA_FALSE);
70 }
71
72 EAPI_MAIN int
73 elm_main(int argc, char **argv)
74 {
75    Evas_Object *win, *bg, *list;
76
77    win = elm_win_add(NULL, "Contextual Popup", ELM_WIN_BASIC);
78    elm_win_title_set(win, "Contextual Popup");
79    elm_win_autodel_set(win, EINA_TRUE);
80    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
81    evas_object_resize(win, 400, 400);
82    evas_object_show(win);
83
84    bg = elm_bg_add(win);
85    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
86    elm_win_resize_object_add(win, bg);
87    evas_object_show(bg);
88
89    list = elm_list_add(win);
90    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
91    elm_win_resize_object_add(win, list);
92    elm_list_mode_set(list, ELM_LIST_COMPRESS);
93
94    elm_list_item_append(list, "Ctxpopup with icons and labels", NULL, NULL,
95                         _list_item_cb, NULL);
96    elm_list_item_append(list, "Ctxpopup with icons only", NULL, NULL,
97                         _list_item_cb2, NULL);
98    evas_object_show(list);
99    elm_list_go(list);
100
101    elm_run();
102    elm_shutdown();
103
104    return 0;
105 }
106 ELM_MAIN()