More work on the Windows control hooking.

This commit is contained in:
Pietro Gagliardi 2015-04-07 01:33:26 -04:00
parent 9742cc02df
commit 249cc1f2f0
3 changed files with 25 additions and 20 deletions

View File

@ -1,8 +1,15 @@
// 6 april 2015 // 6 april 2015
#include "uipriv_windows.h" #include "uipriv_windows.h"
// Common code for controls with a single window handle. typedef struct uiSingleHWNDControl uiSingleHWNDControl;
// The only method NOT defined is preferredSize(); this differs between controls.
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)) #define S(c) ((uiSingleHWNDControl *) (c))
@ -17,6 +24,8 @@ void singleSetParent(uiControl *c, uintptr_t parentHWND)
logLastError("error changing control parent in singleSetParent()"); 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) 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) if (MoveWindow(S(c)->hwnd, x, y, width, height, TRUE) == 0)
@ -33,18 +42,18 @@ static void singleContainerHide(uiControl *c)
ShowWindow(S(c)->hwnd, SW_HIDE); ShowWindow(S(c)->hwnd, SW_HIDE);
} }
uiSingleHWNDControl *newSingleHWNDControl(DWORD exstyle, const WCHAR *class, DWORD style, HINSTANCE hInstance) uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p)
{ {
uiSingleHWNDControl *c; uiSingleHWNDControl *c;
c = uiNew(uiSingleHWNDControl); c = uiNew(uiSingleHWNDControl);
c->hwnd = CreateWindowExW(exstyle, c->hwnd = CreateWindowExW(p->dwExStyle,
class, L"", p->lpClassName, L"",
style | WS_CHILD | WS_VISIBLE, p->dwStyle | WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
100, 100, 100, 100,
// TODO specify control IDs properly // TODO specify control IDs properly
initialParent, NULL, hInstance, NULL); initialParent, NULL, p->hInstance, NULL);
if (c->hwnd == NULL) if (c->hwnd == NULL)
logLastError("error creating control in newSingleHWNDControl()"); logLastError("error creating control in newSingleHWNDControl()");
@ -54,5 +63,9 @@ uiSingleHWNDControl *newSingleHWNDControl(DWORD exstyle, const WCHAR *class, DWO
c->control.containerShow = singleContainerShow; c->control.containerShow = singleContainerShow;
c->control.containerHide = singleContainerHide; c->control.containerHide = singleContainerHide;
return c; c->onWM_COMMAND = p->onWM_COMMAND;
c->onWM_NOTIFY = p->onWM_NOTIFY;
c->onCommandNotifyData = p->onCommandNotifyData;
return (uiControl *) c;
} }

View File

@ -21,8 +21,10 @@ struct uiWindowsNewControlParams {
// ui redirects the message back and calls these functions. // 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. // 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. // 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_COMMAND)(uiControl *, WPARAM, LPARAM, void *, LRESULT *);
BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, LRESULT *); BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *);
// This is the void * parameter to both of the above.
void *onCommandNotifyData;
}; };
uiControl *uiWindowsNewControl(uiWindowsNewControlParams *); uiControl *uiWindowsNewControl(uiWindowsNewControlParams *);

View File

@ -51,13 +51,3 @@ extern WCHAR *toUTF16(const char *);
// window_windows.c // window_windows.c
extern ATOM registerWindowClass(HICON, HCURSOR); 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);