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_add(Evas_Object *parent)
146 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
148 ELM_SET_WIDTYPE(widtype, "bubble");
149 elm_widget_type_set(obj, "bubble");
150 elm_widget_sub_object_add(parent, obj);
151 elm_widget_data_set(obj, wd);
152 elm_widget_del_hook_set(obj, _del_hook);
153 elm_widget_theme_hook_set(obj, _theme_hook);
154 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
155 elm_widget_can_focus_set(obj, EINA_FALSE);
157 wd->corner = eina_stringshare_add("base");
159 wd->bbl = edje_object_add(e);
160 elm_widget_resize_object_set(obj, wd->bbl);
162 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
163 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
166 evas_object_smart_callbacks_descriptions_set(obj, _signals);
167 _mirrored_set(obj, elm_widget_mirrored_get(obj));
168 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
169 elm_widget_style_get(obj));
175 elm_bubble_label_set(Evas_Object *obj, const char *label)
177 ELM_CHECK_WIDTYPE(obj, widtype);
178 Widget_Data *wd = elm_widget_data_get(obj);
180 eina_stringshare_replace(&wd->label, label);
181 edje_object_part_text_set(wd->bbl, "elm.text", label);
182 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
183 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
188 elm_bubble_label_get(const Evas_Object *obj)
190 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
191 Widget_Data *wd = elm_widget_data_get(obj);
192 if (!wd) return NULL;
197 elm_bubble_info_set(Evas_Object *obj, const char *info)
199 ELM_CHECK_WIDTYPE(obj, widtype);
200 Widget_Data *wd = elm_widget_data_get(obj);
202 eina_stringshare_replace(&wd->info, info);
203 edje_object_part_text_set(wd->bbl, "elm.info", info);
204 if (info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
205 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
210 elm_bubble_info_get(const Evas_Object *obj)
212 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
213 Widget_Data *wd = elm_widget_data_get(obj);
214 if (!wd) return NULL;
219 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
221 ELM_CHECK_WIDTYPE(obj, widtype);
222 Widget_Data *wd = elm_widget_data_get(obj);
224 if (wd->content == content) return;
225 if (wd->content) evas_object_del(wd->content);
226 wd->content = content;
229 elm_widget_sub_object_add(obj, content);
230 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
231 _changed_size_hints, obj);
232 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
238 elm_bubble_content_get(const Evas_Object *obj)
240 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
241 Widget_Data *wd = elm_widget_data_get(obj);
242 if (!wd) return NULL;
247 elm_bubble_content_unset(Evas_Object *obj)
249 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
250 Widget_Data *wd = elm_widget_data_get(obj);
251 Evas_Object *content;
252 if (!wd) return NULL;
253 if (!wd->content) return NULL;
254 content = wd->content;
255 elm_widget_sub_object_del(obj, content);
256 edje_object_part_unswallow(wd->bbl, content);
262 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
264 ELM_CHECK_WIDTYPE(obj, widtype);
265 Widget_Data *wd = elm_widget_data_get(obj);
267 if (wd->icon == icon) return;
268 if (wd->icon) evas_object_del(wd->icon);
272 elm_widget_sub_object_add(obj, icon);
273 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
274 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
275 _changed_size_hints, obj);
276 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
277 edje_object_message_signal_process(wd->bbl);
283 elm_bubble_icon_get(const Evas_Object *obj)
285 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
286 Widget_Data *wd = elm_widget_data_get(obj);
287 if (!wd) return NULL;
292 elm_bubble_icon_unset(Evas_Object *obj)
294 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
295 Widget_Data *wd = elm_widget_data_get(obj);
297 if (!wd) return NULL;
298 if (!wd->icon) return NULL;
300 elm_widget_sub_object_del(obj, icon);
301 edje_object_part_unswallow(wd->bbl, icon);
307 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
309 ELM_CHECK_WIDTYPE(obj, widtype);
310 Widget_Data *wd = elm_widget_data_get(obj);
312 EINA_SAFETY_ON_NULL_RETURN(corner);
313 eina_stringshare_replace(&wd->corner, corner);
318 elm_bubble_corner_get(const Evas_Object *obj)
320 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
321 Widget_Data *wd = elm_widget_data_get(obj);
322 if (!wd) return NULL;