1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
9 Evas_Object *content, *icon;
10 const char *label, *info, *corner;
13 static const char *widtype = NULL;
14 static void _del_hook(Evas_Object *obj);
15 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
16 static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
17 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
18 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
19 static void _theme_hook(Evas_Object *obj);
20 static void _sizing_eval(Evas_Object *obj);
21 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
22 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
24 static const char SIG_CLICKED[] = "clicked";
26 static const Evas_Smart_Cb_Description _signals[] =
33 _del_hook(Evas_Object *obj)
35 Widget_Data *wd = elm_widget_data_get(obj);
37 if (wd->label) eina_stringshare_del(wd->label);
38 if (wd->info) eina_stringshare_del(wd->info);
39 if (wd->corner) eina_stringshare_del(wd->corner);
44 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
46 Widget_Data *wd = elm_widget_data_get(obj);
48 edje_object_mirrored_set(wd->bbl, rtl);
52 _theme_hook(Evas_Object *obj)
54 Widget_Data *wd = elm_widget_data_get(obj);
56 _elm_widget_mirrored_reload(obj);
57 _mirrored_set(obj, elm_widget_mirrored_get(obj));
58 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
59 elm_widget_style_get(obj));
60 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
61 if (wd->label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
62 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
63 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
64 if (wd->info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
65 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
68 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
69 edje_object_message_signal_process(wd->bbl);
72 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
74 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
75 edje_object_scale_set(wd->bbl,
76 elm_widget_scale_get(obj) * _elm_config->scale);
81 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__, Evas_Object *content)
83 ELM_CHECK_WIDTYPE(obj, widtype);
84 Widget_Data *wd = elm_widget_data_get(obj);
86 if (wd->content == content) return;
87 if (wd->content) evas_object_del(wd->content);
88 wd->content = content;
91 elm_widget_sub_object_add(obj, content);
92 evas_object_event_callback_add(content,
93 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
94 _changed_size_hints, obj);
95 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
101 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
103 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
104 Widget_Data *wd = elm_widget_data_get(obj);
105 if (!wd) return NULL;
110 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
112 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
113 Widget_Data *wd = elm_widget_data_get(obj);
114 Evas_Object *content;
115 if (!wd) return NULL;
116 if (!wd->content) return NULL;
117 content = wd->content;
118 elm_widget_sub_object_del(obj, content);
119 evas_object_event_callback_del_full(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
120 _changed_size_hints, obj);
121 edje_object_part_unswallow(wd->bbl, content);
127 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
129 Widget_Data *wd = elm_widget_data_get(obj);
132 if ((!wd) || (!wd->content))
137 /* Try Focus cycle in subitem */
138 return elm_widget_focus_next_get(cur, dir, next);
142 _sizing_eval(Evas_Object *obj)
144 Widget_Data *wd = elm_widget_data_get(obj);
145 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
147 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
148 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
149 evas_object_size_hint_min_set(obj, minw, minh);
150 evas_object_size_hint_max_set(obj, maxw, maxh);
154 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
156 Widget_Data *wd = elm_widget_data_get(data);
162 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
164 Widget_Data *wd = elm_widget_data_get(obj);
165 Evas_Object *sub = event_info;
167 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
168 _changed_size_hints, obj);
169 if (sub == wd->content) wd->content = NULL;
170 else if (sub == wd->icon)
172 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
174 edje_object_message_signal_process(wd->bbl);
180 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
182 Evas_Event_Mouse_Up *ev = event_info;
183 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
185 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
189 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
191 ELM_CHECK_WIDTYPE(obj, widtype);
192 Widget_Data *wd = elm_widget_data_get(obj);
195 if (!item || !strcmp(item, "default"))
197 eina_stringshare_replace(&wd->label, label);
198 edje_object_part_text_set(wd->bbl, "elm.text", label);
199 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
201 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
204 else if (!strcmp(item, "info"))
206 eina_stringshare_replace(&wd->info, label);
207 edje_object_part_text_set(wd->bbl, "elm.info", label);
208 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
210 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
216 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
218 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
219 Widget_Data *wd = elm_widget_data_get(obj);
220 if (!wd) return NULL;
222 if (!item || !strcmp(item, "default"))
226 else if (!strcmp(item, "info"))
235 elm_bubble_add(Evas_Object *parent)
241 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
243 ELM_SET_WIDTYPE(widtype, "bubble");
244 elm_widget_type_set(obj, "bubble");
245 elm_widget_sub_object_add(parent, obj);
246 elm_widget_data_set(obj, wd);
247 elm_widget_del_hook_set(obj, _del_hook);
248 elm_widget_theme_hook_set(obj, _theme_hook);
249 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
250 elm_widget_can_focus_set(obj, EINA_FALSE);
251 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
252 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
253 elm_widget_content_set_hook_set(obj, _content_set_hook);
254 elm_widget_content_get_hook_set(obj, _content_get_hook);
255 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
257 wd->corner = eina_stringshare_add("base");
259 wd->bbl = edje_object_add(e);
260 elm_widget_resize_object_set(obj, wd->bbl);
262 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
263 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
266 evas_object_smart_callbacks_descriptions_set(obj, _signals);
267 _mirrored_set(obj, elm_widget_mirrored_get(obj));
268 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
269 elm_widget_style_get(obj));
275 elm_bubble_label_set(Evas_Object *obj, const char *label)
277 _elm_bubble_label_set(obj, NULL, label);
281 elm_bubble_label_get(const Evas_Object *obj)
283 return _elm_bubble_label_get(obj, NULL);
287 elm_bubble_info_set(Evas_Object *obj, const char *info)
289 _elm_bubble_label_set(obj, "info", info);
293 elm_bubble_info_get(const Evas_Object *obj)
295 return _elm_bubble_label_get(obj, "info");
299 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
301 _content_set_hook(obj, NULL, content);
305 elm_bubble_content_get(const Evas_Object *obj)
307 return _content_get_hook(obj, NULL);
311 elm_bubble_content_unset(Evas_Object *obj)
313 return _content_unset_hook(obj, NULL);
317 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
319 ELM_CHECK_WIDTYPE(obj, widtype);
320 Widget_Data *wd = elm_widget_data_get(obj);
322 if (wd->icon == icon) return;
323 if (wd->icon) evas_object_del(wd->icon);
327 elm_widget_sub_object_add(obj, icon);
328 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
329 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
330 _changed_size_hints, obj);
331 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
332 edje_object_message_signal_process(wd->bbl);
338 elm_bubble_icon_get(const Evas_Object *obj)
340 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
341 Widget_Data *wd = elm_widget_data_get(obj);
342 if (!wd) return NULL;
347 elm_bubble_icon_unset(Evas_Object *obj)
349 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
350 Widget_Data *wd = elm_widget_data_get(obj);
352 if (!wd) return NULL;
353 if (!wd->icon) return NULL;
355 elm_widget_sub_object_del(obj, icon);
356 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
357 _changed_size_hints, obj);
358 edje_object_part_unswallow(wd->bbl, icon);
364 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
366 ELM_CHECK_WIDTYPE(obj, widtype);
367 Widget_Data *wd = elm_widget_data_get(obj);
369 EINA_SAFETY_ON_NULL_RETURN(corner);
370 eina_stringshare_replace(&wd->corner, corner);
375 elm_bubble_corner_get(const Evas_Object *obj)
377 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
378 Widget_Data *wd = elm_widget_data_get(obj);
379 if (!wd) return NULL;