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, *sweep;
18 const char *label, *info;
21 Evas_Coord_Point down_point;
24 #define SWEEP_THRESHOLD 100
26 static const char *widtype = NULL;
27 static void _del_hook(Evas_Object *obj);
28 static void _theme_hook(Evas_Object *obj);
29 static void _sizing_eval(Evas_Object *obj);
30 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
31 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
34 _del_hook(Evas_Object *obj)
36 Widget_Data *wd = elm_widget_data_get(obj);
38 if (wd->label) eina_stringshare_del(wd->label);
39 if (wd->info) eina_stringshare_del(wd->info);
44 _theme_hook(Evas_Object *obj)
46 Widget_Data *wd = elm_widget_data_get(obj);
48 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", elm_widget_style_get(obj));
49 edje_object_part_text_set(wd->bbl, "elm.text", wd->label);
50 edje_object_part_text_set(wd->bbl, "elm.info", wd->info);
51 if (wd->content) edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
54 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", wd->icon);
55 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
56 edje_object_message_signal_process(wd->bbl);
58 edje_object_scale_set(wd->bbl, elm_widget_scale_get(obj) * _elm_config->scale);
63 _sizing_eval(Evas_Object *obj)
65 Widget_Data *wd = elm_widget_data_get(obj);
66 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
68 edje_object_size_min_calc(wd->bbl, &minw, &minh);
69 evas_object_size_hint_min_set(obj, minw, minh);
70 evas_object_size_hint_max_set(obj, maxw, maxh);
74 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
76 Widget_Data *wd = elm_widget_data_get(data);
82 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
84 Widget_Data *wd = elm_widget_data_get(obj);
85 Evas_Object *sub = event_info;
87 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
88 _changed_size_hints, obj);
89 if (sub == wd->content) wd->content = NULL;
90 else if (sub == wd->icon)
92 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
94 edje_object_message_signal_process(wd->bbl);
96 else if (sub == wd->sweep) wd->sweep = NULL;
101 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
103 Widget_Data *wd = elm_widget_data_get(data);
104 Evas_Event_Mouse_Down *ev = event_info;
106 wd->down = EINA_TRUE;
107 wd->down_point.x = ev->canvas.x;
108 wd->down_point.y = ev->canvas.y;
112 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
114 Widget_Data *wd = elm_widget_data_get(data);
115 Evas_Event_Mouse_Up *ev = event_info;
117 if (!wd->down) return;
119 if (ev->canvas.x - wd->down_point.x > SWEEP_THRESHOLD)
120 evas_object_smart_callback_call(data, "sweep,left,right", NULL);
121 else if (wd->down_point.x - ev->canvas.x > SWEEP_THRESHOLD)
122 evas_object_smart_callback_call(data, "sweep,right,left", NULL);
124 wd->down = EINA_FALSE;
125 wd->down_point.x = 0;
126 wd->down_point.y = 0;
130 * Add a new bubble to the parent
132 * @param parent The parent object
133 * @return The new object or NULL if it cannot be created
135 * This function adds a text bubble to the given parent evas object.
140 elm_bubble_add(Evas_Object *parent)
146 wd = ELM_NEW(Widget_Data);
147 e = evas_object_evas_get(parent);
148 obj = elm_widget_add(e);
149 ELM_SET_WIDTYPE(widtype, "bubble");
150 elm_widget_type_set(obj, "bubble");
151 elm_widget_sub_object_add(parent, obj);
152 elm_widget_data_set(obj, wd);
153 elm_widget_del_hook_set(obj, _del_hook);
154 elm_widget_theme_hook_set(obj, _theme_hook);
156 wd->bbl = edje_object_add(e);
157 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", "default");
158 elm_widget_resize_object_set(obj, wd->bbl);
160 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
161 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
162 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
164 wd->down = EINA_FALSE;
165 wd->down_point.x = 0;
166 wd->down_point.y = 0;
173 * Set the label of the bubble
175 * @param obj The bubble object
176 * @param label The string to set in the label
178 * This function sets the title of the bubble that is shown on top of
184 elm_bubble_label_set(Evas_Object *obj, const char *label)
186 ELM_CHECK_WIDTYPE(obj, widtype);
187 Widget_Data *wd = elm_widget_data_get(obj);
189 if (label) edje_object_signal_emit(wd->bbl, "elm,state,label,visible", "elm");
190 else edje_object_signal_emit(wd->bbl, "elm,state,label,hidden", "elm");
191 eina_stringshare_replace(&wd->label, label);
192 edje_object_part_text_set(wd->bbl, "elm.text", label);
197 * Get the label of the bubble
199 * @param obj The bubble object
200 * @return The string of set in the label
202 * This function gets the title of the bubble that is shown on top of
208 elm_bubble_label_get(const Evas_Object *obj)
210 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
211 Widget_Data *wd = elm_widget_data_get(obj);
212 if (!wd) return NULL;
217 * Set the info of the bubble
219 * @param obj The bubble object
220 * @param info The given info about the bubble
222 * This function sets the text shown on the top right of bubble.
223 * In the Anchorblock example of the Elementary tests application it
230 elm_bubble_info_set(Evas_Object *obj, const char *info)
232 ELM_CHECK_WIDTYPE(obj, widtype);
233 Widget_Data *wd = elm_widget_data_get(obj);
235 eina_stringshare_replace(&wd->info, info);
236 edje_object_part_text_set(wd->bbl, "elm.info", info);
241 * Get the info of the bubble
243 * @param obj The bubble object
245 * @return The "info" string of the bubble
247 * This function gets the text set to be displayed at the top right of
254 elm_bubble_info_get(const Evas_Object *obj)
256 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
257 Widget_Data *wd = elm_widget_data_get(obj);
258 if (!wd) return NULL;
263 * Set the content to be shown in the bubble
265 * Once the content object is set, a previously set one will be deleted.
266 * If you want to keep the old content object, use the
267 * elm_bubble_content_unset() function.
269 * @param obj The bubble object
270 * @param content The given content of the bubble
272 * This function sets the content shown on the middle of the bubble.
273 * In the Anchorblock example of the Elementary tests application it
279 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
281 ELM_CHECK_WIDTYPE(obj, widtype);
282 Widget_Data *wd = elm_widget_data_get(obj);
284 if (wd->content == content) return;
285 if (wd->content) evas_object_del(wd->content);
286 wd->content = content;
289 elm_widget_sub_object_add(obj, content);
290 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
291 _changed_size_hints, obj);
292 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
298 * Get the content shown in the bubble
300 * Return the content object which is set for this widget.
302 * @param obj The bubble object
303 * @return The content that is being used
308 elm_bubble_content_get(const Evas_Object *obj)
310 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
311 Widget_Data *wd = elm_widget_data_get(obj);
312 if (!wd) return NULL;
317 * Unset the content shown in the bubble
319 * Unparent and return the content object which was set for this widget.
321 * @param obj The bubble object
322 * @return The content that was being used
327 elm_bubble_content_unset(Evas_Object *obj)
329 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
330 Widget_Data *wd = elm_widget_data_get(obj);
331 Evas_Object *content;
332 if (!wd) return NULL;
333 if (!wd->content) return NULL;
334 content = wd->content;
335 elm_widget_sub_object_del(obj, content);
336 edje_object_part_unswallow(wd->bbl, content);
342 * Set the icon of the bubble
344 * Once the icon object is set, a previously set one will be deleted.
345 * If you want to keep the old content object, use the
346 * elm_icon_content_unset() function.
348 * @param obj The bubble object
349 * @param icon The given icon for the bubble
354 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
356 ELM_CHECK_WIDTYPE(obj, widtype);
357 Widget_Data *wd = elm_widget_data_get(obj);
359 if (wd->icon == icon) return;
360 if (wd->icon) evas_object_del(wd->icon);
364 elm_widget_sub_object_add(obj, icon);
365 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
366 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
367 _changed_size_hints, obj);
368 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
369 edje_object_message_signal_process(wd->bbl);
375 * Get the icon of the bubble
377 * @param obj The bubble object
378 * @return The icon for the bubble
380 * This function gets the icon shown on the top left of bubble.
385 elm_bubble_icon_get(const Evas_Object *obj)
387 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
388 Widget_Data *wd = elm_widget_data_get(obj);
389 if (!wd) return NULL;
394 * Unset the icon of the bubble
396 * Unparent and return the icon object which was set for this widget.
398 * @param obj The bubble object
399 * @return The icon that was being used
404 elm_bubble_icon_unset(Evas_Object *obj)
406 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
407 Widget_Data *wd = elm_widget_data_get(obj);
409 if (!wd) return NULL;
410 if (!wd->icon) return NULL;
412 elm_widget_sub_object_del(obj, icon);
413 edje_object_part_unswallow(wd->bbl, icon);
419 * Set the sweep layout
421 * @param obj The bubble object
422 * @param content The given content of the bubble
424 * This function sets the sweep layout when "sweep,left,right"signal is emitted.
429 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
431 ELM_CHECK_WIDTYPE(obj, widtype);
432 Widget_Data *wd = elm_widget_data_get(obj);
434 if (wd->sweep == sweep) return;
435 if (wd->sweep) evas_object_del(wd->sweep);
439 elm_widget_sub_object_add(obj, sweep);
440 edje_object_part_swallow(wd->bbl, "elm.swallow.sweep", sweep);
445 * Unset and hide the sweep layout
447 * @param obj The bubble object
448 * @param content The given content of the bubble
450 * This function sets the sweep layout when "sweep,right,left"signal is emitted.
455 elm_bubble_sweep_layout_unset(Evas_Object *obj)
457 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
458 Widget_Data *wd = elm_widget_data_get(obj);
460 if (!wd) return NULL;
461 if (!wd->sweep) return NULL;
463 elm_widget_sub_object_del(obj, sweep);
464 edje_object_part_unswallow(wd->bbl, sweep);
465 evas_object_hide(sweep);
471 * Set the corner of the bubble
473 * @param obj The bubble object.
474 * @param corner The given corner for the bubble.
476 * This function sets the corner of the bubble.
481 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
483 ELM_CHECK_WIDTYPE(obj, widtype);
484 Widget_Data *wd = elm_widget_data_get(obj);
486 _elm_theme_object_set(obj, wd->bbl, "bubble", corner, elm_widget_style_get(obj));
488 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", wd->icon);
490 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
491 // FIXME: fix label etc.