2 * gcc -o entry_example entry_example.c `pkg-config --cflags --libs elementary`
4 #include <Elementary.h>
6 # include "elementary_config.h"
8 # define __UNUSED__ __attribute__((unused))
14 Evas_Object *edit_buffer;
22 Evas_Object *settings;
34 _edit_buffer_insert(Evas_Object *e, const char *text)
36 elm_entry_entry_insert(e, text);
41 _it_sel_cb(void *data, Evas_Object *obj __UNUSED__, void *event)
43 App_Inwin_Data *aid = data;
44 Elm_Gengrid_Item *it = event;
46 aid->emo = elm_gengrid_item_data_get(it);
48 elm_pager_content_promote(aid->pager, aid->settings);
52 _emo_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
58 _emo_content_get(void *data, Evas_Object *obj, const char *part)
62 if (strcmp(part, "elm.swallow.icon"))
64 o = elm_layout_add(obj);
65 elm_layout_theme_set(o, "entry/emoticon", data, "default");
70 _emo_del(void *data, Evas_Object *obj __UNUSED__)
76 _page_grid_add(Evas_Object *parent, App_Inwin_Data *aid)
81 static Elm_Gengrid_Item_Class it_class = {
91 theme = elm_theme_list_item_path_get("default", NULL);
92 if (!theme) return NULL;
93 emos = edje_file_collection_list(theme);
95 if (!emos) return NULL;
97 grid = elm_gengrid_add(parent);
98 elm_gengrid_item_size_set(grid, 64, 80);
99 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
102 EINA_LIST_FOREACH(emos, it, emo)
106 if (strncmp(emo, "elm/entry/emoticon/", 19))
108 sscanf(emo, "elm/entry/emoticon/%[^/]/default", name);
109 elm_gengrid_item_append(grid, &it_class, strdup(name), _it_sel_cb, aid);
111 edje_file_collection_list_free(emos);
117 _btn_insert_cb(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
119 App_Inwin_Data *aid = data;
120 const char *size[] = {
125 const char *vsize[] = {
131 snprintf(buf, sizeof(buf), "<item %s=%dx%d vsize=%s href=emoticon/%s>"
132 "</item>", size[aid->size], aid->width, aid->height,
133 vsize[aid->vsize], aid->emo);
134 _edit_buffer_insert(aid->ad->edit_buffer, buf);
136 evas_object_del(aid->inwin);
140 _width_changed_cb(void *data, Evas_Object *obj, void *event __UNUSED__)
142 App_Inwin_Data *aid = data;
144 aid->width = atoi(elm_object_text_get(obj));
148 _height_changed_cb(void *data, Evas_Object *obj, void *event __UNUSED__)
150 App_Inwin_Data *aid = data;
152 aid->height = atoi(elm_object_text_get(obj));
156 _page_settings_add(Evas_Object *parent, App_Inwin_Data *aid)
158 Evas_Object *box, *sizeopts, *box2, *sizebox, *vsizebox,
159 *rsize, *rabsize, *rrelsize, *rvfull, *rvascent,
160 *fwidth, *ewidth, *fheight, *eheight,
163 static Elm_Entry_Filter_Accept_Set accept_set = {
164 .accepted = "0123456789",
167 static Elm_Entry_Filter_Limit_Size limit_size = {
172 box = elm_box_add(parent);
173 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
176 sizeopts = elm_frame_add(parent);
177 elm_object_text_set(sizeopts, "Size");
178 evas_object_size_hint_weight_set(sizeopts, EVAS_HINT_EXPAND, 0.0);
179 evas_object_size_hint_align_set(sizeopts, EVAS_HINT_FILL, EVAS_HINT_FILL);
180 elm_box_pack_end(box, sizeopts);
181 evas_object_show(sizeopts);
183 box2 = elm_box_add(parent);
184 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
185 evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
186 elm_object_content_set(sizeopts, box2);
187 evas_object_show(box2);
189 sizebox = elm_box_add(parent);
190 elm_box_horizontal_set(sizebox, EINA_TRUE);
191 evas_object_size_hint_weight_set(sizebox, EVAS_HINT_EXPAND,
193 evas_object_size_hint_align_set(sizebox, EVAS_HINT_FILL, EVAS_HINT_FILL);
194 elm_box_pack_end(box2, sizebox);
195 evas_object_show(sizebox);
197 rsize = elm_radio_add(parent);
198 elm_object_text_set(rsize, "Scale adjusted (size)");
199 elm_radio_state_value_set(rsize, 0);
200 elm_radio_value_pointer_set(rsize, &aid->size);
201 elm_box_pack_end(sizebox, rsize);
202 evas_object_show(rsize);
204 rabsize = elm_radio_add(parent);
205 elm_object_text_set(rabsize, "Absolute size (absize)");
206 elm_radio_state_value_set(rabsize, 1);
207 elm_radio_value_pointer_set(rabsize, &aid->size);
208 elm_radio_group_add(rabsize, rsize);
209 elm_box_pack_end(sizebox, rabsize);
210 evas_object_show(rabsize);
212 rrelsize = elm_radio_add(parent);
213 elm_object_text_set(rrelsize, "Relative to line (relsize)");
214 elm_radio_state_value_set(rrelsize, 2);
215 elm_radio_value_pointer_set(rrelsize, &aid->size);
216 elm_radio_group_add(rrelsize, rsize);
217 elm_box_pack_end(sizebox, rrelsize);
218 evas_object_show(rrelsize);
220 vsizebox = elm_box_add(parent);
221 elm_box_horizontal_set(vsizebox, EINA_TRUE);
222 evas_object_size_hint_weight_set(vsizebox, EVAS_HINT_EXPAND,
224 evas_object_size_hint_align_set(vsizebox, EVAS_HINT_FILL, EVAS_HINT_FILL);
225 elm_box_pack_end(box2, vsizebox);
226 evas_object_show(vsizebox);
228 rvfull = elm_radio_add(parent);
229 elm_object_text_set(rvfull, "Full height (vsize=full)");
230 elm_radio_state_value_set(rvfull, 0);
231 elm_radio_value_pointer_set(rvfull, &aid->vsize);
232 elm_box_pack_end(vsizebox, rvfull);
233 evas_object_show(rvfull);
235 rvascent = elm_radio_add(parent);
236 elm_object_text_set(rvascent, "Ascent only (vsize=ascent)");
237 elm_radio_state_value_set(rvascent, 1);
238 elm_radio_value_pointer_set(rvascent, &aid->vsize);
239 elm_radio_group_add(rvascent, rvfull);
240 elm_box_pack_end(vsizebox, rvascent);
241 evas_object_show(rvascent);
243 fwidth = elm_frame_add(parent);
244 elm_object_text_set(fwidth, "Width");
245 evas_object_size_hint_weight_set(fwidth, EVAS_HINT_EXPAND, 0.0);
246 evas_object_size_hint_align_set(fwidth, EVAS_HINT_FILL, EVAS_HINT_FILL);
247 elm_box_pack_end(box2, fwidth);
248 evas_object_show(fwidth);
250 snprintf(buf, sizeof(buf), "%d", aid->width);
251 ewidth = elm_entry_add(parent);
252 elm_entry_single_line_set(ewidth, EINA_TRUE);
253 elm_entry_text_filter_append(ewidth, elm_entry_filter_accept_set,
255 elm_entry_text_filter_append(ewidth, elm_entry_filter_limit_size,
257 elm_object_text_set(ewidth, buf);
258 evas_object_size_hint_weight_set(ewidth, EVAS_HINT_EXPAND, 0.0);
259 evas_object_size_hint_align_set(ewidth, EVAS_HINT_FILL, EVAS_HINT_FILL);
260 elm_object_content_set(fwidth, ewidth);
261 evas_object_show(ewidth);
263 evas_object_smart_callback_add(ewidth, "changed", _width_changed_cb, aid);
265 fheight = elm_frame_add(parent);
266 elm_object_text_set(fheight, "Height");
267 evas_object_size_hint_weight_set(fheight, EVAS_HINT_EXPAND, 0.0);
268 evas_object_size_hint_align_set(fheight, EVAS_HINT_FILL, EVAS_HINT_FILL);
269 elm_box_pack_end(box2, fheight);
270 evas_object_show(fheight);
272 snprintf(buf, sizeof(buf), "%d", aid->height);
273 eheight = elm_entry_add(parent);
274 elm_entry_single_line_set(eheight, EINA_TRUE);
275 elm_entry_text_filter_append(eheight, elm_entry_filter_accept_set,
277 elm_entry_text_filter_append(eheight, elm_entry_filter_limit_size,
279 elm_object_text_set(eheight, buf);
280 evas_object_size_hint_weight_set(eheight, EVAS_HINT_EXPAND, 0.0);
281 evas_object_size_hint_align_set(eheight, EVAS_HINT_FILL, EVAS_HINT_FILL);
282 elm_object_content_set(fheight, eheight);
283 evas_object_show(eheight);
285 evas_object_smart_callback_add(eheight, "changed", _height_changed_cb, aid);
287 binsert = elm_button_add(parent);
288 elm_object_text_set(binsert, "Insert");
289 elm_box_pack_end(box, binsert);
290 evas_object_show(binsert);
292 evas_object_smart_callback_add(binsert, "clicked", _btn_insert_cb, aid);
298 _insert_cancel_cb(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
300 App_Inwin_Data *aid = data;
302 evas_object_del(aid->inwin);
306 _inwin_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
312 _image_insert_cb(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
316 Evas_Object *inwin, *box, *box2, *pager, *o;
318 aid = calloc(1, sizeof(App_Inwin_Data));
327 inwin = elm_win_inwin_add(ad->win);
328 evas_object_size_hint_weight_set(inwin, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
329 evas_object_size_hint_align_set(inwin, EVAS_HINT_FILL, EVAS_HINT_FILL);
330 evas_object_show(inwin);
332 evas_object_event_callback_add(inwin, EVAS_CALLBACK_DEL, _inwin_del_cb,
335 box = elm_box_add(ad->win);
336 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
337 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
338 elm_win_inwin_content_set(inwin, box);
339 evas_object_show(box);
341 pager = elm_pager_add(ad->win);
342 evas_object_size_hint_weight_set(pager, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
343 evas_object_size_hint_align_set(pager, EVAS_HINT_FILL, EVAS_HINT_FILL);
344 elm_box_pack_end(box, pager);
345 evas_object_show(pager);
347 o = _page_grid_add(ad->win, aid);
348 elm_pager_content_push(pager, o);
351 o = _page_settings_add(ad->win, aid);
352 elm_pager_content_push(pager, o);
355 elm_pager_content_promote(pager, aid->grid);
357 box2 = elm_box_add(ad->win);
358 elm_box_horizontal_set(box2, EINA_TRUE);
359 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
360 evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
361 elm_box_pack_end(box, box2);
362 evas_object_show(box2);
364 o = elm_button_add(ad->win);
365 elm_object_text_set(o, "Cancel");
366 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
367 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
368 elm_box_pack_end(box2, o);
371 evas_object_smart_callback_add(o, "clicked", _insert_cancel_cb, aid);
378 _format_change_cb(void *data, Evas_Object *obj, void *event __UNUSED__)
381 char fmt_open[5], fmt_close[6];
385 const char *ptr, *what;
386 Eina_Strbuf *buf = NULL;
388 sel = elm_object_text_get(obj);
389 snprintf(fmt_open, sizeof(fmt_open), "<%s>", sel);
390 snprintf(fmt_close, sizeof(fmt_close), "</%s>", sel);
392 buf = eina_strbuf_new();
394 cursor = elm_entry_cursor_pos_get(ad->edit_buffer);
395 elm_entry_cursor_begin_set(ad->edit_buffer);
396 elm_entry_cursor_selection_begin(ad->edit_buffer);
397 elm_entry_cursor_pos_set(ad->edit_buffer, cursor);
398 elm_entry_cursor_selection_end(ad->edit_buffer);
399 sel = elm_entry_selection_get(ad->edit_buffer);
402 eina_strbuf_append(buf, fmt_open);
407 while ((s = strstr(ptr, what)))
409 ptr = s + strlen(what);
410 if (what == fmt_open) what = fmt_close;
411 else what = fmt_open;
413 eina_strbuf_append(buf, what);
414 if (what == fmt_close)
416 elm_entry_cursor_selection_begin(ad->edit_buffer);
417 elm_entry_cursor_end_set(ad->edit_buffer);
418 elm_entry_cursor_selection_end(ad->edit_buffer);
419 sel = elm_entry_selection_get(ad->edit_buffer);
422 Eina_Strbuf *buf2 = eina_strbuf_new();
423 eina_strbuf_append(buf2, sel);
424 eina_strbuf_replace_first(buf2, fmt_close, "");
425 elm_entry_entry_insert(ad->edit_buffer,
426 eina_strbuf_string_get(buf2));
427 eina_strbuf_free(buf2);
430 elm_entry_select_none(ad->edit_buffer);
431 elm_entry_cursor_pos_set(ad->edit_buffer, cursor);
434 _edit_buffer_insert(ad->edit_buffer, eina_strbuf_string_get(buf));
435 eina_strbuf_free(buf);
439 _autosave_change_cb(void *data, Evas_Object *obj, void *event __UNUSED__)
442 Eina_Bool state = elm_check_state_get(obj);
444 elm_entry_autosave_set(ad->edit_buffer, state);
445 if (state) elm_entry_file_save(ad->edit_buffer);
449 _edit_dblclick_cb(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
453 current_cursor = elm_entry_cursor_pos_get(obj);
455 while (elm_entry_cursor_prev(obj))
458 if (elm_entry_cursor_is_visible_format_get(obj))
460 content = elm_entry_cursor_content_get(obj);
461 if (content && (content[0] == ' '))
465 if (current_cursor == elm_entry_cursor_pos_get(obj))
468 elm_entry_cursor_next(obj);
469 elm_entry_cursor_selection_begin(obj);
470 elm_entry_cursor_pos_set(obj, current_cursor);
471 while (elm_entry_cursor_next(obj))
474 if (elm_entry_cursor_is_visible_format_get(obj))
476 content = elm_entry_cursor_content_get(obj);
477 if (content && (content[0] == ' '))
480 elm_entry_cursor_selection_end(obj);
484 _edit_tplclick_cb(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
486 elm_entry_cursor_line_begin_set(obj);
487 elm_entry_cursor_selection_begin(obj);
488 elm_entry_cursor_line_end_set(obj);
489 elm_entry_cursor_selection_end(obj);
493 _win_del_cb(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
495 evas_object_del(obj);
500 elm_main(int argc __UNUSED__, char *argv[] __UNUSED__)
502 Evas_Object *win, *bg, *box, *tb, *en, *o, *icon;
505 memset(&app, 0, sizeof(app));
507 win = elm_win_add(NULL, "entry-example", ELM_WIN_BASIC);
508 elm_win_title_set(win, "Emacs Lite");
509 evas_object_show(win);
511 bg = elm_bg_add(win);
512 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
513 elm_win_resize_object_add(win, bg);
514 evas_object_show(bg);
516 box = elm_box_add(win);
517 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
518 elm_win_resize_object_add(win, box);
519 evas_object_show(box);
521 tb = elm_box_add(win);
522 elm_box_horizontal_set(tb, EINA_TRUE);
523 evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0);
524 evas_object_size_hint_weight_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
525 elm_box_pack_end(box, tb);
526 evas_object_show(tb);
528 o = elm_check_add(win);
529 elm_check_state_set(o, EINA_FALSE);
530 elm_object_text_set(o, "Autosave");
531 elm_box_pack_end(tb, o);
534 evas_object_smart_callback_add(o, "changed", _autosave_change_cb, &app);
536 o = elm_button_add(win);
537 elm_object_text_set(o, "b");
538 elm_box_pack_end(tb, o);
541 evas_object_smart_callback_add(o, "clicked", _format_change_cb, &app);
543 o = elm_button_add(win);
544 elm_object_text_set(o, "em");
545 elm_box_pack_end(tb, o);
548 evas_object_smart_callback_add(o, "clicked", _format_change_cb, &app);
550 o = elm_button_add(win);
551 elm_box_pack_end(tb, o);
554 icon = elm_layout_add(win);
555 elm_layout_theme_set(icon, "entry", "emoticon/haha", "default");
556 elm_object_part_content_set(o, "icon", icon);
558 evas_object_smart_callback_add(o, "clicked", _image_insert_cb, &app);
560 en = elm_entry_add(win);
561 elm_entry_autosave_set(en, EINA_FALSE);
562 elm_entry_file_set(en, "/tmp/da_test.txt", ELM_TEXT_FORMAT_MARKUP_UTF8);
563 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
564 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
565 elm_box_pack_end(box, en);
566 evas_object_show(en);
569 app.edit_buffer = en;
571 evas_object_smart_callback_add(en, "clicked,double", _edit_dblclick_cb,
573 evas_object_smart_callback_add(en, "clicked,triple", _edit_tplclick_cb,
576 evas_object_smart_callback_add(win, "delete,request", _win_del_cb, &app);
578 elm_object_focus(app.edit_buffer);
580 evas_object_resize(win, 300, 780);