don't call SelectObject() twice in SetBrush() nor SetFont() neither
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
121
src/msw/dc.cpp
121
src/msw/dc.cpp
@@ -1320,36 +1320,44 @@ void wxDC::InitializePalette()
|
|||||||
|
|
||||||
#endif // wxUSE_PALETTE
|
#endif // wxUSE_PALETTE
|
||||||
|
|
||||||
void wxDC::SetFont(const wxFont& the_font)
|
// SetFont/Pen/Brush() really ask to be implemented as a single template
|
||||||
|
// function... but doing it is not worth breaking OpenWatcom build <sigh>
|
||||||
|
|
||||||
|
void wxDC::SetFont(const wxFont& font)
|
||||||
{
|
{
|
||||||
WXMICROWIN_CHECK_HDC
|
WXMICROWIN_CHECK_HDC
|
||||||
|
|
||||||
// Set the old object temporarily, in case the assignment deletes an object
|
if ( font == m_font )
|
||||||
// that's not yet selected out.
|
return;
|
||||||
if (m_oldFont)
|
|
||||||
{
|
|
||||||
::SelectObject(GetHdc(), (HFONT) m_oldFont);
|
|
||||||
m_oldFont = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_font = the_font;
|
if ( font.Ok() )
|
||||||
|
|
||||||
if (!the_font.Ok())
|
|
||||||
{
|
{
|
||||||
if (m_oldFont)
|
HGDIOBJ hfont = ::SelectObject(GetHdc(), GetHfontOf(font));
|
||||||
::SelectObject(GetHdc(), (HFONT) m_oldFont);
|
if ( hfont == HGDI_ERROR )
|
||||||
m_oldFont = 0;
|
{
|
||||||
|
wxLogLastError(_T("SelectObject(font)"));
|
||||||
}
|
}
|
||||||
|
else // selected ok
|
||||||
if (m_font.Ok() && m_font.GetResourceHandle())
|
|
||||||
{
|
{
|
||||||
HFONT f = (HFONT) ::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle());
|
|
||||||
if (f == (HFONT) NULL)
|
|
||||||
{
|
|
||||||
wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
|
|
||||||
}
|
|
||||||
if ( !m_oldFont )
|
if ( !m_oldFont )
|
||||||
m_oldFont = (WXHFONT) f;
|
m_oldFont = (WXHPEN)hfont;
|
||||||
|
|
||||||
|
m_font = font;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // invalid font, reset the current font
|
||||||
|
{
|
||||||
|
if ( m_oldFont )
|
||||||
|
{
|
||||||
|
if ( ::SelectObject(GetHdc(), (HPEN) m_oldFont) == HGDI_ERROR )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("SelectObject(old font)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_oldFont = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_font = wxNullFont;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1395,47 +1403,54 @@ void wxDC::SetBrush(const wxBrush& brush)
|
|||||||
{
|
{
|
||||||
WXMICROWIN_CHECK_HDC
|
WXMICROWIN_CHECK_HDC
|
||||||
|
|
||||||
// Set the old object temporarily, in case the assignment deletes an object
|
if ( brush == m_brush )
|
||||||
// that's not yet selected out.
|
return;
|
||||||
if (m_oldBrush)
|
|
||||||
{
|
|
||||||
::SelectObject(GetHdc(), (HBRUSH) m_oldBrush);
|
|
||||||
m_oldBrush = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_brush = brush;
|
if ( brush.Ok() )
|
||||||
|
|
||||||
if (!m_brush.Ok())
|
|
||||||
{
|
{
|
||||||
if (m_oldBrush)
|
// we must make sure the brush is aligned with the logical coordinates
|
||||||
::SelectObject(GetHdc(), (HBRUSH) m_oldBrush);
|
// before selecting it
|
||||||
m_oldBrush = 0;
|
wxBitmap *stipple = brush.GetStipple();
|
||||||
}
|
|
||||||
|
|
||||||
if (m_brush.Ok())
|
|
||||||
{
|
|
||||||
// to make sure the brush is alligned with the logical coordinates
|
|
||||||
wxBitmap *stipple = m_brush.GetStipple();
|
|
||||||
if ( stipple && stipple->Ok() )
|
if ( stipple && stipple->Ok() )
|
||||||
{
|
{
|
||||||
#ifdef __WIN32__
|
if ( !::SetBrushOrgEx
|
||||||
::SetBrushOrgEx(GetHdc(),
|
(
|
||||||
|
GetHdc(),
|
||||||
m_deviceOriginX % stipple->GetWidth(),
|
m_deviceOriginX % stipple->GetWidth(),
|
||||||
m_deviceOriginY % stipple->GetHeight(),
|
m_deviceOriginY % stipple->GetHeight(),
|
||||||
NULL); // don't need previous brush origin
|
NULL // [out] previous brush origin
|
||||||
#else
|
) )
|
||||||
::SetBrushOrg(GetHdc(),
|
{
|
||||||
m_deviceOriginX % stipple->GetWidth(),
|
wxLogLastError(_T("SetBrushOrgEx()"));
|
||||||
m_deviceOriginY % stipple->GetHeight());
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_brush.GetResourceHandle() )
|
HGDIOBJ hbrush = ::SelectObject(GetHdc(), GetHbrushOf(brush));
|
||||||
|
if ( hbrush == HGDI_ERROR )
|
||||||
{
|
{
|
||||||
HBRUSH b = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH)m_brush.GetResourceHandle());
|
wxLogLastError(_T("SelectObject(brush)"));
|
||||||
if (!m_oldBrush)
|
|
||||||
m_oldBrush = (WXHBRUSH) b;
|
|
||||||
}
|
}
|
||||||
|
else // selected ok
|
||||||
|
{
|
||||||
|
if ( !m_oldBrush )
|
||||||
|
m_oldBrush = (WXHPEN)hbrush;
|
||||||
|
|
||||||
|
m_brush = brush;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // invalid brush, reset the current brush
|
||||||
|
{
|
||||||
|
if ( m_oldBrush )
|
||||||
|
{
|
||||||
|
if ( ::SelectObject(GetHdc(), (HPEN) m_oldBrush) == HGDI_ERROR )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("SelectObject(old brush)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_oldBrush = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_brush = wxNullBrush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user