\section{diskselector\+\_\+example\+\_\+02.\+c}

\begin{DoxyCodeInclude}

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

\textcolor{keyword}{static} \textcolor{keywordtype}{int} counter = 3;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_ds\_selected\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED,
                \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *it = event\_info;
   printf(\textcolor{stringliteral}{"Selected Item %s\(\backslash\)n"}, elm\_object\_item\_text\_get(it));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ds\_it = elm\_diskselector\_item\_append(ds, label, NULL, NULL, NULL);
   \textcolor{keywordflow}{if} (!ds\_it) printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_ic\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ic, *ds = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ic = elm_icon_add(ds);
   elm\_icon\_standard\_set(ic, \textcolor{stringliteral}{"home"});

   ds\_it = elm\_diskselector\_item\_append(ds, label, ic, NULL, NULL);
   \textcolor{keywordflow}{if} (!ds\_it) printf(\textcolor{stringliteral}{"Error adding item with icon\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_sel\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s\(\backslash\)n"}, elm\_object\_item\_text\_get(ds\_it));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_func\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ds\_it = elm\_diskselector\_item\_append(ds, label, NULL, \_sel\_cb, NULL);
   \textcolor{keywordflow}{if} (!ds\_it) printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_sel\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{char} *content = data;
   Elm_Object_Item *ds\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s with data: %s\(\backslash\)n"},
          elm\_object\_item\_text\_get(ds\_it), content);
\}

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

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;
   \textcolor{keywordtype}{char} label[32];
   \textcolor{keywordtype}{char} *content = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 32);

   snprintf(content, 32, \textcolor{stringliteral}{"Item content %i"}, counter);
   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ds\_it = elm\_diskselector\_item\_append(ds, label, NULL, \_sel\_data\_cb, content);
   \textcolor{keywordflow}{if} (!ds\_it)
     \{
        printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}
   elm\_object\_item\_del\_cb\_set(ds\_it, \_free\_data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_del\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   elm\_object\_item\_del(selected\_ds\_it);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_unselect\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   elm\_diskselector\_item\_selected\_set(selected\_ds\_it, EINA\_FALSE);
\}

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

   items = elm\_diskselector\_items\_get(ds);
   EINA\_LIST\_FOREACH(items, l, ds\_it)
     printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, elm\_object\_item\_text\_get(ds\_it));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_clear\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *ds = data;
   elm\_diskselector\_clear(ds);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_select\_first\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *first\_ds\_it;
   Evas\_Object *ds = data;

   first\_ds\_it = elm\_diskselector\_first\_item\_get(ds);
   \textcolor{keywordflow}{if} (first\_ds\_it)
     elm\_diskselector\_item\_selected\_set(first\_ds\_it, EINA\_TRUE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_select\_last\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *last\_ds\_it;
   Evas\_Object *ds = data;

   last\_ds\_it = elm\_diskselector\_last\_item\_get(ds);
   \textcolor{keywordflow}{if} (last\_ds\_it)
     elm\_diskselector\_item\_selected\_set(last\_ds\_it, EINA\_TRUE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_select\_next\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it, *next\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   \textcolor{keywordflow}{if} (!selected\_ds\_it) \textcolor{keywordflow}{return};

   next\_ds\_it = elm\_diskselector\_item\_next\_get(selected\_ds\_it);
   \textcolor{keywordflow}{if} (next\_ds\_it)
     elm\_diskselector\_item\_selected\_set(next\_ds\_it, EINA\_TRUE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_select\_prev\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it, *prev\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   \textcolor{keywordflow}{if} (!selected\_ds\_it) \textcolor{keywordflow}{return};

   prev\_ds\_it = elm\_diskselector\_item\_prev\_get(selected\_ds\_it);
   \textcolor{keywordflow}{if} (prev\_ds\_it)
     elm\_diskselector\_item\_selected\_set(prev\_ds\_it, EINA\_TRUE);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *bx, *hbx, *ds, *bt;

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

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

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

   ds = elm_diskselector_add(win);
   evas\_object\_size\_hint\_weight\_set(ds, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(ds, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_smart\_callback\_add(ds, \textcolor{stringliteral}{"selected"}, \_ds\_selected\_cb, NULL);
   elm\_box\_pack\_end(bx, ds);
   evas\_object\_show(ds);

   elm\_diskselector\_item\_append(ds, \textcolor{stringliteral}{"Item 0"}, NULL, NULL, NULL);
   elm\_diskselector\_item\_append(ds, \textcolor{stringliteral}{"Item 1"}, NULL, NULL, NULL);
   elm\_diskselector\_item\_append(ds, \textcolor{stringliteral}{"Item 2"}, NULL, NULL, NULL);

   hbx = elm_box_add(win);
   elm\_box\_horizontal\_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_box\_pack\_end(bx, hbx);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append with icon"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_ic\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append with selected function"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_func\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append with data"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_data\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   hbx = elm_box_add(win);
   elm\_box\_horizontal\_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_box\_pack\_end(bx, hbx);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Delete item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_del\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Unselect item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_unselect\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Print items"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_print\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Clear"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_clear\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   hbx = elm_box_add(win);
   elm\_box\_horizontal\_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_box\_pack\_end(bx, hbx);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(hbx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Select first item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_select\_first\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Select last item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_select\_last\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Select next item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_select\_next\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Select previous item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_select\_prev\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

   evas\_object\_show(win);

   elm_run();

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