e_view_textblock : Add textblock interface 73/325573/1
authorjinbong.lee <jinbong.lee@samsung.com>
Tue, 27 May 2025 06:56:14 +0000 (15:56 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Thu, 12 Jun 2025 08:25:50 +0000 (17:25 +0900)
 - split textblock interface from e_view_text
 - add new interface for textblock

Change-Id: Ia2b05e9d5f92ad25433ce3714fb298eea384a40c
Signed-off-by: jinbong.lee <jinbong.lee@samsung.com>
src/bin/Makefile.mk
src/bin/core/e_view_intern.h
src/bin/core/e_view_text.c
src/bin/core/e_view_textblock.c [new file with mode: 0755]
src/include/e_view_text.h
src/include/e_view_textblock.h [new file with mode: 0755]

index 48a0ece7ec0be46ba8712b465b43ef0c5be2ad56..0c4b8c79ac4fa9e6e591b65c406419abd07082d0 100644 (file)
@@ -130,6 +130,7 @@ src/include/e_view_edje.h \
 src/include/e_view_layout.h \
 src/include/e_blur_video_capture.h \
 src/include/e_view_text.h \
+src/include/e_view_textblock.h \
 src/include/e_seat.h
 
 enlightenment_src = \
@@ -157,6 +158,7 @@ src/bin/core/e_view_event.c \
 src/bin/core/e_view_layout.c \
 src/bin/core/e_device.c \
 src/bin/core/e_view_text.c \
+src/bin/core/e_view_textblock.c \
 src/bin/server/e_compositor.c \
 src/bin/server/e_comp_wl.c \
 src/bin/server/e_comp_wl_data.c \
index 0b17b8f9125419d01b9edfc881674e10dc1cc6bc..61c2b9e67e05ec6bfe628f096f8093ad74342951 100644 (file)
@@ -23,6 +23,7 @@ typedef enum {
      E_VIEW_TYPE_CLIENT,
      E_VIEW_TYPE_EDJE,
      E_VIEW_TYPE_TEXT,
+     E_VIEW_TYPE_TEXTBLOCK,
 } E_View_Type;
 
 struct _E_View_Impl
index 0babe934cde47e80d17178e7433a5c023cb3c961..5e2c2972bc53d26e9a475dbf54e903f41ff996d2 100644 (file)
@@ -202,88 +202,3 @@ e_view_text_text_get(E_View_Text *text)
 
    return evas_object_text_text_get(text->view.eo);
 }
