From e6be301fedf750e66b3d4ec43065fb7f4afc1f54 Mon Sep 17 00:00:00 2001 From: Christopher Michael Date: Wed, 22 Apr 2009 16:08:32 +0000 Subject: [PATCH] Formatting & whitespace removal. SVN revision: 40291 --- src/bin/e_editable.c | 465 ++++++++++++++++++++++----------------------------- 1 file changed, 197 insertions(+), 268 deletions(-) diff --git a/src/bin/e_editable.c b/src/bin/e_editable.c index c2e49dc..4a10fc0 100644 --- a/src/bin/e_editable.c +++ b/src/bin/e_editable.c @@ -24,12 +24,12 @@ struct _E_Editable_Smart_Data int selection_pos; int selection_visible; int password_mode; - + char *text; int char_length; int unicode_length; int allocated_length; - + int cursor_width; int selection_on_fg; int average_char_w; @@ -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 */ /** @@ -95,7 +94,7 @@ e_editable_add(Evas *evas) _e_editable_smart = evas_smart_class_new(&sc); _e_editable_smart_use = 0; } - + return evas_object_smart_add(evas, _e_editable_smart); } @@ -114,33 +113,29 @@ e_editable_theme_set(Evas_Object *editable, const char *category, const char *gr E_Editable_Smart_Data *sd; char *obj_group; const char *data; - + 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 */ sprintf(obj_group, "%s/text", group); e_theme_edje_object_set(sd->text_object, category, obj_group); 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); e_theme_edje_object_set(sd->selection_object, category, obj_group); - + data = edje_object_data_get(sd->selection_object, "on_foreground"); if ((data) && (strcmp(data, "1") == 0)) { @@ -152,7 +147,7 @@ e_editable_theme_set(Evas_Object *editable, const char *category, const char *gr sd->selection_on_fg = 0; evas_object_stack_below(sd->selection_object, sd->text_object); } - + _e_editable_text_update(editable); _e_editable_cursor_update(editable); } @@ -169,12 +164,11 @@ EAPI void e_editable_password_set(Evas_Object *editable, int password_mode) { E_Editable_Smart_Data *sd; - + 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); _e_editable_cursor_update(editable); @@ -190,7 +184,7 @@ EAPI int e_editable_password_get(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; return sd->password_mode; @@ -206,18 +200,17 @@ EAPI void e_editable_text_set(Evas_Object *editable, const char *text) { E_Editable_Smart_Data *sd; - + 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; sd->unicode_length = 0; sd->allocated_length = -1; - + if (_e_editable_text_insert(editable, 0, text) <= 0) { sd->text = malloc((E_EDITABLE_BLOCK_SIZE + 1) * sizeof(char)); @@ -227,7 +220,7 @@ e_editable_text_set(Evas_Object *editable, const char *text) sd->allocated_length = E_EDITABLE_BLOCK_SIZE; _e_editable_text_update(editable); } - + sd->cursor_pos = sd->unicode_length; sd->selection_pos = sd->unicode_length; _e_editable_cursor_update(editable); @@ -243,7 +236,7 @@ EAPI const char * e_editable_text_get(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return NULL; return sd->text; @@ -263,33 +256,27 @@ 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; - - start_id = 0; - end_id = 0; + if (end <= start) return NULL; + 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); range[end_id - start_id] = '\0'; - + return range; } @@ -305,7 +292,7 @@ EAPI int e_editable_text_length_get(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; return sd->unicode_length; @@ -324,19 +311,18 @@ e_editable_insert(Evas_Object *editable, int pos, const char *text) { E_Editable_Smart_Data *sd; int unicode_length; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) 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); if (sd->selection_pos >= pos) e_editable_selection_pos_set(editable, sd->selection_pos + unicode_length); - + _e_editable_text_position_update(editable, -1); return 1; } @@ -355,24 +341,23 @@ e_editable_delete(Evas_Object *editable, int start, int end) { E_Editable_Smart_Data *sd; int unicode_length; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) 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); else if (sd->cursor_pos > start) e_editable_cursor_pos_set(editable, start); - + if (sd->selection_pos > end) e_editable_selection_pos_set(editable, sd->selection_pos - unicode_length); else if (sd->selection_pos > start) e_editable_selection_pos_set(editable, start); - + _e_editable_text_position_update(editable, -1); return 1; } @@ -387,14 +372,13 @@ EAPI void e_editable_cursor_pos_set(Evas_Object *editable, int pos) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) 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); } @@ -409,7 +393,7 @@ EAPI int e_editable_cursor_pos_get(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; return sd->cursor_pos; @@ -424,7 +408,7 @@ EAPI void e_editable_cursor_move_to_start(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_cursor_pos_set(editable, 0); @@ -439,7 +423,7 @@ EAPI void e_editable_cursor_move_to_end(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_cursor_pos_set(editable, sd->unicode_length); @@ -454,7 +438,7 @@ EAPI void e_editable_cursor_move_left(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_cursor_pos_set(editable, sd->cursor_pos - 1); @@ -469,7 +453,7 @@ EAPI void e_editable_cursor_move_right(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_cursor_pos_set(editable, sd->cursor_pos + 1); @@ -484,12 +468,11 @@ EAPI void e_editable_cursor_show(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + 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)) { @@ -507,12 +490,11 @@ EAPI void e_editable_cursor_hide(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + 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); } @@ -527,14 +509,13 @@ EAPI void e_editable_selection_pos_set(Evas_Object *editable, int pos) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) 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); } @@ -549,7 +530,7 @@ EAPI int e_editable_selection_pos_get(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; return sd->selection_pos; @@ -564,7 +545,7 @@ EAPI void e_editable_selection_move_to_start(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_selection_pos_set(editable, 0); @@ -579,7 +560,7 @@ EAPI void e_editable_selection_move_to_end(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_selection_pos_set(editable, sd->unicode_length); @@ -594,7 +575,7 @@ EAPI void e_editable_selection_move_left(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_selection_pos_set(editable, sd->selection_pos - 1); @@ -609,7 +590,7 @@ EAPI void e_editable_selection_move_right(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_selection_pos_set(editable, sd->selection_pos + 1); @@ -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); } @@ -641,7 +621,7 @@ EAPI void e_editable_unselect_all(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; e_editable_selection_pos_set(editable, sd->cursor_pos); @@ -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; - - if (!editable || (!(sd = evas_object_smart_data_get(editable)))) - return; + int spos = 0, epos = -1, i = 0, pos = 0; - if (index < 0 || index >= sd->unicode_length) + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) 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); } @@ -698,12 +668,10 @@ EAPI void e_editable_selection_show(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + 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)) @@ -719,12 +687,10 @@ EAPI void e_editable_selection_hide(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + 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); } @@ -750,32 +716,31 @@ e_editable_pos_get_from_coords(Evas_Object *editable, Evas_Coord x, Evas_Coord y Evas_Coord canvas_x, canvas_y; int index, pos, i, j; const char *text; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return 0; if (!(text_obj = edje_object_part_object_get(sd->text_object, "e.text.text"))) return 0; - + evas_object_geometry_get(editable, &ox, &oy, NULL, NULL); evas_object_geometry_get(text_obj, &tx, &ty, &tw, &th); canvas_x = ox + x; 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; pos = 0; @@ -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,22 +779,20 @@ 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; - + if ((sd->average_char_w <= 0) || (sd->average_char_h <= 0)) { font_source = evas_object_text_font_source_get(text_obj); evas_object_text_font_get(text_obj, &font, &font_size); style = evas_object_text_style_get(text_obj); - + obj = evas_object_text_add(evas); evas_object_scale_set(obj, edje_scale_get()); evas_object_text_font_source_set(obj, font_source); @@ -842,23 +801,21 @@ 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 e_editable_enable(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; - + edje_object_signal_emit(sd->text_object, "e,state,enabled", "e"); } @@ -866,10 +823,10 @@ EAPI void e_editable_disable(Evas_Object *editable) { E_Editable_Smart_Data *sd; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; - + edje_object_signal_emit(sd->text_object, "e,state,disabled", "e"); } /* Private functions */ @@ -880,40 +837,33 @@ 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 (pos < 0) - pos = 0; + if ((!text) || (*text == '\0')) return 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; new_unicode_length = sd->unicode_length + unicode_length; - + if (new_char_length > sd->allocated_length) { int new_allocated_length = E_EDITABLE_SIZE_TO_ALLOC(new_char_length); @@ -948,14 +898,13 @@ _e_editable_text_insert(Evas_Object *editable, int pos, const char *text) } sd->unicode_length = new_unicode_length; sd->char_length = new_char_length; - + if (prev_char_length > index) memmove(&sd->text[index + char_length], &sd->text[index], prev_char_length - index); strncpy(&sd->text[index], text, char_length); sd->text[sd->char_length] = '\0'; - + _e_editable_text_update(editable); - return unicode_length; } @@ -965,37 +914,31 @@ 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; - - start_id = 0; - end_id = 0; + if (end <= start) return 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); sd->unicode_length -= (end - start); sd->text[sd->char_length] = '\0'; - + _e_editable_text_update(editable); - - return end - start; + + return (end - start); } /* Updates the position of the cursor @@ -1007,25 +950,25 @@ _e_editable_cursor_update(Evas_Object *editable) const Evas_Object *text_obj; Evas_Coord tx, ty; Evas_Coord cx, cy, ch; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; if (!(text_obj = edje_object_part_object_get(sd->text_object, "e.text.text"))) return; - + evas_object_geometry_get(text_obj, &tx, &ty, NULL, NULL); _e_editable_char_geometry_get_from_pos(editable, sd->cursor_pos, &cx, &cy, NULL, &ch); - + evas_object_move(sd->cursor_object, tx + cx, ty + cy); evas_object_resize(sd->cursor_object, sd->cursor_width, ch); - + if (sd->cursor_visible && evas_object_visible_get(editable)) { evas_object_show(sd->cursor_object); edje_object_signal_emit(sd->cursor_object, "e,action,show,cursor", "e"); } - + _e_editable_selection_update(editable); _e_editable_text_position_update(editable, -1); } @@ -1040,32 +983,31 @@ _e_editable_selection_update(Evas_Object *editable) Evas_Coord cx, cy; Evas_Coord sx, sy, sw, sh; int start_pos, end_pos; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; if (!(text_obj = edje_object_part_object_get(sd->text_object, "e.text.text"))) return; - + if ((sd->cursor_pos == sd->selection_pos) || (!sd->selection_visible)) evas_object_hide(sd->selection_object); 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); sx = tx + cx; sy = ty + cy; - + _e_editable_char_geometry_get_from_pos(editable, end_pos, &cx, NULL, NULL, &sh); sw = tx + cx - sx; - + evas_object_move(sd->selection_object, sx, sy); evas_object_resize(sd->selection_object, sw, sh); evas_object_show(sd->selection_object); @@ -1080,14 +1022,14 @@ _e_editable_text_update(Evas_Object *editable) { E_Editable_Smart_Data *sd; Evas_Coord minw, minh; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) return; - + if (sd->password_mode) { char *text; - + text = malloc((sd->unicode_length + 1) * sizeof(char)); memset(text, '*', sd->unicode_length * sizeof(char)); text[sd->unicode_length] = '\0'; @@ -1095,10 +1037,8 @@ _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); } @@ -1114,24 +1054,23 @@ _e_editable_text_position_update(Evas_Object *editable, Evas_Coord real_w) Evas_Coord cx, cy, cw; Evas_Coord sx, sy; Evas_Coord offset_x = 0; - + if ((!editable) || (!(sd = evas_object_smart_data_get(editable)))) 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); - + if (tw <= ow) offset_x = ox - tx; else if (cx < (ox + E_EDITABLE_CURSOR_MARGIN)) offset_x = ox + E_EDITABLE_CURSOR_MARGIN - cx; else if ((cx + cw + E_EDITABLE_CURSOR_MARGIN) > (ox + ow)) offset_x = (ox + ow) - (cx + cw + E_EDITABLE_CURSOR_MARGIN); - + if (tw > ow) { if ((tx + offset_x) > ox) @@ -1139,13 +1078,13 @@ _e_editable_text_position_update(Evas_Object *editable, Evas_Coord real_w) else if ((tx + tw + offset_x) < (ox + ow)) offset_x = (ox + ow) - (tx + tw); } - + 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,25 +1095,23 @@ _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; - - if (cx) *cx = 0; - if (cy) *cy = 0; - if (cw) *cw = 0; - if (ch) *ch = 0; - + int index = 0, i, last_pos, ret; + + 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; if (!(text_obj = edje_object_part_object_get(sd->text_object, "e.text.text"))) return 0; - + 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; } @@ -1187,15 +1124,13 @@ _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; } } @@ -1208,29 +1143,28 @@ _e_editable_smart_add(Evas_Object *object) Evas *evas; E_Editable_Smart_Data *sd; Evas_Coord ox, oy; - + if ((!object) || !(evas = evas_object_evas_get(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); evas_object_geometry_get(object, &ox, &oy, NULL, NULL); - + sd->text = malloc((E_EDITABLE_BLOCK_SIZE + 1) * sizeof(char)); sd->text[0] = '\0'; sd->char_length = 0; sd->unicode_length = 0; sd->allocated_length = E_EDITABLE_BLOCK_SIZE; - + sd->cursor_width = 1; sd->selection_on_fg = 0; sd->average_char_w = -1; sd->average_char_h = -1; - + sd->cursor_pos = 0; sd->cursor_visible = 1; sd->selection_pos = 0; @@ -1240,31 +1174,31 @@ _e_editable_smart_add(Evas_Object *object) sd->clip_object = evas_object_rectangle_add(evas); evas_object_move(sd->clip_object, ox, oy); evas_object_smart_member_add(sd->clip_object, object); - + sd->event_object = evas_object_rectangle_add(evas); evas_object_color_set(sd->event_object, 0, 0, 0, 0); evas_object_clip_set(sd->event_object, sd->clip_object); evas_object_move(sd->event_object, ox, oy); evas_object_smart_member_add(sd->event_object, object); - + sd->text_object = edje_object_add(evas); evas_object_pass_events_set(sd->text_object, 1); evas_object_clip_set(sd->text_object, sd->clip_object); evas_object_move(sd->text_object, ox, oy); evas_object_smart_member_add(sd->text_object, object); - + sd->selection_object = edje_object_add(evas); evas_object_pass_events_set(sd->selection_object, 1); evas_object_clip_set(sd->selection_object, sd->clip_object); evas_object_move(sd->selection_object, ox, oy); evas_object_smart_member_add(sd->selection_object, object); - + sd->cursor_object = edje_object_add(evas); evas_object_pass_events_set(sd->cursor_object, 1); evas_object_clip_set(sd->cursor_object, sd->clip_object); evas_object_move(sd->cursor_object, ox, oy); evas_object_smart_member_add(sd->cursor_object, object); - + _e_editable_cursor_update(object); } @@ -1273,21 +1207,20 @@ static void _e_editable_smart_del(Evas_Object *object) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; - + evas_object_del(sd->clip_object); evas_object_del(sd->event_object); evas_object_del(sd->text_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); - + _e_editable_smart_use--; if (_e_editable_smart_use <= 0) { @@ -1303,21 +1236,17 @@ _e_editable_smart_move(Evas_Object *object, Evas_Coord x, Evas_Coord y) E_Editable_Smart_Data *sd; Evas_Coord prev_x, prev_y; Evas_Coord ox, oy; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) 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)); } @@ -1327,10 +1256,10 @@ static void _e_editable_smart_resize(Evas_Object *object, Evas_Coord w, Evas_Coord h) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; - + evas_object_resize(sd->clip_object, w, h); evas_object_resize(sd->event_object, w, h); _e_editable_text_position_update(object, w); @@ -1341,20 +1270,20 @@ static void _e_editable_smart_show(Evas_Object *object) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; - + evas_object_show(sd->clip_object); evas_object_show(sd->event_object); evas_object_show(sd->text_object); - + if (sd->cursor_visible) { evas_object_show(sd->cursor_object); edje_object_signal_emit(sd->cursor_object, "e,action,show,cursor", "e"); } - + if ((sd->selection_visible) && (sd->cursor_pos != sd->selection_pos)) evas_object_show(sd->selection_object); } @@ -1364,10 +1293,10 @@ static void _e_editable_smart_hide(Evas_Object *object) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; - + evas_object_hide(sd->clip_object); evas_object_hide(sd->event_object); evas_object_hide(sd->text_object); @@ -1380,7 +1309,7 @@ static void _e_editable_color_set(Evas_Object *object, int r, int g, int b, int a) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; evas_object_color_set(sd->clip_object, r, g, b, a); @@ -1391,7 +1320,7 @@ static void _e_editable_clip_set(Evas_Object *object, Evas_Object *clip) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; evas_object_clip_set(sd->clip_object, clip); @@ -1402,7 +1331,7 @@ static void _e_editable_clip_unset(Evas_Object *object) { E_Editable_Smart_Data *sd; - + if ((!object) || (!(sd = evas_object_smart_data_get(object)))) return; evas_object_clip_unset(sd->clip_object); -- 2.7.4