diff --git a/windows/area.c b/windows/area.cpp similarity index 91% rename from windows/area.c rename to windows/area.cpp index b33d574d..061335fa 100644 --- a/windows/area.c +++ b/windows/area.cpp @@ -1,6 +1,6 @@ // 8 september 2015 -#include "uipriv_windows.h" -#include "area.h" +#include "uipriv_windows.hpp" +#include "area.hpp" uiWindowsDefineControl( uiArea, // type name @@ -38,7 +38,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM if ((wp->flags & SWP_NOSIZE) != 0) return DefWindowProcW(hwnd, uMsg, wParam, lParam); if (GetClientRect(a->hwnd, &client) == 0) - logLastError("error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling in areaWndProc()"); + logLastError(L"error getting client rect of uiArea for WM_WINDOWPOSCHANGED handling"); areaDrawOnResize(a, &client); areaScrollOnResize(a, &client); return 0; @@ -81,7 +81,7 @@ void unregisterArea(void) { unregisterAreaFilter(); if (UnregisterClassW(areaClass, hInstance) == 0) - logLastError("error unregistering uiArea window class in unregisterArea()"); + logLastError(L"error unregistering uiArea window class"); } void uiAreaSetSize(uiArea *a, intmax_t width, intmax_t height) @@ -95,7 +95,7 @@ void uiAreaQueueRedrawAll(uiArea *a) { // don't erase the background; we do that ourselves in doPaint() if (InvalidateRect(a->hwnd, NULL, FALSE) == 0) - logLastError("error queueing uiArea redraw in uiAreaQueueRedrawAll()"); + logLastError(L"error queueing uiArea redraw"); } void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height) diff --git a/windows/area.h b/windows/area.h index 35966989..52261c5b 100644 --- a/windows/area.h +++ b/windows/area.h @@ -27,21 +27,20 @@ struct uiArea { ID2D1HwndRenderTarget *rt; }; -// areadraw.h +// areadraw.cpp extern BOOL areaDoDraw(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); extern void areaDrawOnResize(uiArea *, RECT *); -// areascroll.c +// areascroll.cpp extern BOOL areaDoScroll(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); extern void areaScrollOnResize(uiArea *, RECT *); extern void areaUpdateScroll(uiArea *a); -// areaevents.c +// areaevents.cpp extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); extern void unregisterAreaFilter(void); -// areautil.c -extern void renderTargetGetSize(ID2D1RenderTarget *rt, D2D1_SIZE_F *size); +// areautil.cpp extern void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height); extern void pixelsToDIP(uiArea *a, double *x, double *y); extern void dipToPixels(uiArea *a, double *x, double *y); diff --git a/windows/areadraw.c b/windows/areadraw.cpp similarity index 88% rename from windows/areadraw.c rename to windows/areadraw.cpp index 4b05caa1..0bedf67f 100644 --- a/windows/areadraw.c +++ b/windows/areadraw.cpp @@ -1,6 +1,6 @@ // 8 september 2015 -#include "uipriv_windows.h" -#include "area.h" +#include "uipriv_windows.hpp" +#include "area.hpp" static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) { @@ -24,7 +24,7 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) dp.ClipY += a->vscrollpos; } - ID2D1RenderTarget_BeginDraw(rt); + rt->BeginDraw(); if (a->scrolling) { ZeroMemory(&scrollTransform, sizeof (D2D1_MATRIX_3X2_F)); @@ -33,7 +33,7 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) // negative because we want nonzero scroll positions to move the drawing area up/left scrollTransform._31 = -a->hscrollpos; scrollTransform._32 = -a->vscrollpos; - ID2D1RenderTarget_SetTransform(rt, &scrollTransform); + rt->SetTransform(&scrollTransform); } // TODO push axis aligned clip @@ -47,7 +47,7 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) bgcolor.g = ((float) ((BYTE) ((bgcolorref & 0xFF00) >> 8))) / 255.0; bgcolor.b = ((float) GetBValue(bgcolorref)) / 255.0; bgcolor.a = 1.0; - ID2D1RenderTarget_Clear(rt, &bgcolor); + rt->Clear(&bgcolor); (*(ah->Draw))(ah, a, &dp); @@ -55,7 +55,7 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) // TODO pop axis aligned clip - return ID2D1RenderTarget_EndDraw(rt, NULL, NULL); + return rt->EndDraw(NULL, NULL); } static void onWM_PAINT(uiArea *a) @@ -75,7 +75,7 @@ static void onWM_PAINT(uiArea *a) switch (hr) { case S_OK: if (ValidateRect(a->hwnd, NULL) == 0) - logLastError("error validating rect in onWM_PAINT()"); + logLastError(L"error validating rect"); break; case D2DERR_RECREATE_TARGET: // DON'T validate the rect @@ -86,7 +86,7 @@ static void onWM_PAINT(uiArea *a) a->rt = NULL; break; default: - logHRESULT("error painting in onWM_PAINT()", hr); + logHRESULT(L"error painting", hr); } } @@ -95,7 +95,7 @@ static void onWM_PRINTCLIENT(uiArea *a) RECT client; if (GetClientRect(a->hwnd, &client) == 0) - logLastError("error getting client rect in onWM_PRINTCLIENT()"); + logLastError(L"error getting client rect"); //TODO doPaint(a, (HDC) wParam, &client); } @@ -128,5 +128,5 @@ void areaDrawOnResize(uiArea *a, RECT *newClient) // according to Rick Brewster, we must always redraw the entire client area after calling ID2D1RenderTarget::Resize() (see http://stackoverflow.com/a/33222983/3408572) // we used to have a uiAreaHandler.RedrawOnResize() method to decide this; now you know why we don't anymore if (InvalidateRect(a->hwnd, NULL, TRUE) == 0) - logLastError("error redrawing area on resize in areaDrawOnResize()"); + logLastError(L"error redrawing area on resize"); } diff --git a/windows/areaevents.c b/windows/areaevents.cpp similarity index 98% rename from windows/areaevents.c rename to windows/areaevents.cpp index 8913d223..516690d7 100644 --- a/windows/areaevents.c +++ b/windows/areaevents.cpp @@ -1,6 +1,6 @@ // 8 september 2015 -#include "uipriv_windows.h" -#include "area.h" +#include "uipriv_windows.hpp" +#include "area.hpp" static uiModifiers getModifiers(void) { @@ -52,7 +52,7 @@ static void track(uiArea *a, BOOL tracking) tm.dwFlags |= TME_CANCEL; tm.hwndTrack = a->hwnd; if (_TrackMouseEvent(&tm) == 0) - logLastError("error setting up mouse tracking in track()"); + logLastError(L"error setting up mouse tracking"); } static void capture(uiArea *a, BOOL capturing) @@ -70,7 +70,7 @@ static void capture(uiArea *a, BOOL capturing) SetCapture(a->hwnd); } else if (ReleaseCapture() == 0) - logLastError("error releasing capture on drag in capture()"); + logLastError(L"error releasing capture on drag"); } static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wParam, LPARAM lParam) @@ -86,7 +86,7 @@ static void areaMouseEvent(uiArea *a, uintmax_t down, uintmax_t up, WPARAM wPar clientpt.x = GET_X_LPARAM(lParam); clientpt.y = GET_Y_LPARAM(lParam); if (GetClientRect(a->hwnd, &client) == 0) - logLastError("TODO"); + logLastError(L"error getting uiAreaclient rect for mouse crossing on capture on drag"); inClient = PtInRect(&client, clientpt); if (inClient && !a->inside) { a->inside = TRUE; diff --git a/windows/areascroll.c b/windows/areascroll.cpp similarity index 92% rename from windows/areascroll.c rename to windows/areascroll.cpp index 799b2707..7f4cec9e 100644 --- a/windows/areascroll.c +++ b/windows/areascroll.cpp @@ -1,6 +1,6 @@ // 8 september 2015 -#include "uipriv_windows.h" -#include "area.h" +#include "uipriv_windows.hpp" +#include "area.hpp" // TODO // - move from pixels to points somehow @@ -34,7 +34,7 @@ static void scrollto(uiArea *a, int which, struct scrollParams *p, intmax_t pos) // Direct2D doesn't have a method for scrolling the existing contents of a render target. // We'll have to just invalidate everything and hope for the best. if (InvalidateRect(a->hwnd, NULL, FALSE) == 0) - logLastError("error invalidating uiArea after scrolling in scrollto()"); + logLastError(L"error invalidating uiArea after scrolling"); *(p->pos) = pos; @@ -84,7 +84,7 @@ static void scroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, si.cbSize = sizeof (SCROLLINFO); si.fMask = SIF_POS; if (GetScrollInfo(a->hwnd, which, &si) == 0) - logLastError("error getting thumb position for area in scroll()"); + logLastError(L"error getting thumb position for area"); pos = si.nPos; break; case SB_THUMBTRACK: @@ -92,7 +92,7 @@ static void scroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, si.cbSize = sizeof (SCROLLINFO); si.fMask = SIF_TRACKPOS; if (GetScrollInfo(a->hwnd, which, &si) == 0) - logLastError("error getting thumb track position for area in scroll()"); + logLastError(L"error getting thumb track position for area"); pos = si.nTrackPos; break; } @@ -108,7 +108,7 @@ static void wheelscroll(uiArea *a, int which, struct scrollParams *p, WPARAM wPa delta = GET_WHEEL_DELTA_WPARAM(wParam); if (SystemParametersInfoW(p->wheelSPIAction, 0, &scrollAmount, 0) == 0) // TODO use scrollAmount == 3 (for both v and h) instead? - logLastError("error getting area wheel scroll amount in wheelscroll()"); + logLastError(L"error getting area wheel scroll amount"); if (scrollAmount == WHEEL_PAGESCROLL) scrollAmount = p->pagesize; if (scrollAmount == 0) // no mouse wheel scrolling (or t->pagesize == 0) @@ -129,7 +129,7 @@ static void hscrollParams(uiArea *a, struct scrollParams *p) p->pos = &(a->hscrollpos); // TODO get rid of these and replace with points if (GetClientRect(a->hwnd, &r) == 0) - logLastError("error getting area client rect in hscrollParams()"); + logLastError(L"error getting area client rect"); p->pagesize = r.right - r.left; p->length = a->scrollWidth; p->wheelCarry = &(a->hwheelCarry); @@ -175,7 +175,7 @@ static void vscrollParams(uiArea *a, struct scrollParams *p) ZeroMemory(p, sizeof (struct scrollParams)); p->pos = &(a->vscrollpos); if (GetClientRect(a->hwnd, &r) == 0) - logLastError("error getting area client rect in vscrollParams()"); + logLastError(L"error getting area client rect"); p->pagesize = r.bottom - r.top; p->length = a->scrollHeight; p->wheelCarry = &(a->vwheelCarry); diff --git a/windows/areautil.c b/windows/areautil.c deleted file mode 100644 index 3373fc0c..00000000 --- a/windows/areautil.c +++ /dev/null @@ -1,53 +0,0 @@ -// 18 december 2015 -#include "uipriv_windows.h" -#include "area.h" - -// I love COM interfaces that actually only work on C++ -// ID2D1RenderTarget::GetSize is defined as returninig a structure -// with stdcall, this means it's an extra last argument -// the compiler tries to return it directly, and crashes -// I originally thought this was a bug in MinGW-w64, but it turns out it also affects MSVC! https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64384 -// So we have to work around it. -// TODO is the return type correct? or should we just use C++? -void renderTargetGetSize(ID2D1RenderTarget *rt, D2D1_SIZE_F *size) -{ - typedef void (STDMETHODCALLTYPE *fptr)(ID2D1RenderTarget *, D2D1_SIZE_F *); - fptr f; - - f = (fptr) (rt->lpVtbl->GetSize); - (*f)(rt, size); -} - -void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height) -{ - D2D1_SIZE_F size; - - *width = 0; - *height = 0; - if (!a->scrolling) { - if (rt == NULL) - rt = (ID2D1RenderTarget *) (a->rt); - renderTargetGetSize(rt, &size); - *width = size.width; - *height = size.height; - } -} - -void pixelsToDIP(uiArea *a, double *x, double *y) -{ - FLOAT dpix, dpiy; - - ID2D1HwndRenderTarget_GetDpi(a->rt, &dpix, &dpiy); - // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd756649%28v=vs.85%29.aspx (and others; search "direct2d mouse") - *x = (*x * 96) / dpix; - *y = (*y * 96) / dpiy; -} - -void dipToPixels(uiArea *a, double *x, double *y) -{ - FLOAT dpix, dpiy; - - ID2D1HwndRenderTarget_GetDpi(a->rt, &dpix, &dpiy); - *x = (*x * dpix) / 96; - *y = (*y * dpiy) / 96; -} diff --git a/windows/areautil.cpp b/windows/areautil.cpp new file mode 100644 index 00000000..8d2d7fc8 --- /dev/null +++ b/windows/areautil.cpp @@ -0,0 +1,37 @@ +// 18 december 2015 +#include "uipriv_windows.hpp" +#include "area.hpp" + +void loadAreaSize(uiArea *a, ID2D1RenderTarget *rt, double *width, double *height) +{ + D2D1_SIZE_F size; + + *width = 0; + *height = 0; + if (!a->scrolling) { + if (rt == NULL) + rt = a->rt; + size = rt->GetSize(); + *width = size.width; + *height = size.height; + } +} + +void pixelsToDIP(uiArea *a, double *x, double *y) +{ + FLOAT dpix, dpiy; + + a->rt->GetDpi(&dpix, &dpiy); + // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd756649%28v=vs.85%29.aspx (and others; search "direct2d mouse") + *x = (*x * 96) / dpix; + *y = (*y * 96) / dpiy; +} + +void dipToPixels(uiArea *a, double *x, double *y) +{ + FLOAT dpix, dpiy; + + a->rt->GetDpi(&dpix, &dpiy); + *x = (*x * dpix) / 96; + *y = (*y * dpiy) / 96; +}