diff options
author | Dmitriy Shilin <dshil@fastmail.com> | 2018-12-14 09:34:34 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-12-27 12:43:50 +0100 |
commit | 71f02295f2dca557fddd7dbdd19bfd464de06508 (patch) | |
tree | 07f6b900ba38aaa0db68492ed5f28a3f85827c64 /vcl/win | |
parent | a7ff057c2bc1d8e034e190c1d06846f26083630b (diff) |
tdf#107792 vcl/win/gdi: introduce ScopedHBRUSH
Change-Id: Ieca634892f4af1b0c38fa6bd8a8bbbb8f1c7370d
Reviewed-on: https://gerrit.libreoffice.org/65141
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/win')
-rw-r--r-- | vcl/win/gdi/gdiimpl.cxx | 40 | ||||
-rw-r--r-- | vcl/win/gdi/scoped_gdi.hxx | 28 |
2 files changed, 49 insertions, 19 deletions
diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx index 50238bf801a9..7b489e32261a 100644 --- a/vcl/win/gdi/gdiimpl.cxx +++ b/vcl/win/gdi/gdiimpl.cxx @@ -20,6 +20,7 @@ #include <svsys.h> #include "gdiimpl.hxx" +#include "scoped_gdi.hxx" #include <string.h> #include <rtl/strbuf.hxx> @@ -772,9 +773,9 @@ bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth, return bRet; } -void WinSalGraphicsImpl::drawMask( const SalTwoRect& rPosAry, - const SalBitmap& rSSalBitmap, - Color nMaskColor ) +void WinSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry, + const SalBitmap& rSSalBitmap, + Color nMaskColor) { SAL_WARN_IF( mrParent.isPrinter(), "vcl", "No transparency print possible!" ); @@ -783,12 +784,12 @@ void WinSalGraphicsImpl::drawMask( const SalTwoRect& rPosAry, const WinSalBitmap& rSalBitmap = static_cast<const WinSalBitmap&>(rSSalBitmap); SalTwoRect aPosAry = rPosAry; - const BYTE cRed = nMaskColor.GetRed(); - const BYTE cGreen = nMaskColor.GetGreen(); - const BYTE cBlue = nMaskColor.GetBlue(); - HDC hDC = mrParent.getHDC(); - HBRUSH hMaskBrush = CreateSolidBrush( RGB( cRed, cGreen, cBlue ) ); - HBRUSH hOldBrush = SelectBrush( hDC, hMaskBrush ); + const HDC hDC = mrParent.getHDC(); + + ScopedHBRUSH hMaskBrush(CreateSolidBrush(RGB(nMaskColor.GetRed(), + nMaskColor.GetGreen(), + nMaskColor.GetBlue()))); + HBRUSH hOldBrush = SelectBrush(hDC, hMaskBrush.get()); // WIN/WNT seems to have a minor problem mapping the correct color of the // mask to the palette if we draw the DIB directly ==> draw DDB @@ -802,8 +803,7 @@ void WinSalGraphicsImpl::drawMask( const SalTwoRect& rPosAry, else ImplDrawBitmap( hDC, aPosAry, rSalBitmap, false, 0x00B8074AUL ); - SelectBrush( hDC, hOldBrush ); - DeleteBrush( hMaskBrush ); + SelectBrush(hDC, hOldBrush); } std::shared_ptr<SalBitmap> WinSalGraphicsImpl::getBitmap( long nX, long nY, long nDX, long nDY ) @@ -1575,16 +1575,18 @@ void WinSalGraphicsImpl::SetROPFillColor( SalROPColor nROPColor ) void WinSalGraphicsImpl::DrawPixelImpl( long nX, long nY, COLORREF crColor ) { - if ( mbXORMode ) + const HDC hDC = mrParent.getHDC(); + + if (!mbXORMode) { - HBRUSH hBrush = CreateSolidBrush( crColor ); - HBRUSH hOldBrush = SelectBrush( mrParent.getHDC(), hBrush ); - PatBlt( mrParent.getHDC(), static_cast<int>(nX), static_cast<int>(nY), int(1), int(1), PATINVERT ); - SelectBrush( mrParent.getHDC(), hOldBrush ); - DeleteBrush( hBrush ); + SetPixel(hDC, static_cast<int>(nX), static_cast<int>(nY), crColor); + return; } - else - SetPixel( mrParent.getHDC(), static_cast<int>(nX), static_cast<int>(nY), crColor ); + + ScopedHBRUSH hBrush(CreateSolidBrush(crColor)); + HBRUSH hOldBrush = SelectBrush(hDC, hBrush.get()); + PatBlt(hDC, static_cast<int>(nX), static_cast<int>(nY), int(1), int(1), PATINVERT); + SelectBrush(hDC, hOldBrush); } void WinSalGraphicsImpl::drawPixel( long nX, long nY ) diff --git a/vcl/win/gdi/scoped_gdi.hxx b/vcl/win/gdi/scoped_gdi.hxx new file mode 100644 index 000000000000..64dbd180b969 --- /dev/null +++ b/vcl/win/gdi/scoped_gdi.hxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_VCL_WIN_GDI_SCOPED_GDI_HXX +#define INCLUDED_VCL_WIN_GDI_SCOPED_GDI_HXX + +#include <win/svsys.h> +#include <win/wincomp.hxx> + +#include <memory> + +struct HBRUSHDeleter +{ + using pointer = HBRUSH; + void operator()(HBRUSH hBrush) { DeleteBrush(hBrush); } +}; + +using ScopedHBRUSH = std::unique_ptr<HBRUSH, HBRUSHDeleter>; + +#endif // INCLUDED_VCL_WIN_GDI_SCOPED_GDI_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |