Skip to content

Commit

Permalink
feat(textedit): add TextEdit_GetProperty()
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Jun 17, 2019
1 parent 062f713 commit 512706e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/LCUI/gui/widget/textedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ LCUI_API size_t TextEdit_GetTextLength(LCUI_Widget w);
/** 设置文本编辑框内的光标,指定是否闪烁、闪烁时间间隔 */
LCUI_API void TextEdit_SetCaretBlink(LCUI_Widget w, LCUI_BOOL visible, int time);

/** 为文本框设置文本(宽字符版) */
LCUI_API LCUI_Object TextEdit_GetProperty(LCUI_Widget w, const char *name);

/** 为文本框设置文本(宽字符版) */
LCUI_API int TextEdit_SetTextW(LCUI_Widget widget, const wchar_t *wstr);

LCUI_API int TextEdit_SetText(LCUI_Widget widget, const char *utf8_str);
Expand Down
3 changes: 2 additions & 1 deletion src/font/textlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ size_t TextLayer_GetTextW(LCUI_TextLayer layer, size_t start_pos,
LCUI_TextRow row_ptr;

if (max_len == 0) {
wstr_buff[0] = 0;
return 0;
}
/* 先根据一维坐标计算行列坐标 */
Expand All @@ -894,7 +895,7 @@ size_t TextLayer_GetTextW(LCUI_TextLayer layer, size_t start_pos,
wstr_buff[i] = row_ptr->string[col]->code;
}
}
wstr_buff[i] = L'\0';
wstr_buff[i] = 0;
return i;
}

Expand Down
16 changes: 16 additions & 0 deletions src/gui/widget/textedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ size_t TextEdit_GetTextLength(LCUI_Widget w)
return edit->layer_source->length;
}

LCUI_Object TextEdit_GetProperty(LCUI_Widget w, const char *name)
{
size_t len = TextEdit_GetTextLength(w);
size_t size = (len + 1) * sizeof(wchar_t);
wchar_t *wcs = malloc(size);
LCUI_Object prop;

if (strcmp(name, "value") != 0) {
return NULL;
}
TextEdit_GetTextW(w, 0, len, wcs);
prop = WString_New(wcs);
free(wcs);
return prop;
}

int TextEdit_SetTextW(LCUI_Widget w, const wchar_t *wstr)
{
TextEdit_ClearText(w);
Expand Down

0 comments on commit 512706e

Please sign in to comment.