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

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

\textcolor{preprocessor}{#define N\_ITEMS 300}

\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} (i % 2)
     \{
        \textcolor{keywordtype}{int} n;
        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Very Long Item # %i - realized at %s"}, i, ctime(&t));
        n = strlen(buf);
        buf[n - 1] = \textcolor{charliteral}{'\(\backslash\)0'};
     \}
   \textcolor{keywordflow}{else}
     snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"short item # %i"}, i);
   \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"});

   evas\_object\_size\_hint\_aspect\_set(ic, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1, 1);
   \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} \textcolor{keywordtype}{void}
\_show\_status\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Evas\_Coord x, y, w, h, mx, my;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   \textcolor{keyword}{const} Eina\_List *selected, *l, *realized;
   printf(\textcolor{stringliteral}{"\(\backslash\)nfirst selected item: %p\(\backslash\)n"}, glit);

   selected = elm_genlist_selected_items_get(list);
   printf(\textcolor{stringliteral}{"all selected items (%d): "}, eina\_list\_count(selected));
   EINA\_LIST\_FOREACH(selected, l, glit)
     printf(\textcolor{stringliteral}{"%p "}, glit);
   printf(\textcolor{stringliteral}{"\(\backslash\)n"});

   realized = elm_genlist_realized_items_get(list);
   printf(\textcolor{stringliteral}{"realized items (%d): "}, eina\_list\_count(realized));
   EINA\_LIST\_FOREACH(realized, l, glit)
     printf(\textcolor{stringliteral}{"%p  "}, glit);
   printf(\textcolor{stringliteral}{"\(\backslash\)n"});
   printf(\textcolor{stringliteral}{"genlist mode: %d\(\backslash\)n"}, elm_genlist_decorate_mode_get(list));
   printf(\textcolor{stringliteral}{"mode item: %p\(\backslash\)n"}, elm_genlist_decorated_item_get(list));

   evas\_object\_geometry\_get(list, &x, &y, &w, &h);
   mx = w / 2 + x;
   my = h / 2 + y;
   glit = elm_genlist_at_xy_item_get(list, mx, my, NULL);
   printf(\textcolor{stringliteral}{"item in the middle of the screen: %p\(\backslash\)n"}, glit);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_realize\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   elm_genlist_realized_items_update(list);
\}

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

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"genlist"}, \textcolor{stringliteral}{"Genlist - simple"});
   elm_policy_set(ELM\_POLICY\_QUIT, ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED);
   elm_win_autodel_set(win, EINA\_TRUE);

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

   list = elm_genlist_add(win);

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

   Eina\_Bool hbounce, vbounce, always, no\_sel;
   Elm_Scroller_Policy hp, vp;
   Elm\_Object\_Select\_Mode sel\_mode;

   always = no\_sel = EINA\_FALSE;
   sel\_mode = elm_genlist_select_mode_get(list);
   \textcolor{keywordflow}{if} (sel\_mode == ELM\_OBJECT\_SELECT\_MODE\_ALWAYS)
     always = EINA\_TRUE;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (sel\_mode == ELM\_OBJECT\_SELECT\_MODE\_NONE)
     no\_sel = EINA\_TRUE;

   printf(\textcolor{stringliteral}{"default values:\(\backslash\)n"});
   printf(\textcolor{stringliteral}{"always select: %d\(\backslash\)n"}, always);
   elm_scroller_bounce_get(list, &hbounce, &vbounce);
   printf(\textcolor{stringliteral}{"bounce - horizontal: %d, vertical: %d\(\backslash\)n"}, hbounce, vbounce);
   printf(\textcolor{stringliteral}{"homogeneous: %d\(\backslash\)n"}, elm_genlist_homogeneous_get(list));
   printf(\textcolor{stringliteral}{"horizontal mode: %d\(\backslash\)n"}, elm_genlist_mode_get(list));
   printf(\textcolor{stringliteral}{"longpress timeout: %0.3f\(\backslash\)n"},
          elm_genlist_longpress_timeout_get(list));
   printf(\textcolor{stringliteral}{"multi selection: %d\(\backslash\)n"}, elm_genlist_multi_select_get(list));
   printf(\textcolor{stringliteral}{"no selection mode: %d\(\backslash\)n"}, no\_sel);
   elm_scroller_policy_get(list, &hp, &vp);
   printf(\textcolor{stringliteral}{"scroller policy - horizontal: %d, vertical: %d\(\backslash\)n"}, hp, vp);
   printf(\textcolor{stringliteral}{"block count: %d\(\backslash\)n"}, elm_genlist_block_count_get(list));
   printf(\textcolor{stringliteral}{"\(\backslash\)n"});

   elm_scroller_bounce_set(list, EINA\_FALSE, EINA\_FALSE);
   elm_genlist_homogeneous_set(list, EINA\_FALSE);
   elm_genlist_mode_set(list, ELM_LIST_LIMIT);
   elm_genlist_multi_select_set(list, EINA\_TRUE);
   elm_genlist_select_mode_set(list, ELM\_OBJECT\_SELECT\_MODE\_DEFAULT);
   elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_ON);
   elm_genlist_longpress_timeout_set(list, 0.5);
   elm_genlist_block_count_set(list, 16);

   \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);
     \}

   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);

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

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Show status"});
   evas\_object\_size\_hint\_weight\_set(btn, 0, 0);
   evas\_object\_size\_hint\_align\_set(btn, 0.5, 0.5);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_show\_status\_cb, list);
   elm_box_pack_end(hbox, btn);
   evas\_object\_show(btn);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Realize"});
   evas\_object\_size\_hint\_weight\_set(btn, 0, 0);
   evas\_object\_size\_hint\_align\_set(btn, 0.5, 0.5);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_realize\_cb, list);
   elm_box_pack_end(hbox, btn);
   evas\_object\_show(btn);

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

   elm_run();

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