]> git.saurik.com Git - wxWidgets.git/commitdiff
made GetTextExtent() work correctly with NULL theFont parameter (m_font might nto...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 30 Jun 2004 15:47:01 +0000 (15:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 30 Jun 2004 15:47:01 +0000 (15:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28105 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/window.cpp

index 0bfc2289326c7a66ec6fb81852dc1ba6817f13cc..ce7542227130a1704d0d3fecfb57f2508815bc83 100644 (file)
@@ -1663,31 +1663,18 @@ void wxWindowMSW::GetTextExtent(const wxString& string,
                              int *descent, int *externalLeading,
                              const wxFont *theFont) const
 {
-    const wxFont *fontToUse = theFont;
-    if ( !fontToUse )
-        fontToUse = &m_font;
+    wxASSERT_MSG( !theFont || theFont->Ok(),
+                    _T("invalid font in GetTextExtent()") );
 
-    HWND hWnd = GetHwnd();
-    HDC dc = ::GetDC(hWnd);
+    const wxFont fontToUse(theFont ? *theFont : GetFont());
 
-    HFONT fnt = 0;
-    HFONT hfontOld = 0;
-    if ( fontToUse && fontToUse->Ok() )
-    {
-        fnt = (HFONT)((wxFont *)fontToUse)->GetResourceHandle(); // const_cast
-        if ( fnt )
-            hfontOld = (HFONT)SelectObject(dc,fnt);
-    }
+    WindowHDC hdc(GetHwnd());
+    SelectInHDC selectFont(hdc, GetHfontOf(fontToUse));
 
     SIZE sizeRect;
     TEXTMETRIC tm;
-    GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
-    GetTextMetrics(dc, &tm);
-
-    if ( fontToUse && fnt && hfontOld )
-        SelectObject(dc, hfontOld);
-
-    ReleaseDC(hWnd, dc);
+    GetTextExtentPoint(hdc, string, string.length(), &sizeRect);
+    GetTextMetrics(hdc, &tm);
 
     if ( x )
         *x = sizeRect.cx;