[JungWooHyun] doing merge job ~
[framework/uifw/elementary.git] / src / examples / popup_example_03.c
1 //Compile with:
2 //gcc -g `pkg-config --cflags --libs elementary` popup_example_03.c -o popup_example_03
3
4 #include <Elementary.h>
5 #ifdef HAVE_CONFIG_H
6 # include "elementary_config.h"
7 #else
8 # define __UNUSED__ __attribute__((unused))
9 # define PACKAGE_DATA_DIR "../../data"
10 #endif
11
12 static void _item_selected_cb(void *data, Evas_Object *obj, void *event_info);
13 static void _response_cb(void *data, Evas_Object *obj, void *event_info);
14
15 EAPI_MAIN int
16 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
17 {
18    Evas_Object *win, *bg, *popup, *btn1, *btn2, *icon1;
19    Elm_Object_Item *popup_it1;
20    char buf[256];
21
22    win = elm_win_add(NULL, "popup", ELM_WIN_BASIC);
23    elm_win_title_set(win, "Popup");
24    elm_win_autodel_set(win, EINA_TRUE);
25    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
26
27    bg = elm_bg_add(win);
28    elm_win_resize_object_add(win, bg);
29    evas_object_show(bg);
30
31    popup = elm_popup_add(win);
32
33    icon1 = elm_icon_add(popup);
34    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
35    elm_icon_file_set(icon1, buf, NULL);
36
37    //Seting popup title-text
38    elm_object_part_text_set(popup, "title,text", "Title");
39
40    //Appending popup content-items
41    elm_popup_item_append(popup, "Message", NULL, _item_selected_cb, NULL);
42    elm_popup_item_append(popup, "Email", NULL, _item_selected_cb, NULL);
43    elm_popup_item_append(popup, "Contacts", NULL, _item_selected_cb, NULL);
44    elm_popup_item_append(popup, "Video", NULL, _item_selected_cb, NULL);
45    elm_popup_item_append(popup, "Music", NULL, _item_selected_cb, NULL);
46    elm_popup_item_append(popup, "Memo", NULL, _item_selected_cb, NULL);
47    popup_it1 = elm_popup_item_append(popup, "Radio", NULL, _item_selected_cb,
48                                      NULL);
49
50    //Changing the label of the item
51    elm_object_item_text_set(popup_it1, "FM");
52    elm_popup_item_append(popup, "Messenger", NULL, _item_selected_cb, NULL);
53    elm_popup_item_append(popup, "Settings", NULL, _item_selected_cb, NULL);
54    elm_popup_item_append(popup, "App Installer", NULL, _item_selected_cb, NULL);
55    elm_popup_item_append(popup, "Browser", NULL, _item_selected_cb, NULL);
56    elm_popup_item_append(popup, "Weather", icon1, _item_selected_cb, NULL);
57    elm_popup_item_append(popup, "News Feeds", NULL, _item_selected_cb, NULL);
58
59    //Seting popup title-text
60    elm_object_part_text_set(popup, "title,text", "Title");
61
62    // Creating the first action button
63    btn1 = elm_button_add(popup);
64    elm_object_text_set(btn1, "OK");
65
66    //Appending the fist action button
67    elm_object_part_content_set(popup, "button1", btn1);
68    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
69
70    //Creating the second action button
71    btn2 = elm_button_add(popup);
72    elm_object_text_set(btn2, "Cancel");
73    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
74
75    //Appending the second action button
76    elm_object_part_content_set(popup, "button1", btn2);
77
78    //Display the popup object
79    evas_object_show(popup);
80
81    evas_object_resize(win, 480, 800);
82    evas_object_show(win);
83
84    elm_run();
85
86    return 0;
87 }
88 ELM_MAIN()
89
90 static void
91 _item_selected_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
92                   void *event_info)
93 {
94    printf("popup item selected: %s\n", elm_object_item_text_get(event_info));
95 }
96
97 static void
98 _response_cb(void *data, Evas_Object *obj __UNUSED__,
99              void *event_info __UNUSED__)
100 {
101    evas_object_hide(data);
102 }