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 _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 _elm_bubble_label_set(Evas_Object *obj, const char *item, const char *label)
180 ELM_CHECK_WIDTYPE(obj, widtype);
181 Widget_Data *wd = elm_widget_data_get(obj);
184 if (!item || !strcmp(item, "default"))
186 eina_stringshare_replace(&wd->label, label);
187 edje_object_part_text_set(wd->bbl, "elm.text", label);
188 if (label) edje_object_signal_emit(wd->bbl, "elm,state,text,visible",
190 else edje_object_signal_emit(wd->bbl, "elm,state,text,hidden", "elm");
193 else if (!strcmp(item, "info"))
195 eina_stringshare_replace(&wd->info, label);
196 edje_object_part_text_set(wd->bbl, "elm.info", label);
197 if (label) edje_object_signal_emit(wd->bbl, "elm,state,info,visible",
199 else edje_object_signal_emit(wd->bbl, "elm,state,info,hidden", "elm");
205 _elm_bubble_label_get(const Evas_Object *obj, const char *item)
207 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
208 Widget_Data *wd = elm_widget_data_get(obj);
209 if (!wd) return NULL;
211 if (!item || !strcmp(item, "default"))
215 else if (!strcmp(item, "info"))
224 elm_bubble_add(Evas_Object *parent)
230 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
232 ELM_SET_WIDTYPE(widtype, "bubble");
233 elm_widget_type_set(obj, "bubble");
234 elm_widget_sub_object_add(parent, obj);
235 elm_widget_data_set(obj, wd);
236 elm_widget_del_hook_set(obj, _del_hook);
237 elm_widget_theme_hook_set(obj, _theme_hook);
238 elm_widget_focus_next_hook_set(obj, _elm_bubble_focus_next_hook);
239 elm_widget_can_focus_set(obj, EINA_FALSE);
240 elm_widget_text_set_hook_set(obj, _elm_bubble_label_set);
241 elm_widget_text_get_hook_set(obj, _elm_bubble_label_get);
243 wd->corner = eina_stringshare_add("base");
245 wd->bbl = edje_object_add(e);
246 elm_widget_resize_object_set(obj, wd->bbl);
248 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
249 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_UP,
252 evas_object_event_callback_add(wd->bbl, EVAS_CALLBACK_MOUSE_DOWN,
255 wd->down = EINA_FALSE;
256 wd->down_point.x = 0;
257 wd->down_point.y = 0;
260 evas_object_smart_callbacks_descriptions_set(obj, _signals);
261 _mirrored_set(obj, elm_widget_mirrored_get(obj));
262 _elm_theme_object_set(obj, wd->bbl, "bubble", wd->corner,
263 elm_widget_style_get(obj));
269 elm_bubble_label_set(Evas_Object *obj, const char *label)
271 _elm_bubble_label_set(obj, NULL, label);
275 elm_bubble_label_get(const Evas_Object *obj)
277 return _elm_bubble_label_get(obj, NULL);
281 elm_bubble_info_set(Evas_Object *obj, const char *info)
283 _elm_bubble_label_set(obj, "info", info);
287 elm_bubble_info_get(const Evas_Object *obj)
289 return _elm_bubble_label_get(obj, "info");
293 elm_bubble_content_set(Evas_Object *obj, Evas_Object *content)
295 ELM_CHECK_WIDTYPE(obj, widtype);
296 Widget_Data *wd = elm_widget_data_get(obj);
298 if (wd->content == content) return;
299 if (wd->content) evas_object_del(wd->content);
300 wd->content = content;
303 elm_widget_sub_object_add(obj, content);
304 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
305 _changed_size_hints, obj);
306 edje_object_part_swallow(wd->bbl, "elm.swallow.content", content);
312 elm_bubble_content_get(const Evas_Object *obj)
314 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
315 Widget_Data *wd = elm_widget_data_get(obj);
316 if (!wd) return NULL;
321 elm_bubble_content_unset(Evas_Object *obj)
323 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
324 Widget_Data *wd = elm_widget_data_get(obj);
325 Evas_Object *content;
326 if (!wd) return NULL;
327 if (!wd->content) return NULL;
328 content = wd->content;
329 elm_widget_sub_object_del(obj, content);
330 edje_object_part_unswallow(wd->bbl, content);
336 elm_bubble_icon_set(Evas_Object *obj, Evas_Object *icon)
338 ELM_CHECK_WIDTYPE(obj, widtype);
339 Widget_Data *wd = elm_widget_data_get(obj);
341 if (wd->icon == icon) return;
342 if (wd->icon) evas_object_del(wd->icon);
346 elm_widget_sub_object_add(obj, icon);
347 edje_object_part_swallow(wd->bbl, "elm.swallow.icon", icon);
348 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
349 _changed_size_hints, obj);
350 edje_object_signal_emit(wd->bbl, "elm,state,icon,visible", "elm");
351 edje_object_message_signal_process(wd->bbl);
357 elm_bubble_icon_get(const Evas_Object *obj)
359 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
360 Widget_Data *wd = elm_widget_data_get(obj);
361 if (!wd) return NULL;
366 elm_bubble_icon_unset(Evas_Object *obj)
368 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
369 Widget_Data *wd = elm_widget_data_get(obj);
371 if (!wd) return NULL;
372 if (!wd->icon) return NULL;
374 elm_widget_sub_object_del(obj, icon);
375 edje_object_part_unswallow(wd->bbl, icon);
381 elm_bubble_sweep_layout_set(Evas_Object *obj, Evas_Object *sweep)
383 ELM_CHECK_WIDTYPE(obj, widtype);
384 Widget_Data *wd = elm_widget_data_get(obj);
387 if (wd->sweep == sweep) return;
388 if (wd->sweep) evas_object_del(wd->sweep);
391 edje_object_part_swallow(wd->bbl, "elm.swallow.sweep", sweep);
396 elm_bubble_sweep_layout_unset(Evas_Object *obj)
398 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
399 Widget_Data *wd = elm_widget_data_get(obj);
400 Evas_Object *sweep = NULL;
401 if (!wd) return NULL;
403 if (!wd->sweep) return NULL;
405 edje_object_part_unswallow(wd->bbl, sweep);
406 evas_object_hide(sweep);
413 elm_bubble_corner_set(Evas_Object *obj, const char *corner)
415 ELM_CHECK_WIDTYPE(obj, widtype);
416 Widget_Data *wd = elm_widget_data_get(obj);
418 EINA_SAFETY_ON_NULL_RETURN(corner);
419 eina_stringshare_replace(&wd->corner, corner);
424 elm_bubble_corner_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;