\section{index\+\_\+example\+\_\+01.\+c}

\begin{DoxyCodeInclude}

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

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *dict[] = \(\backslash\)
\{
\textcolor{preprocessor}{#include "dict.txt"}
\};

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_item\_del(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   fprintf(stdout, \textcolor{stringliteral}{"Deleting index node (%s). Comparing index "}
           \textcolor{stringliteral}{"item data reported via callback with the one returned by "}
           \textcolor{stringliteral}{"index's API on items: %s.\(\backslash\)n"},
           elm\_index\_item\_letter\_get(event\_info),
           data == elm_object_item_data_get(event\_info) ? \textcolor{stringliteral}{"OK"} :
           \textcolor{stringliteral}{"FAIL, something went wrong"});
\}

\textcolor{comment}{/* delete an index item */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_item\_del(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *it = elm\_index\_selected\_item\_get(data, 0);

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

   fprintf(stdout, \textcolor{stringliteral}{"Deleting last selected index item, which had letter"}
           \textcolor{stringliteral}{" %s (pointing to %p)\(\backslash\)n"}, elm\_index\_item\_letter\_get(it),
           elm_object_item_data_get(it));

   elm\_object\_item\_del(it);
   elm\_index\_level\_go(data, 0);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_item\_del\_all(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   elm\_index\_item\_clear(data);
   elm\_index\_level\_go(data, 0);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_active\_set(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Eina\_Bool disabled = elm\_index\_autohide\_disabled\_get(data);
   elm\_index\_autohide\_disabled\_set(data, !disabled);

   fprintf(stdout, \textcolor{stringliteral}{"Toggling index programmatically to %s.\(\backslash\)n"},
           !disabled ? \textcolor{stringliteral}{"On"} : \textcolor{stringliteral}{"Off"});
\}

\textcolor{comment}{/* "delay,changed" hook */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_changed(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   elm\_list\_item\_bring\_in(elm_object_item_data_get(event\_info));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_selected(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *lit = event\_info;

   fprintf(stdout, \textcolor{stringliteral}{"New index item selected. Comparing item reported"}
           \textcolor{stringliteral}{" via callback with the selection returned by the API: "}
           \textcolor{stringliteral}{"%s.\(\backslash\)n"}, lit == elm\_index\_selected\_item\_get(obj, 0) ? \textcolor{stringliteral}{"OK"} :
           \textcolor{stringliteral}{"FAIL, something went wrong"});
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *hbox, *vbox, *bt, *sep, *list, *id;
   Elm_Object_Item *lit;
   \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} i;
   \textcolor{keywordtype}{char} curr = 0;

   elm_policy_set(ELM\_POLICY\_QUIT, ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"index"}, \textcolor{stringliteral}{"Index Example"});
   elm\_win\_autodel\_set(win, EINA\_TRUE);

   vbox = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(vbox, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_win\_resize\_object\_add(win, vbox);
   evas\_object\_show(vbox);

   list = elm_list_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);
   evas\_object\_show(list);
   elm\_box\_pack\_end(vbox, list);

   \textcolor{keywordtype}{id} = elm_index_add(win);
   evas\_object\_size\_hint\_weight\_set(\textcolor{keywordtype}{id}, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_win\_resize\_object\_add(win, \textcolor{keywordtype}{id});
   evas\_object\_show(\textcolor{keywordtype}{id});

   \textcolor{keywordflow}{for} (i = 0; i < (\textcolor{keyword}{sizeof}(dict) / \textcolor{keyword}{sizeof}(dict[0])); i++)
     \{
        lit = elm\_list\_item\_append(list, dict[i], NULL, NULL, NULL, NULL);

        \textcolor{keywordflow}{if} (curr != dict[i][0])
          \{
             Elm_Object_Item *index\_it;
             \textcolor{keywordtype}{char} buf[32];

             curr = dict[i][0];
             \textcolor{comment}{/* indexing by first letters */}

             snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%c"}, curr);
             index\_it = elm\_index\_item\_append(\textcolor{keywordtype}{id}, buf, NULL, lit);

             \textcolor{comment}{/* this is here just to demostrate the API call */}
             (void)elm\_index\_item\_find(\textcolor{keywordtype}{id}, lit);
             assert(elm\_index\_item\_find(\textcolor{keywordtype}{id}, lit) == index\_it);

             elm\_object\_item\_del\_cb\_set(index\_it, \_index\_item\_del);
          \}
     \}

   evas\_object\_smart\_callback\_add(\textcolor{keywordtype}{id}, \textcolor{stringliteral}{"delay,changed"}, \_index\_changed,
                                  NULL);
   evas\_object\_smart\_callback\_add(\textcolor{keywordtype}{id}, \textcolor{stringliteral}{"selected"}, \_index\_selected, NULL);
   elm\_index\_level\_go(\textcolor{keywordtype}{id}, 0);

   \textcolor{comment}{/* attribute setting knobs */}
   sep = elm_separator_add(win);
   elm\_separator\_horizontal\_set(sep, EINA\_TRUE);
   elm\_box\_pack\_end(vbox, sep);
   evas\_object\_show(sep);

   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\_fill\_set(hbox, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_box\_pack\_end(vbox, hbox);
   evas\_object\_show(hbox);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"bring in index"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_active\_set, \textcolor{keywordtype}{id});
   elm\_box\_pack\_end(hbox, bt);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"delete last selected item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_item\_del, \textcolor{keywordtype}{id});
   elm\_box\_pack\_end(hbox, bt);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"delete all items"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_item\_del\_all, \textcolor{keywordtype}{id});
   elm\_box\_pack\_end(hbox, bt);
   evas\_object\_show(bt);

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

   elm_run();

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