Made Areas on Windows tab stops and implemented AreaHandler.Defocuses() on Windows.

This commit is contained in:
Pietro Gagliardi 2014-08-13 10:41:27 -04:00
parent 59f2eeca22
commit b01c653942
5 changed files with 38 additions and 6 deletions

View File

@ -5,8 +5,6 @@
#include "winapi_windows.h"
#include "_cgo_export.h"
#define areaWindowClass L"gouiarea"
static void getScrollPos(HWND hwnd, int *xpos, int *ypos)
{
SCROLLINFO si;
@ -412,6 +410,8 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
case msgAreaRepaintAll:
repaintArea(hwnd);
return 0;
case msgAreaDefocuses:
return (LRESULT) areaDefocuses(data);
default:
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
@ -445,7 +445,7 @@ HWND newArea(void *data)
hwnd = CreateWindowExW(
0,
areaWindowClass, L"",
WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
CW_USEDEFAULT, CW_USEDEFAULT,
100, 100,
msgwin, NULL, hInstance, data);

View File

@ -280,6 +280,15 @@ func areaResetClickCounter(data unsafe.Pointer) {
a.clickCounter.reset()
}
//export areaDefocuses
func areaDefocuses(data unsafe.Pointer) C.BOOL {
a := (*area)(data)
if a.handler.Defocuses() {
return C.TRUE
}
return C.FALSE
}
func (a *area) hwnd() C.HWND {
return a._hwnd
}

View File

@ -3,11 +3,16 @@
#include "winapi_windows.h"
#include "_cgo_export.h"
/* note that this includes the terminating '\0' */
#define NAREACLASS (sizeof areaWindowClass / sizeof areaWindowClass[0])
void uimsgloop(void)
{
MSG msg;
int res;
HWND active;
WCHAR classchk[NAREACLASS];
BOOL dodlgmessage;
for (;;) {
SetLastError(0);
@ -17,9 +22,24 @@ void uimsgloop(void)
if (res == 0) /* WM_QUIT */
break;
active = GetActiveWindow();
// TODO this interferes with Area
if (active != NULL && IsDialogMessageW(active, &msg) != 0)
if (active != NULL) {
HWND focus;
dodlgmessage = TRUE;
focus = GetFocus();
if (focus != NULL) {
// theoretically we could use the class atom to avoid a wcscmp()
// however, raymond chen advises against this - TODO_get_URL
// while I have no idea what could deregister *my* window class from under *me*, better safe than sorry
// we could also theoretically just send msgAreaDefocuses directly, but what DefWindowProc() does to a WM_APP message is undocumented
if (GetClassNameW(focus, classchk, NAREACLASS) == 0)
xpanic("error getting name of focused window class for Area check", GetLastError());
if (wcscmp(classchk, areaWindowClass) == 0)
dodlgmessage = (BOOL) SendMessageW(focus, msgAreaDefocuses, 0, 0);
}
if (dodlgmessage && IsDialogMessageW(active, &msg) != 0)
continue;
}
TranslateMessage(&msg);
DispatchMessageW(&msg);
}

View File

@ -29,6 +29,7 @@ enum {
msgNOTIFY, /* WM_NOTIFY proxy */
msgAreaSizeChanged,
msgAreaRepaintAll,
msgAreaDefocuses,
};
/* uitask_windows.c */
@ -104,6 +105,7 @@ extern HWND newContainer(void *);
extern void calculateBaseUnits(HWND, int *, int *, LONG *);
/* area_window.c */
#define areaWindowClass L"gouiarea"
extern void repaintArea(HWND);
extern DWORD makeAreaWindowClass(char **);
extern HWND newArea(void *);

View File

@ -137,6 +137,7 @@ func (tw *testwin) make(done chan struct{}) {
tw.t.Append("Password Field", tw.e2)
tw.w.Show()
if *smallWindow {
// TODO windows - tab order wrong in wine?
tw.wsmall = NewWindow("Small", 80, 80,
NewVerticalStack(
NewButton("Small"),