summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <hirt.danny@gmail.com>2017-11-09 17:56:41 +0200
committerDaniel Hirt <hirt.danny@gmail.com>2017-11-19 23:47:30 +0200
commit585ded649f3f94ea59b7b65a989059cd62921ac6 (patch)
tree3713aecdf11ba9af1c67c9eb0bcb56c4a0f24d77
parent38e2d267c7d72a53639221d64bf3c5d7646c6f37 (diff)
Ui text: add ability to set item providersdevs/herdsman/object_factory
Added API to set an item provider factory object. This is similar to the previous item providers that used callbacks. You instantiate a factory object and set it on the Ui.Text object. Each factory implements the "create" method from Efl.Canvas.Text.Factory. This also includes 2 public factories (Image and Emoticon), and one internal for Ui.Text as a fallback. The fallback provider can be disabled via API. See the added "Ui text factory" test in elementary_test for an example of usage. @feature
-rw-r--r--src/Makefile_Elementary.am6
-rw-r--r--src/bin/elementary/test.c2
-rw-r--r--src/bin/elementary/test_efl_ui_text.c201
-rw-r--r--src/lib/elementary/Elementary.h3
-rw-r--r--src/lib/elementary/efl_ui_text.c120
-rw-r--r--src/lib/elementary/efl_ui_text.eo49
-rw-r--r--src/lib/elementary/efl_ui_text_emoticon_item_factory.c52
-rw-r--r--src/lib/elementary/efl_ui_text_emoticon_item_factory.eo12
-rw-r--r--src/lib/elementary/efl_ui_text_fallback_item_factory.c62
-rw-r--r--src/lib/elementary/efl_ui_text_fallback_item_factory.eo16
-rw-r--r--src/lib/elementary/efl_ui_text_image_item_factory.c97
-rw-r--r--src/lib/elementary/efl_ui_text_image_item_factory.eo42
12 files changed, 543 insertions, 119 deletions
diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am
index 95d1cf8976..8e300b9add 100644
--- a/src/Makefile_Elementary.am
+++ b/src/Makefile_Elementary.am
@@ -33,6 +33,9 @@ elm_public_eolian_files = \
33 lib/elementary/efl_ui_text.eo \ 33 lib/elementary/efl_ui_text.eo \
34 lib/elementary/efl_ui_text_editable.eo \ 34 lib/elementary/efl_ui_text_editable.eo \
35 lib/elementary/efl_ui_text_async.eo \ 35 lib/elementary/efl_ui_text_async.eo \
36 lib/elementary/efl_ui_text_image_item_factory.eo \
37 lib/elementary/efl_ui_text_emoticon_item_factory.eo \
38 lib/elementary/efl_ui_text_fallback_item_factory.eo \
36 lib/elementary/efl_ui_textpath.eo \ 39 lib/elementary/efl_ui_textpath.eo \
37 lib/elementary/efl_ui_translatable.eo \ 40 lib/elementary/efl_ui_translatable.eo \
38 lib/elementary/efl_ui_clock.eo \ 41 lib/elementary/efl_ui_clock.eo \
@@ -689,6 +692,9 @@ lib_elementary_libelementary_la_SOURCES = \
689 lib/elementary/efl_ui_grid_static.c \ 692 lib/elementary/efl_ui_grid_static.c \
690 lib/elementary/efl_ui_grid_private.h \ 693 lib/elementary/efl_ui_grid_private.h \
691 lib/elementary/efl_ui_text.c \ 694 lib/elementary/efl_ui_text.c \
695 lib/elementary/efl_ui_text_emoticon_item_factory.c \
696 lib/elementary/efl_ui_text_image_item_factory.c \
697 lib/elementary/efl_ui_text_fallback_item_factory.c \
692 lib/elementary/efl_ui_clock.c \ 698 lib/elementary/efl_ui_clock.c \
693 lib/elementary/efl_ui_clock_private.h \ 699 lib/elementary/efl_ui_clock_private.h \
694 lib/elementary/efl_ui_image_factory.c \ 700 lib/elementary/efl_ui_image_factory.c \
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index 57b1916d53..0d30541c46 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -316,6 +316,7 @@ void test_code_diff_inline(void *data, Evas_Object *obj, void *event_info);
316void test_efl_ui_text(void *data, Evas_Object *obj, void *event_info); 316void test_efl_ui_text(void *data, Evas_Object *obj, void *event_info);
317void test_efl_ui_text_label(void *data, Evas_Object *obj, void *event_info); 317void test_efl_ui_text_label(void *data, Evas_Object *obj, void *event_info);
318void test_efl_ui_text_async(void *data, Evas_Object *obj, void *event_info); 318void test_efl_ui_text_async(void *data, Evas_Object *obj, void *event_info);
319void test_ui_text_item_factory(void *data, Evas_Object *obj, void *event_info);
319void test_evas_mask(void *data, Edje_Object *obj, void *event_info); 320void test_evas_mask(void *data, Edje_Object *obj, void *event_info);
320void test_gfx_filters(void *data, Evas_Object *obj, void *event_info); 321void test_gfx_filters(void *data, Evas_Object *obj, void *event_info);
321void test_evas_snapshot(void *data, Evas_Object *obj, void *event_info); 322void test_evas_snapshot(void *data, Evas_Object *obj, void *event_info);
@@ -778,6 +779,7 @@ add_tests:
778 ADD_TEST(NULL, "Entries", "Efl UI Text", test_efl_ui_text); 779 ADD_TEST(NULL, "Entries", "Efl UI Text", test_efl_ui_text);
779 ADD_TEST(NULL, "Entries", "Efl UI Text Label", test_efl_ui_text_label); 780 ADD_TEST(NULL, "Entries", "Efl UI Text Label", test_efl_ui_text_label);
780 ADD_TEST(NULL, "Entries", "Efl UI Text Async", test_efl_ui_text_async); 781 ADD_TEST(NULL, "Entries", "Efl UI Text Async", test_efl_ui_text_async);
782 ADD_TEST(NULL, "Entries", "UI Text Item Provider", test_ui_text_item_factory);
781 783
782 //------------------------------// 784 //------------------------------//
783 ADD_TEST(NULL, "Advanced Entries", "Code Entry Markup", test_code_welcome); 785 ADD_TEST(NULL, "Advanced Entries", "Code Entry Markup", test_code_welcome);
diff --git a/src/bin/elementary/test_efl_ui_text.c b/src/bin/elementary/test_efl_ui_text.c
index b53c427b9a..3f41e801de 100644
--- a/src/bin/elementary/test_efl_ui_text.c
+++ b/src/bin/elementary/test_efl_ui_text.c
@@ -187,6 +187,7 @@ test_efl_ui_text(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
187{ 187{
188 Evas_Object *win, *bx, *bx2, *bx3, *bt, *en; 188 Evas_Object *win, *bx, *bx2, *bx3, *bt, *en;
189 Efl_Text_Cursor_Cursor *main_cur, *cur; 189 Efl_Text_Cursor_Cursor *main_cur, *cur;
190 char buf[128];
190 191
191 win = elm_win_util_standard_add("entry", "Entry"); 192 win = elm_win_util_standard_add("entry", "Entry");
192 elm_win_autodel_set(win, EINA_TRUE); 193 elm_win_autodel_set(win, EINA_TRUE);
@@ -215,9 +216,12 @@ test_efl_ui_text(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
215 cur = efl_text_cursor_new(en); 216 cur = efl_text_cursor_new(en);
216 217
217 efl_text_cursor_position_set(en, cur, 2); 218 efl_text_cursor_position_set(en, cur, 2);
218 efl_text_cursor_object_item_insert(en, cur, "size=32x32 href=emoticon"); 219 efl_text_cursor_object_item_insert(en, cur, "size=32x32 href=emoticon/happy");
219 efl_text_cursor_position_set(en, cur, 50); 220 efl_text_cursor_position_set(en, cur, 50);
220 efl_text_cursor_object_item_insert(en, cur, "size=32x32 href=emoticon"); 221
222 sprintf(buf, "size=32x32 href=file://%s/images/sky_01.jpg",
223 elm_app_data_dir_get());
224 efl_text_cursor_object_item_insert(en, cur, buf);
221 225
222 efl_text_cursor_position_set(en, main_cur, 5); 226 efl_text_cursor_position_set(en, main_cur, 5);
223 efl_text_cursor_position_set(en, cur, 20); 227 efl_text_cursor_position_set(en, cur, 20);
@@ -297,7 +301,7 @@ test_efl_ui_text_async(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
297 elm_win_resize_object_add(win, bx); 301 elm_win_resize_object_add(win, bx);
298 evas_object_show(bx); 302 evas_object_show(bx);
299 303
300 en = efl_add(EFL_UI_TEXT_ASYNC_CLASS, win, 304 en = efl_add(EFL_UI_TEXT_CLASS, win,
301 efl_text_wrap_set(efl_added, EFL_TEXT_FORMAT_WRAP_WORD), 305 efl_text_wrap_set(efl_added, EFL_TEXT_FORMAT_WRAP_WORD),
302 efl_text_multiline_set(efl_added, EINA_TRUE) 306 efl_text_multiline_set(efl_added, EINA_TRUE)
303 ); 307 );
@@ -332,3 +336,194 @@ test_efl_ui_text_async(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
332 evas_object_resize(win, 480, 320); 336 evas_object_resize(win, 480, 320);
333 evas_object_show(win); 337 evas_object_show(win);
334} 338}
339
340static const char *images[4] = { "sky", "logo", "dog" };
341
342static void
343my_efl_ui_text_item_factory_bt_image(void *data, Evas_Object *obj EINA_UNUSED,
344 void *event_info EINA_UNUSED)
345{
346 Evas_Object *en = data;
347 char buf[128];
348
349 static int image_idx = 0;
350 image_idx = (image_idx + 1) % 5;
351 if (image_idx == 3)
352 {
353 sprintf(buf, "size=32x32 href=file://%s/images/sky_02.jpg",
354 elm_app_data_dir_get());
355 }
356 else if (image_idx == 4)
357 {
358 sprintf(buf, "size=32x32 href=%s/images/sky_03.jpg",
359 elm_app_data_dir_get());
360 }
361 else
362 {
363 sprintf(buf, "size=32x32 href=%s", images[image_idx]);
364 }
365 printf("Adding image: %s\n", buf);
366 efl_text_cursor_object_item_insert(en, efl_text_cursor_get(en, EFL_TEXT_CURSOR_GET_MAIN),
367 buf);
368}
369
370static void
371my_efl_ui_text_item_factory_bt_emoticon(void *data, Evas_Object *obj EINA_UNUSED,
372 void *event_info EINA_UNUSED)
373{
374 Evas_Object *en = data;
375 efl_text_cursor_object_item_insert(en, efl_text_cursor_get(en, EFL_TEXT_CURSOR_GET_MAIN),
376 "size=32x32 href=emoticon/evil-laugh");
377}
378
379static void
380my_efl_ui_text_item_factory_bt_fallback(void *data, Evas_Object *obj EINA_UNUSED,
381 void *event_info EINA_UNUSED)
382{
383 Evas_Object *en = data;
384 efl_ui_text_item_provider_fallback_disabled_set(en,
385 !efl_ui_text_item_provider_fallback_disabled_get(en));
386 printf("Fallback changed to: %s\n",
387 efl_ui_text_item_provider_fallback_disabled_get(en) ?
388 "disabled" : "enabled");
389
390}
391
392static struct
393{
394 const char *name;
395 Eo *item_factory;
396} factories[3];
397
398static void
399my_efl_ui_text_item_factory_bt_change(void *data, Evas_Object *obj EINA_UNUSED,
400 void *event_info EINA_UNUSED)
401{
402 Evas_Object *en = data;
403 static int item_factory_idx = 0;
404
405 item_factory_idx = (item_factory_idx + 1) % 3;
406 efl_ui_text_item_factory_set(en, factories[item_factory_idx].item_factory);
407 printf("Factory set to: %s\n", factories[item_factory_idx].name);
408}
409
410void
411test_ui_text_item_factory(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
412{
413 Evas_Object *win, *bx, *bx2, *bx3, *bt, *en;
414 Efl_Text_Cursor_Cursor *main_cur, *cur;
415 char buf[128];
416
417 win = elm_win_util_standard_add("entry", "Entry");
418 elm_win_autodel_set(win, EINA_TRUE);
419
420 bx = elm_box_add(win);
421 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
422 elm_win_resize_object_add(win, bx);
423 evas_object_show(bx);
424
425 en = efl_add(EFL_UI_TEXT_CLASS, win,
426 efl_text_multiline_set(efl_added, EINA_TRUE));
427
428 factories[0].name = "None";
429 factories[0].item_factory = NULL;
430
431 factories[1].name = "Image Factory";
432 factories[1].item_factory = efl_add(EFL_UI_TEXT_IMAGE_ITEM_FACTORY_CLASS, en);
433
434 factories[2].name = "Emoticon Factory";
435 factories[2].item_factory = efl_add(EFL_UI_TEXT_EMOTICON_ITEM_FACTORY_CLASS, en);
436
437 sprintf(buf, "%s/images/sky_01.jpg", elm_app_data_dir_get());
438 efl_ui_text_image_item_factory_matches_add(factories[1].item_factory,
439 images[0], buf, NULL);
440 sprintf(buf, "%s/images/logo.png", elm_app_data_dir_get());
441 efl_ui_text_image_item_factory_matches_add(factories[1].item_factory,
442 images[1], buf, NULL);
443 sprintf(buf, "%s/images/mystrale.jpg", elm_app_data_dir_get());
444 efl_ui_text_image_item_factory_matches_add(factories[1].item_factory,
445 images[2], buf, NULL);
446
447 printf("Added Efl.Ui.Text object\n");
448 efl_text_set(en, "Hello world! Goodbye world! This is a test text for the"
449 " new UI Text widget.\xE2\x80\xA9This is the next paragraph.\nThis"
450 " is the next line.\nThis is Yet another line! Line and paragraph"
451 " separators are actually different!");
452 efl_text_font_set(en, "Sans", 14);
453 efl_text_normal_color_set(en, 255, 255, 255, 255);
454
455 main_cur = efl_text_cursor_get(en, EFL_TEXT_CURSOR_GET_MAIN);
456 cur = efl_text_cursor_new(en);
457
458 efl_text_cursor_position_set(en, cur, 2);
459 efl_text_cursor_object_item_insert(en, cur, "size=32x32 href=emoticon/happy");
460 efl_text_cursor_position_set(en, cur, 50);
461
462 sprintf(buf, "size=32x32 href=file://%s/images/sky_01.jpg",
463 elm_app_data_dir_get());
464 efl_text_cursor_object_item_insert(en, cur, buf);
465 efl_text_cursor_position_set(en, main_cur, 5);
466
467 efl_ui_text_interactive_editable_set(en, EINA_TRUE);
468 efl_ui_text_scrollable_set(en, EINA_TRUE);
469 elm_box_pack_end(bx, en);
470 elm_object_focus_set(en, EINA_TRUE);
471
472 bx2 = elm_box_add(win);
473 elm_box_horizontal_set(bx2, EINA_TRUE);
474 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0.0);
475 evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, EVAS_HINT_FILL);
476
477 bt = elm_button_add(win);
478 elm_object_text_set(bt, "Image");
479 evas_object_smart_callback_add(bt, "clicked",
480 my_efl_ui_text_item_factory_bt_image, en);
481 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
482 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
483 elm_box_pack_end(bx2, bt);
484 elm_object_focus_allow_set(bt, EINA_FALSE);
485 evas_object_show(bt);
486
487 bt = elm_button_add(win);
488 elm_object_text_set(bt, "Emoticon");
489 evas_object_smart_callback_add(bt, "clicked",
490 my_efl_ui_text_item_factory_bt_emoticon, en);
491 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
492 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
493 elm_box_pack_end(bx2, bt);
494 elm_object_focus_allow_set(bt, EINA_FALSE);
495 evas_object_show(bt);
496
497 bt = elm_button_add(win);
498 elm_object_text_set(bt, "Factory");
499 evas_object_smart_callback_add(bt, "clicked",
500 my_efl_ui_text_item_factory_bt_change, en);
501 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
502 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
503 elm_box_pack_end(bx2, bt);
504 elm_object_focus_allow_set(bt, EINA_FALSE);
505 evas_object_show(bt);
506
507 bt = elm_button_add(win);
508 elm_object_text_set(bt, "Fallback");
509 evas_object_smart_callback_add(bt, "clicked",
510 my_efl_ui_text_item_factory_bt_fallback, en);
511 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
512 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
513 elm_box_pack_end(bx2, bt);
514 elm_object_focus_allow_set(bt, EINA_FALSE);
515 evas_object_show(bt);
516
517 bx3 = elm_box_add(win);
518 elm_box_horizontal_set(bx3, EINA_TRUE);
519 evas_object_size_hint_weight_set(bx3, EVAS_HINT_EXPAND, 0.0);
520 evas_object_size_hint_align_set(bx3, EVAS_HINT_FILL, EVAS_HINT_FILL);
521
522 elm_box_pack_end(bx, bx3);
523 elm_box_pack_end(bx, bx2);
524 evas_object_show(bx3);
525 evas_object_show(bx2);
526
527 evas_object_resize(win, 480, 320);
528 evas_object_show(win);
529}
diff --git a/src/lib/elementary/Elementary.h b/src/lib/elementary/Elementary.h
index 806e04821e..f3214d9e79 100644
--- a/src/lib/elementary/Elementary.h
+++ b/src/lib/elementary/Elementary.h
@@ -280,6 +280,9 @@ EAPI extern Elm_Version *elm_version;
280# include <efl_ui_win_socket.eo.h> 280# include <efl_ui_win_socket.eo.h>
281# include <efl_ui_text_interactive.eo.h> 281# include <efl_ui_text_interactive.eo.h>
282# include <efl_ui_text.eo.h> 282# include <efl_ui_text.eo.h>
283# include <efl_ui_text_image_item_factory.eo.h>
284# include <efl_ui_text_emoticon_item_factory.eo.h>
285# include <efl_ui_text_fallback_item_factory.eo.h>
283# include <efl_ui_text_editable.eo.h> 286# include <efl_ui_text_editable.eo.h>
284# include <efl_ui_text_async.eo.h> 287# include <efl_ui_text_async.eo.h>
285# include <efl_ui_clock.eo.h> 288# include <efl_ui_clock.eo.h>
diff --git a/src/lib/elementary/efl_ui_text.c b/src/lib/elementary/efl_ui_text.c
index c1b9bd7287..c80d378fe4 100644
--- a/src/lib/elementary/efl_ui_text.c
+++ b/src/lib/elementary/efl_ui_text.c
@@ -63,7 +63,8 @@ struct _Efl_Ui_Text_Data
63 Eina_List *sel; 63 Eina_List *sel;
64 Eina_List *items; /** context menu item list */ 64 Eina_List *items; /** context menu item list */
65 Item_Obj *item_objs; 65 Item_Obj *item_objs;
66 Eina_List *item_providers; 66 Efl_Canvas_Text_Item_Factory *item_factory_fallback;
67 Efl_Canvas_Text_Item_Factory *item_factory;
67 Eina_List *markup_filters; 68 Eina_List *markup_filters;
68 Ecore_Job *hov_deljob; 69 Ecore_Job *hov_deljob;
69 Mod_Api *api; // module api if supplied 70 Mod_Api *api; // module api if supplied
@@ -131,6 +132,7 @@ struct _Efl_Ui_Text_Data
131 Eina_Bool scroll : 1; 132 Eina_Bool scroll : 1;
132 Eina_Bool input_panel_show_on_demand : 1; 133 Eina_Bool input_panel_show_on_demand : 1;
133 Eina_Bool anchors_updated : 1; 134 Eina_Bool anchors_updated : 1;
135 Eina_Bool fallback_item_provider_disabled : 1;
134}; 136};
135 137
136struct _Anchor 138struct _Anchor
@@ -2557,43 +2559,22 @@ _entry_mouse_triple_signal_cb(void *data,
2557static Evas_Object * 2559static Evas_Object *
2558_item_get(void *data, const char *item) 2560_item_get(void *data, const char *item)
2559{ 2561{
2560 Eina_List *l; 2562 Evas_Object *o = NULL;
2561 Evas_Object *o;
2562 Elm_Entry_Item_Provider *ip;
2563 const char *style = elm_widget_style_get(data);
2564 2563
2565 EFL_UI_TEXT_DATA_GET(data, sd); 2564 EFL_UI_TEXT_DATA_GET(data, sd);
2566 2565
2567 EINA_LIST_FOREACH(sd->item_providers, l, ip) 2566 if (item)
2568 {
2569 o = ip->func(ip->data, data, item);
2570 if (o) return o;
2571 }
2572 if (item && !strncmp(item, "file://", 7))
2573 { 2567 {
2574 const char *fname = item + 7; 2568 if (sd->item_factory)
2575
2576 o = evas_object_image_filled_add(evas_object_evas_get(data));
2577 evas_object_image_file_set(o, fname, NULL);
2578 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2579 { 2569 {
2580 evas_object_show(o); 2570 o = efl_canvas_text_item_factory_create(sd->item_factory, data, item);
2581 } 2571 }
2582 else 2572 if (!o && !sd->fallback_item_provider_disabled)
2583 { 2573 {
2584 evas_object_del(o); 2574 o = efl_canvas_text_item_factory_create(sd->item_factory_fallback,
2585 o = edje_object_add(evas_object_evas_get(data)); 2575 data, item);
2586 elm_widget_theme_object_set
2587 (data, o, "entry/emoticon", "wtf", style);
2588 } 2576 }
2589 return o;
2590 } 2577 }
2591
2592 o = edje_object_add(evas_object_evas_get(data));
2593 if (!elm_widget_theme_object_set
2594 (data, o, "entry", item, style))
2595 elm_widget_theme_object_set
2596 (data, o, "entry/emoticon", "wtf", style);
2597 return o; 2578 return o;
2598} 2579}
2599 2580
@@ -3182,6 +3163,7 @@ _efl_ui_text_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Text_Data *priv)
3182 if (_elm_config->desktop_entry) 3163 if (_elm_config->desktop_entry)
3183 priv->sel_handler_disabled = EINA_TRUE; 3164 priv->sel_handler_disabled = EINA_TRUE;
3184 3165
3166 priv->item_factory_fallback = efl_add(EFL_UI_TEXT_FALLBACK_ITEM_FACTORY_CLASS, obj);
3185 _create_text_cursors(obj, priv); 3167 _create_text_cursors(obj, priv);
3186} 3168}
3187 3169
@@ -3264,10 +3246,6 @@ _efl_ui_text_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Text_Data *sd)
3264 eina_stringshare_del(it->icon_group); 3246 eina_stringshare_del(it->icon_group);
3265 free(it); 3247 free(it);
3266 } 3248 }
3267 EINA_LIST_FREE(sd->item_providers, ip)
3268 {
3269 free(ip);
3270 }
3271 EINA_LIST_FREE(sd->markup_filters, tf) 3249 EINA_LIST_FREE(sd->markup_filters, tf)
3272 { 3250 {
3273 _filter_free(tf); 3251 _filter_free(tf);
@@ -3304,6 +3282,7 @@ _efl_ui_text_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Text_Data *sd)
3304 // a specific behavior of SWALLOW parts. 3282 // a specific behavior of SWALLOW parts.
3305 efl_del(sd->text_obj); 3283 efl_del(sd->text_obj);
3306 sd->text_obj = NULL; 3284 sd->text_obj = NULL;
3285 if (sd->item_factory_fallback) efl_del(sd->item_factory_fallback);
3307 efl_canvas_group_del(efl_super(obj, MY_CLASS)); 3286 efl_canvas_group_del(efl_super(obj, MY_CLASS));
3308} 3287}
3309 3288
@@ -3619,55 +3598,6 @@ _efl_ui_text_context_menu_disabled_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd
3619 return !sd->context_menu; 3598 return !sd->context_menu;
3620} 3599}
3621 3600
3622EOLIAN static void
3623_efl_ui_text_item_provider_append(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Elm_Entry_Item_Provider_Cb func, void *data)
3624{
3625 Elm_Entry_Item_Provider *ip;
3626
3627 EINA_SAFETY_ON_NULL_RETURN(func);
3628
3629 ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3630 if (!ip) return;
3631
3632 ip->func = func;
3633 ip->data = data;
3634 sd->item_providers = eina_list_append(sd->item_providers, ip);
3635}
3636
3637EOLIAN static void
3638_efl_ui_text_item_provider_prepend(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Elm_Entry_Item_Provider_Cb func, void *data)
3639{
3640 Elm_Entry_Item_Provider *ip;
3641
3642 EINA_SAFETY_ON_NULL_RETURN(func);
3643
3644 ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3645 if (!ip) return;
3646
3647 ip->func = func;
3648 ip->data = data;
3649 sd->item_providers = eina_list_prepend(sd->item_providers, ip);
3650}
3651
3652EOLIAN static void
3653_efl_ui_text_item_provider_remove(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Elm_Entry_Item_Provider_Cb func, void *data)
3654{
3655 Eina_List *l;
3656 Elm_Entry_Item_Provider *ip;
3657
3658 EINA_SAFETY_ON_NULL_RETURN(func);
3659
3660 EINA_LIST_FOREACH(sd->item_providers, l, ip)
3661 {
3662 if ((ip->func == func) && ((!data) || (ip->data == data)))
3663 {
3664 sd->item_providers = eina_list_remove_list(sd->item_providers, l);
3665 free(ip);
3666 return;
3667 }
3668 }
3669}
3670
3671EOLIAN static Eina_Bool 3601EOLIAN static Eina_Bool
3672_efl_ui_text_efl_file_file_set(Eo *obj, Efl_Ui_Text_Data *sd, const char *file, const char *group EINA_UNUSED) 3602_efl_ui_text_efl_file_file_set(Eo *obj, Efl_Ui_Text_Data *sd, const char *file, const char *group EINA_UNUSED)
3673{ 3603{
@@ -5375,6 +5305,32 @@ _efl_ui_text_move_cb(void *data, Evas *e EINA_UNUSED,
5375 _decoration_defer_all(data); 5305 _decoration_defer_all(data);
5376} 5306}
5377 5307
5308static void
5309_efl_ui_text_item_factory_set(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *pd,
5310 Efl_Canvas_Text_Item_Factory *item_factory)
5311{
5312 pd->item_factory = item_factory;
5313}
5314
5315static Eo *
5316_efl_ui_text_item_factory_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *pd)
5317{
5318 return pd->item_factory;
5319}
5320
5321static void
5322_efl_ui_text_item_provider_fallback_disabled_set(Eo *obj EINA_UNUSED,
5323 Efl_Ui_Text_Data *pd, Eina_Bool disabled)
5324{
5325 pd->fallback_item_provider_disabled = disabled;
5326}
5327
5328static Eina_Bool
5329_efl_ui_text_item_provider_fallback_disabled_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *pd)
5330{
5331 return pd->fallback_item_provider_disabled;
5332}
5333
5378#if 0 5334#if 0
5379/* Efl.Part begin */ 5335/* Efl.Part begin */
5380 5336
diff --git a/src/lib/elementary/efl_ui_text.eo b/src/lib/elementary/efl_ui_text.eo
index 67ad82d034..d2e1aff32d 100644
--- a/src/lib/elementary/efl_ui_text.eo
+++ b/src/lib/elementary/efl_ui_text.eo
@@ -232,13 +232,22 @@ class Efl.Ui.Text (Efl.Ui.Layout, Elm.Interface_Scrollable, Efl.Ui.Clickable,
232 enabled: bool; [[If $enabled is $true, the return key is automatically disabled when the entry has no text.]] 232 enabled: bool; [[If $enabled is $true, the return key is automatically disabled when the entry has no text.]]
233 } 233 }
234 } 234 }
235 item_provider_prepend { 235 @property item_factory {
236 [[This prepends a custom item provider to the list for that entry 236 [[The factory that provides items for "href" items e.g.
237 "href=emoticon/happy" or "href=file://image.jpg"
238 ]]
239 values {
240 item_factory: Efl.Canvas.Text.Item_Factory; [[Factory to create items]]
241 }
242 }
243 @property item_provider_fallback_disabled {
244 [[Fallback to internal item provider.
237 245
238 This prepends the given callback.]] 246 This will query the internal item provider for object items, in case
239 params { 247 there was no result querying the set item_provider.
240 @in func: Elm_Entry_Item_Provider_Cb; [[The function called to provide the item object.]] 248 ]]
241 @in data: void_ptr @optional; [[The data passed to $func.]] 249 values {
250 disabled: bool;
242 } 251 }
243 } 252 }
244 input_panel_show { 253 input_panel_show {
@@ -251,17 +260,6 @@ class Efl.Ui.Text (Efl.Ui.Layout, Elm.Interface_Scrollable, Efl.Ui.Clickable,
251 selection_copy { 260 selection_copy {
252 [[This executes a "copy" action on the selected text in the entry.]] 261 [[This executes a "copy" action on the selected text in the entry.]]
253 } 262 }
254 item_provider_remove {
255 [[This removes a custom item provider to the list for that entry
256
257 This removes the given callback. See @.item_provider_append for
258 more information
259 ]]
260 params {
261 @in func: Elm_Entry_Item_Provider_Cb; [[The function called to provide the item object.]]
262 @in data: void_ptr @optional; [[The data passed to $func.]]
263 }
264 }
265 context_menu_clear { 263 context_menu_clear {
266 [[This clears and frees the items in a entry's contextual (longpress) 264 [[This clears and frees the items in a entry's contextual (longpress)
267 menu. 265 menu.
@@ -305,23 +303,6 @@ class Efl.Ui.Text (Efl.Ui.Layout, Elm.Interface_Scrollable, Efl.Ui.Clickable,
305 selection_cut { 303 selection_cut {
306 [[This executes a "cut" action on the selected text in the entry.]] 304 [[This executes a "cut" action on the selected text in the entry.]]
307 } 305 }
308 item_provider_append {
309 [[This appends a custom item provider to the list for that entry
310
311 This appends the given callback. The list is walked from beginning to end
312 with each function called given the item href string in the text. If the
313 function returns an object handle other than $null (it should create an
314 object to do this), then this object is used to replace that item. If
315 not the next provider is called until one provides an item object, or the
316 default provider in entry does.
317
318 See also \@ref entry-items.
319 ]]
320 params {
321 @in func: Elm_Entry_Item_Provider_Cb; [[The function called to provide the item object.]]
322 @in data: void_ptr @optional; [[The data passed to $func.]]
323 }
324 }
325 context_menu_item_add { 306 context_menu_item_add {
326 [[This adds an item to the entry's contextual menu. 307 [[This adds an item to the entry's contextual menu.
327 308
diff --git a/src/lib/elementary/efl_ui_text_emoticon_item_factory.c b/src/lib/elementary/efl_ui_text_emoticon_item_factory.c
new file mode 100644
index 0000000000..022446d47e
--- /dev/null
+++ b/src/lib/elementary/efl_ui_text_emoticon_item_factory.c
@@ -0,0 +1,52 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include <Elementary_Cursor.h>
7#include "elm_priv.h"
8
9#define MY_CLASS EFL_UI_TEXT_EMOTICON_ITEM_FACTORY_CLASS
10
11typedef struct _Efl_Ui_Text_Emoticon_Item_Factory_Data Efl_Ui_Text_Emoticon_Item_Factory_Data;
12
13struct _Efl_Ui_Text_Emoticon_Item_Factory_Data
14{
15 const char *name;
16};
17
18EOLIAN static Eo *
19_efl_ui_text_emoticon_item_factory_efl_object_constructor(Eo *obj,
20 Efl_Ui_Text_Emoticon_Item_Factory_Data *pd EINA_UNUSED)
21{
22 obj = efl_constructor(efl_super(obj, MY_CLASS));
23 return obj;
24}
25
26EOLIAN static void
27_efl_ui_text_emoticon_item_factory_efl_object_destructor(Eo *obj,
28 Efl_Ui_Text_Emoticon_Item_Factory_Data *pd EINA_UNUSED)
29{
30 efl_destructor(efl_super(obj, MY_CLASS));
31}
32
33
34EOLIAN static Efl_Canvas_Object
35*_efl_ui_text_emoticon_item_factory_efl_canvas_text_item_factory_create(
36 Eo *obj EINA_UNUSED,
37 Efl_Ui_Text_Emoticon_Item_Factory_Data *pd EINA_UNUSED,
38 Efl_Canvas_Object *object,
39 const char *key)
40{
41 Eo *o;
42 const char *style = elm_widget_style_get(object);
43
44 o = edje_object_add(evas_object_evas_get(object));
45 if (!_elm_theme_object_set
46 (object, o, "entry", key, style))
47 _elm_theme_object_set
48 (object, o, "entry/emoticon", "wtf", style);
49 return o;
50}
51
52#include "efl_ui_text_emoticon_item_factory.eo.c"
diff --git a/src/lib/elementary/efl_ui_text_emoticon_item_factory.eo b/src/lib/elementary/efl_ui_text_emoticon_item_factory.eo
new file mode 100644
index 0000000000..b8bc7715dc
--- /dev/null
+++ b/src/lib/elementary/efl_ui_text_emoticon_item_factory.eo
@@ -0,0 +1,12 @@
1class Efl.Ui.Text.Emoticon_Item_Factory (Efl.Object, Efl.Canvas.Text.Item_Factory)
2{
3 [[Factory that creates emoticons from the current theme given a key.
4
5 @since 1.21
6 ]]
7 implements {
8 Efl.Object.constructor;
9 Efl.Object.destructor;
10 Efl.Canvas.Text.Item_Factory.create;
11 }
12}
diff --git a/src/lib/elementary/efl_ui_text_fallback_item_factory.c b/src/lib/elementary/efl_ui_text_fallback_item_factory.c
new file mode 100644
index 0000000000..5e439259e2
--- /dev/null
+++ b/src/lib/elementary/efl_ui_text_fallback_item_factory.c
@@ -0,0 +1,62 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include <Elementary_Cursor.h>
7#include "elm_priv.h"
8
9#define MY_CLASS EFL_UI_TEXT_FALLBACK_ITEM_FACTORY_CLASS
10
11typedef struct _Efl_Ui_Text_Fallback_Item_Factory_Data Efl_Ui_Text_Fallback_Item_Factory_Data;
12
13struct _Efl_Ui_Text_Fallback_Item_Factory_Data
14{
15 Efl_Canvas_Text_Item_Factory *emoticon_item_factory, *image_item_factory;
16};
17
18EOLIAN static Eo *
19_efl_ui_text_fallback_item_factory_efl_object_constructor(Eo *obj,
20 Efl_Ui_Text_Fallback_Item_Factory_Data *pd EINA_UNUSED)
21{
22 obj = efl_constructor(efl_super(obj, MY_CLASS));
23 pd->emoticon_item_factory = efl_add(EFL_UI_TEXT_EMOTICON_ITEM_FACTORY_CLASS, obj);
24 pd->image_item_factory = efl_add(EFL_UI_TEXT_IMAGE_ITEM_FACTORY_CLASS, obj);
25 return obj;
26}
27
28EOLIAN static void
29_efl_ui_text_fallback_item_factory_efl_object_destructor(Eo *obj,
30 Efl_Ui_Text_Fallback_Item_Factory_Data *pd EINA_UNUSED)
31{
32 efl_del(pd->emoticon_item_factory);
33 efl_del(pd->image_item_factory);
34 efl_destructor(efl_super(obj, MY_CLASS));
35}
36
37
38EOLIAN static Efl_Canvas_Object
39*_efl_ui_text_fallback_item_factory_efl_canvas_text_item_factory_create(
40 Eo *obj EINA_UNUSED,
41 Efl_Ui_Text_Fallback_Item_Factory_Data *pd EINA_UNUSED,
42 Efl_Canvas_Object *object,
43 const char *key)
44{
45 Efl_Canvas_Object *o = NULL;
46
47 // Parse the string. Can be either:
48 // 1. some/name - an emoticon (load from theme)
49 // 2. file:// - image file
50 if (key && !strncmp(key, "file://", 7))
51 {
52 const char *fname = key + 7;
53 o = efl_canvas_text_item_factory_create(pd->image_item_factory, object, fname);
54 }
55 else
56 {
57 o = efl_canvas_text_item_factory_create(pd->emoticon_item_factory, object, key);
58 }
59 return o;
60}
61
62#include "efl_ui_text_fallback_item_factory.eo.c"
diff --git a/src/lib/elementary/efl_ui_text_fallback_item_factory.eo b/src/lib/elementary/efl_ui_text_fallback_item_factory.eo
new file mode 100644
index 0000000000..c4bb90e900
--- /dev/null
+++ b/src/lib/elementary/efl_ui_text_fallback_item_factory.eo
@@ -0,0 +1,16 @@
1class Efl.Ui.Text.Fallback_Item_Factory (Efl.Object, Efl.Canvas.Text.Item_Factory)
2{
3 [[Internal factory for fallback cases.
4
5 This wraps some internal functionality:
6 - Contains 2 factories: image and emoticon
7 - Strips-off "file://" prefix for image items, to be used with the image
8 factory.
9 @since 1.21
10 ]]
11 implements {
12 Efl.Object.constructor;
13 Efl.Object.destructor;
14 Efl.Canvas.Text.Item_Factory.create;
15 }
16}
diff --git a/src/lib/elementary/efl_ui_text_image_item_factory.c b/src/lib/elementary/efl_ui_text_image_item_factory.c
new file mode 100644
index 0000000000..38ce8407ea
--- /dev/null
+++ b/src/lib/elementary/efl_ui_text_image_item_factory.c
@@ -0,0 +1,97 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Elementary.h>
6#include <Elementary_Cursor.h>
7#include "elm_priv.h"
8
9#define MY_CLASS EFL_UI_TEXT_IMAGE_ITEM_FACTORY_CLASS
10
11typedef struct _Efl_Ui_Text_Image_Item_Factory_Data Efl_Ui_Text_Image_Item_Factory_Data;
12
13struct _Efl_Ui_Text_Image_Item_Factory_Data
14{
15 const char *name;
16 Eina_Hash *hash;
17};
18
19typedef struct
20{
21 const char *file;
22 const char *key;
23} Image_Entry;
24
25static void
26_entry_free_cb(void *data)
27{
28 Image_Entry *e = data;
29 eina_stringshare_del(e->file);
30 eina_stringshare_del(e->key);
31 free(e);
32}
33
34EOLIAN static Eo *
35_efl_ui_text_image_item_factory_efl_object_constructor(Eo *obj,
36 Efl_Ui_Text_Image_Item_Factory_Data *pd EINA_UNUSED)
37{
38 obj = efl_constructor(efl_super(obj, MY_CLASS));
39 pd->hash = eina_hash_string_superfast_new(_entry_free_cb);
40 return obj;
41}
42
43EOLIAN static void
44_efl_ui_text_image_item_factory_efl_object_destructor(Eo *obj,
45 Efl_Ui_Text_Image_Item_Factory_Data *pd EINA_UNUSED)
46{
47 eina_hash_free(pd->hash);
48 efl_destructor(efl_super(obj, MY_CLASS));
49}
50
51EOLIAN static Efl_Canvas_Object
52*_efl_ui_text_image_item_factory_efl_canvas_text_item_factory_create(Eo *obj EINA_UNUSED,
53 Efl_Ui_Text_Image_Item_Factory_Data *pd EINA_UNUSED,
54 Efl_Canvas_Object *object,
55 const char *key)
56{
57 Efl_Canvas_Object *o;
58 Image_Entry *e;
59 const char *file = key, *filekey = NULL;
60
61 e = eina_hash_find(pd->hash, key);
62 if (e)
63 {
64 file = e->file;
65 filekey = e->key;
66 }
67
68 o = evas_object_image_filled_add(evas_object_evas_get(object));
69 evas_object_image_file_set(o, file, filekey);
70 if (evas_object_image_load_error_get(o) != EVAS_LOAD_ERROR_NONE)
71 {
72 evas_object_del(o);
73 o = NULL;
74 }
75 return o;
76}
77
78EOLIAN static Eina_Bool
79_efl_ui_text_image_item_factory_matches_add(Eo *obj EINA_UNUSED,
80 Efl_Ui_Text_Image_Item_Factory_Data *pd,
81 const char *name, const char *file, const char *key)
82{
83 Image_Entry *e = malloc(sizeof(*e));
84 e->file = eina_stringshare_add(file);
85 e->key = eina_stringshare_add(key);
86 return eina_hash_add(pd->hash, name, e);
87}
88
89EOLIAN static Eina_Bool
90_efl_ui_text_image_item_factory_matches_del(Eo *obj EINA_UNUSED,
91 Efl_Ui_Text_Image_Item_Factory_Data *pd,
92 const char *name)
93{
94 return eina_hash_del(pd->hash, name, NULL);
95}
96
97#include "efl_ui_text_image_item_factory.eo.c"
diff --git a/src/lib/elementary/efl_ui_text_image_item_factory.eo b/src/lib/elementary/efl_ui_text_image_item_factory.eo
new file mode 100644
index 0000000000..7911c83981
--- /dev/null
+++ b/src/lib/elementary/efl_ui_text_image_item_factory.eo
@@ -0,0 +1,42 @@
1class Efl.Ui.Text.Image_Item_Factory (Efl.Object, Efl.Canvas.Text.Item_Factory)
2{
3 [[Factory that creates images given key string
4
5 The key can be either a full image path, or associated with one. The
6 factory will fallback if key was not matches with an image, and try
7 to load it as a full path.
8
9 @since 1.21
10 ]]
11 methods {
12 matches_add {
13 [[Associates given name with a filename of an image.
14
15 This can be used for quick retrieval (instead of
16 providing actual filenames.
17 ]]
18 params {
19 name: string; [[the name associated with filename]]
20 filename: string; [[the image filename]]
21 key: string; [[the key to use (in cases of loading an EET file]]
22 }
23 return: bool;
24 }
25 matches_del {
26 [[Associated given name with a filename of an image.
27
28 This can be used for quick retrieval (instead of
29 providing actual filenames.
30 ]]
31 params {
32 key: string; [[the key to use (in cases of loading an EET file]]
33 }
34 return: bool;
35 }
36 }
37 implements {
38 Efl.Object.constructor;
39 Efl.Object.destructor;
40 Efl.Canvas.Text.Item_Factory.create;
41 }
42}