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

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

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

\textcolor{keyword}{static} \textcolor{keywordtype}{int} list\_mouse\_down = 0;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_dismissed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   evas\_object\_del(obj);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_ctxpopup\_item\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   printf(\textcolor{stringliteral}{"ctxpopup item selected: %s\(\backslash\)n"}, elm\_object\_item\_text\_get(event\_info));
\}

Elm_Object_Item *item\_new(Evas\_Object *ctxpopup, \textcolor{keyword}{const} \textcolor{keywordtype}{char} * label, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *icon)
\{
   Evas\_Object *ic = elm_icon_add(ctxpopup);
   elm_icon_standard_set(ic, icon);
   elm_image_resizable_set(ic, EINA\_FALSE, EINA\_FALSE);
   \textcolor{keywordflow}{return} elm_ctxpopup_item_append(ctxpopup, label, ic, \_ctxpopup\_item\_cb, NULL);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_list\_item\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *ctxpopup;
   Elm_Object_Item *it;
   Evas\_Coord x,y;

   \textcolor{keywordflow}{if} (list\_mouse\_down > 0) \textcolor{keywordflow}{return};

   ctxpopup = elm_ctxpopup_add(obj);
   evas\_object\_smart\_callback\_add(ctxpopup, \textcolor{stringliteral}{"dismissed"}, \_dismissed\_cb, NULL);

   item\_new(ctxpopup, \textcolor{stringliteral}{"Go to home folder"}, \textcolor{stringliteral}{"home"});
   item\_new(ctxpopup, \textcolor{stringliteral}{"Save file"}, \textcolor{stringliteral}{"file"});
   item\_new(ctxpopup, \textcolor{stringliteral}{"Delete file"}, \textcolor{stringliteral}{"delete"});
   it = item\_new(ctxpopup, \textcolor{stringliteral}{"Navigate to folder"}, \textcolor{stringliteral}{"folder"});
   elm\_object\_item\_disabled\_set(it, EINA\_TRUE);
   item\_new(ctxpopup, \textcolor{stringliteral}{"Edit entry"}, \textcolor{stringliteral}{"edit"});
   it = item\_new(ctxpopup, \textcolor{stringliteral}{"Set date and time"}, \textcolor{stringliteral}{"clock"});
   elm\_object\_item\_disabled\_set(it, EINA\_TRUE);

   evas\_pointer\_canvas\_xy\_get(evas\_object\_evas\_get(obj), &x, &y);
   evas\_object\_move(ctxpopup, x, y);
   evas\_object\_show(ctxpopup);

   elm\_list\_item\_selected\_set(event\_info, EINA\_FALSE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_list\_item\_cb2(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *ctxpopup;
   Elm_Object_Item *it;
   Evas\_Coord x,y;

   \textcolor{keywordflow}{if} (list\_mouse\_down > 0) \textcolor{keywordflow}{return};

   ctxpopup = elm_ctxpopup_add(obj);
   evas\_object\_smart\_callback\_add(ctxpopup, \textcolor{stringliteral}{"dismissed"}, \_dismissed\_cb, NULL);
   elm_ctxpopup_horizontal_set(ctxpopup, EINA\_TRUE);

   item\_new(ctxpopup, NULL, \textcolor{stringliteral}{"home"});
   item\_new(ctxpopup, NULL, \textcolor{stringliteral}{"file"});
   item\_new(ctxpopup, NULL, \textcolor{stringliteral}{"delete"});
   item\_new(ctxpopup, NULL, \textcolor{stringliteral}{"folder"});
   it = item\_new(ctxpopup, NULL, \textcolor{stringliteral}{"edit"});
   elm\_object\_item\_disabled\_set(it, EINA\_TRUE);
   item\_new(ctxpopup, NULL, \textcolor{stringliteral}{"clock"});

   evas\_pointer\_canvas\_xy\_get(evas\_object\_evas\_get(obj), &x, &y);
   evas\_object\_move(ctxpopup, x, y);
   evas\_object\_show(ctxpopup);

   elm\_list\_item\_selected\_set(event\_info, EINA\_FALSE);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_list\_mouse\_down(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas *e EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED, \textcolor{keywordtype}{void} *
      event\_info EINA\_UNUSED)
\{
   list\_mouse\_down++;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_list\_mouse\_up(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas *e EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED, \textcolor{keywordtype}{void} *event\_info 
      EINA\_UNUSED)
\{
   list\_mouse\_down--;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_win\_del(\textcolor{keywordtype}{void} *data EINA\_UNUSED, Evas\_Object *obj EINA\_UNUSED, \textcolor{keywordtype}{void} *event\_info EINA\_UNUSED)
\{
   list\_mouse\_down = 0;
\}

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

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

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"Contextual Popup"}, \textcolor{stringliteral}{"Contextual Popup"});
   evas\_object\_smart\_callback\_add(win, \textcolor{stringliteral}{"delete,request"}, \_win\_del, NULL);
   elm_win_autodel_set(win, EINA\_TRUE);

   list = elm_list_add(win);
   evas\_object\_event\_callback\_add(list, EVAS\_CALLBACK\_MOUSE\_DOWN,
                                  \_list\_mouse\_down, NULL);
   evas\_object\_event\_callback\_add(list, EVAS\_CALLBACK\_MOUSE\_UP,
                                  \_list\_mouse\_up, NULL);
   evas\_object\_size\_hint\_weight\_set(list, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, list);
   elm_list_mode_set(list, ELM\_LIST\_COMPRESS);

   elm_list_item_append(list, \textcolor{stringliteral}{"Ctxpopup with icons and labels"}, NULL, NULL,
                        \_list\_item\_cb, NULL);
   elm_list_item_append(list, \textcolor{stringliteral}{"Ctxpopup with icons only"}, NULL, NULL,
                        \_list\_item\_cb2, NULL);
   evas\_object\_show(list);
   elm_list_go(list);

   evas\_object\_resize(win, 400, 400);
   evas\_object\_show(win);

   elm_run();

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