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 if (wd->label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
70 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
71 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
72 if (wd->info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
73 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
76 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
77 edje_object_message_signal_process(wd->bbl);
80 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
82 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
83 edje_object_scale_set(wd->bbl,
84 elm_widget_scale_get(obj) * _elm_config->scale);
89 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
91 Widget_Data *wd = elm_widget_data_get(obj);
94 if ((!wd) || (!wd->content))
99 /* Try Focus cycle in subitem */
100 return elm_widget_focus_next_get(cur, dir, next);
104 _sizing_eval(Evas_Object *obj)
106 Widget_Data *wd = elm_widget_data_get(obj);
107 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
109 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
110 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
111 evas_object_size_hint_min_set(obj, minw, minh);
112 evas_object_size_hint_max_set(obj, maxw, maxh);
116 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
118 Widget_Data *wd = elm_widget_data_get(data);
124 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
126 Widget_Data *wd = elm_widget_data_get(obj);
127 Evas_Object *sub = event_info;
129 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
130 _changed_size_hints, obj);
131 if (sub == wd->content) wd->content = NULL;
132 else if (sub == wd->icon)
134 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
136 edje_object_message_signal_process(wd->bbl);
143 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
145 Widget_Data *wd = elm_widget_data_get(data);
146 Evas_Event_Mouse_Down *ev = event_info;
148 wd->down = EINA_TRUE;
149 wd->down_point.x = ev->canvas.x;
150 wd->down_point.y = ev->canvas.y;
155 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
157 Evas_Event_Mouse_Up *ev = event_info;
158 Widget_Data *wd = elm_widget_data_get(data);
159 if (!wd->down) return;
160 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
163 if (ev->canvas.x - wd->down_point.x > SWEEP_THRESHOLD)
164 evas_object_smart_callback_call(data, "sweep,left,right", NULL);
165 else if (wd->down_point.x - ev->canvas.x > SWEEP_THRESHOLD)
166 evas_object_smart_callback_call(data, "sweep,right,left", NULL);
168 wd->down = EINA_FALSE;
169 wd->down_point.x = 0;
170 wd->down_point.y = 0;
174 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
178 * Add a new bubble to the parent
180 * @param parent The parent object
181 * @return The new object or NULL if it cannot be created
183 * This function adds a text bubble to the given parent evas object.
188 elm_bubble_add(Evas_Object *parent)
194 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
196 wd = ELM_NEW(Widget_Data);
197 e = evas_object_evas_get(parent);
199 obj = elm_widget_add(e);
200 ELM_SET_WIDTYPE(widtype, "bubble");
201 elm_widget_type_set(obj, "bubble");
202 elm_widget_sub_object_add(parent, obj);
203 elm_widget_data_set(obj, wd);
204 elm_widget_del_hook_set(obj, _del_hook);
205 elm_widget_theme_hook_set(obj, _theme_hook);
206 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
207 elm_widget_can_focus_set(obj, EINA_FALSE);
209 wd->corner = eina_stringshare_add("base");
211 wd->bbl = edje_object_add(e);
212 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", "default");
213 elm_widget_resize_object_set(obj, wd->bbl);
215 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
216 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
219 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN,
222 wd->down = EINA_FALSE;
223 wd->down_point.x = 0;
224 wd->down_point.y = 0;
226 evas_object_smart_callbacks_descriptions_set(obj, _signals);
232 * Set the label of the bubble
234 * @param obj The bubble object
235 * @param label The string to set in the label
237 * This function sets the title of the bubble that is shown on top of
243 elm_bubble_label_set(Evas_Object *obj, const char *label)
245 ELM_CHECK_WIDTYPE(obj, widtype);
246 Widget_Data *wd = elm_widget_data_get(obj);
248 eina_stringshare_replace(&wd->label, label);
249 edje_object_part_text_set(wd->bbl, "elm.text", label);
250 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible", "elm");
251 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
256 * Get the label of the bubble
258 * @param obj The bubble object
259 * @return The string of set in the label
261 * This function gets the title of the bubble that is shown on top of
267 elm_bubble_label_get(const Evas_Object *obj)
269 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
270 Widget_Data *wd = elm_widget_data_get(obj);
271 if (!wd) return NULL;
276 * Set the info of the bubble
278 * @param obj The bubble object
279 * @param info The given info about the bubble
281 * This function sets the text shown on the top right of bubble.
282 * In the Anchorblock example of the Elementary tests application it
289 elm_bubble_info_set(Evas_Object *obj, const char *info)
291 ELM_CHECK_WIDTYPE(obj, widtype);
292 Widget_Data *wd = elm_widget_data_get(obj);
294 eina_stringshare_replace(&wd->info, info);
295 edje_object_part_text_set(wd->bbl, "elm.info", info);
296 if (info) edje_object_signal_emit(wd->bbl, "elm,state,info,visible", "elm");
297 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
302 * Get the info of the bubble
304 * @param obj The bubble object
306 * @return The "info" string of the bubble
308 * This function gets the text set to be displayed at the top right of
315 elm_bubble_info_get(const Evas_Object *obj)
317 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
318 Widget_Data *wd = elm_widget_data_get(obj);
319 if (!wd) return NULL;
324 * Set the content to be shown in the bubble
326 * Once the content object is set, a previously set one will be deleted.
327 * If you want to keep the old content object, use the
328 * elm_bubble_content_unset() function.
330 * @param obj The bubble object
331 * @param content The given content of the bubble
333 * This function sets the content shown on the middle of the bubble.
334 * In the Anchorblock example of the Elementary tests application it
340 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
342 ELM_CHECK_WIDTYPE(obj, widtype);
343 Widget_Data *wd = elm_widget_data_get(obj);
345 if (wd->content == content) return;
346 if (wd->content) evas_object_del(wd->content);
347 wd->content = content;
350 elm_widget_sub_object_add(obj, content);
351 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
352 _changed_size_hints, obj);
353 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
359 * Get the content shown in the bubble
361 * Return the content object which is set for this widget.
363 * @param obj The bubble object
364 * @return The content that is being used
369 elm_bubble_content_get(const Evas_Object *obj)
371 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
372 Widget_Data *wd = elm_widget_data_get(obj);
373 if (!wd) return NULL;
378 * Unset the content shown in the bubble
380 * Unparent and return the content object which was set for this widget.
382 * @param obj The bubble object
383 * @return The content that was being used
388 elm_bubble_content_unset(Evas_Object *obj)
390 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
391 Widget_Data *wd = elm_widget_data_get(obj);
392 Evas_Object *content;
393 if (!wd) return NULL;
394 if (!wd->content) return NULL;
395 content = wd->content;
396 elm_widget_sub_object_del(obj, content);
397 edje_object_part_unswallow(wd->bbl, content);
403 * Set the icon of the bubble
405 * Once the icon object is set, a previously set one will be deleted.
406 * If you want to keep the old content object, use the
407 * elm_icon_content_unset() function.
409 * @param obj The bubble object
410 * @param icon The given icon for the bubble
415 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
417 ELM_CHECK_WIDTYPE(obj, widtype);
418 Widget_Data *wd = elm_widget_data_get(obj);
420 if (wd->icon == icon) return;
421 if (wd->icon) evas_object_del(wd->icon);
425 elm_widget_sub_object_add(obj, icon);
426 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
427 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
428 _changed_size_hints, obj);
429 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
430 edje_object_message_signal_process(wd->bbl);
436 * Get the icon of the bubble
438 * @param obj The bubble object
439 * @return The icon for the bubble
441 * This function gets the icon shown on the top left of bubble.
446 elm_bubble_icon_get(const Evas_Object *obj)
448 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
449 Widget_Data *wd = elm_widget_data_get(obj);
450 if (!wd) return NULL;
455 * Unset the icon of the bubble
457 * Unparent and return the icon object which was set for this widget.
459 * @param obj The bubble object
460 * @return The icon that was being used
465 elm_bubble_icon_unset(Evas_Object *obj)
467 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
468 Widget_Data *wd = elm_widget_data_get(obj);
470 if (!wd) return NULL;
471 if (!wd->icon) return NULL;
473 elm_widget_sub_object_del(obj, icon);
474 edje_object_part_unswallow(wd->bbl, icon);
480 * Set the sweep layout
482 * @param obj The bubble object
483 * @param content The given content of the bubble
485 * This function sets the sweep layout when "sweep,left,right"signal is emitted.
490 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
492 ELM_CHECK_WIDTYPE(obj, widtype);
493 Widget_Data *wd = elm_widget_data_get(obj);
496 if (wd->sweep == sweep) return;
497 if (wd->sweep) evas_object_del(wd->sweep);
500 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 edje_object_part_unswallow(wd->bbl, sweep);
525 evas_object_hide(sweep);
532 * Set the corner of the bubble
534 * @param obj The bubble object.
535 * @param corner The given corner for the bubble.
537 * This function sets the corner of the bubble.
538 * The corner will be used to find the group in the theme
539 * For example, if you set the corner to "bottom_right",
540 * the following group will be searched:
541 * "elm/bubble/bottom_right/default",
542 * considering default style.
547 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
549 ELM_CHECK_WIDTYPE(obj, widtype);
550 Widget_Data *wd = elm_widget_data_get(obj);
552 EINA_SAFETY_ON_NULL_RETURN(corner);
553 eina_stringshare_replace(&wd->corner, corner);
558 * Get the corner of the bubble
560 * @param obj The bubble object.
561 * @return The given corner for the bubble.
563 * This function gets the corner of the bubble.
568 elm_bubble_corner_get(const Evas_Object *obj)
570 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
571 Widget_Data *wd = elm_widget_data_get(obj);
572 if (!wd) return NULL;