2015-12-06 13:38:13 -06:00
|
|
|
// 8 april 2015
|
2016-04-22 19:14:12 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-12-06 13:38:13 -06:00
|
|
|
|
2016-05-29 20:13:03 -05:00
|
|
|
// TODO there's alpha darkening of text going on in read-only ones; something is up in our parent logic
|
2015-12-06 13:38:13 -06:00
|
|
|
|
|
|
|
struct uiMultilineEntry {
|
|
|
|
uiWindowsControl c;
|
|
|
|
HWND hwnd;
|
|
|
|
void (*onChanged)(uiMultilineEntry *, void *);
|
|
|
|
void *onChangedData;
|
|
|
|
BOOL inhibitChanged;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
uiMultilineEntry *e = uiMultilineEntry(c);
|
|
|
|
|
|
|
|
if (code != EN_CHANGE)
|
|
|
|
return FALSE;
|
|
|
|
if (e->inhibitChanged)
|
|
|
|
return FALSE;
|
|
|
|
(*(e->onChanged))(e, e->onChangedData);
|
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-04-29 12:50:08 -05:00
|
|
|
static void uiMultilineEntryDestroy(uiControl *c)
|
|
|
|
{
|
|
|
|
uiMultilineEntry *e = uiMultilineEntry(c);
|
|
|
|
|
|
|
|
uiWindowsUnregisterWM_COMMANDHandler(e->hwnd);
|
|
|
|
uiWindowsEnsureDestroyWindow(e->hwnd);
|
|
|
|
uiFreeControl(uiControl(e));
|
|
|
|
}
|
|
|
|
|
2016-04-29 16:08:31 -05:00
|
|
|
uiWindowsControlAllDefaultsExceptDestroy(uiMultilineEntry)
|
2016-04-29 12:50:08 -05:00
|
|
|
|
2015-12-06 13:38:13 -06:00
|
|
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
#define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */
|
2016-05-29 20:13:03 -05:00
|
|
|
// LONGTERM change this for multiline text boxes (longterm because how?)
|
2015-12-06 13:38:13 -06:00
|
|
|
#define entryHeight 14
|
|
|
|
|
2016-06-13 20:54:15 -05:00
|
|
|
static void uiMultilineEntryMinimumSize(uiWindowsControl *c, int *width, int *height)
|
2015-12-06 13:38:13 -06:00
|
|
|
{
|
2016-04-29 12:50:08 -05:00
|
|
|
uiMultilineEntry *e = uiMultilineEntry(c);
|
|
|
|
uiWindowsSizing sizing;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
x = entryWidth;
|
|
|
|
y = entryHeight;
|
|
|
|
uiWindowsGetSizing(e->hwnd, &sizing);
|
|
|
|
uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y);
|
|
|
|
*width = x;
|
|
|
|
*height = y;
|
2015-12-06 13:38:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiMultilineEntry *e, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
char *uiMultilineEntryText(uiMultilineEntry *e)
|
|
|
|
{
|
2016-05-22 12:42:37 -05:00
|
|
|
char *out;
|
|
|
|
|
|
|
|
out = uiWindowsWindowText(e->hwnd);
|
|
|
|
CRLFtoLF(out);
|
|
|
|
return out;
|
2015-12-06 13:38:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)
|
|
|
|
{
|
2016-05-22 12:42:37 -05:00
|
|
|
char *crlf;
|
|
|
|
|
2015-12-06 13:38:13 -06:00
|
|
|
// doing this raises an EN_CHANGED
|
|
|
|
e->inhibitChanged = TRUE;
|
2016-05-22 12:42:37 -05:00
|
|
|
crlf = LFtoCRLF(text);
|
2018-05-28 12:37:40 -05:00
|
|
|
uiWindowsSetWindowText(e->hwnd, crlf);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(crlf);
|
2015-12-06 13:38:13 -06:00
|
|
|
e->inhibitChanged = FALSE;
|
|
|
|
// don't queue the control for resize; entry sizes are independent of their contents
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text)
|
|
|
|
{
|
|
|
|
LRESULT n;
|
2016-05-22 12:42:37 -05:00
|
|
|
char *crlf;
|
2015-12-06 13:38:13 -06:00
|
|
|
WCHAR *wtext;
|
|
|
|
|
2016-05-29 20:13:03 -05:00
|
|
|
// doing this raises an EN_CHANGED
|
|
|
|
e->inhibitChanged = TRUE;
|
2015-12-06 13:38:13 -06:00
|
|
|
// TODO preserve selection? caret? what if caret used to be at end?
|
|
|
|
// TODO scroll to bottom?
|
|
|
|
n = SendMessageW(e->hwnd, WM_GETTEXTLENGTH, 0, 0);
|
|
|
|
SendMessageW(e->hwnd, EM_SETSEL, n, n);
|
2016-05-22 12:42:37 -05:00
|
|
|
crlf = LFtoCRLF(text);
|
|
|
|
wtext = toUTF16(crlf);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(crlf);
|
2015-12-06 13:38:13 -06:00
|
|
|
SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(wtext);
|
2016-05-29 20:13:03 -05:00
|
|
|
e->inhibitChanged = FALSE;
|
2015-12-06 13:38:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiMultilineEntryOnChanged(uiMultilineEntry *e, void (*f)(uiMultilineEntry *, void *), void *data)
|
|
|
|
{
|
|
|
|
e->onChanged = f;
|
|
|
|
e->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uiMultilineEntryReadOnly(uiMultilineEntry *e)
|
|
|
|
{
|
|
|
|
return (getStyle(e->hwnd) & ES_READONLY) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly)
|
|
|
|
{
|
|
|
|
WPARAM ro;
|
|
|
|
|
|
|
|
ro = (WPARAM) FALSE;
|
|
|
|
if (readonly)
|
|
|
|
ro = (WPARAM) TRUE;
|
|
|
|
if (SendMessage(e->hwnd, EM_SETREADONLY, ro, 0) == 0)
|
2016-04-22 19:14:12 -05:00
|
|
|
logLastError(L"error making uiMultilineEntry read-only");
|
2015-12-06 13:38:13 -06:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:56:36 -05:00
|
|
|
static uiMultilineEntry *finishMultilineEntry(DWORD style)
|
2015-12-06 13:38:13 -06:00
|
|
|
{
|
|
|
|
uiMultilineEntry *e;
|
|
|
|
|
2016-04-29 12:50:08 -05:00
|
|
|
uiWindowsNewControl(uiMultilineEntry, e);
|
2015-12-06 13:38:13 -06:00
|
|
|
|
|
|
|
e->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
|
|
|
|
L"edit", L"",
|
2016-05-22 12:56:36 -05:00
|
|
|
ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | ES_WANTRETURN | WS_TABSTOP | WS_VSCROLL | style,
|
2015-12-06 13:38:13 -06:00
|
|
|
hInstance, NULL,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e));
|
|
|
|
uiMultilineEntryOnChanged(e, defaultOnChanged, NULL);
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
2016-05-22 12:56:36 -05:00
|
|
|
|
|
|
|
uiMultilineEntry *uiNewMultilineEntry(void)
|
|
|
|
{
|
|
|
|
return finishMultilineEntry(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiMultilineEntry *uiNewNonWrappingMultilineEntry(void)
|
|
|
|
{
|
|
|
|
return finishMultilineEntry(WS_HSCROLL | ES_AUTOHSCROLL);
|
|
|
|
}
|