1 #include <Elementary.h>
5 * @defgroup Hover Hover
7 * A Hover object will over over the @p Parent object at the @p Target
8 * location. Anything in the background will be given a darker coloring
9 * to indicate that the hover object is on top.
11 * NOTE: The hover object will take up the entire space of @p Target object.
14 typedef struct _Widget_Data Widget_Data;
15 typedef struct _Subinfo Subinfo;
19 Evas_Object *hov, *cov;
20 Evas_Object *offset, *size;
21 Evas_Object *parent, *target;
31 static const char *widtype = NULL;
32 static void _del_pre_hook(Evas_Object *obj);
33 static void _del_hook(Evas_Object *obj);
34 static void _theme_hook(Evas_Object *obj);
35 static void _sizing_eval(Evas_Object *obj);
36 static void _reval_content(Evas_Object *obj);
37 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
38 static void _hov_show_do(Evas_Object *obj);
39 static void _hov_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
40 static void _hov_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
41 static void _hov_show(void *data, Evas *e, Evas_Object *obj, void *event_info);
42 static void _hov_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
45 _del_pre_hook(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
50 if (evas_object_visible_get(obj))
51 evas_object_smart_callback_call(obj, "clicked", NULL);
52 elm_hover_target_set(obj, NULL);
53 elm_hover_parent_set(obj, NULL);
54 evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_MOVE, _hov_move, obj);
55 evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_RESIZE, _hov_resize, obj);
56 evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_SHOW, _hov_show, obj);
57 evas_object_event_callback_del_full(wd->hov, EVAS_CALLBACK_HIDE, _hov_hide, obj);
59 EINA_LIST_FREE(wd->subs, si)
61 eina_stringshare_del(si->swallow);
67 _del_hook(Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
75 _theme_hook(Evas_Object *obj)
77 Widget_Data *wd = elm_widget_data_get(obj);
79 // FIXME: hover contents doesnt seem to propagate resizes properly
80 _elm_theme_object_set(obj, wd->cov, "hover", "base", elm_widget_style_get(obj));
81 edje_object_scale_set(wd->cov, elm_widget_scale_get(obj) *
85 if (evas_object_visible_get(wd->cov)) _hov_show_do(obj);
90 _sizing_eval(Evas_Object *obj)
92 Widget_Data *wd = elm_widget_data_get(obj);
93 Evas_Coord x = 0, y = 0, w = 0, h = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0;
95 if (wd->parent) evas_object_geometry_get(wd->parent, &x, &y, &w, &h);
96 if (wd->hov) evas_object_geometry_get(wd->hov, &x2, &y2, &w2, &h2);
97 evas_object_move(wd->cov, x, y);
98 evas_object_resize(wd->cov, w, h);
99 evas_object_size_hint_min_set(wd->offset, x2 - x, y2 - y);
100 evas_object_size_hint_min_set(wd->size, w2, h2);
101 edje_object_part_swallow(wd->cov, "elm.swallow.offset", wd->offset);
102 edje_object_part_swallow(wd->cov, "elm.swallow.size", wd->size);
106 _reval_content(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
112 EINA_LIST_FOREACH(wd->subs, l, si)
113 edje_object_part_swallow(wd->cov, si->swallow, si->obj);
117 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
119 Widget_Data *wd = elm_widget_data_get(obj);
120 Evas_Object *sub = event_info;
124 EINA_LIST_FOREACH(wd->subs, l, si)
128 wd->subs = eina_list_remove_list(wd->subs, l);
129 eina_stringshare_del(si->swallow);
137 _hov_show_do(Evas_Object *obj)
139 Widget_Data *wd = elm_widget_data_get(obj);
145 evas_object_show(wd->cov);
146 edje_object_signal_emit(wd->cov, "elm,action,show", "elm");
148 EINA_LIST_FOREACH(wd->subs, l, si)
152 if (!strncmp(si->swallow, "elm.swallow.slot.", 17))
154 snprintf(buf, sizeof(buf), "elm,action,slot,%s,show",
156 edje_object_signal_emit(wd->cov, buf, "elm");
162 _hov_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
168 _hov_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
174 _hov_show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
180 _hov_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
182 Widget_Data *wd = elm_widget_data_get(data);
188 edje_object_signal_emit(wd->cov, "elm,action,hide", "elm");
189 evas_object_hide(wd->cov);
191 EINA_LIST_FOREACH(wd->subs, l, si)
195 if (!strncmp(si->swallow, "elm.swallow.slot.", 17))
197 snprintf(buf, sizeof(buf), "elm,action,slot,%s,hide",
199 edje_object_signal_emit(wd->cov, buf, "elm");
205 _target_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
207 Widget_Data *wd = elm_widget_data_get(data);
213 _signal_dismiss(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
215 Widget_Data *wd = elm_widget_data_get(data);
217 evas_object_hide(data);
218 evas_object_smart_callback_call(data, "clicked", NULL);
222 _parent_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
228 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
234 _parent_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
239 _parent_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
241 Widget_Data *wd = elm_widget_data_get(data);
243 if (wd) evas_object_hide(wd->cov);
247 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
249 Widget_Data *wd = elm_widget_data_get(data);
251 elm_hover_parent_set(data, NULL);
256 * Adds a hover object to @p parent
258 * @param parent The parent object
259 * @return The hover object or NULL if one could not be created
264 elm_hover_add(Evas_Object *parent)
270 wd = ELM_NEW(Widget_Data);
271 e = evas_object_evas_get(parent);
272 obj = elm_widget_add(e);
273 ELM_SET_WIDTYPE(widtype, "hover");
274 elm_widget_type_set(obj, "hover");
275 elm_widget_sub_object_add(parent, obj);
276 elm_widget_data_set(obj, wd);
277 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
278 elm_widget_theme_hook_set(obj, _theme_hook);
279 elm_widget_del_hook_set(obj, _del_hook);
281 wd->hov = evas_object_rectangle_add(e);
282 evas_object_pass_events_set(wd->hov, 1);
283 evas_object_color_set(wd->hov, 0, 0, 0, 0);
284 elm_widget_resize_object_set(obj, wd->hov);
285 evas_object_event_callback_add(wd->hov, EVAS_CALLBACK_MOVE, _hov_move, obj);
286 evas_object_event_callback_add(wd->hov, EVAS_CALLBACK_RESIZE, _hov_resize, obj);
287 evas_object_event_callback_add(wd->hov, EVAS_CALLBACK_SHOW, _hov_show, obj);
288 evas_object_event_callback_add(wd->hov, EVAS_CALLBACK_HIDE, _hov_hide, obj);
290 wd->cov = edje_object_add(e);
291 _elm_theme_object_set(obj, wd->cov, "hover", "base", "default");
292 elm_widget_sub_object_add(obj, wd->cov);
293 edje_object_signal_callback_add(wd->cov, "elm,action,dismiss", "",
294 _signal_dismiss, obj);
296 wd->offset = evas_object_rectangle_add(e);
297 evas_object_pass_events_set(wd->offset, 1);
298 evas_object_color_set(wd->offset, 0, 0, 0, 0);
299 elm_widget_sub_object_add(obj, wd->offset);
301 wd->size = evas_object_rectangle_add(e);
302 evas_object_pass_events_set(wd->size, 1);
303 evas_object_color_set(wd->size, 0, 0, 0, 0);
304 elm_widget_sub_object_add(obj, wd->size);
306 edje_object_part_swallow(wd->cov, "elm.swallow.offset", wd->offset);
307 edje_object_part_swallow(wd->cov, "elm.swallow.size", wd->size);
309 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
316 * Sets the target object for the hover.
318 * @param obj The hover object
319 * @param target The object to center the hover onto. The hover
320 * will take up the entire space that the target object fills.
325 elm_hover_target_set(Evas_Object *obj, Evas_Object *target)
327 ELM_CHECK_WIDTYPE(obj, widtype);
328 Widget_Data *wd = elm_widget_data_get(obj);
331 evas_object_event_callback_del_full(wd->target, EVAS_CALLBACK_DEL,
336 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_DEL,
338 elm_widget_hover_object_set(target, obj);
345 * Sets the parent object for the hover.
347 * @param obj The hover object
348 * @param parent The object to locate the hover over.
353 elm_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
355 ELM_CHECK_WIDTYPE(obj, widtype);
356 Widget_Data *wd = elm_widget_data_get(obj);
360 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_MOVE,
362 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
363 _parent_resize, obj);
364 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_SHOW,
366 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_HIDE,
368 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL,
374 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_MOVE,
376 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE,
377 _parent_resize, obj);
378 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_SHOW,
380 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_HIDE,
382 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL,
384 // elm_widget_sub_object_add(parent, obj);
390 * Gets the target object for the hover.
392 * @param obj The hover object
393 * @return The target object of the hover.
398 elm_hover_target_get(Evas_Object *obj)
400 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
401 Widget_Data *wd = elm_widget_data_get(obj);
402 if (!wd) return NULL;
408 * Gets the parent object for the hover.
410 * @param obj The hover object
411 * @return The parent object to locate the hover over.
416 elm_hover_parent_get(Evas_Object *obj)
418 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
419 Widget_Data *wd = elm_widget_data_get(obj);
420 if (!wd) return NULL;
426 * Sets the content of the hover object and the direction in which
429 * @param obj The hover object
430 * @param swallow The direction that the object will display in. Multiple
431 * objects can have the same swallow location. Objects placed in the same
432 * swallow will be placed starting at the middle of the hover and ending
433 * farther from the middle.
434 * Accepted values are "left" "right" "top" "bottom" "middle"
435 * @param content The content to place at @p swallow
440 elm_hover_content_set(Evas_Object *obj, const char *swallow, Evas_Object *content)
442 ELM_CHECK_WIDTYPE(obj, widtype);
443 Widget_Data *wd = elm_widget_data_get(obj);
448 snprintf(buf, sizeof(buf), "elm.swallow.slot.%s", swallow);
449 EINA_LIST_FOREACH(wd->subs, l, si)
451 if (!strcmp(buf, si->swallow))
453 if (content == si->obj) return;
454 elm_widget_sub_object_del(obj, si->obj);
460 elm_widget_sub_object_add(obj, content);
461 edje_object_part_swallow(wd->cov, buf, content);
462 si = ELM_NEW(Subinfo);
463 si->swallow = eina_stringshare_add(buf);
465 wd->subs = eina_list_append(wd->subs, si);
471 * Returns the best swallow location for content in the hover.
473 * @param obj The hover object
474 * @return The edje location to place content into the hover.
475 * See also elm_hover_content_set()
480 elm_hover_best_content_location_get(const Evas_Object *obj, Elm_Hover_Axis pref_axis)
482 ELM_CHECK_WIDTYPE(obj, widtype) "left";
483 Widget_Data *wd = elm_widget_data_get(obj);
484 Evas_Coord x = 0, y = 0, w = 0, h = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0;
485 Evas_Coord spc_l, spc_r, spc_t, spc_b;
486 if (!wd) return "left";
487 if (wd->parent) evas_object_geometry_get(wd->parent, &x, &y, &w, &h);
488 if (wd->target) evas_object_geometry_get(wd->target, &x2, &y2, &w2, &h2);
490 spc_r = (x + w) - (x2 + w2);
491 if (spc_l < 0) spc_l = 0;
492 if (spc_r < 0) spc_r = 0;
494 spc_b = (y + h) - (y2 + h2);
495 if (spc_t < 0) spc_t = 0;
496 if (spc_b < 0) spc_b = 0;
497 if (pref_axis == ELM_HOVER_AXIS_HORIZONTAL)
499 if (spc_l < spc_r) return "right";
502 else if (pref_axis == ELM_HOVER_AXIS_VERTICAL)
504 if (spc_t < spc_b) return "bottom";
509 if (spc_t > spc_r) return "top";
510 else if (spc_b > spc_r) return "bottom";
513 if (spc_t > spc_r) return "top";
514 else if (spc_b > spc_r) return "bottom";