2 * Elementary's <b>diskselector widget</b> example, illustrating its
3 * covering most of item functions.
5 * See stdout/stderr for output. Compile with:
8 * gcc -g `pkg-config --cflags --libs elementary` diskselector_example_02.c -o diskselector_example_02
12 #include <Elementary.h>
14 # include "elementary_config.h"
19 static int counter = 3;
22 _on_done(void *data __UNUSED__,
23 Evas_Object *obj __UNUSED__,
24 void *event_info __UNUSED__)
30 _add_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
32 Elm_Object_Item *ds_it;
33 Evas_Object *ds = data;
36 snprintf(label, sizeof(label), "Item %i", counter++);
37 ds_it = elm_diskselector_item_append(ds, label, NULL, NULL, NULL);
38 if (!ds_it) printf("Error adding item\n");
42 _add_ic_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
44 Elm_Object_Item *ds_it;
45 Evas_Object *ic, *ds = data;
48 snprintf(label, sizeof(label), "Item %i", counter++);
49 ic = elm_icon_add(ds);
50 elm_icon_standard_set(ic, "home");
52 ds_it = elm_diskselector_item_append(ds, label, ic, NULL, NULL);
53 if (!ds_it) printf("Error adding item with icon\n");
57 _sel_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
59 Elm_Object_Item *ds_it = event_info;
60 printf("Selected label: %s\n", elm_object_item_text_get(ds_it));
64 _add_func_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
66 Elm_Object_Item *ds_it;
67 Evas_Object *ds = data;
70 snprintf(label, sizeof(label), "Item %i", counter++);
71 ds_it = elm_diskselector_item_append(ds, label, NULL, _sel_cb, NULL);
72 if (!ds_it) printf("Error adding item\n");
76 _sel_data_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
79 Elm_Object_Item *ds_it = event_info;
80 printf("Selected label: %s with data: %s\n",
81 elm_object_item_text_get(ds_it), content);
85 _free_data(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
91 _add_data_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
93 Elm_Object_Item *ds_it;
94 Evas_Object *ds = data;
96 char *content = malloc(sizeof(char) * 32);
98 snprintf(content, 32, "Item content %i", counter);
99 snprintf(label, sizeof(label), "Item %i", counter++);
100 ds_it = elm_diskselector_item_append(ds, label, NULL, _sel_data_cb, content);
102 printf("Error adding item\n");
105 elm_object_item_del_cb_set(ds_it, _free_data);
109 _del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
111 Elm_Object_Item *selected_ds_it;
112 Evas_Object *ds = data;
114 selected_ds_it = elm_diskselector_selected_item_get(ds);
115 elm_object_item_del(selected_ds_it);
119 _unselect_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
121 Elm_Object_Item *selected_ds_it;
122 Evas_Object *ds = data;
124 selected_ds_it = elm_diskselector_selected_item_get(ds);
125 elm_diskselector_item_selected_set(selected_ds_it, EINA_FALSE);
129 _print_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
131 const Eina_List *l, *items;
132 Elm_Object_Item *ds_it;
133 Evas_Object *ds = data;
135 items = elm_diskselector_items_get(ds);
136 EINA_LIST_FOREACH(items, l, ds_it)
137 printf("%s\n", elm_object_item_text_get(ds_it));
141 _clear_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
143 Evas_Object *ds = data;
144 elm_diskselector_clear(ds);
148 _select_first_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
150 Elm_Object_Item *first_ds_it;
151 Evas_Object *ds = data;
153 first_ds_it = elm_diskselector_first_item_get(ds);
155 elm_diskselector_item_selected_set(first_ds_it, EINA_TRUE);
159 _select_last_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
161 Elm_Object_Item *last_ds_it;
162 Evas_Object *ds = data;
164 last_ds_it = elm_diskselector_last_item_get(ds);
166 elm_diskselector_item_selected_set(last_ds_it, EINA_TRUE);
170 _select_next_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
172 Elm_Object_Item *selected_ds_it, *next_ds_it;
173 Evas_Object *ds = data;
175 selected_ds_it = elm_diskselector_selected_item_get(ds);
176 if (!selected_ds_it) return;
178 next_ds_it = elm_diskselector_item_next_get(selected_ds_it);
180 elm_diskselector_item_selected_set(next_ds_it, EINA_TRUE);
184 _select_prev_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
186 Elm_Object_Item *selected_ds_it, *prev_ds_it;
187 Evas_Object *ds = data;
189 selected_ds_it = elm_diskselector_selected_item_get(ds);
190 if (!selected_ds_it) return;
192 prev_ds_it = elm_diskselector_item_prev_get(selected_ds_it);
194 elm_diskselector_item_selected_set(prev_ds_it, EINA_TRUE);
198 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
200 Evas_Object *win, *bg, *bx, *hbx, *ds, *bt;
202 win = elm_win_add(NULL, "diskselector", ELM_WIN_BASIC);
203 elm_win_title_set(win, "Diskselector Items Example");
204 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
206 bg = elm_bg_add(win);
207 elm_win_resize_object_add(win, bg);
208 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
209 evas_object_show(bg);
211 bx = elm_box_add(win);
212 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213 elm_win_resize_object_add(win, bx);
214 evas_object_show(bx);
216 ds = elm_diskselector_add(win);
217 evas_object_size_hint_weight_set(ds, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
218 evas_object_size_hint_align_set(ds, EVAS_HINT_FILL, EVAS_HINT_FILL);
219 elm_box_pack_end(bx, ds);
220 evas_object_show(ds);
222 elm_diskselector_item_append(ds, "Item 0", NULL, NULL, NULL);
223 elm_diskselector_item_append(ds, "Item 1", NULL, NULL, NULL);
224 elm_diskselector_item_append(ds, "Item 2", NULL, NULL, NULL);
226 hbx = elm_box_add(win);
227 elm_box_horizontal_set(hbx, EINA_TRUE);
228 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
229 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
230 elm_box_pack_end(bx, hbx);
231 evas_object_show(hbx);
233 bt = elm_button_add(win);
234 elm_object_text_set(bt, "Append item");
235 evas_object_smart_callback_add(bt, "clicked", _add_cb, ds);
236 elm_box_pack_end(hbx, bt);
237 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
238 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
239 evas_object_show(bt);
241 bt = elm_button_add(win);
242 elm_object_text_set(bt, "Append with icon");
243 evas_object_smart_callback_add(bt, "clicked", _add_ic_cb, ds);
244 elm_box_pack_end(hbx, bt);
245 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
246 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
247 evas_object_show(bt);
249 bt = elm_button_add(win);
250 elm_object_text_set(bt, "Append with selected function");
251 evas_object_smart_callback_add(bt, "clicked", _add_func_cb, ds);
252 elm_box_pack_end(hbx, bt);
253 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
254 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
255 evas_object_show(bt);
257 bt = elm_button_add(win);
258 elm_object_text_set(bt, "Append with data");
259 evas_object_smart_callback_add(bt, "clicked", _add_data_cb, ds);
260 elm_box_pack_end(hbx, bt);
261 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
262 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
263 evas_object_show(bt);
265 hbx = elm_box_add(win);
266 elm_box_horizontal_set(hbx, EINA_TRUE);
267 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
268 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
269 elm_box_pack_end(bx, hbx);
270 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
271 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
272 evas_object_show(hbx);
274 bt = elm_button_add(win);
275 elm_object_text_set(bt, "Delete item");
276 evas_object_smart_callback_add(bt, "clicked", _del_cb, ds);
277 elm_box_pack_end(hbx, bt);
278 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
280 evas_object_show(bt);
282 bt = elm_button_add(win);
283 elm_object_text_set(bt, "Unselect item");
284 evas_object_smart_callback_add(bt, "clicked", _unselect_cb, ds);
285 elm_box_pack_end(hbx, bt);
286 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
287 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
288 evas_object_show(bt);
290 bt = elm_button_add(win);
291 elm_object_text_set(bt, "Print items");
292 evas_object_smart_callback_add(bt, "clicked", _print_cb, ds);
293 elm_box_pack_end(hbx, bt);
294 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
295 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
296 evas_object_show(bt);
298 bt = elm_button_add(win);
299 elm_object_text_set(bt, "Clear");
300 evas_object_smart_callback_add(bt, "clicked", _clear_cb, ds);
301 elm_box_pack_end(hbx, bt);
302 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
303 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
304 evas_object_show(bt);
306 hbx = elm_box_add(win);
307 elm_box_horizontal_set(hbx, EINA_TRUE);
308 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
309 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
310 elm_box_pack_end(bx, hbx);
311 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
312 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
313 evas_object_show(hbx);
315 bt = elm_button_add(win);
316 elm_object_text_set(bt, "Select first item");
317 evas_object_smart_callback_add(bt, "clicked", _select_first_cb, ds);
318 elm_box_pack_end(hbx, bt);
319 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
320 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
321 evas_object_show(bt);
323 bt = elm_button_add(win);
324 elm_object_text_set(bt, "Select last item");
325 evas_object_smart_callback_add(bt, "clicked", _select_last_cb, ds);
326 elm_box_pack_end(hbx, bt);
327 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
328 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
329 evas_object_show(bt);
331 bt = elm_button_add(win);
332 elm_object_text_set(bt, "Select next item");
333 evas_object_smart_callback_add(bt, "clicked", _select_next_cb, ds);
334 elm_box_pack_end(hbx, bt);
335 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
336 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
337 evas_object_show(bt);
339 bt = elm_button_add(win);
340 elm_object_text_set(bt, "Select previous item");
341 evas_object_smart_callback_add(bt, "clicked", _select_prev_cb, ds);
342 elm_box_pack_end(hbx, bt);
343 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
344 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
345 evas_object_show(bt);
347 evas_object_show(win);