2015-08-30 11:25:53 -05:00
|
|
|
// 8 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct uiEntry {
|
|
|
|
uiWindowsControl c;
|
|
|
|
HWND hwnd;
|
|
|
|
void (*onChanged)(uiEntry *, void *);
|
|
|
|
void *onChangedData;
|
|
|
|
BOOL inhibitChanged;
|
|
|
|
};
|
|
|
|
|
|
|
|
uiWindowsDefineControlWithOnDestroy(
|
|
|
|
uiEntry, // type name
|
|
|
|
uiEntryType, // type function
|
|
|
|
uiWindowsUnregisterWM_COMMANDHandler(this->hwnd); // on destroy
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return uiWindowsUtilText(e->hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiEntrySetText(uiEntry *e, const char *text)
|
|
|
|
{
|
|
|
|
// doing this raises an EN_CHANGED
|
|
|
|
e->inhibitChanged = TRUE;
|
|
|
|
uiWindowsUtilSetText(e->hwnd, text);
|
|
|
|
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)
|
|
|
|
logLastError("error making uiEntry read-only in uiEntrySetReadOnly()");
|
|
|
|
}
|
|
|
|
|
|
|
|
uiEntry *uiNewEntry(void)
|
|
|
|
{
|
|
|
|
uiEntry *e;
|
|
|
|
|
2015-08-31 16:50:23 -05:00
|
|
|
e = (uiEntry *) uiNewControl(uiEntryType());
|
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;
|
|
|
|
}
|