Replaced GraphicsHDC from src/msw/renderer.cpp with wxDC::GetTempHDC().

wxDC::GetTempHDC() method provides a convenient and safe way to retrieve HDC
from a wxDC object, whether it is using GDI or GDI+. It is implemented using
(MSW-specific) virtual functions in wxDC and so doesn't need ugly hacks like
wxDynamicCast which were used in src/msw/renderer.cpp to achieve the same
effect.

Also, we now use GetTempHDC() consistently in all wxMSW rendering methods as
the old GraphicsHDC was only used in some of them meaning that many methods
didn't work at all with wxGCDC.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62294 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-10-05 22:56:58 +00:00
parent 6c9aaf7d0c
commit 942d5e2d72
4 changed files with 87 additions and 62 deletions

View File

@@ -1199,7 +1199,50 @@ public:
#endif // WXWIN_COMPATIBILITY_2_8
#ifdef __WXMSW__
// GetHDC() is the simplest way to retrieve an HDC From a wxDC but only
// works if this wxDC is GDI-based and fails for GDI+ contexts (and
// anything else without HDC, e.g. wxPostScriptDC)
WXHDC GetHDC() const;
// don't use these methods manually, use GetTempHDC() instead
virtual WXHDC AcquireHDC() { return GetHDC(); }
virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { }
// helper class holding the result of GetTempHDC() with std::auto_ptr<>-like
// semantics, i.e. it is moved when copied
class TempHDC
{
public:
TempHDC(wxDC& dc)
: m_dc(dc),
m_hdc(dc.AcquireHDC())
{
}
TempHDC(const TempHDC& thdc)
: m_dc(thdc.m_dc),
m_hdc(thdc.m_hdc)
{
const_cast<TempHDC&>(thdc).m_hdc = 0;
}
~TempHDC()
{
if ( m_hdc )
m_dc.ReleaseHDC(m_hdc);
}
WXHDC GetHDC() const { return m_hdc; }
private:
wxDC& m_dc;
WXHDC m_hdc;
wxDECLARE_NO_ASSIGN_CLASS(TempHDC);
};
// GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c)
TempHDC GetTempHDC() { return TempHDC(*this); }
#endif // __WXMSW__
protected: