m_windowExtX = VIEWPORT_EXTENT;
m_windowExtY = VIEWPORT_EXTENT;
-
- m_hDCCount = 0;
}
wxDC::~wxDC()
{
- if ( m_hDC != 0 ) {
+ if ( m_hDC != 0 )
+ {
SelectOldObjects(m_hDC);
- if ( m_bOwnsDC ) {
- if ( m_canvas == NULL )
- ::DeleteDC(GetHdc());
+
+ // if we own the HDC, we delete it, otherwise we just release it
+
+ if ( m_bOwnsDC )
+ {
+ ::DeleteDC(GetHdc());
+ }
+ else // we don't own our HDC
+ {
+ if (m_canvas)
+ {
+ ::ReleaseDC(GetHwndOf(m_canvas), GetHdc());
+ }
else
- ::ReleaseDC((HWND)m_canvas->GetHWND(), GetHdc());
+ {
+ // Must have been a wxScreenDC
+ ::ReleaseDC((HWND) NULL, GetHdc());
+ }
}
}
-
}
// This will select current objects out of the DC,
SetROP2(GetHdc(), rop);
}
-bool wxDC::StartDoc(const wxString& message)
+bool wxDC::StartDoc(const wxString& WXUNUSED(message))
{
// We might be previewing, so return TRUE to let it continue.
return TRUE;
void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
wxCoord *descent, wxCoord *externalLeading,
- wxFont *theFont) const
+ wxFont *font) const
{
- wxFont *fontToUse = (wxFont*) theFont;
- if (!fontToUse)
- fontToUse = (wxFont*) &m_font;
+ HFONT hfontOld;
+ if ( font )
+ {
+ wxASSERT_MSG( font->Ok(), _T("invalid font in wxDC::GetTextExtent") );
+
+ hfontOld = (HFONT)::SelectObject(GetHdc(), GetHfontOf(*font));
+ }
+ else // don't change the font
+ {
+ hfontOld = 0;
+ }
SIZE sizeRect;
TEXTMETRIC tm;
- GetTextExtentPoint(GetHdc(), WXSTRINGCAST string, wxStrlen(WXSTRINGCAST string), &sizeRect);
+ GetTextExtentPoint(GetHdc(), string, string.length(), &sizeRect);
GetTextMetrics(GetHdc(), &tm);
if (x) *x = XDEV2LOGREL(sizeRect.cx);
if (y) *y = YDEV2LOGREL(sizeRect.cy);
if (descent) *descent = tm.tmDescent;
if (externalLeading) *externalLeading = tm.tmExternalLeading;
+
+ if ( hfontOld )
+ {
+ ::SelectObject(GetHdc(), hfontOld);
+ }
}
void wxDC::SetMapMode(int mode)