[Libreoffice-commits] core.git: vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Jan 20 10:12:50 UTC 2019


 vcl/win/gdi/gdiimpl.cxx |   46 ++++++----------------------------------------
 vcl/win/gdi/gdiimpl.hxx |    2 --
 2 files changed, 6 insertions(+), 42 deletions(-)

New commits:
commit b940eb5903f583089e99042d60ceae635ae2af83
Author:     Dmitriy Shilin <dshil at fastmail.com>
AuthorDate: Sat Jan 19 22:52:35 2019 -0800
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Jan 20 11:12:29 2019 +0100

    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/66646
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx
index a9406729fa21..b3f5b0735bb0 100644
--- a/vcl/win/gdi/gdiimpl.cxx
+++ b/vcl/win/gdi/gdiimpl.cxx
@@ -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;
 }
diff --git a/vcl/win/gdi/gdiimpl.hxx b/vcl/win/gdi/gdiimpl.hxx
index f1cd729daf1b..e96b226457f7 100644
--- a/vcl/win/gdi/gdiimpl.hxx
+++ b/vcl/win/gdi/gdiimpl.hxx
@@ -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


More information about the Libreoffice-commits mailing list