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.
11 * Signals that you can add callbacks for are:
13 * clicked - This is called when a user has clicked the bubble.
16 typedef struct _Widget_Data Widget_Data;
18 #define SWEEP_SUPPORT 1
23 Evas_Object *content, *icon;
24 const char *label, *info, *corner;
28 Evas_Coord_Point down_point;
33 #define SWEEP_THRESHOLD 100
36 static const char *widtype = NULL;
37 static void _del_hook(Evas_Object *obj);
38 static void _theme_hook(Evas_Object *obj);
39 static void _sizing_eval(Evas_Object *obj);
40 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
41 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
43 #define SIG_CLICKED "clicked"
44 static const Evas_Smart_Cb_Description _signals[] =
51 _del_hook(Evas_Object *obj)
53 Widget_Data *wd = elm_widget_data_get(obj);
55 if (wd->label) eina_stringshare_del(wd->label);
56 if (wd->info) eina_stringshare_del(wd->info);
57 if (wd->corner) eina_stringshare_del(wd->corner);
62 _theme_hook(Evas_Object *obj)
64 Widget_Data *wd = elm_widget_data_get(obj);
66 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
67 elm_widget_style_get(obj));
68 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
69 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
72 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
73 edje_object_message_signal_process(wd->bbl);
76 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
78 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
79 edje_object_scale_set(wd->bbl,
80 elm_widget_scale_get(obj) * _elm_config->scale);
85 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
87 Widget_Data *wd = elm_widget_data_get(obj);
90 if ((!wd) || (!wd->content))
95 /* Try Focus cycle in subitem */
96 return elm_widget_focus_next_get(cur, dir, next);
100 _sizing_eval(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
103 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
105 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
106 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
107 evas_object_size_hint_min_set(obj, minw, minh);
108 evas_object_size_hint_max_set(obj, maxw, maxh);
112 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
114 Widget_Data *wd = elm_widget_data_get(data);
120 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
122 Widget_Data *wd = elm_widget_data_get(obj);
123 Evas_Object *sub = event_info;
125 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
126 _changed_size_hints, obj);
127 if (sub == wd->content) wd->content = NULL;
128 else if (sub == wd->icon)
130 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
132 edje_object_message_signal_process(wd->bbl);
135 else if (sub == wd->sweep) wd->sweep = NULL;
142 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
144 Widget_Data *wd = elm_widget_data_get(data);
145 Evas_Event_Mouse_Down *ev = event_info;
147 wd->down = EINA_TRUE;
148 wd->down_point.x = ev->canvas.x;
149 wd->down_point.y = ev->canvas.y;
154 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
156 Evas_Event_Mouse_Up *ev = event_info;
157 Widget_Data *wd = elm_widget_data_get(data);
158 if (!wd->down) return;
159 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
162 if (ev->canvas.x - wd->down_point.x > SWEEP_THRESHOLD)
163 evas_object_smart_callback_call(data, "sweep,left,right", NULL);
164 else if (wd->down_point.x - ev->canvas.x > SWEEP_THRESHOLD)
165 evas_object_smart_callback_call(data, "sweep,right,left", NULL);
167 wd->down = EINA_FALSE;
168 wd->down_point.x = 0;
169 wd->down_point.y = 0;
173 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
177 * Add a new bubble to the parent
179 * @param parent The parent object
180 * @return The new object or NULL if it cannot be created
182 * This function adds a text bubble to the given parent evas object.
187 elm_bubble_add(Evas_Object *parent)
193 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
195 wd = ELM_NEW(Widget_Data);
196 e = evas_object_evas_get(parent);
198 obj = elm_widget_add(e);
199 ELM_SET_WIDTYPE(widtype, "bubble");
200 elm_widget_type_set(obj, "bubble");
201 elm_widget_sub_object_add(parent, obj);
202 elm_widget_data_set(obj, wd);
203 elm_widget_del_hook_set(obj, _del_hook);
204 elm_widget_theme_hook_set(obj, _theme_hook);
205 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
206 elm_widget_can_focus_set(obj, EINA_FALSE);
208 wd->corner = eina_stringshare_add("base");
210 wd->bbl = edje_object_add(e);
211 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", "default");
212 elm_widget_resize_object_set(obj, wd->bbl);
214 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
215 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
218 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN,
221 wd->down = EINA_FALSE;
222 wd->down_point.x = 0;
223 wd->down_point.y = 0;
225 evas_object_smart_callbacks_descriptions_set(obj, _signals);
231 * Set the label of the bubble
233 * @param obj The bubble object
234 * @param label The string to set in the label
236 * This function sets the title of the bubble that is shown on top of
242 elm_bubble_label_set(Evas_Object *obj, const char *label)
244 ELM_CHECK_WIDTYPE(obj, widtype);
245 Widget_Data *wd = elm_widget_data_get(obj);
247 if (label) edje_object_signal_emit(wd->bbl, "elm,state,label,visible", "elm");
248 else edje_object_signal_emit(wd->bbl, "elm,state,label,hidden", "elm");
249 eina_stringshare_replace(&wd->label, label);
250 edje_object_part_text_set(wd->bbl, "elm.text", label);
255 * Get the label of the bubble
257 * @param obj The bubble object
258 * @return The string of set in the label
260 * This function gets the title of the bubble that is shown on top of
266 elm_bubble_label_get(const Evas_Object *obj)
268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
269 Widget_Data *wd = elm_widget_data_get(obj);
270 if (!wd) return NULL;
275 * Set the info of the bubble
277 * @param obj The bubble object
278 * @param info The given info about the bubble
280 * This function sets the text shown on the top right of bubble.
281 * In the Anchorblock example of the Elementary tests application it
288 elm_bubble_info_set(Evas_Object *obj, const char *info)
290 ELM_CHECK_WIDTYPE(obj, widtype);
291 Widget_Data *wd = elm_widget_data_get(obj);
293 eina_stringshare_replace(&wd->info, info);
294 edje_object_part_text_set(wd->bbl, "elm.info", info);
299 * Get the info of the bubble
301 * @param obj The bubble object
303 * @return The "info" string of the bubble
305 * This function gets the text set to be displayed at the top right of
312 elm_bubble_info_get(const Evas_Object *obj)
314 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
315 Widget_Data *wd = elm_widget_data_get(obj);
316 if (!wd) return NULL;
321 * Set the content to be shown in the bubble
323 * Once the content object is set, a previously set one will be deleted.
324 * If you want to keep the old content object, use the
325 * elm_bubble_content_unset() function.
327 * @param obj The bubble object
328 * @param content The given content of the bubble
330 * This function sets the content shown on the middle of the bubble.
331 * In the Anchorblock example of the Elementary tests application it
337 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
339 ELM_CHECK_WIDTYPE(obj, widtype);
340 Widget_Data *wd = elm_widget_data_get(obj);
342 if (wd->content == content) return;
343 if (wd->content) evas_object_del(wd->content);
344 wd->content = content;
347 elm_widget_sub_object_add(obj, content);
348 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
349 _changed_size_hints, obj);
350 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
356 * Get the content shown in the bubble
358 * Return the content object which is set for this widget.
360 * @param obj The bubble object
361 * @return The content that is being used
366 elm_bubble_content_get(const Evas_Object *obj)
368 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
369 Widget_Data *wd = elm_widget_data_get(obj);
370 if (!wd) return NULL;
375 * Unset the content shown in the bubble
377 * Unparent and return the content object which was set for this widget.
379 * @param obj The bubble object
380 * @return The content that was being used
385 elm_bubble_content_unset(Evas_Object *obj)
387 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
388 Widget_Data *wd = elm_widget_data_get(obj);
389 Evas_Object *content;
390 if (!wd) return NULL;
391 if (!wd->content) return NULL;
392 content = wd->content;
393 elm_widget_sub_object_del(obj, content);
394 edje_object_part_unswallow(wd->bbl, content);
400 * Set the icon of the bubble
402 * Once the icon object is set, a previously set one will be deleted.
403 * If you want to keep the old content object, use the
404 * elm_icon_content_unset() function.
406 * @param obj The bubble object
407 * @param icon The given icon for the bubble
412 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
414 ELM_CHECK_WIDTYPE(obj, widtype);
415 Widget_Data *wd = elm_widget_data_get(obj);
417 if (wd->icon == icon) return;
418 if (wd->icon) evas_object_del(wd->icon);
422 elm_widget_sub_object_add(obj, icon);
423 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
424 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
425 _changed_size_hints, obj);
426 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
427 edje_object_message_signal_process(wd->bbl);
433 * Get the icon of the bubble
435 * @param obj The bubble object
436 * @return The icon for the bubble
438 * This function gets the icon shown on the top left of bubble.
443 elm_bubble_icon_get(const Evas_Object *obj)
445 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
446 Widget_Data *wd = elm_widget_data_get(obj);
447 if (!wd) return NULL;
452 * Unset the icon of the bubble
454 * Unparent and return the icon object which was set for this widget.
456 * @param obj The bubble object
457 * @return The icon that was being used
462 elm_bubble_icon_unset(Evas_Object *obj)
464 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
465 Widget_Data *wd = elm_widget_data_get(obj);
467 if (!wd) return NULL;
468 if (!wd->icon) return NULL;
470 elm_widget_sub_object_del(obj, icon);
471 edje_object_part_unswallow(wd->bbl, icon);
477 * Set the sweep layout
479 * @param obj The bubble object
480 * @param content The given content of the bubble
482 * This function sets the sweep layout when "sweep,left,right"signal is emitted.
487 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
489 ELM_CHECK_WIDTYPE(obj, widtype);
490 Widget_Data *wd = elm_widget_data_get(obj);
493 if (wd->sweep == sweep) return;
494 if (wd->sweep) evas_object_del(wd->sweep);
498 elm_widget_sub_object_add(obj, sweep);
499 edje_object_part_swallow(wd->bbl, "elm.swallow.sweep", sweep);
505 * Unset and hide the sweep layout
507 * @param obj The bubble object
508 * @param content The given content of the bubble
510 * This function sets the sweep layout when "sweep,right,left"signal is emitted.
515 elm_bubble_sweep_layout_unset(Evas_Object *obj)
517 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
518 Widget_Data *wd = elm_widget_data_get(obj);
519 Evas_Object *sweep = NULL;
520 if (!wd) return NULL;
522 if (!wd->sweep) return NULL;
524 elm_widget_sub_object_del(obj, sweep);
525 edje_object_part_unswallow(wd->bbl, sweep);
526 evas_object_hide(sweep);
533 * Set the corner of the bubble
535 * @param obj The bubble object.
536 * @param corner The given corner for the bubble.
538 * This function sets the corner of the bubble.
539 * The corner will be used to find the group in the theme
540 * For example, if you set the corner to "bottom_right",
541 * the following group will be searched:
542 * "elm/bubble/bottom_right/default",
543 * considering default style.
548 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
550 ELM_CHECK_WIDTYPE(obj, widtype);
551 Widget_Data *wd = elm_widget_data_get(obj);
553 EINA_SAFETY_ON_NULL_RETURN(corner);
554 eina_stringshare_replace(&wd->corner, corner);
559 * Get the corner of the bubble
561 * @param obj The bubble object.
562 * @return The given corner for the bubble.
564 * This function gets the corner of the bubble.
569 elm_bubble_corner_get(const Evas_Object *obj)
571 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
572 Widget_Data *wd = elm_widget_data_get(obj);
573 if (!wd) return NULL;