1 #include <Elementary.h>
3 #include "elm_widget_bubble.h"
5 EAPI const char ELM_BUBBLE_SMART_NAME[] = "elm_bubble";
7 static const char SIG_CLICKED[] = "clicked";
9 static const Elm_Layout_Part_Alias_Description _content_aliases[] =
11 {"default", "elm.swallow.content"},
12 {"icon", "elm.swallow.icon"},
16 static const Elm_Layout_Part_Alias_Description _text_aliases[] =
18 {"default", "elm.text"},
23 static const Evas_Smart_Cb_Description _smart_callbacks[] =
29 static const char *corner_string[] =
37 EVAS_SMART_SUBCLASS_NEW
38 (ELM_BUBBLE_SMART_NAME, _elm_bubble, Elm_Bubble_Smart_Class,
39 Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks);
42 _elm_bubble_smart_sizing_eval(Evas_Object *obj)
44 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
46 ELM_BUBBLE_DATA_GET(obj, sd);
48 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
49 edje_object_size_min_restricted_calc
50 (ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh, minw, minh);
51 evas_object_size_hint_min_set(obj, minw, minh);
52 evas_object_size_hint_max_set(obj, maxw, maxh);
56 _on_mouse_up(void *data,
58 Evas_Object *obj __UNUSED__,
61 Evas_Event_Mouse_Up *ev = event_info;
63 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
66 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
69 /* overriding layout's focus_next() in order to just cycle through the
72 _elm_bubble_smart_focus_next(const Evas_Object *obj,
73 Elm_Focus_Direction dir,
78 ELM_BUBBLE_DATA_GET(obj, sd);
80 if ((elm_widget_can_focus_get(obj)) &&
81 (!ELM_WIDGET_DATA(sd)->focused))
84 *next = (Evas_Object *)obj;
89 content = elm_layout_content_get(obj, NULL);
90 if (!content) return EINA_FALSE;
92 /* attempt to follow focus cycle into sub-object */
93 return elm_widget_focus_next_get(content, dir, next);
98 _elm_bubble_smart_focus_direction(const Evas_Object *obj,
99 const Evas_Object *base,
101 Evas_Object **direction,
104 Evas_Object *content;
106 content = elm_layout_content_get(obj, NULL);
108 if (!content) return EINA_FALSE;
110 /* Try Focus cycle in subitem */
111 return elm_widget_focus_direction_get
112 (content, base, degree, direction, weight);
116 _elm_bubble_smart_text_set(Evas_Object *obj,
120 if (!_elm_bubble_parent_sc->text_set(obj, item, label))
123 if (item && (!strcmp(item, "info") || !strcmp(item, "elm.info")))
126 elm_layout_signal_emit(obj, "elm,state,info,visible", "elm");
128 elm_layout_signal_emit(obj, "elm,state,info,hidden", "elm");
131 elm_layout_sizing_eval(obj);
137 _access_info_cb(void *data __UNUSED__, Evas_Object *obj)
141 buf = eina_strbuf_new();
142 Evas_Object *content;
143 const char *default_txt = NULL;
144 const char *content_txt = NULL;
145 const char *info_txt = NULL;
147 default_txt = elm_widget_access_info_get(obj);
148 if (!default_txt) default_txt = elm_layout_text_get(obj, NULL);
149 if (default_txt) eina_strbuf_append(buf, default_txt);
151 content = elm_layout_content_get(obj, NULL);
152 if (content) content_txt = elm_layout_text_get(content, NULL);
155 if (!eina_strbuf_length_get(buf))
156 eina_strbuf_append(buf, content_txt);
158 eina_strbuf_append_printf(buf, ", %s", content_txt);
162 info_txt = edje_object_part_text_get(elm_layout_edje_get(obj), "elm.info");
165 if (!eina_strbuf_length_get(buf))
166 eina_strbuf_append(buf, info_txt);
168 eina_strbuf_append_printf(buf, ", %s", info_txt);
171 ret = eina_strbuf_string_steal(buf);
172 eina_strbuf_free(buf);
177 _elm_bubble_smart_add(Evas_Object *obj)
179 EVAS_SMART_DATA_ALLOC(obj, Elm_Bubble_Smart_Data);
181 ELM_WIDGET_CLASS(_elm_bubble_parent_sc)->base.add(obj);
183 priv->pos = ELM_BUBBLE_POS_TOP_LEFT; //default
185 elm_widget_can_focus_set(obj, EINA_FALSE);
187 evas_object_event_callback_add
188 (ELM_WIDGET_DATA(priv)->resize_obj, EVAS_CALLBACK_MOUSE_UP,
192 _elm_access_object_register(obj, ELM_WIDGET_DATA(priv)->resize_obj);
194 (_elm_access_object_get(obj), ELM_ACCESS_TYPE, E_("Bubble"));
195 _elm_access_callback_set
196 (_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
198 elm_layout_theme_set(obj, "bubble", "base", elm_widget_style_get(obj));
200 elm_layout_sizing_eval(obj);
202 if ((_elm_config->access_mode == ELM_ACCESS_MODE_ON))
203 elm_widget_can_focus_set(obj, EINA_TRUE);
207 _elm_bubble_smart_access(Evas_Object *obj, Eina_Bool is_access)
209 ELM_BUBBLE_CHECK(obj);
212 elm_widget_can_focus_set(obj, EINA_TRUE);
214 elm_widget_can_focus_set(obj, EINA_FALSE);
218 _elm_bubble_smart_set_user(Elm_Bubble_Smart_Class *sc)
220 ELM_WIDGET_CLASS(sc)->base.add = _elm_bubble_smart_add;
222 ELM_WIDGET_CLASS(sc)->focus_next = _elm_bubble_smart_focus_next;
223 ELM_WIDGET_CLASS(sc)->focus_direction = _elm_bubble_smart_focus_direction;
224 ELM_WIDGET_CLASS(sc)->access = _elm_bubble_smart_access;
226 ELM_LAYOUT_CLASS(sc)->text_set = _elm_bubble_smart_text_set;
227 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_bubble_smart_sizing_eval;
229 ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
230 ELM_LAYOUT_CLASS(sc)->text_aliases = _text_aliases;
233 EAPI const Elm_Bubble_Smart_Class *
234 elm_bubble_smart_class_get(void)
236 static Elm_Bubble_Smart_Class _sc =
237 ELM_BUBBLE_SMART_CLASS_INIT_NAME_VERSION(ELM_BUBBLE_SMART_NAME);
238 static const Elm_Bubble_Smart_Class *class = NULL;
239 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
244 _elm_bubble_smart_set(&_sc);
245 esc->callbacks = _smart_callbacks;
252 elm_bubble_add(Evas_Object *parent)
256 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
258 obj = elm_widget_add(_elm_bubble_smart_class_new(), parent);
259 if (!obj) return NULL;
261 if (!elm_widget_sub_object_add(parent, obj))
262 ERR("could not add %p as sub object of %p", obj, parent);
268 elm_bubble_pos_set(Evas_Object *obj,
271 ELM_BUBBLE_CHECK(obj);
272 ELM_BUBBLE_DATA_GET_OR_RETURN(obj, sd);
274 if (pos < ELM_BUBBLE_POS_TOP_LEFT || pos > ELM_BUBBLE_POS_BOTTOM_RIGHT)
279 eina_stringshare_replace
280 (&(ELM_LAYOUT_DATA(sd)->group), corner_string[sd->pos]);
282 ELM_WIDGET_DATA(sd)->api->theme(obj);
286 elm_bubble_pos_get(const Evas_Object *obj)
288 ELM_BUBBLE_CHECK(obj) ELM_BUBBLE_POS_INVALID;
289 ELM_BUBBLE_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_BUBBLE_POS_INVALID);