-
-E_API E_View_Text *
-e_view_textblock_create(E_View_Tree *parent)
-{
-   E_Canvas *canvas;
-   E_View_Text *text;
-   Evas_Object *eo;
-
-   assert(parent != NULL);
-
-   text = malloc(sizeof(*text));
-   if (!text)
-     return NULL;
-
-   canvas = e_canvas_get(&parent->view);
-   eo = evas_object_textblock_add(canvas->evas);
-   if (!eo)
-     {
-        free(text);
-        return NULL;
-     }
-
-   e_view_init(&text->view, E_VIEW_TYPE_TEXT, (E_View_Impl*)&view_text_impl, eo, parent);
-
-   wl_signal_init(&text->events.resize);
-
-   evas_object_event_callback_add(text->view.eo, EVAS_CALLBACK_RESIZE, _view_text_evas_object_cb_resize, text);
-
-   return text;
-}
-
-E_API void
-e_view_textblock_style_set(E_View_Text *text, char *style)
-{
-   Evas_Textblock_Style *st;
-
-   if (text == NULL) return;
-
-   st = evas_textblock_style_new();
-
-   evas_textblock_style_set(st, style);
-   evas_object_textblock_style_set(text->view.eo, st);
-
-   evas_textblock_style_free(st);
-}
-
-E_API void
-e_view_textblock_text_markup_set(E_View_Text *text, char *markup)
-{
-   if (text == NULL) return;
-
-   evas_object_textblock_text_markup_set(text->view.eo, markup);
-}
-
-E_API char *
-e_view_textblock_text_utf8_to_markup(E_View_Text *text, char *markup)
-{
-   if (text == NULL) return NULL;
-
-   return evas_textblock_text_utf8_to_markup(text->view.eo, markup);
-}
-
-E_API void
-e_view_textblock_valign_set(E_View_Text *text, double valign)
-{
-   if (text == NULL) return;
-
-   evas_object_textblock_valign_set(text->view.eo, valign);
-}
-
-E_API void
-e_view_textblock_size_formatted_get(E_View_Text *text, int *width, int *height)
-{
-   if (text == NULL) return;
-
-   evas_object_textblock_size_formatted_get(text->view.eo, width, height);
-}
-
-E_API void
-e_view_textblock_line_number_geometry_get(E_View_Text *text, int line_num, int *x, int *y, int *width, int *height)
-{
-   if (text == NULL) return;
-
-   evas_object_textblock_line_number_geometry_get(text->view.eo, line_num, x, y, width, height);
-}
diff --git a/src/bin/core/e_view_textblock.c b/src/bin/core/e_view_textblock.c
new file mode 100755 (executable)
index 0000000..e19cc9c
--- /dev/null
@@ -0,0 +1,206 @@
+#include "e_intern.h"
+#include "e_view_intern.h"
+#include "e_view_textblock.h"
+#include "e_canvas_intern.h"
+
+struct _E_View_Textblock
+{
+   E_View view;
+
+   struct
+     {
+        struct wl_signal resize;
+     } events;
+
+   int width;
+   int height;
+};
+
+static E_View_Textblock *_view_textblock_from_view(E_View *view);
+static void _view_textblock_handle_destroy(E_View *view);
+static void _view_textblock_evas_object_cb_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
+
+const static E_View_Impl view_textblock_impl = {
+     .destroy = _view_textblock_handle_destroy,
+};
+
+static E_View_Textblock *
+_view_textblock_from_view(E_View *view)
+{
+   E_View_Textblock *textblock;
+   assert(view->impl == &view_textblock_impl);
+   return wl_container_of(view, textblock, view);
+}
+
+static void
+_view_textblock_handle_destroy(E_View *view)
+{
+   E_View_Textblock *textblock = _view_textblock_from_view(view);
+
+   evas_object_event_callback_del(textblock->view.eo, EVAS_CALLBACK_RESIZE, _view_textblock_evas_object_cb_resize);
+
+   evas_object_del(view->eo);
+   free(textblock);
+}
+
+static void
+_view_textblock_evas_object_cb_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+   E_View_Textblock *textblock = (E_View_Textblock *)data;
+   int width, height;
+
+   // for debugging
+   evas_object_geometry_get(textblock->view.eo,
+                            NULL, NULL, &width, &height);
+   if (width != textblock->width || height!= textblock->height)
+     {
+        ERR("e_view_textblock(%p) size mismatched: %dx%d != %dx%d", textblock,
+            textblock->width, textblock->height, width, height);
+
+        // FIXME: set the size of evas_object to the size of textblock
+        //       for avoiding regression.
+        textblock->width = width;
+        textblock->height = height;
+     }
+
+   wl_signal_emit_mutable(&textblock->events.resize, textblock);
+}
+
+static void
+_view_textblock_size_set(E_View_Textblock *textblock, int width, int height)
+{
+   textblock->width = width;
+   textblock->height = height;
+
+   evas_object_resize(textblock->view.eo, width, height);
+}
+
+E_API E_View_Textblock *
+e_view_textblock_create(E_View_Tree *parent)
+{
+   E_Canvas *canvas;
+   E_View_Textblock *textblock;
+   Evas_Object *eo;
+
+   assert(parent != NULL);
+
+   textblock = malloc(sizeof(*textblock));
+   if (!textblock)
+     return NULL;
+
+   canvas = e_canvas_get(&parent->view);
+   eo = evas_object_textblock_add(canvas->evas);
+   if (!eo)
+     {
+        free(textblock);
+        return NULL;
+     }
+
+   e_view_init(&textblock->view, E_VIEW_TYPE_TEXTBLOCK, (E_View_Impl*)&view_textblock_impl, eo, parent);
+
+   wl_signal_init(&textblock->events.resize);
+
+   evas_object_event_callback_add(textblock->view.eo, EVAS_CALLBACK_RESIZE, _view_textblock_evas_object_cb_resize, textblock);
+
+   return textblock;
+}
+
+E_API E_View *
+e_view_textblock_view_get(E_View_Textblock *textblock)
+{
+   if (textblock == NULL) return NULL;
+
+   return &textblock->view;
+}
+
+E_API E_View_Textblock *
+e_view_textblock_try_from_view(E_View *view)
+{
+   if (view == NULL) return NULL;
+
+   if (view->impl != &view_textblock_impl)
+     return NULL;
+
+   return _view_textblock_from_view(view);
+}
+
+
+E_API void
+e_view_textblock_style_set(E_View_Textblock *textblock, char *style)
+{
+   Evas_Textblock_Style *st;
+
+   if (textblock == NULL) return;
+
+   st = evas_textblock_style_new();
+
+   evas_textblock_style_set(st, style);
+   evas_object_textblock_style_set(textblock->view.eo, st);
+
+   evas_textblock_style_free(st);
+}
+
+E_API void
+e_view_textblock_text_markup_set(E_View_Textblock *textblock, char *markup)
+{
+   if (textblock == NULL) return;
+
+   evas_object_textblock_text_markup_set(textblock->view.eo, markup);
+}
+
+E_API char *
+e_view_textblock_text_utf8_to_markup(E_View_Textblock *textblock, char *markup)
+{
+   if (textblock == NULL) return NULL;
+
+   return evas_textblock_text_utf8_to_markup(textblock->view.eo, markup);
+}
+
+E_API void
+e_view_textblock_valign_set(E_View_Textblock *textblock, double valign)
+{
+   if (textblock == NULL) return;
+
+   evas_object_textblock_valign_set(textblock->view.eo, valign);
+}
+
+E_API void
+e_view_textblock_size_set(E_View_Textblock *textblock, int width, int height)
+{
+   if (textblock == NULL || (textblock->width == width && textblock->height == height)) return;
+
+   _view_textblock_size_set(textblock, width, height);
+}
+
+E_API void
+e_view_textblock_size_get(E_View_Textblock *textblock, int *width, int *height)
+{
+   if (textblock == NULL) return;
+
+   *width = textblock->width;
+   *height = textblock->height;
+}
+
+E_API void
+e_view_textblock_size_native_get(E_View_Textblock *textblock, int *w, int *h)
+{
+   if (textblock == NULL) return;
+
+   evas_object_textblock_size_native_get(textblock->view.eo, w, h);
+}
+
+E_API void
+e_view_textblock_size_formatted_get(E_View_Textblock *textblock, int *width, int *height)
+{
+   if (textblock == NULL) return;
+
+   evas_object_textblock_size_formatted_get(textblock->view.eo, width, height);
+}
+
+E_API bool
+e_view_textblock_line_number_geometry_get(E_View_Textblock *textblock, int line_num, int *x, int *y, int *width, int *height)
+{
+   if (textblock == NULL) return false;
+
+   return evas_object_textblock_line_number_geometry_get(textblock->view.eo, line_num, x, y, width, height);
+}
index 7b97b0cc73c8faed208530a28c2589ccf8b07896..1460521e4c989797aa1f3cee27b8e6ac6770b9f0 100644 (file)
@@ -69,41 +69,6 @@ E_API void e_view_text_text_set(E_View_Text *text, const char *sentence);
  */
 E_API const char *e_view_text_text_get(E_View_Text *text);
 
