From: tasn Date: Sun, 22 Aug 2010 11:00:45 +0000 (+0000) Subject: Evas textblock: fixed most of the cases on which a cursor was not drawn correctly. X-Git-Tag: accepted/2.0/20130306.225542~242^2~1632 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10a1bdf183b21a583cb98d9c099d8e39b7f1494d;p=profile%2Fivi%2Fevas.git Evas textblock: fixed most of the cases on which a cursor was not drawn correctly. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@51515 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/lib/canvas/evas_object_textblock.c b/src/lib/canvas/evas_object_textblock.c index 37d30c3..9a12f43 100644 --- a/src/lib/canvas/evas_object_textblock.c +++ b/src/lib/canvas/evas_object_textblock.c @@ -5641,7 +5641,7 @@ _evas_textblock_node_format_free(Evas_Object_Textblock_Node_Format *n) * @param format the text to create the format node from. * @return Returns the new format node */ - static Evas_Object_Textblock_Node_Format * +static Evas_Object_Textblock_Node_Format * _evas_textblock_node_format_new(const char *format) { Evas_Object_Textblock_Node_Format *n; @@ -5655,6 +5655,26 @@ _evas_textblock_node_format_new(const char *format) } /** + * Check if the current cursor position points to the terminating null of the + * last paragraph. (shouldn't be allowed to point to the terminating null of + * any previous paragraph anyway. + * + * @param cur the cursor to look at. + * @return #EINA_TRUE if the cursor points to the terminating null, #EINA_FALSE otherwise. + */ +static Eina_Bool +_evas_textblock_cursor_is_at_the_end(const Evas_Textblock_Cursor *cur) +{ + const Eina_Unicode *text; + + if (!cur) return EINA_FALSE; + if (!cur->node) return EINA_FALSE; + text = eina_ustrbuf_string_get(cur->node->unicode); + return ((text[cur->pos] == 0) && (!EINA_INLIST_GET(cur->node)->next)) ? + EINA_TRUE : EINA_FALSE; +} + +/** * Adds format to the current cursor position. If the format being added is a * visible format, add it *before* the cursor position, otherwise, add it after. * This behavior is because visible formats are like characters and invisible @@ -6233,8 +6253,10 @@ evas_textblock_cursor_char_geometry_get(const Evas_Textblock_Cursor *cur, Evas_C Evas_Object_Textblock_Line *ln = NULL; Evas_Object_Textblock_Item *it = NULL; Evas_Object_Textblock_Format_Item *fi = NULL; + Evas_Textblock_Cursor cur2; int x = 0, y = 0, w = 0, h = 0; int pos, ret; + int previous_format = 0; if (!cur) return -1; o = (Evas_Object_Textblock *)(cur->obj->object_data); @@ -6255,6 +6277,15 @@ evas_textblock_cursor_char_geometry_get(const Evas_Textblock_Cursor *cur, Evas_C return -1; } if (!o->formatted.valid) _relayout(cur->obj); + + /* Cur 2 is pointing to the previous char */ + cur2.obj = cur->obj; + evas_textblock_cursor_copy(cur, &cur2); + if (cur2.pos > 0) + { + cur2.pos--; + } + if (evas_textblock_cursor_format_is_visible_get(cur)) { _find_layout_format_item_line_match(cur->obj, @@ -6262,15 +6293,20 @@ evas_textblock_cursor_char_geometry_get(const Evas_Textblock_Cursor *cur, Evas_C _evas_textblock_cursor_node_format_at_pos_get(cur)), &ln, &fi); } - else + else if (_evas_textblock_cursor_is_at_the_end(cur) && + evas_textblock_cursor_format_is_visible_get(&cur2)) { - _find_layout_item_line_match(cur->obj, cur->node, cur->pos, &ln, &it); + _find_layout_format_item_line_match(cur->obj, + _evas_textblock_node_visible_at_pos_get( + _evas_textblock_cursor_node_format_at_pos_get(&cur2)), + &ln, &fi); + previous_format = 1; } - if (!ln) + else { - return -1; + _find_layout_item_line_match(cur->obj, cur->node, cur->pos, &ln, &it); } - if (it) + if (ln && it) { pos = cur->pos - it->source_pos; ret = -1; @@ -6301,12 +6337,31 @@ evas_textblock_cursor_char_geometry_get(const Evas_Textblock_Cursor *cur, Evas_C y = ln->y; h = ln->h; } - else if (fi) + else if (ln && fi) { - x = ln->x + fi->x; - y = ln->y; - w = fi->w; - h = ln->h; + if (previous_format) + { + if (_IS_LINE_SEPARATOR( + eina_strbuf_string_get(fi->source_node->format))) + { + x = 0; + y = ln->y + ln->h; + } + else + { + x = ln->x + fi->x + fi->w; + y = ln->y; + } + w = 0; + h = ln->h; + } + else + { + x = ln->x + fi->x; + y = ln->y; + w = fi->w; + h = ln->h; + } } else {