1 #include <Elementary.h>
4 # include "elementary_config.h"
6 #ifndef ELM_LIB_QUICKLAUNCH
9 Evas_Object *id; /* Pointer to Index */
10 Elm_Object_Item *item; /* Item we use for search */
12 typedef struct _Idx_Data_Type Idx_Data_Type;
16 unsigned int state; /* What state we are testing */
19 typedef struct _api_data api_data;
25 INDEX_APPEND_RELATIVE,
30 INDEX_INDICATOR_DISABLED,
34 typedef enum _api_state api_state;
37 set_api_state(api_data *api)
39 Idx_Data_Type *d = &api->dt;
41 { /* Put all api-changes under switch */
43 elm_index_autohide_disabled_set(d->id, EINA_TRUE);
44 elm_index_item_level_set(d->id, (elm_index_item_level_get(d->id) ? 0 : 1));
47 case INDEX_ACTIVE_SET:
48 elm_index_autohide_disabled_set(d->id, EINA_FALSE);
51 case INDEX_APPEND_RELATIVE:
52 elm_index_item_insert_after(d->id,
53 elm_index_item_find(d->id, d->item),
55 elm_index_item_insert_before(d->id,
56 elm_index_item_find(d->id, d->item),
61 elm_index_item_prepend(d->id, "D", NULL, d->item);
65 elm_object_item_del(elm_index_item_find(d->id, d->item));
70 Elm_Object_Item *i = elm_index_item_find(d->id, d->item);
73 printf("Item Find - Found Item.\n");
74 elm_object_item_del(i);
79 case INDEX_HORIZONTAL:
80 elm_index_horizontal_set(d->id, EINA_TRUE);
83 case INDEX_INDICATOR_DISABLED:
84 elm_index_indicator_disabled_set(d->id, EINA_TRUE);
88 elm_index_item_clear(d->id);
100 _api_bt_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
101 { /* Will add here a SWITCH command containing code to modify test-object */
102 /* in accordance a->state value. */
106 printf("clicked event on API Button: api_state=<%d>\n", a->state);
109 sprintf(str, "Next API function (%u)", a->state);
110 elm_object_text_set(obj, str);
111 elm_object_disabled_set(obj, a->state == API_STATE_LAST);
114 static Elm_Genlist_Item_Class itci;
115 char *gli_text_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
119 snprintf(buf, sizeof(buf), "%c%c",
120 'A' + ((j >> 4) & 0xf),
127 _index_delay_changed_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
129 // called on a change but delayed in case multiple changes happen in a
131 elm_genlist_item_top_bring_in(elm_object_item_data_get(event_info));
135 _index_changed_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
137 // this is calld on every change, no matter how often
138 // elm_genlist_item_bring_in(event_info);
142 _index_selected_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
144 // called on final select
145 elm_genlist_item_top_bring_in(elm_object_item_data_get(event_info));
149 _cleanup_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
155 id_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
157 printf("Current Index : %s\n", elm_index_item_letter_get((const Elm_Object_Item *)event_info));
161 test_index(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
163 Evas_Object *win, *bg, *bxx, *gl, *id, *bt;
164 Elm_Object_Item *glit;
166 api_data *api = calloc(1, sizeof(api_data));
168 win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
169 elm_win_title_set(win, "Index");
170 elm_win_autodel_set(win, EINA_TRUE);
171 evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
173 bg = elm_bg_add(win);
174 elm_win_resize_object_add(win, bg);
175 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
176 evas_object_show(bg);
178 bxx = elm_box_add(win);
179 elm_win_resize_object_add(win, bxx);
180 evas_object_size_hint_weight_set(bxx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
181 evas_object_show(bxx);
183 gl = elm_genlist_add(win);
184 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
185 evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
186 evas_object_show(gl);
188 api->dt.id = id = elm_index_add(win);
189 evas_object_size_hint_weight_set(id, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
190 evas_object_size_hint_align_set(id, EVAS_HINT_FILL, EVAS_HINT_FILL);
191 elm_win_resize_object_add(win, id);
193 bt = elm_button_add(win);
194 elm_object_text_set(bt, "Next API function");
195 evas_object_smart_callback_add(bt, "clicked", _api_bt_clicked, (void *) api);
196 elm_box_pack_end(bxx, bt);
197 elm_object_disabled_set(bt, api->state == API_STATE_LAST);
198 evas_object_show(bt);
200 elm_box_pack_end(bxx, gl);
202 evas_object_show(id);
204 itci.item_style = "default";
205 itci.func.text_get = gli_text_get;
206 itci.func.content_get = NULL;
207 itci.func.state_get = NULL;
208 itci.func.del = NULL;
211 for (i = 0; i < 100; i++)
213 glit = elm_genlist_item_append(gl, &itci,
214 (void *)(long)j/* item data */,
216 ELM_GENLIST_ITEM_NONE,
217 NULL/* func */, NULL/* func data */);
222 snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 4) & 0xf));
223 elm_index_item_append(id, buf, id_cb, glit);
224 if (*buf == 'G') /* Just init dt->item later used in API test */
229 evas_object_smart_callback_add(id, "delay,changed", _index_delay_changed_cb, NULL);
230 evas_object_smart_callback_add(id, "changed", _index_changed_cb, NULL);
231 evas_object_smart_callback_add(id, "selected", _index_selected_cb, NULL);
232 elm_index_level_go(id, 0);
233 evas_object_resize(win, 320, 480);
234 evas_object_show(win);
239 typedef struct _Test_Index2_Elements
241 Evas_Object *entry, *lst, *id;
242 } Test_Index2_Elements;
245 test_index2_del(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
247 /* FIXME it won't be called if elm_test main window is closed */
252 test_index2_cmp(const void *data1, const void *data2)
254 const char *label1, *label2;
255 const Elm_Object_Item *li_it1 = data1;
256 const Elm_Object_Item *li_it2 = data2;
258 label1 = elm_object_item_text_get(li_it1);
259 label2 = elm_object_item_text_get(li_it2);
261 return strcasecmp(label1, label2);
265 test_index2_icmp(const void *data1, const void *data2)
267 const char *label1, *label2;
268 const Elm_Object_Item *index_it1 = data1;
269 const Elm_Object_Item *index_it2 = data2;
271 label1 = elm_index_item_letter_get(index_it1);
272 label2 = elm_index_item_letter_get(index_it2);
274 return strcasecmp(label1, label2);
278 test_index2_it_add(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
280 Test_Index2_Elements *gui = data;
281 Elm_Object_Item *list_it;
285 label = elm_object_text_get(gui->entry);
286 snprintf(letter, sizeof(letter), "%c", label[0]);
287 list_it = elm_list_item_sorted_insert(gui->lst, label, NULL, NULL, NULL,
288 NULL, test_index2_cmp);
289 elm_index_item_sorted_insert(gui->id, letter, NULL, list_it, test_index2_icmp,
291 elm_list_go(gui->lst);
292 /* FIXME it's not showing the recently added item */
293 elm_list_item_show(list_it);
297 test_index2_it_del(void *data, Evas_Object *obj, void *event_info __UNUSED__)
299 Test_Index2_Elements *gui = data;
300 const char *label, *label_next;
301 Elm_Object_Item *list_it, *list_it_next;
302 Elm_Object_Item *iit;
304 list_it = elm_list_selected_item_get(obj);
305 list_it_next = elm_list_item_next(list_it);
309 iit = elm_index_item_find(gui->id, list_it);
310 if (iit) elm_object_item_del(iit);
311 elm_object_item_del(list_it);
315 label = elm_object_item_text_get(list_it);
316 label_next = elm_object_item_text_get(list_it_next);
318 iit = elm_index_item_find(gui->id, list_it);
319 if (label[0] == label_next[0])
320 elm_object_item_data_set(iit, list_it_next);
322 elm_object_item_del(iit);
324 elm_object_item_del(list_it);
328 test_index2_id_changed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
330 elm_list_item_show(elm_object_item_data_get(event_info));
334 test_index2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
336 Evas_Object *win, *bg, *box, *bt;
337 Test_Index2_Elements *gui;
339 gui = malloc(sizeof(*gui));
341 win = elm_win_add(NULL, "sorted-index-list", ELM_WIN_BASIC);
342 elm_win_title_set(win, "Sorted Index and List");
343 evas_object_smart_callback_add(win, "delete,request", test_index2_del, gui);
344 elm_win_autodel_set(win, EINA_TRUE);
346 bg = elm_bg_add(win);
347 elm_win_resize_object_add(win, bg);
348 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
349 evas_object_show(bg);
351 box = elm_box_add(win);
352 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
353 elm_win_resize_object_add(win, box);
354 evas_object_show(box);
356 gui->id = elm_index_add(win);
357 evas_object_size_hint_weight_set(gui->id, EVAS_HINT_EXPAND,
359 elm_win_resize_object_add(win, gui->id);
360 evas_object_smart_callback_add(gui->id, "delay,changed",
361 test_index2_id_changed, NULL);
362 evas_object_show(gui->id);
364 gui->entry = elm_entry_add(win);
365 elm_entry_scrollable_set(gui->entry, EINA_TRUE);
366 elm_object_text_set(gui->entry, "Label");
367 elm_entry_single_line_set(gui->entry, EINA_TRUE);
368 evas_object_size_hint_weight_set(gui->entry, EVAS_HINT_EXPAND, 0);
369 evas_object_size_hint_fill_set(gui->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
370 elm_box_pack_end(box, gui->entry);
371 evas_object_show(gui->entry);
373 bt = elm_button_add(win);
374 elm_object_text_set(bt, "Add");
375 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
376 evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
377 elm_box_pack_end(box, bt);
378 evas_object_smart_callback_add(bt, "clicked", test_index2_it_add, gui);
379 evas_object_show(bt);
381 gui->lst = elm_list_add(win);
382 elm_box_pack_end(box, gui->lst);
383 evas_object_size_hint_weight_set(gui->lst, EVAS_HINT_EXPAND,
385 evas_object_size_hint_fill_set(gui->lst, EVAS_HINT_FILL, EVAS_HINT_FILL);
386 evas_object_smart_callback_add(gui->lst, "selected", test_index2_it_del,
388 elm_list_go(gui->lst);
389 evas_object_show(gui->lst);
391 evas_object_resize(win, 320, 480);
392 evas_object_show(win);