1 #include <Elementary.h>
5 * @defgroup Anchorview Anchorview
7 * This is just like the Anchorblock object, but provides a scroller to hold
8 * the text automatically.
10 * Signals that you can add callbacks for are:
12 * anchor,clicked - achor called was clicked. event_info is anchor info -
13 * Elm_Entry_Anchorview_Info
15 typedef struct _Widget_Data Widget_Data;
16 typedef struct _Elm_Anchorview_Item_Provider Elm_Anchorview_Item_Provider;
20 Evas_Object *scroller, *entry;
21 Evas_Object *hover_parent;
22 Evas_Object *pop, *hover;
23 Eina_List *item_providers;
24 const char *hover_style;
27 struct _Elm_Anchorview_Item_Provider
29 Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item);
33 static const char *widtype = NULL;
35 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
36 static const Evas_Smart_Cb_Description _signals[] = {
37 {SIG_ANCHOR_CLICKED, ""}, /* TODO: declare the type properly, as data is
43 static void _del_pre_hook(Evas_Object *obj);
44 static void _del_hook(Evas_Object *obj);
45 static void _sizing_eval(Evas_Object *obj);
46 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
50 _del_pre_hook(Evas_Object *obj)
52 elm_anchorview_hover_end(obj);
53 elm_anchorview_hover_parent_set(obj, NULL);
57 _del_hook(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
60 Elm_Anchorview_Item_Provider *ip;
62 if (wd->hover_style) eina_stringshare_del(wd->hover_style);
63 EINA_LIST_FREE(wd->item_providers, ip)
71 _sizing_eval(Evas_Object *obj)
73 Widget_Data *wd = elm_widget_data_get(obj);
74 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
76 evas_object_size_hint_min_set(obj, minw, minh);
77 evas_object_size_hint_max_set(obj, maxw, maxh);
81 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
87 _hover_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
89 elm_anchorview_hover_end(data);
93 _anchor_clicked(void *data, Evas_Object *obj, void *event_info)
95 Widget_Data *wd = elm_widget_data_get(data);
96 Elm_Entry_Anchor_Info *info = event_info;
97 Evas_Object *hover_parent;
98 Elm_Entry_Anchorview_Info ei;
99 Evas_Coord x, w, y, h, px, py;
101 wd->pop = elm_icon_add(obj);
102 evas_object_move(wd->pop, info->x, info->y);
103 evas_object_resize(wd->pop, info->w, info->h);
104 wd->hover = elm_hover_add(obj);
105 if (wd->hover_style) elm_object_style_set(wd->hover, wd->hover_style);
106 hover_parent = wd->hover_parent;
107 if (!hover_parent) hover_parent = obj;
108 elm_hover_parent_set(wd->hover, hover_parent);
109 elm_hover_target_set(wd->hover, wd->pop);
110 ei.name = info->name;
111 ei.button = info->button;
112 ei.hover = wd->hover;
113 ei.anchor.x = info->x;
114 ei.anchor.y = info->y;
115 ei.anchor.w = info->w;
116 ei.anchor.h = info->h;
117 evas_object_geometry_get(hover_parent, &x, &y, &w, &h);
118 ei.hover_parent.x = x;
119 ei.hover_parent.y = y;
120 ei.hover_parent.w = w;
121 ei.hover_parent.h = h;
122 px = info->x + (info->w / 2);
123 py = info->y + (info->h / 2);
125 if (px < (x + (w / 3))) ei.hover_left = 0;
127 if (px > (x + ((w * 2) / 3))) ei.hover_right = 0;
129 if (py < (y + (h / 3))) ei.hover_top = 0;
131 if (py > (y + ((h * 2) / 3))) ei.hover_bottom = 0;
132 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
133 evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked, data);
134 evas_object_show(wd->hover);
138 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
140 Widget_Data *wd = elm_widget_data_get(data);
142 wd->hover_parent = NULL;
146 _item_provider(void *data, Evas_Object *entry __UNUSED__, const char *item)
148 Widget_Data *wd = elm_widget_data_get(data);
150 Elm_Anchorview_Item_Provider *ip;
152 EINA_LIST_FOREACH(wd->item_providers, l, ip)
156 o = ip->func(ip->data, data, item);
163 * Add a new Anchorview object
165 * @param parent The parent object
166 * @return The new object or NULL if it cannot be created
168 * @ingroup Anchorview
171 elm_anchorview_add(Evas_Object *parent)
177 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
179 wd = ELM_NEW(Widget_Data);
180 e = evas_object_evas_get(parent);
182 obj = elm_widget_add(e);
183 ELM_SET_WIDTYPE(widtype, "anchorview");
184 elm_widget_type_set(obj, "anchorview");
185 elm_widget_sub_object_add(parent, obj);
186 elm_widget_data_set(obj, wd);
187 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
188 elm_widget_del_hook_set(obj, _del_hook);
189 elm_widget_can_focus_set(obj, EINA_TRUE);
191 wd->scroller = elm_scroller_add(parent);
192 elm_widget_resize_object_set(obj, wd->scroller);
193 wd->entry = elm_entry_add(parent);
194 elm_entry_item_provider_prepend(wd->entry, _item_provider, obj);
195 elm_entry_editable_set(wd->entry, 0);
196 evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197 evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
198 elm_scroller_content_set(wd->scroller, wd->entry);
199 evas_object_show(wd->entry);
201 evas_object_event_callback_add(wd->entry, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
202 _changed_size_hints, obj);
204 elm_entry_entry_set(wd->entry, "");
206 evas_object_smart_callback_add(wd->entry, "anchor,clicked",
207 _anchor_clicked, obj);
211 // TODO: convert Elementary to subclassing of Evas_Smart_Class
212 // TODO: and save some bytes, making descriptions per-class and not instance!
213 evas_object_smart_callbacks_descriptions_set(obj, _signals);
218 * Set the text markup of the anchorview
220 * This sets the text of the anchorview to be the text given as @p text. This
221 * text is in markup format with \<a href=XXX\> beginning an achor with the
222 * string link of 'XXX', and \</\> or \</a\> ending the link. Other markup can
223 * be used dependign on the style support.
225 * @param obj The anchorview object
226 * @param text The text to set, or NULL to clear
228 * @ingroup Anchorview
231 elm_anchorview_text_set(Evas_Object *obj, const char *text)
233 ELM_CHECK_WIDTYPE(obj, widtype);
234 Widget_Data *wd = elm_widget_data_get(obj);
236 elm_entry_entry_set(wd->entry, text);
237 if (wd->hover) evas_object_del(wd->hover);
238 if (wd->pop) evas_object_del(wd->pop);
245 * Get the markup text set for the anchorview
247 * This retrieves back the string set by @c elm_anchorview_text_set().
249 * @param obj The anchorview object
250 * @return text The markup text set or @c NULL, either if it was not set
251 * or an error occurred
253 * @ingroup Anchorview
256 elm_anchorview_text_get(const Evas_Object *obj)
258 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
259 Widget_Data *wd = elm_widget_data_get(obj);
260 if (!wd) return NULL;
261 return elm_entry_entry_get(wd->entry);
265 * Set the parent of the hover popup
267 * This sets the parent of the hover that anchorview will create. See hover
268 * objects for more information on this.
270 * @param obj The anchorview object
271 * @param parent The parent the hover should use
273 * @ingroup Anchorview
276 elm_anchorview_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
278 ELM_CHECK_WIDTYPE(obj, widtype);
279 Widget_Data *wd = elm_widget_data_get(obj);
281 if (wd->hover_parent)
282 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL, _parent_del, obj);
283 wd->hover_parent = parent;
284 if (wd->hover_parent)
285 evas_object_event_callback_add(wd->hover_parent, EVAS_CALLBACK_DEL, _parent_del, obj);
289 * Get the parent of the hover popup
291 * This gets the parent of the hover that anchorview will created. See hover
292 * objects for more information on this.
294 * @param obj The anchorview object
295 * @return The parent used by hover
297 * @ingroup Anchorview
300 elm_anchorview_hover_parent_get(const Evas_Object *obj)
302 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
303 Widget_Data *wd = elm_widget_data_get(obj);
304 if (!wd) return NULL;
305 return wd->hover_parent;
309 * Set the style that the hover should use
311 * This sets the style for the hover that anchorview will create. See hover
312 * objects for more information
314 * @param obj The anchorview object
315 * @param style The style to use
317 * @ingroup Anchorview
320 elm_anchorview_hover_style_set(Evas_Object *obj, const char *style)
322 ELM_CHECK_WIDTYPE(obj, widtype);
323 Widget_Data *wd = elm_widget_data_get(obj);
325 eina_stringshare_replace(&wd->hover_style, style);
329 * Get the style that the hover should use
331 * This gets the style for the hover that anchorview will create. See hover
332 * objects for more information
334 * @param obj The anchorview object
335 * @return The style defined
337 * @ingroup Anchorview
340 elm_anchorview_hover_style_get(const Evas_Object *obj)
342 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
343 Widget_Data *wd = elm_widget_data_get(obj);
344 if (!wd) return NULL;
345 return wd->hover_style;
349 * Stop the hover popup in the anchorview
351 * This will stop the hover popup in the anchorview if it is currently active.
353 * @param obj The anchorview object
355 * @ingroup Anchorview
358 elm_anchorview_hover_end(Evas_Object *obj)
360 ELM_CHECK_WIDTYPE(obj, widtype);
361 Widget_Data *wd = elm_widget_data_get(obj);
363 if (wd->hover) evas_object_del(wd->hover);
364 if (wd->pop) evas_object_del(wd->pop);
372 * This will enable or disable the scroller bounce mode for the anchorview. See
373 * elm_scroller_bounce_set() for details
375 * @param obj The anchorview anchorview
376 * @param h_bounce Allow bounce horizontally
377 * @param v_bounce Allow bounce vertically
379 * @ingroup Anchorview
382 elm_anchorview_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
384 ELM_CHECK_WIDTYPE(obj, widtype);
385 Widget_Data *wd = elm_widget_data_get(obj);
387 elm_scroller_bounce_set(wd->scroller, h_bounce, v_bounce);
391 * Get the bounce mode
393 * @param obj The Anchorview object
394 * @param h_bounce Allow bounce horizontally
395 * @param v_bounce Allow bounce vertically
397 * @ingroup Anchorview
400 elm_anchorview_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
402 ELM_CHECK_WIDTYPE(obj, widtype);
403 Widget_Data *wd = elm_widget_data_get(obj);
405 elm_scroller_bounce_get(wd->scroller, h_bounce, v_bounce);
409 * This appends a custom item provider to the list for that anchorview
411 * This appends the given callback. The list is walked from beginning to end
412 * with each function called given the item href string in the text. If the
413 * function returns an object handle other than NULL (it should create an
414 * and object to do this), then this object is used to replace that item. If
415 * not the next provider is called until one provides an item object, or the
416 * default provider in anchorview does.
418 * @param obj The anchorview object
419 * @param func The function called to provide the item object
420 * @param data The data passed to @p func
422 * @ingroup Anchorview
425 elm_anchorview_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
427 ELM_CHECK_WIDTYPE(obj, widtype);
428 Widget_Data *wd = elm_widget_data_get(obj);
430 EINA_SAFETY_ON_NULL_RETURN(func);
431 Elm_Anchorview_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorview_Item_Provider));
435 wd->item_providers = eina_list_append(wd->item_providers, ip);
439 * This prepends a custom item provider to the list for that anchorview
441 * This prepends the given callback. See elm_anchorview_item_provider_append() for
444 * @param obj The anchorview object
445 * @param func The function called to provide the item object
446 * @param data The data passed to @p func
448 * @ingroup Anchorview
451 elm_anchorview_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
453 ELM_CHECK_WIDTYPE(obj, widtype);
454 Widget_Data *wd = elm_widget_data_get(obj);
456 EINA_SAFETY_ON_NULL_RETURN(func);
457 Elm_Anchorview_Item_Provider *ip = calloc(1, sizeof(Elm_Anchorview_Item_Provider));
461 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
465 * This removes a custom item provider to the list for that anchorview
467 * This removes the given callback. See elm_anchorview_item_provider_append() for
470 * @param obj The anchorview object
471 * @param func The function called to provide the item object
472 * @param data The data passed to @p func
474 * @ingroup Anchorview
477 elm_anchorview_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *anchorview, const char *item), void *data)
479 ELM_CHECK_WIDTYPE(obj, widtype);
480 Widget_Data *wd = elm_widget_data_get(obj);
482 Elm_Anchorview_Item_Provider *ip;
484 EINA_SAFETY_ON_NULL_RETURN(func);
485 EINA_LIST_FOREACH(wd->item_providers, l, ip)
487 if ((ip->func == func) && (ip->data == data))
489 wd->item_providers = eina_list_remove_list(wd->item_providers, l);