Implemented read-only uiEntries on Windows.

This commit is contained in:
Pietro Gagliardi 2015-05-06 22:21:11 -04:00
parent 372cbf044d
commit 6a1661fd91
3 changed files with 27 additions and 5 deletions

View File

@ -156,7 +156,7 @@ uiBox *makePage2(void)
readonly = uiNewEntry(); readonly = uiNewEntry();
uiEntryOnChanged(entry, echoReadOnlyText, readonly); uiEntryOnChanged(entry, echoReadOnlyText, readonly);
uiEntrySetText(readonly, "If you can see this, uiEntryReadOnly() isn't working properly."); uiEntrySetText(readonly, "If you can see this, uiEntryReadOnly() isn't working properly.");
uiEntrySetReadOnly(readonly), 1); uiEntrySetReadOnly(readonly, 1);
if (uiEntryReadOnly(readonly)) if (uiEntryReadOnly(readonly))
uiEntrySetText(readonly, ""); uiEntrySetText(readonly, "");
uiBoxAppend(page2, uiControl(entry), 0); uiBoxAppend(page2, uiControl(entry), 0);

View File

@ -200,12 +200,13 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
if (c->brush != NULL) if (c->brush != NULL)
if (DeleteObject(c->brush) == 0) if (DeleteObject(c->brush) == 0)
logLastError("error deleting old background brush in containerWndProc()"); logLastError("error deleting old background brush in containerWndProc()");
/*TODO // read-only TextFields and Textboxes are exempt // read-only TextFields and Textboxes are exempt
// this is because read-only edit controls count under WM_CTLCOLORSTATIC // this is because read-only edit controls count under WM_CTLCOLORSTATIC
// TODO really?
if (windowClassOf((HWND) lParam, L"edit", NULL) == 0) if (windowClassOf((HWND) lParam, L"edit", NULL) == 0)
if (textfieldReadOnly((HWND) lParam)) if ((getStyle((HWND) lParam) & ES_READONLY) != 0)
return DefWindowProcW(hwnd, uMsg, wParam, lParam); break;
*/ if (SetBkMode((HDC) wParam, TRANSPARENT) == 0) if (SetBkMode((HDC) wParam, TRANSPARENT) == 0)
logLastError("error setting transparent background mode to controls in containerWndProc()"); logLastError("error setting transparent background mode to controls in containerWndProc()");
c->brush = getControlBackgroundBrush((HWND) lParam, (HDC) wParam); c->brush = getControlBackgroundBrush((HWND) lParam, (HDC) wParam);
return (LRESULT) (c->brush); return (LRESULT) (c->brush);

View File

@ -65,6 +65,25 @@ static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data
e->onChangedData = data; 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()");
}
uiEntry *uiNewEntry(void) uiEntry *uiNewEntry(void)
{ {
struct entry *e; struct entry *e;
@ -93,6 +112,8 @@ uiEntry *uiNewEntry(void)
uiEntry(e)->Text = entryText; uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText; uiEntry(e)->SetText = entrySetText;
uiEntry(e)->OnChanged = entryOnChanged; uiEntry(e)->OnChanged = entryOnChanged;
uiEntry(e)->ReadOnly = entryReadOnly;
uiEntry(e)->SetReadOnly = entrySetReadOnly;
return uiEntry(e); return uiEntry(e);
} }