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 _content_set(Evas_Object *obj, Evas_Object *content)
80 Widget_Data *wd = elm_widget_data_get(obj);
83 if (wd->content == content) return;
84 if (wd->content) evas_object_del(wd->content);
85 wd->content = content;
88 elm_widget_sub_object_add(obj, content);
89 evas_object_event_callback_add(content,
90 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
91 _changed_size_hints, obj);
92 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
98 _content_unset(Evas_Object *obj)
100 Widget_Data *wd = elm_widget_data_get(obj);
101 Evas_Object *content;
102 if (!wd) return NULL;
103 if (!wd->content) return NULL;
104 content = wd->content;
105 elm_widget_sub_object_del(obj, content);
106 evas_object_event_callback_del_full(content,
107 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
108 _changed_size_hints, obj);
109 edje_object_part_unswallow(wd->bbl, content);
115 _icon_set(Evas_Object *obj, Evas_Object* icon)
117 Widget_Data *wd = elm_widget_data_get(obj);
119 if (wd->icon == icon) return;
120 if (wd->icon) evas_object_del(wd->icon);
124 elm_widget_sub_object_add(obj, icon);
125 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
126 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
127 _changed_size_hints, obj);
128 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
129 edje_object_message_signal_process(wd->bbl);
135 _icon_unset(Evas_Object *obj)
137 Widget_Data *wd = elm_widget_data_get(obj);
139 if (!wd) return NULL;
140 if (!wd->icon) return NULL;
142 elm_widget_sub_object_del(obj, icon);
143 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
144 _changed_size_hints, obj);
145 edje_object_part_unswallow(wd->bbl, icon);
151 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
153 ELM_CHECK_WIDTYPE(obj, widtype);
154 Widget_Data *wd = elm_widget_data_get(obj);
157 if (!part || !strcmp(part, "default"))
158 _content_set(obj, content);
159 else if(!strcmp(part, "icon"))
160 _icon_set(obj, content);
164 _content_get_hook(const Evas_Object *obj, const char *part)
166 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
167 Widget_Data *wd = elm_widget_data_get(obj);
168 if (!wd) return NULL;
169 if (!part || !strcmp(part, "default"))
171 else if(!strcmp(part, "icon"))
177 _content_unset_hook(Evas_Object *obj, const char *part)
179 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
180 Widget_Data *wd = elm_widget_data_get(obj);
181 if (!wd) return NULL;
182 if (!part || !strcmp(part, "default"))
183 return _content_unset(obj);
184 else if(!strcmp(part, "icon"))
185 return _icon_unset(obj);
190 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
192 Widget_Data *wd = elm_widget_data_get(obj);
195 if ((!wd) || (!wd->content))
200 /* Try Focus cycle in subitem */
201 return elm_widget_focus_next_get(cur, dir, next);
205 _sizing_eval(Evas_Object *obj)
207 Widget_Data *wd = elm_widget_data_get(obj);
208 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
210 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
211 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
212 evas_object_size_hint_min_set(obj, minw, minh);
213 evas_object_size_hint_max_set(obj, maxw, maxh);
217 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
219 Widget_Data *wd = elm_widget_data_get(data);
225 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
227 Widget_Data *wd = elm_widget_data_get(obj);
228 Evas_Object *sub = event_info;
230 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
231 _changed_size_hints, obj);
232 if (sub == wd->content) wd->content = NULL;
233 else if (sub == wd->icon)
235 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
237 edje_object_message_signal_process(wd->bbl);
243 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
245 Evas_Event_Mouse_Up *ev = event_info;
246 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
248 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
252 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
254 ELM_CHECK_WIDTYPE(obj, widtype);
255 Widget_Data *wd = elm_widget_data_get(obj);
258 if (!item || !strcmp(item, "default"))
260 eina_stringshare_replace(&wd->label, label);
261 edje_object_part_text_set(wd->bbl, "elm.text", label);
262 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
264 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
267 else if (!strcmp(item, "info"))
269 eina_stringshare_replace(&wd->info, label);
270 edje_object_part_text_set(wd->bbl, "elm.info", label);
271 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
273 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
279 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
281 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
282 Widget_Data *wd = elm_widget_data_get(obj);
283 if (!wd) return NULL;
285 if (!item || !strcmp(item, "default"))
289 else if (!strcmp(item, "info"))
298 elm_bubble_add(Evas_Object *parent)
304 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
306 ELM_SET_WIDTYPE(widtype, "bubble");
307 elm_widget_type_set(obj, "bubble");
308 elm_widget_sub_object_add(parent, obj);
309 elm_widget_data_set(obj, wd);
310 elm_widget_del_hook_set(obj, _del_hook);
311 elm_widget_theme_hook_set(obj, _theme_hook);
312 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
313 elm_widget_can_focus_set(obj, EINA_FALSE);
314 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
315 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
317 wd->corner = eina_stringshare_add("base");
319 wd->bbl = edje_object_add(e);
320 elm_widget_resize_object_set(obj, wd->bbl);
322 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
323 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
326 evas_object_smart_callbacks_descriptions_set(obj, _signals);
327 _mirrored_set(obj, elm_widget_mirrored_get(obj));
328 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
329 elm_widget_style_get(obj));
335 elm_bubble_label_set(Evas_Object *obj, const char *label)
337 _elm_bubble_label_set(obj, NULL, label);
341 elm_bubble_label_get(const Evas_Object *obj)
343 return _elm_bubble_label_get(obj, NULL);
347 elm_bubble_info_set(Evas_Object *obj, const char *info)
349 _elm_bubble_label_set(obj, "info", info);
353 elm_bubble_info_get(const Evas_Object *obj)
355 return _elm_bubble_label_get(obj, "info");
359 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
361 ELM_CHECK_WIDTYPE(obj, widtype);
362 Widget_Data *wd = elm_widget_data_get(obj);
364 if (wd->content == content) return;
365 if (wd->content) evas_object_del(wd->content);
366 wd->content = content;
369 elm_widget_sub_object_add(obj, content);
370 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
371 _changed_size_hints, obj);
372 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
378 elm_bubble_content_get(const Evas_Object *obj)
380 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
381 Widget_Data *wd = elm_widget_data_get(obj);
382 if (!wd) return NULL;
387 elm_bubble_content_unset(Evas_Object *obj)
389 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
390 Widget_Data *wd = elm_widget_data_get(obj);
391 Evas_Object *content;
392 if (!wd) return NULL;
393 if (!wd->content) return NULL;
394 content = wd->content;
395 elm_widget_sub_object_del(obj, content);
396 evas_object_event_callback_del_full(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
397 _changed_size_hints, obj);
398 edje_object_part_unswallow(wd->bbl, content);
404 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
406 _content_set_hook(obj, "elm.swallow.icon", icon);
410 elm_bubble_icon_get(const Evas_Object *obj)
412 return _content_get_hook(obj, "elm.swallow.icon");
416 elm_bubble_icon_unset(Evas_Object *obj)
418 return _content_unset_hook(obj, "elm.swallow.icon");
422 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
424 ELM_CHECK_WIDTYPE(obj, widtype);
425 Widget_Data *wd = elm_widget_data_get(obj);
427 EINA_SAFETY_ON_NULL_RETURN(corner);
428 eina_stringshare_replace(&wd->corner, corner);
433 elm_bubble_corner_get(const Evas_Object *obj)
435 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
436 Widget_Data *wd = elm_widget_data_get(obj);
437 if (!wd) return NULL;