diff --git a/legacy/edje/src/lib/edje_calc.c b/legacy/edje/src/lib/edje_calc.c index 4f692cb55e..7ae43ec3d1 100644 --- a/legacy/edje/src/lib/edje_calc.c +++ b/legacy/edje/src/lib/edje_calc.c @@ -644,11 +644,19 @@ _edje_part_recalc_single(Edje *ed, if (evas_object_textblock_style_get(ep->object) != stl->style) evas_object_textblock_style_set(ep->object, stl->style); - ptxt = evas_object_textblock_text_markup_get(ep->object); - if (((!ptxt) && (text)) || - ((ptxt) && (text) && (strcmp(ptxt, text))) || - ((ptxt) && (!text))) - evas_object_textblock_text_markup_set(ep->object, text); + // FIXME: need to account for editing + if (ep->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) + { + // do nothing - should be done elsewhere + } + else + { + ptxt = evas_object_textblock_text_markup_get(ep->object); + if (((!ptxt) && (text)) || + ((ptxt) && (text) && (strcmp(ptxt, text))) || + ((ptxt) && (!text))) + evas_object_textblock_text_markup_set(ep->object, text); + } if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y)) { int mw = 0, mh = 0; diff --git a/legacy/edje/src/lib/edje_entry.c b/legacy/edje/src/lib/edje_entry.c index 5d52a83009..a691b9d827 100644 --- a/legacy/edje/src/lib/edje_entry.c +++ b/legacy/edje/src/lib/edje_entry.c @@ -5,6 +5,7 @@ #include "edje_private.h" typedef struct _Entry Entry; +typedef struct _Sel Sel; struct _Entry { @@ -14,9 +15,17 @@ struct _Entry Evas_Textblock_Cursor *cursor; Evas_Textblock_Cursor *sel_start, *sel_end; Evas_List *sel; + Evas_Bool selecting : 1; Evas_Bool have_selection : 1; }; +struct _Sel +{ + Evas_Object *obj_bg; + Evas_Object *obj_fg; + Evas_Textblock_Rectangle rect; +}; + // FIXME: this has to emit signals for "request selection", "set selection" // so copy & paste work, need api calls to insert text, insert format, // get text (with markup) delete text, etc. etc. etc. @@ -39,6 +48,230 @@ _edje_focus_out_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) // FIXME: emit focus,out to selections and cursors } +static void +_curs_back(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + if (evas_textblock_cursor_char_prev(c)) return; + if (!evas_textblock_cursor_node_prev(c)) return; + while (evas_textblock_cursor_node_format_get(c)) + { + if (evas_textblock_cursor_node_format_is_visible_get(c)) break; + if (!evas_textblock_cursor_node_prev(c)) break; + } +} + +static void +_curs_next(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + if (evas_textblock_cursor_char_next(c)) return; + if (!evas_textblock_cursor_node_next(c)) return; + while (evas_textblock_cursor_node_format_get(c)) + { + if (evas_textblock_cursor_node_format_is_visible_get(c)) break; + if (!evas_textblock_cursor_node_next(c)) break; + } +} + +static int +_curs_line_last_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + Evas_Textblock_Cursor *cc; + int ln; + + cc = evas_object_textblock_cursor_new(o); + evas_textblock_cursor_node_last(cc); + ln = evas_textblock_cursor_line_geometry_get(cc, NULL, NULL, NULL, NULL); + evas_textblock_cursor_free(cc); + return ln; +} + +static void +_curs_jump_line(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en, int ln) +{ + Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch; + + if (ln < 0) ln = 0; + else + { + int last = _curs_line_last_get(c, o, en); + if (ln > last) ln = last; + } + if (!evas_object_textblock_line_number_geometry_get(o, ln, &lx, &ly, &lw, &lh)) + return; + evas_textblock_cursor_char_geometry_get(c, &cx, &cy, &cw, &ch); + if (evas_textblock_cursor_char_coord_set(c, cx + (cw / 2), ly + (lh / 2))) + return; + evas_textblock_cursor_line_coord_set(c, ly + (lh / 2)); + if (cx + (cw / 2) < (lx + (lw / 2))) evas_textblock_cursor_line_first(c); + else evas_textblock_cursor_line_last(c); +} + +static void +_curs_jump_line_by(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en, int by) +{ + int ln; + + ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL) + by; + _curs_jump_line(c, o, en, ln); +} + +static void +_curs_up(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + _curs_jump_line_by(c, o, en, -1); +} + +static void +_curs_down(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + _curs_jump_line_by(c, o, en, 1); +} + +static void +_curs_lin_start(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + evas_textblock_cursor_line_first(c); +} + +static void +_curs_lin_end(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + evas_textblock_cursor_line_last(c); + if (!evas_textblock_cursor_node_format_get(c)) + _curs_next(c, o, en); +} + +static void +_curs_start(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + evas_textblock_cursor_line_set(c, 0); + evas_textblock_cursor_line_first(c); +} + +static void +_curs_end(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + evas_textblock_cursor_line_set(c, _curs_line_last_get(c, o, en)); + _curs_lin_end(c, o, en); +} + + + +static void +_sel_start(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + if (en->sel_start) return; + en->sel_start = evas_object_textblock_cursor_new(o); + evas_textblock_cursor_copy(en->cursor, en->sel_start); + en->sel_end = evas_object_textblock_cursor_new(o); + evas_textblock_cursor_copy(en->cursor, en->sel_start); + en->have_selection = 0; +} + +static void +_sel_enable(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + if (en->have_selection) return; + en->have_selection = 1; + // FIXME: emit "selection changed" +} + +static void +_sel_extend(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + if (!en->sel_end) return; + _sel_enable(c, o, en); + if (!evas_textblock_cursor_compare(c, en->sel_end)) return; + evas_textblock_cursor_copy(c, en->sel_end); + // FIXME: emit "selection changed" +} + +static void +_sel_clear(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + if (en->sel_start) + { + evas_textblock_cursor_free(en->sel_start); + evas_textblock_cursor_free(en->sel_end); + en->sel_start = NULL; + en->sel_end = NULL; + } + en->have_selection = 0; + while (en->sel) + { + Sel *sel; + + sel = en->sel->data; + if (sel->obj_bg) evas_object_del(sel->obj_bg); + if (sel->obj_fg) evas_object_del(sel->obj_fg); + free(sel); + en->sel = evas_list_remove_list(en->sel, en->sel); + } +} + +static void +_sel_update(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) +{ + Evas_List *range = NULL, *l; + Sel *sel; + Evas_Object *ob; + Evas_Coord x, y, w, h; + Evas_Object *smart, *clip; + + smart = evas_object_smart_parent_get(o); + clip = evas_object_clip_get(o); + if (en->sel_start) + range = evas_textblock_cursor_range_geometry_get(en->sel_start, en->sel_end); + if (evas_list_count(range) != evas_list_count(en->sel)) + { + while (en->sel) + { + sel = en->sel->data; + if (sel->obj_bg) evas_object_del(sel->obj_bg); + if (sel->obj_fg) evas_object_del(sel->obj_fg); + free(sel); + en->sel = evas_list_remove_list(en->sel, en->sel); + } + if (en->have_selection) + { + for (l = range; l; l = l->next) + { + sel = calloc(1, sizeof(Sel)); + en->sel = evas_list_append(en->sel, sel); + ob = evas_object_rectangle_add(evas_object_evas_get(o)); + evas_object_smart_member_add(ob, smart); + evas_object_stack_below(ob, o); + evas_object_clip_set(ob, clip); + evas_object_color_set(ob, 20, 20, 255, 150); + evas_object_pass_events_set(ob, 1); + evas_object_show(ob); + sel->obj_bg = ob; + } + } + } + x = y = w = h = -1; + evas_object_geometry_get(o, &x, &y, &w, &h); + for (l = en->sel; l; l = l->next) + { + Evas_Textblock_Rectangle *r; + + sel = l->data; + r = range->data; + if (sel->obj_bg) + { + evas_object_move(sel->obj_bg, x + r->x, y + r->y); + evas_object_resize(sel->obj_bg, r->w, r->h); + } + if (sel->obj_fg) + { + evas_object_move(sel->obj_fg, x + r->x, y + r->y); + evas_object_resize(sel->obj_fg, r->w, r->h); + } + range = evas_list_remove_list(range, range); + free(r); + } +} + static void _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { @@ -47,6 +280,7 @@ _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) Edje_Real_Part *rp = ed->focused_part; Entry *en; Evas_Bool control, alt, shift; + Evas_Bool multiline; if (!rp) return; en = rp->entry_data; if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) || @@ -58,136 +292,68 @@ _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) control = evas_key_modifier_is_set(ev->modifiers, "Control"); alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); + multiline = rp->part->entry_mode; if (!strcmp(ev->key, "Escape")) { // dead keys here. Escape for now (should emit these) } - else if (!strcmp(ev->key, "Up")) + else if ((!strcmp(ev->key, "Up")) && (multiline)) { Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch; int line_num; - if (shift) - { - // if no selection, start one - } - line_num = evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, NULL); - line_num--; - if (evas_object_textblock_line_number_geometry_get(rp->object, line_num, &lx, &ly, &lw, &lh)) - { - evas_textblock_cursor_char_geometry_get(en->cursor, &cx, &cy, &cw, &ch); - if (!evas_textblock_cursor_char_coord_set(en->cursor, cx + (cw / 2), ly + (lh / 2))) - { - evas_textblock_cursor_line_coord_set(en->cursor, ly + (lh / 2)); - if (cx + (cw / 2) < (lx + (lw / 2))) - evas_textblock_cursor_line_first(en->cursor); - else - evas_textblock_cursor_line_last(en->cursor); - } - } - if (shift) - { - // also extend selection - } + if (shift) _sel_start(en->cursor, rp->object, en); + _curs_up(en->cursor, rp->object, en); + if (shift) _sel_extend(en->cursor, rp->object, en); } - else if (!strcmp(ev->key, "Down")) + else if ((!strcmp(ev->key, "Down")) && (multiline)) { Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch; int line_num; - if (shift) - { - // if no selection, start one - } - line_num = evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, NULL); - line_num++; - if (evas_object_textblock_line_number_geometry_get(rp->object, line_num, &lx, &ly, &lw, &lh)) - { - evas_textblock_cursor_char_geometry_get(en->cursor, &cx, &cy, &cw, &ch); - if (!evas_textblock_cursor_char_coord_set(en->cursor, cx + (cw / 2), ly + (lh / 2))) - { - evas_textblock_cursor_line_coord_set(en->cursor, ly + (lh / 2)); - if (cx + (cw / 2) < (lx + (lw / 2))) - evas_textblock_cursor_line_first(en->cursor); - else - evas_textblock_cursor_line_last(en->cursor); - } - } - if (shift) - { - // also extend selection - } + if (shift) _sel_start(en->cursor, rp->object, en); + _curs_down(en->cursor, rp->object, en); + if (shift) _sel_extend(en->cursor, rp->object, en); } else if (!strcmp(ev->key, "Left")) { - if (shift) - { - // if no selection, start one - } - if (!evas_textblock_cursor_char_prev(en->cursor)) - { - evas_textblock_cursor_node_prev(en->cursor); - } - if (shift) - { - // also extend selection - } + if (shift) _sel_start(en->cursor, rp->object, en); + _curs_back(en->cursor, rp->object, en); + if (shift) _sel_extend(en->cursor, rp->object, en); } else if (!strcmp(ev->key, "Right")) { - if (shift) - { - // if no selection, start one - } - if (!evas_textblock_cursor_char_next(en->cursor)) - { - evas_textblock_cursor_node_next(en->cursor); - } - if (shift) - { - // also extend selection - } + if (shift) _sel_start(en->cursor, rp->object, en); + _curs_next(en->cursor, rp->object, en); + if (shift) _sel_extend(en->cursor, rp->object, en); } else if (!strcmp(ev->key, "BackSpace")) { if (control) { - // if ctrl pressed del to start of previois word + // del to start of previous word } else if ((alt) && (shift)) { - // FIXME: undo last action + // undo last action } else { - if ((en->sel_start) && (en->sel_end) && (en->have_selection)) - { - printf("del sel\n"); - evas_textblock_cursor_range_delete(en->sel_start, en->sel_end); - } + if (en->have_selection) + evas_textblock_cursor_range_delete(en->sel_start, en->sel_end); else { - if (!evas_textblock_cursor_char_prev(en->cursor)) - { - evas_textblock_cursor_node_prev(en->cursor); - } + _curs_back(en->cursor, rp->object, en); evas_textblock_cursor_char_delete(en->cursor); } } - if ((en->sel_start) && (en->sel_end)) - { - // FIXME: func - evas_textblock_cursor_free(en->sel_start); - en->sel_start = NULL; - evas_textblock_cursor_free(en->sel_end); - en->sel_end = NULL; - } + _sel_clear(en->cursor, rp->object, en); } else if (!strcmp(ev->key, "Delete")) { if (control) { - // if ctrl pressed del to end of next word + // del to end of next word } else if (shift) { @@ -195,61 +361,30 @@ _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) } else { - if ((en->sel_start) && (en->sel_end) && (en->have_selection)) - { - evas_textblock_cursor_range_delete(en->sel_start, en->sel_end); - } + if (en->have_selection) + evas_textblock_cursor_range_delete(en->sel_start, en->sel_end); else - { - evas_textblock_cursor_char_delete(en->cursor); - } - } - if ((en->sel_start) && (en->sel_end)) - { - // FIXME: func - evas_textblock_cursor_free(en->sel_start); - en->sel_start = NULL; - evas_textblock_cursor_free(en->sel_end); - en->sel_end = NULL; + evas_textblock_cursor_char_delete(en->cursor); } + _sel_clear(en->cursor, rp->object, en); } else if (!strcmp(ev->key, "Home")) { - if (shift) - { - // if no selection, start one - } - if (control) - { - // goto start of text - } + if (shift) _sel_start(en->cursor, rp->object, en); + if ((control) && (multiline)) + _curs_start(en->cursor, rp->object, en); else - { - evas_textblock_cursor_line_first(en->cursor); - } - if (shift) - { - // also extend selection - } + _curs_lin_start(en->cursor, rp->object, en); + if (shift) _sel_extend(en->cursor, rp->object, en); } else if (!strcmp(ev->key, "End")) { - if (shift) - { - // if no selection, start one - } - if (control) - { - // goto end of text - } + if (shift) _sel_start(en->cursor, rp->object, en); + if ((control) && (multiline)) + _curs_end(en->cursor, rp->object, en); else - { - evas_textblock_cursor_line_last(en->cursor); - } - if (shift) - { - // also extend selection - } + _curs_lin_end(en->cursor, rp->object, en); + if (shift) _sel_extend(en->cursor, rp->object, en); } else if ((control) && (!strcmp(ev->key, "v"))) { @@ -267,22 +402,23 @@ _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) { if (shift) { - // FIXME: redo + // redo } else { - // FIXME: undo + // undo } } else if ((control) && (!strcmp(ev->key, "y"))) { - // FIXME: redo + // redo } else if ((control) && (!strcmp(ev->key, "w"))) { + _sel_clear(en->cursor, rp->object, en); // select current word } - else if (!strcmp(ev->key, "Tab")) + else if ((!strcmp(ev->key, "Tab")) && (multiline)) { if (shift) { @@ -290,26 +426,30 @@ _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) } else { - // add a tab + evas_textblock_cursor_format_prepend(en->cursor, "\t"); + _curs_next(en->cursor, rp->object, en); } } - else if (!strcmp(ev->key, "ISO_Left_Tab")) - { + else if ((!strcmp(ev->key, "ISO_Left_Tab")) && (multiline)) + { // remove a tab } - else if (!strcmp(ev->key, "Prior")) + else if ((!strcmp(ev->key, "Prior")) && (multiline)) { - // pgup + if (shift) _sel_start(en->cursor, rp->object, en); + _curs_jump_line_by(en->cursor, rp->object, en, -10); + if (shift) _sel_extend(en->cursor, rp->object, en); } - else if (!strcmp(ev->key, "Next")) + else if ((!strcmp(ev->key, "Next")) && (multiline)) { - // pgdn + if (shift) _sel_start(en->cursor, rp->object, en); + _curs_jump_line_by(en->cursor, rp->object, en, 10); + if (shift) _sel_extend(en->cursor, rp->object, en); } - else if ((!strcmp(ev->key, "Return")) || (!strcmp(ev->key, "KP_Enter"))) + else if (((!strcmp(ev->key, "Return")) || (!strcmp(ev->key, "KP_Enter"))) && (multiline)) { - // newline evas_textblock_cursor_format_prepend(en->cursor, "\n"); - evas_textblock_cursor_node_next(en->cursor); + _curs_next(en->cursor, rp->object, en); } else if ((!strcmp(ev->key, "Multi_key"))) { @@ -327,18 +467,10 @@ _edje_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) // FIXME: if composing.. store 2 keys if (ev->string) { - if (evas_textblock_cursor_node_format_get(en->cursor)) - { - printf("on format node\n"); - while (evas_textblock_cursor_node_prev(en->cursor)) - { - if (!evas_textblock_cursor_node_format_get(en->cursor)) - break; - } - evas_textblock_cursor_text_append(en->cursor, ev->string); - } - else - evas_textblock_cursor_text_prepend(en->cursor, ev->string); + if (en->have_selection) + evas_textblock_cursor_range_delete(en->sel_start, en->sel_end); + evas_textblock_cursor_text_prepend(en->cursor, ev->string); + _sel_clear(en->cursor, rp->object, en); } } _edje_entry_real_part_configure(rp); @@ -365,11 +497,15 @@ _edje_part_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info Evas_Event_Mouse_Down *ev = event_info; Entry *en; Evas_Coord x, y, w, h; + Evas_Bool multiline; if (!rp) return; en = rp->entry_data; if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) || - (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE)) + (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE)) return; + // double click -> select word + // triple click -> select line + multiline = rp->part->entry_mode; evas_object_geometry_get(rp->object, &x, &y, &w, &h); en->cx = ev->canvas.x - x; en->cy = ev->canvas.y - y; @@ -380,21 +516,13 @@ _edje_part_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info evas_textblock_cursor_line_coord_set(en->cursor, en->cy); evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh); if (en->cx <= lx) - evas_textblock_cursor_line_first(en->cursor); + _curs_lin_start(en->cursor, rp->object, en); else - evas_textblock_cursor_line_last(en->cursor); + _curs_lin_end(en->cursor, rp->object, en); } - en->sel_start = evas_object_textblock_cursor_new(rp->object); - evas_textblock_cursor_copy(en->cursor, en->sel_start); - en->sel_end = evas_object_textblock_cursor_new(rp->object); - evas_textblock_cursor_copy(en->cursor, en->sel_start); - en->have_selection = 0; - while (en->sel) - { - evas_object_del(en->sel->data); - en->sel = evas_list_remove_list(en->sel, en->sel); - } - // FIXME: emit "selection cleared" + en->selecting = 1; + _sel_clear(en->cursor, rp->object, en); + _sel_start(en->cursor, rp->object, en); _edje_entry_real_part_configure(rp); } @@ -405,11 +533,13 @@ _edje_part_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) Evas_Event_Mouse_Up *ev = event_info; Entry *en; Evas_Coord x, y, w, h; + Evas_Bool multiline; if (!rp) return; en = rp->entry_data; if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) || - (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE)) + (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE)) return; + multiline = rp->part->entry_mode; evas_object_geometry_get(rp->object, &x, &y, &w, &h); en->cx = ev->canvas.x - x; en->cy = ev->canvas.y - y; @@ -420,18 +550,12 @@ _edje_part_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info) evas_textblock_cursor_line_coord_set(en->cursor, en->cy); evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh); if (en->cx <= lx) - evas_textblock_cursor_line_first(en->cursor); + _curs_lin_start(en->cursor, rp->object, en); else - evas_textblock_cursor_line_last(en->cursor); + _curs_lin_end(en->cursor, rp->object, en); } evas_textblock_cursor_copy(en->cursor, en->sel_end); - - // FIXME: emit "selection ended" - - evas_textblock_cursor_free(en->sel_start); - en->sel_start = NULL; - evas_textblock_cursor_free(en->sel_end); - en->sel_end = NULL; + en->selecting = 0; _edje_entry_real_part_configure(rp); } @@ -443,11 +567,13 @@ _edje_part_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info Entry *en; Evas_Coord x, y, w, h; if (!rp) return; + Evas_Bool multiline; en = rp->entry_data; if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) || - (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE)) + (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE)) return; - if (!en->sel_start) return; + multiline = rp->part->entry_mode; + if (!en->selecting) return; evas_object_geometry_get(rp->object, &x, &y, &w, &h); en->cx = ev->cur.canvas.x - x; en->cy = ev->cur.canvas.y - y; @@ -458,50 +584,15 @@ _edje_part_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info evas_textblock_cursor_line_coord_set(en->cursor, en->cy); evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh); if (en->cx <= lx) - evas_textblock_cursor_line_first(en->cursor); + _curs_lin_start(en->cursor, rp->object, en); else - evas_textblock_cursor_line_last(en->cursor); + _curs_lin_end(en->cursor, rp->object, en); } - evas_textblock_cursor_copy(en->cursor, en->sel_end); + _sel_extend(en->cursor, rp->object, en); if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) != 0) - { - en->have_selection = 1; - // FIXME: emit "selection started" - } + _sel_enable(en->cursor, rp->object, en); if (en->have_selection) - { - Evas_List *range; - - printf("update sel\n"); - range = evas_textblock_cursor_range_geometry_get(en->sel_start, en->sel_end); - while (en->sel) - { - evas_object_del(en->sel->data); - en->sel = evas_list_remove_list(en->sel, en->sel); - } - while (range) - { - Evas_Textblock_Rectangle *r; - Evas_Object *o; - - r = range->data; - - o = evas_object_rectangle_add(evas_object_evas_get(rp->object)); - evas_object_smart_member_add(o, rp->edje->obj); - evas_object_stack_below(o, rp->object); - evas_object_clip_set(o, evas_object_clip_get(rp->object)); - evas_object_color_set(o, 20, 20, 255, 150); - evas_object_pass_events_set(o, 1); - evas_object_show(o); - evas_object_move(o, x + r->x, y + r->y); - evas_object_resize(o, r->w, r->h); - en->sel = evas_list_append(en->sel, o); - - range = evas_list_remove_list(range, range); - free(r); - } - // FIXME: emit "selection changed" - } + _sel_update(en->cursor, rp->object, en); _edje_entry_real_part_configure(rp); } @@ -540,7 +631,8 @@ _edje_entry_real_part_init(Edje_Real_Part *rp) evas_object_clip_set(en->cursor_bg, evas_object_clip_get(rp->object)); evas_object_color_set(en->cursor_bg, 255, 20, 20, 150); evas_object_pass_events_set(en->cursor_bg, 1); - evas_object_show(en->cursor_bg); + if (rp->part->entry_mode >= EDJE_ENTRY_EDIT_MODE_EDITABLE) + evas_object_show(en->cursor_bg); en->cursor = evas_object_textblock_cursor_get(rp->object); } @@ -561,24 +653,70 @@ _edje_entry_real_part_configure(Edje_Real_Part *rp) Evas_Coord x, y, w, h, xx, yy, ww, hh; Entry *en = rp->entry_data; if (!en) return; - + + _sel_update(en->cursor, rp->object, en); + x = y = w = h = -1; + xx = yy = ww = hh = -1; evas_object_geometry_get(rp->object, &x, &y, &w, &h); - // move cursor/selections etc. - if (evas_textblock_cursor_char_geometry_get(en->cursor, &xx, &yy, &ww, &hh) < 0) - { - printf("line < 0!\n"); - } - printf("%i %i %ix%i\n", xx, yy, ww, hh); + evas_textblock_cursor_char_geometry_get(en->cursor, &xx, &yy, &ww, &hh); if (ww < 1) ww = 1; if (hh < 1) ww = 1; - evas_object_move(en->cursor_bg, x + xx, y + yy); - evas_object_resize(en->cursor_bg, ww, hh); - // FIXME: move/resize en->sel (record the sels and intended geom) + if (en->cursor_bg) + { + evas_object_move(en->cursor_bg, x + xx, y + yy); + evas_object_resize(en->cursor_bg, ww, hh); + } + if (en->cursor_fg) + { + evas_object_move(en->cursor_fg, x + xx, y + yy); + evas_object_resize(en->cursor_fg, ww, hh); + } + // FIXME: move anchor objects based on cursor geometry } -// FIXME: need to implement -// get text -// insert text -// delete selected text -// get selection -// +char * +_edje_entry_selection_get(Edje_Real_Part *rp) +{ + Entry *en = rp->entry_data; + if (!en) return; + // get selection - convert to markup +} + +const char * +_edje_entry_text_get(Edje_Real_Part *rp) +{ + Entry *en = rp->entry_data; + if (!en) return; + // get text - convert to markup + return evas_object_textblock_text_markup_get(rp->object); +} + +void +_edje_entry_text_markup_set(Edje_Real_Part *rp, const char *text) +{ + Entry *en = rp->entry_data; + if (!en) return; + // set text as markup + evas_object_textblock_text_markup_set(rp->object, text); + // walk textblock nodes + // in walk find anything of style "a href=XXX" and matching end tag + // add 2 cursors and save this link in a list +} + +void +_edje_entry_set_cursor_start(Edje_Real_Part *rp) +{ + Entry *en = rp->entry_data; + if (!en) return; + _curs_start(en->cursor, rp->object, en); +} + +void +_edje_entry_set_cursor_end(Edje_Real_Part *rp) +{ + Entry *en = rp->entry_data; + if (!en) return; + _curs_end(en->cursor, rp->object, en); +} + +// FIXME: apis 's query anchor stuff??? diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h index b70edf6430..3b3997f945 100644 --- a/legacy/edje/src/lib/edje_private.h +++ b/legacy/edje/src/lib/edje_private.h @@ -260,7 +260,6 @@ typedef struct _Edje_Patterns Edje_Patterns; #define EDJE_STATE_PARAM_VISIBLE 31 #define EDJE_STATE_PARAM_LAST 32 -// FIXME: doing #define EDJE_ENTRY_EDIT_MODE_NONE 0 #define EDJE_ENTRY_EDIT_MODE_SELECTABLE 1 #define EDJE_ENTRY_EDIT_MODE_EDITABLE 2 @@ -1237,5 +1236,10 @@ void _edje_entry_shutdown(Edje *ed); void _edje_entry_real_part_init(Edje_Real_Part *rp); void _edje_entry_real_part_shutdown(Edje_Real_Part *rp); void _edje_entry_real_part_configure(Edje_Real_Part *rp); +char *_edje_entry_selection_get(Edje_Real_Part *rp); +const char *_edje_entry_text_get(Edje_Real_Part *rp); +void _edje_entry_text_markup_set(Edje_Real_Part *rp, const char *text); +void _edje_entry_set_cursor_start(Edje_Real_Part *rp); +void _edje_entry_set_cursor_end(Edje_Real_Part *rp); #endif diff --git a/legacy/edje/src/lib/edje_util.c b/legacy/edje/src/lib/edje_util.c index 5826bad260..2cfe3043c1 100644 --- a/legacy/edje/src/lib/edje_util.c +++ b/legacy/edje/src/lib/edje_util.c @@ -878,9 +878,17 @@ edje_object_part_text_set(Evas_Object *obj, const char *part, const char *text) if ((rp->text.text) && (text) && (!strcmp(rp->text.text, text))) return; - if (rp->text.text) evas_stringshare_del(rp->text.text); - if (text) rp->text.text = evas_stringshare_add(text); - else rp->text.text = NULL; + if (rp->text.text) + { + evas_stringshare_del(rp->text.text); + rp->text.text = NULL; + } + if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) + { + _edje_entry_text_markup_set(rp, text); + } + else + if (text) rp->text.text = evas_stringshare_add(text); rp->edje->dirty = 1; _edje_recalc(rp->edje); if (rp->edje->text_change.func) @@ -902,8 +910,15 @@ edje_object_part_text_get(const Evas_Object *obj, const char *part) if ((!ed) || (!part)) return NULL; rp = _edje_real_part_recursive_get(ed, (char *)part); if (!rp) return NULL; - if (rp->part->type == EDJE_PART_TYPE_TEXT) - return rp->text.text; + if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE) + { + return _edje_entry_text_get(rp); + } + else + { + if (rp->part->type == EDJE_PART_TYPE_TEXT) + return rp->text.text; + } return NULL; }