As a general overview of \hyperlink{group__Entry}{Entry} we are going to write an, albeit simple, functional editor.

Although intended to show how elm\-\_\-entry works, this example also makes extensive use of several other widgets. The full code can be found in \hyperlink{entry_example_8c-example}{entry\-\_\-example.c} and in the following lines we'll go through the parts especific to the \hyperlink{group__Entry}{Entry} widget.

The program itself is a simple editor, with a file already set to it, that can be set to autosave or not and allows insertion of emoticons and some formatted text. As of this writing, the capabilities of format edition in the entry are very limited, so a lot of manual work is required to change the current text.

In any case, the program allows some changes by using the buttons on the top of the window and returning focus back to the main entry afterwards.

 
\begin{DoxyImage}
\includegraphics{screenshots/entry_example}
\caption{width=}
\end{DoxyImage}


We'll begin by showing a few structures used throught the program. First, the application owns data that holds the main window and the main entry where the editting happens. Then, an auxiliar structure we'll use later when inserting icons in our text.  
\begin{DoxyCodeInclude}
\textcolor{keyword}{typedef} \textcolor{keyword}{struct}
\{
   Evas\_Object *win;
   Evas\_Object *edit\_buffer;
\} App\_Data;

\textcolor{keyword}{typedef} \textcolor{keyword}{struct}
\{
   Evas\_Object *inwin;
   Evas\_Object *naviframe;
   Evas\_Object *grid;
   Evas\_Object *settings;

   \textcolor{keywordtype}{int} size;
   \textcolor{keywordtype}{int} vsize;
   \textcolor{keywordtype}{int} width, height;

   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *emo;

   App\_Data *ad;
\} App\_Inwin\_Data;

\end{DoxyCodeInclude}


A little convenience function will insert whatever text we need in the buffer at the current cursor's position and set focus back to this entry. This is done mostly because clicking on any button will make them steal focus, which makes writing text more cumbersome. 
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_edit\_buffer\_insert(Evas\_Object *e, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *text)
\{
   elm_entry_entry_insert(e, text);
   elm_object_focus_set(e, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


One of the buttons on the top will trigger an \hyperlink{group__Inwin}{Inwin} to open and show us several icons we can insert into the text. We'll jump over most of these functions, but when all the options are chosen, we insert the special markup text that will show the chosen icon in place. 
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_insert\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   App\_Inwin\_Data *aid = data;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *size[] = \{
        \textcolor{stringliteral}{"size"},
        \textcolor{stringliteral}{"absize"},
        \textcolor{stringliteral}{"relsize"}
   \};
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *vsize[] = \{
        \textcolor{stringliteral}{"full"},
        \textcolor{stringliteral}{"ascent"}
   \};
   \textcolor{keywordtype}{char} buf[512];

   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"<item %s=%dx%d vsize=%s href=emoticon/%s>"}
            \textcolor{stringliteral}{"</item>"}, size[aid->size], aid->width, aid->height,
            vsize[aid->vsize], aid->emo);
   \_edit\_buffer\_insert(aid->ad->edit\_buffer, buf);

   evas\_object\_del(aid->inwin);
\}

\end{DoxyCodeInclude}


As can be seen in that function, the program lets us add icons to our entry using all the possible configurations for them. That should help to clarify how the different combinations work out by actually seeing them in action.

The same popup window has a page to set the settings of the chosen icon, that is, the size and how the item will be placed within the line.

The size is done with two entries, limitted to accept numbers and a fixed size of characters. Changing the value in this entries will update the icon size in our struct as seen in the next two callbacks. 
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_width\_changed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   App\_Inwin\_Data *aid = data;

   aid->width = atoi(elm\_object\_text\_get(obj));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_height\_changed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   App\_Inwin\_Data *aid = data;

   aid->height = atoi(elm\_object\_text\_get(obj));
\}

\end{DoxyCodeInclude}


The rest of the options are handled with radio buttons, since only one type of size can be used ({\ttfamily size}, {\ttfamily absize} or {\ttfamily relsize}) and for the vertical sizing it needs to choose between {\ttfamily ascent} and {\ttfamily full}. Depending on which is chosen, the {\ttfamily item} tag is formed accordingly as seen before. 
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} Evas\_Object *
\_page\_settings\_add(Evas\_Object *parent, App\_Inwin\_Data *aid)
\{
   Evas\_Object *box, *sizeopts, *box2, *sizebox, *vsizebox,
               *rsize, *rabsize, *rrelsize, *rvfull, *rvascent,
               *fwidth, *ewidth, *fheight, *eheight,
               *binsert;
   \textcolor{keywordtype}{char} buf[100];
   \textcolor{keyword}{static} Elm_Entry_Filter_Accept_Set accept\_set = \{
        .accepted = \textcolor{stringliteral}{"0123456789"},
        .rejected = NULL
   \};
   \textcolor{keyword}{static} Elm_Entry_Filter_Limit_Size limit\_size = \{
        .max_char_count = 5,
        .max\_byte\_count = 0
   \};

   box = elm_box_add(parent);
   evas\_object\_size\_hint\_weight\_set(box, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(box, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);

   sizeopts = elm_frame_add(parent);
   elm\_object\_text\_set(sizeopts, \textcolor{stringliteral}{"Size"});
   evas\_object\_size\_hint\_weight\_set(sizeopts, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(sizeopts, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box, sizeopts);
   evas\_object\_show(sizeopts);

   box2 = elm_box_add(parent);
   evas\_object\_size\_hint\_weight\_set(box2, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(box2, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_object\_content\_set(sizeopts, box2);
   evas\_object\_show(box2);

   sizebox = elm_box_add(parent);
   elm_box_horizontal_set(sizebox, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(sizebox, EVAS\_HINT\_EXPAND,
                                    EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(sizebox, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box2, sizebox);
   evas\_object\_show(sizebox);

   rsize = elm_radio_add(parent);
   elm\_object\_text\_set(rsize, \textcolor{stringliteral}{"Scale adjusted (size)"});
   elm_radio_state_value_set(rsize, 0);
   elm_radio_value_pointer_set(rsize, &aid->size);
   elm_box_pack_end(sizebox, rsize);
   evas\_object\_show(rsize);

   rabsize = elm_radio_add(parent);
   elm\_object\_text\_set(rabsize, \textcolor{stringliteral}{"Absolute size (absize)"});
   elm_radio_state_value_set(rabsize, 1);
   elm_radio_value_pointer_set(rabsize, &aid->size);
   elm_radio_group_add(rabsize, rsize);
   elm_box_pack_end(sizebox, rabsize);
   evas\_object\_show(rabsize);

   rrelsize = elm_radio_add(parent);
   elm\_object\_text\_set(rrelsize, \textcolor{stringliteral}{"Relative to line (relsize)"});
   elm_radio_state_value_set(rrelsize, 2);
   elm_radio_value_pointer_set(rrelsize, &aid->size);
   elm_radio_group_add(rrelsize, rsize);
   elm_box_pack_end(sizebox, rrelsize);
   evas\_object\_show(rrelsize);

   vsizebox = elm_box_add(parent);
   elm_box_horizontal_set(vsizebox, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(vsizebox, EVAS\_HINT\_EXPAND,
                                    EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(vsizebox, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box2, vsizebox);
   evas\_object\_show(vsizebox);

   rvfull = elm_radio_add(parent);
   elm\_object\_text\_set(rvfull, \textcolor{stringliteral}{"Full height (vsize=full)"});
   elm_radio_state_value_set(rvfull, 0);
   elm_radio_value_pointer_set(rvfull, &aid->vsize);
   elm_box_pack_end(vsizebox, rvfull);
   evas\_object\_show(rvfull);

   rvascent = elm_radio_add(parent);
   elm\_object\_text\_set(rvascent, \textcolor{stringliteral}{"Ascent only (vsize=ascent)"});
   elm_radio_state_value_set(rvascent, 1);
   elm_radio_value_pointer_set(rvascent, &aid->vsize);
   elm_radio_group_add(rvascent, rvfull);
   elm_box_pack_end(vsizebox, rvascent);
   evas\_object\_show(rvascent);

\end{DoxyCodeInclude}


The first of our entries is here. There's something worth mentioning about the way we'll create this one. Normally, any entry regardless of whether is single line or not, will be set to scrollable, but in this case, since we are limitting how many characters can fit in them and we know we don't need scrolling, we are not setting this flag. This makes the entry have virtually no appearance on screen, other than its text. This is because an entry is just that, a box that holds text, and in order to have some frame around it or a background color, another widget needs to provide this. When an entry is scrollable, the same scroller used internally does this. We are using \hyperlink{group__Frame}{frames} here to provide some decoration around, then creating our entries, set them to single line, add our two filters and the callback for when their value change. 
\begin{DoxyCodeInclude}

   fwidth = elm_frame_add(parent);
   elm\_object\_text\_set(fwidth, \textcolor{stringliteral}{"Width"});
   evas\_object\_size\_hint\_weight\_set(fwidth, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(fwidth, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box2, fwidth);
   evas\_object\_show(fwidth);

   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%d"}, aid->width);
   ewidth = elm_entry_add(parent);
   elm_entry_single_line_set(ewidth, EINA\_TRUE);
   elm_entry_markup_filter_append(ewidth, elm_entry_filter_accept_set,
                                  &accept\_set);
   elm_entry_markup_filter_append(ewidth, elm_entry_filter_limit_size,
                                  &limit\_size);
   elm\_object\_text\_set(ewidth, buf);
   evas\_object\_size\_hint\_weight\_set(ewidth, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(ewidth, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_object\_content\_set(fwidth, ewidth);
   evas\_object\_show(ewidth);

   evas\_object\_smart\_callback\_add(ewidth, \textcolor{stringliteral}{"changed"}, \_width\_changed\_cb, aid);

   fheight = elm_frame_add(parent);
   elm\_object\_text\_set(fheight, \textcolor{stringliteral}{"Height"});
   evas\_object\_size\_hint\_weight\_set(fheight, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(fheight, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box2, fheight);
   evas\_object\_show(fheight);

   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%d"}, aid->height);
   eheight = elm_entry_add(parent);
   elm_entry_single_line_set(eheight, EINA\_TRUE);
   elm_entry_markup_filter_append(eheight, elm_entry_filter_accept_set,
                                  &accept\_set);
   elm_entry_markup_filter_append(eheight, elm_entry_filter_limit_size,
                                  &limit\_size);
   elm\_object\_text\_set(eheight, buf);
   evas\_object\_size\_hint\_weight\_set(eheight, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(eheight, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_object\_content\_set(fheight, eheight);
   evas\_object\_show(eheight);

   evas\_object\_smart\_callback\_add(eheight, \textcolor{stringliteral}{"changed"}, \_height\_changed\_cb, aid);

\end{DoxyCodeInclude}


This function ends with the button that will finally call the item into our editting string. 
\begin{DoxyCodeInclude}

   binsert = elm_button_add(parent);
   elm\_object\_text\_set(binsert, \textcolor{stringliteral}{"Insert"});
   elm_box_pack_end(box, binsert);
   evas\_object\_show(binsert);

   evas\_object\_smart\_callback\_add(binsert, \textcolor{stringliteral}{"clicked"}, \_btn\_insert\_cb, aid);

   \textcolor{keywordflow}{return} box;
\}

\end{DoxyCodeInclude}


Then we get to the format edition. Here we can add the {\ttfamily bold} and {\ttfamily emphasis} tags to parts of our text. There's a lot of manual work to know what to do here, since we are not implementing an entire state manager and the entry itself doesn't, yet, support all the needed capabilities to make this simpler. We begin by getting the format we are using in our function from the button pressed. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Next we need to find out if we need to insert an opening or a closing tag. For this, we store the current cursor position and create a selection from this point until the beginning of our text, and then get the selected text to look for any existing format tags in it. This is currently the only way in which we can find out what formats is being used in the entry. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Once we know what tag to insert, we need a second check in the case it was a closing tag. This is because any other closing tag that comes after would be left dangling alone, so we need to remove it to keep the text consistent. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
 Finally, we clear our fake selections and return the cursor back to the position it had at first, since there is where we want to insert our format. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And finish by calling our convenience function from before, to insert the text at the current cursor and give focus back to the entry. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


A checkbox on the top of our program tells us if the text we are editing will autosave or not. In it's {\ttfamily \char`\"{}changed\char`\"{}} callback we get the value from the checkbox and call the \hyperlink{group__Entry_ga505c45571480c28b2697f830c15a6f04}{elm\-\_\-entry\-\_\-autosave\-\_\-set()} function with it. If autosave is set, we also call \hyperlink{group__Entry_ga794aa256197588a0aa8f67f024f949ba}{elm\-\_\-entry\-\_\-file\-\_\-save()}. This is so the internal timer used to periodically store to disk our changes is started. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Two more functions to show some cursor playing. Whenever we double click anywhere on our entry, we'll find what word is the cursor placed at and select it. Likewise, for triple clicking, we select the entire line. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And finally, the main window of the program contains the entry where we do all the edition and some helping widgets to change format, add icons or change the autosave flag. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And the main entry of the program. Set to scroll, by default we disable autosave and we'll begin with a file set to it because no file selector is being used here. The file is loaded with \#\-E\-L\-M\-\_\-\-T\-E\-X\-T\-\_\-\-F\-O\-R\-M\-A\-T\-\_\-\-M\-A\-R\-K\-U\-P\-\_\-\-U\-T\-F8 so that any format contained in it is interpreted, otherwise the entry would load it as just text, escaping any tags found and no format or icons would be shown. Then we connect to the double and triple click signals and set focus on the entry so we can start typing right away. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
 