summaryrefslogtreecommitdiff
path: root/app/wlib/mswlib/mswtext.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 21:26:53 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-24 21:26:53 +0200
commitdf247efec654e512242e4f4f1b0212034f9e01fe (patch)
tree25c02e16957f3aa613af30c140fd8e8a3d52fda6 /app/wlib/mswlib/mswtext.c
parentd0b6a8a4ec298024f14f704f9e40a6f9d324ccf3 (diff)
parenta5ade52caa489cf0a713e0f02b764000d203140e (diff)
Merge branch 'release/debian/1%5.2.0Beta2.1-1' into masterdebian/1%5.2.0Beta2.1-1
Diffstat (limited to 'app/wlib/mswlib/mswtext.c')
-rw-r--r--app/wlib/mswlib/mswtext.c63
1 files changed, 39 insertions, 24 deletions
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; l<lc ; l++) {
- int charIndex = (int)SendMessage(b->hWnd, 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<lc && s>=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);
}