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