diff options
Diffstat (limited to 'new/newcontrol_windows.c')
| -rw-r--r-- | new/newcontrol_windows.c | 100 |
1 files changed, 43 insertions, 57 deletions
diff --git a/new/newcontrol_windows.c b/new/newcontrol_windows.c index 1ff404b..3a561c6 100644 --- a/new/newcontrol_windows.c +++ b/new/newcontrol_windows.c @@ -1,37 +1,35 @@ // 6 april 2015 #include "uipriv_windows.h" -typedef struct uiSingleHWNDControl uiSingleHWNDControl; +typedef struct singleHWND singleHWND; struct uiSingleHWNDControl { - uiControl control; HWND hwnd; - BOOL (*onWM_COMMAND)(uiControl *, WPARAM, LPARAM, void *, LRESULT *); - BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *); - void (*onWM_DESTROY)(uiControl *, void *); - void *onCommandNotifyDestroyData; - void (*preferredSize)(uiControl *, int, int, LONG, intmax_t *, intmax_t *); - void *data; + BOOL (*onWM_COMMAND)(uiControl *, WPARAM, LPARAM, LRESULT *); + BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, LRESULT *); + void (*onWM_DESTROY)(uiControl *); uintptr_t parent; }; -#define S(c) ((uiSingleHWNDControl *) (c)) - static void singleDestroy(uiControl *c) { - if (DestroyWindow(S(c)->hwnd) == 0) + singleHWND *s = (singleHWND *) (c->internal); + + if (DestroyWindow(s->hwnd) == 0) logLastError("error destroying control in singleDestroy()"); - // the uiSingleHWNDControl is destroyed in the subclass procedure + // the data structures are destroyed in the subclass procedure } static uintptr_t singleHandle(uiControl *c) { - return (uintptr_t) (S(c)->hwnd); + singleHWND *s = (singleHWND *) (c->internal); + + return (uintptr_t) (s->hwnd); } static void singleSetParent(uiControl *c, uintptr_t parent) { - uiSingleHWNDControl *s = S(c); + singleHWND *s = (singleHWND *) (c->internal); s->parent = parent; if (SetParent(s->hwnd, (HWND) (s->parent)) == NULL) @@ -41,7 +39,7 @@ static void singleSetParent(uiControl *c, uintptr_t parent) static void singleRemoveParent(uiControl *c) { - uiSingleHWNDControl *s = S(c); + singleHWND *s = (singleHWND *) (c->internal); uintptr_t oldparent; oldparent = s->parent; @@ -51,38 +49,32 @@ static void singleRemoveParent(uiControl *c) updateParent(oldparent); } -static uiSize singlePreferredSize(uiControl *c, uiSizing *d) -{ - uiSize size; - - (*(S(c)->preferredSize))(c, - d->baseX, d->baseY, d->internalLeading, - &(size.width), &(size.height)); - return size; -} - static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) { - if (MoveWindow(S(c)->hwnd, x, y, width, height, TRUE) == 0) + singleHWND *s = (singleHWND *) (c->internal); + + if (MoveWindow(s->hwnd, x, y, width, height, TRUE) == 0) logLastError("error moving control in singleResize()"); } static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { - uiSingleHWNDControl *c = (uiSingleHWNDControl *) dwRefData; + uiControl *c = (uiControl *) dwRefData; + singleHWND *s = (singleHWND *) (c->internal); LRESULT lResult; switch (uMsg) { case msgCOMMAND: - if ((*(c->onWM_COMMAND))((uiControl *) c, wParam, lParam, c->onCommandNotifyDestroyData, &lResult) != FALSE) + if ((*(s->onWM_COMMAND))(c, wParam, lParam, &lResult) != FALSE) return lResult; break; case msgNOTIFY: - if ((*(c->onWM_NOTIFY))((uiControl *) c, wParam, lParam, c->onCommandNotifyDestroyData, &lResult) != FALSE) + if ((*(s->onWM_NOTIFY))(c, wParam, lParam, &lResult) != FALSE) return lResult; break; case WM_DESTROY: - (*(c->onWM_DESTROY))((uiControl *) c, c->onCommandNotifyDestroyData); + (*(s->onWM_DESTROY))(c); + uiFree(s); uiFree(c); break; case WM_NCDESTROY: @@ -95,51 +87,44 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p) { - uiSingleHWNDControl *c; + uiControl *c; + singleHWND *s; - c = uiNew(uiSingleHWNDControl); - c->hwnd = CreateWindowExW(p->dwExStyle, + s = uiNew(singleHWND); + s->hwnd = CreateWindowExW(p->dwExStyle, p->lpClassName, p->lpWindowName, p->dwStyle | WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, // TODO specify control IDs properly initialParent, NULL, p->hInstance, NULL); - if (c->hwnd == NULL) + if (s->hwnd == NULL) logLastError("error creating control in uiWindowsNewControl()"); + s->onWM_COMMAND = p->onWM_COMMAND; + s->onWM_NOTIFY = p->onWM_NOTIFY; + s->onWM_DESTROY = p->onWM_DESTROY; - c->control.destroy = singleDestroy; - c->control.handle = singleHandle; - c->control.setParent = singleSetParent; - c->control.removeParent = singleRemoveParent; - c->control.preferredSize = singlePreferredSize; - c->control.resize = singleResize; - - c->onWM_COMMAND = p->onWM_COMMAND; - c->onWM_NOTIFY = p->onWM_NOTIFY; - c->onWM_DESTROY = p->onWM_DESTROY; - c->onCommandNotifyDestroyData = p->onCommandNotifyDestroyData; - c->preferredSize = p->preferredSize; - - c->data = p->data; + c = uiNew(uiControl); + c->internal = s; + c->destroy = singleDestroy; + c->handle = singleHandle; + c->setParent = singleSetParent; + c->removeParent = singleRemoveParent; + c->resize = singleResize; - if ((*fv_SetWindowSubclass)(c->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE) + if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE) logLastError("error subclassing Windows control in uiWindowsNewControl()"); - return (uiControl *) c; -} - -void *uiWindowsControlData(uiControl *c) -{ - return S(c)->data; + return c; } char *uiWindowsControlText(uiControl *c) { + singleHWND *s = (singleHWND *) (c->internal); WCHAR *wtext; char *text; - wtext = windowText(S(c)->hwnd); + wtext = windowText(s->hwnd); text = toUTF8(wtext); uiFree(wtext); return text; @@ -147,10 +132,11 @@ char *uiWindowsControlText(uiControl *c) void uiWindowsControlSetText(uiControl *c, const char *text) { + singleHWND *s = (singleHWND *) (c->internal); WCHAR *wtext; wtext = toUTF16(text); - if (SetWindowTextW(S(c)->hwnd, wtext) == 0) + if (SetWindowTextW(s->hwnd, wtext) == 0) logLastError("error setting control text in uiWindowsControlSetText()"); uiFree(wtext); } |
