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 _theme_hook(Evas_Object *obj);
17 static void _sizing_eval(Evas_Object *obj);
18 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
19 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
21 static const char SIG_CLICKED[] = "clicked";
23 static const Evas_Smart_Cb_Description _signals[] =
30 _del_hook(Evas_Object *obj)
32 Widget_Data *wd = elm_widget_data_get(obj);
34 if (wd->label) eina_stringshare_del(wd->label);
35 if (wd->info) eina_stringshare_del(wd->info);
36 if (wd->corner) eina_stringshare_del(wd->corner);
41 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
43 Widget_Data *wd = elm_widget_data_get(obj);
45 edje_object_mirrored_set(wd->bbl, rtl);
49 _theme_hook(Evas_Object *obj)
51 Widget_Data *wd = elm_widget_data_get(obj);
53 _elm_widget_mirrored_reload(obj);
54 _mirrored_set(obj, elm_widget_mirrored_get(obj));
55 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
56 elm_widget_style_get(obj));
57 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
58 if (wd->label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
59 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
60 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
61 if (wd->info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
62 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
65 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
66 edje_object_message_signal_process(wd->bbl);
69 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
71 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
72 edje_object_scale_set(wd->bbl,
73 elm_widget_scale_get(obj) * _elm_config->scale);
78 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
80 Widget_Data *wd = elm_widget_data_get(obj);
83 if ((!wd) || (!wd->content))
88 /* Try Focus cycle in subitem */
89 return elm_widget_focus_next_get(cur, dir, next);
93 _sizing_eval(Evas_Object *obj)
95 Widget_Data *wd = elm_widget_data_get(obj);
96 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
98 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
99 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
100 evas_object_size_hint_min_set(obj, minw, minh);
101 evas_object_size_hint_max_set(obj, maxw, maxh);
105 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
107 Widget_Data *wd = elm_widget_data_get(data);
113 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
115 Widget_Data *wd = elm_widget_data_get(obj);
116 Evas_Object *sub = event_info;
118 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
119 _changed_size_hints, obj);
120 if (sub == wd->content) wd->content = NULL;
121 else if (sub == wd->icon)
123 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
125 edje_object_message_signal_process(wd->bbl);
131 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
133 Evas_Event_Mouse_Up *ev = event_info;
134 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
136 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
140 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
142 ELM_CHECK_WIDTYPE(obj, widtype);
143 Widget_Data *wd = elm_widget_data_get(obj);
146 if (!item || !strcmp(item, "default"))
148 eina_stringshare_replace(&wd->label, label);
149 edje_object_part_text_set(wd->bbl, "elm.text", label);
150 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
152 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
155 else if (!strcmp(item, "info"))
157 eina_stringshare_replace(&wd->info, label);
158 edje_object_part_text_set(wd->bbl, "elm.info", label);
159 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
161 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
167 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
169 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
170 Widget_Data *wd = elm_widget_data_get(obj);
171 if (!wd) return NULL;
173 if (!item || !strcmp(item, "default"))
177 else if (!strcmp(item, "info"))
186 elm_bubble_add(Evas_Object *parent)
192 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
194 ELM_SET_WIDTYPE(widtype, "bubble");
195 elm_widget_type_set(obj, "bubble");
196 elm_widget_sub_object_add(parent, obj);
197 elm_widget_data_set(obj, wd);
198 elm_widget_del_hook_set(obj, _del_hook);
199 elm_widget_theme_hook_set(obj, _theme_hook);
200 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
201 elm_widget_can_focus_set(obj, EINA_FALSE);
202 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
203 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
205 wd->corner = eina_stringshare_add("base");
207 wd->bbl = edje_object_add(e);
208 elm_widget_resize_object_set(obj, wd->bbl);
210 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
211 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
214 evas_object_smart_callbacks_descriptions_set(obj, _signals);
215 _mirrored_set(obj, elm_widget_mirrored_get(obj));
216 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
217 elm_widget_style_get(obj));
223 elm_bubble_label_set(Evas_Object *obj, const char *label)
225 _elm_bubble_label_set(obj, NULL, label);
229 elm_bubble_label_get(const Evas_Object *obj)
231 return _elm_bubble_label_get(obj, NULL);
235 elm_bubble_info_set(Evas_Object *obj, const char *info)
237 _elm_bubble_label_set(obj, "info", info);
241 elm_bubble_info_get(const Evas_Object *obj)
243 return _elm_bubble_label_get(obj, "info");
247 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
249 ELM_CHECK_WIDTYPE(obj, widtype);
250 Widget_Data *wd = elm_widget_data_get(obj);
252 if (wd->content == content) return;
253 if (wd->content) evas_object_del(wd->content);
254 wd->content = content;
257 elm_widget_sub_object_add(obj, content);
258 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
259 _changed_size_hints, obj);
260 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
266 elm_bubble_content_get(const Evas_Object *obj)
268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
269 Widget_Data *wd = elm_widget_data_get(obj);
270 if (!wd) return NULL;
275 elm_bubble_content_unset(Evas_Object *obj)
277 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
278 Widget_Data *wd = elm_widget_data_get(obj);
279 Evas_Object *content;
280 if (!wd) return NULL;
281 if (!wd->content) return NULL;
282 content = wd->content;
283 elm_widget_sub_object_del(obj, content);
284 evas_object_event_callback_del_full(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
285 _changed_size_hints, obj);
286 edje_object_part_unswallow(wd->bbl, content);
292 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
294 ELM_CHECK_WIDTYPE(obj, widtype);
295 Widget_Data *wd = elm_widget_data_get(obj);
297 if (wd->icon == icon) return;
298 if (wd->icon) evas_object_del(wd->icon);
302 elm_widget_sub_object_add(obj, icon);
303 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
304 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
305 _changed_size_hints, obj);
306 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
307 edje_object_message_signal_process(wd->bbl);
313 elm_bubble_icon_get(const Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
316 Widget_Data *wd = elm_widget_data_get(obj);
317 if (!wd) return NULL;
322 elm_bubble_icon_unset(Evas_Object *obj)
324 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
325 Widget_Data *wd = elm_widget_data_get(obj);
327 if (!wd) return NULL;
328 if (!wd->icon) return NULL;
330 elm_widget_sub_object_del(obj, icon);
331 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
332 _changed_size_hints, obj);
333 edje_object_part_unswallow(wd->bbl, icon);
339 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
341 ELM_CHECK_WIDTYPE(obj, widtype);
342 Widget_Data *wd = elm_widget_data_get(obj);
344 EINA_SAFETY_ON_NULL_RETURN(corner);
345 eina_stringshare_replace(&wd->corner, corner);
350 elm_bubble_corner_get(const Evas_Object *obj)
352 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
353 Widget_Data *wd = elm_widget_data_get(obj);
354 if (!wd) return NULL;