diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/ecore/src/lib/ecore_evas/ecore_evas_util.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/lib/ecore_evas/ecore_evas_util.c | 437 |
1 files changed, 437 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_evas/ecore_evas_util.c b/libraries/ecore/src/lib/ecore_evas/ecore_evas_util.c new file mode 100644 index 0000000..95b6d22 --- /dev/null +++ b/libraries/ecore/src/lib/ecore_evas/ecore_evas_util.c | |||
@@ -0,0 +1,437 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <string.h> | ||
6 | |||
7 | #include <Ecore.h> | ||
8 | #include "ecore_private.h" | ||
9 | |||
10 | #include "ecore_evas_private.h" | ||
11 | #include "Ecore_Evas.h" | ||
12 | |||
13 | static const char ASSOCIATE_KEY[] = "__Ecore_Evas_Associate"; | ||
14 | |||
15 | static void _ecore_evas_object_associate(Ecore_Evas *ee, Evas_Object *obj, Ecore_Evas_Object_Associate_Flags flags); | ||
16 | static void _ecore_evas_object_dissociate(Ecore_Evas *ee, Evas_Object *obj); | ||
17 | |||
18 | |||
19 | static Evas_Object * | ||
20 | _ecore_evas_associate_get(const Ecore_Evas *ee) | ||
21 | { | ||
22 | return ecore_evas_data_get(ee, ASSOCIATE_KEY); | ||
23 | } | ||
24 | |||
25 | static void | ||
26 | _ecore_evas_associate_set(Ecore_Evas *ee, Evas_Object *obj) | ||
27 | { | ||
28 | ecore_evas_data_set(ee, ASSOCIATE_KEY, obj); | ||
29 | } | ||
30 | |||
31 | static void | ||
32 | _ecore_evas_associate_del(Ecore_Evas *ee) | ||
33 | { | ||
34 | ecore_evas_data_set(ee, ASSOCIATE_KEY, NULL); | ||
35 | } | ||
36 | |||
37 | static Ecore_Evas * | ||
38 | _evas_object_associate_get(const Evas_Object *obj) | ||
39 | { | ||
40 | return evas_object_data_get(obj, ASSOCIATE_KEY); | ||
41 | } | ||
42 | |||
43 | static void | ||
44 | _evas_object_associate_set(Evas_Object *obj, Ecore_Evas *ee) | ||
45 | { | ||
46 | evas_object_data_set(obj, ASSOCIATE_KEY, ee); | ||
47 | } | ||
48 | |||
49 | static void | ||
50 | _evas_object_associate_del(Evas_Object *obj) | ||
51 | { | ||
52 | evas_object_data_del(obj, ASSOCIATE_KEY); | ||
53 | } | ||
54 | |||
55 | /** Associated Events: ******************************************************/ | ||
56 | |||
57 | /* Interceptors Callbacks */ | ||
58 | |||
59 | static void | ||
60 | _ecore_evas_obj_intercept_move(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y) | ||
61 | { | ||
62 | Ecore_Evas *ee = data; | ||
63 | // FIXME: account for frame | ||
64 | ecore_evas_move(ee, x, y); | ||
65 | if (ecore_evas_override_get(ee)) evas_object_move(obj, x, y); | ||
66 | } | ||
67 | |||
68 | static void | ||
69 | _ecore_evas_obj_intercept_raise(void *data, Evas_Object *obj __UNUSED__) | ||
70 | { | ||
71 | Ecore_Evas *ee = data; | ||
72 | ecore_evas_raise(ee); | ||
73 | } | ||
74 | |||
75 | static void | ||
76 | _ecore_evas_obj_intercept_lower(void *data, Evas_Object *obj __UNUSED__) | ||
77 | { | ||
78 | Ecore_Evas *ee = data; | ||
79 | ecore_evas_lower(ee); | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | _ecore_evas_obj_intercept_stack_above(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *above __UNUSED__) | ||
84 | { | ||
85 | INF("TODO: %s", __FUNCTION__); | ||
86 | } | ||
87 | |||
88 | static void | ||
89 | _ecore_evas_obj_intercept_stack_below(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *below __UNUSED__) | ||
90 | { | ||
91 | INF("TODO: %s", __FUNCTION__); | ||
92 | } | ||
93 | |||
94 | static void | ||
95 | _ecore_evas_obj_intercept_layer_set(void *data, Evas_Object *obj __UNUSED__, int l) | ||
96 | { | ||
97 | Ecore_Evas *ee = data; | ||
98 | ecore_evas_layer_set(ee, l); | ||
99 | } | ||
100 | |||
101 | /* Event Callbacks */ | ||
102 | |||
103 | static void | ||
104 | _ecore_evas_obj_callback_show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
105 | { | ||
106 | Ecore_Evas *ee = data; | ||
107 | ecore_evas_show(ee); | ||
108 | } | ||
109 | |||
110 | static void | ||
111 | _ecore_evas_obj_callback_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
112 | { | ||
113 | Ecore_Evas *ee = data; | ||
114 | ecore_evas_hide(ee); | ||
115 | } | ||
116 | |||
117 | static void | ||
118 | _ecore_evas_obj_callback_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) | ||
119 | { | ||
120 | Ecore_Evas *ee = data; | ||
121 | Evas_Coord ow, oh, w, h; | ||
122 | |||
123 | evas_object_geometry_get(obj, NULL, NULL, &ow, &oh); | ||
124 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
125 | /*if ((w != ow) || (h != oh))*/ /* avoid recursion on ecore_evas_resize side */ | ||
126 | ecore_evas_resize(ee, ow, oh); | ||
127 | } | ||
128 | |||
129 | static void | ||
130 | _ecore_evas_obj_callback_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) | ||
131 | { | ||
132 | Ecore_Evas *ee = data; | ||
133 | Evas_Coord w, h; | ||
134 | |||
135 | evas_object_size_hint_min_get(obj, &w, &h); | ||
136 | ecore_evas_size_min_set(ee, w, h); | ||
137 | |||
138 | evas_object_size_hint_max_get(obj, &w, &h); | ||
139 | if (w < 1) w = -1; | ||
140 | if (h < 1) h = -1; | ||
141 | ecore_evas_size_max_set(ee, w, h); | ||
142 | } | ||
143 | |||
144 | static void | ||
145 | _ecore_evas_obj_callback_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) | ||
146 | { | ||
147 | Ecore_Evas *ee = data; | ||
148 | _ecore_evas_object_dissociate(ee, obj); | ||
149 | ecore_evas_free(ee); | ||
150 | } | ||
151 | |||
152 | static void | ||
153 | _ecore_evas_obj_callback_del_dissociate(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) | ||
154 | { | ||
155 | Ecore_Evas *ee = data; | ||
156 | _ecore_evas_object_dissociate(ee, obj); | ||
157 | } | ||
158 | |||
159 | static void | ||
160 | _ecore_evas_delete_request(Ecore_Evas *ee) | ||
161 | { | ||
162 | Evas_Object *obj = _ecore_evas_associate_get(ee); | ||
163 | _ecore_evas_object_dissociate(ee, obj); | ||
164 | evas_object_del(obj); | ||
165 | ecore_evas_free(ee); | ||
166 | } | ||
167 | |||
168 | static void | ||
169 | _ecore_evas_destroy(Ecore_Evas *ee) | ||
170 | { | ||
171 | Evas_Object *obj = _ecore_evas_associate_get(ee); | ||
172 | if (!obj) | ||
173 | return; | ||
174 | _ecore_evas_object_dissociate(ee, obj); | ||
175 | evas_object_del(obj); | ||
176 | } | ||
177 | |||
178 | static void | ||
179 | _ecore_evas_resize(Ecore_Evas *ee) | ||
180 | { | ||
181 | Evas_Object *obj = _ecore_evas_associate_get(ee); | ||
182 | Evas_Coord w, h; | ||
183 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
184 | evas_object_resize(obj, w, h); | ||
185 | } | ||
186 | |||
187 | static void | ||
188 | _ecore_evas_pre_free(Ecore_Evas *ee) | ||
189 | { | ||
190 | Evas_Object *obj = _ecore_evas_associate_get(ee); | ||
191 | if (!obj) | ||
192 | return; | ||
193 | _ecore_evas_object_dissociate(ee, obj); | ||
194 | evas_object_del(obj); | ||
195 | } | ||
196 | |||
197 | static int | ||
198 | _ecore_evas_object_evas_check(const char *function, const Ecore_Evas *ee, const Evas_Object *obj) | ||
199 | { | ||
200 | const char *name, *type; | ||
201 | Evas *e; | ||
202 | |||
203 | e = evas_object_evas_get(obj); | ||
204 | if (e == ee->evas) | ||
205 | return 1; | ||
206 | |||
207 | name = evas_object_name_get(obj); | ||
208 | type = evas_object_type_get(obj); | ||
209 | |||
210 | ERR("ERROR: %s(): object %p (name=\"%s\", type=\"%s\") evas " | ||
211 | "is not the same as this Ecore_Evas evas: %p != %p", | ||
212 | function, obj, | ||
213 | name ? name : "", type ? type : "", e, ee->evas); | ||
214 | fflush(stderr); | ||
215 | if (getenv("ECORE_ERROR_ABORT")) abort(); | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | EAPI Eina_Bool | ||
221 | ecore_evas_object_associate(Ecore_Evas *ee, Evas_Object *obj, Ecore_Evas_Object_Associate_Flags flags) | ||
222 | { | ||
223 | Ecore_Evas *old_ee; | ||
224 | Evas_Object *old_obj; | ||
225 | |||
226 | if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS)) | ||
227 | { | ||
228 | ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__); | ||
229 | return EINA_FALSE; | ||
230 | } | ||
231 | |||
232 | CHECK_PARAM_POINTER_RETURN("obj", obj, EINA_FALSE); | ||
233 | if (!_ecore_evas_object_evas_check(__FUNCTION__, ee, obj)) | ||
234 | return EINA_FALSE; | ||
235 | |||
236 | old_ee = _evas_object_associate_get(obj);; | ||
237 | if (old_ee) | ||
238 | ecore_evas_object_dissociate(old_ee, obj); | ||
239 | |||
240 | old_obj = _ecore_evas_associate_get(ee); | ||
241 | if (old_obj) | ||
242 | ecore_evas_object_dissociate(ee, old_obj); | ||
243 | |||
244 | _ecore_evas_object_associate(ee, obj, flags); | ||
245 | return EINA_TRUE; | ||
246 | } | ||
247 | |||
248 | EAPI Eina_Bool | ||
249 | ecore_evas_object_dissociate(Ecore_Evas *ee, Evas_Object *obj) | ||
250 | { | ||
251 | Ecore_Evas *old_ee; | ||
252 | Evas_Object *old_obj; | ||
253 | |||
254 | if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS)) | ||
255 | { | ||
256 | ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__); | ||
257 | return EINA_FALSE; | ||
258 | } | ||
259 | |||
260 | CHECK_PARAM_POINTER_RETURN("obj", obj, EINA_FALSE); | ||
261 | old_ee = _evas_object_associate_get(obj); | ||
262 | if (ee != old_ee) { | ||
263 | ERR("ERROR: trying to dissociate object that is not using " | ||
264 | "this Ecore_Evas: %p != %p", ee, old_ee); | ||
265 | return EINA_FALSE; | ||
266 | } | ||
267 | |||
268 | old_obj = _ecore_evas_associate_get(ee); | ||
269 | if (old_obj != obj) { | ||
270 | ERR("ERROR: trying to dissociate object that is not being " | ||
271 | "used by this Ecore_Evas: %p != %p", old_obj, obj); | ||
272 | return EINA_FALSE; | ||
273 | } | ||
274 | |||
275 | _ecore_evas_object_dissociate(ee, obj); | ||
276 | |||
277 | return EINA_TRUE; | ||
278 | } | ||
279 | |||
280 | EAPI Evas_Object * | ||
281 | ecore_evas_object_associate_get(const Ecore_Evas *ee) | ||
282 | { | ||
283 | if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS)) | ||
284 | { | ||
285 | ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__); | ||
286 | return NULL; | ||
287 | } | ||
288 | return _ecore_evas_associate_get(ee); | ||
289 | } | ||
290 | |||
291 | static void | ||
292 | _ecore_evas_object_associate(Ecore_Evas *ee, Evas_Object *obj, Ecore_Evas_Object_Associate_Flags flags) | ||
293 | { | ||
294 | evas_object_event_callback_add | ||
295 | (obj, EVAS_CALLBACK_SHOW, | ||
296 | _ecore_evas_obj_callback_show, ee); | ||
297 | evas_object_event_callback_add | ||
298 | (obj, EVAS_CALLBACK_HIDE, | ||
299 | _ecore_evas_obj_callback_hide, ee); | ||
300 | evas_object_event_callback_add | ||
301 | (obj, EVAS_CALLBACK_RESIZE, | ||
302 | _ecore_evas_obj_callback_resize, ee); | ||
303 | evas_object_event_callback_add | ||
304 | (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, | ||
305 | _ecore_evas_obj_callback_changed_size_hints, ee); | ||
306 | if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_DEL) | ||
307 | evas_object_event_callback_add | ||
308 | (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del, ee); | ||
309 | else | ||
310 | evas_object_event_callback_add | ||
311 | (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del_dissociate, ee); | ||
312 | |||
313 | evas_object_intercept_move_callback_add | ||
314 | (obj, _ecore_evas_obj_intercept_move, ee); | ||
315 | |||
316 | if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_STACK) | ||
317 | { | ||
318 | evas_object_intercept_raise_callback_add | ||
319 | (obj, _ecore_evas_obj_intercept_raise, ee); | ||
320 | evas_object_intercept_lower_callback_add | ||
321 | (obj, _ecore_evas_obj_intercept_lower, ee); | ||
322 | evas_object_intercept_stack_above_callback_add | ||
323 | (obj, _ecore_evas_obj_intercept_stack_above, ee); | ||
324 | evas_object_intercept_stack_below_callback_add | ||
325 | (obj, _ecore_evas_obj_intercept_stack_below, ee); | ||
326 | } | ||
327 | |||
328 | if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_LAYER) | ||
329 | evas_object_intercept_layer_set_callback_add | ||
330 | (obj, _ecore_evas_obj_intercept_layer_set, ee); | ||
331 | |||
332 | if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_DEL) | ||
333 | { | ||
334 | ecore_evas_callback_delete_request_set(ee, _ecore_evas_delete_request); | ||
335 | ecore_evas_callback_destroy_set(ee, _ecore_evas_destroy); | ||
336 | } | ||
337 | ecore_evas_callback_pre_free_set(ee, _ecore_evas_pre_free); | ||
338 | ecore_evas_callback_resize_set(ee, _ecore_evas_resize); | ||
339 | |||
340 | _evas_object_associate_set(obj, ee); | ||
341 | _ecore_evas_associate_set(ee, obj); | ||
342 | } | ||
343 | |||
344 | static void | ||
345 | _ecore_evas_object_dissociate(Ecore_Evas *ee, Evas_Object *obj) | ||
346 | { | ||
347 | evas_object_event_callback_del_full | ||
348 | (obj, EVAS_CALLBACK_SHOW, | ||
349 | _ecore_evas_obj_callback_show, ee); | ||
350 | evas_object_event_callback_del_full | ||
351 | (obj, EVAS_CALLBACK_HIDE, | ||
352 | _ecore_evas_obj_callback_hide, ee); | ||
353 | evas_object_event_callback_del_full | ||
354 | (obj, EVAS_CALLBACK_RESIZE, | ||
355 | _ecore_evas_obj_callback_resize, ee); | ||
356 | evas_object_event_callback_del_full | ||
357 | (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, | ||
358 | _ecore_evas_obj_callback_changed_size_hints, ee); | ||
359 | evas_object_event_callback_del_full | ||
360 | (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del, ee); | ||
361 | evas_object_event_callback_del_full | ||
362 | (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del_dissociate, ee); | ||
363 | |||
364 | evas_object_intercept_move_callback_del | ||
365 | (obj, _ecore_evas_obj_intercept_move); | ||
366 | |||
367 | evas_object_intercept_raise_callback_del | ||
368 | (obj, _ecore_evas_obj_intercept_raise); | ||
369 | evas_object_intercept_lower_callback_del | ||
370 | (obj, _ecore_evas_obj_intercept_lower); | ||
371 | evas_object_intercept_stack_above_callback_del | ||
372 | (obj, _ecore_evas_obj_intercept_stack_above); | ||
373 | evas_object_intercept_stack_below_callback_del | ||
374 | (obj, _ecore_evas_obj_intercept_stack_below); | ||
375 | |||
376 | evas_object_intercept_layer_set_callback_del | ||
377 | (obj, _ecore_evas_obj_intercept_layer_set); | ||
378 | |||
379 | if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS)) | ||
380 | { | ||
381 | ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__); | ||
382 | } | ||
383 | else | ||
384 | { | ||
385 | if (ee->func.fn_delete_request == _ecore_evas_delete_request) | ||
386 | ecore_evas_callback_delete_request_set(ee, NULL); | ||
387 | if (ee->func.fn_destroy == _ecore_evas_destroy) | ||
388 | ecore_evas_callback_destroy_set(ee, NULL); | ||
389 | if (ee->func.fn_resize == _ecore_evas_resize) | ||
390 | ecore_evas_callback_resize_set(ee, NULL); | ||
391 | if (ee->func.fn_pre_free == _ecore_evas_pre_free) | ||
392 | ecore_evas_callback_pre_free_set(ee, NULL); | ||
393 | |||
394 | _ecore_evas_associate_del(ee); | ||
395 | } | ||
396 | |||
397 | _evas_object_associate_del(obj); | ||
398 | } | ||
399 | |||
400 | /** | ||
401 | * Helper ecore_getopt callback to list available Ecore_Evas engines. | ||
402 | * | ||
403 | * This will list all available engines except buffer, this is useful | ||
404 | * for applications to let user choose how they should create windows | ||
405 | * with ecore_evas_new(). | ||
406 | * | ||
407 | * @c callback_data value is used as @c FILE* and says where to output | ||
408 | * messages, by default it is @c stdout. You can specify this value | ||
409 | * with ECORE_GETOPT_CALLBACK_FULL() or ECORE_GETOPT_CALLBACK_ARGS(). | ||
410 | * | ||
411 | * If there is a boolean storage provided, then it is marked with 1 | ||
412 | * when this option is executed. | ||
413 | */ | ||
414 | unsigned char | ||
415 | ecore_getopt_callback_ecore_evas_list_engines(const Ecore_Getopt *parser __UNUSED__, const Ecore_Getopt_Desc *desc __UNUSED__, const char *str __UNUSED__, void *data, Ecore_Getopt_Value *storage) | ||
416 | { | ||
417 | Eina_List *lst, *n; | ||
418 | const char *engine; | ||
419 | FILE *fp = data; | ||
420 | |||
421 | if (!fp) | ||
422 | fp = stdout; | ||
423 | |||
424 | lst = ecore_evas_engines_get(); | ||
425 | |||
426 | fputs("supported engines:\n", fp); | ||
427 | EINA_LIST_FOREACH(lst, n, engine) | ||
428 | if (strcmp(engine, "buffer") != 0) | ||
429 | fprintf(fp, "\t%s\n", engine); | ||
430 | |||
431 | ecore_evas_engines_free(lst); | ||
432 | |||
433 | if (storage->boolp) | ||
434 | *storage->boolp = 1; | ||
435 | |||
436 | return 1; | ||
437 | } | ||