8 #include "ecore_private.h"
10 #include "ecore_evas_private.h"
11 #include "Ecore_Evas.h"
13 static const char ASSOCIATE_KEY[] = "__Ecore_Evas_Associate";
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);
20 _ecore_evas_associate_get(const Ecore_Evas *ee)
22 return ecore_evas_data_get(ee, ASSOCIATE_KEY);
26 _ecore_evas_associate_set(Ecore_Evas *ee, Evas_Object *obj)
28 ecore_evas_data_set(ee, ASSOCIATE_KEY, obj);
32 _ecore_evas_associate_del(Ecore_Evas *ee)
34 ecore_evas_data_set(ee, ASSOCIATE_KEY, NULL);
38 _evas_object_associate_get(const Evas_Object *obj)
40 return evas_object_data_get(obj, ASSOCIATE_KEY);
44 _evas_object_associate_set(Evas_Object *obj, Ecore_Evas *ee)
46 evas_object_data_set(obj, ASSOCIATE_KEY, ee);
50 _evas_object_associate_del(Evas_Object *obj)
52 evas_object_data_del(obj, ASSOCIATE_KEY);
55 /** Associated Events: ******************************************************/
57 /* Interceptors Callbacks */
60 _ecore_evas_obj_intercept_move(void *data, Evas_Object *obj __UNUSED__, Evas_Coord x, Evas_Coord y)
62 Ecore_Evas *ee = data;
63 // FIXME: account for frame
64 ecore_evas_move(ee, x, y);
68 _ecore_evas_obj_intercept_raise(void *data, Evas_Object *obj __UNUSED__)
70 Ecore_Evas *ee = data;
75 _ecore_evas_obj_intercept_lower(void *data, Evas_Object *obj __UNUSED__)
77 Ecore_Evas *ee = data;
82 _ecore_evas_obj_intercept_stack_above(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *above __UNUSED__)
84 INF("TODO: %s", __FUNCTION__);
88 _ecore_evas_obj_intercept_stack_below(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *below __UNUSED__)
90 INF("TODO: %s", __FUNCTION__);
94 _ecore_evas_obj_intercept_layer_set(void *data, Evas_Object *obj __UNUSED__, int l)
96 Ecore_Evas *ee = data;
97 ecore_evas_layer_set(ee, l);
100 /* Event Callbacks */
103 _ecore_evas_obj_callback_show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
105 Ecore_Evas *ee = data;
110 _ecore_evas_obj_callback_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
112 Ecore_Evas *ee = data;
117 _ecore_evas_obj_callback_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
119 Ecore_Evas *ee = data;
120 Evas_Coord ow, oh, w, h;
122 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
123 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
124 if ((w != ow) || (h != oh)) /* avoid recursion on ecore_evas_resize side */
125 ecore_evas_resize(ee, ow, oh);
129 _ecore_evas_obj_callback_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
131 Ecore_Evas *ee = data;
134 evas_object_size_hint_min_get(obj, &w, &h);
135 ecore_evas_size_min_set(ee, w, h);
137 evas_object_size_hint_max_get(obj, &w, &h);
140 ecore_evas_size_max_set(ee, w, h);
144 _ecore_evas_obj_callback_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
146 Ecore_Evas *ee = data;
147 _ecore_evas_object_dissociate(ee, obj);
152 _ecore_evas_obj_callback_del_dissociate(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
154 Ecore_Evas *ee = data;
155 _ecore_evas_object_dissociate(ee, obj);
159 _ecore_evas_delete_request(Ecore_Evas *ee)
161 Evas_Object *obj = _ecore_evas_associate_get(ee);
162 _ecore_evas_object_dissociate(ee, obj);
163 evas_object_del(obj);
168 _ecore_evas_destroy(Ecore_Evas *ee)
170 Evas_Object *obj = _ecore_evas_associate_get(ee);
173 _ecore_evas_object_dissociate(ee, obj);
174 evas_object_del(obj);
178 _ecore_evas_resize(Ecore_Evas *ee)
180 Evas_Object *obj = _ecore_evas_associate_get(ee);
182 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
183 evas_object_resize(obj, w, h);
187 _ecore_evas_pre_free(Ecore_Evas *ee)
189 Evas_Object *obj = _ecore_evas_associate_get(ee);
192 _ecore_evas_object_dissociate(ee, obj);
193 evas_object_del(obj);
197 _ecore_evas_object_evas_check(const char *function, const Ecore_Evas *ee, const Evas_Object *obj)
199 const char *name, *type;
202 e = evas_object_evas_get(obj);
206 name = evas_object_name_get(obj);
207 type = evas_object_type_get(obj);
209 ERR("ERROR: %s(): object %p (name=\"%s\", type=\"%s\") evas "
210 "is not the same as this Ecore_Evas evas: %p != %p",
212 name ? name : "", type ? type : "", e, ee->evas);
214 if (getenv("ECORE_ERROR_ABORT")) abort();
220 * Associate the given object to this ecore evas.
222 * Association means that operations on one will affect the other, for
223 * example moving the object will move the window, resize the object will
224 * also affect the ecore evas window, hide and show applies as well.
226 * This is meant to simplify development, since you often need to associate
227 * these events with your "base" objects, background or bottom-most object.
229 * Be aware that some methods might not be what you would like, deleting
230 * either the window or the object will delete the other. If you want to
231 * change that behavior, let's say to hide window when it's closed, you
232 * must use ecore_evas_callback_delete_request_set() and set your own code,
233 * like ecore_evas_hide(). Just remember that if you override delete_request
234 * and still want to delete the window/object, you must do that yourself.
236 * Since we now define delete_request, deleting windows will not quit
237 * main loop, if you wish to do so, you should listen for EVAS_CALLBACK_FREE
238 * on the object, that way you get notified and you can call
239 * ecore_main_loop_quit().
241 * Flags can be OR'ed of:
242 * - ECORE_EVAS_OBJECT_ASSOCIATE_BASE (or 0): to listen to basic events
243 * like delete, resize and move, but no stacking or layer are used.
244 * - ECORE_EVAS_OBJECT_ASSOCIATE_STACK: stacking operations will act
245 * on the Ecore_Evas, not the object. So evas_object_raise() will
246 * call ecore_evas_raise(). Relative operations (stack_above, stack_below)
247 * are still not implemented.
248 * - ECORE_EVAS_OBJECT_ASSOCIATE_LAYER: stacking operations will act
249 * on the Ecore_Evas, not the object. So evas_object_layer_set() will
250 * call ecore_evas_layer_set().
251 * - ECORE_EVAS_OBJECT_ASSOCIATE_DEL: the object delete will delete the
252 * ecore_evas as well as delete_requests on the ecore_evas will delete
255 * @param ee The Ecore_Evas to associate to @a obj
256 * @param obj The object to associate to @a ee
257 * @param flags The association flags.
258 * @return 1 on success, 0 otherwise.
261 ecore_evas_object_associate(Ecore_Evas *ee, Evas_Object *obj, Ecore_Evas_Object_Associate_Flags flags)
264 Evas_Object *old_obj;
266 if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS))
268 ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__);
272 CHECK_PARAM_POINTER_RETURN("obj", obj, 0);
273 if (!_ecore_evas_object_evas_check(__FUNCTION__, ee, obj))
276 old_ee = _evas_object_associate_get(obj);;
278 ecore_evas_object_dissociate(old_ee, obj);
280 old_obj = _ecore_evas_associate_get(ee);
282 ecore_evas_object_dissociate(ee, old_obj);
284 _ecore_evas_object_associate(ee, obj, flags);
289 * Cancel the association set with ecore_evas_object_associate().
291 * @param ee The Ecore_Evas to dissociate from @a obj
292 * @param obj The object to dissociate from @a ee
293 * @return 1 on success, 0 otherwise.
296 ecore_evas_object_dissociate(Ecore_Evas *ee, Evas_Object *obj)
299 Evas_Object *old_obj;
301 if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS))
303 ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__);
307 CHECK_PARAM_POINTER_RETURN("obj", obj, 0);
308 old_ee = _evas_object_associate_get(obj);
310 ERR("ERROR: trying to dissociate object that is not using "
311 "this Ecore_Evas: %p != %p", ee, old_ee);
315 old_obj = _ecore_evas_associate_get(ee);
316 if (old_obj != obj) {
317 ERR("ERROR: trying to dissociate object that is not being "
318 "used by this Ecore_Evas: %p != %p", old_obj, obj);
322 _ecore_evas_object_dissociate(ee, obj);
328 ecore_evas_object_associate_get(const Ecore_Evas *ee)
330 if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS))
332 ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__);
335 return _ecore_evas_associate_get(ee);
339 _ecore_evas_object_associate(Ecore_Evas *ee, Evas_Object *obj, Ecore_Evas_Object_Associate_Flags flags)
341 evas_object_event_callback_add
342 (obj, EVAS_CALLBACK_SHOW,
343 _ecore_evas_obj_callback_show, ee);
344 evas_object_event_callback_add
345 (obj, EVAS_CALLBACK_HIDE,
346 _ecore_evas_obj_callback_hide, ee);
347 evas_object_event_callback_add
348 (obj, EVAS_CALLBACK_RESIZE,
349 _ecore_evas_obj_callback_resize, ee);
350 evas_object_event_callback_add
351 (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
352 _ecore_evas_obj_callback_changed_size_hints, ee);
353 if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_DEL)
354 evas_object_event_callback_add
355 (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del, ee);
357 evas_object_event_callback_add
358 (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del_dissociate, ee);
360 evas_object_intercept_move_callback_add
361 (obj, _ecore_evas_obj_intercept_move, ee);
363 if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_STACK)
365 evas_object_intercept_raise_callback_add
366 (obj, _ecore_evas_obj_intercept_raise, ee);
367 evas_object_intercept_lower_callback_add
368 (obj, _ecore_evas_obj_intercept_lower, ee);
369 evas_object_intercept_stack_above_callback_add
370 (obj, _ecore_evas_obj_intercept_stack_above, ee);
371 evas_object_intercept_stack_below_callback_add
372 (obj, _ecore_evas_obj_intercept_stack_below, ee);
375 if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_LAYER)
376 evas_object_intercept_layer_set_callback_add
377 (obj, _ecore_evas_obj_intercept_layer_set, ee);
379 if (flags & ECORE_EVAS_OBJECT_ASSOCIATE_DEL)
381 ecore_evas_callback_delete_request_set(ee, _ecore_evas_delete_request);
382 ecore_evas_callback_destroy_set(ee, _ecore_evas_destroy);
384 ecore_evas_callback_pre_free_set(ee, _ecore_evas_pre_free);
385 ecore_evas_callback_resize_set(ee, _ecore_evas_resize);
387 _evas_object_associate_set(obj, ee);
388 _ecore_evas_associate_set(ee, obj);
392 _ecore_evas_object_dissociate(Ecore_Evas *ee, Evas_Object *obj)
394 evas_object_event_callback_del_full
395 (obj, EVAS_CALLBACK_SHOW,
396 _ecore_evas_obj_callback_show, ee);
397 evas_object_event_callback_del_full
398 (obj, EVAS_CALLBACK_HIDE,
399 _ecore_evas_obj_callback_hide, ee);
400 evas_object_event_callback_del_full
401 (obj, EVAS_CALLBACK_RESIZE,
402 _ecore_evas_obj_callback_resize, ee);
403 evas_object_event_callback_del_full
404 (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
405 _ecore_evas_obj_callback_changed_size_hints, ee);
406 evas_object_event_callback_del_full
407 (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del, ee);
408 evas_object_event_callback_del_full
409 (obj, EVAS_CALLBACK_DEL, _ecore_evas_obj_callback_del_dissociate, ee);
411 evas_object_intercept_move_callback_del
412 (obj, _ecore_evas_obj_intercept_move);
414 evas_object_intercept_raise_callback_del
415 (obj, _ecore_evas_obj_intercept_raise);
416 evas_object_intercept_lower_callback_del
417 (obj, _ecore_evas_obj_intercept_lower);
418 evas_object_intercept_stack_above_callback_del
419 (obj, _ecore_evas_obj_intercept_stack_above);
420 evas_object_intercept_stack_below_callback_del
421 (obj, _ecore_evas_obj_intercept_stack_below);
423 evas_object_intercept_layer_set_callback_del
424 (obj, _ecore_evas_obj_intercept_layer_set);
426 if (!ECORE_MAGIC_CHECK(ee, ECORE_MAGIC_EVAS))
428 ECORE_MAGIC_FAIL(ee, ECORE_MAGIC_EVAS, __FUNCTION__);
432 if (ee->func.fn_delete_request == _ecore_evas_delete_request)
433 ecore_evas_callback_delete_request_set(ee, NULL);
434 if (ee->func.fn_destroy == _ecore_evas_destroy)
435 ecore_evas_callback_destroy_set(ee, NULL);
436 if (ee->func.fn_resize == _ecore_evas_resize)
437 ecore_evas_callback_resize_set(ee, NULL);
438 if (ee->func.fn_pre_free == _ecore_evas_pre_free)
439 ecore_evas_callback_pre_free_set(ee, NULL);
441 _ecore_evas_associate_del(ee);
444 _evas_object_associate_del(obj);
448 * Helper ecore_getopt callback to list available Ecore_Evas engines.
450 * This will list all available engines except buffer, this is useful
451 * for applications to let user choose how they should create windows
452 * with ecore_evas_new().
454 * @c callback_data value is used as @c FILE* and says where to output
455 * messages, by default it is @c stdout. You can specify this value
456 * with ECORE_GETOPT_CALLBACK_FULL() or ECORE_GETOPT_CALLBACK_ARGS().
458 * If there is a boolean storage provided, then it is marked with 1
459 * when this option is executed.
462 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)
471 lst = ecore_evas_engines_get();
473 fputs("supported engines:\n", fp);
474 EINA_LIST_FOREACH(lst, n, engine)
475 if (strcmp(engine, "buffer") != 0)
476 fprintf(fp, "\t%s\n", engine);
478 ecore_evas_engines_free(lst);