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);
53 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
54 edje_object_message_signal_process(wd->bbl);
58 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", wd->icon);
59 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
62 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
63 edje_object_scale_set(wd->bbl, elm_widget_scale_get(obj) * _elm_config->scale);
68 _sizing_eval(Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
71 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
73 edje_object_size_min_calc(wd->bbl, &minw, &minh);
74 evas_object_size_hint_min_set(obj, minw, minh);
75 evas_object_size_hint_max_set(obj, maxw, maxh);
79 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
81 Widget_Data *wd = elm_widget_data_get(data);
87 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
89 Widget_Data *wd = elm_widget_data_get(obj);
90 Evas_Object *sub = event_info;
92 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
93 _changed_size_hints, obj);
94 if (sub == wd->content) wd->content = NULL;
95 else if (sub == wd->icon)
97 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
99 edje_object_message_signal_process(wd->bbl);
101 else if (sub == wd->sweep) wd->sweep = NULL;
106 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
108 Widget_Data *wd = elm_widget_data_get(data);
109 Evas_Event_Mouse_Down *ev = event_info;
111 wd->down = EINA_TRUE;
112 wd->down_point.x = ev->canvas.x;
113 wd->down_point.y = ev->canvas.y;
117 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
119 Widget_Data *wd = elm_widget_data_get(data);
120 Evas_Event_Mouse_Up *ev = event_info;
122 if (!wd->down) return;
124 if (ev->canvas.x - wd->down_point.x > SWEEP_THRESHOLD)
125 evas_object_smart_callback_call(data, "sweep,left,right", NULL);
126 else if (wd->down_point.x - ev->canvas.x > SWEEP_THRESHOLD)
127 evas_object_smart_callback_call(data, "sweep,right,left", NULL);
129 wd->down = EINA_FALSE;
130 wd->down_point.x = 0;
131 wd->down_point.y = 0;
135 * Add a new bubble to the parent
137 * @param parent The parent object
138 * @return The new object or NULL if it cannot be created
140 * This function adds a text bubble to the given parent evas object.
145 elm_bubble_add(Evas_Object *parent)
151 wd = ELM_NEW(Widget_Data);
152 e = evas_object_evas_get(parent);
153 obj = elm_widget_add(e);
154 ELM_SET_WIDTYPE(widtype, "bubble");
155 elm_widget_type_set(obj, "bubble");
156 elm_widget_sub_object_add(parent, obj);
157 elm_widget_data_set(obj, wd);
158 elm_widget_del_hook_set(obj, _del_hook);
159 elm_widget_theme_hook_set(obj, _theme_hook);
161 wd->bbl = edje_object_add(e);
162 _elm_theme_object_set(obj, wd->bbl, "bubble", "base", "default");
163 elm_widget_resize_object_set(obj, wd->bbl);
165 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
166 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP, _mouse_up, obj);
167 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, obj);
169 wd->down = EINA_FALSE;
170 wd->down_point.x = 0;
171 wd->down_point.y = 0;
178 * Set the label of the bubble
180 * @param obj The bubble object
181 * @param label The string to set in the label
183 * This function sets the title of the bubble that is shown on top of
189 elm_bubble_label_set(Evas_Object *obj, const char *label)
191 ELM_CHECK_WIDTYPE(obj, widtype);
192 Widget_Data *wd = elm_widget_data_get(obj);
194 if (label) edje_object_signal_emit(wd->bbl, "elm,state,label,visible", "elm");
195 else edje_object_signal_emit(wd->bbl, "elm,state,label,hidden", "elm");
196 eina_stringshare_replace(&wd->label, label);
197 edje_object_part_text_set(wd->bbl, "elm.text", label);
202 * Get the label of the bubble
204 * @param obj The bubble object
205 * @return The string of set in the label
207 * This function gets the title of the bubble that is shown on top of
213 elm_bubble_label_get(const Evas_Object *obj)
215 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
216 Widget_Data *wd = elm_widget_data_get(obj);
217 if (!wd) return NULL;
222 * Set the info of the bubble
224 * @param obj The bubble object
225 * @param info The given info about the bubble
227 * This function sets the text shown on the top right of bubble.
228 * In the Anchorblock example of the Elementary tests application it
235 elm_bubble_info_set(Evas_Object *obj, const char *info)
237 ELM_CHECK_WIDTYPE(obj, widtype);
238 Widget_Data *wd = elm_widget_data_get(obj);
240 eina_stringshare_replace(&wd->info, info);
241 edje_object_part_text_set(wd->bbl, "elm.info", info);
246 * Get the info of the bubble
248 * @param obj The bubble object
250 * @return The "info" string of the bubble
252 * This function gets the text set to be displayed at the top right of
259 elm_bubble_info_get(const Evas_Object *obj)
261 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
262 Widget_Data *wd = elm_widget_data_get(obj);
263 if (!wd) return NULL;
268 * Set the content to be shown in the bubble
270 * Once the content object is set, a previously set one will be deleted.
271 * If you want to keep the old content object, use the
272 * elm_bubble_content_unset() function.
274 * @param obj The bubble object
275 * @param content The given content of the bubble
277 * This function sets the content shown on the middle of the bubble.
278 * In the Anchorblock example of the Elementary tests application it
284 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
286 ELM_CHECK_WIDTYPE(obj, widtype);
287 Widget_Data *wd = elm_widget_data_get(obj);
289 if (wd->content == content) return;
290 if (wd->content) evas_object_del(wd->content);
291 wd->content = content;
294 elm_widget_sub_object_add(obj, content);
295 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
296 _changed_size_hints, obj);
297 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
303 * Get the content shown in the bubble
305 * Return the content object which is set for this widget.
307 * @param obj The bubble object
308 * @return The content that is being used
313 elm_bubble_content_get(const Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
316 Widget_Data *wd = elm_widget_data_get(obj);
317 if (!wd) return NULL;
322 * Unset the content shown in the bubble
324 * Unparent and return the content object which was set for this widget.
326 * @param obj The bubble object
327 * @return The content that was being used
332 elm_bubble_content_unset(Evas_Object *obj)
334 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
335 Widget_Data *wd = elm_widget_data_get(obj);
336 Evas_Object *content;
337 if (!wd) return NULL;
338 if (!wd->content) return NULL;
339 content = wd->content;
340 elm_widget_sub_object_del(obj, content);
341 edje_object_part_unswallow(wd->bbl, content);
347 * Set the icon of the bubble
349 * Once the icon object is set, a previously set one will be deleted.
350 * If you want to keep the old content object, use the
351 * elm_icon_content_unset() function.
353 * @param obj The bubble object
354 * @param icon The given icon for the bubble
359 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
361 ELM_CHECK_WIDTYPE(obj, widtype);
362 Widget_Data *wd = elm_widget_data_get(obj);
364 if (wd->icon == icon) return;
365 if (wd->icon) evas_object_del(wd->icon);
369 elm_widget_sub_object_add(obj, icon);
370 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
371 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
372 _changed_size_hints, obj);
373 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
374 edje_object_message_signal_process(wd->bbl);
380 * Get the icon of the bubble
382 * @param obj The bubble object
383 * @return The icon for the bubble
385 * This function gets the icon shown on the top left of bubble.
390 elm_bubble_icon_get(const Evas_Object *obj)
392 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
393 Widget_Data *wd = elm_widget_data_get(obj);
394 if (!wd) return NULL;
399 * Unset the icon of the bubble
401 * Unparent and return the icon object which was set for this widget.
403 * @param obj The bubble object
404 * @return The icon that was being used
409 elm_bubble_icon_unset(Evas_Object *obj)
411 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
412 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd) return NULL;
415 if (!wd->icon) return NULL;
417 elm_widget_sub_object_del(obj, icon);
418 edje_object_part_unswallow(wd->bbl, icon);
424 * Set the sweep layout
426 * @param obj The bubble object
427 * @param content The given content of the bubble
429 * This function sets the sweep layout when "sweep,left,right"signal is emitted.
434 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
436 ELM_CHECK_WIDTYPE(obj, widtype);
437 Widget_Data *wd = elm_widget_data_get(obj);
439 if (wd->sweep == sweep) return;
440 if (wd->sweep) evas_object_del(wd->sweep);
444 elm_widget_sub_object_add(obj, sweep);
445 edje_object_part_swallow(wd->bbl, "elm.swallow.sweep", sweep);
450 * Unset and hide the sweep layout
452 * @param obj The bubble object
453 * @param content The given content of the bubble
455 * This function sets the sweep layout when "sweep,right,left"signal is emitted.
460 elm_bubble_sweep_layout_unset(Evas_Object *obj)
462 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
463 Widget_Data *wd = elm_widget_data_get(obj);
465 if (!wd) return NULL;
466 if (!wd->sweep) return NULL;
468 elm_widget_sub_object_del(obj, sweep);
469 edje_object_part_unswallow(wd->bbl, sweep);
470 evas_object_hide(sweep);
476 * Set the corner of the bubble
478 * @param obj The bubble object.
479 * @param corner The given corner for the bubble.
481 * This function sets the corner of the bubble.
486 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
488 ELM_CHECK_WIDTYPE(obj, widtype);
489 Widget_Data *wd = elm_widget_data_get(obj);
491 _elm_theme_object_set(obj, wd->bbl, "bubble", corner, elm_widget_style_get(obj));
493 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", wd->icon);
495 edje_object_part_swallow(wd->bbl, "elm.swallow.content", wd->content);
496 // FIXME: fix label etc.