Initialize Tizen 2.3
[framework/uifw/elementary.git] / mobile / 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_image_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_move(ctxpopup, x, y);
40    evas_object_show(ctxpopup);
41
42    elm_list_item_selected_set(event_info, EINA_FALSE);
43 }
44
45 static void
46 _list_item_cb2(void *data, Evas_Object *obj, void *event_info)
47 {
48    Evas_Object *ctxpopup;
49    Elm_Object_Item *it;
50    Evas_Coord x,y;
51
52    ctxpopup = elm_ctxpopup_add(obj);
53    elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE);
54
55    item_new(ctxpopup, NULL, "home");
56    item_new(ctxpopup, NULL, "file");
57    item_new(ctxpopup, NULL, "delete");
58    item_new(ctxpopup, NULL, "folder");
59    it = item_new(ctxpopup, NULL, "edit");
60    elm_object_item_disabled_set(it, EINA_TRUE);
61    item_new(ctxpopup, NULL, "clock");
62
63    evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
64    evas_object_move(ctxpopup, x, y);
65    evas_object_show(ctxpopup);
66
67    elm_list_item_selected_set(event_info, EINA_FALSE);
68 }
69
70 EAPI_MAIN int
71 elm_main(int argc, char **argv)
72 {
73    Evas_Object *win, *bg, *list;
74
75    win = elm_win_add(NULL, "Contextual Popup", ELM_WIN_BASIC);
76    elm_win_title_set(win, "Contextual Popup");
77    elm_win_autodel_set(win, EINA_TRUE);
78    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
79    evas_object_resize(win, 400, 400);
80    evas_object_show(win);
81
82    bg = elm_bg_add(win);
83    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
84    elm_win_resize_object_add(win, bg);
85    evas_object_show(bg);
86
87    list = elm_list_add(win);
88    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
89    elm_win_resize_object_add(win, list);
90    elm_list_mode_set(list, ELM_LIST_COMPRESS);
91
92    elm_list_item_append(list, "Ctxpopup with icons and labels", NULL, NULL,
93                         _list_item_cb, NULL);
94    elm_list_item_append(list, "Ctxpopup with icons only", NULL, NULL,
95                         _list_item_cb2, NULL);
96    evas_object_show(list);
97    elm_list_go(list);
98
99    elm_run();
100    elm_shutdown();
101
102    return 0;
103 }
104 ELM_MAIN()