src/misc_gui.cpp
changeset 10751 ebd94f2d6385
parent 10703 2c998f3776d1
child 10754 e190e710da4e
equal deleted inserted replaced
10749:b8ac8a8e27c4 10751:ebd94f2d6385
   749 	WChar c;
   749 	WChar c;
   750 	char *s = tb->buf + tb->caretpos;
   750 	char *s = tb->buf + tb->caretpos;
   751 
   751 
   752 	if (backspace) s = Utf8PrevChar(s);
   752 	if (backspace) s = Utf8PrevChar(s);
   753 
   753 
   754 	size_t len = Utf8Decode(&c, s);
   754 	uint16 len = (uint16)Utf8Decode(&c, s);
   755 	uint width = GetCharacterWidth(FS_NORMAL, c);
   755 	uint width = GetCharacterWidth(FS_NORMAL, c);
   756 
   756 
   757 	tb->width  -= width;
   757 	tb->width  -= width;
   758 	if (backspace) {
   758 	if (backspace) {
   759 		tb->caretpos   -= len;
   759 		tb->caretpos   -= len;
   805  * @return Return true on successful change of Textbuf, or false otherwise
   805  * @return Return true on successful change of Textbuf, or false otherwise
   806  */
   806  */
   807 bool InsertTextBufferChar(Textbuf *tb, WChar key)
   807 bool InsertTextBufferChar(Textbuf *tb, WChar key)
   808 {
   808 {
   809 	const byte charwidth = GetCharacterWidth(FS_NORMAL, key);
   809 	const byte charwidth = GetCharacterWidth(FS_NORMAL, key);
   810 	size_t len = Utf8CharLen(key);
   810 	uint16 len = (uint16)Utf8CharLen(key);
   811 	if (tb->length < (tb->maxlength - len) && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
   811 	if (tb->length < (tb->maxlength - len) && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
   812 		memmove(tb->buf + tb->caretpos + len, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
   812 		memmove(tb->buf + tb->caretpos + len, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
   813 		Utf8Encode(tb->buf + tb->caretpos, key);
   813 		Utf8Encode(tb->buf + tb->caretpos, key);
   814 		tb->length += len;
   814 		tb->length += len;
   815 		tb->width  += charwidth;
   815 		tb->width  += charwidth;
   845 
   845 
   846 		case WKC_RIGHT:
   846 		case WKC_RIGHT:
   847 			if (tb->caretpos < tb->length) {
   847 			if (tb->caretpos < tb->length) {
   848 				WChar c;
   848 				WChar c;
   849 
   849 
   850 				tb->caretpos   += Utf8Decode(&c, tb->buf + tb->caretpos);
   850 				tb->caretpos   += (uint16)Utf8Decode(&c, tb->buf + tb->caretpos);
   851 				tb->caretxoffs += GetCharacterWidth(FS_NORMAL, c);
   851 				tb->caretxoffs += GetCharacterWidth(FS_NORMAL, c);
   852 
   852 
   853 				return true;
   853 				return true;
   854 			}
   854 			}
   855 			break;
   855 			break;