X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e65a6cc1ec5537dc7f19f89e10cdfaae54adb264..ddadf560da7ec1d7477a40ed5b9277b6468dc5e7:/include/wx/dc.h diff --git a/include/wx/dc.h b/include/wx/dc.h index b928314386..82f4848adf 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -702,6 +702,9 @@ private: class WXDLLIMPEXP_CORE wxDC : public wxObject { public: + // copy attributes (font, colours and writing direction) from another DC + void CopyAttributes(const wxDC& dc); + virtual ~wxDC() { delete m_pimpl; } wxDCImpl *GetImpl() @@ -1196,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(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: @@ -1331,8 +1377,21 @@ private: class WXDLLIMPEXP_CORE wxDCFontChanger { public: - wxDCFontChanger(wxDC& dc, const wxFont& font) : m_dc(dc), m_fontOld(dc.GetFont()) + wxDCFontChanger(wxDC& dc) + : m_dc(dc), m_fontOld() + { + } + + wxDCFontChanger(wxDC& dc, const wxFont& font) + : m_dc(dc), m_fontOld(dc.GetFont()) + { + m_dc.SetFont(font); + } + + void Set(const wxFont& font) { + if ( !m_fontOld.Ok() ) + m_fontOld = m_dc.GetFont(); m_dc.SetFont(font); }