forked from enlightenment/enlightenment
parent
cadb8b5b91
commit
e6be301fed
|
@ -59,7 +59,6 @@ static void _e_editable_clip_unset(Evas_Object *object);
|
|||
static Evas_Smart *_e_editable_smart = NULL;
|
||||
static int _e_editable_smart_use = 0;
|
||||
|
||||
|
||||
/* externally accessible functions */
|
||||
|
||||
/**
|
||||
|
@ -117,8 +116,7 @@ e_editable_theme_set(Evas_Object *editable, const char *category, const char *gr
|
|||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if ((!category) || (!group))
|
||||
return;
|
||||
if ((!category) || (!group)) return;
|
||||
obj_group = alloca(strlen(group) + strlen("/selection") + 1);
|
||||
|
||||
/* Gets the theme for the text object */
|
||||
|
@ -127,15 +125,12 @@ e_editable_theme_set(Evas_Object *editable, const char *category, const char *gr
|
|||
sd->average_char_w = -1;
|
||||
sd->average_char_h = -1;
|
||||
|
||||
|
||||
/* Gets the theme for the cursor */
|
||||
sprintf(obj_group, "%s/cursor", group);
|
||||
e_theme_edje_object_set(sd->cursor_object, category, obj_group);
|
||||
|
||||
edje_object_size_min_get(sd->cursor_object, &sd->cursor_width, NULL);
|
||||
if (sd->cursor_width < 1)
|
||||
sd->cursor_width = 1;
|
||||
|
||||
if (sd->cursor_width < 1) sd->cursor_width = 1;
|
||||
|
||||
/* Gets the theme for the selection */
|
||||
sprintf(obj_group, "%s/selection", group);
|
||||
|
@ -172,8 +167,7 @@ e_editable_password_set(Evas_Object *editable, int password_mode)
|
|||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if (sd->password_mode == password_mode)
|
||||
return;
|
||||
if (sd->password_mode == password_mode) return;
|
||||
|
||||
sd->password_mode = password_mode;
|
||||
_e_editable_text_update(editable);
|
||||
|
@ -210,8 +204,7 @@ e_editable_text_set(Evas_Object *editable, const char *text)
|
|||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
|
||||
if (sd->password_mode)
|
||||
memset(sd->text, 0, sd->char_length);
|
||||
if (sd->password_mode) memset(sd->text, 0, sd->char_length);
|
||||
free(sd->text);
|
||||
sd->text = NULL;
|
||||
sd->char_length = 0;
|
||||
|
@ -263,28 +256,22 @@ e_editable_text_range_get(Evas_Object *editable, int start, int end)
|
|||
{
|
||||
E_Editable_Smart_Data *sd;
|
||||
char *range;
|
||||
int start_id, end_id;
|
||||
int i;
|
||||
int start_id = 0, end_id = 0, i;
|
||||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return NULL;
|
||||
|
||||
start = E_CLAMP(start, 0, sd->unicode_length);
|
||||
end = E_CLAMP(end, 0, sd->unicode_length);
|
||||
if (end <= start)
|
||||
return NULL;
|
||||
if (end <= start) return NULL;
|
||||
|
||||
start_id = 0;
|
||||
end_id = 0;
|
||||
for (i = 0; i < end; i++)
|
||||
{
|
||||
end_id = evas_string_char_next_get(sd->text, end_id, NULL);
|
||||
if (i < start)
|
||||
start_id = end_id;
|
||||
if (i < start) start_id = end_id;
|
||||
}
|
||||
|
||||
if (end_id <= start_id)
|
||||
return NULL;
|
||||
if (end_id <= start_id) return NULL;
|
||||
|
||||
range = malloc((end_id - start_id + 1) * sizeof(char));
|
||||
strncpy(range, &sd->text[start_id], end_id - start_id);
|
||||
|
@ -329,8 +316,7 @@ e_editable_insert(Evas_Object *editable, int pos, const char *text)
|
|||
return 0;
|
||||
|
||||
unicode_length = _e_editable_text_insert(editable, pos, text);
|
||||
if (unicode_length <= 0)
|
||||
return 0;
|
||||
if (unicode_length <= 0) return 0;
|
||||
|
||||
if (sd->cursor_pos >= pos)
|
||||
e_editable_cursor_pos_set(editable, sd->cursor_pos + unicode_length);
|
||||
|
@ -360,8 +346,7 @@ e_editable_delete(Evas_Object *editable, int start, int end)
|
|||
return 0;
|
||||
|
||||
unicode_length = _e_editable_text_delete(editable, start, end);
|
||||
if (unicode_length <= 0)
|
||||
return 0;
|
||||
if (unicode_length <= 0) return 0;
|
||||
|
||||
if (sd->cursor_pos > end)
|
||||
e_editable_cursor_pos_set(editable, sd->cursor_pos - unicode_length);
|
||||
|
@ -392,8 +377,7 @@ e_editable_cursor_pos_set(Evas_Object *editable, int pos)
|
|||
return;
|
||||
|
||||
pos = E_CLAMP(pos, 0, sd->unicode_length);
|
||||
if ((sd->cursor_pos == pos))
|
||||
return;
|
||||
if ((sd->cursor_pos == pos)) return;
|
||||
|
||||
sd->cursor_pos = pos;
|
||||
_e_editable_cursor_update(editable);
|
||||
|
@ -487,8 +471,7 @@ e_editable_cursor_show(Evas_Object *editable)
|
|||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if (sd->cursor_visible)
|
||||
return;
|
||||
if (sd->cursor_visible) return;
|
||||
|
||||
sd->cursor_visible = 1;
|
||||
if (evas_object_visible_get(editable))
|
||||
|
@ -510,8 +493,7 @@ e_editable_cursor_hide(Evas_Object *editable)
|
|||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if (!sd->cursor_visible)
|
||||
return;
|
||||
if (!sd->cursor_visible) return;
|
||||
|
||||
sd->cursor_visible = 0;
|
||||
evas_object_hide(sd->cursor_object);
|
||||
|
@ -532,8 +514,7 @@ e_editable_selection_pos_set(Evas_Object *editable, int pos)
|
|||
return;
|
||||
|
||||
pos = E_CLAMP(pos, 0, sd->unicode_length);
|
||||
if ((sd->selection_pos == pos))
|
||||
return;
|
||||
if (sd->selection_pos == pos) return;
|
||||
|
||||
sd->selection_pos = pos;
|
||||
_e_editable_selection_update(editable);
|
||||
|
@ -625,8 +606,7 @@ e_editable_selection_move_right(Evas_Object *editable)
|
|||
EAPI void
|
||||
e_editable_select_all(Evas_Object *editable)
|
||||
{
|
||||
if (!editable)
|
||||
return;
|
||||
if (!editable) return;
|
||||
e_editable_selection_move_to_start(editable);
|
||||
e_editable_cursor_move_to_end(editable);
|
||||
}
|
||||
|
@ -654,37 +634,27 @@ EAPI void
|
|||
e_editable_select_word(Evas_Object *editable, int index)
|
||||
{
|
||||
E_Editable_Smart_Data *sd;
|
||||
int spos, epos, i, pos;
|
||||
int spos = 0, epos = -1, i = 0, pos = 0;
|
||||
|
||||
if (!editable || (!(sd = evas_object_smart_data_get(editable))))
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if ((index < 0) || (index >= sd->unicode_length)) return;
|
||||
|
||||
if (index < 0 || index >= sd->unicode_length)
|
||||
return;
|
||||
|
||||
i = 0;
|
||||
spos = 0;
|
||||
epos = -1;
|
||||
pos = 0;
|
||||
while (i < sd->char_length)
|
||||
{
|
||||
if (sd->text[i] == ' ')
|
||||
{
|
||||
if (pos < index)
|
||||
spos = pos + 1;
|
||||
if (pos < index) spos = pos + 1;
|
||||
else if (pos > index)
|
||||
{
|
||||
epos = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
i = evas_string_char_next_get(sd->text, i, NULL);
|
||||
pos++;
|
||||
}
|
||||
if (epos == -1)
|
||||
epos = pos;
|
||||
|
||||
if (epos == -1) epos = pos;
|
||||
e_editable_selection_pos_set(editable, spos);
|
||||
e_editable_cursor_pos_set(editable, epos);
|
||||
}
|
||||
|
@ -701,9 +671,7 @@ e_editable_selection_show(Evas_Object *editable)
|
|||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if (sd->selection_visible)
|
||||
return;
|
||||
|
||||
if (sd->selection_visible) return;
|
||||
sd->selection_visible = 1;
|
||||
if ((evas_object_visible_get(editable)) &&
|
||||
(sd->cursor_pos != sd->selection_pos))
|
||||
|
@ -722,9 +690,7 @@ e_editable_selection_hide(Evas_Object *editable)
|
|||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return;
|
||||
if (!sd->selection_visible)
|
||||
return;
|
||||
|
||||
if (!sd->selection_visible) return;
|
||||
sd->selection_visible = 0;
|
||||
evas_object_hide(sd->selection_object);
|
||||
}
|
||||
|
@ -762,19 +728,18 @@ e_editable_pos_get_from_coords(Evas_Object *editable, Evas_Coord x, Evas_Coord y
|
|||
canvas_y = oy + y;
|
||||
|
||||
if ((canvas_y < ty) || (canvas_x < tx))
|
||||
pos = 0;
|
||||
pos = 0;
|
||||
else if ((canvas_y > (ty + th)) || (canvas_x > (tx + tw)))
|
||||
pos = sd->unicode_length;
|
||||
pos = sd->unicode_length;
|
||||
else
|
||||
{
|
||||
index = evas_object_text_char_coords_get(text_obj,
|
||||
canvas_x - tx, canvas_y - ty,
|
||||
&cx, NULL, &cw, NULL);
|
||||
canvas_x - tx, canvas_y - ty,
|
||||
&cx, NULL, &cw, NULL);
|
||||
text = evas_object_text_text_get(text_obj);
|
||||
if ((index >= 0) && (text))
|
||||
{
|
||||
if ((canvas_x - tx) > (cx + (cw / 2)))
|
||||
index++;
|
||||
if ((canvas_x - tx) > (cx + (cw / 2))) index++;
|
||||
|
||||
i = 0;
|
||||
j = -1;
|
||||
|
@ -785,14 +750,10 @@ e_editable_pos_get_from_coords(Evas_Object *editable, Evas_Coord x, Evas_Coord y
|
|||
j = i;
|
||||
i = evas_string_char_next_get(text, i, NULL);
|
||||
}
|
||||
|
||||
if (pos > sd->unicode_length)
|
||||
pos = sd->unicode_length;
|
||||
if (pos > sd->unicode_length) pos = sd->unicode_length;
|
||||
}
|
||||
else
|
||||
pos = 0;
|
||||
else pos = 0;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
@ -818,13 +779,11 @@ e_editable_char_size_get(Evas_Object *editable, int *w, int *h)
|
|||
Evas_Text_Style_Type style;
|
||||
int font_size;
|
||||
|
||||
if (w) *w = 0;
|
||||
if (h) *h = 0;
|
||||
|
||||
if (w) *w = 0;
|
||||
if (h) *h = 0;
|
||||
if ((!editable) || (!(evas = evas_object_evas_get(editable))))
|
||||
return;
|
||||
if (!(sd = evas_object_smart_data_get(editable)))
|
||||
return;
|
||||
if (!(sd = evas_object_smart_data_get(editable))) return;
|
||||
if (!(text_obj = edje_object_part_object_get(sd->text_object, "e.text.text")))
|
||||
return;
|
||||
|
||||
|
@ -842,13 +801,11 @@ e_editable_char_size_get(Evas_Object *editable, int *w, int *h)
|
|||
evas_object_text_text_set(obj, text);
|
||||
evas_object_geometry_get(obj, NULL, NULL, &tw, &th);
|
||||
evas_object_del(obj);
|
||||
|
||||
sd->average_char_w = tw / strlen(text);
|
||||
sd->average_char_w = (tw / strlen(text));
|
||||
sd->average_char_h = th;
|
||||
}
|
||||
|
||||
if (w) *w = sd->average_char_w;
|
||||
if (h) *h = sd->average_char_h;
|
||||
if (w) *w = sd->average_char_w;
|
||||
if (h) *h = sd->average_char_h;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
|
@ -880,35 +837,28 @@ static int
|
|||
_e_editable_text_insert(Evas_Object *editable, int pos, const char *text)
|
||||
{
|
||||
E_Editable_Smart_Data *sd;
|
||||
int char_length, unicode_length;
|
||||
int char_length = -1, unicode_length = -1;
|
||||
int prev_char_length, new_char_length, new_unicode_length;
|
||||
int index;
|
||||
int i;
|
||||
int index = 0, i = 0;
|
||||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return 0;
|
||||
if ((!text) || (*text == '\0'))
|
||||
return 0;
|
||||
if ((!text) || (*text == '\0')) return 0;
|
||||
|
||||
if (pos < 0)
|
||||
pos = 0;
|
||||
if (pos < 0) pos = 0;
|
||||
else if (pos > sd->unicode_length)
|
||||
pos = sd->unicode_length;
|
||||
|
||||
char_length = -1;
|
||||
unicode_length = -1;
|
||||
for (i = 0; i != char_length; i = evas_string_char_next_get(text, i, NULL))
|
||||
{
|
||||
char_length = i;
|
||||
unicode_length++;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
for (i = 0; i < pos; i++)
|
||||
index = evas_string_char_next_get(sd->text, index, NULL);
|
||||
|
||||
if ((unicode_length <= 0) || (char_length <= 0))
|
||||
return 0;
|
||||
if ((unicode_length <= 0) || (char_length <= 0)) return 0;
|
||||
|
||||
prev_char_length = sd->char_length;
|
||||
new_char_length = sd->char_length + char_length;
|
||||
|
@ -955,7 +905,6 @@ _e_editable_text_insert(Evas_Object *editable, int pos, const char *text)
|
|||
sd->text[sd->char_length] = '\0';
|
||||
|
||||
_e_editable_text_update(editable);
|
||||
|
||||
return unicode_length;
|
||||
}
|
||||
|
||||
|
@ -965,28 +914,22 @@ static int
|
|||
_e_editable_text_delete(Evas_Object *editable, int start, int end)
|
||||
{
|
||||
E_Editable_Smart_Data *sd;
|
||||
int start_id, end_id;
|
||||
int i;
|
||||
int start_id = 0, end_id = 0, i = 0;
|
||||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return 0;
|
||||
|
||||
start = E_CLAMP(start, 0, sd->unicode_length);
|
||||
end = E_CLAMP(end, 0, sd->unicode_length);
|
||||
if (end <= start)
|
||||
return 0;
|
||||
if (end <= start) return 0;
|
||||
|
||||
start_id = 0;
|
||||
end_id = 0;
|
||||
for (i = 0; i < end; i++)
|
||||
{
|
||||
end_id = evas_string_char_next_get(sd->text, end_id, NULL);
|
||||
if (i < start)
|
||||
start_id = end_id;
|
||||
if (i < start) start_id = end_id;
|
||||
}
|
||||
|
||||
if (end_id <= start_id)
|
||||
return 0;
|
||||
if (end_id <= start_id) return 0;
|
||||
|
||||
memmove(&sd->text[start_id], &sd->text[end_id], sd->char_length - end_id);
|
||||
sd->char_length -= (end_id - start_id);
|
||||
|
@ -995,7 +938,7 @@ _e_editable_text_delete(Evas_Object *editable, int start, int end)
|
|||
|
||||
_e_editable_text_update(editable);
|
||||
|
||||
return end - start;
|
||||
return (end - start);
|
||||
}
|
||||
|
||||
/* Updates the position of the cursor
|
||||
|
@ -1051,11 +994,10 @@ _e_editable_selection_update(Evas_Object *editable)
|
|||
else
|
||||
{
|
||||
evas_object_geometry_get(text_obj, &tx, &ty, NULL, NULL);
|
||||
|
||||
start_pos = (sd->cursor_pos <= sd->selection_pos) ?
|
||||
sd->cursor_pos : sd->selection_pos;
|
||||
sd->cursor_pos : sd->selection_pos;
|
||||
end_pos = (sd->cursor_pos >= sd->selection_pos) ?
|
||||
sd->cursor_pos : sd->selection_pos;
|
||||
sd->cursor_pos : sd->selection_pos;
|
||||
|
||||
_e_editable_char_geometry_get_from_pos(editable, start_pos,
|
||||
&cx, &cy, NULL, NULL);
|
||||
|
@ -1095,9 +1037,7 @@ _e_editable_text_update(Evas_Object *editable)
|
|||
free(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
edje_object_part_text_set(sd->text_object, "e.text.text", sd->text);
|
||||
}
|
||||
edje_object_part_text_set(sd->text_object, "e.text.text", sd->text);
|
||||
|
||||
edje_object_size_min_calc(sd->text_object, &minw, &minh);
|
||||
evas_object_resize(sd->text_object, minw, minh);
|
||||
|
@ -1119,8 +1059,7 @@ _e_editable_text_position_update(Evas_Object *editable, Evas_Coord real_w)
|
|||
return;
|
||||
|
||||
evas_object_geometry_get(editable, &ox, &oy, &ow, NULL);
|
||||
if (real_w >= 0)
|
||||
ow = real_w;
|
||||
if (real_w >= 0) ow = real_w;
|
||||
evas_object_geometry_get(sd->text_object, &tx, &ty, &tw, NULL);
|
||||
evas_object_geometry_get(sd->cursor_object, &cx, &cy, &cw, NULL);
|
||||
evas_object_geometry_get(sd->selection_object, &sx, &sy, NULL, NULL);
|
||||
|
@ -1141,11 +1080,11 @@ _e_editable_text_position_update(Evas_Object *editable, Evas_Coord real_w)
|
|||
}
|
||||
|
||||
if (offset_x != 0)
|
||||
{
|
||||
evas_object_move(sd->text_object, tx + offset_x, ty);
|
||||
evas_object_move(sd->cursor_object, cx + offset_x, cy);
|
||||
evas_object_move(sd->selection_object, sx + offset_x, sy);
|
||||
}
|
||||
{
|
||||
evas_object_move(sd->text_object, tx + offset_x, ty);
|
||||
evas_object_move(sd->cursor_object, cx + offset_x, cy);
|
||||
evas_object_move(sd->selection_object, sx + offset_x, sy);
|
||||
}
|
||||
}
|
||||
|
||||
/* Gets the geometry of the char according to its utf-8 pos */
|
||||
|
@ -1156,14 +1095,12 @@ _e_editable_char_geometry_get_from_pos(Evas_Object *editable, int utf_pos, Evas_
|
|||
const Evas_Object *text_obj;
|
||||
const char *text;
|
||||
Evas_Coord x, w;
|
||||
int index, i;
|
||||
int last_pos;
|
||||
int ret;
|
||||
int index = 0, i, last_pos, ret;
|
||||
|
||||
if (cx) *cx = 0;
|
||||
if (cy) *cy = 0;
|
||||
if (cw) *cw = 0;
|
||||
if (ch) *ch = 0;
|
||||
if (cx) *cx = 0;
|
||||
if (cy) *cy = 0;
|
||||
if (cw) *cw = 0;
|
||||
if (ch) *ch = 0;
|
||||
|
||||
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
|
||||
return 0;
|
||||
|
@ -1173,8 +1110,8 @@ _e_editable_char_geometry_get_from_pos(Evas_Object *editable, int utf_pos, Evas_
|
|||
text = evas_object_text_text_get(text_obj);
|
||||
if ((!text) || (sd->unicode_length <= 0) || (utf_pos <= 0))
|
||||
{
|
||||
if (cx) *cx = 0;
|
||||
if (cy) *cy = 0;
|
||||
if (cx) *cx = 0;
|
||||
if (cy) *cy = 0;
|
||||
e_editable_char_size_get(editable, cw, ch);
|
||||
return 1;
|
||||
}
|
||||
|
@ -1188,14 +1125,12 @@ _e_editable_char_geometry_get_from_pos(Evas_Object *editable, int utf_pos, Evas_
|
|||
else
|
||||
last_pos = 0;
|
||||
|
||||
|
||||
index = 0;
|
||||
for (i = 0; i < utf_pos; i++)
|
||||
index = evas_string_char_next_get(text, index, NULL);
|
||||
|
||||
ret = evas_object_text_char_pos_get(text_obj, index, &x, cy, &w, ch);
|
||||
if (cx) *cx = x - 1 + (last_pos ? w : 0);
|
||||
if (cw) *cw = last_pos ? 1 : w;
|
||||
if (cx) *cx = x - 1 + (last_pos ? w : 0);
|
||||
if (cw) *cw = last_pos ? 1 : w;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -1213,8 +1148,7 @@ _e_editable_smart_add(Evas_Object *object)
|
|||
return;
|
||||
|
||||
sd = malloc(sizeof(E_Editable_Smart_Data));
|
||||
if (!sd)
|
||||
return;
|
||||
if (!sd) return;
|
||||
|
||||
_e_editable_smart_use++;
|
||||
evas_object_smart_data_set(object, sd);
|
||||
|
@ -1283,8 +1217,7 @@ _e_editable_smart_del(Evas_Object *object)
|
|||
evas_object_del(sd->cursor_object);
|
||||
evas_object_del(sd->selection_object);
|
||||
/* Security - clear out memory that contained a password */
|
||||
if (sd->password_mode)
|
||||
memset(sd->text, 0, sd->char_length);
|
||||
if (sd->password_mode) memset(sd->text, 0, sd->char_length);
|
||||
free(sd->text);
|
||||
free(sd);
|
||||
|
||||
|
@ -1308,16 +1241,12 @@ _e_editable_smart_move(Evas_Object *object, Evas_Coord x, Evas_Coord y)
|
|||
return;
|
||||
|
||||
evas_object_geometry_get(object, &prev_x, &prev_y, NULL, NULL);
|
||||
|
||||
evas_object_move(sd->clip_object, x, y);
|
||||
evas_object_move(sd->event_object, x, y);
|
||||
|
||||
evas_object_geometry_get(sd->text_object, &ox, &oy, NULL, NULL);
|
||||
evas_object_move(sd->text_object, ox + (x - prev_x), oy + (y - prev_y));
|
||||
|
||||
evas_object_geometry_get(sd->cursor_object, &ox, &oy, NULL, NULL);
|
||||
evas_object_move(sd->cursor_object, ox + (x - prev_x), oy + (y - prev_y));
|
||||
|
||||
evas_object_geometry_get(sd->selection_object, &ox, &oy, NULL, NULL);
|
||||
evas_object_move(sd->selection_object, ox + (x - prev_x), oy + (y - prev_y));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue