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(Evas_Object *obj, Evas_Object *content)
83 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_unset(Evas_Object *obj)
103 Widget_Data *wd = elm_widget_data_get(obj);
104 Evas_Object *content;
105 if (!wd) return NULL;
106 if (!wd->content) return NULL;
107 content = wd->content;
108 elm_widget_sub_object_del(obj, content);
109 evas_object_event_callback_del_full(content,
110 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
111 _changed_size_hints, obj);
112 edje_object_part_unswallow(wd->bbl, content);
118 _icon_set(Evas_Object *obj, Evas_Object* icon)
120 Widget_Data *wd = elm_widget_data_get(obj);
122 if (wd->icon == icon) return;
123 if (wd->icon) evas_object_del(wd->icon);
127 elm_widget_sub_object_add(obj, icon);
128 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
129 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
130 _changed_size_hints, obj);
131 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
132 edje_object_message_signal_process(wd->bbl);
138 _icon_unset(Evas_Object *obj)
140 Widget_Data *wd = elm_widget_data_get(obj);
142 if (!wd) return NULL;
143 if (!wd->icon) return NULL;
145 elm_widget_sub_object_del(obj, icon);
146 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
147 _changed_size_hints, obj);
148 edje_object_part_unswallow(wd->bbl, icon);
154 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
156 ELM_CHECK_WIDTYPE(obj, widtype);
157 Widget_Data *wd = elm_widget_data_get(obj);
160 if (!part || !strcmp(part, "default"))
161 _content_set(obj, content);
162 else if(!strcmp(part, "icon"))
163 _icon_set(obj, content);
167 _content_get_hook(const Evas_Object *obj, const char *part)
169 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
170 Widget_Data *wd = elm_widget_data_get(obj);
171 if (!wd) return NULL;
172 if (!part || !strcmp(part, "default"))
174 else if(!strcmp(part, "icon"))
180 _content_unset_hook(Evas_Object *obj, const char *part)
182 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
183 Widget_Data *wd = elm_widget_data_get(obj);
184 if (!wd) return NULL;
185 if (!part || !strcmp(part, "default"))
186 return _content_unset(obj);
187 else if(!strcmp(part, "icon"))
188 return _icon_unset(obj);
193 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
195 Widget_Data *wd = elm_widget_data_get(obj);
198 if ((!wd) || (!wd->content))
203 /* Try Focus cycle in subitem */
204 return elm_widget_focus_next_get(cur, dir, next);
208 _sizing_eval(Evas_Object *obj)
210 Widget_Data *wd = elm_widget_data_get(obj);
211 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
213 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
214 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
215 evas_object_size_hint_min_set(obj, minw, minh);
216 evas_object_size_hint_max_set(obj, maxw, maxh);
220 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
222 Widget_Data *wd = elm_widget_data_get(data);
228 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
230 Widget_Data *wd = elm_widget_data_get(obj);
231 Evas_Object *sub = event_info;
233 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
234 _changed_size_hints, obj);
235 if (sub == wd->content) wd->content = NULL;
236 else if (sub == wd->icon)
238 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
240 edje_object_message_signal_process(wd->bbl);
246 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
248 Evas_Event_Mouse_Up *ev = event_info;
249 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
251 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
255 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
257 ELM_CHECK_WIDTYPE(obj, widtype);
258 Widget_Data *wd = elm_widget_data_get(obj);
261 if (!item || !strcmp(item, "default"))
263 eina_stringshare_replace(&wd->label, label);
264 edje_object_part_text_set(wd->bbl, "elm.text", label);
265 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
267 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
270 else if (!strcmp(item, "info"))
272 eina_stringshare_replace(&wd->info, label);
273 edje_object_part_text_set(wd->bbl, "elm.info", label);
274 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
276 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
282 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
284 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
285 Widget_Data *wd = elm_widget_data_get(obj);
286 if (!wd) return NULL;
288 if (!item || !strcmp(item, "default"))
292 else if (!strcmp(item, "info"))
301 elm_bubble_add(Evas_Object *parent)
307 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
309 ELM_SET_WIDTYPE(widtype, "bubble");
310 elm_widget_type_set(obj, "bubble");
311 elm_widget_sub_object_add(parent, obj);
312 elm_widget_data_set(obj, wd);
313 elm_widget_del_hook_set(obj, _del_hook);
314 elm_widget_theme_hook_set(obj, _theme_hook);
315 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
316 elm_widget_can_focus_set(obj, EINA_FALSE);
317 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
318 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
319 elm_widget_content_set_hook_set(obj, _content_set_hook);
320 elm_widget_content_get_hook_set(obj, _content_get_hook);
321 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
323 wd->corner = eina_stringshare_add("base");
325 wd->bbl = edje_object_add(e);
326 elm_widget_resize_object_set(obj, wd->bbl);
328 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
329 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
332 evas_object_smart_callbacks_descriptions_set(obj, _signals);
333 _mirrored_set(obj, elm_widget_mirrored_get(obj));
334 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
335 elm_widget_style_get(obj));
341 elm_bubble_label_set(Evas_Object *obj, const char *label)
343 _elm_bubble_label_set(obj, NULL, label);
347 elm_bubble_label_get(const Evas_Object *obj)
349 return _elm_bubble_label_get(obj, NULL);
353 elm_bubble_info_set(Evas_Object *obj, const char *info)
355 _elm_bubble_label_set(obj, "info", info);
359 elm_bubble_info_get(const Evas_Object *obj)
361 return _elm_bubble_label_get(obj, "info");
365 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
367 _content_set_hook(obj, NULL, content);
371 elm_bubble_content_get(const Evas_Object *obj)
373 return _content_get_hook(obj, NULL);
377 elm_bubble_content_unset(Evas_Object *obj)
379 return _content_unset_hook(obj, NULL);
383 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
385 _content_set_hook(obj, "elm.swallow.icon", icon);
389 elm_bubble_icon_get(const Evas_Object *obj)
391 return _content_get_hook(obj, "elm.swallow.icon");
395 elm_bubble_icon_unset(Evas_Object *obj)
397 return _content_unset_hook(obj, "elm.swallow.icon");
401 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
403 ELM_CHECK_WIDTYPE(obj, widtype);
404 Widget_Data *wd = elm_widget_data_get(obj);
406 EINA_SAFETY_ON_NULL_RETURN(corner);
407 eina_stringshare_replace(&wd->corner, corner);
412 elm_bubble_corner_get(const Evas_Object *obj)
414 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
415 Widget_Data *wd = elm_widget_data_get(obj);
416 if (!wd) return NULL;