2015-04-08 22:43:01 -05:00
|
|
|
// 8 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct entry {
|
2015-04-16 08:20:00 -05:00
|
|
|
uiEntry e;
|
2015-04-17 10:13:42 -05:00
|
|
|
HWND hwnd;
|
2015-05-06 19:06:16 -05:00
|
|
|
void (*onChanged)(uiEntry *, void *);
|
|
|
|
void *onChangedData;
|
2015-05-09 20:18:27 -05:00
|
|
|
BOOL inhibitChanged;
|
2015-05-29 17:03:24 -05:00
|
|
|
void (*baseCommitDestroy)(uiControl *);
|
2015-04-08 22:43:01 -05:00
|
|
|
};
|
|
|
|
|
2015-05-29 17:03:24 -05:00
|
|
|
uiDefineControlType(uiEntry, uiTypeEntry, struct entry)
|
|
|
|
|
2015-05-21 13:52:21 -05:00
|
|
|
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
2015-04-08 22:43:01 -05:00
|
|
|
{
|
2015-05-06 19:06:16 -05:00
|
|
|
struct entry *e = (struct entry *) c;
|
|
|
|
|
|
|
|
if (code != EN_CHANGE)
|
|
|
|
return FALSE;
|
2015-05-09 20:18:27 -05:00
|
|
|
if (e->inhibitChanged)
|
|
|
|
return FALSE;
|
2015-05-06 19:06:16 -05:00
|
|
|
(*(e->onChanged))(uiEntry(e), e->onChangedData);
|
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
2015-04-08 22:43:01 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 17:03:24 -05:00
|
|
|
static void entryCommitDestroy(uiControl *c)
|
2015-04-08 22:43:01 -05:00
|
|
|
{
|
2015-05-29 17:03:24 -05:00
|
|
|
struct entry *e = (struct entry *) c;
|
2015-04-08 22:43:01 -05:00
|
|
|
|
2015-05-21 11:07:11 -05:00
|
|
|
uiWindowsUnregisterWM_COMMANDHandler(e->hwnd);
|
2015-05-29 17:03:24 -05:00
|
|
|
(*(e->baseCommitDestroy))(uiControl(e));
|
2015-04-08 22:43:01 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 18:48:27 -05:00
|
|
|
static uintptr_t entryHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) c;
|
|
|
|
|
|
|
|
return (uintptr_t) (e->hwnd);
|
|
|
|
}
|
|
|
|
|
2015-04-08 22:43:01 -05: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 */
|
|
|
|
#define entryHeight 14
|
|
|
|
|
2015-05-04 13:56:26 -05:00
|
|
|
static void entryPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
2015-04-08 22:43:01 -05:00
|
|
|
{
|
2015-05-07 13:33:46 -05:00
|
|
|
*width = uiWindowsDlgUnitsToX(entryWidth, d->Sys->BaseX);
|
|
|
|
*height = uiWindowsDlgUnitsToY(entryHeight, d->Sys->BaseY);
|
2015-04-08 22:43:01 -05:00
|
|
|
}
|
|
|
|
|
2015-05-06 19:06:16 -05:00
|
|
|
static void defaultOnChanged(uiEntry *e, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-04-17 10:13:42 -05:00
|
|
|
static char *entryText(uiEntry *e)
|
2015-04-16 08:20:00 -05:00
|
|
|
{
|
|
|
|
return uiWindowsControlText(uiControl(e));
|
|
|
|
}
|
|
|
|
|
2015-05-09 20:18:27 -05:00
|
|
|
static void entrySetText(uiEntry *ee, const char *text)
|
2015-04-16 08:20:00 -05:00
|
|
|
{
|
2015-05-09 20:18:27 -05:00
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
// doing this raises an EN_CHANGED
|
|
|
|
e->inhibitChanged = TRUE;
|
2015-04-16 08:20:00 -05:00
|
|
|
uiWindowsControlSetText(uiControl(e), text);
|
2015-05-09 20:18:27 -05:00
|
|
|
e->inhibitChanged = FALSE;
|
2015-04-16 08:20:00 -05:00
|
|
|
}
|
|
|
|
|
2015-05-06 19:06:16 -05:00
|
|
|
static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
e->onChanged = f;
|
|
|
|
e->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
2015-05-06 21:21:11 -05:00
|
|
|
static int entryReadOnly(uiEntry *ee)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
return (getStyle(e->hwnd) & ES_READONLY) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void entrySetReadOnly(uiEntry *ee, int readonly)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
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 entrySetReadOnly()");
|
|
|
|
}
|
|
|
|
|
2015-04-16 08:33:21 -05:00
|
|
|
uiEntry *uiNewEntry(void)
|
2015-04-08 22:43:01 -05:00
|
|
|
{
|
|
|
|
struct entry *e;
|
2015-05-29 17:03:24 -05:00
|
|
|
|
|
|
|
e = (struct entry *) uiWindowsNewSingleHWNDControl(uiTypeEntry());
|
|
|
|
|
2015-05-29 19:53:12 -05:00
|
|
|
e->hwnd = uiWindowsUtilCreateControlHWND(WS_EX_CLIENTEDGE,
|
2015-05-29 17:03:24 -05:00
|
|
|
L"edit", L"",
|
|
|
|
ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP,
|
|
|
|
hInstance, NULL,
|
|
|
|
TRUE);
|
|
|
|
|
2015-05-21 11:07:11 -05:00
|
|
|
uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e));
|
2015-04-17 10:13:42 -05:00
|
|
|
|
2015-05-06 19:06:16 -05:00
|
|
|
e->onChanged = defaultOnChanged;
|
|
|
|
|
2015-05-29 18:48:27 -05:00
|
|
|
uiControl(e)->Handle = entryHandle;
|
2015-05-04 13:56:26 -05:00
|
|
|
uiControl(e)->PreferredSize = entryPreferredSize;
|
2015-05-29 17:03:24 -05:00
|
|
|
e->baseCommitDestroy = uiControl(e)->CommitDestroy;
|
|
|
|
uiControl(e)->CommitDestroy = entryCommitDestroy;
|
2015-04-08 22:43:01 -05:00
|
|
|
|
2015-04-17 10:13:42 -05:00
|
|
|
uiEntry(e)->Text = entryText;
|
|
|
|
uiEntry(e)->SetText = entrySetText;
|
2015-05-06 19:06:16 -05:00
|
|
|
uiEntry(e)->OnChanged = entryOnChanged;
|
2015-05-06 21:21:11 -05:00
|
|
|
uiEntry(e)->ReadOnly = entryReadOnly;
|
|
|
|
uiEntry(e)->SetReadOnly = entrySetReadOnly;
|
2015-04-09 10:12:01 -05:00
|
|
|
|
2015-04-16 08:20:00 -05:00
|
|
|
return uiEntry(e);
|
2015-04-09 10:12:01 -05:00
|
|
|
}
|