libui/windows/entry.c

119 lines
2.7 KiB
C
Raw Normal View History

2015-04-08 22:43:01 -05:00
// 8 april 2015
#include "uipriv_windows.h"
struct entry {
uiEntry e;
HWND hwnd;
void (*onChanged)(uiEntry *, void *);
void *onChangedData;
2015-04-08 22:43:01 -05:00
};
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
2015-04-08 22:43:01 -05:00
{
struct entry *e = (struct entry *) c;
if (code != EN_CHANGE)
return FALSE;
(*(e->onChanged))(uiEntry(e), e->onChangedData);
*lResult = 0;
return TRUE;
2015-04-08 22:43:01 -05:00
}
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
2015-04-08 22:43:01 -05:00
{
return FALSE;
}
static void onDestroy(void *data)
2015-04-08 22:43:01 -05:00
{
struct entry *e = (struct entry *) data;
2015-04-08 22:43:01 -05:00
uiFree(e);
}
// 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
static void entryPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
2015-04-08 22:43:01 -05:00
{
*width = uiWindowsDlgUnitsToX(entryWidth, d->sys->baseX);
*height = uiWindowsDlgUnitsToY(entryHeight, d->sys->baseY);
2015-04-08 22:43:01 -05:00
}
static void defaultOnChanged(uiEntry *e, void *data)
{
// do nothing
}
static char *entryText(uiEntry *e)
{
return uiWindowsControlText(uiControl(e));
}
static void entrySetText(uiEntry *e, const char *text)
{
uiWindowsControlSetText(uiControl(e), text);
}
static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data)
{
struct entry *e = (struct entry *) ee;
e->onChanged = f;
e->onChangedData = data;
}
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;
uiWindowsMakeControlParams p;
2015-04-08 22:43:01 -05:00
e = uiNew(struct entry);
2015-04-08 22:43:01 -05:00
p.dwExStyle = WS_EX_CLIENTEDGE;
p.lpClassName = L"edit";
p.lpWindowName = L"";
p.dwStyle = ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP;
2015-04-08 22:43:01 -05:00
p.hInstance = hInstance;
p.useStandardControlFont = TRUE;
2015-04-08 22:43:01 -05:00
p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY;
p.onDestroy = onDestroy;
p.onDestroyData = e;
uiWindowsMakeControl(uiControl(e), &p);
2015-04-09 16:46:26 -05:00
e->hwnd = (HWND) uiControlHandle(uiControl(e));
e->onChanged = defaultOnChanged;
uiControl(e)->PreferredSize = entryPreferredSize;
2015-04-08 22:43:01 -05:00
uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText;
uiEntry(e)->OnChanged = entryOnChanged;
uiEntry(e)->ReadOnly = entryReadOnly;
uiEntry(e)->SetReadOnly = entrySetReadOnly;
return uiEntry(e);
}