1 #include <Elementary.h>
\r
2 #include "elm_priv.h"
\r
5 * @defgroup Autocompleteview Autocompleteview
\r
6 * @ingroup Elementary
\r
8 * This widget show's the completed strings in a dropdown list
\r
9 * based on the initial few characters entered by the user.
\r
13 typedef struct _Widget_Data Widget_Data;
\r
17 Evas_Object *editfield;
\r
19 Evas_Object *layout;
\r
22 Eina_List *data_list;
\r
23 Eina_Bool text_set : 1;
\r
24 elmautocompleteview_matchfunction func;
\r
29 static void _editfield_clicked_cb(void *data, Evas_Object *obj, void *event_info)
\r
31 evas_object_smart_callback_call(data, "clicked", NULL);
\r
34 static void _entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
\r
36 Widget_Data *wd = elm_widget_data_get(data);
\r
39 char *real=NULL,*res=NULL;
\r
41 Eina_Bool textfound=EINA_FALSE;
\r
43 if (elm_widget_disabled_get(data)) return;
\r
46 evas_object_hide(wd->hover);
\r
47 wd->text_set = EINA_FALSE;
\r
50 text = elm_entry_entry_get(obj);
\r
53 textlen = strlen(text);
\r
54 if(textlen <wd->threshold)
\r
56 evas_object_hide(wd->hover);
\r
59 evas_object_hide(wd->hover);
\r
62 textfound = wd->func(data,text,wd->list,wd->data);
\r
64 else if(wd->data_list)
\r
66 elm_list_clear(wd->list);
\r
67 EINA_LIST_FOREACH(wd->data_list, l, real)
\r
69 res = strcasestr(real,text);
\r
72 elm_list_item_append(wd->list, real, NULL, NULL,
\r
74 textfound=EINA_TRUE;
\r
82 elm_list_go(wd->list);
\r
83 evas_object_show(wd->hover);
\r
89 _del_pre_hook(Evas_Object *obj)
\r
91 Widget_Data *wd = elm_widget_data_get(obj);
\r
93 evas_object_del(wd->hover);
\r
98 _del_hook(Evas_Object *obj)
\r
100 Widget_Data *wd = elm_widget_data_get(obj);
\r
106 _sizing_eval(Evas_Object *obj)
\r
108 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
\r
110 evas_object_size_hint_min_set(obj, minw, minh);
\r
111 evas_object_size_hint_max_set(obj, maxw, maxh);
\r
116 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
\r
118 _sizing_eval(data);
\r
122 _hover_clicked(void *data, Evas_Object *obj, void *event_info)
\r
124 printf("\n\ncurrently nothin to be done\n");
\r
127 static void _list_click( void *data, Evas_Object *obj, void *event_info )
\r
129 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
\r
130 Widget_Data *wd = elm_widget_data_get(data);
\r
131 if((it==NULL)||(wd==NULL))
\r
133 const char *text = elm_list_item_label_get(it);
\r
134 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
\r
139 elm_entry_entry_set(wd->entry, text);
\r
140 elm_entry_cursor_end_set(wd->entry);
\r
141 wd->text_set = EINA_TRUE;
\r
147 _eina_cmp_str(const char *a, const char *b)
\r
149 return strcasecmp(a,b);
\r
154 * Add a new Autocompleteview object
\r
156 * @param parent The parent object
\r
157 * @return The new object or NULL if it cannot be created
\r
159 * @ingroup Autocompleteview
\r
162 elm_autocompleteview_add(Evas_Object *parent)
\r
168 wd = ELM_NEW(Widget_Data);
\r
169 e = evas_object_evas_get(parent);
\r
170 obj = elm_widget_add(e);
\r
171 elm_widget_type_set(obj, "autocompleteview");
\r
172 elm_widget_sub_object_add(parent, obj);
\r
173 elm_widget_data_set(obj, wd);
\r
174 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
\r
175 elm_widget_del_hook_set(obj, _del_hook);
\r
177 wd->editfield = elm_editfield_add(parent);
\r
178 elm_widget_resize_object_set(obj, wd->editfield);
\r
179 elm_editfield_entry_single_line_set(wd->editfield, EINA_TRUE);
\r
180 evas_object_size_hint_weight_set(wd->editfield, 0, EVAS_HINT_EXPAND);
\r
181 evas_object_size_hint_align_set(wd->editfield, 0, EVAS_HINT_FILL);
\r
182 evas_object_event_callback_add(wd->editfield,
\r
183 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
\r
184 _changed_size_hints, obj);
\r
186 wd->entry = elm_editfield_entry_get(wd->editfield);
\r
188 evas_object_smart_callback_add(wd->editfield, "clicked", _editfield_clicked_cb, obj);
\r
189 evas_object_smart_callback_add(wd->entry, "changed", _entry_changed_cb, obj);
\r
191 wd->hover = elm_hover_add(obj);
\r
192 elm_hover_parent_set(wd->hover, parent);
\r
193 elm_hover_target_set(wd->hover, wd->editfield);
\r
195 wd->layout = elm_layout_add(wd->hover);
\r
196 elm_layout_theme_set(wd->layout,"autocompleteview","base","default");
\r
197 wd->list = elm_list_add(wd->layout);
\r
198 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
\r
199 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
\r
200 elm_list_horizontal_mode_set(wd->list, ELM_LIST_COMPRESS);
\r
201 elm_object_style_set(wd->list,"autocompleteview");
\r
202 elm_list_go(wd->list);
\r
203 evas_object_smart_callback_add(wd->list, "selected", _list_click, obj);
\r
204 elm_layout_content_set( wd->layout, "elm.swallow.content", wd->list );
\r
205 elm_hover_content_set(wd->hover,
\r
206 elm_hover_best_content_location_get(wd->hover,
\r
207 ELM_HOVER_AXIS_VERTICAL),
\r
209 evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked, obj);
\r
217 * This Get's the entry object of Autocompleteview object.
\r
219 * @param obj The Autocompleteview object.
\r
220 * @return the entry object.
\r
222 * @ingroup Autocompleteview
\r
225 elm_autocompleteview_entry_get(Evas_Object *obj)
\r
227 Widget_Data *wd = elm_widget_data_get(obj);
\r
236 * This Get's the editfield object of the Autocompleteview object.
\r
238 * @param obj The Autocompleteview object.
\r
239 * @return The Editfield object.
\r
241 * @ingroup Autocompleteview
\r
244 elm_autocompleteview_editfield_get(Evas_Object *obj)
\r
246 Widget_Data *wd = elm_widget_data_get(obj);
\r
251 return wd->editfield;
\r
256 * This Specifies the minimum number of characters the user has to type in the editfield
\r
257 * before the drop down list is shown.When threshold is less than or equals 0, a threshold of 1 is applied by default.
\r
259 * @param obj The Autocompleteview object
\r
260 * @param threshold the number of characters to type before the drop down is shown
\r
262 * @ingroup Autocompleteview
\r
265 elm_autocompleteview_threshold_set(Evas_Object *obj, int threshold)
\r
267 Widget_Data *wd = elm_widget_data_get(obj);
\r
277 wd->threshold = threshold;
\r
283 * This Returns the number of characters the user must type before the drop down list is shown.
\r
285 * @param obj The Autocompleteview object.
\r
286 * @return The threshold value.
\r
288 * @ingroup Autocompleteview
\r
291 elm_autocompleteview_threshold_get(Evas_Object *obj)
\r
293 Widget_Data *wd = elm_widget_data_get(obj);
\r
297 return wd->threshold;
\r
303 * This Specifies the list of strings which has to be searched to get the list of completion strings.
\r
305 * @param obj The Autocompleteview object
\r
306 * @param data_list the list of static strings, which has to be searched to get the completion strings.
\r
308 * @ingroup Autocompleteview
\r
311 elm_autocompleteview_data_set(Evas_Object *obj, Eina_List *data_list)
\r
313 Widget_Data *wd = elm_widget_data_get(obj);
\r
318 wd->data_list = data_list;
\r
320 /*storing sorted list*/
\r
321 wd->data_list = eina_list_sort(wd->data_list, eina_list_count(wd->data_list), EINA_COMPARE_CB(_eina_cmp_str));
\r
326 * This Registers the callback function that would be called whenever text is entered in to the entry.
\r
328 * @param obj The Autocompleteview object
\r
329 * @param elmautocompleteview_matchfunction completion function which list's the completion strings.
\r
330 * @param data userdata that would be passed whenever the callback function is called.
\r
332 * @ingroup Autocompleteview
\r
335 elm_autocompleteview_match_func_set(Evas_Object *obj, elmautocompleteview_matchfunction func,void *data)
\r
337 Widget_Data *wd = elm_widget_data_get(obj);
\r
347 * This updates the text in to autocomplete view.
\r
349 * @param obj The Autocompleteview object
\r
350 * @param text the text to be updated in to the entry of autocompleteview.
\r
352 * @ingroup Autocompleteview
\r
355 elm_autocompleteview_text_update(Evas_Object *obj, char *text)
\r
357 Widget_Data *wd = elm_widget_data_get(obj);
\r
364 elm_entry_entry_set(wd->entry, text);
\r
365 elm_entry_cursor_end_set(wd->entry);
\r
366 wd->text_set = EINA_TRUE;
\r