]> git.saurik.com Git - wxWidgets.git/commitdiff
don't call SelectObject() twice in SetPen() (slow!); don't do anything if setting...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Feb 2004 14:22:12 +0000 (14:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Feb 2004 14:22:12 +0000 (14:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25631 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/dc.cpp

index 6c8aa17100c2b688b022fd3ac7f4c520c20b4946..91de2abe8e197af902cf42a8da3a6d9cae8b3055 100644 (file)
@@ -1357,31 +1357,37 @@ void wxDC::SetPen(const wxPen& pen)
 {
     WXMICROWIN_CHECK_HDC
 
-    // Set the old object temporarily, in case the assignment deletes an object
-    // that's not yet selected out.
-    if (m_oldPen)
-    {
-        ::SelectObject(GetHdc(), (HPEN) m_oldPen);
-        m_oldPen = 0;
-    }
-
-    m_pen = pen;
+    if ( pen == m_pen )
+        return;
 
-    if (!m_pen.Ok())
+    if ( pen.Ok() )
     {
-        if (m_oldPen)
-            ::SelectObject(GetHdc(), (HPEN) m_oldPen);
-        m_oldPen = 0;
-    }
+        HGDIOBJ hpen = ::SelectObject(GetHdc(), GetHpenOf(pen));
+        if ( hpen == HGDI_ERROR )
+        {
+            wxLogLastError(_T("SelectObject(pen)"));
+        }
+        else // selected ok
+        {
+            if ( !m_oldPen )
+                m_oldPen = (WXHPEN)hpen;
 
-    if (m_pen.Ok())
+            m_pen = pen;
+        }
+    }
+    else // invalid pen, reset the current pen
     {
-        if (m_pen.GetResourceHandle())
+        if ( m_oldPen )
         {
-            HPEN p = (HPEN) ::SelectObject(GetHdc(), (HPEN)m_pen.GetResourceHandle());
-            if (!m_oldPen)
-                m_oldPen = (WXHPEN) p;
+            if ( ::SelectObject(GetHdc(), (HPEN) m_oldPen) == HGDI_ERROR )
+            {
+                wxLogLastError(_T("SelectObject(old pen)"));
+            }
+
+            m_oldPen = NULL;
         }
+
+        m_pen = wxNullPen;
     }
 }