1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Anchorview_Item_Provider Elm_Anchorview_Item_Provider;
9 Evas_Object *scroller, *entry;
10 Evas_Object *hover_parent;
11 Evas_Object *pop, *hover;
12 Eina_List *item_providers;
13 const char *hover_style;
16 struct _Elm_Anchorview_Item_Provider
18 Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item);
22 static const char *widtype = NULL;
24 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
25 static const Evas_Smart_Cb_Description _signals[] = {
26 {SIG_ANCHOR_CLICKED, ""}, /* TODO: declare the type properly, as data is
32 static void _del_pre_hook(Evas_Object *obj);
33 static void _del_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
36 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
40 _del_pre_hook(Evas_Object *obj)
42 elm_anchorview_hover_end(obj);
43 elm_anchorview_hover_parent_set(obj, NULL);
47 _del_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_get(obj);
50 Elm_Anchorview_Item_Provider *ip;
52 if (wd->hover_style) eina_stringshare_del(wd->hover_style);
53 EINA_LIST_FREE(wd->item_providers, ip)
61 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
63 Widget_Data *wd = elm_widget_data_get(obj);
65 elm_widget_mirrored_set(wd->hover, rtl);
69 _theme_hook(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
73 _elm_widget_mirrored_reload(obj);
74 _mirrored_set(obj, elm_widget_mirrored_get(obj));
78 _sizing_eval(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
81 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
83 evas_object_size_hint_min_set(obj, minw, minh);
84 evas_object_size_hint_max_set(obj, maxw, maxh);
88 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
94 _hover_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
96 elm_anchorview_hover_end(data);
100 _anchor_clicked(void *data, Evas_Object *obj, void *event_info)
102 Widget_Data *wd = elm_widget_data_get(data);
103 Elm_Entry_Anchor_Info *info = event_info;
104 Evas_Object *hover_parent;
105 Elm_Entry_Anchorview_Info ei;
106 Evas_Coord x, w, y, h, px, py;
108 wd->pop = elm_icon_add(obj);
109 evas_object_move(wd->pop, info->x, info->y);
110 evas_object_resize(wd->pop, info->w, info->h);
111 wd->hover = elm_hover_add(obj);
112 elm_widget_mirrored_set(wd->hover, elm_widget_mirrored_get((Evas_Object *) data));
113 if (wd->hover_style) elm_object_style_set(wd->hover, wd->hover_style);
114 hover_parent = wd->hover_parent;
115 if (!hover_parent) hover_parent = obj;
116 elm_hover_parent_set(wd->hover, hover_parent);
117 elm_hover_target_set(wd->hover, wd->pop);
118 ei.name = info->name;
119 ei.button = info->button;
120 ei.hover = wd->hover;
121 ei.anchor.x = info->x;
122 ei.anchor.y = info->y;
123 ei.anchor.w = info->w;
124 ei.anchor.h = info->h;
125 evas_object_geometry_get(hover_parent, &x, &y, &w, &h);
126 ei.hover_parent.x = x;
127 ei.hover_parent.y = y;
128 ei.hover_parent.w = w;
129 ei.hover_parent.h = h;
130 px = info->x + (info->w / 2);
131 py = info->y + (info->h / 2);
133 if (px < (x + (w / 3))) ei.hover_left = 0;
135 if (px > (x + ((w * 2) / 3))) ei.hover_right = 0;
137 if (py < (y + (h / 3))) ei.hover_top = 0;
139 if (py > (y + ((h * 2) / 3))) ei.hover_bottom = 0;
141 if (elm_widget_mirrored_get(wd->hover))
142 { /* Swap right and left because they switch sides in RTL */
143 Eina_Bool tmp = ei.hover_left;
144 ei.hover_left = ei.hover_right;
145 ei.hover_right = tmp;
148 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
149 evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked, data);
150 evas_object_show(wd->hover);
154 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
156 Widget_Data *wd = elm_widget_data_get(data);
158 wd->hover_parent = NULL;
162 _item_provider(void *data, Evas_Object *entry __UNUSED__, const char *item)
164 Widget_Data *wd = elm_widget_data_get(data);
166 Elm_Anchorview_Item_Provider *ip;
168 EINA_LIST_FOREACH(wd->item_providers, l, ip)
172 o = ip->func(ip->data, data, item);
179 _elm_anchorview_text_set(Evas_Object *obj, const char *item, const char *text)
181 ELM_CHECK_WIDTYPE(obj, widtype);
182 Widget_Data *wd = elm_widget_data_get(obj);
183 if (item && strcmp(item, "default")) return;
185 elm_object_text_set(wd->entry, text);
186 if (wd->hover) evas_object_del(wd->hover);
187 if (wd->pop) evas_object_del(wd->pop);
194 _elm_anchorview_text_get(const Evas_Object *obj, const char *item)
196 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
197 Widget_Data *wd = elm_widget_data_get(obj);
198 if (item && strcmp(item, "default")) return NULL;
199 if (!wd) return NULL;
200 return elm_object_text_get(wd->entry);
204 elm_anchorview_add(Evas_Object *parent)
210 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
212 ELM_SET_WIDTYPE(widtype, "anchorview");
213 elm_widget_type_set(obj, "anchorview");
214 elm_widget_sub_object_add(parent, obj);
215 elm_widget_data_set(obj, wd);
216 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
217 elm_widget_del_hook_set(obj, _del_hook);
218 elm_widget_theme_hook_set(obj, _theme_hook);
219 elm_widget_can_focus_set(obj, EINA_TRUE);
220 elm_widget_text_set_hook_set(obj, _elm_anchorview_text_set);
221 elm_widget_text_get_hook_set(obj, _elm_anchorview_text_get);
223 wd->scroller = elm_scroller_add(parent);
224 elm_widget_resize_object_set(obj, wd->scroller);
225 wd->entry = elm_entry_add(parent);
226 elm_entry_item_provider_prepend(wd->entry, _item_provider, obj);
227 elm_entry_editable_set(wd->entry, 0);
228 evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
229 evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
230 elm_object_content_set(wd->scroller, wd->entry);
231 evas_object_show(wd->entry);
233 evas_object_event_callback_add(wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
234 _changed_size_hints, obj);
236 elm_object_text_set(wd->entry, "");
238 evas_object_smart_callback_add(wd->entry, "anchor,clicked",
239 _anchor_clicked, obj);
241 _mirrored_set(obj, elm_widget_mirrored_get(obj));
244 // TODO: convert Elementary to subclassing of Evas_Smart_Class
245 // TODO: and save some bytes, making descriptions per-class and not instance!
246 evas_object_smart_callbacks_descriptions_set(obj, _signals);
251 elm_anchorview_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
253 ELM_CHECK_WIDTYPE(obj, widtype);
254 Widget_Data *wd = elm_widget_data_get(obj);
256 if (wd->hover_parent)
257 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL, _parent_del, obj);
258 wd->hover_parent = parent;
259 if (wd->hover_parent)
260 evas_object_event_callback_add(wd->hover_parent, EVAS_CALLBACK_DEL, _parent_del, obj);
264 elm_anchorview_hover_parent_get(const Evas_Object *obj)
266 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
267 Widget_Data *wd = elm_widget_data_get(obj);
268 if (!wd) return NULL;
269 return wd->hover_parent;
273 elm_anchorview_hover_style_set(Evas_Object *obj, const char *style)
275 ELM_CHECK_WIDTYPE(obj, widtype);
276 Widget_Data *wd = elm_widget_data_get(obj);
278 eina_stringshare_replace(&wd->hover_style, style);
282 elm_anchorview_hover_style_get(const Evas_Object *obj)
284 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
285 Widget_Data *wd = elm_widget_data_get(obj);
286 if (!wd) return NULL;
287 return wd->hover_style;
291 elm_anchorview_hover_end(Evas_Object *obj)
293 ELM_CHECK_WIDTYPE(obj, widtype);
294 Widget_Data *wd = elm_widget_data_get(obj);
296 if (wd->hover) evas_object_del(wd->hover);
297 if (wd->pop) evas_object_del(wd->pop);
303 elm_anchorview_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
305 ELM_CHECK_WIDTYPE(obj, widtype);
306 Widget_Data *wd = elm_widget_data_get(obj);
308 elm_scroller_bounce_set(wd->scroller, h_bounce, v_bounce);
312 elm_anchorview_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
314 ELM_CHECK_WIDTYPE(obj, widtype);
315 Widget_Data *wd = elm_widget_data_get(obj);
317 elm_scroller_bounce_get(wd->scroller, h_bounce, v_bounce);
321 elm_anchorview_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
323 ELM_CHECK_WIDTYPE(obj, widtype);
324 Widget_Data *wd = elm_widget_data_get(obj);
326 EINA_SAFETY_ON_NULL_RETURN(func);
327 Elm_Anchorview_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorview_Item_Provider));
331 wd->item_providers = eina_list_append(wd->item_providers, ip);
335 elm_anchorview_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
337 ELM_CHECK_WIDTYPE(obj, widtype);
338 Widget_Data *wd = elm_widget_data_get(obj);
340 EINA_SAFETY_ON_NULL_RETURN(func);
341 Elm_Anchorview_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorview_Item_Provider));
345 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
349 elm_anchorview_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
351 ELM_CHECK_WIDTYPE(obj, widtype);
352 Widget_Data *wd = elm_widget_data_get(obj);
354 Elm_Anchorview_Item_Provider *ip;
356 EINA_SAFETY_ON_NULL_RETURN(func);
357 EINA_LIST_FOREACH(wd->item_providers, l, ip)
359 if ((ip->func == func) && (ip->data == data))
361 wd->item_providers = eina_list_remove_list(wd->item_providers, l);