1 #include <Elementary.h>
3 # include "elementary_config.h"
5 #ifndef ELM_LIB_QUICKLAUNCH
6 static Elm_Genlist_Item_Class itci;
7 char *gli_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
11 snprintf(buf, sizeof(buf), "%c%c",
12 'A' + ((j >> 4) & 0xf),
19 index_changed2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
21 // called on a change but delayed in case multiple changes happen in a
23 elm_genlist_item_top_bring_in(event_info);
27 index_changed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
29 // this is calld on every change, no matter how often
30 // elm_genlist_item_bring_in(event_info);
34 index_selected(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
36 // called on final select
37 elm_genlist_item_top_bring_in(event_info);
41 test_index(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
43 Evas_Object *win, *bg, *gl, *id;
47 win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
48 elm_win_title_set(win, "Index");
49 elm_win_autodel_set(win, EINA_TRUE);
52 elm_win_resize_object_add(win, bg);
53 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
56 gl = elm_genlist_add(win);
57 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
58 elm_win_resize_object_add(win, gl);
61 id = elm_index_add(win);
62 evas_object_size_hint_weight_set(id, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
63 elm_win_resize_object_add(win, id);
67 itci.item_style = "default";
68 itci.func.label_get = gli_label_get;
69 itci.func.content_get = NULL;
70 itci.func.state_get = NULL;
74 for (i = 0; i < 100; i++)
76 it = elm_genlist_item_append(gl, &itci,
77 (void *)(long)j/* item data */,
78 NULL/* parent */, ELM_GENLIST_ITEM_NONE,
79 NULL/* func */, NULL/* func data */);
84 snprintf(buf, sizeof(buf), "%c", 'A' + ((j >> 4) & 0xf));
85 elm_index_item_append(id, buf, it);
89 evas_object_smart_callback_add(id, "delay,changed", index_changed2, NULL);
90 evas_object_smart_callback_add(id, "changed", index_changed, NULL);
91 evas_object_smart_callback_add(id, "selected", index_selected, NULL);
92 elm_index_item_go(id, 0);
94 evas_object_resize(win, 320, 480);
95 evas_object_show(win);
100 typedef struct _Test_Index2_Elements
102 Evas_Object *entry, *lst, *id;
103 } Test_Index2_Elements;
106 test_index2_del(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
108 /* FIXME it won't be called if elm_test main window is closed */
113 test_index2_cmp(const void *data1, const void *data2)
115 const char *label1, *label2;
116 const Elm_List_Item *it1 = data1;
117 const Elm_List_Item *it2 = data2;
119 label1 = elm_list_item_label_get(it1);
120 label2 = elm_list_item_label_get(it2);
122 return strcasecmp(label1, label2);
126 test_index2_icmp(const void *data1, const void *data2)
128 const char *label1, *label2;
129 const Elm_Index_Item *it1 = data1;
130 const Elm_Index_Item *it2 = data2;
132 label1 = elm_index_item_letter_get(it1);
133 label2 = elm_index_item_letter_get(it2);
135 return strcasecmp(label1, label2);
139 test_index2_it_add(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
141 Test_Index2_Elements *gui = data;
146 label = elm_entry_entry_get(gui->entry);
147 snprintf(letter, sizeof(letter), "%c", label[0]);
148 it = elm_list_item_sorted_insert(gui->lst, label, NULL, NULL, NULL, NULL,
150 elm_index_item_sorted_insert(gui->id, letter, it, test_index2_icmp,
152 elm_list_go(gui->lst);
153 /* FIXME it's not showing the recently added item */
154 elm_list_item_show(it);
158 test_index2_it_del(void *data, Evas_Object *obj, void *event_info __UNUSED__)
160 Test_Index2_Elements *gui = data;
161 const char *label, *label_next;
162 Elm_List_Item *it, *it_next;
164 it = elm_list_selected_item_get(obj);
165 it_next = elm_list_item_next(it);
169 elm_index_item_del(gui->id, it);
170 elm_list_item_del(it);
174 label = elm_list_item_label_get(it);
175 label_next = elm_list_item_label_get(it_next);
177 if (label[0] == label_next[0])
180 iit = elm_index_item_find(gui->id, it);
181 elm_index_item_data_set(iit, it_next);
184 elm_index_item_del(gui->id, it);
186 elm_list_item_del(it);
190 test_index2_id_changed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
192 elm_list_item_show(event_info);
196 test_index2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
198 Evas_Object *win, *bg, *box, *bt;
199 Test_Index2_Elements *gui;
201 gui = malloc(sizeof(*gui));
203 win = elm_win_add(NULL, "sorted-index-list", ELM_WIN_BASIC);
204 elm_win_title_set(win, "Sorted Index and List");
205 evas_object_smart_callback_add(win, "delete,request", test_index2_del, gui);
206 elm_win_autodel_set(win, EINA_TRUE);
208 bg = elm_bg_add(win);
209 elm_win_resize_object_add(win, bg);
210 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
211 evas_object_show(bg);
213 box = elm_box_add(win);
214 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215 elm_win_resize_object_add(win, box);
216 evas_object_show(box);
218 gui->id = elm_index_add(win);
219 evas_object_size_hint_weight_set(gui->id, EVAS_HINT_EXPAND,
221 elm_win_resize_object_add(win, gui->id);
222 evas_object_smart_callback_add(gui->id, "delay,changed",
223 test_index2_id_changed, NULL);
224 evas_object_show(gui->id);
226 gui->entry = elm_entry_add(win);
227 elm_entry_scrollable_set(gui->entry, EINA_TRUE);
228 elm_entry_entry_set(gui->entry, "Label");
229 elm_entry_single_line_set(gui->entry, EINA_TRUE);
230 evas_object_size_hint_weight_set(gui->entry, EVAS_HINT_EXPAND, 0);
231 evas_object_size_hint_fill_set(gui->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
232 elm_box_pack_end(box, gui->entry);
233 evas_object_show(gui->entry);
235 bt = elm_button_add(win);
236 elm_object_text_set(bt, "Add");
237 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
238 evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
239 elm_box_pack_end(box, bt);
240 evas_object_smart_callback_add(bt, "clicked", test_index2_it_add, gui);
241 evas_object_show(bt);
243 gui->lst = elm_list_add(win);
244 elm_box_pack_end(box, gui->lst);
245 evas_object_size_hint_weight_set(gui->lst, EVAS_HINT_EXPAND,
247 evas_object_size_hint_fill_set(gui->lst, EVAS_HINT_FILL, EVAS_HINT_FILL);
248 evas_object_smart_callback_add(gui->lst, "selected", test_index2_it_del,
250 elm_list_go(gui->lst);
251 evas_object_show(gui->lst);
253 evas_object_resize(win, 320, 480);
254 evas_object_show(win);