2015-08-30 11:25:53 -05:00
|
|
|
// 8 april 2015
|
2016-04-22 19:14:12 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-08-30 11:25:53 -05:00
|
|
|
|
|
|
|
struct uiEntry {
|
|
|
|
uiWindowsControl c;
|
|
|
|
HWND hwnd;
|
|
|
|
void (*onChanged)(uiEntry *, void *);
|
|
|
|
void *onChangedData;
|
|
|
|
BOOL inhibitChanged;
|
|
|
|
};
|
|
|
|
|
|
|
|
uiWindowsDefineControlWithOnDestroy(
|
|
|
|
uiEntry, // type name
|
2016-04-23 15:52:53 -05:00
|
|
|
uiWindowsUnregisterWM_COMMANDHandler(me->hwnd); // on destroy
|
2015-08-30 11:25:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
uiEntry *e = uiEntry(c);
|
|
|
|
|
|
|
|
if (code != EN_CHANGE)
|
|
|
|
return FALSE;
|
|
|
|
if (e->inhibitChanged)
|
|
|
|
return FALSE;
|
|
|
|
(*(e->onChanged))(e, e->onChangedData);
|
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 */
|
|
|
|
#define entryHeight 14
|
|
|
|
|
2015-08-31 16:50:23 -05:00
|
|
|
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
2015-08-30 11:25:53 -05:00
|
|
|
{
|
|
|
|
*width = uiWindowsDlgUnitsToX(entryWidth, d->BaseX);
|
|
|
|
*height = uiWindowsDlgUnitsToY(entryHeight, d->BaseY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiEntry *e, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
char *uiEntryText(uiEntry *e)
|
|
|
|
{
|
2016-04-22 19:04:30 -05:00
|
|
|
return uiWindowsWindowText(e->hwnd);
|
2015-08-30 11:25:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiEntrySetText(uiEntry *e, const char *text)
|
|
|
|
{
|
|
|
|
// doing this raises an EN_CHANGED
|
|
|
|
e->inhibitChanged = TRUE;
|
2016-04-22 19:04:30 -05:00
|
|
|
uiWindowsSetWindowText(e->hwnd, text);
|
2015-08-30 11:25:53 -05:00
|
|
|
e->inhibitChanged = FALSE;
|
|
|
|
// don't queue the control for resize; entry sizes are independent of their contents
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *, void *), void *data)
|
|
|
|
{
|
|
|
|
e->onChanged = f;
|
|
|
|
e->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uiEntryReadOnly(uiEntry *e)
|
|
|
|
{
|
|
|
|
return (getStyle(e->hwnd) & ES_READONLY) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiEntrySetReadOnly(uiEntry *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 uiEntry read-only");
|
2015-08-30 11:25:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiEntry *uiNewEntry(void)
|
|
|
|
{
|
|
|
|
uiEntry *e;
|
|
|
|
|
2016-04-24 16:38:48 -05:00
|
|
|
e = (uiEntry *) uiNewControl(uiEntry);
|
2015-08-30 11:25:53 -05:00
|
|
|
|
2015-08-31 11:33:44 -05:00
|
|
|
e->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
|
2015-08-30 11:25:53 -05:00
|
|
|
L"edit", L"",
|
|
|
|
ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP,
|
|
|
|
hInstance, NULL,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e));
|
2015-09-01 06:21:18 -05:00
|
|
|
uiEntryOnChanged(e, defaultOnChanged, NULL);
|
2015-08-30 11:25:53 -05:00
|
|
|
|
|
|
|
uiWindowsFinishNewControl(e, uiEntry);
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|