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

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_reverse\_btn\_clicked\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordflow}{if} (!data) \textcolor{keywordflow}{return};
   elm_object_mirrored_set(data, !elm_object_mirrored_get (data));
   printf(\textcolor{stringliteral}{"\(\backslash\)nMirrored mode is now %s"}, elm_object_mirrored_get(data) ? \textcolor{stringliteral}{"ON"} : \textcolor{stringliteral}{"OFF"} );
   fflush(stdout);
\}

Eina\_Bool is\_eng = EINA\_TRUE;
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_arabic\_btn\_clicked\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordflow}{if} (!data) \textcolor{keywordflow}{return};
   is\_eng = !is\_eng;
   elm\_object\_text\_set(data, is\_eng ?
                       \textcolor{stringliteral}{"Enable Arabic for new items"} :
                       \textcolor{stringliteral}{"Enable English for new items"});
\}

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

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

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Change Mirror Mode"});
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_reverse\_btn\_clicked\_cb, hoversel);
   evas\_object\_resize(btn, 180, 30);
   evas\_object\_move(btn, 10, 90);
   evas\_object\_show(btn);

   btn = elm_button_add(win);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Enable Arabic for new items"});
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_arabic\_btn\_clicked\_cb, btn);
   evas\_object\_resize(btn, 180, 30);
   evas\_object\_move(btn, 10, 130);
   evas\_object\_show(btn);

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

   elm_run();

   \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}) * 11);
   Elm_Object_Item *hoversel\_it;

   \textcolor{keywordflow}{if}(is\_eng)
     snprintf(str, 11, \textcolor{stringliteral}{"item %d"}, ++num);
   \textcolor{keywordflow}{else}
     snprintf(str, 11, \textcolor{stringliteral}{"بند %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}
 