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

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

\textcolor{preprocessor}{#define N\_ITEMS 300}
\textcolor{preprocessor}{}
\textcolor{keyword}{static} Elm_Genlist_Item_Class *\_itc = NULL;
\textcolor{keyword}{static} Elm_Genlist_Item_Class *\_itc\_group = NULL;
\textcolor{keyword}{static} \textcolor{keywordtype}{int} nitems = 0;

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

   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}{char} *
\_group\_label\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)
\{
   \textcolor{keywordtype}{char} buf[256];
   \textcolor{keywordtype}{int} i = (int)(\textcolor{keywordtype}{long})data;

   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Group %d (item #%d)"}, i / 7, i);

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

\textcolor{keyword}{static} Evas\_Object *
\_group\_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}{"home"});

   evas\_object\_size\_hint\_aspect\_set(ic, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1, 1);
   \textcolor{keywordflow}{return} ic;
\}

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

   elm_genlist_item_append(list, \_itc,
                           (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, NULL,
                           ELM_GENLIST_ITEM_NONE,
                           \_item\_sel\_cb, NULL);

\}

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

   elm_genlist_item_prepend(list, \_itc,
                            (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, NULL,
                            ELM_GENLIST_ITEM_NONE,
                            \_item\_sel\_cb, NULL);

\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_insert\_before\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_insert_before(list, \_itc,
                                  (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, NULL,
                                  glit, ELM_GENLIST_ITEM_NONE,
                                  \_item\_sel\_cb, NULL);

\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_insert\_after\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_insert_after(list, \_itc,
                                 (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, NULL,
                                 glit, ELM_GENLIST_ITEM_NONE,
                                 \_item\_sel\_cb, NULL);

\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_next\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   \textcolor{keywordflow}{if} (glit) glit = elm_genlist_item_next_get(glit);
   \textcolor{keywordflow}{if} (!glit) glit = elm_genlist_first_item_get(list);

   elm_genlist_item_selected_set(glit, EINA\_TRUE);
   elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_prev\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   \textcolor{keywordflow}{if} (glit) glit = elm_genlist_item_prev_get(glit);
   \textcolor{keywordflow}{if} (!glit) glit = elm_genlist_last_item_get(list);

   elm_genlist_item_selected_set(glit, EINA\_TRUE);
   elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_bring\_in\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *glit = data;
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_bring_in(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_show\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *glit = data;
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_middle\_in\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *glit = data;
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_bring_in(glit, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_middle\_show\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *glit = data;
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_top\_in\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *glit = data;
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_bring_in(glit, ELM_GENLIST_ITEM_SCROLLTO_TOP);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_top\_show\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *glit = data;
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_TOP);
\}

\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_Object_Item *glit = elm_genlist_selected_item_get(list);
   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};

   elm_genlist_item_update(glit);
\}

\textcolor{keyword}{static} Evas\_Object *
\_button\_add(Evas\_Object *list, Evas\_Object *box, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *label, Evas\_Smart\_Cb cb)
\{
   Evas\_Object *bt;

   bt = elm_button_add(elm_object_parent_widget_get(list));
   elm\_object\_text\_set(bt, label);
   elm_box_pack_end(box, bt);
   evas\_object\_show(bt);

   \textcolor{keywordflow}{if} (cb)
     evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, cb, list);

   \textcolor{keywordflow}{return} bt;
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *box, *fbox;
   Evas\_Object *list;
   Evas\_Object *bt\_bring\_in, *bt\_show;
   Evas\_Object *bt\_middle\_in, *bt\_middle\_show;
   Evas\_Object *bt\_top\_in, *bt\_top\_show;
   \textcolor{keywordtype}{int} i;

   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);
   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}{"default"};
        \_itc->func.text\_get = \_item\_label\_get;
        \_itc->func.content\_get = \_item\_content\_get;
        \_itc->func.state\_get = NULL;
        \_itc->func.del = NULL;
     \}

   \textcolor{keywordflow}{if} (!\_itc\_group)
     \{
        \_itc\_group = elm_genlist_item_class_new();
        \_itc\_group->item\_style = \textcolor{stringliteral}{"group\_index"};
        \_itc\_group->func.text\_get = \_group\_label\_get;
        \_itc\_group->func.content\_get = \_group\_content\_get;
        \_itc\_group->func.state\_get = NULL;
        \_itc\_group->func.del = NULL;
     \}
   list = elm_genlist_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);
   elm_box_pack_end(box, list);
   evas\_object\_show(list);

   fbox = elm_box_add(win);
   elm_box_layout_set(fbox, evas\_object\_box\_layout\_flow\_horizontal,
                      NULL, NULL);
   evas\_object\_size\_hint\_weight\_set(fbox, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(fbox, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box, fbox);
   evas\_object\_show(fbox);

   \_button\_add(list, fbox, \textcolor{stringliteral}{"prepend"}, \_prepend\_cb);
   \_button\_add(list, fbox, \textcolor{stringliteral}{"append"}, \_append\_cb);
   \_button\_add(list, fbox, \textcolor{stringliteral}{"insert before"}, \_insert\_before\_cb);
   \_button\_add(list, fbox, \textcolor{stringliteral}{"insert after"}, \_insert\_after\_cb);
   \_button\_add(list, fbox, \textcolor{stringliteral}{"prev"}, \_prev\_cb);
   \_button\_add(list, fbox, \textcolor{stringliteral}{"next"}, \_next\_cb);
   \_button\_add(list, fbox, \textcolor{stringliteral}{"realize"}, \_realize\_cb);
   bt\_bring\_in = \_button\_add(list, fbox, \textcolor{stringliteral}{"bring #50"}, NULL);
   bt\_show = \_button\_add(list, fbox, \textcolor{stringliteral}{"show #50"}, NULL);
   bt\_middle\_in = \_button\_add(list, fbox, \textcolor{stringliteral}{"bring to middle #200"}, NULL);
   bt\_middle\_show = \_button\_add(list, fbox, \textcolor{stringliteral}{"show in middle #200"}, NULL);
   bt\_top\_in = \_button\_add(list, fbox, \textcolor{stringliteral}{"bring to top #250"}, NULL);
   bt\_top\_show = \_button\_add(list, fbox, \textcolor{stringliteral}{"show in top #250"}, NULL);

   \textcolor{keywordflow}{for} (i = 0; i < N\_ITEMS; i++)
     \{
        Elm_Object_Item *gli = NULL, *glg = NULL;

        \textcolor{keywordflow}{if} (i % 7 == 0)
          \{
             glg = gli = elm_genlist_item_append(list, \_itc\_group,
                                                 (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, NULL,
                                                 ELM_GENLIST_ITEM_GROUP,
                                                 \_item\_sel\_cb, NULL);
             elm_genlist_item_select_mode_set(gli, 
      ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
          \}
        \textcolor{keywordflow}{else}
          \{
             gli = elm_genlist_item_append(list, \_itc,
                                           (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, glg,
                                           ELM_GENLIST_ITEM_NONE,
                                           \_item\_sel\_cb, NULL);
          \}

        \textcolor{keywordflow}{switch} (i)
          \{
           \textcolor{keywordflow}{case} 3:
              elm_object_item_disabled_set(gli, EINA\_TRUE);
              \textcolor{keywordflow}{break};
           \textcolor{keywordflow}{case} 50:
              evas\_object\_smart\_callback\_add(
                 bt\_bring\_in, \textcolor{stringliteral}{"clicked"}, \_bring\_in\_cb, gli);
              evas\_object\_smart\_callback\_add(
                 bt\_show, \textcolor{stringliteral}{"clicked"}, \_show\_cb, gli);
              \textcolor{keywordflow}{break};
           \textcolor{keywordflow}{case} 200:
              evas\_object\_smart\_callback\_add(
                 bt\_middle\_in, \textcolor{stringliteral}{"clicked"}, \_middle\_in\_cb, gli);
              evas\_object\_smart\_callback\_add(
                 bt\_middle\_show, \textcolor{stringliteral}{"clicked"}, \_middle\_show\_cb, gli);
              \textcolor{keywordflow}{break};
           \textcolor{keywordflow}{case} 250:
              evas\_object\_smart\_callback\_add(
                 bt\_top\_in, \textcolor{stringliteral}{"clicked"}, \_top\_in\_cb, gli);
              evas\_object\_smart\_callback\_add(
                 bt\_top\_show, \textcolor{stringliteral}{"clicked"}, \_top\_show\_cb, gli);
          \}
     \}

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

   elm_run();
   elm_shutdown();

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