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";
8 static const char SIG_ACCESS_CHANGED[] = "access,changed";
10 static const Elm_Layout_Part_Alias_Description _content_aliases[] =
12 {"default", "elm.swallow.content"},
13 {"icon", "elm.swallow.icon"},
17 static const Elm_Layout_Part_Alias_Description _text_aliases[] =
19 {"default", "elm.text"},
24 static const Evas_Smart_Cb_Description _smart_callbacks[] =
27 {SIG_ACCESS_CHANGED, ""},
31 static const char *corner_string[] =
39 EVAS_SMART_SUBCLASS_NEW
40 (ELM_BUBBLE_SMART_NAME, _elm_bubble, Elm_Bubble_Smart_Class,
41 Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks);
44 _elm_bubble_smart_sizing_eval(Evas_Object *obj)
46 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
48 ELM_BUBBLE_DATA_GET(obj, sd);
50 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
51 edje_object_size_min_restricted_calc
52 (ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh, minw, minh);
53 evas_object_size_hint_min_set(obj, minw, minh);
54 evas_object_size_hint_max_set(obj, maxw, maxh);
58 _on_mouse_up(void *data,
60 Evas_Object *obj __UNUSED__,
63 Evas_Event_Mouse_Up *ev = event_info;
65 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
68 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
71 /* overriding layout's focus_next() in order to just cycle through the
74 _elm_bubble_smart_focus_next(const Evas_Object *obj,
75 Elm_Focus_Direction dir,
80 ELM_BUBBLE_DATA_GET(obj, sd);
82 if ((elm_widget_can_focus_get(obj)) &&
83 (!ELM_WIDGET_DATA(sd)->focused))
86 *next = (Evas_Object *)obj;
91 content = elm_layout_content_get(obj, NULL);
92 if (!content) return EINA_FALSE;
94 /* attempt to follow focus cycle into sub-object */
95 return elm_widget_focus_next_get(content, dir, next);
100 _elm_bubble_smart_focus_direction(const Evas_Object *obj,
101 const Evas_Object *base,
103 Evas_Object **direction,
106 Evas_Object *content;
108 content = elm_layout_content_get(obj, NULL);
110 if (!content) return EINA_FALSE;
112 /* Try Focus cycle in subitem */
113 return elm_widget_focus_direction_get
114 (content, base, degree, direction, weight);
118 _elm_bubble_smart_text_set(Evas_Object *obj,
122 if (!_elm_bubble_parent_sc->text_set(obj, item, label))
125 if (item && (!strcmp(item, "info") || !strcmp(item, "elm.info")))
128 elm_layout_signal_emit(obj, "elm,state,info,visible", "elm");
130 elm_layout_signal_emit(obj, "elm,state,info,hidden", "elm");
133 elm_layout_sizing_eval(obj);
139 _access_info_cb(void *data __UNUSED__, Evas_Object *obj)
143 buf = eina_strbuf_new();
144 Evas_Object *content;
145 const char *default_txt = NULL;
146 const char *content_txt = NULL;
147 const char *info_txt = NULL;
149 default_txt = elm_widget_access_info_get(obj);
150 if (!default_txt) default_txt = elm_layout_text_get(obj, NULL);
151 if (default_txt) eina_strbuf_append(buf, default_txt);
153 content = elm_layout_content_get(obj, NULL);
154 if (content) content_txt = elm_layout_text_get(content, NULL);
157 if (!eina_strbuf_length_get(buf))
158 eina_strbuf_append(buf, content_txt);
160 eina_strbuf_append_printf(buf, ", %s", content_txt);
164 info_txt = edje_object_part_text_get(elm_layout_edje_get(obj), "elm.info");
167 if (!eina_strbuf_length_get(buf))
168 eina_strbuf_append(buf, info_txt);
170 eina_strbuf_append_printf(buf, ", %s", info_txt);
173 ret = eina_strbuf_string_steal(buf);
174 eina_strbuf_free(buf);
179 _elm_bubble_smart_add(Evas_Object *obj)
181 EVAS_SMART_DATA_ALLOC(obj, Elm_Bubble_Smart_Data);
183 ELM_WIDGET_CLASS(_elm_bubble_parent_sc)->base.add(obj);
185 priv->pos = ELM_BUBBLE_POS_TOP_LEFT; //default
187 elm_widget_can_focus_set(obj, EINA_FALSE);
189 evas_object_event_callback_add
190 (ELM_WIDGET_DATA(priv)->resize_obj, EVAS_CALLBACK_MOUSE_UP,
194 _elm_access_object_register(obj, ELM_WIDGET_DATA(priv)->resize_obj);
196 (_elm_access_object_get(obj), ELM_ACCESS_TYPE, E_("Bubble"));
197 _elm_access_callback_set
198 (_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
200 elm_layout_theme_set(obj, "bubble", "base", elm_widget_style_get(obj));
202 elm_layout_sizing_eval(obj);
204 if ((_elm_config->access_mode == ELM_ACCESS_MODE_ON))
205 elm_widget_can_focus_set(obj, EINA_TRUE);
209 _elm_bubble_smart_access(Evas_Object *obj, Eina_Bool is_access)
211 ELM_BUBBLE_CHECK(obj);
214 elm_widget_can_focus_set(obj, EINA_TRUE);
216 elm_widget_can_focus_set(obj, EINA_FALSE);
218 evas_object_smart_callback_call(obj, SIG_ACCESS_CHANGED, NULL);
222 _elm_bubble_smart_set_user(Elm_Bubble_Smart_Class *sc)
224 ELM_WIDGET_CLASS(sc)->base.add = _elm_bubble_smart_add;
226 ELM_WIDGET_CLASS(sc)->focus_next = _elm_bubble_smart_focus_next;
227 ELM_WIDGET_CLASS(sc)->focus_direction = _elm_bubble_smart_focus_direction;
228 ELM_WIDGET_CLASS(sc)->access = _elm_bubble_smart_access;
230 ELM_LAYOUT_CLASS(sc)->text_set = _elm_bubble_smart_text_set;
231 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_bubble_smart_sizing_eval;
233 ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
234 ELM_LAYOUT_CLASS(sc)->text_aliases = _text_aliases;
237 EAPI const Elm_Bubble_Smart_Class *
238 elm_bubble_smart_class_get(void)
240 static Elm_Bubble_Smart_Class _sc =
241 ELM_BUBBLE_SMART_CLASS_INIT_NAME_VERSION(ELM_BUBBLE_SMART_NAME);
242 static const Elm_Bubble_Smart_Class *class = NULL;
243 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
248 _elm_bubble_smart_set(&_sc);
249 esc->callbacks = _smart_callbacks;
256 elm_bubble_add(Evas_Object *parent)
260 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
262 obj = elm_widget_add(_elm_bubble_smart_class_new(), parent);
263 if (!obj) return NULL;
265 if (!elm_widget_sub_object_add(parent, obj))
266 ERR("could not add %p as sub object of %p", obj, parent);
272 elm_bubble_pos_set(Evas_Object *obj,
275 ELM_BUBBLE_CHECK(obj);
276 ELM_BUBBLE_DATA_GET_OR_RETURN(obj, sd);
278 if (pos < ELM_BUBBLE_POS_TOP_LEFT || pos > ELM_BUBBLE_POS_BOTTOM_RIGHT)
283 eina_stringshare_replace
284 (&(ELM_LAYOUT_DATA(sd)->group), corner_string[sd->pos]);
286 ELM_WIDGET_DATA(sd)->api->theme(obj);
290 elm_bubble_pos_get(const Evas_Object *obj)
292 ELM_BUBBLE_CHECK(obj) ELM_BUBBLE_POS_INVALID;
293 ELM_BUBBLE_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_BUBBLE_POS_INVALID);