summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_text_attribute_factory.c
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2019-11-27 13:04:31 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2019-11-27 13:04:32 +0900
commitc7f37fe61852ea45dce071e0f80f98adcce08981 (patch)
tree964906c510dd0af5310157ab0ebbcc4c29d42543 /src/lib/evas/canvas/efl_text_attribute_factory.c
parentf10c91cda9795a43e6984814b7394383cf9da812 (diff)
Efl.Text.Attribute_Factory
Summary: Implementation of new Efl.Text.Attribute_Factory class which replace the annotation interface. Currently, we have two public methods: ``` void efl_text_attribute_factory_attribute_insert(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end, const char *format) unsigned int efl_text_attribute_factory_attribute_clear(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end); ``` Other methods will be internal methods, for the time being, we will redesign internal methods Reviewers: woohyun, tasn, segfaultxavi, bu5hm4n, zmike Subscribers: zmike, q66, cedric, segfaultxavi, bu5hm4n, a.srour, #committers, #reviewers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10646
Diffstat (limited to 'src/lib/evas/canvas/efl_text_attribute_factory.c')
-rw-r--r--src/lib/evas/canvas/efl_text_attribute_factory.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/lib/evas/canvas/efl_text_attribute_factory.c b/src/lib/evas/canvas/efl_text_attribute_factory.c
new file mode 100644
index 0000000000..2e01ee8cae
--- /dev/null
+++ b/src/lib/evas/canvas/efl_text_attribute_factory.c
@@ -0,0 +1,133 @@
1//#define EFL_BETA_API_SUPPORT
2#include "evas_common_private.h"
3#include "evas_private.h"
4#include "efl_canvas_text_internal.h"
5#include "efl_text_cursor.eo.h"
6
7#define MY_CLASS EFL_TEXT_ATTRIBUTE_FACTORY_CLASS
8
9typedef struct
10{
11
12} Efl_Text_Attribute_Factory_Data;
13
14EOLIAN static void
15_efl_text_attribute_factory_attribute_insert(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end, const char *format)
16{
17 EINA_SAFETY_ON_TRUE_RETURN(!efl_text_cursor_handle_get(start) ||
18 !efl_text_cursor_handle_get(end) ||
19 efl_text_cursor_handle_get(start)->obj != efl_text_cursor_handle_get(end)->obj);
20
21 Eo *eo_obj= efl_text_cursor_handle_get(start)->obj;
22 evas_textblock_async_block(eo_obj);
23
24 _evas_textblock_annotations_insert(eo_obj, efl_text_cursor_handle_get(start), efl_text_cursor_handle_get(end), format,
25 EINA_FALSE);
26 efl_event_callback_legacy_call(eo_obj, EFL_CANVAS_TEXT_EVENT_CHANGED, NULL);
27}
28
29EOLIAN static unsigned int
30_efl_text_attribute_factory_attribute_clear(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end)
31{
32 unsigned int ret = 0;
33 Eina_Iterator *annotations;
34 Efl_Text_Attribute_Handle *an;
35 annotations = efl_text_attribute_factory_range_attributes_get(start, end);
36
37 if (!annotations) return ret;
38
39 EINA_ITERATOR_FOREACH(annotations, an)
40 {
41 ret++;
42 efl_text_attribute_factory_remove(an);
43 }
44 eina_iterator_free(annotations);
45
46 return ret;
47}
48
49const char *
50efl_text_attribute_factory_attribute_get(Efl_Text_Attribute_Handle *annotation)
51{
52 EINA_SAFETY_ON_TRUE_RETURN_VAL(!annotation || !(annotation->obj), NULL);
53
54 return (annotation->start_node ? annotation->start_node->format : NULL);
55}
56
57Eina_Iterator *
58efl_text_attribute_factory_range_attributes_get(const Efl_Text_Cursor *start, const Efl_Text_Cursor *end)
59{
60 Eina_List *lst = NULL;
61 Efl_Text_Attribute_Handle *it;
62
63 EINA_SAFETY_ON_TRUE_RETURN_VAL(!efl_text_cursor_handle_get(start) ||
64 !efl_text_cursor_handle_get(end) ||
65 efl_text_cursor_handle_get(start)->obj != efl_text_cursor_handle_get(end)->obj, NULL);
66
67 Eina_Inlist *annotations = _evas_textblock_annotations_get(efl_text_cursor_handle_get(start)->obj);
68
69 EINA_INLIST_FOREACH(annotations, it)
70 {
71 Efl_Text_Cursor_Handle start2, end2;
72 _evas_textblock_cursor_init(&start2, efl_text_cursor_handle_get(start)->obj);
73 _evas_textblock_cursor_init(&end2, efl_text_cursor_handle_get(start)->obj);
74
75 if (!it->start_node || !it->end_node) continue;
76 _textblock_cursor_pos_at_fnode_set(&start2, it->start_node);
77 _textblock_cursor_pos_at_fnode_set(&end2, it->end_node);
78 evas_textblock_cursor_char_prev(&end2);
79 if (!((evas_textblock_cursor_compare(&start2, efl_text_cursor_handle_get(end)) > 0) ||
80 (evas_textblock_cursor_compare(&end2, efl_text_cursor_handle_get(start)) < 0)))
81 {
82 lst = eina_list_append(lst, it);
83 }
84 }
85 return _evas_textblock_annotation_iterator_new(lst);
86}
87
88void
89efl_text_attribute_factory_attribute_cursors_get(const Efl_Text_Attribute_Handle *handle, Efl_Text_Cursor *start, Efl_Text_Cursor *end)
90{
91 EINA_SAFETY_ON_TRUE_RETURN (!handle || !(handle->obj));
92
93 efl_text_cursor_text_object_set(start, handle->obj, handle->obj);
94 efl_text_cursor_text_object_set(end, handle->obj, handle->obj);
95 _textblock_cursor_pos_at_fnode_set(efl_text_cursor_handle_get(start), handle->start_node);
96 _textblock_cursor_pos_at_fnode_set(efl_text_cursor_handle_get(end), handle->end_node);
97}
98
99void
100efl_text_attribute_factory_remove(Efl_Text_Attribute_Handle *annotation)
101{
102 EINA_SAFETY_ON_TRUE_RETURN (!annotation || !(annotation->obj));
103
104 evas_textblock_async_block(annotation->obj);
105 _evas_textblock_annotation_remove(annotation->obj, NULL, annotation, EINA_TRUE, EINA_TRUE);
106}
107
108Eina_Bool
109efl_text_attribute_factory_attribute_is_item(Efl_Text_Attribute_Handle *annotation)
110{
111 EINA_SAFETY_ON_TRUE_RETURN_VAL(!annotation || !(annotation->obj), EINA_FALSE);
112
113 return annotation->is_item;
114}
115
116Eina_Bool
117efl_text_attribute_factory_item_geometry_get(const Efl_Text_Attribute_Handle *annotation, int *x, int *y, int *w, int *h)
118{
119 EINA_SAFETY_ON_TRUE_RETURN_VAL(!annotation || !(annotation->obj), EINA_FALSE);
120
121 Efl_Text_Cursor_Handle cur;
122
123 Eo *eo_obj = annotation->obj;
124 Evas_Object_Protected_Data *obj_data = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
125 evas_object_async_block(obj_data);
126 _evas_textblock_relayout_if_needed(eo_obj);
127
128 _evas_textblock_cursor_init(&cur, eo_obj);
129 _textblock_cursor_pos_at_fnode_set(&cur, annotation->start_node);
130 return evas_textblock_cursor_format_item_geometry_get(&cur, x, y, w, h);
131}
132
133#include "efl_text_attribute_factory.eo.c"