Implemented TextField.Invalid() on Windows.

This commit is contained in:
Pietro Gagliardi 2014-08-20 14:17:00 -04:00
parent e06e327155
commit ac6d0429f1
4 changed files with 28 additions and 1 deletions

View File

@ -104,3 +104,23 @@ void setTextFieldSubclass(HWND hwnd, void *data)
if ((*fv_SetWindowSubclass)(hwnd, textfieldSubProc, 0, (DWORD_PTR) data) == FALSE)
xpanic("error subclassing TextField to give it its own event handler", GetLastError());
}
void textfieldSetAndShowInvalidBalloonTip(HWND hwnd, WCHAR *text)
{
EDITBALLOONTIP ti;
ZeroMemory(&ti, sizeof (EDITBALLOONTIP));
ti.cbStruct = sizeof (EDITBALLOONTIP);
ti.pszTitle = L"Invalid Input"; // TODO verify
ti.pszText = text;
ti.ttiIcon = TTI_ERROR;
if (SendMessageW(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM) (&ti)) == FALSE)
xpanic("error showing TextField.Invalid() balloon tip", GetLastError());
MessageBeep(0xFFFFFFFF); // TODO can this return an error?
}
void textfieldHideInvalidBalloonTip(HWND hwnd)
{
if (SendMessageW(hwnd, EM_HIDEBALLOONTIP, 0, 0) == FALSE)
xpanic("error hiding TextField.Invalid() balloon tip", GetLastError());
}

View File

@ -71,6 +71,7 @@ func (t *textfield) Invalid(reason string) {
creason := togstr(reason)
defer freegstr(creason)
C.gtk_entry_set_icon_tooltip_text(t.entry, C.GTK_ENTRY_ICON_SECONDARY, creason)
// TODO beep
}
//export textfieldChanged

View File

@ -51,7 +51,11 @@ func (t *textfield) OnChanged(f func()) {
}
func (t *textfield) Invalid(reason string) {
// TODO
if reason == "" {
C.textfieldHideInvalidBalloonTip(t._hwnd)
return
}
C.textfieldSetAndShowInvalidBalloonTip(t._hwnd, toUTF16(reason))
}
//export textfieldChanged

View File

@ -64,6 +64,8 @@ extern void setCheckboxSubclass(HWND, void *);
extern BOOL checkboxChecked(HWND);
extern void checkboxSetChecked(HWND, BOOL);
extern void setTextFieldSubclass(HWND, void *);
extern void textfieldSetAndShowInvalidBalloonTip(HWND, WCHAR *);
extern void textfieldHideInvalidBalloonTip(HWND);
// init_windows.c
extern HINSTANCE hInstance;