From: Daniel Juyung Seo Date: Wed, 20 Nov 2013 01:40:02 +0000 (+0900) Subject: index_example_01.c: sample code internal refactoring. X-Git-Tag: upstream/1.20.0~7116^2~14^2~3720 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=674287da502d33dd287c1f36a24062b23ba2d18e;p=platform%2Fupstream%2Fefl.git index_example_01.c: sample code internal refactoring. - avoid using unnecessary global variable. - use common name for item variable, it. - print out more useful messages on _active_set. --- diff --git a/legacy/elementary/src/examples/index_example_01.c b/legacy/elementary/src/examples/index_example_01.c index 332c8db..d8627ed 100644 --- a/legacy/elementary/src/examples/index_example_01.c +++ b/legacy/elementary/src/examples/index_example_01.c @@ -12,22 +12,13 @@ #include #include -struct example_data -{ - Evas_Object *list, *index; -}; - -struct example_data d = {NULL, NULL}; - static const char *dict[] = \ { #include "dict.txt" }; static void -_index_item_del(void *data, - Evas_Object *obj, - void *event_info) +_index_item_del(void *data, Evas_Object *obj, void *event_info) { fprintf(stdout, "Deleting index node (%s). Comparing index " "item data reported via callback with the one returned by " @@ -39,55 +30,46 @@ _index_item_del(void *data, /* delete an index item */ static void -_item_del(void *data, - Evas_Object *obj, - void *event_info) +_item_del(void *data, Evas_Object *obj, void *event_info) { - Elm_Object_Item *iit = elm_index_selected_item_get(d.index, 0); + Elm_Object_Item *it = elm_index_selected_item_get(data, 0); - if (!iit) return; + if (!it) return; fprintf(stdout, "Deleting last selected index item, which had letter" - " %s (pointing to %p)\n", elm_index_item_letter_get(iit), - elm_object_item_data_get(iit)); + " %s (pointing to %p)\n", elm_index_item_letter_get(it), + elm_object_item_data_get(it)); - elm_object_item_del(iit); - elm_index_level_go(d.index, 0); + elm_object_item_del(it); + elm_index_level_go(data, 0); } static void -_item_del_all(void *data, - Evas_Object *obj, - void *event_info) +_item_del_all(void *data, Evas_Object *obj, void *event_info) { - elm_index_item_clear(d.index); - elm_index_level_go(d.index, 0); + elm_index_item_clear(data); + elm_index_level_go(data, 0); } static void -_active_set(void *data, - Evas_Object *obj, - void *event_info) +_active_set(void *data, Evas_Object *obj, void *event_info) { - elm_index_autohide_disabled_set - (d.index, !elm_index_autohide_disabled_get(d.index)); + Eina_Bool disabled = elm_index_autohide_disabled_get(data); + elm_index_autohide_disabled_set(data, !disabled); - fprintf(stdout, "Toggling index programmatically.\n"); + fprintf(stdout, "Toggling index programmatically to %s.\n", + !disabled ? "On" : "Off"); } /* "delay,changed" hook */ static void -_index_changed(void *data, - Evas_Object *obj, - void *event_info) +_index_changed(void *data, Evas_Object *obj, void *event_info) { elm_list_item_bring_in(elm_object_item_data_get(event_info)); } static void -_index_selected(void *data, - Evas_Object *obj, - void *event_info) +_index_selected(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *lit = event_info; @@ -98,10 +80,9 @@ _index_selected(void *data, } EAPI_MAIN int -elm_main(int argc, - char **argv) +elm_main(int argc, char **argv) { - Evas_Object *win, *hbox, *vbox, *bt, *sep; + Evas_Object *win, *hbox, *vbox, *bt, *sep, *list, *id; Elm_Object_Item *lit; unsigned int i; char curr = 0; @@ -110,28 +91,28 @@ elm_main(int argc, win = elm_win_util_standard_add("index", "Index Example"); elm_win_autodel_set(win, EINA_TRUE); + evas_object_resize(win, 320, 600); + evas_object_show(win); vbox = elm_box_add(win); evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, vbox); evas_object_show(vbox); - d.list = elm_list_add(win); - evas_object_size_hint_weight_set(d.list, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(d.list, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(d.list); - elm_box_pack_end(vbox, d.list); + list = elm_list_add(win); + evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(list); + elm_box_pack_end(vbox, list); - d.index = elm_index_add(win); - evas_object_size_hint_weight_set(d.index, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, d.index); - evas_object_show(d.index); + id = elm_index_add(win); + evas_object_size_hint_weight_set(id, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, id); + evas_object_show(id); for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++) { - lit = elm_list_item_append(d.list, dict[i], NULL, NULL, NULL, NULL); + lit = elm_list_item_append(list, dict[i], NULL, NULL, NULL, NULL); if (curr != dict[i][0]) { @@ -142,20 +123,20 @@ elm_main(int argc, /* indexing by first letters */ snprintf(buf, sizeof(buf), "%c", curr); - index_it = elm_index_item_append(d.index, buf, NULL, lit); + index_it = elm_index_item_append(id, buf, NULL, lit); /* this is here just to demostrate the API call */ - it = elm_index_item_find(d.index, lit); + it = elm_index_item_find(id, lit); assert(it == index_it); elm_object_item_del_cb_set(index_it, _index_item_del); } } - evas_object_smart_callback_add(d.index, "delay,changed", _index_changed, + evas_object_smart_callback_add(id, "delay,changed", _index_changed, NULL); - evas_object_smart_callback_add(d.index, "selected", _index_selected, NULL); - elm_index_level_go(d.index, 0); + evas_object_smart_callback_add(id, "selected", _index_selected, NULL); + elm_index_level_go(id, 0); /* attribute setting knobs */ sep = elm_separator_add(win); @@ -172,25 +153,22 @@ elm_main(int argc, bt = elm_button_add(win); elm_object_text_set(bt, "bring in index"); - evas_object_smart_callback_add(bt, "clicked", _active_set, NULL); + evas_object_smart_callback_add(bt, "clicked", _active_set, id); elm_box_pack_end(hbox, bt); evas_object_show(bt); bt = elm_button_add(win); elm_object_text_set(bt, "delete last selected item"); - evas_object_smart_callback_add(bt, "clicked", _item_del, NULL); + evas_object_smart_callback_add(bt, "clicked", _item_del, id); elm_box_pack_end(hbox, bt); evas_object_show(bt); bt = elm_button_add(win); elm_object_text_set(bt, "delete all items"); - evas_object_smart_callback_add(bt, "clicked", _item_del_all, NULL); + evas_object_smart_callback_add(bt, "clicked", _item_del_all, id); elm_box_pack_end(hbox, bt); evas_object_show(bt); - evas_object_resize(win, 320, 600); - evas_object_show(win); - elm_run(); elm_shutdown();