Kaydet (Commit) b940eb59 authored tarafından Dmitriy Shilin's avatar Dmitriy Shilin Kaydeden (comit) Mike Kaganski

tdf#107792 vcl/win: do not afraid to delete stock objects

Calling the DeleteObject function with a stock object does nothing [1].

1. https://docs.microsoft.com/en-us/previous-versions/ms969928(v=msdn.10)

Change-Id: Icfa1eb834dae33132ff49633035d52606e0cc236
Reviewed-on: https://gerrit.libreoffice.org/66646Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 64b80124
......@@ -210,9 +210,7 @@ WinSalGraphicsImpl::WinSalGraphicsImpl(WinSalGraphics& rParent):
mbXORMode(false),
mbPen(false),
mhPen(nullptr),
mbStockPen(false),
mbBrush(false),
mbStockBrush(false),
mhBrush(nullptr)
{
}
......@@ -220,16 +218,10 @@ WinSalGraphicsImpl::WinSalGraphicsImpl(WinSalGraphics& rParent):
WinSalGraphicsImpl::~WinSalGraphicsImpl()
{
if ( mhPen )
{
if ( !mbStockPen )
DeletePen( mhPen );
}
DeletePen( mhPen );
if ( mhBrush )
{
if ( !mbStockBrush )
DeleteBrush( mhBrush );
}
DeleteBrush( mhBrush );
}
void WinSalGraphicsImpl::Init()
......@@ -1286,7 +1278,6 @@ void WinSalGraphicsImpl::SetLineColor()
// set new data
mbPen = FALSE;
mbStockPen = TRUE;
}
void WinSalGraphicsImpl::SetLineColor(Color nColor)
......@@ -1294,12 +1285,8 @@ void WinSalGraphicsImpl::SetLineColor(Color nColor)
COLORREF nPenColor = PALETTERGB(nColor.GetRed(),
nColor.GetGreen(),
nColor.GetBlue());
bool bStockPen = false;
HPEN hNewPen = SearchStockPen(nPenColor);
if (hNewPen)
bStockPen = true;
else
if (!hNewPen)
hNewPen = MakePen(nColor);
ResetPen(hNewPen);
......@@ -1308,7 +1295,6 @@ void WinSalGraphicsImpl::SetLineColor(Color nColor)
mnPenColor = nPenColor;
maLineColor = nColor;
mbPen = TRUE;
mbStockPen = bStockPen;
}
HPEN WinSalGraphicsImpl::SearchStockPen(COLORREF nPenColor)
......@@ -1350,16 +1336,9 @@ void WinSalGraphicsImpl::ResetPen(HPEN hNewPen)
HPEN hOldPen = SelectPen(mrParent.getHDC(), hNewPen);
if (mhPen)
{
if (!mbStockPen)
{
DeletePen(mhPen);
}
}
DeletePen(mhPen);
else
{
mrParent.mhDefPen = hOldPen;
}
mhPen = hNewPen;
}
......@@ -1370,7 +1349,6 @@ void WinSalGraphicsImpl::SetFillColor()
// set new data
mbBrush = FALSE;
mbStockBrush = TRUE;
}
void WinSalGraphicsImpl::SetFillColor(Color nColor)
......@@ -1378,12 +1356,8 @@ void WinSalGraphicsImpl::SetFillColor(Color nColor)
COLORREF nBrushColor = PALETTERGB(nColor.GetRed(),
nColor.GetGreen(),
nColor.GetBlue());
bool bStockBrush = false;
HBRUSH hNewBrush = SearchStockBrush(nBrushColor);
if (hNewBrush)
bStockBrush = true;
else
if (!hNewBrush)
hNewBrush = MakeBrush(nColor);
ResetBrush(hNewBrush);
......@@ -1392,7 +1366,6 @@ void WinSalGraphicsImpl::SetFillColor(Color nColor)
mnBrushColor = nBrushColor;
maFillColor = nColor;
mbBrush = TRUE;
mbStockBrush = bStockBrush;
}
HBRUSH WinSalGraphicsImpl::SearchStockBrush(COLORREF nBrushColor)
......@@ -1525,16 +1498,9 @@ void WinSalGraphicsImpl::ResetBrush(HBRUSH hNewBrush)
HBRUSH hOldBrush = SelectBrush(mrParent.getHDC(), hNewBrush);
if (mhBrush)
{
if (!mbStockBrush)
{
DeleteBrush(mhBrush);
}
}
DeleteBrush(mhBrush);
else
{
mrParent.mhDefBrush = hOldBrush;
}
mhBrush = hNewBrush;
}
......
......@@ -38,9 +38,7 @@ private:
bool mbXORMode : 1; // _every_ output with RasterOp XOR
bool mbPen : 1; // is Pen (FALSE == NULL_PEN)
HPEN mhPen; // Pen
bool mbStockPen : 1; // is Pen a stockpen
bool mbBrush : 1; // is Brush (FALSE == NULL_BRUSH)
bool mbStockBrush : 1; // is Brush a stockbrush
HBRUSH mhBrush; // Brush
COLORREF mnPenColor; // PenColor
COLORREF mnBrushColor; // BrushColor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment