From b623f5953691b2a0614e6f1f4def86bdbb9a4113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 8 Aug 2020 11:53:00 +0200 Subject: New upstream version 5.2.0Beta2.1 --- app/wlib/mswlib/mswtext.c | 63 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 24 deletions(-) (limited to 'app/wlib/mswlib/mswtext.c') diff --git a/app/wlib/mswlib/mswtext.c b/app/wlib/mswlib/mswtext.c index 293e2b4..0a0ce88 100644 --- a/app/wlib/mswlib/mswtext.c +++ b/app/wlib/mswlib/mswtext.c @@ -137,6 +137,9 @@ void wTextAppend( if (b->option&BO_READONLY) { SendMessage(b->hWnd, EM_SETREADONLY, 1, 0L); } + + // scroll to bottom of text box + SendMessage(b->hWnd, EM_LINESCROLL, 0, 10000L); } @@ -247,42 +250,54 @@ wBool_t wTextGetModified( return (wBool_t)rc; } +/** + * Get the size of the text in the text control including terminating '\0'. Note that + * the text actually might be shorter if the text includes CRs. + * + * \param b IN text control + * \return required buffer size + */ int wTextGetSize( wText_p b) { - int lc, l, len=0; - lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L); + int len; - for (l=0; lhWnd, EM_LINEINDEX, l, 0L); - len += (int)SendMessage(b->hWnd, EM_LINELENGTH, charIndex, 0L) + 1; - } - - if (len == 1) { - len = 0; - } + len = GetWindowTextLength(b->hWnd); - return len; + return len + 1; } +/** + * Get the text from a textentry. The buffer must be large enough for the text and + * the terminating \0. + * In case the string contains carriage returns these are removed. The returned string + * will be shortened accordingly. + * To get the complete contents the buffer size must be equal or greater then the return + * value of wTextGetSize() + * + * \param b IN text entry + * \param t IN/OUT buffer for text + * \param s IN size of buffer + */ + void wTextGetText( wText_p b, char * t, int s) { - int lc, l, len; - s--; - lc = (int)SendMessage(b->hWnd, EM_GETLINECOUNT, 0, 0L); - - for (l=0; l=0; l++) { - *(WORD*)t = s; - len = (int)SendMessage(b->hWnd, EM_GETLINE, l, (LPARAM)t); - t += len; - *t++ = '\n'; - s -= len+1; - } - - *(t - 1) = '\0'; // overwrite the last \n added + char *buffer = malloc(s); + char *ptr = buffer; + GetWindowText(b->hWnd, buffer, s); + + // remove carriage returns + while (*ptr) { + if (*ptr != '\r') { + *t = *ptr; + t++; + } + ptr++; + } + free(buffer); } -- cgit v1.2.3