1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
9 Evas_Object *content, *icon;
10 const char *label, *info, *corner;
14 static const char *widtype = NULL;
15 static void _del_hook(Evas_Object *obj);
16 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
17 static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
18 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
19 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
20 static void _theme_hook(Evas_Object *obj);
21 static void _sizing_eval(Evas_Object *obj);
22 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
23 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
25 static const char SIG_CLICKED[] = "clicked";
27 static const Evas_Smart_Cb_Description _signals[] =
33 static const char *corner_string[] =
42 _del_hook(Evas_Object *obj)
44 Widget_Data *wd = elm_widget_data_get(obj);
46 if (wd->label) eina_stringshare_del(wd->label);
47 if (wd->info) eina_stringshare_del(wd->info);
48 if (wd->corner) eina_stringshare_del(wd->corner);
53 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
55 Widget_Data *wd = elm_widget_data_get(obj);
57 edje_object_mirrored_set(wd->bbl, rtl);
61 _theme_hook(Evas_Object *obj)
63 Widget_Data *wd = elm_widget_data_get(obj);
65 _elm_widget_mirrored_reload(obj);
66 _mirrored_set(obj, elm_widget_mirrored_get(obj));
67 _elm_theme_object_set(obj, wd->bbl, "bubble", corner_string[wd->pos],
68 elm_widget_style_get(obj));
69 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
70 if (wd->label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
71 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
72 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
73 if (wd->info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
74 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
77 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
78 edje_object_message_signal_process(wd->bbl);
81 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
83 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
84 edje_object_scale_set(wd->bbl,
85 elm_widget_scale_get(obj) * _elm_config->scale);
90 _content_set(Evas_Object *obj, Evas_Object *content)
92 Widget_Data *wd = elm_widget_data_get(obj);
95 if (wd->content == content) return;
96 if (wd->content) evas_object_del(wd->content);
97 wd->content = content;
100 elm_widget_sub_object_add(obj, content);
101 evas_object_event_callback_add(content,
102 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
103 _changed_size_hints, obj);
104 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
110 _content_unset(Evas_Object *obj)
112 Widget_Data *wd = elm_widget_data_get(obj);
113 Evas_Object *content;
114 if (!wd) return NULL;
115 if (!wd->content) return NULL;
116 content = wd->content;
117 elm_widget_sub_object_del(obj, content);
118 evas_object_event_callback_del_full(content,
119 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
120 _changed_size_hints, obj);
121 edje_object_part_unswallow(wd->bbl, content);
127 _icon_set(Evas_Object *obj, Evas_Object* icon)
129 Widget_Data *wd = elm_widget_data_get(obj);
131 if (wd->icon == icon) return;
132 if (wd->icon) evas_object_del(wd->icon);
136 elm_widget_sub_object_add(obj, icon);
137 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
138 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
139 _changed_size_hints, obj);
140 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
141 edje_object_message_signal_process(wd->bbl);
147 _icon_unset(Evas_Object *obj)
149 Widget_Data *wd = elm_widget_data_get(obj);
151 if (!wd) return NULL;
152 if (!wd->icon) return NULL;
154 elm_widget_sub_object_del(obj, icon);
155 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
156 _changed_size_hints, obj);
157 edje_object_part_unswallow(wd->bbl, icon);
163 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
165 ELM_CHECK_WIDTYPE(obj, widtype);
166 Widget_Data *wd = elm_widget_data_get(obj);
169 if (!part || !strcmp(part, "default"))
170 _content_set(obj, content);
171 else if(!strcmp(part, "icon"))
172 _icon_set(obj, content);
176 _content_get_hook(const Evas_Object *obj, const char *part)
178 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
179 Widget_Data *wd = elm_widget_data_get(obj);
180 if (!wd) return NULL;
181 if (!part || !strcmp(part, "default"))
183 else if(!strcmp(part, "icon"))
189 _content_unset_hook(Evas_Object *obj, const char *part)
191 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
192 Widget_Data *wd = elm_widget_data_get(obj);
193 if (!wd) return NULL;
194 if (!part || !strcmp(part, "default"))
195 return _content_unset(obj);
196 else if(!strcmp(part, "icon"))
197 return _icon_unset(obj);
202 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
204 Widget_Data *wd = elm_widget_data_get(obj);
207 if ((!wd) || (!wd->content))
212 /* Try Focus cycle in subitem */
213 return elm_widget_focus_next_get(cur, dir, next);
217 _sizing_eval(Evas_Object *obj)
219 Widget_Data *wd = elm_widget_data_get(obj);
220 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
222 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
223 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
224 evas_object_size_hint_min_set(obj, minw, minh);
225 evas_object_size_hint_max_set(obj, maxw, maxh);
229 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
231 Widget_Data *wd = elm_widget_data_get(data);
237 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
239 Widget_Data *wd = elm_widget_data_get(obj);
240 Evas_Object *sub = event_info;
242 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
243 _changed_size_hints, obj);
244 if (sub == wd->content) wd->content = NULL;
245 else if (sub == wd->icon)
247 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
249 edje_object_message_signal_process(wd->bbl);
255 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
257 Evas_Event_Mouse_Up *ev = event_info;
258 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
260 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
264 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
266 ELM_CHECK_WIDTYPE(obj, widtype);
267 Widget_Data *wd = elm_widget_data_get(obj);
270 if (!item || !strcmp(item, "default"))
272 eina_stringshare_replace(&wd->label, label);
273 edje_object_part_text_set(wd->bbl, "elm.text", label);
274 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
276 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
279 else if (!strcmp(item, "info"))
281 eina_stringshare_replace(&wd->info, label);
282 edje_object_part_text_set(wd->bbl, "elm.info", label);
283 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
285 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
291 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
293 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
294 Widget_Data *wd = elm_widget_data_get(obj);
295 if (!wd) return NULL;
297 if (!item || !strcmp(item, "default"))
301 else if (!strcmp(item, "info"))
310 elm_bubble_add(Evas_Object *parent)
316 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
318 ELM_SET_WIDTYPE(widtype, "bubble");
319 elm_widget_type_set(obj, "bubble");
320 elm_widget_sub_object_add(parent, obj);
321 elm_widget_data_set(obj, wd);
322 elm_widget_del_hook_set(obj, _del_hook);
323 elm_widget_theme_hook_set(obj, _theme_hook);
324 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
325 elm_widget_can_focus_set(obj, EINA_FALSE);
326 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
327 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
328 elm_widget_content_set_hook_set(obj, _content_set_hook);
329 elm_widget_content_get_hook_set(obj, _content_get_hook);
330 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
332 wd->corner = eina_stringshare_add("base");
333 wd->pos = ELM_BUBBLE_POS_TOP_LEFT; //default
335 wd->bbl = edje_object_add(e);
336 elm_widget_resize_object_set(obj, wd->bbl);
338 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
339 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
342 evas_object_smart_callbacks_descriptions_set(obj, _signals);
343 _mirrored_set(obj, elm_widget_mirrored_get(obj));
344 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
345 elm_widget_style_get(obj));
351 elm_bubble_label_set(Evas_Object *obj, const char *label)
353 _elm_bubble_label_set(obj, NULL, label);
357 elm_bubble_label_get(const Evas_Object *obj)
359 return _elm_bubble_label_get(obj, NULL);
363 elm_bubble_info_set(Evas_Object *obj, const char *info)
365 _elm_bubble_label_set(obj, "info", info);
369 elm_bubble_info_get(const Evas_Object *obj)
371 return _elm_bubble_label_get(obj, "info");
375 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
377 _content_set_hook(obj, NULL, content);
381 elm_bubble_content_get(const Evas_Object *obj)
383 return _content_get_hook(obj, NULL);
387 elm_bubble_content_unset(Evas_Object *obj)
389 return _content_unset_hook(obj, NULL);
393 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
395 _content_set_hook(obj, "icon", icon);
399 elm_bubble_icon_get(const Evas_Object *obj)
401 return _content_get_hook(obj, "icon");
405 elm_bubble_icon_unset(Evas_Object *obj)
407 return _content_unset_hook(obj, "icon");
410 EINA_DEPRECATED EAPI void
411 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
414 for (i=ELM_BUBBLE_POS_TOP_LEFT; i<=ELM_BUBBLE_POS_BOTTOM_RIGHT; i++)
416 if (!strcmp(corner,corner_string[i]))
417 elm_bubble_pos_set(obj, i);
422 elm_bubble_pos_set(Evas_Object *obj, Elm_Bubble_Pos pos)
424 ELM_CHECK_WIDTYPE(obj, widtype);
425 Widget_Data *wd = elm_widget_data_get(obj);
427 if(pos<ELM_BUBBLE_POS_TOP_LEFT || pos>ELM_BUBBLE_POS_BOTTOM_RIGHT) return;
432 EINA_DEPRECATED EAPI const char*
433 elm_bubble_corner_get(const Evas_Object *obj)
435 return corner_string[elm_bubble_pos_get(obj)];
439 elm_bubble_pos_get(const Evas_Object *obj)
441 ELM_CHECK_WIDTYPE(obj, widtype) ELM_BUBBLE_POS_INVALID;
442 Widget_Data *wd = elm_widget_data_get(obj);
443 if (!wd) return ELM_BUBBLE_POS_INVALID;