1 #include <Elementary.h>
\r
2 #include "elm_priv.h"
\r
6 * @defgroup Autocompleteview Autocompleteview
\r
7 * @ingroup Elementary
\r
9 * This widget show's the completed strings in a dropdown list
\r
10 * based on the initial few characters entered by the user.
\r
14 typedef struct _Widget_Data Widget_Data;
\r
18 Evas_Object *editfield;
\r
20 Evas_Object *layout;
\r
23 Eina_List *data_list;
\r
24 Eina_Bool text_set : 1;
\r
25 elmautocompleteview_matchfunction func;
\r
30 static void _editfield_clicked_cb(void *data, Evas_Object *obj, void *event_info)
\r
32 evas_object_smart_callback_call(data, "clicked", NULL);
\r
35 static void _entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
\r
37 Widget_Data *wd = elm_widget_data_get(data);
\r
38 const char *text = NULL;
\r
40 char *real = NULL,*res = NULL;
\r
42 Eina_Bool textfound = EINA_FALSE;
\r
44 if (elm_widget_disabled_get(data)) return;
\r
47 evas_object_hide(wd->hover);
\r
48 wd->text_set = EINA_FALSE;
\r
51 text = elm_entry_entry_get(obj);
\r
54 textlen = strlen(text);
\r
55 if(textlen <wd->threshold)
\r
57 evas_object_hide(wd->hover);
\r
60 evas_object_hide(wd->hover);
\r
63 textfound = wd->func(data,text,wd->list,wd->data);
\r
65 else if(wd->data_list)
\r
67 elm_list_clear(wd->list);
\r
68 EINA_LIST_FOREACH(wd->data_list, l, real)
\r
70 res = strcasestr(real,text);
\r
73 elm_list_item_append(wd->list, real, NULL, NULL,
\r
75 textfound=EINA_TRUE;
\r
83 elm_list_go(wd->list);
\r
84 evas_object_show(wd->hover);
\r
90 _del_pre_hook(Evas_Object *obj)
\r
92 Widget_Data *wd = elm_widget_data_get(obj);
\r
94 evas_object_del(wd->hover);
\r
99 _del_hook(Evas_Object *obj)
\r
101 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
115 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
\r
117 _sizing_eval(data);
\r
121 _hover_clicked(void *data, Evas_Object *obj, void *event_info)
\r
123 printf("\n\ncurrently nothin to be done\n");
\r
126 static void _list_click( void *data, Evas_Object *obj, void *event_info )
\r
128 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
\r
129 Widget_Data *wd = elm_widget_data_get(data);
\r
130 if((it==NULL)||(wd==NULL))
\r
132 const char *text = elm_list_item_label_get(it);
\r
133 evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
\r
138 elm_entry_entry_set(wd->entry, text);
\r
139 elm_entry_cursor_end_set(wd->entry);
\r
140 wd->text_set = EINA_TRUE;
\r
146 _eina_cmp_str(const char *a, const char *b)
\r
148 return strcasecmp(a,b);
\r
153 * Add a new Autocompleteview object
\r
155 * @param parent The parent object
\r
156 * @return The new object or NULL if it cannot be created
\r
158 * @ingroup Autocompleteview
\r
161 elm_autocompleteview_add(Evas_Object *parent)
\r
167 wd = ELM_NEW(Widget_Data);
\r
168 e = evas_object_evas_get(parent);
\r
169 obj = elm_widget_add(e);
\r
170 elm_widget_type_set(obj, "autocompleteview");
\r
171 elm_widget_sub_object_add(parent, obj);
\r
172 elm_widget_data_set(obj, wd);
\r
173 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
\r
174 elm_widget_del_hook_set(obj, _del_hook);
\r
176 wd->editfield = elm_editfield_add(parent);
\r
177 elm_widget_resize_object_set(obj, wd->editfield);
\r
178 elm_editfield_entry_single_line_set(wd->editfield, EINA_TRUE);
\r
179 evas_object_size_hint_weight_set(wd->editfield, 0, EVAS_HINT_EXPAND);
\r
180 evas_object_size_hint_align_set(wd->editfield, 0, EVAS_HINT_FILL);
\r
181 evas_object_event_callback_add(wd->editfield,
\r
182 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
\r
183 _changed_size_hints, obj);
\r
185 wd->entry = elm_editfield_entry_get(wd->editfield);
\r
187 evas_object_smart_callback_add(wd->editfield, "clicked", _editfield_clicked_cb, obj);
\r
188 evas_object_smart_callback_add(wd->entry, "changed", _entry_changed_cb, obj);
\r
190 wd->hover = elm_hover_add(obj);
\r
191 elm_hover_parent_set(wd->hover, parent);
\r
192 elm_hover_target_set(wd->hover, wd->editfield);
\r
194 wd->layout = elm_layout_add(wd->hover);
\r
195 elm_layout_theme_set(wd->layout,"autocompleteview","base","default");
\r
196 wd->list = elm_list_add(wd->layout);
\r
197 evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
\r
198 evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
\r
199 elm_list_horizontal_mode_set(wd->list, ELM_LIST_COMPRESS);
\r
200 elm_object_style_set(wd->list,"autocompleteview");
\r
201 elm_list_go(wd->list);
\r
202 evas_object_smart_callback_add(wd->list, "selected", _list_click, obj);
\r
203 elm_layout_content_set( wd->layout, "elm.swallow.content", wd->list );
\r
204 elm_hover_content_set(wd->hover,
\r
205 elm_hover_best_content_location_get(wd->hover,
\r
206 ELM_HOVER_AXIS_VERTICAL),
\r
208 evas_object_smart_callback_add(wd->hover, "clicked", _hover_clicked, obj);
\r
216 * This Get's the entry object of Autocompleteview object.
\r
218 * @param obj The Autocompleteview object.
\r
219 * @return the entry object.
\r
221 * @ingroup Autocompleteview
\r
224 elm_autocompleteview_entry_get(Evas_Object *obj)
\r
226 Widget_Data *wd = elm_widget_data_get(obj);
\r
227 if(!wd) return NULL;
\r
233 * This Get's the editfield object of the Autocompleteview object.
\r
235 * @param obj The Autocompleteview object.
\r
236 * @return The Editfield object.
\r
238 * @ingroup Autocompleteview
\r
241 elm_autocompleteview_editfield_get(Evas_Object *obj)
\r
243 Widget_Data *wd = elm_widget_data_get(obj);
\r
244 if(!wd) return NULL;
\r
246 return wd->editfield;
\r
251 * This Specifies the minimum number of characters the user has to type in the editfield
\r
252 * before the drop down list is shown.When threshold is less than or equals 0, a threshold of 1 is applied by default.
\r
254 * @param obj The Autocompleteview object
\r
255 * @param threshold the number of characters to type before the drop down is shown
\r
257 * @ingroup Autocompleteview
\r
260 elm_autocompleteview_threshold_set(Evas_Object *obj, int threshold)
\r
262 Widget_Data *wd = elm_widget_data_get(obj);
\r
271 wd->threshold = threshold;
\r
277 * This Returns the number of characters the user must type before the drop down list is shown.
\r
279 * @param obj The Autocompleteview object.
\r
280 * @return The threshold value.
\r
282 * @ingroup Autocompleteview
\r
285 elm_autocompleteview_threshold_get(Evas_Object *obj)
\r
287 Widget_Data *wd = elm_widget_data_get(obj);
\r
290 return wd->threshold;
\r
295 * This Specifies the list of strings which has to be searched to get the list of completion strings.
\r
297 * @param obj The Autocompleteview object
\r
298 * @param data_list the list of static strings, which has to be searched to get the completion strings.
\r
300 * @ingroup Autocompleteview
\r
303 elm_autocompleteview_data_set(Evas_Object *obj, Eina_List *data_list)
\r
305 Widget_Data *wd = elm_widget_data_get(obj);
\r
308 wd->data_list = data_list;
\r
310 /*storing sorted list*/
\r
311 wd->data_list = eina_list_sort(wd->data_list, eina_list_count(wd->data_list), EINA_COMPARE_CB(_eina_cmp_str));
\r
316 * This Registers the callback function that would be called whenever text is entered in to the entry.
\r
318 * @param obj The Autocompleteview object
\r
319 * @param elmautocompleteview_matchfunction completion function which list's the completion strings.
\r
320 * @param data userdata that would be passed whenever the callback function is called.
\r
322 * @ingroup Autocompleteview
\r
325 elm_autocompleteview_match_func_set(Evas_Object *obj, elmautocompleteview_matchfunction func,void *data)
\r
327 Widget_Data *wd = elm_widget_data_get(obj);
\r
335 * This updates the text in to autocomplete view.
\r
337 * @param obj The Autocompleteview object
\r
338 * @param text the text to be updated in to the entry of autocompleteview.
\r
340 * @ingroup Autocompleteview
\r
343 elm_autocompleteview_text_update(Evas_Object *obj, char *text)
\r
345 Widget_Data *wd = elm_widget_data_get(obj);
\r
350 elm_entry_entry_set(wd->entry, text);
\r
351 elm_entry_cursor_end_set(wd->entry);
\r
352 wd->text_set = EINA_TRUE;
\r