From f3dad94039bf79dfc08a10693c32aa62fcc9cd44 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 22 May 2016 13:42:37 -0400 Subject: [PATCH] Added CRLF translation to uiMultilineEntry on Windows. More TODOs. --- README.md | 1 + windows/multilineentry.cpp | 16 ++++++++++++++-- windows/uipriv_windows.hpp | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b7a6b562..0f602090 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ This README is being written.
* **22 May 2016** ** Removed `uiControlVerifyDestroy()`; that is now part of `uiFreeControl()` itself. ** Added `uiPi`, a constant for π. This is provided for C and C++ programmers, where there is no standard named constant for π; bindings authors shouldn't need to worry about this. +** Fixed uiMultilineEntry not properly having line breaks on Windows. ## Runtime Requirements diff --git a/windows/multilineentry.cpp b/windows/multilineentry.cpp index 38908f38..afb5ceaa 100644 --- a/windows/multilineentry.cpp +++ b/windows/multilineentry.cpp @@ -63,15 +63,23 @@ static void defaultOnChanged(uiMultilineEntry *e, void *data) // TODO apply crlf conversion char *uiMultilineEntryText(uiMultilineEntry *e) { - return uiWindowsWindowText(e->hwnd); + char *out; + + out = uiWindowsWindowText(e->hwnd); + CRLFtoLF(out); + return out; } // TODO apply crlf conversion void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text) { + char *crlf; + // doing this raises an EN_CHANGED e->inhibitChanged = TRUE; + crlf = LFtoCRLF(text); uiWindowsSetWindowText(e->hwnd, text); + uiFree(crlf); e->inhibitChanged = FALSE; // don't queue the control for resize; entry sizes are independent of their contents } @@ -80,14 +88,18 @@ void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text) void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text) { LRESULT n; + char *crlf; WCHAR *wtext; // TODO does doing this raise EN_CHANGED? // TODO preserve selection? caret? what if caret used to be at end? // TODO scroll to bottom? + // TODO overdraw issues n = SendMessageW(e->hwnd, WM_GETTEXTLENGTH, 0, 0); SendMessageW(e->hwnd, EM_SETSEL, n, n); - wtext = toUTF16(text); + crlf = LFtoCRLF(text); + wtext = toUTF16(crlf); + uiFree(crlf); SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext); uiFree(wtext); } diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index dcd31617..7cd2be62 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -36,7 +36,7 @@ extern WCHAR *utf16dup(const WCHAR *orig); extern WCHAR *strf(const WCHAR *format, ...); extern WCHAR *vstrf(const WCHAR *format, va_list ap); extern char *LFtoCRLF(const char *lfonly); -extern void CRLFtoLF(const char *s); +extern void CRLFtoLF(char *s); extern WCHAR *ftoutf16(double d); extern WCHAR *itoutf16(intmax_t i);