1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
6 #define SWEEP_SUPPORT 1
11 Evas_Object *content, *icon;
12 const char *label, *info, *corner;
16 Evas_Coord_Point down_point;
21 #define SWEEP_THRESHOLD 100
24 static const char *widtype = NULL;
25 static void _del_hook(Evas_Object *obj);
26 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
27 static void _theme_hook(Evas_Object *obj);
28 static void _sizing_eval(Evas_Object *obj);
29 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
30 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
32 static const char SIG_CLICKED[] = "clicked";
34 static const Evas_Smart_Cb_Description _signals[] =
41 _del_hook(Evas_Object *obj)
43 Widget_Data *wd = elm_widget_data_get(obj);
45 if (wd->label) eina_stringshare_del(wd->label);
46 if (wd->info) eina_stringshare_del(wd->info);
47 if (wd->corner) eina_stringshare_del(wd->corner);
52 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
54 Widget_Data *wd = elm_widget_data_get(obj);
56 edje_object_mirrored_set(wd->bbl, rtl);
60 _theme_hook(Evas_Object *obj)
62 Widget_Data *wd = elm_widget_data_get(obj);
64 _elm_widget_mirrored_reload(obj);
65 _mirrored_set(obj, elm_widget_mirrored_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 _content_set(Evas_Object *obj, Evas_Object *content)
91 Widget_Data *wd = elm_widget_data_get(obj);
94 if (wd->content == content) return;
95 if (wd->content) evas_object_del(wd->content);
96 wd->content = content;
99 elm_widget_sub_object_add(obj, content);
100 evas_object_event_callback_add(content,
101 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
102 _changed_size_hints, obj);
103 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
109 _content_unset(Evas_Object *obj)
111 Widget_Data *wd = elm_widget_data_get(obj);
112 Evas_Object *content;
113 if (!wd) return NULL;
114 if (!wd->content) return NULL;
115 content = wd->content;
116 elm_widget_sub_object_del(obj, content);
117 evas_object_event_callback_del_full(content,
118 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
119 _changed_size_hints, obj);
120 edje_object_part_unswallow(wd->bbl, content);
126 _icon_set(Evas_Object *obj, Evas_Object* icon)
128 Widget_Data *wd = elm_widget_data_get(obj);
130 if (wd->icon == icon) return;
131 if (wd->icon) evas_object_del(wd->icon);
135 elm_widget_sub_object_add(obj, icon);
136 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
137 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
138 _changed_size_hints, obj);
139 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
140 edje_object_message_signal_process(wd->bbl);
146 _icon_unset(Evas_Object *obj)
148 Widget_Data *wd = elm_widget_data_get(obj);
150 if (!wd) return NULL;
151 if (!wd->icon) return NULL;
153 elm_widget_sub_object_del(obj, icon);
154 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
155 _changed_size_hints, obj);
156 edje_object_part_unswallow(wd->bbl, icon);
162 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
164 ELM_CHECK_WIDTYPE(obj, widtype);
165 Widget_Data *wd = elm_widget_data_get(obj);
168 if (!part || !strcmp(part, "default"))
169 _content_set(obj, content);
170 else if(!strcmp(part, "icon"))
171 _icon_set(obj, content);
175 _content_get_hook(const Evas_Object *obj, const char *part)
177 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
178 Widget_Data *wd = elm_widget_data_get(obj);
179 if (!wd) return NULL;
180 if (!part || !strcmp(part, "default"))
182 else if(!strcmp(part, "icon"))
188 _content_unset_hook(Evas_Object *obj, const char *part)
190 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
191 Widget_Data *wd = elm_widget_data_get(obj);
192 if (!wd) return NULL;
193 if (!part || !strcmp(part, "default"))
194 return _content_unset(obj);
195 else if(!strcmp(part, "icon"))
196 return _icon_unset(obj);
201 _elm_bubble_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
203 Widget_Data *wd = elm_widget_data_get(obj);
206 if ((!wd) || (!wd->content))
211 /* Try Focus cycle in subitem */
212 return elm_widget_focus_next_get(cur, dir, next);
216 _sizing_eval(Evas_Object *obj)
218 Widget_Data *wd = elm_widget_data_get(obj);
219 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
221 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
222 edje_object_size_min_restricted_calc(wd->bbl, &minw, &minh, minw, minh);
223 evas_object_size_hint_min_set(obj, minw, minh);
224 evas_object_size_hint_max_set(obj, maxw, maxh);
228 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
230 Widget_Data *wd = elm_widget_data_get(data);
236 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
238 Widget_Data *wd = elm_widget_data_get(obj);
239 Evas_Object *sub = event_info;
241 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
242 _changed_size_hints, obj);
243 if (sub == wd->content) wd->content = NULL;
244 else if (sub == wd->icon)
246 edje_object_signal_emit(wd->bbl, "elm,state,icon,hidden", "elm");
248 edje_object_message_signal_process(wd->bbl);
255 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
257 Widget_Data *wd = elm_widget_data_get(data);
258 Evas_Event_Mouse_Down *ev = event_info;
260 wd->down = EINA_TRUE;
261 wd->down_point.x = ev->canvas.x;
262 wd->down_point.y = ev->canvas.y;
267 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
269 Evas_Event_Mouse_Up *ev = event_info;
270 Widget_Data *wd = elm_widget_data_get(data);
271 if (!wd->down) return;
272 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
275 if (ev->canvas.x - wd->down_point.x > SWEEP_THRESHOLD)
276 evas_object_smart_callback_call(data, "sweep,left,right", NULL);
277 else if (wd->down_point.x - ev->canvas.x > SWEEP_THRESHOLD)
278 evas_object_smart_callback_call(data, "sweep,right,left", NULL);
280 wd->down = EINA_FALSE;
281 wd->down_point.x = 0;
282 wd->down_point.y = 0;
286 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
290 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
292 ELM_CHECK_WIDTYPE(obj, widtype);
293 Widget_Data *wd = elm_widget_data_get(obj);
296 if (!item || !strcmp(item, "default"))
298 eina_stringshare_replace(&wd->label, label);
299 edje_object_part_text_set(wd->bbl, "elm.text", label);
300 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
302 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
305 else if (!strcmp(item, "info"))
307 eina_stringshare_replace(&wd->info, label);
308 edje_object_part_text_set(wd->bbl, "elm.info", label);
309 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
311 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
317 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
319 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
320 Widget_Data *wd = elm_widget_data_get(obj);
321 if (!wd) return NULL;
323 if (!item || !strcmp(item, "default"))
327 else if (!strcmp(item, "info"))
336 elm_bubble_add(Evas_Object *parent)
342 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
344 ELM_SET_WIDTYPE(widtype, "bubble");
345 elm_widget_type_set(obj, "bubble");
346 elm_widget_sub_object_add(parent, obj);
347 elm_widget_data_set(obj, wd);
348 elm_widget_del_hook_set(obj, _del_hook);
349 elm_widget_theme_hook_set(obj, _theme_hook);
350 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
351 elm_widget_can_focus_set(obj, EINA_FALSE);
352 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
353 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
355 wd->corner = eina_stringshare_add("base");
357 wd->bbl = edje_object_add(e);
358 elm_widget_resize_object_set(obj, wd->bbl);
360 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
361 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
364 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN,
367 wd->down = EINA_FALSE;
368 wd->down_point.x = 0;
369 wd->down_point.y = 0;
372 evas_object_smart_callbacks_descriptions_set(obj, _signals);
373 _mirrored_set(obj, elm_widget_mirrored_get(obj));
374 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
375 elm_widget_style_get(obj));
381 elm_bubble_label_set(Evas_Object *obj, const char *label)
383 _elm_bubble_label_set(obj, NULL, label);
387 elm_bubble_label_get(const Evas_Object *obj)
389 return _elm_bubble_label_get(obj, NULL);
393 elm_bubble_info_set(Evas_Object *obj, const char *info)
395 _elm_bubble_label_set(obj, "info", info);
399 elm_bubble_info_get(const Evas_Object *obj)
401 return _elm_bubble_label_get(obj, "info");
405 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
407 ELM_CHECK_WIDTYPE(obj, widtype);
408 Widget_Data *wd = elm_widget_data_get(obj);
410 if (wd->content == content) return;
411 if (wd->content) evas_object_del(wd->content);
412 wd->content = content;
415 elm_widget_sub_object_add(obj, content);
416 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
417 _changed_size_hints, obj);
418 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
424 elm_bubble_content_get(const Evas_Object *obj)
426 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
427 Widget_Data *wd = elm_widget_data_get(obj);
428 if (!wd) return NULL;
433 elm_bubble_content_unset(Evas_Object *obj)
435 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
436 Widget_Data *wd = elm_widget_data_get(obj);
437 Evas_Object *content;
438 if (!wd) return NULL;
439 if (!wd->content) return NULL;
440 content = wd->content;
441 elm_widget_sub_object_del(obj, content);
442 evas_object_event_callback_del_full(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
443 _changed_size_hints, obj);
444 edje_object_part_unswallow(wd->bbl, content);
450 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
452 _content_set_hook(obj, "elm.swallow.icon", icon);
456 elm_bubble_icon_get(const Evas_Object *obj)
458 return _content_get_hook(obj, "elm.swallow.icon");
462 elm_bubble_icon_unset(Evas_Object *obj)
464 return _content_unset_hook(obj, "elm.swallow.icon");
468 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
470 ELM_CHECK_WIDTYPE(obj, widtype);
471 Widget_Data *wd = elm_widget_data_get(obj);
474 if (wd->sweep == sweep) return;
475 if (wd->sweep) evas_object_del(wd->sweep);
478 edje_object_part_swallow(wd->bbl, "elm.swallow.sweep", sweep);
483 elm_bubble_sweep_layout_unset(Evas_Object *obj)
485 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
486 Widget_Data *wd = elm_widget_data_get(obj);
487 Evas_Object *icon = NULL;
488 if (!wd) return NULL;
489 if (!wd->icon) return NULL;
491 elm_widget_sub_object_del(obj, icon);
492 evas_object_event_callback_del_full(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
493 _changed_size_hints, obj);
494 edje_object_part_unswallow(wd->bbl, icon);
500 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
502 ELM_CHECK_WIDTYPE(obj, widtype);
503 Widget_Data *wd = elm_widget_data_get(obj);
505 EINA_SAFETY_ON_NULL_RETURN(corner);
506 eina_stringshare_replace(&wd->corner, corner);
511 elm_bubble_corner_get(const Evas_Object *obj)
513 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
514 Widget_Data *wd = elm_widget_data_get(obj);
515 if (!wd) return NULL;