

This example shows how to create a menu with regular items, object items, submenus and how to delete items from a menu. The full source for this example is \mbox{\hyperlink{menu_example_01_8c-example}{menu\+\_\+example\+\_\+01.c}}.

We\textquotesingle{}ll start looking at the menu creation and how to create a very simple item\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   menu = \mbox{\hyperlink{group__Elm__Menu_gaaeecc450db4e359289c16c41489ca94b}{elm\_menu\_add}}(win);}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, NULL, NULL, \textcolor{stringliteral}{"{}first item"{}}, NULL, NULL);}

\end{DoxyCodeInclude}
 For our next item we are going to add an icon\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   menu\_it = elm\_menu\_item\_add(menu, NULL, \textcolor{stringliteral}{"{}mail-\/reply-\/all"{}}, \textcolor{stringliteral}{"{}second item"{}}, NULL, NULL);}

\end{DoxyCodeInclude}
 Now we are going to add more items, but these icons are going to have a parent, which will put them in a sub-\/menu. First just another item with an icon\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, menu\_it, \textcolor{stringliteral}{"{}object-\/rotate-\/left"{}}, \textcolor{stringliteral}{"{}menu 1"{}}, NULL, NULL);}

\end{DoxyCodeInclude}
 Next we are going to add a button to our menu(any elm widget can be added to a menu)\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   button = \mbox{\hyperlink{group__Elm__Button_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(button, \textcolor{stringliteral}{"{}button -\/ delete items"{}});}
\DoxyCodeLine{   menu\_it1 = elm\_menu\_item\_add(menu, menu\_it, NULL, NULL, NULL, NULL);}

\end{DoxyCodeInclude}
 We are also going to have the button delete the first item of our sub-\/menu when clicked\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   elm\_object\_item\_content\_set(menu\_it1, button);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(button, \textcolor{stringliteral}{"{}clicked"{}}, \_del\_it, menu);}

\end{DoxyCodeInclude}
 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_del\_it(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *l;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *menu\_it = elm\_menu\_first\_item\_get(data);}
\DoxyCodeLine{   menu\_it = elm\_menu\_item\_next\_get(menu\_it);}
\DoxyCodeLine{   l = elm\_menu\_item\_subitems\_get(menu\_it);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gad1b5a0d41fa322b28000a290154ec3a4}{elm\_object\_item\_del}}(\mbox{\hyperlink{group__Eina__List__Group_gaec845f0bfb16a14e8d7f0cd508ca7e9c}{eina\_list\_data\_get}}(l));}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 We now add a separator and three more regular items\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_show(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}} *e \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Evas__Event__Mouse__Down}{Evas\_Event\_Mouse\_Down}} *ev = event\_info;}
\DoxyCodeLine{   elm\_menu\_move(data, ev-\/>\mbox{\hyperlink{struct__Evas__Event__Mouse__Down_adcaa4cd5eadd8c04cc5510a5b2514eb5}{canvas}}.\mbox{\hyperlink{struct__Evas__Coord__Point_ad809771faf3700a1492e4465336e6b1e}{x}}, ev-\/>\mbox{\hyperlink{struct__Evas__Event__Mouse__Down_adcaa4cd5eadd8c04cc5510a5b2514eb5}{canvas}}.\mbox{\hyperlink{struct__Evas__Coord__Point_ad7450d6ad43e6a7394af6807721144f7}{y}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(data);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{EAPI\_MAIN \textcolor{keywordtype}{int}}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int} argc \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{char} **argv \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *win, *menu, *button, *rect;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *menu\_it, *menu\_it1;}
\DoxyCodeLine{}
\DoxyCodeLine{   win = \mbox{\hyperlink{group__Elm__Win__Group_gac75d7752662fab73d6420706ce5be996}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"{}menu"{}}, \textcolor{stringliteral}{"{}Menu"{}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win__Group_ga9a16a2f8c9fd5b6e9203ed9dcb53ea8b}{elm\_win\_autodel\_set}}(win, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}}, \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{}
\DoxyCodeLine{   rect = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(\mbox{\hyperlink{group__Evas__Object__Group_gae1058082dae7b97590c41f43405dfdbf}{evas\_object\_evas\_get}}(win));}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win__Group_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win, rect);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga3014f5c9dfbdc6c7af41a27826e50e57}{evas\_object\_size\_hint\_min\_set}}(rect, 0, 0);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(rect, 0, 0, 0, 0);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(rect);}
\DoxyCodeLine{}
\DoxyCodeLine{   menu = \mbox{\hyperlink{group__Elm__Menu_gaaeecc450db4e359289c16c41489ca94b}{elm\_menu\_add}}(win);}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, NULL, NULL, \textcolor{stringliteral}{"{}first item"{}}, NULL, NULL);}
\DoxyCodeLine{   menu\_it = elm\_menu\_item\_add(menu, NULL, \textcolor{stringliteral}{"{}mail-\/reply-\/all"{}}, \textcolor{stringliteral}{"{}second item"{}}, NULL, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, menu\_it, \textcolor{stringliteral}{"{}object-\/rotate-\/left"{}}, \textcolor{stringliteral}{"{}menu 1"{}}, NULL, NULL);}

\end{DoxyCodeInclude}
 We now add another item, however this time it won\textquotesingle{}t go the sub-\/menu and it\textquotesingle{}ll be disabled\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   button = \mbox{\hyperlink{group__Elm__Button_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(button, \textcolor{stringliteral}{"{}button -\/ delete items"{}});}
\DoxyCodeLine{   menu\_it1 = elm\_menu\_item\_add(menu, menu\_it, NULL, NULL, NULL, NULL);}
\DoxyCodeLine{   elm\_object\_item\_content\_set(menu\_it1, button);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(button, \textcolor{stringliteral}{"{}clicked"{}}, \_del\_it, menu);}
\DoxyCodeLine{   elm\_menu\_item\_separator\_add(menu, menu\_it);}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, menu\_it, NULL, \textcolor{stringliteral}{"{}third item"{}}, NULL, NULL);}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, menu\_it, NULL, \textcolor{stringliteral}{"{}fourth item"{}}, NULL, NULL);}
\DoxyCodeLine{   elm\_menu\_item\_add(menu, menu\_it, \textcolor{stringliteral}{"{}window-\/new"{}}, \textcolor{stringliteral}{"{}sub menu"{}}, NULL, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   menu\_it = elm\_menu\_item\_add(menu, NULL, NULL, \textcolor{stringliteral}{"{}third item"{}}, NULL, NULL);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga1d4c8d3c83ed9408eaa35d605adbd7d2}{elm\_object\_item\_disabled\_set}}(menu\_it, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}

\end{DoxyCodeInclude}
 To make sure that our menu is shown whenever the window is clicked(and where clicked) we use the following callback\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_del\_it(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *l;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *menu\_it = elm\_menu\_first\_item\_get(data);}
\DoxyCodeLine{   menu\_it = elm\_menu\_item\_next\_get(menu\_it);}
\DoxyCodeLine{   l = elm\_menu\_item\_subitems\_get(menu\_it);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gad1b5a0d41fa322b28000a290154ec3a4}{elm\_object\_item\_del}}(\mbox{\hyperlink{group__Eina__List__Group_gaec845f0bfb16a14e8d7f0cd508ca7e9c}{eina\_list\_data\_get}}(l));}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Our example will look like this\+:

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