\section{list\+\_\+example\+\_\+03.\+c}

\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{int} counter = 3;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_prepend\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_prepend(li, label, NULL, NULL, NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_append(li, label, NULL, NULL, NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_ic\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *ic, *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ic = elm_icon_add(li);
   elm_icon_standard_set(ic, \textcolor{stringliteral}{"home"});
   elm_image_resizable_set(ic, EINA\_FALSE, EINA\_FALSE);

   list\_it = elm_list_item_append(li, label, ic,  NULL, NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item with icon\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_sel\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s\(\backslash\)n"}, elm\_object\_item\_text\_get(list\_it));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_func\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_append(li, label, NULL, NULL, \_sel\_cb, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_sel\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{char} *content = data;
   Elm_Object_Item *list\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s with data: %s\(\backslash\)n"},
          elm\_object\_item\_text\_get(list\_it), content);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_free\_data(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   free(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];
   \textcolor{keywordtype}{char} *content = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 32);

   snprintf(content, 32, \textcolor{stringliteral}{"Item content %i"}, counter);
   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_append(li, label, NULL, NULL, \_sel\_data\_cb, content);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     \{
        printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}
   elm\_object\_item\_del\_cb\_set(list\_it, \_free\_data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_del\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   elm\_object\_item\_del(selected\_item);
   elm_list_go(li);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_unselect\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   elm_list_item_selected_set(selected\_item, EINA\_FALSE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_print\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} Eina\_List *l, *items;
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;

   items = elm_list_items_get(li);
   EINA\_LIST\_FOREACH(items, l, list\_it)
     printf("%s\(\backslash\)n", elm\_object\_item\_text\_get(list\_it));
\}

static \textcolor{keywordtype}{void}
\_clear\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *li = data;
   elm_list_clear(li);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_select\_next\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *next\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   next\_item = elm_list_item_next(selected\_item);
   \textcolor{keywordflow}{if} (next\_item)
     elm_list_item_selected_set(next\_item, EINA\_TRUE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_insert\_after\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_insert_after(li, selected\_item, label, NULL, NULL,
                                        NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_select\_prev\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *prev\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   prev\_item = elm_list_item_prev(selected\_item);
   \textcolor{keywordflow}{if} (prev\_item)
     elm_list_item_selected_set(prev\_item, EINA\_TRUE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_insert\_before\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_insert_before(li, selected\_item, label, NULL, NULL,
                                         NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_set\_separator\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};
   elm_list_item_separator_set(selected\_item, EINA\_TRUE);
   elm_list_go(li);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_disable\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};
   elm\_object\_item\_disabled\_set(selected\_item, EINA\_TRUE);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *bx, *hbx, *li, *bt;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"list"}, \textcolor{stringliteral}{"List Items Example"});
   elm_win_autodel_set(win, EINA\_TRUE);

   bx = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(bx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas\_object\_show(bx);

   li = elm_list_add(win);
   evas\_object\_size\_hint\_weight\_set(li, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(li, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bx, li);

   elm_list_item_append(li, \textcolor{stringliteral}{"Item 0"}, NULL, NULL, NULL, NULL);
   elm_list_item_append(li, \textcolor{stringliteral}{"Item 1"}, NULL, NULL, NULL, NULL);
   elm_list_item_append(li, \textcolor{stringliteral}{"Item 2"}, NULL, NULL, NULL, NULL);

   hbx = elm_box_add(win);
   elm_box_horizontal_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, 0);
   elm_box_pack_end(bx, hbx);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Prepend item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_prepend\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   hbx = elm_box_add(win);
   elm_box_horizontal_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, 0);
   elm_box_pack_end(bx, hbx);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append with icon"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_ic\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append with selected function"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_func\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append with data"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_data\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   hbx = elm_box_add(win);
   elm_box_horizontal_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, 0);
   elm_box_pack_end(bx, hbx);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Delete item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_del\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Unselect item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_unselect\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Print items"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_print\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Clear"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_clear\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   hbx = elm_box_add(win);
   elm_box_horizontal_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, 0);
   elm_box_pack_end(bx, hbx);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Select next item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_select\_next\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Insert after item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_insert\_after\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Select previous item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_select\_prev\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Insert before item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_insert\_before\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   hbx = elm_box_add(win);
   elm_box_horizontal_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, 0);
   elm_box_pack_end(bx, hbx);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Set as separator"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_set\_separator\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Disable item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_disable\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

   elm_list_go(li);
   evas\_object\_show(li);

   evas\_object\_resize(win, 320, 600);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()
\end{DoxyCodeInclude}
 