1 #include <Elementary.h>
5 * @defgroup Bubble Bubble
7 * The Bubble is an widget used to show a text in a frame as speech is
8 * represented in comics.
10 * Signals that you can add callbacks for are:
12 * "clicked" - This is called when a user has clicked the bubble.
15 typedef struct _Widget_Data Widget_Data;
20 Evas_Object *content, *icon;
21 const char *label, *info, *corner;
24 static const char *widtype = NULL;
25 static void _del_hook(Evas_Object *obj);
26 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
27 static void _theme_hook(Evas_Object *obj);
28 static void _sizing_eval(Evas_Object *obj);
29 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
30 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
32 #define SIG_CLICKED "clicked"
33 static const Evas_Smart_Cb_Description _signals[] =
40 _del_hook(Evas_Object *obj)
42 Widget_Data *wd = elm_widget_data_get(obj);
44 if (wd->label) eina_stringshare_del(wd->label);
45 if (wd->info) eina_stringshare_del(wd->info);
46 if (wd->corner) eina_stringshare_del(wd->corner);
51 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
53 Widget_Data *wd = elm_widget_data_get(obj);
55 edje_object_mirrored_set(wd->bbl, rtl);
59 _theme_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
63 _elm_widget_mirrored_reload(obj);
64 _mirrored_set(obj, elm_widget_mirrored_get(obj));
65 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
66 elm_widget_style_get(obj));
67 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
68 if (wd->label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
69 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
70 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
71 if (wd->info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
72 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
75 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
76 edje_object_message_signal_process(wd->bbl);
79 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
81 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
82 edje_object_scale_set(wd->bbl,
83 elm_widget_scale_get(obj) * _elm_config->scale);
88 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
90 Widget_Data *wd = elm_widget_data_get(obj);
93 if ((!wd) || (!wd->content))
98 /* Try Focus cycle in subitem */
99 return elm_widget_focus_next_get(cur, dir, next);
103 _sizing_eval(Evas_Object *obj)
105 Widget_Data *wd = elm_widget_data_get(obj);
106 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
108 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
109 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
110 evas_object_size_hint_min_set(obj, minw, minh);
111 evas_object_size_hint_max_set(obj, maxw, maxh);
115 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
117 Widget_Data *wd = elm_widget_data_get(data);
123 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
125 Widget_Data *wd = elm_widget_data_get(obj);
126 Evas_Object *sub = event_info;
128 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
129 _changed_size_hints, obj);
130 if (sub == wd->content) wd->content = NULL;
131 else if (sub == wd->icon)
133 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
135 edje_object_message_signal_process(wd->bbl);
141 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
143 Evas_Event_Mouse_Up *ev = event_info;
144 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
146 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
150 * Add a new bubble to the parent
152 * @param parent The parent object
153 * @return The new object or NULL if it cannot be created
155 * This function adds a text bubble to the given parent evas object.
160 elm_bubble_add(Evas_Object *parent)
166 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
168 ELM_SET_WIDTYPE(widtype, "bubble");
169 elm_widget_type_set(obj, "bubble");
170 elm_widget_sub_object_add(parent, obj);
171 elm_widget_data_set(obj, wd);
172 elm_widget_del_hook_set(obj, _del_hook);
173 elm_widget_theme_hook_set(obj, _theme_hook);
174 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
175 elm_widget_can_focus_set(obj, EINA_FALSE);
177 wd->corner = eina_stringshare_add("base");
179 wd->bbl = edje_object_add(e);
180 elm_widget_resize_object_set(obj, wd->bbl);
182 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
183 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
186 evas_object_smart_callbacks_descriptions_set(obj, _signals);
187 _mirrored_set(obj, elm_widget_mirrored_get(obj));
188 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
189 elm_widget_style_get(obj));
195 * Set the label of the bubble
197 * @param obj The bubble object
198 * @param label The string to set in the label
200 * This function sets the title of the bubble that is shown on top of
206 elm_bubble_label_set(Evas_Object *obj, const char *label)
208 ELM_CHECK_WIDTYPE(obj, widtype);
209 Widget_Data *wd = elm_widget_data_get(obj);
211 eina_stringshare_replace(&wd->label, label);
212 edje_object_part_text_set(wd->bbl, "elm.text", label);
213 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
214 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
219 * Get the label of the bubble
221 * @param obj The bubble object
222 * @return The string of set in the label
224 * This function gets the title of the bubble that is shown on top of
230 elm_bubble_label_get(const Evas_Object *obj)
232 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
233 Widget_Data *wd = elm_widget_data_get(obj);
234 if (!wd) return NULL;
239 * Set the info of the bubble
241 * @param obj The bubble object
242 * @param info The given info about the bubble
244 * This function sets the text shown on the top right of bubble.
245 * In the Anchorblock example of the Elementary tests application it
252 elm_bubble_info_set(Evas_Object *obj, const char *info)
254 ELM_CHECK_WIDTYPE(obj, widtype);
255 Widget_Data *wd = elm_widget_data_get(obj);
257 eina_stringshare_replace(&wd->info, info);
258 edje_object_part_text_set(wd->bbl, "elm.info", info);
259 if (info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
260 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
265 * Get the info of the bubble
267 * @param obj The bubble object
269 * @return The "info" string of the bubble
271 * This function gets the text set to be displayed at the top right of
278 elm_bubble_info_get(const Evas_Object *obj)
280 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
281 Widget_Data *wd = elm_widget_data_get(obj);
282 if (!wd) return NULL;
287 * Set the content to be shown in the bubble
289 * Once the content object is set, a previously set one will be deleted.
290 * If you want to keep the old content object, use the
291 * elm_bubble_content_unset() function.
293 * @param obj The bubble object
294 * @param content The given content of the bubble
296 * This function sets the content shown on the middle of the bubble.
297 * In the Anchorblock example of the Elementary tests application it
303 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
305 ELM_CHECK_WIDTYPE(obj, widtype);
306 Widget_Data *wd = elm_widget_data_get(obj);
308 if (wd->content == content) return;
309 if (wd->content) evas_object_del(wd->content);
310 wd->content = content;
313 elm_widget_sub_object_add(obj, content);
314 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
315 _changed_size_hints, obj);
316 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
322 * Get the content shown in the bubble
324 * Return the content object which is set for this widget.
326 * @param obj The bubble object
327 * @return The content that is being used
332 elm_bubble_content_get(const Evas_Object *obj)
334 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
335 Widget_Data *wd = elm_widget_data_get(obj);
336 if (!wd) return NULL;
341 * Unset the content shown in the bubble
343 * Unparent and return the content object which was set for this widget.
345 * @param obj The bubble object
346 * @return The content that was being used
351 elm_bubble_content_unset(Evas_Object *obj)
353 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
354 Widget_Data *wd = elm_widget_data_get(obj);
355 Evas_Object *content;
356 if (!wd) return NULL;
357 if (!wd->content) return NULL;
358 content = wd->content;
359 elm_widget_sub_object_del(obj, content);
360 edje_object_part_unswallow(wd->bbl, content);
366 * Set the icon of the bubble
368 * Once the icon object is set, a previously set one will be deleted.
369 * If you want to keep the old content object, use the
370 * elm_icon_content_unset() function.
372 * @param obj The bubble object
373 * @param icon The given icon for the bubble
378 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
380 ELM_CHECK_WIDTYPE(obj, widtype);
381 Widget_Data *wd = elm_widget_data_get(obj);
383 if (wd->icon == icon) return;
384 if (wd->icon) evas_object_del(wd->icon);
388 elm_widget_sub_object_add(obj, icon);
389 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
390 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
391 _changed_size_hints, obj);
392 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
393 edje_object_message_signal_process(wd->bbl);
399 * Get the icon of the bubble
401 * @param obj The bubble object
402 * @return The icon for the bubble
404 * This function gets the icon shown on the top left of bubble.
409 elm_bubble_icon_get(const Evas_Object *obj)
411 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
412 Widget_Data *wd = elm_widget_data_get(obj);
413 if (!wd) return NULL;
418 * Unset the icon of the bubble
420 * Unparent and return the icon object which was set for this widget.
422 * @param obj The bubble object
423 * @return The icon that was being used
428 elm_bubble_icon_unset(Evas_Object *obj)
430 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
431 Widget_Data *wd = elm_widget_data_get(obj);
433 if (!wd) return NULL;
434 if (!wd->icon) return NULL;
436 elm_widget_sub_object_del(obj, icon);
437 edje_object_part_unswallow(wd->bbl, icon);
443 * Set the corner of the bubble
445 * @param obj The bubble object.
446 * @param corner The given corner for the bubble.
448 * This function sets the corner of the bubble.
449 * The corner will be used to find the group in the theme
450 * For example, if you set the corner to "bottom_right",
451 * the following group will be searched:
452 * "elm/bubble/bottom_right/default",
453 * considering default style.
458 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
460 ELM_CHECK_WIDTYPE(obj, widtype);
461 Widget_Data *wd = elm_widget_data_get(obj);
463 EINA_SAFETY_ON_NULL_RETURN(corner);
464 eina_stringshare_replace(&wd->corner, corner);
469 * Get the corner of the bubble
471 * @param obj The bubble object.
472 * @return The given corner for the bubble.
474 * This function gets the corner of the bubble.
479 elm_bubble_corner_get(const Evas_Object *obj)
481 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
482 Widget_Data *wd = elm_widget_data_get(obj);
483 if (!wd) return NULL;