1 #include <Elementary.h>
5 * @defgroup Bubble Bubble
8 * The Bubble is an widget used to show a text in a frame as speech is
9 * represented in comics.
12 typedef struct _Widget_Data Widget_Data;
17 Evas_Object *content, *icon;
18 const char *label, *info;
21 static const char *widtype = NULL;
22 static void _del_hook(Evas_Object *obj);
23 static void _theme_hook(Evas_Object *obj);
24 static void _sizing_eval(Evas_Object *obj);
25 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
26 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
29 _del_hook(Evas_Object *obj)
31 Widget_Data *wd = elm_widget_data_get(obj);
33 if (wd->label) eina_stringshare_del(wd->label);
34 if (wd->info) eina_stringshare_del(wd->info);
39 _theme_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
43 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", elm_widget_style_get(obj));
44 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
45 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
46 edje_object_scale_set(wd->bbl, elm_widget_scale_get(obj) * _elm_config->scale);
51 _sizing_eval(Evas_Object *obj)
53 Widget_Data *wd = elm_widget_data_get(obj);
54 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
56 edje_object_size_min_calc(wd->bbl, &minw, &minh);
57 evas_object_size_hint_min_set(obj, minw, minh);
58 evas_object_size_hint_max_set(obj, maxw, maxh);
62 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
64 Widget_Data *wd = elm_widget_data_get(data);
70 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
72 Widget_Data *wd = elm_widget_data_get(obj);
73 Evas_Object *sub = event_info;
75 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
76 _changed_size_hints, obj);
77 if (sub == wd->content) wd->content = NULL;
78 else if (sub == wd->icon)
80 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
82 edje_object_message_signal_process(wd->bbl);
88 * Add a new bubble to the parent
90 * @param parent The parent object
91 * @return The new object or NULL if it cannot be created
93 * This function adds a text bubble to the given parent evas object.
98 elm_bubble_add(Evas_Object *parent)
104 wd = ELM_NEW(Widget_Data);
105 e = evas_object_evas_get(parent);
106 obj = elm_widget_add(e);
107 ELM_SET_WIDTYPE(widtype, "bubble");
108 elm_widget_type_set(obj, "bubble");
109 elm_widget_sub_object_add(parent, obj);
110 elm_widget_data_set(obj, wd);
111 elm_widget_del_hook_set(obj, _del_hook);
112 elm_widget_theme_hook_set(obj, _theme_hook);
114 wd->bbl = edje_object_add(e);
115 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", "default");
116 elm_widget_resize_object_set(obj, wd->bbl);
118 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
125 * Set the label of the bubble
127 * @param obj The bubble object
128 * @param label The string to set in the label
130 * This function sets the title of the bubble that is shown on top of
136 elm_bubble_label_set(Evas_Object *obj, const char *label)
138 ELM_CHECK_WIDTYPE(obj, widtype);
139 Widget_Data *wd = elm_widget_data_get(obj);
141 if (label) edje_object_signal_emit(wd->bbl, "elm,state,label,visible", "elm");
142 else edje_object_signal_emit(wd->bbl, "elm,state,label,hidden", "elm");
143 eina_stringshare_replace(&wd->label, label);
144 edje_object_part_text_set(wd->bbl, "elm.text", label);
149 * Get the label of the bubble
151 * @param obj The bubble object
152 * @return The string of set in the label
154 * This function gets the title of the bubble that is shown on top of
160 elm_bubble_label_get(const Evas_Object *obj)
162 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
163 Widget_Data *wd = elm_widget_data_get(obj);
164 if (!wd) return NULL;
169 * Set the info of the bubble
171 * @param obj The bubble object
172 * @param info The given info about the bubble
174 * This function sets the text shown on the top right of bubble.
175 * In the Anchorblock example of the Elementary tests application it
182 elm_bubble_info_set(Evas_Object *obj, const char *info)
184 ELM_CHECK_WIDTYPE(obj, widtype);
185 Widget_Data *wd = elm_widget_data_get(obj);
187 eina_stringshare_replace(&wd->info, info);
188 edje_object_part_text_set(wd->bbl, "elm.info", info);
193 * Get the info of the bubble
195 * @param obj The bubble object
197 * @return The "info" string of the bubble
199 * This function gets the text set to be displayed at the top right of
206 elm_bubble_info_get(const Evas_Object *obj)
208 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
209 Widget_Data *wd = elm_widget_data_get(obj);
210 if (!wd) return NULL;
215 * Set the content to be shown in the bubble
217 * Once the content object is set, a previously set one will be deleted.
218 * If you want to keep the old content object, use the
219 * elm_bubble_content_unset() function.
221 * @param obj The bubble object
222 * @param content The given content of the bubble
224 * This function sets the content shown on the middle of the bubble.
225 * In the Anchorblock example of the Elementary tests application it
231 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
233 ELM_CHECK_WIDTYPE(obj, widtype);
234 Widget_Data *wd = elm_widget_data_get(obj);
236 if (wd->content == content) return;
237 if (wd->content) evas_object_del(wd->content);
238 wd->content = content;
241 elm_widget_sub_object_add(obj, content);
242 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
243 _changed_size_hints, obj);
244 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
250 * Unset the content shown in the bubble
252 * Unparent and return the content object which was set for this widget.
254 * @param obj The bubble object
255 * @return The content that was being used
260 elm_bubble_content_unset(Evas_Object *obj)
262 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
263 Widget_Data *wd = elm_widget_data_get(obj);
264 Evas_Object *content;
265 if (!wd) return NULL;
266 if (!wd->content) return NULL;
267 content = wd->content;
268 elm_widget_sub_object_del(obj, wd->content);
269 edje_object_part_unswallow(wd->bbl, wd->content);
275 * Set the icon of the bubble
277 * Once the icon object is set, a previously set one will be deleted.
279 * @param obj The bubble object
280 * @param icon The given icon for the bubble
285 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
287 ELM_CHECK_WIDTYPE(obj, widtype);
288 Widget_Data *wd = elm_widget_data_get(obj);
290 if (wd->icon == icon) return;
291 if (wd->icon) evas_object_del(wd->icon);
295 elm_widget_sub_object_add(obj, icon);
296 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
297 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
298 _changed_size_hints, obj);
299 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
300 edje_object_message_signal_process(wd->bbl);
307 * Get the icon of the bubble
309 * @param obj The bubble object
310 * @return The icon for the bubble
312 * This function gets the icon shown on the top left of bubble.
317 elm_bubble_icon_get(const Evas_Object *obj)
319 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
320 Widget_Data *wd = elm_widget_data_get(obj);
321 if (!wd) return NULL;
326 * Set the corner of the bubble
328 * @param obj The bubble object.
329 * @param corner The given corner for the bubble.
331 * This function sets the corner of the bubble.
336 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
338 ELM_CHECK_WIDTYPE(obj, widtype);
339 Widget_Data *wd = elm_widget_data_get(obj);
341 _elm_theme_object_set(obj, wd->bbl, "bubble", corner, elm_widget_style_get(obj));
343 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", wd->icon);
345 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
346 // FIXME: fix label etc.