From dd8de11cc2b4601c6b6252c859d52b840ea801c3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 01:33:26 -0400 Subject: More work on the Windows control hooking. --- new/newcontrol_windows.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ new/singlehandle_windows.c | 58 ------------------------------------- new/ui_windows.h | 6 ++-- new/uipriv_windows.h | 10 ------- 4 files changed, 75 insertions(+), 70 deletions(-) create mode 100644 new/newcontrol_windows.c delete mode 100644 new/singlehandle_windows.c diff --git a/new/newcontrol_windows.c b/new/newcontrol_windows.c new file mode 100644 index 0000000..0a46c0a --- /dev/null +++ b/new/newcontrol_windows.c @@ -0,0 +1,71 @@ +// 6 april 2015 +#include "uipriv_windows.h" + +typedef struct uiSingleHWNDControl uiSingleHWNDControl; + +struct uiSingleHWNDControl { + uiControl control; + HWND hwnd; + BOOL (*onWM_COMMAND)(uiControl *, WPARAM, LPARAM, void *, LRESULT *); + BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *); + void *onCommandNotifyData; +}; + +#define S(c) ((uiSingleHWNDControl *) (c)) + +static uintptr_t singleHandle(uiControl *c) +{ + return (uintptr_t) (S(c)->hwnd); +} + +void singleSetParent(uiControl *c, uintptr_t parentHWND) +{ + if (SetParent(S(c)->hwnd, (HWND) parentHWND) == NULL) + logLastError("error changing control parent in singleSetParent()"); +} + +// TODO preferred 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) + logLastError("error moving control in singleResize()"); +} + +static void singleContainerShow(uiControl *c) +{ + ShowWindow(S(c)->hwnd, SW_SHOW); +} + +static void singleContainerHide(uiControl *c) +{ + ShowWindow(S(c)->hwnd, SW_HIDE); +} + +uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p) +{ + uiSingleHWNDControl *c; + + c = uiNew(uiSingleHWNDControl); + c->hwnd = CreateWindowExW(p->dwExStyle, + p->lpClassName, L"", + p->dwStyle | WS_CHILD | WS_VISIBLE, + 0, 0, + 100, 100, + // TODO specify control IDs properly + initialParent, NULL, p->hInstance, NULL); + if (c->hwnd == NULL) + logLastError("error creating control in newSingleHWNDControl()"); + + c->control.handle = singleHandle; + c->control.setParent = singleSetParent; + c->control.resize = singleResize; + c->control.containerShow = singleContainerShow; + c->control.containerHide = singleContainerHide; + + c->onWM_COMMAND = p->onWM_COMMAND; + c->onWM_NOTIFY = p->onWM_NOTIFY; + c->onCommandNotifyData = p->onCommandNotifyData; + + return (uiControl *) c; +} diff --git a/new/singlehandle_windows.c b/new/singlehandle_windows.c deleted file mode 100644 index b55a8b9..0000000 --- a/new/singlehandle_windows.c +++ /dev/null @@ -1,58 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.h" - -// Common code for controls with a single window handle. -// The only method NOT defined is preferredSize(); this differs between controls. - -#define S(c) ((uiSingleHWNDControl *) (c)) - -static uintptr_t singleHandle(uiControl *c) -{ - return (uintptr_t) (S(c)->hwnd); -} - -void singleSetParent(uiControl *c, uintptr_t parentHWND) -{ - if (SetParent(S(c)->hwnd, (HWND) parentHWND) == NULL) - logLastError("error changing control parent in singleSetParent()"); -} - -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) - logLastError("error moving control in singleResize()"); -} - -static void singleContainerShow(uiControl *c) -{ - ShowWindow(S(c)->hwnd, SW_SHOW); -} - -static void singleContainerHide(uiControl *c) -{ - ShowWindow(S(c)->hwnd, SW_HIDE); -} - -uiSingleHWNDControl *newSingleHWNDControl(DWORD exstyle, const WCHAR *class, DWORD style, HINSTANCE hInstance) -{ - uiSingleHWNDControl *c; - - c = uiNew(uiSingleHWNDControl); - c->hwnd = CreateWindowExW(exstyle, - class, L"", - style | WS_CHILD | WS_VISIBLE, - 0, 0, - 100, 100, - // TODO specify control IDs properly - initialParent, NULL, hInstance, NULL); - if (c->hwnd == NULL) - logLastError("error creating control in newSingleHWNDControl()"); - - c->control.handle = singleHandle; - c->control.setParent = singleSetParent; - c->control.resize = singleResize; - c->control.containerShow = singleContainerShow; - c->control.containerHide = singleContainerHide; - - return c; -} diff --git a/new/ui_windows.h b/new/ui_windows.h index eb68475..675f45b 100644 --- a/new/ui_windows.h +++ b/new/ui_windows.h @@ -21,8 +21,10 @@ struct uiWindowsNewControlParams { // ui redirects the message back and calls these functions. // Store the result in the LRESULT pointer and return TRUE to return the given result; return FALSE to pass the notification up to your window procedure. // Note that these are only issued if they come from the uiControl itself; notifications from children of the uiControl (such as a header control) will be received normally. - BOOL (*onWM_COMMAND)(uiControl *, WPARAM, LPARAM, LRESULT *); - BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, LRESULT *); + BOOL (*onWM_COMMAND)(uiControl *, WPARAM, LPARAM, void *, LRESULT *); + BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *); + // This is the void * parameter to both of the above. + void *onCommandNotifyData; }; uiControl *uiWindowsNewControl(uiWindowsNewControlParams *); diff --git a/new/uipriv_windows.h b/new/uipriv_windows.h index 7f714ac..bdaf793 100644 --- a/new/uipriv_windows.h +++ b/new/uipriv_windows.h @@ -51,13 +51,3 @@ extern WCHAR *toUTF16(const char *); // window_windows.c extern ATOM registerWindowClass(HICON, HCURSOR); - -// singlehandle_windows.c -typedef struct uiSingleHWNDControl uiSingleHWNDControl; -struct uiSingleHWNDControl { - uiControl control; - HWND hwnd; - void (*voidEvent)(uiControl *, void *); - void *voidEventData; -}; -extern uiSingleHWNDControl *newSingleHWNDControl(DWORD, const WCHAR *, DWORD, HINSTANCE); -- cgit v1.2.3