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 _sizing_eval(Evas_Object *obj)
87 Widget_Data *wd = elm_widget_data_get(obj);
88 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
90 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
91 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
92 evas_object_size_hint_min_set(obj, minw, minh);
93 evas_object_size_hint_max_set(obj, maxw, maxh);
97 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
99 Widget_Data *wd = elm_widget_data_get(data);
105 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
107 Widget_Data *wd = elm_widget_data_get(obj);
108 Evas_Object *sub = event_info;
110 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
111 _changed_size_hints, obj);
112 if (sub == wd->content) wd->content = NULL;
113 else if (sub == wd->icon)
115 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
117 edje_object_message_signal_process(wd->bbl);
120 else if (sub == wd->sweep) wd->sweep = NULL;
127 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
129 Widget_Data *wd = elm_widget_data_get(data);
130 Evas_Event_Mouse_Down *ev = event_info;
132 wd->down = EINA_TRUE;
133 wd->down_point.x = ev->canvas.x;
134 wd->down_point.y = ev->canvas.y;
139 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
141 Evas_Event_Mouse_Up *ev = event_info;
142 Widget_Data *wd = elm_widget_data_get(data);
143 if (!wd->down) return;
144 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
147 if (ev->canvas.x - wd->down_point.x > SWEEP_THRESHOLD)
148 evas_object_smart_callback_call(data, "sweep,left,right", NULL);
149 else if (wd->down_point.x - ev->canvas.x > SWEEP_THRESHOLD)
150 evas_object_smart_callback_call(data, "sweep,right,left", NULL);
152 wd->down = EINA_FALSE;
153 wd->down_point.x = 0;
154 wd->down_point.y = 0;
158 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
162 * Add a new bubble to the parent
164 * @param parent The parent object
165 * @return The new object or NULL if it cannot be created
167 * This function adds a text bubble to the given parent evas object.
172 elm_bubble_add(Evas_Object *parent)
178 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
180 wd = ELM_NEW(Widget_Data);
181 e = evas_object_evas_get(parent);
183 obj = elm_widget_add(e);
184 ELM_SET_WIDTYPE(widtype, "bubble");
185 elm_widget_type_set(obj, "bubble");
186 elm_widget_sub_object_add(parent, obj);
187 elm_widget_data_set(obj, wd);
188 elm_widget_del_hook_set(obj, _del_hook);
189 elm_widget_theme_hook_set(obj, _theme_hook);
190 elm_widget_can_focus_set(obj, EINA_FALSE);
192 wd->corner = eina_stringshare_add("base");
194 wd->bbl = edje_object_add(e);
195 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", "default");
196 elm_widget_resize_object_set(obj, wd->bbl);
198 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
199 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
202 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN,
205 wd->down = EINA_FALSE;
206 wd->down_point.x = 0;
207 wd->down_point.y = 0;
209 evas_object_smart_callbacks_descriptions_set(obj, _signals);
215 * Set the label of the bubble
217 * @param obj The bubble object
218 * @param label The string to set in the label
220 * This function sets the title of the bubble that is shown on top of
226 elm_bubble_label_set(Evas_Object *obj, const char *label)
228 ELM_CHECK_WIDTYPE(obj, widtype);
229 Widget_Data *wd = elm_widget_data_get(obj);
231 if (label) edje_object_signal_emit(wd->bbl, "elm,state,label,visible", "elm");
232 else edje_object_signal_emit(wd->bbl, "elm,state,label,hidden", "elm");
233 eina_stringshare_replace(&wd->label, label);
234 edje_object_part_text_set(wd->bbl, "elm.text", label);
239 * Get the label of the bubble
241 * @param obj The bubble object
242 * @return The string of set in the label
244 * This function gets the title of the bubble that is shown on top of
250 elm_bubble_label_get(const Evas_Object *obj)
252 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
253 Widget_Data *wd = elm_widget_data_get(obj);
254 if (!wd) return NULL;
259 * Set the info of the bubble
261 * @param obj The bubble object
262 * @param info The given info about the bubble
264 * This function sets the text shown on the top right of bubble.
265 * In the Anchorblock example of the Elementary tests application it
272 elm_bubble_info_set(Evas_Object *obj, const char *info)
274 ELM_CHECK_WIDTYPE(obj, widtype);
275 Widget_Data *wd = elm_widget_data_get(obj);
277 eina_stringshare_replace(&wd->info, info);
278 edje_object_part_text_set(wd->bbl, "elm.info", info);
283 * Get the info of the bubble
285 * @param obj The bubble object
287 * @return The "info" string of the bubble
289 * This function gets the text set to be displayed at the top right of
296 elm_bubble_info_get(const Evas_Object *obj)
298 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
299 Widget_Data *wd = elm_widget_data_get(obj);
300 if (!wd) return NULL;
305 * Set the content to be shown in the bubble
307 * Once the content object is set, a previously set one will be deleted.
308 * If you want to keep the old content object, use the
309 * elm_bubble_content_unset() function.
311 * @param obj The bubble object
312 * @param content The given content of the bubble
314 * This function sets the content shown on the middle of the bubble.
315 * In the Anchorblock example of the Elementary tests application it
321 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
323 ELM_CHECK_WIDTYPE(obj, widtype);
324 Widget_Data *wd = elm_widget_data_get(obj);
326 if (wd->content == content) return;
327 if (wd->content) evas_object_del(wd->content);
328 wd->content = content;
331 elm_widget_sub_object_add(obj, content);
332 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
333 _changed_size_hints, obj);
334 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
340 * Get the content shown in the bubble
342 * Return the content object which is set for this widget.
344 * @param obj The bubble object
345 * @return The content that is being used
350 elm_bubble_content_get(const Evas_Object *obj)
352 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
353 Widget_Data *wd = elm_widget_data_get(obj);
354 if (!wd) return NULL;
359 * Unset the content shown in the bubble
361 * Unparent and return the content object which was set for this widget.
363 * @param obj The bubble object
364 * @return The content that was being used
369 elm_bubble_content_unset(Evas_Object *obj)
371 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
372 Widget_Data *wd = elm_widget_data_get(obj);
373 Evas_Object *content;
374 if (!wd) return NULL;
375 if (!wd->content) return NULL;
376 content = wd->content;
377 elm_widget_sub_object_del(obj, content);
378 edje_object_part_unswallow(wd->bbl, content);
384 * Set the icon of the bubble
386 * Once the icon object is set, a previously set one will be deleted.
387 * If you want to keep the old content object, use the
388 * elm_icon_content_unset() function.
390 * @param obj The bubble object
391 * @param icon The given icon for the bubble
396 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
398 ELM_CHECK_WIDTYPE(obj, widtype);
399 Widget_Data *wd = elm_widget_data_get(obj);
401 if (wd->icon == icon) return;
402 if (wd->icon) evas_object_del(wd->icon);
406 elm_widget_sub_object_add(obj, icon);
407 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
408 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
409 _changed_size_hints, obj);
410 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
411 edje_object_message_signal_process(wd->bbl);
417 * Get the icon of the bubble
419 * @param obj The bubble object
420 * @return The icon for the bubble
422 * This function gets the icon shown on the top left of bubble.
427 elm_bubble_icon_get(const Evas_Object *obj)
429 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
430 Widget_Data *wd = elm_widget_data_get(obj);
431 if (!wd) return NULL;
436 * Unset the icon of the bubble
438 * Unparent and return the icon object which was set for this widget.
440 * @param obj The bubble object
441 * @return The icon that was being used
446 elm_bubble_icon_unset(Evas_Object *obj)
448 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
449 Widget_Data *wd = elm_widget_data_get(obj);
451 if (!wd) return NULL;
452 if (!wd->icon) return NULL;
454 elm_widget_sub_object_del(obj, icon);
455 edje_object_part_unswallow(wd->bbl, icon);
461 * Set the sweep layout
463 * @param obj The bubble object
464 * @param content The given content of the bubble
466 * This function sets the sweep layout when "sweep,left,right"signal is emitted.
471 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
473 ELM_CHECK_WIDTYPE(obj, widtype);
474 Widget_Data *wd = elm_widget_data_get(obj);
477 if (wd->sweep == sweep) return;
478 if (wd->sweep) evas_object_del(wd->sweep);
482 elm_widget_sub_object_add(obj, sweep);
483 edje_object_part_swallow(wd->bbl, "elm.swallow.sweep", sweep);
489 * Unset and hide the sweep layout
491 * @param obj The bubble object
492 * @param content The given content of the bubble
494 * This function sets the sweep layout when "sweep,right,left"signal is emitted.
499 elm_bubble_sweep_layout_unset(Evas_Object *obj)
501 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
502 Widget_Data *wd = elm_widget_data_get(obj);
503 Evas_Object *sweep = NULL;
504 if (!wd) return NULL;
506 if (!wd->sweep) return NULL;
508 elm_widget_sub_object_del(obj, sweep);
509 edje_object_part_unswallow(wd->bbl, sweep);
510 evas_object_hide(sweep);
517 * Set the corner of the bubble
519 * @param obj The bubble object.
520 * @param corner The given corner for the bubble.
522 * This function sets the corner of the bubble.
523 * The corner will be used to find the group in the theme
524 * For example, if you set the corner to "bottom_right",
525 * the following group will be searched:
526 * "elm/bubble/bottom_right/default",
527 * considering default style.
532 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
534 ELM_CHECK_WIDTYPE(obj, widtype);
535 Widget_Data *wd = elm_widget_data_get(obj);
537 EINA_SAFETY_ON_NULL_RETURN(corner);
538 eina_stringshare_replace(&wd->corner, corner);
543 * Get the corner of the bubble
545 * @param obj The bubble object.
546 * @return The given corner for the bubble.
548 * This function gets the corner of the bubble.
553 elm_bubble_corner_get(const Evas_Object *obj)
555 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
556 Widget_Data *wd = elm_widget_data_get(obj);
557 if (!wd) return NULL;