elm examples: Use standard way of elementary applications. EAPI_MAIN, elm_shutdown...
[framework/uifw/elementary.git] / src / examples / popup_example_02.c
1 //Compile with:
2 //gcc -o popup_example_02 popup_example_02.c -g `pkg-config --cflags --libs elementary`
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 _response_cb(void *data, Evas_Object *obj, void *event_info);
13
14 EAPI_MAIN int
15 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
16 {
17    Evas_Object *win, *bg, *popup, *btn1, *btn2, *btn3, *icon1;
18    char buf[256];
19
20    win = elm_win_add(NULL, "popup", ELM_WIN_BASIC);
21    elm_win_title_set(win, "Popup");
22    elm_win_autodel_set(win, EINA_TRUE);
23    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
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    popup = elm_popup_add(win);
31
32    // Setting popup content-text
33    elm_object_text_set(popup, "This is the Content-Text for popup. The wrap"
34             "for the content-text is character wrapping");
35    // Setting the wrapping type to character wrapping
36    elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
37
38    // Seting popup title-text
39    elm_object_part_text_set(popup, "title,text", "Title");
40
41    icon1 = elm_icon_add(popup);
42    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
43    elm_icon_file_set(icon1, buf, NULL);
44    //Setting popup title-icon
45    elm_object_part_content_set(popup, "title,icon", icon1);
46
47    // Creating the first action button
48    btn1 = elm_button_add(popup);
49    elm_object_text_set(btn1, "OK");
50
51    // Setting the fist action button
52    elm_object_part_content_set(popup, "button1", btn1);
53    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
54
55    // Creating the second action button
56    btn2 = elm_button_add(popup);
57    elm_object_text_set(btn2, "Cancel");
58
59    // Setting the second action button
60    elm_object_part_content_set(popup, "button2", btn2);
61    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
62
63    btn3 = elm_button_add(popup);
64    elm_object_text_set(btn3, "Close");
65    // Setting this action button
66    elm_object_part_content_set(popup, "button3", btn3);
67    // Setting the orientation of popup to Top
68    elm_popup_orient_set(popup, ELM_POPUP_ORIENT_TOP);
69    // Display the popup object
70    evas_object_show(popup);
71
72    evas_object_resize(win, 480, 800);
73    evas_object_show(win);
74
75    elm_run();
76    elm_shutdown();
77
78    return 0;
79 }
80 ELM_MAIN()
81
82 static void
83 _response_cb(void *data, Evas_Object *obj __UNUSED__,
84              void *event_info __UNUSED__)
85 {
86    evas_object_del(data);
87 }
88