diff options
author | David Walter Seikel | 2012-04-22 09:20:32 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:20:32 +1000 |
commit | 3ad3455551be0d7859ecb02290376206d5e66498 (patch) | |
tree | 497917e12b4d7f458dff9765d9b53f64c4e03fc3 /libraries/elementary/src/examples/win_example.c | |
parent | Update EFL to latest beta. (diff) | |
download | SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.zip SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.gz SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.bz2 SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.xz |
And actually include new files, plus elementary libraries.
Diffstat (limited to 'libraries/elementary/src/examples/win_example.c')
-rw-r--r-- | libraries/elementary/src/examples/win_example.c | 327 |
1 files changed, 327 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/win_example.c b/libraries/elementary/src/examples/win_example.c new file mode 100644 index 0000000..87e985d --- /dev/null +++ b/libraries/elementary/src/examples/win_example.c | |||
@@ -0,0 +1,327 @@ | |||
1 | /* | ||
2 | * gcc -o win_example win_example.c `pkg-config --cflags --libs elementary ecore-x` | ||
3 | */ | ||
4 | #ifdef HAVE_ELEMENTARY_X | ||
5 | # include <Ecore_X.h> | ||
6 | #endif | ||
7 | |||
8 | #include <Elementary.h> | ||
9 | |||
10 | static void | ||
11 | _btn_activate_cb(void *data, Evas_Object *obj, void *event) | ||
12 | { | ||
13 | elm_win_activate(data); | ||
14 | } | ||
15 | |||
16 | static void | ||
17 | _btn_lower_cb(void *data, Evas_Object *obj, void *event) | ||
18 | { | ||
19 | elm_win_lower(data); | ||
20 | } | ||
21 | |||
22 | static void | ||
23 | _btn_raise_cb(void *data, Evas_Object *obj, void *event) | ||
24 | { | ||
25 | elm_win_raise(data); | ||
26 | } | ||
27 | |||
28 | static void | ||
29 | _btn_borderless_cb(void *data, Evas_Object *obj, void *event) | ||
30 | { | ||
31 | Eina_Bool flag = elm_win_borderless_get(data); | ||
32 | elm_win_borderless_set(data, !flag); | ||
33 | } | ||
34 | |||
35 | static void | ||
36 | _btn_shaped_cb(void *data, Evas_Object *obj, void *event) | ||
37 | { | ||
38 | Eina_Bool flag = elm_win_shaped_get(data); | ||
39 | elm_win_shaped_set(data, !flag); | ||
40 | } | ||
41 | |||
42 | static void | ||
43 | _btn_alpha_cb(void *data, Evas_Object *obj, void *event) | ||
44 | { | ||
45 | Eina_Bool flag = elm_win_alpha_get(data); | ||
46 | elm_win_alpha_set(data, !flag); | ||
47 | } | ||
48 | |||
49 | static void | ||
50 | _btn_fullscreen_cb(void *data, Evas_Object *obj, void *event) | ||
51 | { | ||
52 | Eina_Bool flag = elm_win_fullscreen_get(data); | ||
53 | elm_win_fullscreen_set(data, !flag); | ||
54 | } | ||
55 | |||
56 | static void | ||
57 | _btn_maximized_cb(void *data, Evas_Object *obj, void *event) | ||
58 | { | ||
59 | Eina_Bool flag = elm_win_maximized_get(data); | ||
60 | elm_win_maximized_set(data, !flag); | ||
61 | } | ||
62 | |||
63 | static void | ||
64 | _btn_iconified_cb(void *data, Evas_Object *obj, void *event) | ||
65 | { | ||
66 | Eina_Bool flag = elm_win_iconified_get(data); | ||
67 | elm_win_iconified_set(data, !flag); | ||
68 | } | ||
69 | |||
70 | static void | ||
71 | _btn_rotation_cb(void *data, Evas_Object *obj, void *event) | ||
72 | { | ||
73 | int angle = elm_win_rotation_get(data); | ||
74 | angle = (angle + 90) % 360; | ||
75 | elm_win_rotation_set(data, angle); | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | _btn_rotation_resize_cb(void *data, Evas_Object *obj, void *event) | ||
80 | { | ||
81 | int angle = elm_win_rotation_get(data); | ||
82 | angle = (angle + 90) % 360; | ||
83 | elm_win_rotation_with_resize_set(data, angle); | ||
84 | } | ||
85 | |||
86 | static void | ||
87 | _btn_sticky_cb(void *data, Evas_Object *obj, void *event) | ||
88 | { | ||
89 | Eina_Bool flag = elm_win_sticky_get(data); | ||
90 | elm_win_sticky_set(data, !flag); | ||
91 | } | ||
92 | |||
93 | static void | ||
94 | _yes_quit_cb(void *data, Evas_Object *obj, void *event) | ||
95 | { | ||
96 | elm_exit(); | ||
97 | } | ||
98 | |||
99 | static void | ||
100 | _no_quit_cb(void *data, Evas_Object *obj, void *event) | ||
101 | { | ||
102 | evas_object_del(data); | ||
103 | } | ||
104 | |||
105 | static void | ||
106 | _main_win_del_cb(void *data, Evas_Object *obj, void *event) | ||
107 | { | ||
108 | Evas_Object *msg, *box, *box2, *btn, *lbl, *sep; | ||
109 | |||
110 | msg = elm_notify_add(obj); | ||
111 | elm_notify_orient_set(msg, ELM_NOTIFY_ORIENT_CENTER); | ||
112 | elm_notify_allow_events_set(msg, EINA_FALSE); | ||
113 | evas_object_show(msg); | ||
114 | |||
115 | box = elm_box_add(obj); | ||
116 | evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
117 | evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
118 | elm_object_content_set(msg, box); | ||
119 | evas_object_show(box); | ||
120 | |||
121 | lbl = elm_label_add(obj); | ||
122 | elm_object_text_set(lbl, "Really want quit?"); | ||
123 | evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
124 | evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
125 | elm_box_pack_end(box, lbl); | ||
126 | evas_object_show(lbl); | ||
127 | |||
128 | sep = elm_separator_add(obj); | ||
129 | elm_separator_horizontal_set(sep, EINA_TRUE); | ||
130 | elm_box_pack_end(box, sep); | ||
131 | evas_object_show(sep); | ||
132 | |||
133 | box2 = elm_box_add(obj); | ||
134 | elm_box_horizontal_set(box2, EINA_TRUE); | ||
135 | evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0); | ||
136 | evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
137 | elm_box_pack_end(box, box2); | ||
138 | evas_object_show(box2); | ||
139 | |||
140 | btn = elm_button_add(obj); | ||
141 | elm_object_text_set(btn, "Yes"); | ||
142 | elm_box_pack_end(box2, btn); | ||
143 | evas_object_show(btn); | ||
144 | |||
145 | evas_object_smart_callback_add(btn, "clicked", _yes_quit_cb, NULL); | ||
146 | |||
147 | btn = elm_button_add(obj); | ||
148 | elm_object_text_set(btn, "No"); | ||
149 | elm_box_pack_end(box2, btn); | ||
150 | evas_object_show(btn); | ||
151 | |||
152 | evas_object_smart_callback_add(btn, "clicked", _no_quit_cb, msg); | ||
153 | } | ||
154 | |||
155 | static void | ||
156 | _force_focus_cb(void *data, Evas_Object *obj, void *event) | ||
157 | { | ||
158 | #ifdef HAVE_ELEMENTARY_X | ||
159 | Ecore_X_Window xwin = elm_win_xwindow_get(data); | ||
160 | ecore_x_window_focus(xwin); | ||
161 | #endif | ||
162 | } | ||
163 | |||
164 | static void | ||
165 | _win_focused_cb(void *data, Evas_Object *obj, void *event) | ||
166 | { | ||
167 | const char *name = data; | ||
168 | printf("Window focused: %s\n", name); | ||
169 | } | ||
170 | |||
171 | EAPI_MAIN int | ||
172 | elm_main(int argc, char *argv[]) | ||
173 | { | ||
174 | Evas_Object *win, *win2, *bg, *bigbox, *box, *btn, *o; | ||
175 | char buf[256]; | ||
176 | |||
177 | elm_app_info_set(elm_main, "elementary", "images/logo.png"); | ||
178 | win = elm_win_add(NULL, "win-example", ELM_WIN_BASIC); | ||
179 | elm_win_title_set(win, "Elm_Win Example"); | ||
180 | elm_win_focus_highlight_enabled_set(win, EINA_TRUE); | ||
181 | evas_object_resize(win, 400, 400); | ||
182 | evas_object_show(win); | ||
183 | |||
184 | evas_object_smart_callback_add(win, "focus,in", _win_focused_cb, "mainwin"); | ||
185 | |||
186 | evas_object_smart_callback_add(win, "delete,request", _main_win_del_cb, | ||
187 | NULL); | ||
188 | |||
189 | bg = elm_bg_add(win); | ||
190 | evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
191 | elm_win_resize_object_add(win, bg); | ||
192 | evas_object_show(bg); | ||
193 | |||
194 | bigbox = elm_box_add(win); | ||
195 | elm_box_horizontal_set(bigbox, EINA_TRUE); | ||
196 | evas_object_size_hint_weight_set(bigbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
197 | elm_win_resize_object_add(win, bigbox); | ||
198 | evas_object_show(bigbox); | ||
199 | |||
200 | box = elm_box_add(win); | ||
201 | evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
202 | evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
203 | elm_box_pack_end(bigbox, box); | ||
204 | evas_object_show(box); | ||
205 | |||
206 | win2 = elm_win_add(NULL, "sub-win-example", ELM_WIN_DIALOG_BASIC); | ||
207 | elm_win_autodel_set(win2, EINA_TRUE); | ||
208 | elm_win_title_set(win2, "Managed window"); | ||
209 | evas_object_show(win2); | ||
210 | |||
211 | evas_object_smart_callback_add(win2, "focus,in", _win_focused_cb, "managed"); | ||
212 | |||
213 | o = elm_icon_add(win2); | ||
214 | sprintf(buf, "%s/images/logo.png", elm_app_data_dir_get()); | ||
215 | elm_icon_file_set(o, buf, NULL); | ||
216 | elm_icon_resizable_set(o, 0, 0); | ||
217 | elm_icon_no_scale_set(o, EINA_TRUE); | ||
218 | elm_win_resize_object_add(win2, o); | ||
219 | evas_object_show(o); | ||
220 | |||
221 | o = elm_label_add(win); | ||
222 | elm_object_text_set(o, "<b>Managed Window</b>"); | ||
223 | elm_box_pack_end(box, o); | ||
224 | evas_object_show(o); | ||
225 | |||
226 | #define WIN_ACTION(name) \ | ||
227 | do { \ | ||
228 | btn = elm_button_add(win); \ | ||
229 | elm_object_text_set(btn, #name); \ | ||
230 | elm_box_pack_end(box, btn); \ | ||
231 | evas_object_show(btn); \ | ||
232 | evas_object_smart_callback_add(btn, "clicked", _btn_##name##_cb, win2); \ | ||
233 | } while (0) | ||
234 | |||
235 | WIN_ACTION(activate); | ||
236 | WIN_ACTION(lower); | ||
237 | WIN_ACTION(raise); | ||
238 | WIN_ACTION(borderless); | ||
239 | WIN_ACTION(shaped); | ||
240 | WIN_ACTION(alpha); | ||
241 | WIN_ACTION(fullscreen); | ||
242 | WIN_ACTION(maximized); | ||
243 | WIN_ACTION(iconified); | ||
244 | WIN_ACTION(rotation); | ||
245 | WIN_ACTION(rotation_resize); | ||
246 | WIN_ACTION(sticky); | ||
247 | |||
248 | box = elm_box_add(win); | ||
249 | evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
250 | evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
251 | elm_box_pack_end(bigbox, box); | ||
252 | evas_object_show(box); | ||
253 | |||
254 | win2 = elm_win_add(NULL, "sub-win-example2", ELM_WIN_BASIC); | ||
255 | elm_win_autodel_set(win2, EINA_TRUE); | ||
256 | elm_win_title_set(win2, "Non-managed window"); | ||
257 | elm_win_override_set(win2, EINA_TRUE); | ||
258 | evas_object_show(win2); | ||
259 | |||
260 | evas_object_smart_callback_add(win2, "focus,in", _win_focused_cb, | ||
261 | "override"); | ||
262 | |||
263 | o = elm_bg_add(win2); | ||
264 | evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
265 | elm_win_resize_object_add(win2, o); | ||
266 | evas_object_show(o); | ||
267 | |||
268 | bigbox = elm_box_add(win2); | ||
269 | evas_object_size_hint_weight_set(bigbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
270 | elm_win_resize_object_add(win2, bigbox); | ||
271 | evas_object_show(bigbox); | ||
272 | |||
273 | o = elm_label_add(win2); | ||
274 | elm_object_text_set(o, "This window should have no borders or titlebar.<ps>" | ||
275 | "It was set in override mode, so the Window Manager<ps>" | ||
276 | "should ignore everything about it.<ps>" | ||
277 | "It's up to the program to handle it properly, and some" | ||
278 | "of the actions performed on it may not have any effect." | ||
279 | ); | ||
280 | elm_box_pack_end(bigbox, o); | ||
281 | evas_object_show(o); | ||
282 | |||
283 | o = elm_entry_add(win2); | ||
284 | elm_object_text_set(o, "See if you can focus me"); | ||
285 | elm_entry_single_line_set(o, EINA_TRUE); | ||
286 | elm_entry_scrollable_set(o, EINA_TRUE); | ||
287 | evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); | ||
288 | evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
289 | elm_box_pack_end(bigbox, o); | ||
290 | evas_object_show(o); | ||
291 | |||
292 | o = elm_separator_add(win2); | ||
293 | elm_separator_horizontal_set(o, EINA_TRUE); | ||
294 | elm_box_pack_end(bigbox, o); | ||
295 | evas_object_show(o); | ||
296 | |||
297 | o = elm_button_add(win2); | ||
298 | elm_object_text_set(o, "Focus me"); | ||
299 | elm_box_pack_end(bigbox, o); | ||
300 | evas_object_show(o); | ||
301 | |||
302 | evas_object_smart_callback_add(o, "clicked", _force_focus_cb, win2); | ||
303 | |||
304 | o = elm_label_add(win); | ||
305 | elm_object_text_set(o, "<b>Override Window</b>"); | ||
306 | elm_box_pack_end(box, o); | ||
307 | evas_object_show(o); | ||
308 | |||
309 | WIN_ACTION(activate); | ||
310 | WIN_ACTION(lower); | ||
311 | WIN_ACTION(raise); | ||
312 | WIN_ACTION(borderless); | ||
313 | WIN_ACTION(shaped); | ||
314 | WIN_ACTION(alpha); | ||
315 | WIN_ACTION(fullscreen); | ||
316 | WIN_ACTION(maximized); | ||
317 | WIN_ACTION(iconified); | ||
318 | WIN_ACTION(rotation); | ||
319 | WIN_ACTION(rotation_resize); | ||
320 | WIN_ACTION(sticky); | ||
321 | |||
322 | elm_run(); | ||
323 | elm_shutdown(); | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | ELM_MAIN() | ||