From 5128fed0afb9e5086c979f45515afcfe8efe491d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 6 May 2015 20:06:16 -0400 Subject: [PATCH] Implemented uiEntryOnChanged() on Windows. --- TODO.md | 1 + windows/entry.c | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 7a32ed82..4c90dc81 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/windows/entry.c b/windows/entry.c index 5bf90e32..8817f5ac 100644 --- a/windows/entry.c +++ b/windows/entry.c @@ -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) { - return FALSE; + 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); }