1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Hoversel_Item Elm_Hoversel_Item;
9 Evas_Object *btn, *hover;
10 Evas_Object *hover_parent;
12 Eina_Bool horizontal : 1;
13 Eina_Bool expanded : 1;
16 struct _Elm_Hoversel_Item
20 const char *icon_file;
21 const char *icon_group;
22 Elm_Icon_Type icon_type;
26 static const char *widtype = NULL;
27 static void _del_pre_hook(Evas_Object *obj);
28 static void _del_hook(Evas_Object *obj);
29 static void _activate(Evas_Object *obj);
30 static void _activate_hook(Evas_Object *obj);
31 static void _disable_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
34 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
36 static const char SIG_CLICKED[] = "clicked";
37 static const char SIG_SELECTED[] = "selected";
38 static const char SIG_DISMISSED[] = "dismissed";
40 static const Evas_Smart_Cb_Description _signals[] = {
48 _del_pre_hook(Evas_Object *obj)
50 Elm_Hoversel_Item *item;
51 Widget_Data *wd = elm_widget_data_get(obj);
53 evas_object_event_callback_del_full(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
54 _changed_size_hints, obj);
55 elm_hoversel_hover_end(obj);
56 elm_hoversel_hover_parent_set(obj, NULL);
57 EINA_LIST_FREE(wd->items, item)
59 elm_widget_item_pre_notify_del(item);
60 eina_stringshare_del(item->label);
61 eina_stringshare_del(item->icon_file);
62 eina_stringshare_del(item->icon_group);
63 elm_widget_item_del(item);
68 _del_hook(Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
76 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
78 Widget_Data *wd = elm_widget_data_get(obj);
80 elm_widget_mirrored_set(wd->btn, rtl);
81 elm_widget_mirrored_set(wd->hover, rtl);
85 _theme_hook(Evas_Object *obj)
87 Widget_Data *wd = elm_widget_data_get(obj);
90 _elm_widget_mirrored_reload(obj);
92 elm_hoversel_hover_end(obj);
94 snprintf(buf, sizeof(buf), "hoversel_horizontal/%s", elm_widget_style_get(obj));
96 snprintf(buf, sizeof(buf), "hoversel_vertical/%s", elm_widget_style_get(obj));
97 elm_object_style_set(wd->btn, buf);
98 elm_object_disabled_set(wd->btn, elm_widget_disabled_get(obj));
99 _mirrored_set(obj, elm_widget_mirrored_get(obj));
103 _disable_hook(Evas_Object *obj)
105 Widget_Data *wd = elm_widget_data_get(obj);
107 elm_object_disabled_set(wd->btn, elm_widget_disabled_get(obj));
111 _sizing_eval(Evas_Object *obj)
113 Widget_Data *wd = elm_widget_data_get(obj);
114 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
116 evas_object_size_hint_min_get(wd->btn, &minw, &minh);
117 evas_object_size_hint_max_get(wd->btn, &maxw, &maxh);
118 evas_object_size_hint_min_set(obj, minw, minh);
119 evas_object_size_hint_max_set(obj, maxw, maxh);
123 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
127 if (elm_widget_focus_get(obj))
128 elm_widget_focus_steal(wd->btn);
132 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
138 _hover_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
140 elm_hoversel_hover_end(data);
144 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
146 Elm_Hoversel_Item *item = data;
147 Evas_Object *obj2 = WIDGET(item);
149 elm_hoversel_hover_end(obj2);
150 if (item->func) item->func((void *)item->base.data, obj2, item);
151 evas_object_smart_callback_call(obj2, SIG_SELECTED, item);
155 _activate(Evas_Object *obj)
157 Widget_Data *wd = elm_widget_data_get(obj);
158 Evas_Object *bt, *bx, *ic;
160 const Elm_Hoversel_Item *item;
166 elm_hoversel_hover_end(obj);
169 wd->expanded = EINA_TRUE;
171 if (elm_widget_disabled_get(obj)) return;
172 wd->hover = elm_hover_add(obj);
173 elm_widget_mirrored_automatic_set(wd->hover, EINA_FALSE);
175 snprintf(buf, sizeof(buf), "hoversel_horizontal/%s", elm_widget_style_get(obj));
177 snprintf(buf, sizeof(buf), "hoversel_vertical/%s", elm_widget_style_get(obj));
178 elm_object_style_set(wd->hover, buf);
179 evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked, obj);
180 elm_hover_parent_set(wd->hover, wd->hover_parent);
181 elm_hover_target_set(wd->hover, wd->btn);
183 bx = elm_box_add(wd->hover);
184 elm_widget_mirrored_automatic_set(bx, EINA_FALSE);
185 elm_box_homogeneous_set(bx, 1);
187 elm_box_horizontal_set(bx, wd->horizontal);
190 snprintf(buf, sizeof(buf), "hoversel_horizontal_entry/%s",
191 elm_widget_style_get(obj));
193 snprintf(buf, sizeof(buf), "hoversel_vertical_entry/%s",
194 elm_widget_style_get(obj));
195 EINA_LIST_FOREACH(wd->items, l, item)
197 bt = elm_button_add(wd->hover);
198 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
199 elm_widget_mirrored_set(bt, elm_widget_mirrored_get(obj));
200 elm_object_style_set(bt, buf);
201 elm_object_text_set(bt, item->label);
204 ic = elm_icon_add(obj);
205 elm_icon_scale_set(ic, 0, 1);
206 if (item->icon_type == ELM_ICON_FILE)
207 elm_icon_file_set(ic, item->icon_file, item->icon_group);
208 else if (item->icon_type == ELM_ICON_STANDARD)
209 elm_icon_standard_set(ic, item->icon_file);
210 elm_object_part_content_set(bt, "icon", ic);
211 evas_object_show(ic);
213 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
214 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
215 elm_box_pack_end(bx, bt);
216 evas_object_smart_callback_add(bt, "clicked", _item_clicked, item);
217 evas_object_show(bt);
221 elm_hover_content_set(wd->hover,
222 elm_hover_best_content_location_get(wd->hover,
223 ELM_HOVER_AXIS_HORIZONTAL),
226 elm_hover_content_set(wd->hover,
227 elm_hover_best_content_location_get(wd->hover,
228 ELM_HOVER_AXIS_VERTICAL),
230 evas_object_show(bx);
232 evas_object_show(wd->hover);
233 evas_object_smart_callback_call(obj, SIG_CLICKED, NULL);
235 // if (wd->horizontal) evas_object_hide(wd->btn);
239 _activate_hook(Evas_Object *obj)
245 _button_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
251 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
253 Widget_Data *wd = elm_widget_data_get(data);
255 wd->hover_parent = NULL;
259 _elm_hoversel_label_set(Evas_Object *obj, const char *item, const char *label)
261 ELM_CHECK_WIDTYPE(obj, widtype);
262 Widget_Data *wd = elm_widget_data_get(obj);
263 if (item && strcmp(item, "default")) return;
265 elm_object_text_set(wd->btn, label);
269 _elm_hoversel_label_get(const Evas_Object *obj, const char *item)
271 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
272 Widget_Data *wd = elm_widget_data_get(obj);
273 if (item && strcmp(item, "default")) return NULL;
274 if ((!wd) || (!wd->btn)) return NULL;
275 return elm_object_text_get(wd->btn);
279 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
281 ELM_CHECK_WIDTYPE(obj, widtype);
282 Widget_Data *wd = elm_widget_data_get(obj);
284 elm_object_part_content_set(wd->btn, part, content);
288 _content_get_hook(const Evas_Object *obj, const char *part)
290 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
291 Widget_Data *wd = elm_widget_data_get(obj);
292 if ((!wd) || (!wd->btn)) return NULL;
293 return elm_object_part_content_get(wd->btn, part);
297 _content_unset_hook(Evas_Object *obj, const char *part)
299 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
300 Widget_Data *wd = elm_widget_data_get(obj);
301 if ((!wd) || (!wd->btn)) return NULL;
302 return elm_object_part_content_unset(wd->btn, part);
306 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
308 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
309 if (part && strcmp(part, "default")) return NULL;
310 return ((Elm_Hoversel_Item *) it)->label;
314 elm_hoversel_add(Evas_Object *parent)
320 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
322 ELM_SET_WIDTYPE(widtype, "hoversel");
323 elm_widget_type_set(obj, "hoversel");
324 elm_widget_sub_object_add(parent, obj);
325 elm_widget_data_set(obj, wd);
326 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
327 elm_widget_del_hook_set(obj, _del_hook);
328 elm_widget_theme_hook_set(obj, _theme_hook);
329 elm_widget_disable_hook_set(obj, _disable_hook);
330 elm_widget_activate_hook_set(obj, _activate_hook);
331 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
332 elm_widget_can_focus_set(obj, EINA_TRUE);
333 elm_widget_text_set_hook_set(obj, _elm_hoversel_label_set);
334 elm_widget_text_get_hook_set(obj, _elm_hoversel_label_get);
335 elm_widget_content_set_hook_set(obj, _content_set_hook);
336 elm_widget_content_get_hook_set(obj, _content_get_hook);
337 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
339 wd->btn = elm_button_add(parent);
340 elm_widget_mirrored_automatic_set(wd->btn, EINA_FALSE);
341 wd->expanded = EINA_FALSE;
342 elm_widget_resize_object_set(obj, wd->btn);
343 evas_object_event_callback_add(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
344 _changed_size_hints, obj);
345 evas_object_smart_callback_add(wd->btn, "clicked", _button_clicked, obj);
346 evas_object_smart_callbacks_descriptions_set(obj, _signals);
348 elm_widget_sub_object_add(obj, wd->btn);
350 elm_hoversel_hover_parent_set(obj, parent);
357 elm_hoversel_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
359 ELM_CHECK_WIDTYPE(obj, widtype);
360 Widget_Data *wd = elm_widget_data_get(obj);
362 if (wd->hover_parent)
363 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
365 wd->hover_parent = parent;
366 if (wd->hover_parent)
367 evas_object_event_callback_add(wd->hover_parent, EVAS_CALLBACK_DEL,
372 elm_hoversel_hover_parent_get(const Evas_Object *obj)
374 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
375 Widget_Data *wd = elm_widget_data_get(obj);
376 if (!wd) return NULL;
377 return wd->hover_parent;
381 elm_hoversel_label_set(Evas_Object *obj, const char *label)
383 _elm_hoversel_label_set(obj, NULL, label);
387 elm_hoversel_label_get(const Evas_Object *obj)
389 return _elm_hoversel_label_get(obj, NULL);
393 elm_hoversel_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
395 ELM_CHECK_WIDTYPE(obj, widtype);
396 Widget_Data *wd = elm_widget_data_get(obj);
398 wd->horizontal = !!horizontal;
402 elm_hoversel_horizontal_get(const Evas_Object *obj)
404 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
405 Widget_Data *wd = elm_widget_data_get(obj);
406 if (!wd) return EINA_FALSE;
407 return wd->horizontal;
411 elm_hoversel_icon_set(Evas_Object *obj, Evas_Object *icon)
413 _content_set_hook(obj, "icon", icon);
417 elm_hoversel_icon_get(const Evas_Object *obj)
419 _content_get_hook(obj, "icon");
423 elm_hoversel_icon_unset(Evas_Object *obj)
425 _content_unset_hook(obj, "icon");
429 elm_hoversel_hover_begin(Evas_Object *obj)
431 ELM_CHECK_WIDTYPE(obj, widtype);
432 Widget_Data *wd = elm_widget_data_get(obj);
434 if (wd->hover) return;
439 elm_hoversel_hover_end(Evas_Object *obj)
441 ELM_CHECK_WIDTYPE(obj, widtype);
442 Widget_Data *wd = elm_widget_data_get(obj);
444 if (!wd->hover) return;
445 wd->expanded = EINA_FALSE;
446 evas_object_del(wd->hover);
448 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
452 elm_hoversel_expanded_get(const Evas_Object *obj)
454 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
455 Widget_Data *wd = elm_widget_data_get(obj);
456 if (!wd) return EINA_FALSE;
457 return (wd->hover) ? EINA_TRUE : EINA_FALSE;
461 elm_hoversel_clear(Evas_Object *obj)
465 ELM_CHECK_WIDTYPE(obj, widtype);
466 Widget_Data *wd = elm_widget_data_get(obj);
468 EINA_LIST_FOREACH_SAFE(wd->items, l, ll, it) elm_hoversel_item_del(it);
471 EAPI const Eina_List *
472 elm_hoversel_items_get(const Evas_Object *obj)
474 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
475 Widget_Data *wd = elm_widget_data_get(obj);
476 if (!wd) return NULL;
480 EAPI Elm_Object_Item *
481 elm_hoversel_item_add(Evas_Object *obj, const char *label, const char *icon_file, Elm_Icon_Type icon_type, Evas_Smart_Cb func, const void *data)
483 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
484 Widget_Data *wd = elm_widget_data_get(obj);
485 if (!wd) return NULL;
486 Elm_Hoversel_Item *item = elm_widget_item_new(obj, Elm_Hoversel_Item);
487 if (!item) return NULL;
488 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
489 wd->items = eina_list_append(wd->items, item);
490 item->label = eina_stringshare_add(label);
491 item->icon_file = eina_stringshare_add(icon_file);
492 item->icon_type = icon_type;
494 item->base.data = data;
495 return (Elm_Object_Item *) item;
499 elm_hoversel_item_del(Elm_Object_Item *it)
501 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
503 Elm_Hoversel_Item *item = (Elm_Hoversel_Item *) it;
504 wd = elm_widget_data_get(WIDGET(item));
506 elm_hoversel_hover_end(WIDGET(item));
507 wd->items = eina_list_remove(wd->items, item);
508 elm_widget_item_pre_notify_del(item);
509 eina_stringshare_del(item->label);
510 eina_stringshare_del(item->icon_file);
511 eina_stringshare_del(item->icon_group);
512 elm_widget_item_del(item);
516 elm_hoversel_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
518 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
519 elm_widget_item_del_cb_set(it, func);
523 elm_hoversel_item_data_get(const Elm_Object_Item *it)
525 return elm_object_item_data_get(it);
529 elm_hoversel_item_label_get(const Elm_Object_Item *it)
531 return _item_text_get_hook(it, NULL);
535 elm_hoversel_item_icon_set(Elm_Object_Item *it, const char *icon_file, const char *icon_group, Elm_Icon_Type icon_type)
537 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
538 Elm_Hoversel_Item *item = (Elm_Hoversel_Item *) it;
539 eina_stringshare_replace(&item->icon_file, icon_file);
540 eina_stringshare_replace(&item->icon_group, icon_group);
541 item->icon_type = icon_type;
545 elm_hoversel_item_icon_get(const Elm_Object_Item *it, const char **icon_file, const char **icon_group, Elm_Icon_Type *icon_type)
547 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
548 Elm_Hoversel_Item *item = (Elm_Hoversel_Item *) it;
549 if (icon_file) *icon_file = item->icon_file;
550 if (icon_group) *icon_group = item->icon_group;
551 if (icon_type) *icon_type = item->icon_type;