\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{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();

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