1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
8 Evas_Object *btn, *hover;
9 Evas_Object *hover_parent;
11 Eina_Bool horizontal : 1;
12 Eina_Bool expanded : 1;
15 struct _Elm_Hoversel_Item
19 const char *icon_file;
20 const char *icon_group;
21 Elm_Icon_Type icon_type;
25 static const char *widtype = NULL;
26 static void _del_pre_hook(Evas_Object *obj);
27 static void _del_hook(Evas_Object *obj);
28 static void _activate(Evas_Object *obj);
29 static void _activate_hook(Evas_Object *obj);
30 static void _disable_hook(Evas_Object *obj);
31 static void _sizing_eval(Evas_Object *obj);
32 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
33 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
35 static const char SIG_CLICKED[] = "clicked";
36 static const char SIG_SELECTED[] = "selected";
37 static const char SIG_DISMISSED[] = "dismissed";
39 static const Evas_Smart_Cb_Description _signals[] = {
47 _del_pre_hook(Evas_Object *obj)
49 Elm_Hoversel_Item *item;
50 Widget_Data *wd = elm_widget_data_get(obj);
52 elm_hoversel_hover_end(obj);
53 elm_hoversel_hover_parent_set(obj, NULL);
54 EINA_LIST_FREE(wd->items, item)
56 elm_widget_item_pre_notify_del(item);
57 eina_stringshare_del(item->label);
58 eina_stringshare_del(item->icon_file);
59 eina_stringshare_del(item->icon_group);
60 elm_widget_item_del(item);
65 _del_hook(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
73 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
75 Widget_Data *wd = elm_widget_data_get(obj);
77 elm_widget_mirrored_set(wd->btn, rtl);
78 elm_widget_mirrored_set(wd->hover, rtl);
82 _theme_hook(Evas_Object *obj)
84 Widget_Data *wd = elm_widget_data_get(obj);
87 _elm_widget_mirrored_reload(obj);
89 elm_hoversel_hover_end(obj);
91 snprintf(buf, sizeof(buf), "hoversel_horizontal/%s", elm_widget_style_get(obj));
93 snprintf(buf, sizeof(buf), "hoversel_vertical/%s", elm_widget_style_get(obj));
94 elm_object_style_set(wd->btn, buf);
95 elm_object_disabled_set(wd->btn, elm_widget_disabled_get(obj));
96 _mirrored_set(obj, elm_widget_mirrored_get(obj));
100 _disable_hook(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
104 elm_object_disabled_set(wd->btn, elm_widget_disabled_get(obj));
108 _sizing_eval(Evas_Object *obj)
110 Widget_Data *wd = elm_widget_data_get(obj);
111 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
113 evas_object_size_hint_min_get(wd->btn, &minw, &minh);
114 evas_object_size_hint_max_get(wd->btn, &maxw, &maxh);
115 evas_object_size_hint_min_set(obj, minw, minh);
116 evas_object_size_hint_max_set(obj, maxw, maxh);
120 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
122 Widget_Data *wd = elm_widget_data_get(obj);
124 if (elm_widget_focus_get(obj))
125 elm_widget_focus_steal(wd->btn);
129 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
135 _hover_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
137 elm_hoversel_hover_end(data);
141 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
143 Elm_Hoversel_Item *item = data;
144 Evas_Object *obj2 = WIDGET(item);
146 elm_hoversel_hover_end(obj2);
147 if (item->func) item->func((void *)item->base.data, obj2, item);
148 evas_object_smart_callback_call(obj2, SIG_SELECTED, item);
152 _activate(Evas_Object *obj)
154 Widget_Data *wd = elm_widget_data_get(obj);
155 Evas_Object *bt, *bx, *ic;
157 const Elm_Hoversel_Item *item;
163 elm_hoversel_hover_end(obj);
166 wd->expanded = EINA_TRUE;
168 if (elm_widget_disabled_get(obj)) return;
169 wd->hover = elm_hover_add(obj);
170 elm_widget_mirrored_automatic_set(wd->hover, EINA_FALSE);
172 snprintf(buf, sizeof(buf), "hoversel_horizontal/%s", elm_widget_style_get(obj));
174 snprintf(buf, sizeof(buf), "hoversel_vertical/%s", elm_widget_style_get(obj));
175 elm_object_style_set(wd->hover, buf);
176 evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked, obj);
177 elm_hover_parent_set(wd->hover, wd->hover_parent);
178 elm_hover_target_set(wd->hover, wd->btn);
180 bx = elm_box_add(wd->hover);
181 elm_widget_mirrored_automatic_set(bx, EINA_FALSE);
182 elm_box_homogeneous_set(bx, 1);
184 elm_box_horizontal_set(bx, wd->horizontal);
187 snprintf(buf, sizeof(buf), "hoversel_horizontal_entry/%s",
188 elm_widget_style_get(obj));
190 snprintf(buf, sizeof(buf), "hoversel_vertical_entry/%s",
191 elm_widget_style_get(obj));
192 EINA_LIST_FOREACH(wd->items, l, item)
194 bt = elm_button_add(wd->hover);
195 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
196 elm_widget_mirrored_set(bt, elm_widget_mirrored_get(obj));
197 elm_object_style_set(bt, buf);
198 elm_object_text_set(bt, item->label);
201 ic = elm_icon_add(obj);
202 elm_icon_scale_set(ic, 0, 1);
203 if (item->icon_type == ELM_ICON_FILE)
204 elm_icon_file_set(ic, item->icon_file, item->icon_group);
205 else if (item->icon_type == ELM_ICON_STANDARD)
206 elm_icon_standard_set(ic, item->icon_file);
207 elm_button_icon_set(bt, ic);
208 evas_object_show(ic);
210 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
211 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
212 elm_box_pack_end(bx, bt);
213 evas_object_smart_callback_add(bt, "clicked", _item_clicked, item);
214 evas_object_show(bt);
218 elm_hover_content_set(wd->hover,
219 elm_hover_best_content_location_get(wd->hover,
220 ELM_HOVER_AXIS_HORIZONTAL),
223 elm_hover_content_set(wd->hover,
224 elm_hover_best_content_location_get(wd->hover,
225 ELM_HOVER_AXIS_VERTICAL),
227 evas_object_show(bx);
229 evas_object_show(wd->hover);
230 evas_object_smart_callback_call(obj, SIG_CLICKED, NULL);
232 // if (wd->horizontal) evas_object_hide(wd->btn);
236 _activate_hook(Evas_Object *obj)
242 _button_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
248 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
250 Widget_Data *wd = elm_widget_data_get(data);
252 wd->hover_parent = NULL;
256 _elm_hoversel_label_set(Evas_Object *obj, const char *item, const char *label)
258 ELM_CHECK_WIDTYPE(obj, widtype);
259 Widget_Data *wd = elm_widget_data_get(obj);
260 if (item && strcmp(item, "default")) return;
262 elm_object_text_set(wd->btn, label);
266 _elm_hoversel_label_get(const Evas_Object *obj, const char *item)
268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
269 Widget_Data *wd = elm_widget_data_get(obj);
270 if (item && strcmp(item, "default")) return NULL;
271 if ((!wd) || (!wd->btn)) return NULL;
272 return elm_object_text_get(wd->btn);
276 elm_hoversel_add(Evas_Object *parent)
282 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
284 ELM_SET_WIDTYPE(widtype, "hoversel");
285 elm_widget_type_set(obj, "hoversel");
286 elm_widget_sub_object_add(parent, obj);
287 elm_widget_data_set(obj, wd);
288 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
289 elm_widget_del_hook_set(obj, _del_hook);
290 elm_widget_theme_hook_set(obj, _theme_hook);
291 elm_widget_disable_hook_set(obj, _disable_hook);
292 elm_widget_activate_hook_set(obj, _activate_hook);
293 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
294 elm_widget_can_focus_set(obj, EINA_TRUE);
295 elm_widget_text_set_hook_set(obj, _elm_hoversel_label_set);
296 elm_widget_text_get_hook_set(obj, _elm_hoversel_label_get);
298 wd->btn = elm_button_add(parent);
299 elm_widget_mirrored_automatic_set(wd->btn, EINA_FALSE);
300 wd->expanded = EINA_FALSE;
301 elm_widget_resize_object_set(obj, wd->btn);
302 evas_object_event_callback_add(wd->btn, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
303 _changed_size_hints, obj);
304 evas_object_smart_callback_add(wd->btn, "clicked", _button_clicked, obj);
305 evas_object_smart_callbacks_descriptions_set(obj, _signals);
307 elm_widget_sub_object_add(obj, wd->btn);
309 elm_hoversel_hover_parent_set(obj, parent);
316 elm_hoversel_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
318 ELM_CHECK_WIDTYPE(obj, widtype);
319 Widget_Data *wd = elm_widget_data_get(obj);
321 if (wd->hover_parent)
322 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
324 wd->hover_parent = parent;
325 if (wd->hover_parent)
326 evas_object_event_callback_add(wd->hover_parent, EVAS_CALLBACK_DEL,
331 elm_hoversel_hover_parent_get(const Evas_Object *obj)
333 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
334 Widget_Data *wd = elm_widget_data_get(obj);
335 if (!wd) return NULL;
336 return wd->hover_parent;
340 elm_hoversel_label_set(Evas_Object *obj, const char *label)
342 _elm_hoversel_label_set(obj, NULL, label);
346 elm_hoversel_label_get(const Evas_Object *obj)
348 return _elm_hoversel_label_get(obj, NULL);
352 elm_hoversel_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
354 ELM_CHECK_WIDTYPE(obj, widtype);
355 Widget_Data *wd = elm_widget_data_get(obj);
357 wd->horizontal = !!horizontal;
361 elm_hoversel_horizontal_get(const Evas_Object *obj)
363 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
364 Widget_Data *wd = elm_widget_data_get(obj);
365 if (!wd) return EINA_FALSE;
366 return wd->horizontal;
370 elm_hoversel_icon_set(Evas_Object *obj, Evas_Object *icon)
372 ELM_CHECK_WIDTYPE(obj, widtype);
373 Widget_Data *wd = elm_widget_data_get(obj);
375 elm_button_icon_set(wd->btn, icon);
379 elm_hoversel_icon_get(const Evas_Object *obj)
381 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
382 Widget_Data *wd = elm_widget_data_get(obj);
383 if ((!wd) || (!wd->btn)) return NULL;
384 return elm_button_icon_get(wd->btn);
388 elm_hoversel_icon_unset(Evas_Object *obj)
390 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
391 Widget_Data *wd = elm_widget_data_get(obj);
392 if ((!wd) || (!wd->btn)) return NULL;
393 return elm_button_icon_unset(wd->btn);
397 elm_hoversel_hover_begin(Evas_Object *obj)
399 ELM_CHECK_WIDTYPE(obj, widtype);
400 Widget_Data *wd = elm_widget_data_get(obj);
402 if (wd->hover) return;
407 elm_hoversel_hover_end(Evas_Object *obj)
409 ELM_CHECK_WIDTYPE(obj, widtype);
410 Widget_Data *wd = elm_widget_data_get(obj);
412 if (!wd->hover) return;
413 wd->expanded = EINA_FALSE;
414 evas_object_del(wd->hover);
416 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
420 elm_hoversel_expanded_get(const Evas_Object *obj)
422 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
423 Widget_Data *wd = elm_widget_data_get(obj);
424 if (!wd) return EINA_FALSE;
425 return (wd->hover) ? EINA_TRUE : EINA_FALSE;
429 elm_hoversel_clear(Evas_Object *obj)
431 Elm_Hoversel_Item *item;
433 ELM_CHECK_WIDTYPE(obj, widtype);
434 Widget_Data *wd = elm_widget_data_get(obj);
436 EINA_LIST_FOREACH_SAFE(wd->items, l, ll, item) elm_hoversel_item_del(item);
439 EAPI const Eina_List *
440 elm_hoversel_items_get(const Evas_Object *obj)
442 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
443 Widget_Data *wd = elm_widget_data_get(obj);
444 if (!wd) return NULL;
448 EAPI Elm_Hoversel_Item *
449 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)
451 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
452 Widget_Data *wd = elm_widget_data_get(obj);
453 if (!wd) return NULL;
454 Elm_Hoversel_Item *item = elm_widget_item_new(obj, Elm_Hoversel_Item);
455 if (!item) return NULL;
456 wd->items = eina_list_append(wd->items, item);
457 item->label = eina_stringshare_add(label);
458 item->icon_file = eina_stringshare_add(icon_file);
459 item->icon_type = icon_type;
461 item->base.data = data;
466 elm_hoversel_item_del(Elm_Hoversel_Item *item)
468 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
469 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
471 elm_hoversel_hover_end(WIDGET(item));
472 wd->items = eina_list_remove(wd->items, item);
473 elm_widget_item_pre_notify_del(item);
474 eina_stringshare_del(item->label);
475 eina_stringshare_del(item->icon_file);
476 eina_stringshare_del(item->icon_group);
477 elm_widget_item_del(item);
481 elm_hoversel_item_del_cb_set(Elm_Hoversel_Item *item, Evas_Smart_Cb func)
483 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
484 elm_widget_item_del_cb_set(item, func);
488 elm_hoversel_item_data_get(const Elm_Hoversel_Item *item)
490 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
491 return elm_widget_item_data_get(item);
495 elm_hoversel_item_label_get(const Elm_Hoversel_Item *item)
497 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
502 elm_hoversel_item_icon_set(Elm_Hoversel_Item *item, const char *icon_file, const char *icon_group, Elm_Icon_Type icon_type)
504 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
505 eina_stringshare_replace(&item->icon_file, icon_file);
506 eina_stringshare_replace(&item->icon_group, icon_group);
507 item->icon_type = icon_type;
511 elm_hoversel_item_icon_get(const Elm_Hoversel_Item *item, const char **icon_file, const char **icon_group, Elm_Icon_Type *icon_type)
513 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
514 if (icon_file) *icon_file = item->icon_file;
515 if (icon_group) *icon_group = item->icon_group;
516 if (icon_type) *icon_type = item->icon_type;