diff --git a/windows/debug.cpp b/windows/debug.cpp index 0091c1a5..2c1ad629 100644 --- a/windows/debug.cpp +++ b/windows/debug.cpp @@ -4,14 +4,14 @@ // TODO disable logging and stopping on no-debug builds // TODO are the newlines needed? -static void printDebug(WCHAR *msg) +static void printDebug(const WCHAR *msg) { OutputDebugStringW(msg); } -#define debugfmt L"%s:" L ## PRIiMAX L":%s()" +#define debugfmt L"%s:%s:%s()" -HRESULT _logLastError(debugargs, const WCHAR *func, const WCHAR *s) +HRESULT _logLastError(debugargs, const WCHAR *s) { DWORD le; WCHAR *msg; @@ -92,7 +92,7 @@ void _implbug(debugargs, const WCHAR *format, ...) formatted = debugvstrf(format, ap); va_end(ap); if (formatted == NULL) { - onerr = s; + onerr = format; goto bad; } diff --git a/windows/draw.cpp b/windows/draw.cpp index 1f88a08c..47ec6c09 100644 --- a/windows/draw.cpp +++ b/windows/draw.cpp @@ -14,7 +14,7 @@ HRESULT initDraw(void) // TODO make this an option opts.debugLevel = D2D1_DEBUG_LEVEL_NONE; return D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, - &IID_ID2D1Factory, + IID_ID2D1Factory, &opts, (void **) (&d2dfactory)); } @@ -115,7 +115,7 @@ void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) D2D1_POINT_2F pt; if (p->inFigure) - p-sink->EndFigure(D2D1_FIGURE_END_OPEN); + p->sink->EndFigure(D2D1_FIGURE_END_OPEN); pt.x = x; pt.y = y; p->sink->BeginFigure(pt, D2D1_FIGURE_BEGIN_FILLED); @@ -371,7 +371,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r size_t i; HRESULT hr; - stops = uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]"); + stops = (D2D1_GRADIENT_STOP *) uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]"); for (i = 0; i < b->NumStops; i++) { stops[i].position = b->Stops[i].Pos; stops[i].color.r = b->Stops[i].R; @@ -510,7 +510,7 @@ static ID2D1Layer *applyClip(uiDrawContext *c) params.contentBounds.bottom = FLT_MAX; params.geometricMask = (ID2D1Geometry *) (c->currentClip); // TODO is this correct? - params.maskAntialiasMode = ID2D1RenderTarget_GetAntialiasMode(c->rt); + params.maskAntialiasMode = c->rt->GetAntialiasMode(); // identity matrix params.maskTransform._11 = 1; params.maskTransform._22 = 1; @@ -766,7 +766,7 @@ void uiDrawClip(uiDrawContext *c, uiDrawPath *path) // otherwise we have to intersect the current path with the new one // we do that into a new path, and then replace c->currentClip with that new path - hr = d2dfactoryCreatePathGeometry(&newPath); + hr = d2dfactory->CreatePathGeometry(&newPath); if (hr != S_OK) logHRESULT(L"error creating new path", hr); hr = newPath->Open(&newSink); diff --git a/windows/drawtext.cpp b/windows/drawtext.cpp index ffd9c3ef..ad34b089 100644 --- a/windows/drawtext.cpp +++ b/windows/drawtext.cpp @@ -36,7 +36,7 @@ char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, uintmax_t n) hr = ff->fc->fonts->GetFontFamily(n, &family); if (hr != S_OK) - logHRESULT("error getting font out of collection in uiDrawFontFamiliesFamily()", hr); + logHRESULT(L"error getting font out of collection", hr); wname = fontCollectionFamilyName(ff->fc, family); name = toUTF8(wname); uiFree(wname); @@ -236,17 +236,17 @@ uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc) // always get the latest available font information hr = dwfactory->GetSystemFontCollection(&collection, TRUE); if (hr != S_OK) - logHRESULT("error getting system font collection in uiDrawLoadClosestFont()", hr); + logHRESULT(L"error getting system font collection", hr); wfamily = toUTF16(desc->Family); hr = collection->FindFamilyName(wfamily, &index, &exists); if (hr != S_OK) - logHRESULT("error finding font family in uiDrawLoadClosestFont()", hr); + logHRESULT(L"error finding font family", hr); if (!exists) complain("TODO family not found in uiDrawLoadClosestFont()", hr); hr = collection->GetFontFamily(index, &family); if (hr != S_OK) - logHRESULT("error loading font family in uiDrawLoadClosestFont()", hr); + logHRESULT(L"error loading font family", hr); attr.weight = desc->Weight; attr.italic = desc->Italic; @@ -258,7 +258,7 @@ uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc) attr.ditalic, &match); if (hr != S_OK) - logHRESULT("error loading font in uiDrawLoadClosestFont()", hr); + logHRESULT(L"error loading font", hr); font = mkTextFont(match, FALSE, // we own the initial reference; no need to add another one @@ -360,7 +360,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultF L"", &(layout->format)); if (hr != S_OK) - logHRESULT("error creating IDWriteTextFormat in uiDrawNewTextLayout()", hr); + logHRESULT(L"error creating IDWriteTextFormat", hr); layout->text = toUTF16(text); layout->textlen = wcslen(layout->text); @@ -395,7 +395,7 @@ IDWriteTextLayout *prepareLayout(uiDrawTextLayout *layout, ID2D1RenderTarget *rt FLT_MAX, FLT_MAX, &dl); if (hr != S_OK) - logHRESULT("error creating IDWriteTextLayout in prepareLayout()", hr); + logHRESULT(L"error creating IDWriteTextLayout", hr); for (const struct layoutAttr &attr : *(layout->attrs)) { range.startPosition = attr.start; @@ -410,10 +410,10 @@ IDWriteTextLayout *prepareLayout(uiDrawTextLayout *layout, ID2D1RenderTarget *rt break; default: hr = E_FAIL; - logHRESULT("invalid text attribute type in prepareLayout()", hr); + logHRESULT(L"invalid text attribute type", hr); } if (hr != S_OK) - logHRESULT("error adding attribute to text layout in prepareLayout()", hr); + logHRESULT(L"error adding attribute to text layout", hr); } // and set the width @@ -427,10 +427,10 @@ IDWriteTextLayout *prepareLayout(uiDrawTextLayout *layout, ID2D1RenderTarget *rt } hr = dl->SetWordWrapping(wrap); if (hr != S_OK) - logHRESULT("error setting word wrapping mode in prepareLayout()", hr); + logHRESULT(L"error setting word wrapping mode", hr); hr = dl->SetMaxWidth(maxWidth); if (hr != S_OK) - logHRESULT("error setting max layout width in prepareLayout()", hr); + logHRESULT(L"error setting max layout width", hr); return dl; } @@ -451,7 +451,7 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *he dl = prepareLayout(layout, NULL); hr = dl->GetMetrics(&metrics); if (hr != S_OK) - logHRESULT("error getting layout metrics in uiDrawTextLayoutExtents()", hr); + logHRESULT(L"error getting layout metrics", hr); *width = metrics.width; // TODO make sure the behavior of this on empty strings is the same on all platforms *height = metrics.height; diff --git a/windows/dwrite.cpp b/windows/dwrite.cpp index ecaae41d..9156f179 100644 --- a/windows/dwrite.cpp +++ b/windows/dwrite.cpp @@ -1,5 +1,6 @@ // 14 april 2016 #include "uipriv_windows.hpp" +// TODO really migrate? IDWriteFactory *dwfactory = NULL; @@ -25,7 +26,7 @@ fontCollection *loadFontCollection(void) // always get the latest available font information hr = dwfactory->GetSystemFontCollection(&(fc->fonts), TRUE); if (hr != S_OK) - logHRESULT("error getting system font collection in loadFontCollection()", hr); + logHRESULT(L"error getting system font collection", hr); fc->userLocaleSuccess = GetUserDefaultLocaleName(fc->userLocale, LOCALE_NAME_MAX_LENGTH); return fc; } @@ -38,7 +39,7 @@ WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family) hr = family->GetFamilyNames(&names); if (hr != S_OK) - logHRESULT("error getting names of font out in fontCollectionFamilyName()", hr); + logHRESULT(L"error getting names of font out", hr); str = fontCollectionCorrectString(fc, names); names->Release(); return str; @@ -70,12 +71,12 @@ WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings * hr = names->GetStringLength(index, &length); if (hr != S_OK) - logHRESULT("error getting length of font name in fontCollectionFamilyName()", hr); + logHRESULT(L"error getting length of font name", hr); // GetStringLength() does not include the null terminator, but GetString() does wname = (WCHAR *) uiAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]"); hr = names->GetString(index, wname, length + 1); if (hr != S_OK) - logHRESULT("error getting font name in fontCollectionFamilyName()", hr); + logHRESULT(L"error getting font name", hr); return wname; } diff --git a/windows/fontdialog.cpp b/windows/fontdialog.cpp index 06841436..75aa8974 100644 --- a/windows/fontdialog.cpp +++ b/windows/fontdialog.cpp @@ -38,7 +38,7 @@ static LRESULT cbAddString(HWND cb, const WCHAR *str) lr = SendMessageW(cb, CB_ADDSTRING, 0, (LPARAM) str); if (lr == (LRESULT) CB_ERR || lr == (LRESULT) CB_ERRSPACE) - logLastError("error adding item to combobox in cbAddString()"); + logLastError(L"error adding item to combobox"); return lr; } @@ -48,7 +48,7 @@ static LRESULT cbInsertString(HWND cb, const WCHAR *str, WPARAM pos) lr = SendMessageW(cb, CB_INSERTSTRING, pos, (LPARAM) str); if (lr != (LRESULT) pos) - logLastError("error inserting item to combobox in cbInsertString()"); + logLastError(L"error inserting item to combobox"); return lr; } @@ -58,14 +58,14 @@ static LRESULT cbGetItemData(HWND cb, WPARAM item) data = SendMessageW(cb, CB_GETITEMDATA, item, 0); if (data == (LRESULT) CB_ERR) - logLastError("error getting combobox item data for font dialog in cbGetItemData()"); + logLastError(L"error getting combobox item data for font dialog"); return data; } static void cbSetItemData(HWND cb, WPARAM item, LPARAM data) { if (SendMessageW(cb, CB_SETITEMDATA, item, data) == (LRESULT) CB_ERR) - logLastError("error setting combobox item data in cbSetItemData()"); + logLastError(L"error setting combobox item data"); } static BOOL cbGetCurSel(HWND cb, LRESULT *sel) @@ -83,7 +83,7 @@ static BOOL cbGetCurSel(HWND cb, LRESULT *sel) static void cbSetCurSel(HWND cb, WPARAM item) { if (SendMessageW(cb, CB_SETCURSEL, item, 0) != (LRESULT) item) - logLastError("error selecting combobox item in cbSetCurSel()"); + logLastError(L"error selecting combobox item"); } static LRESULT cbGetCount(HWND cb) @@ -92,7 +92,7 @@ static LRESULT cbGetCount(HWND cb) n = SendMessageW(cb, CB_GETCOUNT, 0, 0); if (n == (LRESULT) CB_ERR) - logLastError("error getting combobox item count in cbGetCount()"); + logLastError(L"error getting combobox item count"); return n; } @@ -117,10 +117,10 @@ static WCHAR *cbGetItemText(HWND cb, WPARAM item) // note: neither message includes the terminating L'\0' len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0); if (len == (LRESULT) CB_ERR) - logLastError("error getting item text length from combobox in cbGetItemText()"); + logLastError(L"error getting item text length from combobox"); text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len) - logLastError("error getting item text from combobox in cbGetItemText()"); + logLastError(L"error getting item text from combobox"); return text; } @@ -143,12 +143,12 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter) *posOut = pos; if (restoreAfter) if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE) - logLastError("error restoring old combobox text in cbTypeToSelect()"); + logLastError(L"error restoring old combobox text"); uiFree(text); // and restore the selection like above // TODO isn't there a 32-bit version of this if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE) - logLastError("error restoring combobox edit selection in cbTypeToSelect()"); + logLastError(L"error restoring combobox edit selection"); return TRUE; } @@ -165,7 +165,7 @@ static WCHAR *fontStyleName(struct fontCollection *fc, IDWriteFont *font) hr = font->GetFaceNames(&str); if (hr != S_OK) - logHRESULT("error getting font style name for font dialog in fontStyleName()", hr); + logHRESULT(L"error getting font style name for font dialog", hr); wstr = fontCollectionCorrectString(fc, str); str->Release(); return wstr; @@ -175,7 +175,7 @@ static void queueRedrawSampleText(struct fontDialog *f) { // TODO TRUE? if (InvalidateRect(f->sampleBox, NULL, TRUE) == 0) - logLastError("error queueing a redraw of the font dialog's sample text in queueRedrawSampleText()"); + logLastError(L"error queueing a redraw of the font dialog's sample text"); } static void styleChanged(struct fontDialog *f) @@ -234,7 +234,7 @@ static void familyChanged(struct fontDialog *f) f->style, &matchFont); if (hr != S_OK) - logHRESULT("error finding first matching font to previous style in font dialog in familyChanged()", hr); + logHRESULT(L"error finding first matching font to previous style in font dialog", hr); // we can't just compare pointers; a "newly created" object comes out // the Choose Font sample appears to do this instead weight = matchFont->GetWeight(); @@ -249,7 +249,7 @@ static void familyChanged(struct fontDialog *f) for (i = 0; i < n; i++) { hr = family->GetFont(i, &font); if (hr != S_OK) - logHRESULT("error getting font for filling styles box in familyChanged()", hr); + logHRESULT(L"error getting font for filling styles box", hr); label = fontStyleName(f->fc, font); pos = cbAddString(f->styleCombobox, label); uiFree(label); @@ -355,7 +355,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt &props, &black); if (hr != S_OK) - logHRESULT("error creating solid brush in fontDialogDrawSampleText()", hr); + logHRESULT(L"error creating solid brush", hr); font = (IDWriteFont *) cbGetItemData(f->styleCombobox, (WPARAM) f->curStyle); hr = font->GetInformationalStrings(DWRITE_INFORMATIONAL_STRING_SAMPLE_TEXT, &sampleStrings, &exists); @@ -382,7 +382,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt L"", &format); if (hr != S_OK) - logHRESULT("error creating IDWriteTextFormat in fontDialogDrawSampleText()", hr); + logHRESULT(L"error creating IDWriteTextFormat", hr); uiFree(family); rect.left = 0; @@ -416,7 +416,7 @@ static LRESULT CALLBACK fontDialogSampleSubProc(HWND hwnd, UINT uMsg, WPARAM wPa return 0; case WM_NCDESTROY: if (RemoveWindowSubclass(hwnd, fontDialogSampleSubProc, uIdSubclass) == FALSE) - logLastError("error removing font dialog sample text subclass in fontDialogSampleSubProc()"); + logLastError(L"error removing font dialog sample text subclass"); break; } return DefSubclassProc(hwnd, uMsg, wParam, lParam); @@ -437,11 +437,11 @@ static void setupInitialFontDialogState(struct fontDialog *f) _snwprintf(wsize, 512, L"%g", f->params->size); // TODO make this a setWindowText() if (SendMessageW(f->sizeCombobox, WM_SETTEXT, 0, (LPARAM) wsize) != (LRESULT) TRUE) - logLastError("error setting size combobox to initial font size in setupInitialFontDialogState()"); + logLastError(L"error setting size combobox to initial font size"); sizeEdited(f); if (cbGetCurSel(f->sizeCombobox, &pos)) if (SendMessageW(f->sizeCombobox, CB_SETTOPINDEX, (WPARAM) pos, 0) != 0) - logLastError("error making chosen size topmost in the size combobox in setupInitialFontDialogState()"); + logLastError(L"error making chosen size topmost in the size combobox"); // now we set the family and style // we do this by first setting the previous style attributes, then simulating a font entered @@ -449,7 +449,7 @@ static void setupInitialFontDialogState(struct fontDialog *f) f->style = f->params->font->GetStyle(); f->stretch = f->params->font->GetStretch(); if (SendMessageW(f->familyCombobox, WM_SETTEXT, 0, (LPARAM) (f->params->familyName)) != (LRESULT) TRUE) - logLastError("error setting family combobox to initial font family in setupInitialFontDialogState()"); + logLastError(L"error setting family combobox to initial font family"); familyEdited(f); } @@ -469,20 +469,20 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) f->familyCombobox = GetDlgItem(f->hwnd, rcFontFamilyCombobox); if (f->familyCombobox == NULL) - logLastError("error getting font family combobox handle in beginFontDialog()"); + logLastError(L"error getting font family combobox handle"); f->styleCombobox = GetDlgItem(f->hwnd, rcFontStyleCombobox); if (f->styleCombobox == NULL) - logLastError("error getting font style combobox handle in beginFontDialog()"); + logLastError(L"error getting font style combobox handle"); f->sizeCombobox = GetDlgItem(f->hwnd, rcFontSizeCombobox); if (f->sizeCombobox == NULL) - logLastError("error getting font size combobox handle in beginFontDialog()"); + logLastError(L"error getting font size combobox handle"); f->fc = loadFontCollection(); nFamilies = f->fc->fonts->GetFontFamilyCount(); for (i = 0; i < nFamilies; i++) { hr = f->fc->fonts->GetFontFamily(i, &family); if (hr != S_OK) - logHRESULT("error getting font family in beginFontDialog()", hr); + logHRESULT(L"error getting font family", hr); wname = fontCollectionFamilyName(f->fc, family); pos = cbAddString(f->familyCombobox, wname); uiFree(wname); @@ -494,12 +494,11 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) samplePlacement = GetDlgItem(f->hwnd, rcFontSamplePlacement); if (samplePlacement == NULL) - logLastError("error getting sample placement static control handle in beginFontDialog()"); + logLastError(L"error getting sample placement static control handle"); if (GetWindowRect(samplePlacement, &(f->sampleRect)) == 0) - logLastError("error getting sample placement in beginFontDialog()"); + logLastError(L"error getting sample placement"); mapWindowRect(NULL, f->hwnd, &(f->sampleRect)); - if (DestroyWindow(samplePlacement) == 0) - logLastError("error getting rid of the sample placement static control in beginFontDialog()"); + uiWindowsEnsureDestroyWindow(samplePlacement); f->sampleBox = newD2DScratch(f->hwnd, &(f->sampleRect), (HMENU) rcFontSamplePlacement, fontDialogSampleSubProc, (DWORD_PTR) f); setupInitialFontDialogState(f); @@ -512,7 +511,7 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code) cbWipeAndReleaseData(f->familyCombobox); fontCollectionFree(f->fc); if (EndDialog(f->hwnd, code) == 0) - logLastError("error ending font dialog in endFontDialog()"); + logLastError(L"error ending font dialog"); uiFree(f); } @@ -607,7 +606,7 @@ BOOL showFontDialog(HWND parent, struct fontDialogParams *params) // make the compiler happy by putting the return after the switch break; default: - logLastError("error running font dialog in showFontDialog()"); + logLastError(L"error running font dialog"); } return TRUE; } @@ -621,12 +620,12 @@ static IDWriteFontFamily *tryFindFamily(IDWriteFontCollection *fc, const WCHAR * hr = fc->FindFamilyName(name, &index, &exists); if (hr != S_OK) - logHRESULT("error finding font family for font dialog in tryFindFamily()", hr); + logHRESULT(L"error finding font family for font dialog", hr); if (!exists) return NULL; hr = fc->GetFontFamily(index, &family); if (hr != S_OK) - logHRESULT("error extracting found font family for font dialog in tryFindFamily()", hr); + logHRESULT(L"error extracting found font family for font dialog", hr); return family; } @@ -652,7 +651,7 @@ void loadInitialFontDialogParams(struct fontDialogParams *params) if (family == NULL) { hr = fc->fonts->GetFontFamily(0, &family); if (hr != S_OK) - logHRESULT("error getting first font out of font collection (worst case scenario) in loadInitialFontDialogParams()", hr); + logHRESULT(L"error getting first font out of font collection (worst case scenario)", hr); } } } @@ -664,7 +663,7 @@ void loadInitialFontDialogParams(struct fontDialogParams *params) DWRITE_FONT_STYLE_NORMAL, &font); if (hr != S_OK) - logHRESULT("error getting Regular font from Arial in loadInitialFontDialogParams()", hr); + logHRESULT(L"error getting Regular font from Arial", hr); params->font = font; params->size = 10; diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index 3a2d0e6d..42b9da7d 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -42,17 +42,19 @@ extern void CRLFtoLF(const char *s); // debug.cpp // see http://stackoverflow.com/questions/14421656/is-there-widely-available-wide-character-variant-of-file -// TODO turn line into a const WCHAR* this way +// we turn __LINE__ into a string because PRIiMAX can't be converted to a wide string in MSVC (it seems to be defined as "ll" "i" according to the compiler errors) // also note the use of __FUNCTION__ here; __func__ doesn't seem to work for some reason #define _ws2(m) L ## m #define _ws(m) _ws2(m) -#define debugargs const WCHAR *file, uintmax_t line, const WCHAR *func +#define _ws2n(m) L ## #m +#define _wsn(m) _ws2n(m) +#define debugargs const WCHAR *file, const WCHAR *line, const WCHAR *func extern HRESULT _logLastError(debugargs, const WCHAR *s); -#define logLastError(s) _logLastError(_ws(__FILE__), __LINE__, _ws(__FUNCTION__), s) +#define logLastError(s) _logLastError(_ws(__FILE__), _wsn(__LINE__), _ws(__FUNCTION__), s) extern HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr); -#define logHRESULT(s, hr) _logHRESULT(_ws(__FILE__), __LINE__, _ws(__FUNCTION__), s, hr) +#define logHRESULT(s, hr) _logHRESULT(_ws(__FILE__), _wsn(__LINE__), _ws(__FUNCTION__), s, hr) extern void _implbug(debugargs, const WCHAR *format, ...); -#define implbug(...) _implbug(_ws(__FILE__), __LINE__, _ws(__FUNCTION__), __VA_LIST__) +#define implbug(...) _implbug(_ws(__FILE__), _wsn(__LINE__), _ws(__FUNCTION__), __VA_LIST__) // winutil.cpp extern int windowClassOf(HWND hwnd, ...);