diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/PlatWin.cxx | 80 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 82 |
2 files changed, 75 insertions, 87 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 31e71988a..ee1d2d71c 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -2309,54 +2309,46 @@ void ListBoxX::Draw(DRAWITEMSTRUCT *pDrawItem) { // Draw the image, if any const RGBAImage *pimage = images.Get(pixId); if (pimage) { - Surface *surfaceItem = Surface::Allocate(technology); - if (surfaceItem) { - if (technology == SCWIN_TECH_GDI) { - surfaceItem->Init(pDrawItem->hDC, pDrawItem->hwndItem); - const long left = pDrawItem->rcItem.left + static_cast<int>(ItemInset.x + ImageInset.x); - PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, - left + images.GetWidth(), pDrawItem->rcItem.bottom); - surfaceItem->DrawRGBAImage(rcImage, - pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); - delete surfaceItem; - ::SetTextAlign(pDrawItem->hDC, TA_TOP); - } else { + std::unique_ptr<Surface> surfaceItem(Surface::Allocate(technology)); + if (technology == SCWIN_TECH_GDI) { + surfaceItem->Init(pDrawItem->hDC, pDrawItem->hwndItem); + const long left = pDrawItem->rcItem.left + static_cast<int>(ItemInset.x + ImageInset.x); + PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, + left + images.GetWidth(), pDrawItem->rcItem.bottom); + surfaceItem->DrawRGBAImage(rcImage, + pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); + ::SetTextAlign(pDrawItem->hDC, TA_TOP); + } else { #if defined(USE_D2D) - D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties( - D2D1_RENDER_TARGET_TYPE_DEFAULT, - D2D1::PixelFormat( - DXGI_FORMAT_B8G8R8A8_UNORM, - D2D1_ALPHA_MODE_IGNORE), - 0, - 0, - D2D1_RENDER_TARGET_USAGE_NONE, - D2D1_FEATURE_LEVEL_DEFAULT - ); - ID2D1DCRenderTarget *pDCRT = 0; - HRESULT hr = pD2DFactory->CreateDCRenderTarget(&props, &pDCRT); + D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties( + D2D1_RENDER_TARGET_TYPE_DEFAULT, + D2D1::PixelFormat( + DXGI_FORMAT_B8G8R8A8_UNORM, + D2D1_ALPHA_MODE_IGNORE), + 0, + 0, + D2D1_RENDER_TARGET_USAGE_NONE, + D2D1_FEATURE_LEVEL_DEFAULT + ); + ID2D1DCRenderTarget *pDCRT = 0; + HRESULT hr = pD2DFactory->CreateDCRenderTarget(&props, &pDCRT); + if (SUCCEEDED(hr)) { + RECT rcWindow; + GetClientRect(pDrawItem->hwndItem, &rcWindow); + hr = pDCRT->BindDC(pDrawItem->hDC, &rcWindow); if (SUCCEEDED(hr)) { - RECT rcWindow; - GetClientRect(pDrawItem->hwndItem, &rcWindow); - hr = pDCRT->BindDC(pDrawItem->hDC, &rcWindow); - if (SUCCEEDED(hr)) { - surfaceItem->Init(pDCRT, pDrawItem->hwndItem); - pDCRT->BeginDraw(); - const long left = pDrawItem->rcItem.left + static_cast<long>(ItemInset.x + ImageInset.x); - PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, - left + images.GetWidth(), pDrawItem->rcItem.bottom); - surfaceItem->DrawRGBAImage(rcImage, - pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); - delete surfaceItem; - pDCRT->EndDraw(); - pDCRT->Release(); - } else { - delete surfaceItem; - } - } else { - delete surfaceItem; + surfaceItem->Init(pDCRT, pDrawItem->hwndItem); + pDCRT->BeginDraw(); + const long left = pDrawItem->rcItem.left + static_cast<long>(ItemInset.x + ImageInset.x); + PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, + left + images.GetWidth(), pDrawItem->rcItem.bottom); + surfaceItem->DrawRGBAImage(rcImage, + pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); + pDCRT->EndDraw(); + pDCRT->Release(); } -#endif } +#endif } } } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 155ebdb72..cb762e54a 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -3289,57 +3289,53 @@ LRESULT PASCAL ScintillaWin::CTWndProc( } else if (iMessage == WM_PAINT) { PAINTSTRUCT ps; ::BeginPaint(hWnd, &ps); - Surface *surfaceWindow = Surface::Allocate(sciThis->technology); - if (surfaceWindow) { + std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(sciThis->technology)); #if defined(USE_D2D) - ID2D1HwndRenderTarget *pCTRenderTarget = 0; + ID2D1HwndRenderTarget *pCTRenderTarget = 0; #endif - RECT rc; - GetClientRect(hWnd, &rc); - // Create a Direct2D render target. - if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) { - surfaceWindow->Init(ps.hdc, hWnd); - } else { + RECT rc; + GetClientRect(hWnd, &rc); + // Create a Direct2D render target. + if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) { + surfaceWindow->Init(ps.hdc, hWnd); + } else { #if defined(USE_D2D) - D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp; - dhrtp.hwnd = hWnd; - dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); - dhrtp.presentOptions = (sciThis->technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ? - D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE; - - D2D1_RENDER_TARGET_PROPERTIES drtp; - drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; - drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN; - drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; - drtp.dpiX = 96.0; - drtp.dpiY = 96.0; - drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE; - drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; - - if (!SUCCEEDED(pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pCTRenderTarget))) { - surfaceWindow->Release(); - delete surfaceWindow; - ::EndPaint(hWnd, &ps); - return 0; - } - surfaceWindow->Init(pCTRenderTarget, hWnd); - pCTRenderTarget->BeginDraw(); -#endif + D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp; + dhrtp.hwnd = hWnd; + dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); + dhrtp.presentOptions = (sciThis->technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ? + D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE; + + D2D1_RENDER_TARGET_PROPERTIES drtp; + drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; + drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN; + drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; + drtp.dpiX = 96.0; + drtp.dpiY = 96.0; + drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE; + drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; + + if (!SUCCEEDED(pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pCTRenderTarget))) { + surfaceWindow->Release(); + ::EndPaint(hWnd, &ps); + return 0; } - surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage); - surfaceWindow->SetDBCSMode(sciThis->ct.codePage); - sciThis->ct.PaintCT(surfaceWindow); + surfaceWindow->Init(pCTRenderTarget, hWnd); + pCTRenderTarget->BeginDraw(); +#endif + } + surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage); + surfaceWindow->SetDBCSMode(sciThis->ct.codePage); + sciThis->ct.PaintCT(surfaceWindow.get()); #if defined(USE_D2D) - if (pCTRenderTarget) - pCTRenderTarget->EndDraw(); + if (pCTRenderTarget) + pCTRenderTarget->EndDraw(); #endif - surfaceWindow->Release(); - delete surfaceWindow; + surfaceWindow->Release(); #if defined(USE_D2D) - if (pCTRenderTarget) - pCTRenderTarget->Release(); + if (pCTRenderTarget) + pCTRenderTarget->Release(); #endif - } ::EndPaint(hWnd, &ps); return 0; } else if ((iMessage == WM_NCLBUTTONDOWN) || (iMessage == WM_NCLBUTTONDBLCLK)) { |