diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am index 28a42ae5de..026c19e615 100644 --- a/src/Makefile_Evas.am +++ b/src/Makefile_Evas.am @@ -101,12 +101,12 @@ lib/evas/Evas.h \ lib/evas/Evas_Common.h \ lib/evas/Evas_Eo.h \ lib/evas/Evas_Legacy.h \ -lib/evas/Evas_Textblock_Legacy.h \ lib/evas/Evas_GL.h \ lib/evas/Evas_Loader.h installed_evascanvasheadersdir = $(includedir)/evas-@VMAJ@/canvas nodist_installed_evascanvasheaders_DATA = $(evas_eolian_pub_h) $(evas_eolian_legacy_h) +dist_installed_evascanvasheaders_DATA = lib/evas/canvas/evas_textblock_legacy.h noinst_DATA += $(evas_eolian_priv_h) noinst_HEADERS += \ diff --git a/src/lib/evas/Evas_Legacy.h b/src/lib/evas/Evas_Legacy.h index 9f982ad4d5..7ca908065f 100644 --- a/src/lib/evas/Evas_Legacy.h +++ b/src/lib/evas/Evas_Legacy.h @@ -4496,7 +4496,7 @@ EAPI void evas_object_text_font_get(const Eo *obj, const char **font, Evas_Font_ * @} */ -#include "Evas_Textblock_Legacy.h" +#include "canvas/evas_textblock_legacy.h" /** * @ingroup Evas_Object_Grid diff --git a/src/lib/evas/canvas/efl_canvas_text.eo b/src/lib/evas/canvas/efl_canvas_text.eo index 1bb2328e66..42925e79c2 100644 --- a/src/lib/evas/canvas/efl_canvas_text.eo +++ b/src/lib/evas/canvas/efl_canvas_text.eo @@ -4,21 +4,6 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) { legacy_prefix: evas_object_textblock; methods { - @property valign { - [[The vertical alignment of text within the textblock object as a whole. - - Normally alignment is 0.0 (top of object). Values given should - be between 0.0 and 1.0 (1.0 bottom of object, 0.5 being - vertically centered etc.). - - @since 1.1 - ]] - set {} - get {} - values { - align: double; [[The alignment set for the object.]] - } - } @property bidi_delimiters { [[BiDi delimiters are used for in-paragraph separation of bidi segments. This is useful for example in recipients fields of @@ -33,14 +18,6 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) delim: string; [[A null terminated string of delimiters, e.g ",|" or $null if empty.]] } } - @property replace_char { - [[The "replacement character" to use for the given textblock object.]] - set {} - get {} - values { - ch: string; [[The charset name.]] - } - } @property legacy_newline { [[When true, newline character will behave as a paragraph separator. @@ -53,15 +30,27 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) } } @property style { - [[The text style of the object]] + [[The text style of the object. + + $key is how you reference the style (for deletion or fetching). $NULL + as key indicates the style has the highest priority (default style). + The style priority is the order of creation, styles created first + are applied first with the exception of $NULL which is implicitly + first. + + Set $style to $NULL to delete it. + ]] set { legacy: null; } get { legacy: null; } + keys { + key: string; [[The name to the style. $NULL is the default style]] + } values { - ts: string; [[The style.]] + style: string; [[The style.]] } } @property size_formatted { @@ -127,42 +116,13 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) b: Evas.Coord; } } - style_user_pop { - [[Del the from the top of the user style stack. - - See also @.style.get. - - @since 1.2 - ]] - legacy: null; - } - style_user_peek @const { - [[Get (don't remove) the style at the top of the user style stack. - - See also @.style.get. - - @since 1.2 - ]] - legacy: null; - return: string; [[The style of the object.]] - } - style_user_push { - [[Push ts to the top of the user style stack. - - FIXME: API is solid but currently only supports 1 style in the - stack. - - The user style overrides the corresponding elements of the - regular style. This is the proper way to do theme overrides - in code. - - See also @.style.set. - - @since 1.2 - ]] - legacy: null; - params { - @in style: string; [[The style to set.]] + @property is_empty { + [[Whether the object is empty (no text) or not]] + get { + legacy: null; + } + values { + is_empty: bool; [[$true if empty]] } } obstacle_add { @@ -229,7 +189,7 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) format: string; } } - annotation_in_range_get { + range_annotations_get { [[Returns an iterator of all the handles in a range. @since 1.18 @@ -309,6 +269,30 @@ class Efl.Canvas.Text (Evas.Object, Efl.Text) @in end: Efl.Canvas.Text.Cursor; [[Range end position.]] } } + range_text_get { + [[Returns the text in the range between $cur1 and $cur2.]] + legacy: null; + return: own(char*); [[The text in the given range.]] + params { + @in cur1: const(Efl.Canvas.Text.Cursor); [[Range start position.]] + @in cur2: const(Efl.Canvas.Text.Cursor); [[Range end position.]] + } + } + object_item_geometry_get { + [[Queries a given object item for its geometry + + Note that the provided annotation should be an object item type. + ]] + legacy: null; + params { + @in an: const(Efl.Canvas.Text.Annotation)*; [[Given annotation to query]] + @out x: Evas.Coord; + @out y: Evas.Coord; + @out w: Evas.Coord; + @out h: Evas.Coord; + } + return: bool; [[$true if given annotation is an object item, $false otherwise]] + } } implements { Eo.Base.constructor; diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index c9464fc96d..2b422bd069 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -475,6 +475,7 @@ struct _Efl_Canvas_Text_Style { const char *style_text; char *default_tag; + Eina_Stringshare *key; /* FIXME: Very hacky. */ Evas_Object_Style_Tag *tags; Eina_List *objects; Eina_Bool delete_me : 1; @@ -503,9 +504,7 @@ struct _Efl_Canvas_Text_Annotation struct _Evas_Object_Textblock { Evas_Textblock_Style *style; - Evas_Textblock_Style *style_user; - Evas_Textblock_Style *current_style; - Evas_Textblock_Style *current_user_style; + Eina_List *styles; Eo *cursor; Eina_List *cursors; Evas_Object_Textblock_Node_Text *text_nodes; @@ -1178,6 +1177,7 @@ static const char *backing_colorstr = NULL; static const char *strikethrough_colorstr = NULL; static const char *alignstr = NULL; static const char *valignstr = NULL; +static const char *text_valignstr = NULL; static const char *wrapstr = NULL; static const char *left_marginstr = NULL; static const char *right_marginstr = NULL; @@ -1194,6 +1194,7 @@ static const char *itemstr = NULL; static const char *linefillstr = NULL; static const char *ellipsisstr = NULL; static const char *passwordstr = NULL; +static const char *replacement_charstr = NULL; static const char *underline_dash_widthstr = NULL; static const char *underline_dash_gapstr = NULL; static const char *underline_heightstr = NULL; @@ -1281,6 +1282,7 @@ _format_command_init(void) strikethrough_colorstr = eina_stringshare_add("strikethrough_color"); alignstr = eina_stringshare_add("align"); valignstr = eina_stringshare_add("valign"); + text_valignstr = eina_stringshare_add("text_valign"); wrapstr = eina_stringshare_add("wrap"); left_marginstr = eina_stringshare_add("left_margin"); right_marginstr = eina_stringshare_add("right_margin"); @@ -1297,6 +1299,7 @@ _format_command_init(void) linefillstr = eina_stringshare_add("linefill"); ellipsisstr = eina_stringshare_add("ellipsis"); passwordstr = eina_stringshare_add("password"); + replacement_charstr = eina_stringshare_add("replacement_char"); underline_dash_widthstr = eina_stringshare_add("underline_dash_width"); underline_dash_gapstr = eina_stringshare_add("underline_dash_gap"); underline_heightstr = eina_stringshare_add("underline_height"); @@ -1333,6 +1336,7 @@ _format_command_shutdown(void) eina_stringshare_del(strikethrough_colorstr); eina_stringshare_del(alignstr); eina_stringshare_del(valignstr); + eina_stringshare_del(text_valignstr); eina_stringshare_del(wrapstr); eina_stringshare_del(left_marginstr); eina_stringshare_del(right_marginstr); @@ -1349,6 +1353,7 @@ _format_command_shutdown(void) eina_stringshare_del(linefillstr); eina_stringshare_del(ellipsisstr); eina_stringshare_del(passwordstr); + eina_stringshare_del(replacement_charstr); eina_stringshare_del(underline_dash_widthstr); eina_stringshare_del(underline_dash_gapstr); eina_stringshare_del(underline_heightstr); @@ -1894,6 +1899,15 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch else if (fmt->valign > 1.0) fmt->valign = 1.0; } } + else if (cmd == text_valignstr) + { + Efl_Canvas_Text_Data *o = eo_data_scope_get(eo_obj, MY_CLASS); + char *endptr = NULL; + double val = strtod(param, &endptr); + o->valign = val; + if (o->valign < 0.0) o->valign = 0.0; + else if (o->valign > 1.0) o->valign = 1.0; + } else if (cmd == wrapstr) { /** @@ -2382,6 +2396,11 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch else if (len == 2 && !strcmp(param, "on")) fmt->password = 1; } + else if (cmd == replacement_charstr) + { + Efl_Canvas_Text_Data *o = eo_data_scope_get(eo_obj, MY_CLASS); + eina_stringshare_replace(&o->repch, param); + } else if (cmd == underline_dash_widthstr) { /** @@ -6007,6 +6026,8 @@ _layout(const Evas_Object *eo_obj, int w, int h, int *w_ret, int *h_ret) /* Start of logical layout creation */ /* setup default base style */ { + Eina_List *itr; + Evas_Textblock_Style *style; Eina_Bool finalize = EINA_FALSE; if ((c->o->style) && (c->o->style->default_tag)) { @@ -6015,14 +6036,17 @@ _layout(const Evas_Object *eo_obj, int w, int h, int *w_ret, int *h_ret) finalize = EINA_TRUE; } - if ((c->o->style_user) && (c->o->style_user->default_tag)) + EINA_LIST_FOREACH(c->o->styles, itr, style) { - if (!c->fmt) + if ((style) && (style->default_tag)) { - c->fmt = _layout_format_push(c, NULL, NULL); + if (!c->fmt) + { + c->fmt = _layout_format_push(c, NULL, NULL); + } + _format_fill(c->obj, c->fmt, style->default_tag); + finalize = EINA_TRUE; } - _format_fill(c->obj, c->fmt, c->o->style_user->default_tag); - finalize = EINA_TRUE; } if (finalize) @@ -6346,6 +6370,7 @@ evas_textblock_style_free(Evas_Textblock_Style *ts) return; } _style_clear(ts); + eina_stringshare_del(ts->key); free(ts); } @@ -6502,10 +6527,18 @@ evas_textblock_style_get(const Evas_Textblock_Style *ts) static const char * _textblock_format_node_from_style_tag(Efl_Canvas_Text_Data *o, Evas_Object_Textblock_Node_Format *fnode, const char *format, size_t format_len) { - const char *match; + Eina_List *itr; + Evas_Textblock_Style *style; + const char *match = NULL; size_t replace_len; - if (!o->style_user || !(match = _style_match_tag(o->style_user, format, - format_len, &replace_len))) + EINA_LIST_REVERSE_FOREACH(o->styles, itr, style) + { + match = _style_match_tag(style, format, format_len, &replace_len); + if (match) + break; + } + + if (!match) { match = _style_match_tag(o->style, format, format_len, &replace_len); @@ -6597,23 +6630,74 @@ evas_object_textblock_style_set(Eo *eo_obj, const Evas_Textblock_Style *ts) _textblock_style_generic_set(eo_obj, (Evas_Textblock_Style *) ts, &(o->style)); } -EOLIAN static void -_efl_canvas_text_style_set(Eo *eo_obj, Efl_Canvas_Text_Data *o, const char *style) +static Evas_Textblock_Style * +_style_by_key_find(Efl_Canvas_Text_Data *o, const char *key) { + Eina_List *itr; + Evas_Textblock_Style *style; + + if (!key) + return o->style; + + EINA_LIST_FOREACH(o->styles, itr, style) + { + if (!strcmp(style->key, key)) + return style; + } + + return NULL; +} + +EOLIAN static void +_efl_canvas_text_style_set(Eo *eo_obj, Efl_Canvas_Text_Data *o, const char *key, const char *style) +{ + // FIXME: Make key value behaviour. Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); - if (!o->current_style) + Evas_Textblock_Style *ts; + + ts = _style_by_key_find(o, key); + + if (!ts && !style) + return; + + if (ts && !style) { - Evas_Textblock_Style *ts = evas_textblock_style_new(); - evas_textblock_style_set(ts, style); - _textblock_style_generic_set(eo_obj, (Evas_Textblock_Style *) ts, &(o->style)); - o->current_style = ts; + if (!key) + { + evas_textblock_style_set(ts, ""); + } + else + { + o->styles = eina_list_remove(o->styles, ts); + evas_textblock_style_free(ts); + } + + goto end; + } + else if (!ts) + { + Evas_Textblock_Style *tmp = NULL; + ts = evas_textblock_style_new(); + _textblock_style_generic_set(eo_obj, ts, &tmp); + } + + evas_textblock_style_set(ts, style); + + if (!key) + { + o->style = ts; } else { - evas_textblock_style_set(o->current_style, style); + ts->key = eina_stringshare_add(key); + o->styles = eina_list_append(o->styles, ts); } +end: + o->format_changed = EINA_TRUE; + _evas_textblock_invalidate_all(o); + _evas_textblock_changed(o, eo_obj); } EAPI Evas_Textblock_Style * @@ -6626,37 +6710,31 @@ evas_object_textblock_style_get(const Eo *eo_obj EINA_UNUSED) } EOLIAN static const char * -_efl_canvas_text_style_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o) +_efl_canvas_text_style_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o, const char *key) { - return o->style->style_text; + Evas_Textblock_Style *ts = _style_by_key_find(o, key); + + return ts->style_text; } +#define _STYLE_USER "_style_user" EAPI void evas_object_textblock_style_user_push(Eo *eo_obj, Evas_Textblock_Style *ts) { - Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); - evas_object_async_block(obj); Efl_Canvas_Text_Data *o = eo_data_scope_get(eo_obj, MY_CLASS); - _textblock_style_generic_set(eo_obj, ts, &(o->style_user)); -} - -EOLIAN static void -_efl_canvas_text_style_user_push(Eo *eo_obj, Efl_Canvas_Text_Data *o, const char *style) -{ Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); - if (!o->current_user_style) + Evas_Textblock_Style *old_ts = _style_by_key_find(o, _STYLE_USER); + + if (old_ts) { - Evas_Textblock_Style *ts = evas_textblock_style_new(); - evas_textblock_style_set(ts, style); - _textblock_style_generic_set(eo_obj, (Evas_Textblock_Style *) ts, &(o->style_user)); - o->current_user_style = ts; - } - else - { - evas_textblock_style_set(o->current_user_style, style); + efl_canvas_text_style_set(eo_obj, _STYLE_USER, NULL); } + Evas_Textblock_Style *tmp = NULL; + _textblock_style_generic_set(eo_obj, ts, &tmp); + ts->key = eina_stringshare_add(_STYLE_USER); + o->styles = eina_list_append(o->styles, ts); } EAPI const Evas_Textblock_Style* @@ -6665,13 +6743,8 @@ evas_object_textblock_style_user_peek(const Eo *eo_obj) Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); Efl_Canvas_Text_Data *o = eo_data_scope_get(eo_obj, MY_CLASS); - return o->style_user; -} - -EOLIAN static const char * -_efl_canvas_text_style_user_peek(const Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o) -{ - return o->style_user ? o->style_user->style_text : NULL; + Evas_Textblock_Style *ts = _style_by_key_find(o, _STYLE_USER); + return ts; } EAPI void @@ -6679,30 +6752,14 @@ evas_object_textblock_style_user_pop(Eo *eo_obj) { Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); + + efl_canvas_text_style_set(eo_obj, _STYLE_USER, NULL); +} + +EAPI void +evas_object_textblock_replace_char_set(Efl_Canvas_Text *eo_obj, const char *ch) +{ Efl_Canvas_Text_Data *o = eo_data_scope_get(eo_obj, MY_CLASS); - _textblock_style_generic_set(eo_obj, NULL, &(o->style_user)); -} - -EOLIAN static void -_efl_canvas_text_style_user_pop(Eo *eo_obj, Efl_Canvas_Text_Data *o) -{ - Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); - evas_object_async_block(obj); - _textblock_style_generic_set(eo_obj, NULL, &(o->style_user)); - if (o->current_user_style) - { - // XXX: remember that the current implementation of user style is still - // lacking as we don't really manage a stack. - // Until that's fixed, we are treating it as there can be only one - // user style. - evas_textblock_style_free(o->current_user_style); - o->current_user_style = NULL; - } -} - -EOLIAN static void -_efl_canvas_text_replace_char_set(Eo *eo_obj, Efl_Canvas_Text_Data *o, const char *ch) -{ Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); if (o->repch) eina_stringshare_del(o->repch); @@ -6712,6 +6769,7 @@ _efl_canvas_text_replace_char_set(Eo *eo_obj, Efl_Canvas_Text_Data *o, const cha _evas_textblock_changed(o, eo_obj); } + EOLIAN static void _efl_canvas_text_legacy_newline_set(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o, Eina_Bool mode) { @@ -6731,9 +6789,16 @@ _efl_canvas_text_legacy_newline_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data return o->legacy_newline; } -EOLIAN static void -_efl_canvas_text_valign_set(Eo *eo_obj, Efl_Canvas_Text_Data *o, double align) +EOLIAN static Eina_Bool +_efl_canvas_text_is_empty_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o) { + return !o->text_nodes || (eina_ustrbuf_length_get(o->text_nodes->unicode) == 0); +} + +EAPI void +evas_object_textblock_valign_set(Efl_Canvas_Text *eo_obj, double align) +{ + Efl_Canvas_Text_Data *o = eo_data_scope_get(eo_obj, MY_CLASS); Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); if (align < 0.0) align = 0.0; @@ -6743,9 +6808,10 @@ _efl_canvas_text_valign_set(Eo *eo_obj, Efl_Canvas_Text_Data *o, double align) _evas_textblock_changed(o, eo_obj); } -EOLIAN static double -_efl_canvas_text_valign_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o) +EAPI double +evas_object_textblock_valign_get(const Efl_Canvas_Text *obj) { + Efl_Canvas_Text_Data *o = eo_data_scope_get(obj, MY_CLASS); return o->valign; } @@ -6763,9 +6829,10 @@ _efl_canvas_text_bidi_delimiters_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Dat return o->bidi_delimiters; } -EOLIAN static const char* -_efl_canvas_text_replace_char_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o) +EAPI const char * +evas_object_textblock_replace_char_get(const Efl_Canvas_Text *obj) { + Efl_Canvas_Text_Data *o = eo_data_scope_get(obj, MY_CLASS); return o->repch; } @@ -10126,26 +10193,32 @@ evas_textblock_cursor_format_append(Evas_Textblock_Cursor *cur_obj, const char * return _evas_textblock_cursor_format_append(cur, format, NULL, EINA_FALSE); } -EAPI Eina_Bool -evas_textblock_cursor_format_prepend(Evas_Textblock_Cursor *cur_obj, const char *format) +static Eina_Bool +_evas_textblock_cursor_format_prepend(Efl_Canvas_Text_Cursor_Data *cur, const char *format) { Eina_Bool is_visible; - Efl_Canvas_Text_Cursor_Data *cur = eo_data_scope_get(cur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); if (!cur) return EINA_FALSE; Evas_Object_Protected_Data *obj = eo_data_scope_get(cur->obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); /* append is essentially prepend without advancing */ - is_visible = evas_textblock_cursor_format_append(cur_obj, format); + is_visible = _evas_textblock_cursor_format_append(cur, format, NULL, EINA_FALSE); if (is_visible) { /* Advance after the replacement char */ - evas_textblock_cursor_char_next(cur_obj); + _evas_textblock_cursor_char_next(cur); } return is_visible; } +EAPI Eina_Bool +evas_textblock_cursor_format_prepend(Evas_Textblock_Cursor *cur_obj, const char *format) +{ + Efl_Canvas_Text_Cursor_Data *cur = eo_data_scope_get(cur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); + return _evas_textblock_cursor_format_prepend(cur, format); +} + static void _evas_textblock_cursor_char_delete(Efl_Canvas_Text_Cursor_Data *cur) { @@ -10647,6 +10720,7 @@ _evas_textblock_cursor_range_text_get(const Efl_Canvas_Text_Cursor_Data *cur1, c return NULL; /* Not yet supported */ } + EAPI char * evas_textblock_cursor_range_text_get(const Efl_Canvas_Text_Cursor *cur1_obj, const Evas_Textblock_Cursor *cur2_obj, Evas_Textblock_Text_Type format) { @@ -10655,6 +10729,17 @@ evas_textblock_cursor_range_text_get(const Efl_Canvas_Text_Cursor *cur1_obj, con return _evas_textblock_cursor_range_text_get(cur1, cur2, format); } +static EOLIAN char * +_efl_canvas_text_range_text_get(Eo *eo_obj EINA_UNUSED, + Efl_Canvas_Text_Data *pd EINA_UNUSED, + const Efl_Canvas_Text_Cursor *cur1_obj, + const Evas_Textblock_Cursor *cur2_obj) +{ + const Efl_Canvas_Text_Cursor_Data *cur1 = eo_data_scope_get(cur1_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); + const Efl_Canvas_Text_Cursor_Data *cur2 = eo_data_scope_get(cur2_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); + return _evas_textblock_cursor_range_text_get(cur1, cur2, EVAS_TEXTBLOCK_TEXT_PLAIN); +} + EAPI const char * evas_textblock_cursor_paragraph_text_get(const Evas_Textblock_Cursor *cur_obj) { @@ -12048,15 +12133,14 @@ evas_textblock_cursor_range_geometry_get(const Efl_Canvas_Text_Cursor *cur1_obj, return rects; } -EAPI Eina_Bool -evas_textblock_cursor_format_item_geometry_get(const Evas_Textblock_Cursor *cur_obj, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch) +static Eina_Bool +_evas_textblock_cursor_format_item_geometry_get(const Efl_Canvas_Text_Cursor_Data *cur, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch) { Evas_Object_Textblock_Line *ln = NULL; Evas_Object_Textblock_Format_Item *fi; Evas_Object_Textblock_Item *it = NULL; Evas_Coord x, y, w, h; - Efl_Canvas_Text_Cursor_Data *cur = eo_data_scope_get(cur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); if (!cur || !_evas_textblock_cursor_format_is_visible_get(cur)) return EINA_FALSE; Evas_Object_Protected_Data *obj = eo_data_scope_get(cur->obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); @@ -12080,6 +12164,13 @@ evas_textblock_cursor_format_item_geometry_get(const Evas_Textblock_Cursor *cur_ return EINA_TRUE; } +EAPI Eina_Bool +evas_textblock_cursor_format_item_geometry_get(const Evas_Textblock_Cursor *cur_obj, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch) +{ + Efl_Canvas_Text_Cursor_Data *cur = eo_data_scope_get(cur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); + return _evas_textblock_cursor_format_item_geometry_get(cur, cx, cy, cw, ch); +} + EAPI Eina_Bool evas_textblock_cursor_eol_get(const Evas_Textblock_Cursor *cur_obj) { @@ -12558,12 +12649,6 @@ evas_object_textblock_free(Evas_Object *eo_obj) _dicts_hyphen_detach(eo_obj); } #endif - - /* free the style if exists */ - if (o->current_style) - { - evas_textblock_style_free(o->current_style); - } } static void @@ -13447,9 +13532,9 @@ _efl_canvas_text_cursor_text_append(Efl_Canvas_Text_Cursor_Data *cur, /* We make use of prepending the cursor, but this needs to return the current * position's cursor, so we use a temporary one. */ - Evas_Textblock_Cursor *cur2_obj = evas_object_textblock_cursor_new (cur->obj); - Efl_Canvas_Text_Cursor_Data *cur2 = eo_data_scope_get(cur2_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); - _evas_textblock_cursor_copy(cur2, cur); + Efl_Canvas_Text_Cursor_Data cur2; + _evas_textblock_cursor_init(&cur2, cur->obj); + _evas_textblock_cursor_copy(&cur2, cur); Evas_Object_Protected_Data *obj = eo_data_scope_get(cur->obj, EVAS_OBJECT_CLASS); evas_object_async_block(obj); @@ -13472,8 +13557,8 @@ _efl_canvas_text_cursor_text_append(Efl_Canvas_Text_Cursor_Data *cur, if (format) { - len += _prepend_text_run2(cur2, text, off); - if (evas_textblock_cursor_format_prepend(cur2_obj, format)) + len += _prepend_text_run2(&cur2, text, off); + if (_evas_textblock_cursor_format_prepend(&cur2, format)) { len++; } @@ -13481,8 +13566,7 @@ _efl_canvas_text_cursor_text_append(Efl_Canvas_Text_Cursor_Data *cur, } off += n; } - len += _prepend_text_run2(cur2, text, off); - eo_del(cur2_obj); + len += _prepend_text_run2(&cur2, text, off); return len; } @@ -13490,13 +13574,11 @@ EOLIAN static void _efl_canvas_text_efl_text_text_set(Eo *eo_obj, Efl_Canvas_Text_Data *o EINA_UNUSED, const char *text) { - Evas_Textblock_Cursor *cur_obj; + Efl_Canvas_Text_Cursor_Data cur; evas_object_textblock_text_markup_set(eo_obj, ""); - cur_obj = evas_object_textblock_cursor_new(eo_obj); - Efl_Canvas_Text_Cursor_Data *cur = eo_data_scope_get(cur_obj, EFL_CANVAS_TEXT_CURSOR_CLASS); - _efl_canvas_text_cursor_text_append(cur, text); - eo_del(cur_obj); + _evas_textblock_cursor_init(&cur, eo_obj); + _efl_canvas_text_cursor_text_append(&cur, text); } EOLIAN static const char * @@ -13861,7 +13943,7 @@ _efl_canvas_text_annotation_insert(Eo *eo_obj, Efl_Canvas_Text_Data *o, } EOLIAN static Eina_Iterator * -_efl_canvas_text_annotation_in_range_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o EINA_UNUSED, +_efl_canvas_text_range_annotations_get(Eo *eo_obj EINA_UNUSED, Efl_Canvas_Text_Data *o EINA_UNUSED, const Evas_Textblock_Cursor *start_obj, const Evas_Textblock_Cursor *end_obj) { Eina_List *lst = NULL; @@ -13906,7 +13988,7 @@ _efl_canvas_text_cursor_object_item_annotation_get(Eo *cur_obj EINA_UNUSED, Eina_Iterator *it; Efl_Canvas_Text_Annotation *data, *ret = NULL; - it = efl_canvas_text_annotation_in_range_get(cur->obj, + it = efl_canvas_text_range_annotations_get(cur->obj, cur_obj, cur_obj); EINA_ITERATOR_FOREACH(it, data) { @@ -13920,6 +14002,21 @@ _efl_canvas_text_cursor_object_item_annotation_get(Eo *cur_obj EINA_UNUSED, return ret; } +EOLIAN static Eina_Bool +_efl_canvas_text_object_item_geometry_get(Eo *eo_obj, Efl_Canvas_Text_Data *o EINA_UNUSED, + const Efl_Canvas_Text_Annotation *an, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch) +{ + Efl_Canvas_Text_Cursor_Data cur; + + Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); + evas_object_async_block(obj); + _relayout_if_needed(eo_obj, o); + + _evas_textblock_cursor_init(&cur, eo_obj); + _textblock_cursor_pos_at_fnode_set(eo_obj, &cur, an->start_node); + return _evas_textblock_cursor_format_item_geometry_get(&cur, cx, cy, cw, ch); +} + /** * @} */ diff --git a/src/lib/evas/Evas_Textblock_Legacy.h b/src/lib/evas/canvas/evas_textblock_legacy.h similarity index 96% rename from src/lib/evas/Evas_Textblock_Legacy.h rename to src/lib/evas/canvas/evas_textblock_legacy.h index 8c6d52fb61..3179a76f01 100644 --- a/src/lib/evas/Evas_Textblock_Legacy.h +++ b/src/lib/evas/canvas/evas_textblock_legacy.h @@ -860,6 +860,54 @@ EAPI void evas_textblock_cursor_free(Evas_Textblock_Cursor *cur); EAPI int evas_textblock_cursor_text_append(Evas_Textblock_Cursor *cur, const char *_text); +/** + * @brief The "replacement character" to use for the given textblock object. + * + * @param[in] ch The charset name. + * + * @ingroup Efl_Canvas_Text + */ +EAPI void evas_object_textblock_replace_char_set(Evas_Object *obj, const char *ch); + +/** + * @brief The "replacement character" to use for the given textblock object. + * + * @return The charset name. + * + * @ingroup Efl_Canvas_Text + */ +EAPI const char *evas_object_textblock_replace_char_get(const Evas_Object *obj); + +/** + * @brief The vertical alignment of text within the textblock object as a + * whole. + * + * Normally alignment is 0.0 (top of object). Values given should be between + * 0.0 and 1.0 (1.0 bottom of object, 0.5 being vertically centered etc.). + * + * @param[in] align The alignment set for the object. + * + * @since 1.1 + * + * @ingroup Efl_Canvas_Text + */ +EAPI void evas_object_textblock_valign_set(Evas_Object *obj, double align); + +/** + * @brief The vertical alignment of text within the textblock object as a + * whole. + * + * Normally alignment is 0.0 (top of object). Values given should be between + * 0.0 and 1.0 (1.0 bottom of object, 0.5 being vertically centered etc.). + * + * @return The alignment set for the object. + * + * @since 1.1 + * + * @ingroup Efl_Canvas_Text + */ +EAPI double evas_object_textblock_valign_get(const Evas_Object *obj); + #include "canvas/efl_canvas_text_cursor.eo.legacy.h" #include "canvas/efl_canvas_text.eo.legacy.h" /** diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index 6be9c385cf..a507fd34d8 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -4058,7 +4058,7 @@ _test_check_annotation(Evas_Object *tb, evas_textblock_cursor_pos_set(end, end_pos); Eina_Iterator *it = - efl_canvas_text_annotation_in_range_get(tb, start, end); + efl_canvas_text_range_annotations_get(tb, start, end); evas_textblock_cursor_free(start); evas_textblock_cursor_free(end); @@ -4277,51 +4277,34 @@ START_TEST(efl_canvas_text_style) { START_TB_TEST(); - Eo *start, *end; - Evas_Coord w; Evas_Coord bw; const char *buf; - buf = - "DEFAULT='font=Sans font_size=12 color=#fff wrap=word text_class=entry'" - "br='\n'" - "ps='ps'" - "tab='\t'"; + buf = "DEFAULT='font=Sans font_size=12 color=#fff wrap=word'"; efl_canvas_text_style_set(tb, buf); ck_assert_str_eq(efl_canvas_text_style_get(tb), buf); - buf = - "DEFAULT='font=Sans font_size=12 color=#fff'" - "c='color=#000'" - "ps='br'" - "tab='\t'"; + buf = "font=Sans font_size=12 color=#fff"; efl_canvas_text_style_set(tb, buf); ck_assert_str_eq(efl_canvas_text_style_get(tb), buf); efl_text_set(tb, "hello world"); - start = evas_object_textblock_cursor_new(tb); - end = evas_object_textblock_cursor_new(tb); - evas_textblock_cursor_pos_set(start, 0); - evas_textblock_cursor_pos_set(end, 4); - efl_canvas_text_annotation_insert(tb, start, end, "sz"); - buf = - "DEFAULT='font=Sans font_size=12 color=#fff'"; + buf = "font=Sans font_size=12 color=#fff"; efl_canvas_text_style_set(tb, buf); evas_object_textblock_size_native_get(tb, &bw, NULL); - buf = - "DEFAULT='font=Sans font_size=16 color=#fff'"; + buf = "font=Sans font_size=16 color=#fff"; efl_canvas_text_style_set(tb, buf); evas_object_textblock_size_native_get(tb, &w, NULL); ck_assert_int_gt(w, bw); bw = w; - buf = "DEFAULT='left_margin=4 right_margin=4'"; + buf = "left_margin=4 right_margin=4"; efl_canvas_text_style_user_push(tb, buf); ck_assert_str_eq(efl_canvas_text_style_user_peek(tb), buf); evas_object_textblock_size_native_get(tb, &w, NULL);