Started handling errors in the Windows Popover code. Also more TODOs.

This commit is contained in:
Pietro Gagliardi 2014-10-10 10:47:37 -04:00
parent a499a99d1a
commit 4777c0c309
1 changed files with 37 additions and 16 deletions

View File

@ -27,38 +27,57 @@
// - make sure redrawing is correct (especially for backgrounds) // - make sure redrawing is correct (especially for backgrounds)
// - wine: BLACK_PEN draws a white line? (might change later so eh) // - wine: BLACK_PEN draws a white line? (might change later so eh)
// - should the parent window appear deactivated? // - should the parent window appear deactivated?
// - switch to using Polyline()
HWND popover; HWND popover;
void xpanic(char *msg, DWORD err)
{
printf("%d | %s\n", err, msg);
abort();
}
#define ARROWHEIGHT 8 #define ARROWHEIGHT 8
#define ARROWWIDTH 8 /* should be the same for smooth lines */ #define ARROWWIDTH 8 /* should be the same for smooth lines */
HRGN makePopoverRegion(HDC dc, LONG width, LONG height) HRGN makePopoverRegion(HDC dc, LONG width, LONG height)
{ {
POINT pt; POINT pt;
HRGN region;
BeginPath(dc); if (BeginPath(dc) == 0)
xpanic("error beginning path for Popover shape", GetLastError());
pt.x = 0; pt.x = 0;
pt.y = ARROWHEIGHT; pt.y = ARROWHEIGHT;
MoveToEx(dc, pt.x, pt.y, NULL); if (MoveToEx(dc, pt.x, pt.y, NULL) == 0)
xpanic("error moving to initial point in Popover shape", GetLastError());
pt.y += height - ARROWHEIGHT; pt.y += height - ARROWHEIGHT;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
xpanic("error drawing line 1 in Popover shape", GetLastError());
pt.x += width; pt.x += width;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
xpanic("error drawing line 2 in Popover shape", GetLastError());
pt.y -= height - ARROWHEIGHT; pt.y -= height - ARROWHEIGHT;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
xpanic("error drawing line 3 in Popover shape", GetLastError());
pt.x -= (width / 2) - ARROWWIDTH; pt.x -= (width / 2) - ARROWWIDTH;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
xpanic("error drawing line 4 in Popover shape", GetLastError());
pt.x -= ARROWWIDTH; pt.x -= ARROWWIDTH;
pt.y -= ARROWHEIGHT; pt.y -= ARROWHEIGHT;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
xpanic("error drawing line 5 in Popover shape", GetLastError());
pt.x -= ARROWWIDTH; pt.x -= ARROWWIDTH;
pt.y += ARROWHEIGHT; pt.y += ARROWHEIGHT;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
xpanic("error drawing line 6 in Popover shape", GetLastError());
pt.x = 0; pt.x = 0;
LineTo(dc, pt.x, pt.y); if (LineTo(dc, pt.x, pt.y) == 0)
EndPath(dc); xpanic("error drawing line 7 in Popover shape", GetLastError());
return PathToRegion(dc); if (EndPath(dc) == 0)
xpanic("error ending path for Popover shape", GetLastError());
region = PathToRegion(dc);
return region;
} }
LRESULT CALLBACK popoverproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK popoverproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -73,13 +92,14 @@ LRESULT CALLBACK popoverproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch (uMsg) { switch (uMsg) {
case WM_NCPAINT: case WM_NCPAINT:
GetWindowRect(hwnd, &r); if (GetWindowRect(hwnd, &r) == 0)
xpanic("error getting Popover window rect for shape redraw", GetLastError());
width = r.right - r.left; width = r.right - r.left;
height = r.bottom - r.top; height = r.bottom - r.top;
dc = GetWindowDC(hwnd); dc = GetWindowDC(hwnd);
if (dc == NULL) abort(); // TODO error
region = makePopoverRegion(dc, width, height); region = makePopoverRegion(dc, width, height);
// TODO use the class brush here // TODO isolate the class brush to a constant
FillRgn(dc, region, GetSysColorBrush(COLOR_BTNFACE)); FillRgn(dc, region, GetSysColorBrush(COLOR_BTNFACE));
FrameRgn(dc, region, GetStockObject(BLACK_PEN), 1, 1); FrameRgn(dc, region, GetStockObject(BLACK_PEN), 1, 1);
DeleteObject(region); DeleteObject(region);
@ -90,9 +110,10 @@ LRESULT CALLBACK popoverproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
wp = (WINDOWPOS *) lParam; wp = (WINDOWPOS *) lParam;
if ((wp->flags & SWP_NOSIZE) == 0) { if ((wp->flags & SWP_NOSIZE) == 0) {
dc = GetWindowDC(hwnd); dc = GetWindowDC(hwnd);
if (dc == NULL) abort(); // TODO error
region = makePopoverRegion(dc, wp->cx, wp->cy); region = makePopoverRegion(dc, wp->cx, wp->cy);
SetWindowRgn(hwnd, region, TRUE); if (SetWindowRgn(hwnd, region, TRUE) == 0)
xpanic("error setting Popover shape", GetLastError());
// don't delete the region; the window manager owns it now // don't delete the region; the window manager owns it now
ReleaseDC(hwnd, dc); ReleaseDC(hwnd, dc);
} }