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