\section{hoversel\-\_\-example\-\_\-01.\-c}

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

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

\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_print\_items(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_free(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_add\_item(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_clear\_btn\_clicked\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordflow}{if} (!data) \textcolor{keywordflow}{return};
   elm_hoversel_clear((Evas\_Object *)data);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *rect, *hoversel, *btn = NULL;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"hoversel"}, \textcolor{stringliteral}{"Hoversel"});
   elm_win_autodel_set(win, EINA\_TRUE);
   evas\_object\_resize(win, 200, 300);
   evas\_object\_show(win);

   rect = evas\_object\_rectangle\_add(evas\_object\_evas\_get(win));
   evas\_object\_color\_set(rect, 255, 0, 0, 255);
   evas\_object\_show(rect);

   hoversel = elm_hoversel_add(win);
   elm_hoversel_hover_parent_set(hoversel, win);
   elm_hoversel_horizontal_set(hoversel, EINA\_FALSE);
   elm\_object\_text\_set(hoversel, \textcolor{stringliteral}{"Add an item to Hoversel"});
   elm_object_part_content_set(hoversel, \textcolor{stringliteral}{"icon"}, rect);
   elm_hoversel_item_add(hoversel, \textcolor{stringliteral}{"Print items"}, NULL, ELM\_ICON\_NONE,
                         \_print\_items, NULL);
   elm_hoversel_item_add(hoversel, \textcolor{stringliteral}{"Option 2"}, \textcolor{stringliteral}{"home"}, ELM\_ICON\_STANDARD, NULL,
                         NULL);
   evas\_object\_smart\_callback\_add(hoversel, \textcolor{stringliteral}{"clicked"}, \_add\_item, NULL);

   evas\_object\_resize(hoversel, 180, 30);
   evas\_object\_move(hoversel, 10, 10);
   evas\_object\_show(hoversel);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Clear all Items"});
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_clear\_btn\_clicked\_cb, hoversel);
   evas\_object\_resize(btn, 180, 30);
   evas\_object\_move(btn, 10, 50);
   evas\_object\_show(btn);

   elm_run();
   elm_shutdown();

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

static \textcolor{keywordtype}{void}
\_print\_items(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} Eina\_List *items = elm_hoversel_items_get(obj);
   \textcolor{keyword}{const} Eina\_List *l;
   Elm_Object_Item *hoversel\_it;

   EINA\_LIST\_FOREACH(items, l, hoversel\_it)
     printf("%s\(\backslash\)n", elm\_object\_item\_text\_get(hoversel\_it));
\}

static \textcolor{keywordtype}{void}
\_add\_item(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{static} \textcolor{keywordtype}{int} num = 0;
   \textcolor{keywordtype}{char} *str = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 10);
   Elm_Object_Item *hoversel\_it;

   snprintf(str, 10, \textcolor{stringliteral}{"item %d"}, ++num);

   hoversel\_it = elm_hoversel_item_add(obj, str, NULL, ELM\_ICON\_NONE, NULL,
                                       str);
   elm_object_item_del_cb_set(hoversel\_it, \_free);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_free(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   free(data);
\}
\end{DoxyCodeInclude}
 