improve mledit for web

This commit is contained in:
xianjimli 2019-07-07 08:52:14 +08:00
parent f4b6699537
commit 4d22ef7a30
3 changed files with 19 additions and 4 deletions

View File

@ -182,6 +182,7 @@ static ret_t mledit_on_destroy(widget_t* widget) {
mledit_t* mledit = MLEDIT(widget);
return_value_if_fail(widget != NULL && mledit != NULL, RET_BAD_PARAMS);
wstr_reset(&(mledit->temp));
text_edit_destroy(mledit->model);
return RET_OK;
@ -196,11 +197,10 @@ static ret_t mledit_on_paint_self(widget_t* widget, canvas_t* c) {
}
static ret_t mledit_commit_str(widget_t* widget, const char* str) {
wchar_t wstr[32] = {0};
mledit_t* mledit = MLEDIT(widget);
utf8_to_utf16(str, wstr, ARRAY_SIZE(wstr));
wstr_set_utf8(&(mledit->temp), str);
text_edit_paste(mledit->model, wstr, wcslen(wstr));
text_edit_paste(mledit->model, mledit->temp.str, mledit->temp.size);
return RET_OK;
}
@ -273,6 +273,16 @@ static ret_t mledit_pointer_up_cleanup(widget_t* widget) {
return RET_OK;
}
ret_t mledit_clear(mledit_t* mledit) {
widget_t* widget = WIDGET(mledit);
return_value_if_fail(widget != NULL && mledit != NULL, RET_BAD_PARAMS);
widget->text.size = 0;
text_edit_set_cursor(mledit->model, 0);
return widget_invalidate_force(widget, NULL);
}
static ret_t mledit_on_event(widget_t* widget, event_t* e) {
uint32_t type = e->type;
mledit_t* mledit = MLEDIT(widget);
@ -318,6 +328,9 @@ static ret_t mledit_on_event(widget_t* widget, event_t* e) {
}
case EVT_IM_COMMIT: {
im_commit_event_t* evt = (im_commit_event_t*)e;
if (evt->replace) {
mledit_clear(mledit);
}
mledit_commit_str(widget, evt->text);
mledit_update_status(widget);
break;
@ -466,6 +479,7 @@ widget_t* mledit_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
mledit->top_margin = 1;
mledit->right_margin = 1;
mledit->bottom_margin = 1;
wstr_init(&(mledit->temp), 0);
return widget;
}

View File

@ -119,6 +119,8 @@ typedef struct _mledit_t {
/*private*/
text_edit_t* model;
uint32_t timer_id;
wstr_t temp;
} mledit_t;
/**

View File

@ -47,7 +47,6 @@ static ret_t hscroll_label_do_paint_self_ellipses(widget_t* widget, canvas_t* c,
if ((x + ellipses_w) >= right) {
x = last_x;
i = i;
break;
}