summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2016-07-03 16:40:34 +0000
committerDaniel Hirt <daniel.hirt@samsung.com>2016-07-03 17:10:57 +0000
commitfed2b7578031d7ab80cac02d4f00636f9d058a1a (patch)
treef6670ed05c66cfd8c76acd74f782f7e5e1c6076d /src
parent5c776eb534f33c8f0da5419a912e5935cec084b0 (diff)
Canvas text: simplify efl_text_get
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c83
1 files changed, 32 insertions, 51 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 6025bbf..f9e5bb6 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -8284,20 +8284,26 @@ found:
8284 _evas_textblock_changed(o, eo_obj); 8284 _evas_textblock_changed(o, eo_obj);
8285} 8285}
8286 8286
8287EOLIAN static void 8287static void
8288_efl_canvas_text_cursor_paragraph_first(Evas_Textblock_Cursor *cur_obj, Efl_Canvas_Text_Cursor_Data *cur) 8288_canvas_text_cursor_paragraph_first(Efl_Canvas_Text_Cursor_Data *cur)
8289{ 8289{
8290 Evas_Object_Protected_Data *obj = eo_data_scope_get(cur->obj, EFL_CANVAS_OBJECT_CLASS); 8290 Evas_Object_Protected_Data *obj = eo_data_scope_get(cur->obj, EFL_CANVAS_OBJECT_CLASS);
8291 evas_object_async_block(obj); 8291 evas_object_async_block(obj);
8292 Efl_Canvas_Text_Data *o = eo_data_scope_get(cur->obj, MY_CLASS); 8292 Efl_Canvas_Text_Data *o = eo_data_scope_get(cur->obj, MY_CLASS);
8293 cur->node = o->text_nodes; 8293 cur->node = o->text_nodes;
8294 cur->pos = 0; 8294 cur->pos = 0;
8295}
8295 8296
8297EOLIAN static void
8298_efl_canvas_text_cursor_paragraph_first(Evas_Textblock_Cursor *cur_obj, Efl_Canvas_Text_Cursor_Data *cur)
8299{
8300 _canvas_text_cursor_paragraph_first(cur);
8296 eo_event_callback_call(cur_obj, EFL_CANVAS_TEXT_CURSOR_EVENT_CHANGED, NULL); 8301 eo_event_callback_call(cur_obj, EFL_CANVAS_TEXT_CURSOR_EVENT_CHANGED, NULL);
8297} 8302}
8298 8303
8299EOLIAN static void 8304
8300_efl_canvas_text_cursor_paragraph_last(Evas_Textblock_Cursor *cur_obj, Efl_Canvas_Text_Cursor_Data *cur) 8305static void
8306_canvas_text_cursor_paragraph_last(Efl_Canvas_Text_Cursor_Data *cur)
8301{ 8307{
8302 Evas_Object_Textblock_Node_Text *node; 8308 Evas_Object_Textblock_Node_Text *node;
8303 8309
@@ -8310,14 +8316,19 @@ _efl_canvas_text_cursor_paragraph_last(Evas_Textblock_Cursor *cur_obj, Efl_Canva
8310 node = _NODE_TEXT(EINA_INLIST_GET(node)->last); 8316 node = _NODE_TEXT(EINA_INLIST_GET(node)->last);
8311 cur->node = node; 8317 cur->node = node;
8312 cur->pos = 0; 8318 cur->pos = 0;
8313 evas_textblock_cursor_paragraph_char_last(cur_obj); 8319 _evas_textblock_cursor_paragraph_char_last(cur);
8314 } 8320 }
8315 else 8321 else
8316 { 8322 {
8317 cur->node = NULL; 8323 cur->node = NULL;
8318 cur->pos = 0; 8324 cur->pos = 0;
8319 } 8325 }
8326}
8320 8327
8328EOLIAN static void
8329_efl_canvas_text_cursor_paragraph_last(Evas_Textblock_Cursor *cur_obj, Efl_Canvas_Text_Cursor_Data *cur)
8330{
8331 _canvas_text_cursor_paragraph_last(cur);
8321 eo_event_callback_call(cur_obj, EFL_CANVAS_TEXT_CURSOR_EVENT_CHANGED, NULL); 8332 eo_event_callback_call(cur_obj, EFL_CANVAS_TEXT_CURSOR_EVENT_CHANGED, NULL);
8322} 8333}
8323 8334
@@ -13599,63 +13610,33 @@ _efl_canvas_text_efl_text_text_set(Eo *eo_obj, Efl_Canvas_Text_Data *o EINA_UNUS
13599 efl_canvas_text_cursor_text_insert(o->cursor, text); 13610 efl_canvas_text_cursor_text_insert(o->cursor, text);
13600} 13611}
13601 13612
13602EOLIAN static const char * 13613static char *
13603_efl_canvas_text_efl_text_text_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o) 13614_canvas_text_get_all(Eo *eo_obj, Efl_Canvas_Text_Data *o)
13604{ 13615{
13605 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); 13616 Efl_Canvas_Text_Cursor_Data start, end;
13606 evas_object_async_block(obj);
13607 13617
13608 Evas_Object_Textblock_Node_Text *node; 13618 _evas_textblock_cursor_init(&start, eo_obj);
13609 char *utf8, *off; 13619 _evas_textblock_cursor_init(&end, eo_obj);
13610 13620
13611 struct 13621 _canvas_text_cursor_paragraph_first(&start);
13612 { 13622 _canvas_text_cursor_paragraph_last(&end);
13613 char *utf8;
13614 int len;
13615 } *en;
13616 Eina_List *lst_utf8 = NULL;
13617 Eina_List *i;
13618 13623
13619 int len = 0; 13624 return _evas_textblock_cursor_range_text_get(&start, &end, EVAS_TEXTBLOCK_TEXT_PLAIN);
13625}
13626
13627EOLIAN static const char *
13628_efl_canvas_text_efl_text_text_get(Eo *eo_obj, Efl_Canvas_Text_Data *o)
13629{
13630 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
13631 evas_object_async_block(obj);
13620 13632
13621 //XXX: not efficient atm. This value will be cached properly so in the
13622 // meantime the utf8 field will be cleared each call.
13623 if (o->utf8) 13633 if (o->utf8)
13624 { 13634 {
13625 free(o->utf8); 13635 free(o->utf8);
13626 o->utf8 = NULL; 13636 o->utf8 = NULL;
13627 } 13637 }
13628 13638
13629 // XXX: won't use cursor_paragraph_text_get as it's inefficient 13639 o->utf8 = _canvas_text_get_all(eo_obj, o);
13630 // for this function (gets ranges, uses strbuf).
13631
13632 // gets utf8s and calc length
13633 EINA_INLIST_FOREACH(o->text_nodes, node)
13634 {
13635 en = malloc(sizeof(*en));
13636 en->utf8 = eina_unicode_unicode_to_utf8(eina_ustrbuf_string_get(node->unicode), &en->len);
13637 lst_utf8 = eina_list_append(lst_utf8, en);
13638 len += en->len;
13639 }
13640
13641 utf8 = malloc(len + 1); // with terminating '/0'
13642 if (!utf8) goto end;
13643
13644 off = utf8;
13645 EINA_LIST_FOREACH(lst_utf8, i, en)
13646 {
13647 memcpy(off, en->utf8, en->len);
13648 off += en->len;
13649 }
13650 utf8[len] = '\0';
13651 o->utf8 = utf8;
13652
13653end:
13654 EINA_LIST_FREE(lst_utf8, en)
13655 {
13656 free(en);
13657 }
13658
13659 return o->utf8; 13640 return o->utf8;
13660} 13641}
13661 13642