summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <hirt.danny@gmail.com>2017-05-23 16:04:04 +0300
committerDaniel Hirt <hirt.danny@gmail.com>2017-05-28 15:34:26 +0300
commite55b91aa910cd79ba08579b2e64ea2820d70c12b (patch)
treeb980e347b6e8d8dd5938a6884138ec27b5173bbf
parent9289e082d86d841f329f72b4074a674961ad7ca4 (diff)
Ui text: use 'wrap' and 'multiline' properties
-rw-r--r--src/bin/elementary/test_efl_ui_text.c38
-rw-r--r--src/lib/elementary/efl_ui_internal_text_interactive.c23
-rw-r--r--src/lib/elementary/efl_ui_internal_text_interactive.eo1
-rw-r--r--src/lib/elementary/efl_ui_text.c116
-rw-r--r--src/lib/elementary/efl_ui_text_interactive.eo11
5 files changed, 79 insertions, 110 deletions
diff --git a/src/bin/elementary/test_efl_ui_text.c b/src/bin/elementary/test_efl_ui_text.c
index a8e05b9680..15c4a2b077 100644
--- a/src/bin/elementary/test_efl_ui_text.c
+++ b/src/bin/elementary/test_efl_ui_text.c
@@ -115,22 +115,31 @@ my_efl_ui_text_bt_4(void *data, Evas_Object *obj EINA_UNUSED, void *event_info E
115 "size=32x32 href=emoticon"); 115 "size=32x32 href=emoticon");
116} 116}
117 117
118const char *_wrap_modes[4] = { "none", "char", "word", "mixed" };
119
120static void 118static void
121my_efl_ui_text_bt_6(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 119my_efl_ui_text_bt_6(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
122{ 120{
123 char style[128]; 121 Eo *text_obj = data;
124 Evas_Object *en = data; 122
125 size_t idx = (size_t) efl_key_data_get(en, "wrap_idx"); 123 Efl_Text_Format_Wrap wrap = efl_text_format_wrap_get(text_obj);
126 idx = (idx + 1) % 4; 124
127 efl_key_data_set(en, "wrap_idx", (void *)idx); 125 switch(wrap)
128 126 {
129 sprintf(style, "DEFAULT='font=Sans font_size=12 color=#fff wrap=%s'", 127 case EFL_TEXT_FORMAT_WRAP_NONE:
130 _wrap_modes[idx]); 128 wrap = EFL_TEXT_FORMAT_WRAP_CHAR;
131 efl_canvas_text_style_set(en, NULL, style); 129 break;
132 printf("wrap mode changed to '%s'\n", _wrap_modes[idx]); 130 case EFL_TEXT_FORMAT_WRAP_CHAR:
133 131 wrap = EFL_TEXT_FORMAT_WRAP_WORD;
132 break;
133 case EFL_TEXT_FORMAT_WRAP_WORD:
134 wrap = EFL_TEXT_FORMAT_WRAP_MIXED;
135 break;
136 case EFL_TEXT_FORMAT_WRAP_MIXED:
137 wrap = EFL_TEXT_FORMAT_WRAP_NONE;
138 break;
139 default:
140 break;
141 }
142 efl_text_format_wrap_set(text_obj, wrap);
134} 143}
135 144
136static void 145static void
@@ -154,7 +163,8 @@ test_efl_ui_text(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
154 elm_win_resize_object_add(win, bx); 163 elm_win_resize_object_add(win, bx);
155 evas_object_show(bx); 164 evas_object_show(bx);
156 165
157 en = efl_add(EFL_UI_TEXT_CLASS, win); 166 en = efl_add(EFL_UI_TEXT_CLASS, win,
167 efl_text_format_multiline_set(efl_added, EINA_TRUE));
158 168
159 printf("Added Efl.Ui.Text object\n"); 169 printf("Added Efl.Ui.Text object\n");
160 efl_key_data_set(en, "wrap_idx", 0); 170 efl_key_data_set(en, "wrap_idx", 0);
diff --git a/src/lib/elementary/efl_ui_internal_text_interactive.c b/src/lib/elementary/efl_ui_internal_text_interactive.c
index b5ef29b734..028135353e 100644
--- a/src/lib/elementary/efl_ui_internal_text_interactive.c
+++ b/src/lib/elementary/efl_ui_internal_text_interactive.c
@@ -16,7 +16,6 @@ typedef struct _Efl_Ui_Internal_Text_Interactive_Data
16 Evas_Textblock_Cursor *preedit_start, *preedit_end; 16 Evas_Textblock_Cursor *preedit_start, *preedit_end;
17 Eina_List *seq; 17 Eina_List *seq;
18 char *selection; 18 char *selection;
19 Eina_Bool multiline : 1;
20 Eina_Bool composing : 1; 19 Eina_Bool composing : 1;
21 Eina_Bool selecting : 1; 20 Eina_Bool selecting : 1;
22 Eina_Bool have_selection : 1; 21 Eina_Bool have_selection : 1;
@@ -730,7 +729,7 @@ _key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void
730 super = evas_key_modifier_is_set(ev->modifiers, "Super"); 729 super = evas_key_modifier_is_set(ev->modifiers, "Super");
731 altgr = evas_key_modifier_is_set(ev->modifiers, "AltGr"); 730 altgr = evas_key_modifier_is_set(ev->modifiers, "AltGr");
732#endif 731#endif
733 multiline = en->multiline; 732 multiline = efl_text_format_multiline_get(obj);
734 733
735 /* Translate some keys to strings. */ 734 /* Translate some keys to strings. */
736 if (!strcmp(ev->key, "Tab")) 735 if (!strcmp(ev->key, "Tab"))
@@ -1253,6 +1252,9 @@ _mouse_move_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, vo
1253 Evas_Event_Mouse_Move *ev = event_info; 1252 Evas_Event_Mouse_Move *ev = event_info;
1254 Evas_Coord x, y, w, h; 1253 Evas_Coord x, y, w, h;
1255 Evas_Textblock_Cursor *tc; 1254 Evas_Textblock_Cursor *tc;
1255 Eina_Bool multiline;
1256
1257 multiline = efl_text_format_multiline_get(obj);
1256 1258
1257#ifdef HAVE_ECORE_IMF 1259#ifdef HAVE_ECORE_IMF
1258 if (en->imf_context) 1260 if (en->imf_context)
@@ -1274,7 +1276,7 @@ _mouse_move_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, vo
1274 cx = ev->cur.canvas.x - x; 1276 cx = ev->cur.canvas.x - x;
1275 cy = ev->cur.canvas.y - y; 1277 cy = ev->cur.canvas.y - y;
1276 1278
1277 if (en->multiline) 1279 if (multiline)
1278 { 1280 {
1279 efl_canvas_text_cursor_coord_set(cur, cx, cy); 1281 efl_canvas_text_cursor_coord_set(cur, cx, cy);
1280 } 1282 }
@@ -1301,7 +1303,6 @@ EOLIAN static Efl_Object *
1301_efl_ui_internal_text_interactive_efl_object_constructor(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *en) 1303_efl_ui_internal_text_interactive_efl_object_constructor(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *en)
1302{ 1304{
1303 en->select_allow = EINA_TRUE; 1305 en->select_allow = EINA_TRUE;
1304 en->multiline = EINA_TRUE;
1305 en->editable = EINA_TRUE; 1306 en->editable = EINA_TRUE;
1306 return efl_constructor(efl_super(obj, MY_CLASS)); 1307 return efl_constructor(efl_super(obj, MY_CLASS));
1307} 1308}
@@ -1381,7 +1382,7 @@ _efl_ui_internal_text_interactive_efl_object_finalize(Eo *obj, Efl_Ui_Internal_T
1381 ecore_imf_context_input_panel_language_set(en->imf_context, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET); 1382 ecore_imf_context_input_panel_language_set(en->imf_context, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET);
1382#endif 1383#endif
1383 1384
1384 if (en->multiline) 1385 if (efl_text_format_multiline_get(obj))
1385 ecore_imf_context_input_hint_set(en->imf_context, 1386 ecore_imf_context_input_hint_set(en->imf_context,
1386 ecore_imf_context_input_hint_get(en->imf_context) | ECORE_IMF_INPUT_HINT_MULTILINE); 1387 ecore_imf_context_input_hint_get(en->imf_context) | ECORE_IMF_INPUT_HINT_MULTILINE);
1387 } 1388 }
@@ -1411,18 +1412,6 @@ _efl_ui_internal_text_interactive_efl_ui_text_interactive_selection_cursors_get(
1411} 1412}
1412 1413
1413EOLIAN static void 1414EOLIAN static void
1414_efl_ui_internal_text_interactive_efl_ui_text_interactive_multiline_set(Eo *obj EINA_UNUSED, Efl_Ui_Internal_Text_Interactive_Data *pd, Eina_Bool enabled)
1415{
1416 pd->multiline = enabled;
1417}
1418
1419EOLIAN static Eina_Bool
1420_efl_ui_internal_text_interactive_efl_ui_text_interactive_multiline_get(Eo *obj EINA_UNUSED, Efl_Ui_Internal_Text_Interactive_Data *pd)
1421{
1422 return pd->multiline;
1423}
1424
1425EOLIAN static void
1426_efl_ui_internal_text_interactive_efl_ui_text_interactive_editable_set(Eo *obj EINA_UNUSED, Efl_Ui_Internal_Text_Interactive_Data *sd, Eina_Bool editable) 1415_efl_ui_internal_text_interactive_efl_ui_text_interactive_editable_set(Eo *obj EINA_UNUSED, Efl_Ui_Internal_Text_Interactive_Data *sd, Eina_Bool editable)
1427{ 1416{
1428 sd->editable = editable; 1417 sd->editable = editable;
diff --git a/src/lib/elementary/efl_ui_internal_text_interactive.eo b/src/lib/elementary/efl_ui_internal_text_interactive.eo
index a79cc70b2d..034576f019 100644
--- a/src/lib/elementary/efl_ui_internal_text_interactive.eo
+++ b/src/lib/elementary/efl_ui_internal_text_interactive.eo
@@ -9,7 +9,6 @@ class Efl.Ui.Internal.Text.Interactive (Efl.Canvas.Text, Efl.Ui.Text.Interactive
9 Efl.Object.finalize; 9 Efl.Object.finalize;
10 Efl.Ui.Text.Interactive.selection_allowed { get; set; } 10 Efl.Ui.Text.Interactive.selection_allowed { get; set; }
11 Efl.Ui.Text.Interactive.selection_cursors { get; } 11 Efl.Ui.Text.Interactive.selection_cursors { get; }
12 Efl.Ui.Text.Interactive.multiline { get; set; }
13 Efl.Ui.Text.Interactive.editable { get; set; } 12 Efl.Ui.Text.Interactive.editable { get; set; }
14 } 13 }
15} 14}
diff --git a/src/lib/elementary/efl_ui_text.c b/src/lib/elementary/efl_ui_text.c
index df169d50bf..4c2274ef20 100644
--- a/src/lib/elementary/efl_ui_text.c
+++ b/src/lib/elementary/efl_ui_text.c
@@ -56,7 +56,7 @@ struct _Efl_Ui_Text_Data
56 const char *text; 56 const char *text;
57 const char *file; 57 const char *file;
58 Elm_Text_Format format; 58 Elm_Text_Format format;
59 Evas_Coord last_w, ent_mw, ent_mh; 59 Evas_Coord ent_w, ent_h;
60 Evas_Coord downx, downy; 60 Evas_Coord downx, downy;
61 Evas_Coord ox, oy; 61 Evas_Coord ox, oy;
62 Eina_List *anchors; 62 Eina_List *anchors;
@@ -1070,91 +1070,60 @@ EOLIAN static void
1070_efl_ui_text_elm_layout_sizing_eval(Eo *obj, Efl_Ui_Text_Data *sd) 1070_efl_ui_text_elm_layout_sizing_eval(Eo *obj, Efl_Ui_Text_Data *sd)
1071{ 1071{
1072 Evas_Coord minw, minh, resw, resh; 1072 Evas_Coord minw, minh, resw, resh;
1073 Evas_Coord fw, fh;
1074 Eo *sw;
1075 Eina_Bool wrap;
1073 1076
1074 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh); 1077 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
1075 1078
1076 if (!sd->changed && (sd->last_w == resw)) 1079 sw = edje_object_part_swallow_get(sd->entry_edje, "elm.text");
1077 { 1080 if (!sw) return;
1078 if (sd->scroll)
1079 {
1080 if (sd->text_obj)
1081 {
1082 Evas_Coord vw = 0, vh = 0, h = 0;
1083 1081
1084 // Called for line wrapping + scrolling; use the viewport 1082 wrap = efl_text_format_wrap_get(sw);
1085 // width and the formatted height as proper constraints.
1086 elm_interface_scrollable_content_viewport_geometry_get
1087 (obj, NULL, NULL, &vw, &vh);
1088 1083
1089 efl_canvas_text_size_formatted_get(sd->text_obj, NULL, &h); 1084 if (!sd->changed && (resw == sd->ent_w) && (resh == sd->ent_h)) return;
1090 if (vh > h) h = vh; 1085
1086 sd->changed = EINA_FALSE;
1087 sd->ent_w = resw;
1088 sd->ent_h = resh;
1091 1089
1092 evas_object_resize(sd->entry_edje, vw, h);
1093 }
1094 }
1095 return;
1096 }
1097 1090
1098 evas_event_freeze(evas_object_evas_get(obj)); 1091 evas_event_freeze(evas_object_evas_get(obj));
1099 sd->changed = EINA_FALSE;
1100 sd->last_w = resw;
1101 if (sd->scroll) 1092 if (sd->scroll)
1102 { 1093 {
1103 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1; 1094 Evas_Coord vw, vh;
1095 Evas_Coord tw, th;
1096 elm_interface_scrollable_content_viewport_geometry_get(obj, NULL, NULL, &vw, &vh);
1097 efl_gfx_size_set(sd->entry_edje, vw, vh);
1098 efl_gfx_size_get(sw, &tw, &th);
1099 efl_canvas_text_size_formatted_get(sw, &fw, &fh);
1100 evas_object_size_hint_min_set(sw, fw, fh);
1101 edje_object_size_min_calc(sd->entry_edje, &minw, &minh);
1102 evas_object_size_hint_min_set(sw, -1, -1);
1104 1103
1105 // XXX: no need for the following line. It's been commented out. 1104 if (vw > minw) minw = vw;
1106 // sd->scr_edje is the resize_object of this widget. It's already 1105 efl_gfx_size_set(sd->entry_edje, minw, minh);
1107 // resized when gfx_size_set was called on this widget.
1108 //evas_object_resize(sd->scr_edje, resw, resh);
1109 1106
1110 edje_object_size_min_calc(sd->scr_edje, &vmw, &vmh); 1107 if (!efl_text_format_multiline_get(sw))
1111 elm_interface_scrollable_content_viewport_geometry_get
1112 (obj, NULL, NULL, &vw, &vh);
1113 edje_object_size_min_restricted_calc
1114 (sd->entry_edje, &minw, &minh, vw, 0);
1115 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1116
1117 /* This is a hack to workaround the way min size hints
1118 * are treated. If the minimum width is smaller than the
1119 * restricted width, it means the minimum doesn't
1120 * matter. */
1121 if (minw <= vw)
1122 { 1108 {
1123 Evas_Coord ominw = -1; 1109 evas_object_size_hint_min_set(obj, -1, minh);
1124
1125 efl_gfx_size_hint_combined_min_get(sd->entry_edje, &ominw, NULL);
1126 minw = ominw;
1127 } 1110 }
1128 sd->ent_mw = minw;
1129 sd->ent_mh = minh;
1130
1131 if ((minw > 0) && (vw < minw)) vw = minw;
1132 if (minh > vh) vh = minh;
1133
1134 if (sd->single_line) h = vmh + minh;
1135 else h = vmh;
1136
1137 evas_object_resize(sd->entry_edje, vw, vh);
1138 evas_object_size_hint_min_set(obj, w, h);
1139
1140 if (sd->single_line)
1141 evas_object_size_hint_max_set(obj, -1, h);
1142 else
1143 evas_object_size_hint_max_set(obj, -1, -1);
1144 } 1111 }
1145 else 1112 else
1146 { 1113 {
1147 Evas_Coord ominw, ominh; 1114 efl_canvas_text_size_formatted_get(sw, &fw, &fh);
1148 Eo *sw = edje_object_part_swallow_get(sd->entry_edje, "elm.text"); 1115 evas_object_size_hint_min_set(sw, fw, fh);
1149 efl_canvas_text_size_native_get(sw, &resw, &resh); 1116 edje_object_size_min_calc(sd->entry_edje, &minw, &minh);
1150 evas_object_size_hint_min_set(sw, resw, resh); 1117 evas_object_size_hint_min_set(sw, -1, -1);
1151 edje_object_size_min_calc(sd->entry_edje, &ominw, &ominh); 1118 if (wrap == EFL_TEXT_FORMAT_WRAP_NONE)
1152 evas_object_size_hint_min_set(obj, ominw, ominh); 1119 {
1120 evas_object_size_hint_min_set(obj, minw, minh);
1121 }
1153 } 1122 }
1154
1155 _cursor_geometry_recalc(obj);
1156 evas_event_thaw(evas_object_evas_get(obj)); 1123 evas_event_thaw(evas_object_evas_get(obj));
1157 evas_event_thaw_eval(evas_object_evas_get(obj)); 1124 evas_event_thaw_eval(evas_object_evas_get(obj));
1125
1126 _cursor_geometry_recalc(obj);
1158} 1127}
1159 1128
1160static void 1129static void
@@ -2105,9 +2074,13 @@ _entry_changed_handle(void *data,
2105{ 2074{
2106 Evas_Coord minh; 2075 Evas_Coord minh;
2107 const char *text; 2076 const char *text;
2077 Eina_Bool single_line;
2078 Eo *obj = data;
2108 2079
2109 EFL_UI_TEXT_DATA_GET(data, sd); 2080 EFL_UI_TEXT_DATA_GET(data, sd);
2110 2081
2082 single_line = !efl_text_format_multiline_get(obj);
2083
2111 evas_event_freeze(evas_object_evas_get(data)); 2084 evas_event_freeze(evas_object_evas_get(data));
2112 sd->changed = EINA_TRUE; 2085 sd->changed = EINA_TRUE;
2113 /* Reset the size hints which are no more relevant. Keep the 2086 /* Reset the size hints which are no more relevant. Keep the
@@ -2116,6 +2089,12 @@ _entry_changed_handle(void *data,
2116 evas_object_size_hint_min_get(data, NULL, &minh); 2089 evas_object_size_hint_min_get(data, NULL, &minh);
2117 evas_object_size_hint_min_set(data, -1, minh); 2090 evas_object_size_hint_min_set(data, -1, minh);
2118 2091
2092 if (sd->single_line != single_line)
2093 {
2094 sd->single_line = single_line;
2095 elm_obj_widget_theme_apply(data);
2096 }
2097
2119 elm_layout_sizing_eval(data); 2098 elm_layout_sizing_eval(data);
2120 ELM_SAFE_FREE(sd->text, eina_stringshare_del); 2099 ELM_SAFE_FREE(sd->text, eina_stringshare_del);
2121 ELM_SAFE_FREE(sd->delay_write, ecore_timer_del); 2100 ELM_SAFE_FREE(sd->delay_write, ecore_timer_del);
@@ -3023,8 +3002,6 @@ _efl_ui_text_resize_internal(Evas_Object *obj)
3023 3002
3024 elm_interface_scrollable_content_viewport_geometry_get 3003 elm_interface_scrollable_content_viewport_geometry_get
3025 (obj, NULL, NULL, &vw, &vh); 3004 (obj, NULL, NULL, &vw, &vh);
3026 if (vw < sd->ent_mw) vw = sd->ent_mw;
3027 if (vh < sd->ent_mh) vh = sd->ent_mh;
3028 evas_object_resize(sd->entry_edje, vw, vh); 3005 evas_object_resize(sd->entry_edje, vw, vh);
3029 } 3006 }
3030 3007
@@ -3272,6 +3249,8 @@ _efl_ui_text_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Text_Data *priv)
3272 priv->editable = EINA_TRUE; 3249 priv->editable = EINA_TRUE;
3273 priv->sel_allow = EINA_TRUE; 3250 priv->sel_allow = EINA_TRUE;
3274 3251
3252 priv->single_line = !efl_text_format_multiline_get(text_obj);
3253
3275 priv->drop_format = ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE; 3254 priv->drop_format = ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE;
3276 elm_drop_target_add(obj, priv->drop_format, 3255 elm_drop_target_add(obj, priv->drop_format,
3277 _dnd_enter_cb, NULL, 3256 _dnd_enter_cb, NULL,
@@ -4050,7 +4029,6 @@ _efl_ui_text_scrollable_set(Eo *obj, Efl_Ui_Text_Data *sd, Eina_Bool scroll)
4050 4029
4051 elm_widget_on_show_region_hook_set(obj, NULL, NULL); 4030 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4052 } 4031 }
4053 sd->last_w = -1;
4054 _update_decorations(obj); 4032 _update_decorations(obj);
4055 elm_obj_widget_theme_apply(obj); 4033 elm_obj_widget_theme_apply(obj);
4056} 4034}
diff --git a/src/lib/elementary/efl_ui_text_interactive.eo b/src/lib/elementary/efl_ui_text_interactive.eo
index 19873e4f70..de0017edbf 100644
--- a/src/lib/elementary/efl_ui_text_interactive.eo
+++ b/src/lib/elementary/efl_ui_text_interactive.eo
@@ -10,7 +10,8 @@ struct Efl.Ui.Text.Interactive.Change_Info {
10 merge: bool; [[$true if can be merged with the previous one. Used for example with insertion when something is already selected]] 10 merge: bool; [[$true if can be merged with the previous one. Used for example with insertion when something is already selected]]
11} 11}
12 12
13interface Efl.Ui.Text.Interactive () 13interface Efl.Ui.Text.Interactive (Efl.Text, Efl.Text.Font,
14 Efl.Text.Format, Efl.Text.Style)
14{ 15{
15 [[This is an interface interactive text inputs should implement]] 16 [[This is an interface interactive text inputs should implement]]
16 methods { 17 methods {
@@ -37,14 +38,6 @@ interface Efl.Ui.Text.Interactive ()
37 end: Efl.Canvas.Text.Cursor; [[The end of the selection]] 38 end: Efl.Canvas.Text.Cursor; [[The end of the selection]]
38 } 39 }
39 } 40 }
40 @property multiline {
41 [[Whether or not this textblock is allowed to be multiline]]
42 set {}
43 get {}
44 values {
45 enabled: bool; [[$true if enabled, $false otherwise]]
46 }
47 }
48 @property editable { 41 @property editable {
49 [[Whether the entry is editable. 42 [[Whether the entry is editable.
50 43