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

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

\textcolor{preprocessor}{#define \_GNU\_SOURCE}
\textcolor{preprocessor}{#include <string.h>}

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

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_combobox\_clicked\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED,
                     \textcolor{keywordtype}{void} *event\_info EINA\_UNUSED)
\{
   printf(\textcolor{stringliteral}{"Hover button is clicked and 'clicked' callback is called.\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_combobox\_selected\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED,
                      \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *txt = elm\_object\_item\_text\_get(event\_info);
   printf(\textcolor{stringliteral}{"'selected' callback is called. (selected item : %s)\(\backslash\)n"}, txt);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_combobox\_dismissed\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED,
                       \textcolor{keywordtype}{void} *event\_info EINA\_UNUSED)
\{
   printf(\textcolor{stringliteral}{"'dismissed' callback is called.\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_combobox\_expanded\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED,
                       \textcolor{keywordtype}{void} *event\_info EINA\_UNUSED)
\{
   printf(\textcolor{stringliteral}{"'expanded' callback is called.\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_combobox\_item\_pressed\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj,
                      \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *txt = elm\_object\_item\_text\_get(event\_info);
   printf(\textcolor{stringliteral}{"'item,pressed' callback is called. (selected item : %s)\(\backslash\)n"}, txt);
   elm\_object\_text\_set(obj, txt);
   elm_combobox_hover_end(obj);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
gl\_text\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj EINA\_UNUSED, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part EINA\_UNUSED)
\{
   \textcolor{keywordtype}{char} buf[256];
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Item # %i"}, (\textcolor{keywordtype}{int})(uintptr\_t)data);
   \textcolor{keywordflow}{return} strdup(buf);
\}

\textcolor{keyword}{static} Eina\_Bool gl\_state\_get(\textcolor{keywordtype}{void} *data EINA\_UNUSED,
                               Evas\_Object *obj EINA\_UNUSED,
                               \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part EINA\_UNUSED)
\{
   \textcolor{keywordflow}{return} EINA\_FALSE;
\}

\textcolor{keyword}{static} Eina\_Bool
gl\_filter\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj EINA\_UNUSED, \textcolor{keywordtype}{void} *key)
\{
   \textcolor{comment}{// if the key is empty/NULL, return true for item}
   \textcolor{keywordflow}{if} (!strlen((\textcolor{keywordtype}{char} *)key)) \textcolor{keywordflow}{return} EINA\_TRUE;
   \textcolor{keywordtype}{char} buf[256];
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Item # %i"}, (\textcolor{keywordtype}{int})(uintptr\_t)data);
   \textcolor{keywordflow}{if} (strcasestr(buf, (\textcolor{keywordtype}{char} *)key))
     \textcolor{keywordflow}{return} EINA\_TRUE;
   \textcolor{comment}{// Default case should return false (item fails filter hence will be hidden)}
   \textcolor{keywordflow}{return} EINA\_FALSE;
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc EINA\_UNUSED, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *bg;

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

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"combobox"}, \textcolor{stringliteral}{"Combobox"});
   elm_win_autodel_set(win, EINA\_TRUE);

   bg = elm_bg_add(win);
   evas\_object\_size\_hint\_weight\_set(bg, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bg, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_win_resize_object_add(win, bg);
   evas\_object\_show(bg);

   Evas\_Object *bx = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(bx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas\_object\_show(bx);

   Evas\_Object *combobox = elm_combobox_add(win);
   evas\_object\_size\_hint\_weight\_set(combobox, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(combobox, EVAS\_HINT\_FILL, 0);
   elm_object_part_text_set(combobox, \textcolor{stringliteral}{"guide"}, \textcolor{stringliteral}{"A Simple list"});
   elm_box_pack_end(bx, combobox);
   evas\_object\_show(combobox);

   Elm_Genlist_Item_Class *itc;
   itc = elm_genlist_item_class_new();
   itc->item\_style = \textcolor{stringliteral}{"default"};
   itc->func.text\_get = gl\_text\_get;
   itc->func.content\_get = NULL;
   itc->func.state\_get = gl\_state\_get;
   itc->func.filter\_get = gl\_filter\_get;
   itc->func.del = NULL;

   \textcolor{keywordflow}{for} (\textcolor{keywordtype}{int} i = 0; i < 1000; i++)
     elm_genlist_item_append(combobox, itc, (\textcolor{keywordtype}{void} *)(uintptr\_t)i,
                             NULL, ELM\_GENLIST\_ITEM\_NONE, NULL,
                             (\textcolor{keywordtype}{void}*)(uintptr\_t)(i * 10));
   evas\_object\_smart\_callback\_add(combobox, \textcolor{stringliteral}{"clicked"},
                                  \_combobox\_clicked\_cb, NULL);
   evas\_object\_smart\_callback\_add(combobox, \textcolor{stringliteral}{"selected"},
                                  \_combobox\_selected\_cb, NULL);
   evas\_object\_smart\_callback\_add(combobox, \textcolor{stringliteral}{"dismissed"},
                                  \_combobox\_dismissed\_cb, NULL);
   evas\_object\_smart\_callback\_add(combobox, \textcolor{stringliteral}{"expanded"},
                                  \_combobox\_expanded\_cb, NULL);
   evas\_object\_smart\_callback\_add(combobox, \textcolor{stringliteral}{"item,pressed"},
                                  \_combobox\_item\_pressed\_cb, NULL);

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

   elm_run();

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