tizen 2.3 release
[framework/uifw/elementary.git] / src / examples / inwin_example.c
1 /*
2  * gcc -o inwin_example inwin_example.c `pkg-config --cflags --libs elementary`
3  */
4 #include <Elementary.h>
5
6 static Evas_Object *inwin = NULL;
7 static const char *styles[] = {
8      "default",
9      "minimal",
10      "minimal_vertical"
11 };
12 static int current_style = 0;
13
14 static void
15 _inwin_hide(void *data, Evas_Object *obj, void *event)
16 {
17    if (inwin)
18      {
19         evas_object_hide(inwin);
20         return;
21      }
22    elm_object_text_set(obj, "No inwin!");
23    elm_object_disabled_set(obj, EINA_TRUE);
24 }
25
26 static void
27 _inwin_destroy(void *data, Evas_Object *obj, void *event)
28 {
29    if (inwin)
30      {
31         evas_object_del(inwin);
32         inwin = NULL;
33         return;
34      }
35    elm_object_text_set(obj, "No inwin!");
36    elm_object_disabled_set(obj, EINA_TRUE);
37 }
38
39 static void
40 _btn_click_cb(void *data, Evas_Object *obj, void *event)
41 {
42    Evas_Object *o, *parent;
43
44    if (inwin)
45      {
46         elm_win_inwin_activate(inwin);
47         return;
48      }
49
50    parent = elm_object_top_widget_get(obj);
51    inwin = elm_win_inwin_add(parent);
52    elm_object_style_set(inwin, styles[current_style]);
53    evas_object_show(inwin);
54
55    current_style = (current_style + 1) % 3;
56
57    o = elm_box_add(parent);
58    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
59    evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
60    elm_win_inwin_content_set(inwin, o);
61    evas_object_show(o);
62
63    o = elm_label_add(parent);
64    elm_object_text_set(o, "Click on the first button to hide the Inwin.<ps>"
65                        "Second to destroy it<ps>");
66    evas_object_show(o);
67
68    elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
69
70    o = elm_button_add(parent);
71    elm_object_text_set(o, "Hide");
72    evas_object_show(o);
73
74    evas_object_smart_callback_add(o, "clicked", _inwin_hide, NULL);
75
76    elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
77
78    o = elm_button_add(parent);
79    elm_object_text_set(o, "Destroy");
80    evas_object_show(o);
81
82    evas_object_smart_callback_add(o, "clicked", _inwin_destroy, NULL);
83
84    elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
85 }
86
87 static void
88 _win_del_cb(void *data, Evas_Object *obj, void *event)
89 {
90    if (inwin)
91      {
92         Evas_Object *hover, *o = elm_win_inwin_content_unset(inwin);
93         evas_object_del(inwin);
94         inwin = NULL;
95         hover = elm_hover_add(obj);
96         elm_hover_target_set(hover, obj);
97         elm_object_part_content_set(hover, "middle", o);
98         evas_object_show(hover);
99         return;
100      }
101    evas_object_del(obj);
102 }
103
104 static Eina_Bool
105 _screenshot_hack_cb(void *data)
106 {
107    _btn_click_cb(NULL, data, NULL);
108    return EINA_FALSE;
109 }
110
111 EAPI_MAIN int
112 elm_main(int argc, char *argv[])
113 {
114    Evas_Object *win, *bg, *box, *o;
115
116    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
117
118    win = elm_win_add(NULL, "inwin-example", ELM_WIN_BASIC);
119    elm_win_title_set(win, "Inwin Example");
120    evas_object_resize(win, 400, 400);
121    evas_object_show(win);
122
123    evas_object_smart_callback_add(win, "delete,request", _win_del_cb, NULL);
124
125    bg = elm_bg_add(win);
126    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
127    elm_win_resize_object_add(win, bg);
128    evas_object_show(bg);
129
130    box = elm_box_add(win);
131    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132    elm_win_resize_object_add(win, box);
133    evas_object_show(box);
134
135    o = elm_button_add(win);
136    elm_object_text_set(o, "Inwin!");
137    evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
138    evas_object_size_hint_align_set(o, 0.0, 0.0);
139    elm_box_pack_end(box, o);
140    evas_object_show(o);
141
142    evas_object_smart_callback_add(o, "clicked", _btn_click_cb, NULL);
143
144    if (!strncmp(elm_config_engine_get(), "shot", 4))
145      ecore_timer_add(0.1, _screenshot_hack_cb, o);
146
147    elm_run();
148    elm_shutdown();
149
150    return 0;
151 }
152 ELM_MAIN()