Implemented uiEntryOnChanged() on Windows.

This commit is contained in:
Pietro Gagliardi 2015-05-06 20:06:16 -04:00
parent fba7450da3
commit 5128fed0af
2 changed files with 27 additions and 1 deletions

View File

@ -61,6 +61,7 @@
- add a final cleanup function (uiUninit() or uiCleanup())
- whenever a list of things is destroyed, each successive item must be removed as it is destroyed, otherwise we might wind up in a situation where we access items after they're freed
- make the name of the variable to refer to a single tab page consistent (already decided to make them all `page`)
- make sure uiEntryOnChanged() is not triggered when calling uiEntrySetText()
ultimately:
- add some sort of runtime type checking

View File

@ -4,11 +4,20 @@
struct entry {
uiEntry e;
HWND hwnd;
void (*onChanged)(uiEntry *, void *);
void *onChangedData;
};
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
{
struct entry *e = (struct entry *) c;
if (code != EN_CHANGE)
return FALSE;
(*(e->onChanged))(uiEntry(e), e->onChangedData);
// TODO EN_CHANGE return value
*lResult = 0;
return TRUE;
}
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
@ -33,6 +42,11 @@ static void entryPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intma
*height = uiDlgUnitsToY(entryHeight, d->sys->baseY);
}
static void defaultOnChanged(uiEntry *e, void *data)
{
// do nothing
}
static char *entryText(uiEntry *e)
{
return uiWindowsControlText(uiControl(e));
@ -43,6 +57,14 @@ 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;
}
uiEntry *uiNewEntry(void)
{
struct entry *e;
@ -64,10 +86,13 @@ uiEntry *uiNewEntry(void)
e->hwnd = (HWND) uiControlHandle(uiControl(e));
e->onChanged = defaultOnChanged;
uiControl(e)->PreferredSize = entryPreferredSize;
uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText;
uiEntry(e)->OnChanged = entryOnChanged;
return uiEntry(e);
}