-/**
- * TODO
- */
-E_API E_View_Text *e_view_textblock_create(E_View_Tree *parent);
-
-/**
- * TODO
- */
-E_API void e_view_textblock_style_set(E_View_Text *text, char *style);
-
-/**
- * TODO
- */
-E_API void e_view_textblock_text_markup_set(E_View_Text *text, char *markup);
-
-/**
- * TODO
- */
-E_API char *e_view_textblock_text_utf8_to_markup(E_View_Text *text, char *markup);
-
-/**
- * TODO
- */
-E_API void e_view_textblock_valign_set(E_View_Text *text, double valign);
-
-/**
- * TODO
- */
-E_API void e_view_textblock_size_formatted_get(E_View_Text *text, int *width, int *height);
-
-/**
- * TODO
- */
-E_API void e_view_textblock_line_number_geometry_get(E_View_Text *text, int line_num, int *x, int *y, int *width, int *height);
-
 #ifdef  __cplusplus
 }
 #endif
diff --git a/src/include/e_view_textblock.h b/src/include/e_view_textblock.h
new file mode 100755 (executable)
index 0000000..91c3cbb
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef E_VIEW_TEXTBLOCK_H
+#define E_VIEW_TEXTBLOCK_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#include <e_view.h>
+
+typedef struct _E_View_Textblock E_View_Textblock;
+
+/**
+ * TODO
+ */
+E_API E_View_Textblock *e_view_textblock_create(E_View_Tree *parent);
+
+/**
+ * TODO
+ */
+E_API E_View_Textblock *e_view_textblock_try_from_view(E_View *view);
+
+/**
+ * TODO
+ */
+E_API E_View *e_view_textblock_view_get(E_View_Textblock *textblock);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_style_set(E_View_Textblock *textblock, char *style);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_text_markup_set(E_View_Textblock *textblock, char *markup);
+
+/**
+ * TODO
+ */
+E_API char *e_view_textblock_text_utf8_to_markup(E_View_Textblock *textblock, char *markup);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_valign_set(E_View_Textblock *textblock, double valign);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_size_set(E_View_Textblock *text, int width, int height);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_size_get(E_View_Textblock *text, int *width, int *height);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_size_native_get(E_View_Textblock *textblock, int *w, int *h);
+
+/**
+ * TODO
+ */
+E_API void e_view_textblock_size_formatted_get(E_View_Textblock *textblock, int *width, int *height);
+
+/**
+ * TODO
+ */
+E_API bool e_view_textblock_line_number_geometry_get(E_View_Textblock *textblock, int line_num, int *x, int *y, int *width, int *height);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file