

In this example we will create a combobox with 1000 items.

We will start with the normal creation of window stuff\+: 
\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);

\end{DoxyCodeInclude}


Next we will create a box. 
\begin{DoxyCodeInclude}

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

\end{DoxyCodeInclude}


And now we create our combobox and set some of it\textquotesingle{}s properties. We set {\ttfamily win} as its parent, set a text \char`\"{}\+A Simple List\char`\"{} (which acts as a placeholder). We pack the combobox in box. 
\begin{DoxyCodeInclude}

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

\end{DoxyCodeInclude}


Next we create a new genlist item class and sets its properties\+: item\+\_\+style as deafult , callback for text\+\_\+get and set others as N\+U\+LL. 
\begin{DoxyCodeInclude}

   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;

\end{DoxyCodeInclude}


Next we will append 1000 items to the combobox, this is similar to appending items to the genlist 
\begin{DoxyCodeInclude}

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

\end{DoxyCodeInclude}


We also set a pair of callbacks to be called whenever any item is selected or pressed. when the combobox is activated, dismissed, expanded \+: 
\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


And then ask that our combobox be shown and run the main loop\+: 
\begin{DoxyCodeInclude}

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

   elm_run();

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

\end{DoxyCodeInclude}


We now have the callback for setting text in the each item of genlist\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Next we have the callback which is called when the combobox is clicked\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Next we have the callback that is called whenever an item is selected and text of that item is set on combobox\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Next we have the callback that is called whenever an item is pressed and text of that item is set on combobox and the hover is closed\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Next we have the callback that is called whenever an item is double-\/clicked or pressing (enter$\vert$return$\vert$spacebar) on an item also the text(event\+\_\+info) of that item is set on combobox and the hover is closed\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And the callback that is called when the hover,genlist are closed. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And finally the callback is called when hover,genlist are shown. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Our example will initially look like this\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/combobox_example_01}}
\end{DoxyImageNoCaption}
 