\section{genlist\-\_\-example\-\_\-03.\-c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -g genlist\_example\_03.c -o genlist\_example\_03 `pkg-config --cflags --libs elementary`}

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

\textcolor{preprocessor}{#define N\_ITEMS 30}
\textcolor{preprocessor}{}
\textcolor{keyword}{static} Elm_Genlist_Item_Class *\_itc = NULL;

\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
\_item\_label\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)
\{
   time\_t t = (time\_t)ecore\_time\_unix\_get();
   \textcolor{keywordtype}{char} buf[256];
   \textcolor{keywordtype}{int} i = (int)(\textcolor{keywordtype}{long})data;

   \textcolor{keywordflow}{if} (!strcmp(part, \textcolor{stringliteral}{"elm.text"}))
     snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Item # %i"}, i);
   \textcolor{keywordflow}{else}
     \{
        \textcolor{keywordtype}{int} n;
        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"created at %s"}, ctime(&t));
        n = strlen(buf);
        buf[n - 1] = \textcolor{charliteral}{'\(\backslash\)0'};
     \}

   \textcolor{keywordflow}{return} strdup(buf);
\}

\textcolor{keyword}{static} Evas\_Object *
\_item\_content\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)
\{
   Evas\_Object *ic = elm_icon_add(obj);

   \textcolor{keywordflow}{if} (!strcmp(part, \textcolor{stringliteral}{"elm.swallow.icon"}))
     elm_icon_standard_set(ic, \textcolor{stringliteral}{"clock"});

   \textcolor{keywordflow}{return} ic;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_item\_sel\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   printf(\textcolor{stringliteral}{"sel item data [%p] on genlist obj [%p], item pointer [%p]\(\backslash\)n"},
          data, obj, event\_info);
\}

\textcolor{keyword}{static} Evas\_Object *
\_genlist\_add(Evas\_Object *box)
\{
   Evas\_Object *list = elm_genlist_add(elm_object_parent_widget_get(box));
   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);
   elm_box_pack_end(box, list);
   evas\_object\_show(list);

   \textcolor{keywordflow}{return} list;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_genlist\_fill(Evas\_Object *list)
\{
   \textcolor{keywordtype}{int} i;

   \textcolor{keywordflow}{for} (i = 0; i < N\_ITEMS; i++)
     \{
        elm_genlist_item_append(list, \_itc,
                                (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})i, NULL,
                                ELM_GENLIST_ITEM_NONE,
                                \_item\_sel\_cb, NULL);
     \}
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *box;
   Evas\_Object *list;

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"genlist"}, \textcolor{stringliteral}{"Genlist"});
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   elm_win_autodel_set(win, EINA\_TRUE);

   box = elm_box_add(win);
   elm_box_horizontal_set(box, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(box, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, box);
   evas\_object\_show(box);

   \textcolor{keywordflow}{if} (!\_itc)
     \{
        \_itc = elm_genlist_item_class_new();
        \_itc->item\_style = \textcolor{stringliteral}{"double\_label"};
        \_itc->func.text\_get = \_item\_label\_get;
        \_itc->func.content\_get = \_item\_content\_get;
        \_itc->func.state\_get = NULL;
        \_itc->func.del = NULL;
     \}

   list = \_genlist\_add(box);
   \_genlist\_fill(list);

   list = \_genlist\_add(box);
   elm_genlist_mode_set(list, ELM_LIST_LIMIT);
   \_genlist\_fill(list);

   list = \_genlist\_add(box);
   elm_genlist_mode_set(list, ELM_LIST_COMPRESS);
   \_genlist\_fill(list);

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

   elm_run();
   elm_shutdown();

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